2008-04-25 13:37:36 +00:00
|
|
|
/*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Cogl
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
2011-02-25 00:31:41 +00:00
|
|
|
* Copyright (C) 2007,2008,2009,2010,2011 Intel Corporation.
|
2008-04-25 13:37:36 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-02-25 00:31:41 +00:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2011-02-25 00:31:41 +00:00
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
2008-04-25 13:37:36 +00:00
|
|
|
*/
|
|
|
|
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-28 01:02:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2008-04-25 13:37:36 +00:00
|
|
|
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-28 01:02:02 +00:00
|
|
|
#include "cogl.h"
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
#include "cogl-util.h"
|
2011-05-24 22:15:37 +00:00
|
|
|
#include "cogl-winsys-egl-private.h"
|
2011-02-25 00:31:41 +00:00
|
|
|
#include "cogl-winsys-private.h"
|
|
|
|
#include "cogl-feature-private.h"
|
|
|
|
#include "cogl-context-private.h"
|
|
|
|
#include "cogl-framebuffer.h"
|
2011-10-13 20:31:04 +00:00
|
|
|
#include "cogl-onscreen-private.h"
|
2011-02-25 00:31:41 +00:00
|
|
|
#include "cogl-swap-chain-private.h"
|
|
|
|
#include "cogl-renderer-private.h"
|
|
|
|
#include "cogl-onscreen-template-private.h"
|
2011-05-24 22:15:37 +00:00
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
#include "cogl-private.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2011-11-07 17:16:13 +00:00
|
|
|
#include <stdio.h>
|
2011-02-25 00:31:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2011-08-22 22:55:57 +00:00
|
|
|
#define MAX_EGL_CONFIG_ATTRIBS 30
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
/* Define a set of arrays containing the functions required from GL
|
|
|
|
for each winsys feature */
|
|
|
|
#define COGL_WINSYS_FEATURE_BEGIN(name, namespaces, extension_names, \
|
2011-05-24 16:21:28 +00:00
|
|
|
egl_private_flags) \
|
2011-02-25 00:31:41 +00:00
|
|
|
static const CoglFeatureFunction \
|
|
|
|
cogl_egl_feature_ ## name ## _funcs[] = {
|
|
|
|
#define COGL_WINSYS_FEATURE_FUNCTION(ret, name, args) \
|
|
|
|
{ G_STRINGIFY (name), G_STRUCT_OFFSET (CoglRendererEGL, pf_ ## name) },
|
|
|
|
#define COGL_WINSYS_FEATURE_END() \
|
|
|
|
{ NULL, 0 }, \
|
|
|
|
};
|
|
|
|
#include "cogl-winsys-egl-feature-functions.h"
|
|
|
|
|
|
|
|
/* Define an array of features */
|
|
|
|
#undef COGL_WINSYS_FEATURE_BEGIN
|
|
|
|
#define COGL_WINSYS_FEATURE_BEGIN(name, namespaces, extension_names, \
|
2011-05-24 16:21:28 +00:00
|
|
|
egl_private_flags) \
|
2011-07-06 17:59:20 +00:00
|
|
|
{ 255, 255, 0, namespaces, extension_names, \
|
2011-05-24 16:21:28 +00:00
|
|
|
0, egl_private_flags, \
|
|
|
|
0, \
|
2011-02-25 00:31:41 +00:00
|
|
|
cogl_egl_feature_ ## name ## _funcs },
|
|
|
|
#undef COGL_WINSYS_FEATURE_FUNCTION
|
|
|
|
#define COGL_WINSYS_FEATURE_FUNCTION(ret, name, args)
|
|
|
|
#undef COGL_WINSYS_FEATURE_END
|
|
|
|
#define COGL_WINSYS_FEATURE_END()
|
|
|
|
|
|
|
|
static const CoglFeatureData winsys_feature_data[] =
|
|
|
|
{
|
|
|
|
#include "cogl-winsys-egl-feature-functions.h"
|
|
|
|
};
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static CoglFuncPtr
|
2011-07-27 11:30:02 +00:00
|
|
|
_cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
|
|
|
|
const char *name)
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-28 01:02:02 +00:00
|
|
|
{
|
2011-07-27 11:30:02 +00:00
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
ptr = eglGetProcAddress (name);
|
|
|
|
|
|
|
|
/* eglGetProcAddress doesn't support fetching core API so we need to
|
|
|
|
get that separately with GModule */
|
|
|
|
if (ptr == NULL)
|
|
|
|
g_module_symbol (renderer->libgl_module, name, &ptr);
|
|
|
|
|
|
|
|
return ptr;
|
Intial Re-layout of the Cogl source code and introduction of a Cogl Winsys
As part of an incremental process to have Cogl be a standalone project we
want to re-consider how we organise the Cogl source code.
Currently this is the structure I'm aiming for:
cogl/
cogl/
<put common source here>
winsys/
cogl-glx.c
cogl-wgl.c
driver/
gl/
gles/
os/ ?
utils/
cogl-fixed
cogl-matrix-stack?
cogl-journal?
cogl-primitives?
pango/
The new winsys component is a starting point for migrating window system
code (i.e. x11,glx,wgl,osx,egl etc) from Clutter to Cogl.
The utils/ and pango/ directories aren't added by this commit, but they are
noted because I plan to add them soon.
Overview of the planned structure:
* The winsys/ API is the API that binds OpenGL to a specific window system,
be that X11 or win32 etc. Example are glx, wgl and egl. Much of the logic
under clutter/{glx,osx,win32 etc} should migrate here.
* Note there is also the idea of a winsys-base that may represent a window
system for which there are multiple winsys APIs. An example of this is
x11, since glx and egl may both be used with x11. (currently only Clutter
has the idea of a winsys-base)
* The driver/ represents a specific varient of OpenGL. Currently we have "gl"
representing OpenGL 1.4-2.1 (mostly fixed function) and "gles" representing
GLES 1.1 (fixed funciton) and 2.0 (fully shader based)
* Everything under cogl/ should fundamentally be supporting access to the
GPU. Essentially Cogl's most basic requirement is to provide a nice GPU
Graphics API and drawing a line between this and the utility functionality
we add to support Clutter should help keep this lean and maintainable.
* Code under utils/ as suggested builds on cogl/ adding more convenient
APIs or mechanism to optimize special cases. Broadly speaking you can
compare cogl/ to OpenGL and utils/ to GLU.
* clutter/pango will be moved to clutter/cogl/pango
How some of the internal configure.ac/pkg-config terminology has changed:
backendextra -> CLUTTER_WINSYS_BASE # e.g. "x11"
backendextralib -> CLUTTER_WINSYS_BASE_LIB # e.g. "x11/libclutter-x11.la"
clutterbackend -> {CLUTTER,COGL}_WINSYS # e.g. "glx"
CLUTTER_FLAVOUR -> {CLUTTER,COGL}_WINSYS
clutterbackendlib -> CLUTTER_WINSYS_LIB
CLUTTER_COGL -> COGL_DRIVER # e.g. "gl"
Note: The CLUTTER_FLAVOUR and CLUTTER_COGL defines are kept for apps
As the first thing to take advantage of the new winsys component in Cogl;
cogl_get_proc_address() has been moved from cogl/{gl,gles}/cogl.c into
cogl/common/cogl.c and this common implementation first trys
_cogl_winsys_get_proc_address() but if that fails then it falls back to
gmodule.
2009-07-28 01:02:02 +00:00
|
|
|
}
|
2008-04-25 13:37:36 +00:00
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
|
|
|
_cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
|
|
|
|
{
|
2011-12-13 13:09:34 +00:00
|
|
|
/* This function must be overridden by a platform winsys */
|
|
|
|
g_assert_not_reached ();
|
2011-02-25 11:29:08 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 16:21:28 +00:00
|
|
|
/* Updates all the function pointers */
|
|
|
|
static void
|
|
|
|
check_egl_extensions (CoglRenderer *renderer)
|
|
|
|
{
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
|
|
|
const char *egl_extensions;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
egl_extensions = eglQueryString (egl_renderer->edpy, EGL_EXTENSIONS);
|
|
|
|
|
|
|
|
COGL_NOTE (WINSYS, " EGL Extensions: %s", egl_extensions);
|
|
|
|
|
|
|
|
egl_renderer->private_features = 0;
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (winsys_feature_data); i++)
|
2011-07-27 11:30:02 +00:00
|
|
|
if (_cogl_feature_check (renderer,
|
2011-07-07 19:44:56 +00:00
|
|
|
"EGL", winsys_feature_data + i, 0, 0,
|
|
|
|
COGL_DRIVER_GL, /* the driver isn't used */
|
2011-05-24 16:21:28 +00:00
|
|
|
egl_extensions,
|
|
|
|
egl_renderer))
|
|
|
|
{
|
|
|
|
egl_renderer->private_features |=
|
2011-07-05 13:03:48 +00:00
|
|
|
winsys_feature_data[i].feature_flags_private;
|
2011-05-24 16:21:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
gboolean
|
|
|
|
_cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
|
|
|
|
|
|
|
if (!eglInitialize (egl_renderer->edpy,
|
|
|
|
&egl_renderer->egl_version_major,
|
|
|
|
&egl_renderer->egl_version_minor))
|
|
|
|
{
|
|
|
|
g_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_INIT,
|
|
|
|
"Couldn't initialize EGL");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
check_egl_extensions (renderer);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static gboolean
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_renderer_connect (CoglRenderer *renderer,
|
|
|
|
GError **error)
|
|
|
|
{
|
2011-12-13 13:09:34 +00:00
|
|
|
/* This function must be overridden by a platform winsys */
|
|
|
|
g_assert_not_reached ();
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 22:55:57 +00:00
|
|
|
static void
|
|
|
|
egl_attributes_from_framebuffer_config (CoglDisplay *display,
|
|
|
|
CoglFramebufferConfig *config,
|
|
|
|
gboolean needs_stencil_override,
|
|
|
|
EGLint *attributes)
|
|
|
|
{
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
2011-12-13 11:42:42 +00:00
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-08-22 22:55:57 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2011-12-13 11:42:42 +00:00
|
|
|
/* Let the platform add attributes first */
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->add_config_attributes)
|
2011-12-13 11:42:42 +00:00
|
|
|
i = egl_renderer->platform_vtable->add_config_attributes (display,
|
|
|
|
config,
|
|
|
|
attributes);
|
|
|
|
|
2011-08-22 22:55:57 +00:00
|
|
|
attributes[i++] = EGL_STENCIL_SIZE;
|
|
|
|
attributes[i++] = needs_stencil_override ? 2 : 0;
|
|
|
|
|
|
|
|
attributes[i++] = EGL_RED_SIZE;
|
|
|
|
attributes[i++] = 1;
|
|
|
|
attributes[i++] = EGL_GREEN_SIZE;
|
|
|
|
attributes[i++] = 1;
|
|
|
|
attributes[i++] = EGL_BLUE_SIZE;
|
|
|
|
attributes[i++] = 1;
|
|
|
|
|
|
|
|
attributes[i++] = EGL_ALPHA_SIZE;
|
|
|
|
attributes[i++] = config->swap_chain->has_alpha ? 1 : EGL_DONT_CARE;
|
|
|
|
|
|
|
|
attributes[i++] = EGL_DEPTH_SIZE;
|
|
|
|
attributes[i++] = 1;
|
|
|
|
|
|
|
|
attributes[i++] = EGL_BUFFER_SIZE;
|
|
|
|
attributes[i++] = EGL_DONT_CARE;
|
|
|
|
|
|
|
|
attributes[i++] = EGL_RENDERABLE_TYPE;
|
2011-12-08 17:38:19 +00:00
|
|
|
attributes[i++] = (renderer->driver == COGL_DRIVER_GL ?
|
2011-08-22 22:55:57 +00:00
|
|
|
EGL_OPENGL_BIT :
|
2011-12-08 17:38:19 +00:00
|
|
|
renderer->driver == COGL_DRIVER_GLES1 ?
|
2011-08-22 22:55:57 +00:00
|
|
|
EGL_OPENGL_ES_BIT :
|
|
|
|
EGL_OPENGL_ES2_BIT);
|
|
|
|
|
|
|
|
attributes[i++] = EGL_SURFACE_TYPE;
|
|
|
|
attributes[i++] = EGL_WINDOW_BIT;
|
|
|
|
|
2011-08-21 20:27:13 +00:00
|
|
|
if (config->samples_per_pixel)
|
|
|
|
{
|
|
|
|
attributes[i++] = EGL_SAMPLE_BUFFERS;
|
|
|
|
attributes[i++] = 1;
|
|
|
|
attributes[i++] = EGL_SAMPLES;
|
|
|
|
attributes[i++] = config->samples_per_pixel;
|
|
|
|
}
|
|
|
|
|
2011-08-22 22:55:57 +00:00
|
|
|
attributes[i++] = EGL_NONE;
|
|
|
|
|
|
|
|
g_assert (i < MAX_EGL_CONFIG_ATTRIBS);
|
|
|
|
}
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
static gboolean
|
|
|
|
try_create_context (CoglDisplay *display,
|
2011-08-22 22:55:57 +00:00
|
|
|
gboolean with_stencil_buffer,
|
2011-02-25 00:31:41 +00:00
|
|
|
GError **error)
|
|
|
|
{
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
2011-02-25 00:31:41 +00:00
|
|
|
CoglDisplayEGL *egl_display = display->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
EGLDisplay edpy;
|
|
|
|
EGLConfig config;
|
|
|
|
EGLint config_count = 0;
|
|
|
|
EGLBoolean status;
|
2011-07-07 19:44:56 +00:00
|
|
|
EGLint attribs[3];
|
2011-11-07 17:16:13 +00:00
|
|
|
EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS];
|
2011-02-25 00:31:41 +00:00
|
|
|
const char *error_message;
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context == NULL, TRUE);
|
2011-07-07 19:44:56 +00:00
|
|
|
|
2011-12-08 17:38:19 +00:00
|
|
|
if (renderer->driver == COGL_DRIVER_GL)
|
2011-07-07 19:44:56 +00:00
|
|
|
eglBindAPI (EGL_OPENGL_API);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
if (display->renderer->driver == COGL_DRIVER_GLES2)
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
2011-12-09 16:10:01 +00:00
|
|
|
attribs[0] = EGL_CONTEXT_CLIENT_VERSION;
|
|
|
|
attribs[1] = 2;
|
|
|
|
attribs[2] = EGL_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
attribs[0] = EGL_NONE;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
/* Divert to the platform implementation if one is defined */
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->try_create_context)
|
2011-12-09 16:10:01 +00:00
|
|
|
return egl_renderer->platform_vtable->
|
|
|
|
try_create_context (display, attribs, error);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
egl_attributes_from_framebuffer_config (display,
|
|
|
|
&display->onscreen_template->config,
|
|
|
|
with_stencil_buffer,
|
|
|
|
cfg_attribs);
|
2011-08-22 22:55:57 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
edpy = egl_renderer->edpy;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
status = eglChooseConfig (edpy,
|
|
|
|
cfg_attribs,
|
|
|
|
&config, 1,
|
|
|
|
&config_count);
|
|
|
|
if (status != EGL_TRUE || config_count == 0)
|
|
|
|
{
|
|
|
|
error_message = "Unable to find a usable EGL configuration";
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
egl_display->egl_config = config;
|
|
|
|
|
|
|
|
egl_display->egl_context = eglCreateContext (edpy,
|
|
|
|
config,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
attribs);
|
|
|
|
if (egl_display->egl_context == EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
error_message = "Unable to create a suitable EGL context";
|
|
|
|
goto fail;
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->context_created &&
|
|
|
|
!egl_renderer->platform_vtable->context_created (display, error))
|
|
|
|
return FALSE;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
2011-08-22 22:55:57 +00:00
|
|
|
g_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_CREATE_CONTEXT,
|
|
|
|
"%s", error_message);
|
|
|
|
return FALSE;
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanup_context (CoglDisplay *display)
|
|
|
|
{
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
2011-02-25 00:31:41 +00:00
|
|
|
CoglDisplayEGL *egl_display = display->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
if (egl_display->egl_context != EGL_NO_CONTEXT)
|
|
|
|
{
|
|
|
|
eglMakeCurrent (egl_renderer->edpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
eglDestroyContext (egl_renderer->edpy, egl_display->egl_context);
|
|
|
|
egl_display->egl_context = EGL_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->cleanup_context)
|
2011-12-12 15:59:35 +00:00
|
|
|
egl_renderer->platform_vtable->cleanup_context (display);
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
create_context (CoglDisplay *display, GError **error)
|
|
|
|
{
|
|
|
|
CoglDisplayEGL *egl_display = display->winsys;
|
|
|
|
|
2011-08-22 22:55:57 +00:00
|
|
|
/* Note: we don't just rely on eglChooseConfig to correctly
|
|
|
|
* report that the driver doesn't support a stencil buffer
|
|
|
|
* because we've seen PVR drivers that claim stencil buffer
|
|
|
|
* support according to the EGLConfig but then later fail
|
|
|
|
* when trying to create a context with such a config.
|
|
|
|
*/
|
|
|
|
if (try_create_context (display, TRUE, error))
|
|
|
|
{
|
|
|
|
egl_display->stencil_disabled = FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-02-25 00:31:41 +00:00
|
|
|
else
|
|
|
|
{
|
2011-05-16 15:04:33 +00:00
|
|
|
g_clear_error (error);
|
2011-02-25 00:31:41 +00:00
|
|
|
cleanup_context (display);
|
2011-08-22 22:55:57 +00:00
|
|
|
egl_display->stencil_disabled = TRUE;
|
|
|
|
return try_create_context (display, FALSE, error);
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
|
|
|
_cogl_winsys_display_destroy (CoglDisplay *display)
|
|
|
|
{
|
2011-12-09 16:10:01 +00:00
|
|
|
CoglRendererEGL *egl_renderer = display->renderer->winsys;
|
2011-02-25 11:29:08 +00:00
|
|
|
CoglDisplayEGL *egl_display = display->winsys;
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (egl_display != NULL);
|
2011-02-25 11:29:08 +00:00
|
|
|
|
|
|
|
cleanup_context (display);
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->display_destroy)
|
2011-12-09 16:10:01 +00:00
|
|
|
egl_renderer->platform_vtable->display_destroy (display);
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
g_slice_free (CoglDisplayEGL, display->winsys);
|
|
|
|
display->winsys = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_display_setup (CoglDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglDisplayEGL *egl_display;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (display->winsys == NULL, FALSE);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
egl_display = g_slice_new0 (CoglDisplayEGL);
|
|
|
|
display->winsys = egl_display;
|
|
|
|
|
2011-05-25 00:37:56 +00:00
|
|
|
#ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT
|
2011-12-12 17:31:27 +00:00
|
|
|
if (display->wayland_compositor_display)
|
2011-05-25 00:37:56 +00:00
|
|
|
{
|
|
|
|
struct wl_display *wayland_display = display->wayland_compositor_display;
|
2011-12-12 17:31:27 +00:00
|
|
|
CoglRendererEGL *egl_renderer = display->renderer->winsys;
|
|
|
|
|
2011-05-25 00:37:56 +00:00
|
|
|
egl_renderer->pf_eglBindWaylandDisplay (egl_renderer->edpy,
|
|
|
|
wayland_display);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->display_setup &&
|
2011-12-09 16:10:01 +00:00
|
|
|
!egl_renderer->platform_vtable->display_setup (display, error))
|
2011-11-07 17:16:13 +00:00
|
|
|
goto error;
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
if (!create_context (display, error))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
egl_display->found_egl_config = TRUE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
_cogl_winsys_display_destroy (display);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static gboolean
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_context_init (CoglContext *context, GError **error)
|
|
|
|
{
|
2011-12-12 15:59:35 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglDisplayEGL *egl_display = context->display->winsys;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
context->winsys = g_new0 (CoglContextEGL, 1);
|
|
|
|
|
2011-12-12 15:59:35 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE);
|
|
|
|
|
|
|
|
memset (context->winsys_features, 0, sizeof (context->winsys_features));
|
|
|
|
|
|
|
|
check_egl_extensions (renderer);
|
|
|
|
|
|
|
|
if (!_cogl_context_update_features (context, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (egl_renderer->private_features & COGL_EGL_WINSYS_FEATURE_SWAP_REGION)
|
|
|
|
{
|
|
|
|
COGL_FLAGS_SET (context->winsys_features,
|
|
|
|
COGL_WINSYS_FEATURE_SWAP_REGION, TRUE);
|
|
|
|
COGL_FLAGS_SET (context->winsys_features,
|
|
|
|
COGL_WINSYS_FEATURE_SWAP_REGION_THROTTLE, TRUE);
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->context_init &&
|
2011-12-12 15:59:35 +00:00
|
|
|
!egl_renderer->platform_vtable->context_init (context, error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_context_deinit (CoglContext *context)
|
|
|
|
{
|
2011-12-12 15:59:35 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->context_deinit)
|
2011-12-12 15:59:35 +00:00
|
|
|
egl_renderer->platform_vtable->context_deinit (context);
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
g_free (context->winsys);
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static gboolean
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *context = framebuffer->context;
|
|
|
|
CoglDisplay *display = context->display;
|
|
|
|
CoglDisplayEGL *egl_display = display->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-08-22 22:55:57 +00:00
|
|
|
EGLint attributes[MAX_EGL_CONFIG_ATTRIBS];
|
|
|
|
EGLConfig egl_config;
|
|
|
|
EGLint config_count = 0;
|
|
|
|
EGLBoolean status;
|
|
|
|
gboolean need_stencil =
|
|
|
|
egl_display->stencil_disabled ? FALSE : framebuffer->config.need_stencil;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context, FALSE);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
egl_attributes_from_framebuffer_config (display,
|
|
|
|
&framebuffer->config,
|
|
|
|
need_stencil,
|
|
|
|
attributes);
|
|
|
|
|
|
|
|
status = eglChooseConfig (egl_renderer->edpy,
|
|
|
|
attributes,
|
|
|
|
&egl_config, 1,
|
|
|
|
&config_count);
|
|
|
|
if (status != EGL_TRUE || config_count == 0)
|
2011-08-22 22:55:57 +00:00
|
|
|
{
|
2011-12-09 16:10:01 +00:00
|
|
|
g_set_error (error, COGL_WINSYS_ERROR,
|
|
|
|
COGL_WINSYS_ERROR_CREATE_ONSCREEN,
|
|
|
|
"Failed to find a suitable EGL configuration");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-12-08 17:38:19 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
/* Update the real number of samples_per_pixel now that we have
|
|
|
|
* found an egl_config... */
|
|
|
|
if (framebuffer->config.samples_per_pixel)
|
|
|
|
{
|
|
|
|
EGLint samples;
|
|
|
|
status = eglGetConfigAttrib (egl_renderer->edpy,
|
|
|
|
egl_config,
|
|
|
|
EGL_SAMPLES, &samples);
|
|
|
|
g_return_val_if_fail (status == EGL_TRUE, TRUE);
|
|
|
|
framebuffer->samples_per_pixel = samples;
|
2011-08-22 22:55:57 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 17:38:19 +00:00
|
|
|
onscreen->winsys = g_slice_new0 (CoglOnscreenEGL);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->onscreen_init &&
|
|
|
|
!egl_renderer->platform_vtable->onscreen_init (onscreen,
|
|
|
|
egl_config,
|
|
|
|
error))
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
2011-12-13 13:09:34 +00:00
|
|
|
g_slice_free (CoglOnscreenEGL, onscreen->winsys);
|
|
|
|
return FALSE;
|
2011-12-08 17:38:19 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
CoglContext *context = framebuffer->context;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
|
|
|
|
|
2011-05-10 19:23:39 +00:00
|
|
|
/* If we never successfully allocated then there's nothing to do */
|
|
|
|
if (egl_onscreen == NULL)
|
|
|
|
return;
|
2011-12-09 16:10:01 +00:00
|
|
|
if (egl_onscreen->egl_surface != EGL_NO_SURFACE)
|
2011-02-25 00:31:41 +00:00
|
|
|
{
|
|
|
|
if (eglDestroySurface (egl_renderer->edpy, egl_onscreen->egl_surface)
|
|
|
|
== EGL_FALSE)
|
|
|
|
g_warning ("Failed to destroy EGL surface");
|
|
|
|
egl_onscreen->egl_surface = EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
|
2011-12-13 13:09:34 +00:00
|
|
|
if (egl_renderer->platform_vtable->onscreen_deinit)
|
2011-12-12 15:59:35 +00:00
|
|
|
egl_renderer->platform_vtable->onscreen_deinit (onscreen);
|
2011-02-25 00:31:41 +00:00
|
|
|
|
2011-05-10 19:23:39 +00:00
|
|
|
g_slice_free (CoglOnscreenEGL, onscreen->winsys);
|
|
|
|
onscreen->winsys = NULL;
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
|
|
|
CoglDisplayEGL *egl_display = context->display->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-12-12 15:59:35 +00:00
|
|
|
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
|
|
|
|
CoglContextEGL *egl_context = context->winsys;
|
2011-11-07 17:16:13 +00:00
|
|
|
|
2011-12-12 15:59:35 +00:00
|
|
|
if (egl_context->current_surface == egl_onscreen->egl_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
eglMakeCurrent (egl_renderer->edpy,
|
|
|
|
egl_onscreen->egl_surface,
|
|
|
|
egl_onscreen->egl_surface,
|
|
|
|
egl_display->egl_context);
|
|
|
|
egl_context->current_surface = egl_onscreen->egl_surface;
|
|
|
|
|
|
|
|
if (onscreen->swap_throttled)
|
|
|
|
eglSwapInterval (egl_renderer->edpy, 1);
|
|
|
|
else
|
|
|
|
eglSwapInterval (egl_renderer->edpy, 0);
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
|
2011-07-22 11:23:40 +00:00
|
|
|
const int *user_rectangles,
|
2011-02-25 00:31:41 +00:00
|
|
|
int n_rectangles)
|
|
|
|
{
|
|
|
|
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
|
2011-07-22 11:23:40 +00:00
|
|
|
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
|
|
|
|
int framebuffer_height = cogl_framebuffer_get_height (framebuffer);
|
|
|
|
int *rectangles = g_alloca (sizeof (int) * n_rectangles * 4);
|
|
|
|
int i;
|
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
/* eglSwapBuffersRegion expects rectangles relative to the
|
|
|
|
* bottom left corner but we are given rectangles relative to
|
|
|
|
* the top left so we need to flip them... */
|
|
|
|
memcpy (rectangles, user_rectangles, sizeof (int) * n_rectangles * 4);
|
|
|
|
for (i = 0; i < n_rectangles; i++)
|
2011-07-22 11:23:40 +00:00
|
|
|
{
|
2011-12-09 16:10:01 +00:00
|
|
|
int *rect = &rectangles[4 * i];
|
|
|
|
rect[1] = framebuffer_height - rect[1] - rect[3];
|
2011-12-08 17:38:19 +00:00
|
|
|
}
|
2011-12-09 16:10:01 +00:00
|
|
|
|
|
|
|
/* At least for eglSwapBuffers the EGL spec says that the surface to
|
|
|
|
swap must be bound to the current context. It looks like Mesa
|
|
|
|
also validates that this is the case for eglSwapBuffersRegion so
|
|
|
|
we must bind here too */
|
|
|
|
_cogl_framebuffer_flush_state (COGL_FRAMEBUFFER (onscreen),
|
|
|
|
COGL_FRAMEBUFFER (onscreen),
|
|
|
|
COGL_FRAMEBUFFER_STATE_BIND);
|
|
|
|
|
|
|
|
if (egl_renderer->pf_eglSwapBuffersRegion (egl_renderer->edpy,
|
|
|
|
egl_onscreen->egl_surface,
|
|
|
|
n_rectangles,
|
|
|
|
rectangles) == EGL_FALSE)
|
|
|
|
g_warning ("Error reported by eglSwapBuffersRegion");
|
2011-02-25 00:31:41 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
2011-12-08 17:38:19 +00:00
|
|
|
CoglRenderer *renderer = context->display->renderer;
|
|
|
|
CoglRendererEGL *egl_renderer = renderer->winsys;
|
2011-02-25 00:31:41 +00:00
|
|
|
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
|
2011-12-05 15:55:12 +00:00
|
|
|
/* The specification for EGL (at least in 1.4) says that the surface
|
|
|
|
needs to be bound to the current context for the swap to work
|
|
|
|
although it may change in future. Mesa explicitly checks for this
|
|
|
|
and just returns an error if this is not the case so we can't
|
|
|
|
just pretend this isn't in the spec. */
|
|
|
|
_cogl_framebuffer_flush_state (COGL_FRAMEBUFFER (onscreen),
|
|
|
|
COGL_FRAMEBUFFER (onscreen),
|
|
|
|
COGL_FRAMEBUFFER_STATE_BIND);
|
|
|
|
|
2011-02-25 00:31:41 +00:00
|
|
|
eglSwapBuffers (egl_renderer->edpy, egl_onscreen->egl_surface);
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static void
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_onscreen_update_swap_throttled (CoglOnscreen *onscreen)
|
|
|
|
{
|
|
|
|
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
|
2011-12-09 16:10:01 +00:00
|
|
|
CoglContextEGL *egl_context = context->winsys;
|
|
|
|
CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
|
2011-12-08 17:38:19 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
if (egl_context->current_surface != egl_onscreen->egl_surface)
|
|
|
|
return;
|
2011-12-08 17:38:19 +00:00
|
|
|
|
2011-12-09 16:10:01 +00:00
|
|
|
egl_context->current_surface = EGL_NO_SURFACE;
|
2011-02-25 00:31:41 +00:00
|
|
|
|
|
|
|
_cogl_winsys_onscreen_bind (onscreen);
|
|
|
|
}
|
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static EGLDisplay
|
2011-02-25 00:31:41 +00:00
|
|
|
_cogl_winsys_context_egl_get_egl_display (CoglContext *context)
|
|
|
|
{
|
|
|
|
CoglRendererEGL *egl_renderer = context->display->renderer->winsys;
|
|
|
|
|
|
|
|
return egl_renderer->edpy;
|
|
|
|
}
|
2011-03-01 14:43:43 +00:00
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
static CoglWinsysVtable _cogl_winsys_vtable =
|
|
|
|
{
|
2011-12-13 18:57:53 +00:00
|
|
|
.criteria = COGL_WINSYS_CRITERIA_USES_EGL,
|
|
|
|
|
2011-12-08 17:24:40 +00:00
|
|
|
/* This winsys is only used as a base for the EGL-platform
|
|
|
|
winsys's so it does not have an ID or a name */
|
|
|
|
|
2011-07-27 11:30:02 +00:00
|
|
|
.renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address,
|
2011-02-25 11:29:08 +00:00
|
|
|
.renderer_connect = _cogl_winsys_renderer_connect,
|
|
|
|
.renderer_disconnect = _cogl_winsys_renderer_disconnect,
|
|
|
|
.display_setup = _cogl_winsys_display_setup,
|
|
|
|
.display_destroy = _cogl_winsys_display_destroy,
|
|
|
|
.context_init = _cogl_winsys_context_init,
|
|
|
|
.context_deinit = _cogl_winsys_context_deinit,
|
|
|
|
.context_egl_get_egl_display =
|
|
|
|
_cogl_winsys_context_egl_get_egl_display,
|
|
|
|
.onscreen_init = _cogl_winsys_onscreen_init,
|
|
|
|
.onscreen_deinit = _cogl_winsys_onscreen_deinit,
|
|
|
|
.onscreen_bind = _cogl_winsys_onscreen_bind,
|
|
|
|
.onscreen_swap_buffers = _cogl_winsys_onscreen_swap_buffers,
|
|
|
|
.onscreen_swap_region = _cogl_winsys_onscreen_swap_region,
|
|
|
|
.onscreen_update_swap_throttled =
|
|
|
|
_cogl_winsys_onscreen_update_swap_throttled,
|
|
|
|
};
|
2011-03-01 14:43:43 +00:00
|
|
|
|
2011-02-25 11:29:08 +00:00
|
|
|
/* XXX: we use a function because no doubt someone will complain
|
|
|
|
* about using c99 member initializers because they aren't portable
|
|
|
|
* to windows. We want to avoid having to rigidly follow the real
|
|
|
|
* order of members since some members are #ifdefd and we'd have
|
|
|
|
* to mirror the #ifdefing to add padding etc. For any winsys that
|
|
|
|
* can assume the platform has a sane compiler then we can just use
|
|
|
|
* c99 initializers for insane platforms they can initialize
|
|
|
|
* the members by name in a function.
|
|
|
|
*/
|
|
|
|
const CoglWinsysVtable *
|
|
|
|
_cogl_winsys_egl_get_vtable (void)
|
2011-03-01 14:43:43 +00:00
|
|
|
{
|
2011-02-25 11:29:08 +00:00
|
|
|
return &_cogl_winsys_vtable;
|
2011-03-01 14:43:43 +00:00
|
|
|
}
|
2011-05-11 13:07:02 +00:00
|
|
|
|
2011-05-24 21:34:10 +00:00
|
|
|
#ifdef EGL_KHR_image_base
|
|
|
|
EGLImageKHR
|
|
|
|
_cogl_egl_create_image (CoglContext *ctx,
|
|
|
|
EGLenum target,
|
|
|
|
EGLClientBuffer buffer,
|
|
|
|
const EGLint *attribs)
|
|
|
|
{
|
|
|
|
CoglDisplayEGL *egl_display = ctx->display->winsys;
|
|
|
|
CoglRendererEGL *egl_renderer = ctx->display->renderer->winsys;
|
2011-07-20 23:52:07 +00:00
|
|
|
EGLContext egl_ctx;
|
2011-05-24 21:34:10 +00:00
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (egl_renderer->pf_eglCreateImage, EGL_NO_IMAGE_KHR);
|
2011-05-24 21:34:10 +00:00
|
|
|
|
2011-07-20 23:52:07 +00:00
|
|
|
/* The EGL_KHR_image_pixmap spec explicitly states that EGL_NO_CONTEXT must
|
|
|
|
* always be used in conjunction with the EGL_NATIVE_PIXMAP_KHR target */
|
|
|
|
#ifdef EGL_KHR_image_pixmap
|
|
|
|
if (target == EGL_NATIVE_PIXMAP_KHR)
|
|
|
|
egl_ctx = EGL_NO_CONTEXT;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
egl_ctx = egl_display->egl_context;
|
|
|
|
|
2011-05-24 21:34:10 +00:00
|
|
|
return egl_renderer->pf_eglCreateImage (egl_renderer->edpy,
|
2011-07-20 23:52:07 +00:00
|
|
|
egl_ctx,
|
2011-05-24 21:34:10 +00:00
|
|
|
target,
|
|
|
|
buffer,
|
|
|
|
attribs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_egl_destroy_image (CoglContext *ctx,
|
|
|
|
EGLImageKHR image)
|
|
|
|
{
|
|
|
|
CoglRendererEGL *egl_renderer = ctx->display->renderer->winsys;
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (egl_renderer->pf_eglDestroyImage);
|
2011-05-24 21:34:10 +00:00
|
|
|
|
|
|
|
egl_renderer->pf_eglDestroyImage (egl_renderer->edpy, image);
|
|
|
|
}
|
|
|
|
#endif
|