Drawing to a glfw window managed from python, using Mac

Skip to first unread message

Kez Cleal

Jul 24, 2022, 10:20:48 AMJul 24
to skia-discuss

I am making a python application that uses glfw (python package) to manage a window and would like to use skia to draw to this window. The application is compiled using python setuptools/pip. However I cannot seem to get this to work using macOS (v11.6.8), although everything seems to work fine on ubuntu. Also everything works fine if the glfw window is managed from c++ and not python.

On the python side the window is created using:

# lib versions are: glfw '3.3.7 Cocoa NSGL EGL OSMesa dynamic' and opengl version 2.1 ATI-4.6.21
glfw.window_hint(glfw.STENCIL_BITS, 8)

window = glfw.create_window(width, height, '', None, None)

I then have a c++ class that manages the skia surface. I try and initialize the context like this:

#include <OpenGL/gl.h>  // glfw is not included here

// glGetString(GL_VERSION) returns 2.1 ATI-4.6.21

auto interface = GrGLMakeNativeInterface();
sContext = GrDirectContext::MakeGL(interface).release();
if (!sContext) { return -1; }

GrGLFramebufferInfo framebufferInfo;
framebufferInfo.fFBOID = 0;
framebufferInfo.fFormat = GL_SRGB8_ALPHA8;

SkColorType colorType = kRGBA_8888_SkColorType;

// this crashes? ->
GrBackendRenderTarget backendRenderTarget(width, height, 0, 0, framebufferInfo);

// https://gist.github.com/ad8e/dd150b775ae6aa4d5cf1a092e4713add
sSurface = SkSurface::MakeFromBackendRenderTarget(sContext, backendRenderTarget,
kBottomLeft_GrSurfaceOrigin, colorType,
SkColorSpace::MakeSRGB(), nullptr).release();

if (!sSurface) { return -1; }

canvas = sSurface->getCanvas();

This crashes on mac with an abort. If I create the glfw window in the c++ layer, then the window seems to work again. As a separate test I tried drawing a triangle using opengl functions from the c++ layer, and this also seems to work.

Im totally confused, any help on this would be amazing, thanks!

Reply all
Reply to author
0 new messages