Skip to content

Instantly share code, notes, and snippets.

@mvduin
Created July 20, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvduin/014fafc53a3d87e8e7bca16be3eb7dde to your computer and use it in GitHub Desktop.
Save mvduin/014fafc53a3d87e8e7bca16be3eb7dde to your computer and use it in GitHub Desktop.
wsegl v4, cleaned up
/*************************************************************************/ /*!
@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
@License Dual MIT/GPLv2
The contents of this file are subject to the MIT license as set out below.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 ("GPL") in which case the provisions
of GPL are applicable instead of those above.
If you wish to allow use of your version of this file only under the terms of
GPL, and not to allow others to use your version of this file under the terms
of the MIT license, indicate your decision by deleting the provisions above
and replace them with the notice and other provisions required by GPL as set
out in the file called "GPL-COPYING" included in this distribution. If you do
not delete the provisions above, a recipient may use your version of this file
under the terms of either the MIT license or GPL.
This License is also included in this distribution in the file called
"MIT-COPYING".
EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ /**************************************************************************/
#pragma once
#define WSEGL_VERSION 4
// The following types must be defined before including this header:
//
// NativeDisplayType
// NativeWindowType
// NativePixmapType
//
// private to the WSEGL module are:
//
typedef struct WSEGLDisplay WSEGLDisplayRef;
typedef struct WSEGLDrawable WSEGLDrawableRef;
// nobody uses this, reject anything but the default
typedef unsigned long NativeEngineType;
#define WSEGL_DEFAULT_DISPLAY ((NativeDisplayType) 0)
#define WSEGL_DEFAULT_NATIVE_ENGINE ((NativeEngineType) 0)
// Display capabilities
typedef enum WSEGLCapsType
{
WSEGL_NO_CAPS = 0,
WSEGL_CAP_MIN_SWAP_INTERVAL = 1, // default 1
WSEGL_CAP_MAX_SWAP_INTERVAL = 2, // default 1
WSEGL_CAP_WINDOWS_USE_HW_SYNC = 3, // default false
WSEGL_CAP_PIXMAPS_USE_HW_SYNC = 4, // default false
// When this capability is set, the EGL lock is not taken around calls
// to WSEGL functions. The WSEGL module is responsible for performing
// its own locking in this case.
WSEGL_CAP_UNLOCKED = 5, // default false
} WSEGLCapsType;
typedef struct WSEGLCaps
{
enum WSEGLCapsType type;
unsigned long value;
} WSEGLCaps;
// array of capabilities, terminated by element with .type == 0
typedef WSEGLCaps const *WSEGLCapsArray;
// Drawable type
#define WSEGL_NO_DRAWABLE 0
#define WSEGL_DRAWABLE_WINDOW (1 << 0)
#define WSEGL_DRAWABLE_PIXMAP (1 << 1)
// YUV format flags and sync
#define WSEGL_FLAGS_YUV_CONFORMANT_RANGE (0 << 0)
#define WSEGL_FLAGS_YUV_FULL_RANGE (1 << 0)
#define WSEGL_FLAGS_YUV_BT601 (0 << 1)
#define WSEGL_FLAGS_YUV_BT709 (1 << 1)
#define WSEGL_FLAGS_EGLIMAGE_COMPOSITION_SYNC (1 << 2)
// Pixel format of display/drawable
typedef enum WSEGLPixelFormat
{
WSEGL_PIXELFORMAT_RGB565 = 0,
WSEGL_PIXELFORMAT_ARGB4444 = 1,
WSEGL_PIXELFORMAT_ARGB8888 = 2,
WSEGL_PIXELFORMAT_ARGB1555 = 3,
WSEGL_PIXELFORMAT_ABGR8888 = 4,
WSEGL_PIXELFORMAT_XBGR8888 = 5,
WSEGL_PIXELFORMAT_NV12 = 6,
WSEGL_PIXELFORMAT_YUYV = 7,
WSEGL_PIXELFORMAT_YV12 = 8,
WSEGL_PIXELFORMAT_XRGB8888 = 9,
WSEGL_PIXELFORMAT_UYVY = 10,
WSEGL_PIXELFORMAT_NV12_4KALIGN = 11,
WSEGL_PIXELFORMAT_NV21_4KALIGN = 12,
WSEGL_PIXELFORMAT_R8 = 13,
WSEGL_PIXELFORMAT_R8G8 = 14,
WSEGL_PIXELFORMAT_NV21 = 15,
// These are compatibility names only; new WSEGL
// modules should not use them.
WSEGL_PIXELFORMAT_565 = WSEGL_PIXELFORMAT_RGB565,
WSEGL_PIXELFORMAT_4444 = WSEGL_PIXELFORMAT_ARGB4444,
WSEGL_PIXELFORMAT_8888 = WSEGL_PIXELFORMAT_ARGB8888,
WSEGL_PIXELFORMAT_1555 = WSEGL_PIXELFORMAT_ARGB1555,
} WSEGLPixelFormat;
// Display/drawable configuration
typedef struct WSEGLConfig
{
// bitmask of drawable types this configuration applies to
unsigned long drawable_types;
enum WSEGLPixelFormat pixel_format;
unsigned long is_native_renderable;
unsigned long framebuffer_level;
unsigned long native_visual_id;
unsigned long native_visual_type;
unsigned int uses_colorkey; // doesn't work
unsigned long colorkey_color; // packed as 0x00RRGGBB
// set to true if config compatible with framebuffer
unsigned long is_framebuffer_target;
} WSEGLConfig;
// array of configs, terminated by element with .drawable_types == 0
typedef WSEGLConfig const *WSEGLConfigArray;
// WSEGL errors
typedef enum WSEGLError
{
WSEGL_SUCCESS = 0,
WSEGL_CANNOT_INITIALISE = 1,
WSEGL_BAD_NATIVE_DISPLAY = 2,
WSEGL_BAD_NATIVE_WINDOW = 3,
WSEGL_BAD_NATIVE_PIXMAP = 4,
WSEGL_BAD_NATIVE_ENGINE = 5,
WSEGL_BAD_DRAWABLE = 6,
WSEGL_BAD_MATCH = 7,
WSEGL_OUT_OF_MEMORY = 8,
WSEGL_RETRY = 9,
// These are compatibility names only; new WSEGL
// modules should not use them.
WSEGL_BAD_CONFIG = WSEGL_BAD_MATCH,
} WSEGLError;
// Drawable orientation (in degrees anti-clockwise)
typedef enum WSEGLRotation
{
WSEGL_ROTATE_0 = 0,
WSEGL_ROTATE_90 = 1,
WSEGL_ROTATE_180 = 2,
WSEGL_ROTATE_270 = 3,
} WSEGLRotation;
// Maximum number of optional PowerVR Services 4 SYNCINFO objects
#define WSEGL_MAX_SRC_SYNCS 32
// Drawable information required by OpenGL-ES driver
typedef struct WSEGLDrawableParams
{
unsigned long width;
unsigned long height;
unsigned long stride; // in pixels
enum WSEGLPixelFormat pixel_format;
// buffer mapped into cpu (userspace) and sgx virtual memory
void *cpu_base;
unsigned long gpu_base;
// (bool) override display's HW_SYNC mode
unsigned long wait_for_render;
unsigned long flags;
// used only when drawable is used as source, since for destination
// drawable the rotation value is the one provided at creation time.
enum WSEGLRotation rotation;
// Optional PowerVR Services 4 MEMINFO pointer. This may be used for
// internal (implicit) synchronization purposes, and by PDUMP. It
// should refer to the same object as the other fields in this
// structure.
void *mem_info;
// Optional PowerVR Services 4 SYNCINFO pointers to send down as source
// surface (texture) dependencies of a render. If these are provided
// when not applicable, they will be ignored. If a sync is not needed,
// it should be passed as NULL.
void *sync_info[WSEGL_MAX_SRC_SYNCS];
} WSEGLDrawableParams;
typedef struct WSEGL_FunctionTable
{
unsigned long version; // must be WSEGL_VERSION
WSEGLError (*is_display_valid)(
NativeDisplayType ndisplay );
// Both arrays must persist until display is closed. Opening a native
// display when already open should increase its refcount and return
// the same display/caps/configs as the first open.
//
// Rumor has it egl never opens twice.
WSEGLError (*open_display)(
NativeDisplayType ndisplay,
WSEGLDisplayRef *display /*out*/,
WSEGLCapsArray *caps /*out*/,
WSEGLConfigArray *configs /*out*/ );
WSEGLError (*close_display)(
WSEGLDisplayRef display );
// The returned rotation is implicitly applied by the GL layer.
WSEGLError (*new_window_drawable)(
WSEGLDisplayRef display,
WSEGLConfig const *config,
WSEGLDrawableRef *drawable /*out*/,
NativeWindowType nwindow,
WSEGLRotation *rotation /*out*/ );
WSEGLError (*new_pixmap_drawable)(
WSEGLDisplayRef display,
WSEGLConfig const *config,
WSEGLDrawableRef *drawable /*out*/,
NativePixmapType npixmap,
WSEGLRotation *rotation /*out*/ );
WSEGLError (*delete_drawable)(
WSEGLDrawableRef drawable );
// eglSwapBuffers, eglSwapInterval, eglWaitNative
WSEGLError (*swap_buffers)(
WSEGLDrawableRef drawable,
unsigned long data );
WSEGLError (*swap_interval)(
WSEGLDrawableRef drawable,
unsigned long frames );
WSEGLError (*wait_native)(
WSEGLDrawableRef drawable,
NativeEngineType nengine );
// rumor has it nobody implements these two
WSEGLError (*copy_from_drawable)(
WSEGLDrawableRef drawable,
NativePixmapType npixmap );
WSEGLError (*copy_from_pbuffer)(
void *pixeldata,
unsigned long width,
unsigned long height,
unsigned long stride,
WSEGLPixelFormat format,
NativePixmapType npixmap );
// Different drawable params may be supplied for drawable used as source
// (e.g. glReadPixels) vs render target. The returned params are not
// required to include virtual/physical mapping (address and stride) if
// the drawable is not connected (see below). XXX is this true?
WSEGLError (*get_drawable_parameters)(
WSEGLDrawableRef drawable,
WSEGLDrawableParams *source /*out*/,
WSEGLDrawableParams *render /*out*/,
unsigned long plane_stride );
// Pin/unpin the drawable for access (refcounted).
WSEGLError (*connect_drawable)(
WSEGLDrawableRef drawable );
WSEGLError (*disconnect_drawable)(
WSEGLDrawableRef drawable );
// First draw after swap buffers, used to support EGL_BUFFER_PRESERVED
WSEGLError (*flag_start_frame)();
} WSEGL_FunctionTable;
#ifdef __cplusplus
extern "C"
#endif
WSEGL_FunctionTable const *WSEGL_GetFunctionTablePointer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment