Commit 79bf48a
authored
Update SkiaGLFWExample-v1.py
Copilot
Copilot navigation
Copilot Chat
New conversation
You said: https://github.com/HinTak/skia-python-examples/blob/main/SkiaGLFWExample-v1.py does not seems to behave correctly
https://github.com/HinTak/skia-python-examples/blob/main/SkiaGLFWExample-v1.py does not seems to behave correctly on window resizing. Can you suggest a fix?
21 references
Copilot said: The retrieved code from `SkiaGLFWExample-v1.py` and other
The retrieved code from SkiaGLFWExample-v1.py and other related files reveals the current implementation of handling window resizing. The key function responsible for resizing is framebuffer_size_callback:
Python
def framebuffer_size_callback(window, width, height):
state.window_width, state.window_height = width, height
glViewport(0, 0, width, height)
This function is linked to GLFW's framebuffer size callback mechanism, ensuring the viewport is updated when the window is resized. However, the Skia surface and rendering target are not updated. This could lead to issues when the window is resized because the Skia rendering context may not match the new dimensions.
Suggested Fix:
To ensure proper resizing, the Skia surface and rendering context should also be updated within the framebuffer_size_callback function. Here's an updated version:
Python
def framebuffer_size_callback(window, width, height):
state.window_width, state.window_height = width, height
glViewport(0, 0, width, height)
# Recreate Skia render target for the new window size
info = skia.GrGLFramebufferInfo(0, GL_RGBA8)
kMsaaSampleCount = 0
kStencilBits = 8
target = skia.GrBackendRenderTarget(
width, height, kMsaaSampleCount, kStencilBits, info
)
props = skia.SurfaceProps(skia.SurfaceProps.kUseDeviceIndependentFonts_Flag,
skia.PixelGeometry.kUnknown_PixelGeometry)
surface = skia.Surface.MakeFromBackendRenderTarget(
grContext, target,
skia.kBottomLeft_GrSurfaceOrigin,
skia.kRGBA_8888_ColorType, None, props
)
assert surface is not None
state.surface = surface
state.canvas = surface.getCanvas()
Integration Steps:
Replace the existing framebuffer_size_callback function with the updated version above.
Ensure the ApplicationState class has properties surface and canvas to hold the Skia surface and canvas objects.
Update any references to the Skia canvas in the rendering loop to use state.canvas.
With these changes, the application should handle window resizing correctly by updating both the OpenGL viewport and the Skia rendering context.1 parent b85dfa8 commit 79bf48a
1 file changed
+21
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
98 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
99 | 117 | | |
100 | 118 | | |
101 | 119 | | |
| |||
0 commit comments