Skip to content

Commit

Permalink
Add OpenGL support to the benchmark program (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins authored Mar 2, 2021
1 parent 3fb9191 commit 0ddaa89
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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(),
)

0 comments on commit 0ddaa89

Please sign in to comment.