Describe the bug
First off, just want to say I'm a big fan of skia-python! But I recently heard from some users of my library coldtype (which uses skia-python extensively), that when they try to use coldtype with Python 3.12, the only option is to install 119.0b4 which triggers all kinds of issues. I've started looking into the issues (many of which are related to the image changes, I think), but there's one fundamental bug I'd like to figure out before the others, which is that I can't seem to reliably draw complex curves with anti-aliasing without triggering some obscure shader compilation errors.
To Reproduce
I'm running this script on Python 3.12.0 on macOS 12.5.1 (a slightly modified version of the glfw example code here):
import contextlib, glfw, skia
from OpenGL import GL
WIDTH, HEIGHT = 640, 480
path = skia.Path()
path.moveTo(184, 445)
path.lineTo(249, 445)
path.quadTo(278, 445, 298, 438)
path.quadTo(318, 431, 331, 419)
path.quadTo(344, 406, 350, 390)
path.quadTo(356, 373, 356, 354)
path.quadTo(356, 331, 347, 312)
path.quadTo(338, 292, 320, 280) # <- comment out this line and shape will draw correctly with anti-aliasing
path.close()
@contextlib.contextmanager
def glfw_window():
if not glfw.init():
raise RuntimeError('glfw.init() failed')
glfw.window_hint(glfw.STENCIL_BITS, 8)
window = glfw.create_window(WIDTH, HEIGHT, '', None, None)
glfw.make_context_current(window)
yield window
glfw.terminate()
@contextlib.contextmanager
def skia_surface(window):
context = skia.GrDirectContext.MakeGL()
(fb_width, fb_height) = glfw.get_framebuffer_size(window)
backend_render_target = skia.GrBackendRenderTarget(
fb_width,
fb_height,
0, # sampleCnt
0, # stencilBits
skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))
surface = skia.Surface.MakeFromBackendRenderTarget(
context, backend_render_target, skia.kBottomLeft_GrSurfaceOrigin,
skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
assert surface is not None
yield surface
context.abandonContext()
with glfw_window() as window:
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
with skia_surface(window) as surface:
with surface as canvas:
canvas.drawCircle(100, 100, 40, skia.Paint(Color=skia.ColorGREEN, AntiAlias=True))
paint = skia.Paint(Color=skia.ColorBLUE)
paint.setStyle(skia.Paint.kStroke_Style)
paint.setStrokeWidth(2)
paint.setAntiAlias(True)
canvas.drawPath(path, paint)
surface.flushAndSubmit()
glfw.swap_buffers(window)
while (glfw.get_key(window, glfw.KEY_ESCAPE) != glfw.PRESS
and not glfw.window_should_close(window)):
glfw.wait_events()
On my setup, running that code produces this output:
Shader compilation error
------------------------
1 #version 110
2
3 uniform vec4 sk_RTAdjust;
4 uniform vec2 uatlas_adjust_S0;
5 attribute vec4 fillBounds;
6 attribute vec4 color;
7 attribute vec4 locations;
8 varying vec2 vatlasCoord_S0;
9 varying vec4 vcolor_S0;
10 void main() {
11 vec2 unitCoord = vec2(float(gl_VertexID & 1), float(gl_VertexID >> 1));
12 vec2 devCoord = mix(fillBounds.xy, fillBounds.zw, unitCoord);
13 vec2 atlasTopLeft = vec2(abs(locations.x) - 1.0, locations.y);
14 vec2 devTopLeft = locations.zw;
15 bool transposed = locations.x < 0.0;
16 vec2 atlasCoord = devCoord - devTopLeft;
17 if (transposed) {
18 atlasCoord = atlasCoord.yx;
19 }
20 atlasCoord += atlasTopLeft;
21 vatlasCoord_S0 = atlasCoord * uatlas_adjust_S0;
22 vcolor_S0 = color;
23 gl_Position = vec4(devCoord, 0.0, 1.0);
24 gl_Position = vec4(gl_Position.xy * sk_RTAdjust.xz + gl_Position.ww * sk_RTAdjust.yw, 0.0, gl_Position.w);
25 }
26
Errors:
ERROR: 0:11: Use of undeclared identifier 'gl_VertexID'
ERROR: 0:11: Use of undeclared identifier 'gl_VertexID'
ERROR: 0:12: Use of undeclared identifier 'unitCoord'
ERROR: 0:16: Use of undeclared identifier 'devCoord'
ERROR: 0:18: Use of undeclared identifier 'atlasCoord'
ERROR: 0:18: Use of undeclared identifier 'atlasCoord'
ERROR: 0:20: Use of undeclared identifier 'atlasCoord'
ERROR: 0:21: Use of undeclared identifier 'atlasCoord'
ERROR: 0:23: Use of undeclared identifier 'devCoord'
Expected behavior
For the curve to be drawn on screen without a shader compilation error. With 87.5 running the same code, this is the graphical output:

Desktop (please complete the following information):
- OS: macOS 12.5.1
- Python: 3.12.0
- skia-python version: 119.0b4
Additional context
I realize these releases are still pre-release, but as they install by default with Python3.12, I wanted to get ahead of the skia updates to make sure Coldtype can continue working correctly. Thanks for all the hard work on this awesome library!
Describe the bug
First off, just want to say I'm a big fan of skia-python! But I recently heard from some users of my library coldtype (which uses skia-python extensively), that when they try to use coldtype with Python 3.12, the only option is to install 119.0b4 which triggers all kinds of issues. I've started looking into the issues (many of which are related to the image changes, I think), but there's one fundamental bug I'd like to figure out before the others, which is that I can't seem to reliably draw complex curves with anti-aliasing without triggering some obscure shader compilation errors.
To Reproduce
I'm running this script on Python 3.12.0 on macOS 12.5.1 (a slightly modified version of the glfw example code here):
On my setup, running that code produces this output:
Expected behavior

For the curve to be drawn on screen without a shader compilation error. With 87.5 running the same code, this is the graphical output:
Desktop (please complete the following information):
Additional context
I realize these releases are still pre-release, but as they install by default with Python3.12, I wanted to get ahead of the skia updates to make sure Coldtype can continue working correctly. Thanks for all the hard work on this awesome library!