Skip to content

Support for EGL contexts in GrDirectContext.MakeGL #287

@Swarzox

Description

@Swarzox

Description

I'm encountering an issue while trying to use Skia-Python in headless mode with EGL. The ModernGL context is created successfully, but Skia is unable to detect it when the backend="egl" is used. However, it works correctly with non-EGL backends (e.g., glx or using glfw).

Here is the test code I'm using:

import moderngl
import skia
from PIL import Image

width, height = 800, 600

moderngl_context = moderngl.create_standalone_context(backend="egl")
print("ModernGL context:", moderngl_context)

skia_context = skia.GrDirectContext.MakeGL()
print("Skia context:", skia_context)

info = skia.ImageInfo.MakeN32Premul(width, height)

surface = skia.Surface.MakeRenderTarget(
    skia_context,
    skia.Budgeted.kYes,
    info
)

canvas = surface.getCanvas()
canvas.clear(skia.Color(255, 255, 255, 255))

paint = skia.Paint(
    Color=skia.Color(0, 100, 255, 200),
    Style=skia.Paint.kFill_Style,
    AntiAlias=True
)

canvas.drawCircle(width // 2, height // 2, min(width, height) // 4, paint)
canvas.flush()

image = surface.makeImageSnapshot()

pixels = image.tobytes()
image = Image.frombytes("RGBA", (width, height), pixels)
image.save('skia_circle.png')

Steps to Reproduce

  1. Use the provided code with moderngl.create_standalone_context(backend="egl").
  2. Observe that the skia.GrDirectContext.MakeGL() context is None.

Expected Behavior

Skia should detect the EGL-based ModernGL context and render as expected.


Actual Behavior

Skia fails to detect the EGL context, and skia.GrDirectContext.MakeGL() returns None.


Additional Notes

  • The same code works when backend="glx" or when using glfw, which relies on xorg and GLX.
  • Running headless with EGL is critical for our use case to avoid X11 dependencies.

Let me know if more details or logs are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions