Skip to content

Commit 318c15d

Browse files
authored
Create gpu-migration.md
1 parent 346e2e9 commit 318c15d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Hardware-Accelerated / GPU Surface Changes
2+
3+
As of SkiaSharp v1.68.0, there has been a fairly major change to the way
4+
hardware-accelerated (GPU) surfaces are created.
5+
6+
These changes were made to better support the new GPU backends. Right now, we
7+
just support OpenGL, but the changes open the door to Vulkan and Metal
8+
support.
9+
10+
The good news is that even though there were many changes, we have been able
11+
to preserve the existing functionality so that you aren't forced to update
12+
your code immediately after upgrading. However, you should migrate your code
13+
as soon as possible as there is no guarantee that the next update will still
14+
support all the existing functionality.
15+
16+
## Migration
17+
18+
The most visible change is that we are no longer using the
19+
`GRBackendRenderTargetDesc` and `GRBackendTextureDesc` types, but rather we
20+
use the similarly-named `GRBackendRenderTarget` and `GRBackendTexture`. The
21+
properties are mostly the same, except that `PixelConfig` and `Origin` have
22+
been moved to the surface construction - and should not affect the manner in
23+
which you draw to that surface.
24+
25+
Another change is that the old structures have been split into two parts, one
26+
to describe the surface we are creating, and the other to explicitly describe
27+
the backend-specific configuration needed to write to that surface.
28+
29+
For example, `GRBackendRenderTargetDesc` has been split into
30+
`GRBackendRenderTarget` which describes the general surface (such as width,
31+
height, and samples) and `GRGlFramebufferInfo` which describes OpenGL-specific
32+
surface (with the FBO ID and color format). If we were to support Vulkan, this
33+
may be swapped out with `GRVkImageInfo`, which will describe the Vulkan-
34+
specific surface (with the image handle and format).
35+
36+
#### Existing Code
37+
38+
```csharp
39+
// create the GPU context (UNCHANGED)
40+
var glInterface = GRGlInterface.CreateNativeGlInterface();
41+
var context = GRContext.Create(GRBackend.OpenGL, glInterface);
42+
43+
// create the surface (OLD)
44+
var renderTarget = new GRBackendRenderTargetDesc {
45+
Width = 1024,
46+
Height = 1024,
47+
Config = GRPixelConfig.Rgba8888,
48+
Origin = GRSurfaceOrigin.BottomLeft,
49+
SampleCount = 0,
50+
StencilBits = 0,
51+
RenderTargetHandle = IntPtr.Zero,
52+
};
53+
var surface = SKSurface.Create(context, renderTarget);
54+
55+
// draw (UNCHANGED)
56+
var canvas = surface.Canvas;
57+
// ...
58+
```
59+
60+
#### New Code
61+
62+
```csharp
63+
// create the GPU context (UNCHANGED)
64+
var glInterface = GRGlInterface.CreateNativeGlInterface();
65+
var context = GRContext.Create(GRBackend.OpenGL, glInterface);
66+
67+
// create the surface (UPDATED)
68+
var glInfo = new GRGlFramebufferInfo(
69+
fboId: 0,
70+
format: SKColorType.Rgba8888.ToGlSizedFormat());
71+
var renderTarget = new GRBackendRenderTarget(
72+
width: 1024,
73+
height: 1024,
74+
sampleCount: 0,
75+
stencilBits: 0,
76+
glInfo: glInfo);
77+
var surface = SKSurface.Create(
78+
context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
79+
80+
// draw (UNCHANGED)
81+
var canvas = surface.Canvas;
82+
// ...
83+
```

0 commit comments

Comments
 (0)