Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions enable/gcbench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"kiva.agg": "enable.null.image",
"cairo": "enable.null.cairo",
"celiagg": "enable.null.celiagg",
"opengl": "enable.gcbench.opengl",
"qpainter": "enable.null.qpainter",
"quartz": "enable.null.quartz",
},
Expand Down
39 changes: 39 additions & 0 deletions enable/gcbench/opengl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# (C) Copyright 2005-2021 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
import pyglet
from pyglet.image.codecs.png import PNGImageEncoder

import kiva.gl as gl_backend

# Pass it along
CompiledPath = gl_backend.CompiledPath


class GraphicsContext(gl_backend.GraphicsContext):
""" This is a wrapper of the GL GraphicsContext which works in headless
mode.
"""
def __init__(self, size, *args, **kw):
width, height = size
self.__window = pyglet.window.Window(width=width, height=height)
super().__init__((width, height), base_pixel_scale=1.0)
self.gl_init()

def clear(self, *args):
self.__window.clear()

def save(self, filename, *args, **kw):
buffer = pyglet.image.get_buffer_manager()
with open(filename, mode="wb") as fp:
buffer.get_color_buffer().save(
filename,
file=fp,
encoder=PNGImageEncoder(),
)