63 var scaling = VisualRoot?.RenderScaling ?? 1.0;
64 var physW = Math.Max(1, (
int)Math.Round(Bounds.Width * scaling));
65 var physH = Math.Max(1, (
int)Math.Round(Bounds.Height * scaling));
68 Host =
new RenderSurfaceHost<GpuBackbuffer>(
Adapter);
72 Adapter.AttachToEngine(RequestNextFrameRendering);
86 if (_disposeRequested != 0)
89 _glInterface = GRGlInterface.Create();
91 if (_glInterface ==
null)
94 "Gondwana Avalonia GPU: could not create a GRGlInterface from the current OpenGL context. Check the Windows GPU backend and driver.");
99 _grContext = GRContext.CreateGl(_glInterface);
101 if (_grContext ==
null)
104 "Gondwana Avalonia GPU: SkiaSharp could not create a GRContext from the current OpenGL context.");
106 _glInterface.Dispose();
112 var scaling = VisualRoot?.RenderScaling ?? 1.0;
113 var physW = (int)Math.Round(Bounds.Width * scaling);
114 var physH = (int)Math.Round(Bounds.Height * scaling);
116 if (physW <= 0 || physH <= 0)
122 Adapter.UpdateDimensions(physW, physH);
123 _gpuBackbuffer?.EnsureInitialized(_grContext);
129 long telemetryGeneration =
Host?.Telemetry?.BeginSample() ?? 0;
131 if (Volatile.Read(ref _disposeRequested) != 0 || _gpuBackbuffer ==
null)
134 if (_grContext ==
null)
136 if (Interlocked.Exchange(ref _contextFailureReported, 1) == 0)
137 Trace.TraceError(
"Gondwana Avalonia GPU: render requested without a SkiaSharp OpenGL context.");
144 _grContext.ResetContext();
146 var scaling = VisualRoot?.RenderScaling ?? 1.0;
147 var physW = (int)Math.Round(Bounds.Width * scaling);
148 var physH = (int)Math.Round(Bounds.Height * scaling);
150 if (physW <= 0 || physH <= 0)
152 _lastPhysW = _lastPhysH = 0;
153 Adapter.UpdateDimensions(0, 0);
158 if (physW != _lastPhysW || physH != _lastPhysH)
162 Adapter.UpdateDimensions(physW, physH);
165 _gpuBackbuffer.EnsureInitialized(_grContext);
169 var fbInfo =
new GRGlFramebufferInfo((uint)fb, GlRgba8);
171 using var renderTarget =
new GRBackendRenderTarget(
178 using var fbSurface = SKSurface.Create(
181 GRSurfaceOrigin.BottomLeft,
182 SKColorType.Rgba8888);
184 if (fbSurface ==
null)
186 if (Interlocked.Exchange(ref _contextFailureReported, 1) == 0)
187 Trace.TraceError(
"Gondwana Avalonia GPU: unable to wrap Avalonia's framebuffer as an SKSurface.");
192 var canvas = fbSurface.Canvas;
195 using var img =
Host.GlRenderAndSnapshot();
203 canvas.Clear(
Adapter.ClearColor);
207 _gpuBackbuffer.RecordFrame();
209 if (telemetryGeneration != 0)
210 Host!.Telemetry!.Record(telemetryGeneration,
"presentation.count", 1);