2021-04-16 23:21:06 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# pyglet
|
|
|
|
# Copyright (c) 2006-2008 Alex Holkner
|
2022-04-30 13:56:57 +08:00
|
|
|
# Copyright (c) 2008-2022 pyglet contributors
|
2021-04-16 23:21:06 +08:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in
|
|
|
|
# the documentation and/or other materials provided with the
|
|
|
|
# distribution.
|
|
|
|
# * Neither the name of pyglet nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written
|
|
|
|
# permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import pyglet
|
|
|
|
import warnings
|
2021-08-13 12:25:29 +08:00
|
|
|
|
2021-04-16 23:21:06 +08:00
|
|
|
from .base import Display, Screen, ScreenMode, Canvas
|
|
|
|
|
|
|
|
|
|
|
|
from ctypes import *
|
|
|
|
from pyglet.libs.egl import egl
|
|
|
|
from pyglet.libs.egl import eglext
|
|
|
|
|
|
|
|
|
|
|
|
class HeadlessDisplay(Display):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
# TODO: fix this placeholder:
|
|
|
|
self._screens = [HeadlessScreen(self, 0, 0, 1920, 1080)]
|
|
|
|
|
|
|
|
num_devices = egl.EGLint()
|
|
|
|
eglext.eglQueryDevicesEXT(0, None, byref(num_devices))
|
|
|
|
if num_devices.value > 0:
|
|
|
|
headless_device = pyglet.options['headless_device']
|
|
|
|
if headless_device < 0 or headless_device >= num_devices.value:
|
2021-08-13 12:25:29 +08:00
|
|
|
raise ValueError('Invalid EGL devide id: %d' % headless_device)
|
2021-04-16 23:21:06 +08:00
|
|
|
devices = (eglext.EGLDeviceEXT * num_devices.value)()
|
|
|
|
eglext.eglQueryDevicesEXT(num_devices.value, devices, byref(num_devices))
|
2021-08-13 12:25:29 +08:00
|
|
|
self._display_connection = eglext.eglGetPlatformDisplayEXT(
|
|
|
|
eglext.EGL_PLATFORM_DEVICE_EXT, devices[headless_device], None)
|
2021-04-16 23:21:06 +08:00
|
|
|
else:
|
2021-08-13 12:25:29 +08:00
|
|
|
warnings.warn('No device available for EGL device platform. Using native display type.')
|
2021-04-16 23:21:06 +08:00
|
|
|
display = egl.EGLNativeDisplayType()
|
|
|
|
self._display_connection = egl.eglGetDisplay(display)
|
|
|
|
|
|
|
|
egl.eglInitialize(self._display_connection, None, None)
|
|
|
|
|
|
|
|
def get_screens(self):
|
|
|
|
return self._screens
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
egl.eglTerminate(self._display_connection)
|
|
|
|
|
|
|
|
|
|
|
|
class HeadlessCanvas(Canvas):
|
|
|
|
def __init__(self, display, egl_surface):
|
2021-08-13 12:25:29 +08:00
|
|
|
super().__init__(display)
|
2021-04-16 23:21:06 +08:00
|
|
|
self.egl_surface = egl_surface
|
|
|
|
|
2021-08-13 12:25:29 +08:00
|
|
|
|
2021-04-16 23:21:06 +08:00
|
|
|
class HeadlessScreen(Screen):
|
|
|
|
def __init__(self, display, x, y, width, height):
|
|
|
|
super().__init__(display, x, y, width, height)
|
|
|
|
|
|
|
|
def get_matching_configs(self, template):
|
|
|
|
canvas = HeadlessCanvas(self.display, None)
|
|
|
|
configs = template.match(canvas)
|
|
|
|
# XXX deprecate
|
|
|
|
for config in configs:
|
|
|
|
config.screen = self
|
|
|
|
return configs
|
|
|
|
|
|
|
|
def get_modes(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def get_mode(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def set_mode(self, mode):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def restore_mode(self):
|
|
|
|
pass
|