aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Barker <jesse.barker@linaro.org>2012-11-13 08:56:32 -0800
committerJesse Barker <jesse.barker@linaro.org>2012-11-13 08:56:32 -0800
commitce690269c4e456a618b388d4c18a8462d8bae2ee (patch)
tree9b40ec0e5c003d9a96f697f29b8fc606f7b246d8
parent9fd15b13acef0cf8a5ff45bd1470a6b1a56e0846 (diff)
downloadglmark2-ce690269c4e456a618b388d4c18a8462d8bae2ee.tar.gz
CanvasX11{EGL,GLX}: Integrate new EGLState object. This requires a small bit
of new plumbing so that there is an explicit acknowledgement of the window system integration layer (::init_gl_winsys()). Additional canvas objects that do not integrate through X11 will not need this as there won't be the added legacy of GLX.
-rw-r--r--src/canvas-x11-egl.cpp264
-rw-r--r--src/canvas-x11-egl.h25
-rw-r--r--src/canvas-x11-glx.h1
-rw-r--r--src/canvas-x11.cpp3
-rw-r--r--src/canvas-x11.h9
5 files changed, 40 insertions, 262 deletions
diff --git a/src/canvas-x11-egl.cpp b/src/canvas-x11-egl.cpp
index 3f23fc8..0844b74 100644
--- a/src/canvas-x11-egl.cpp
+++ b/src/canvas-x11-egl.cpp
@@ -31,6 +31,14 @@
* Protected methods *
*********************/
+bool
+CanvasX11EGL::init_gl_winsys()
+{
+ egl_.init_display(reinterpret_cast<EGLNativeDisplayType>(xdpy_),
+ visual_config_);
+ return true;
+}
+
XVisualInfo *
CanvasX11EGL::get_xvisualinfo()
{
@@ -39,14 +47,9 @@ CanvasX11EGL::get_xvisualinfo()
int num_visuals;
EGLint vid;
- if (!ensure_egl_config())
- return 0;
-
- if (!eglGetConfigAttrib(egl_display_, egl_config_,
- EGL_NATIVE_VISUAL_ID, &vid))
+ if (!egl_.gotNativeConfig(vid))
{
- Log::error("eglGetConfigAttrib() failed with error: %d\n",
- eglGetError());
+ Log::error("Failed to get a native-renderable EGLConfig\n");
return 0;
}
@@ -65,35 +68,27 @@ CanvasX11EGL::get_xvisualinfo()
bool
CanvasX11EGL::make_current()
{
- if (!ensure_egl_surface())
- return false;
-
- if (!ensure_egl_context())
- return false;
-
- if (egl_context_ == eglGetCurrentContext())
- return true;
-
- if (!eglMakeCurrent(egl_display_, egl_surface_, egl_surface_, egl_context_)) {
- Log::error("Error: eglMakeCurrent failed with error %d\n", eglGetError());
+ egl_.init_surface(reinterpret_cast<EGLNativeWindowType>(xwin_));
+ if (!egl_.valid()) {
+ Log::error("CanvasX11EGL: Invalid EGL state\n");
return false;
}
- if (!eglSwapInterval(egl_display_, 0))
- Log::info("** Failed to set swap interval. Results may be bounded above by refresh rate.\n");
-
init_gl_extensions();
return true;
}
void
-CanvasX11EGL::get_glvisualconfig(GLVisualConfig &visual_config)
+CanvasX11EGL::swap_buffers()
{
- if (!ensure_egl_config())
- return;
+ egl_.swap();
+}
- get_glvisualconfig_egl(egl_config_, visual_config);
+void
+CanvasX11EGL::get_glvisualconfig(GLVisualConfig &visual_config)
+{
+ egl_.getVisualConfig(visual_config);
}
/*******************
@@ -101,184 +96,9 @@ CanvasX11EGL::get_glvisualconfig(GLVisualConfig &visual_config)
*******************/
bool
-CanvasX11EGL::ensure_egl_display()
-{
- if (egl_display_)
- return true;
-
- egl_display_ = eglGetDisplay((EGLNativeDisplayType) xdpy_);
- if (!egl_display_) {
- Log::error("eglGetDisplay() failed with error: %d\n",
- eglGetError());
- return false;
- }
- if (!eglInitialize(egl_display_, NULL, NULL)) {
- Log::error("eglInitialize() failed with error: %d\n",
- eglGetError());
- return false;
- egl_display_ = 0;
- }
-
- return true;
-}
-
-bool
-CanvasX11EGL::ensure_egl_config()
-{
- const EGLint attribs[] = {
- EGL_RED_SIZE, visual_config_.red,
- EGL_GREEN_SIZE, visual_config_.green,
- EGL_BLUE_SIZE, visual_config_.blue,
- EGL_ALPHA_SIZE, visual_config_.alpha,
- EGL_DEPTH_SIZE, visual_config_.depth,
- EGL_BUFFER_SIZE, visual_config_.buffer,
-#ifdef USE_GLESv2
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-#elif USE_GL
- EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
-#endif
- EGL_NONE
- };
- EGLint num_configs;
- EGLint vid;
-
- if (egl_config_)
- return true;
-
- if (!ensure_egl_display())
- return false;
-
- /* Find out how many configs match the attributes */
- if (!eglChooseConfig(egl_display_, attribs, 0, 0, &num_configs)) {
- Log::error("eglChooseConfig() (explore) failed with error: %d\n",
- eglGetError());
- return false;
- }
-
- if (num_configs == 0) {
- Log::error("eglChooseConfig() didn't return any configs\n");
- return false;
- }
-
- /* Get all the matching configs */
- std::vector<EGLConfig> configs(num_configs);
-
- if (!eglChooseConfig(egl_display_, attribs, &(configs[0]),
- num_configs, &num_configs))
- {
- Log::error("eglChooseConfig() failed with error: %d\n",
- eglGetError());
- return false;
- }
-
- /* Select the best matching config */
- egl_config_ = select_best_config(configs);
-
- if (!eglGetConfigAttrib(egl_display_, egl_config_,
- EGL_NATIVE_VISUAL_ID, &vid))
- {
- Log::error("eglGetConfigAttrib() failed with error: %d\n",
- eglGetError());
- return false;
- }
-
- if (Options::show_debug) {
- int buf, red, green, blue, alpha, depth, id, native_id;
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_CONFIG_ID, &id);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_NATIVE_VISUAL_ID, &native_id);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_BUFFER_SIZE, &buf);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_RED_SIZE, &red);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_GREEN_SIZE, &green);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_BLUE_SIZE, &blue);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_ALPHA_SIZE, &alpha);
- eglGetConfigAttrib(egl_display_, egl_config_, EGL_DEPTH_SIZE, &depth);
- Log::debug("EGL chosen config ID: 0x%x Native Visual ID: 0x%x\n"
- " Buffer: %d bits\n"
- " Red: %d bits\n"
- " Green: %d bits\n"
- " Blue: %d bits\n"
- " Alpha: %d bits\n"
- " Depth: %d bits\n",
- id, native_id,
- buf, red, green, blue, alpha, depth);
- }
-
- return true;
-}
-
-bool
CanvasX11EGL::reset_context()
{
- if (!ensure_egl_display())
- return false;
-
- if (!egl_context_)
- return true;
-
- if (eglDestroyContext(egl_display_, egl_context_) == EGL_FALSE) {
- Log::debug("eglDestroyContext() failed with error: 0x%x\n",
- eglGetError());
- }
-
- egl_context_ = 0;
- return true;
-}
-
-bool
-CanvasX11EGL::ensure_egl_context()
-{
- if (egl_context_)
- return true;
-
- if (!ensure_egl_display())
- return false;
-
- if (!ensure_egl_config())
- return false;
-
- static const EGLint ctx_attribs[] = {
-#ifdef USE_GLESv2
- EGL_CONTEXT_CLIENT_VERSION, 2,
-#endif
- EGL_NONE
- };
-
- egl_context_ = eglCreateContext(egl_display_, egl_config_,
- EGL_NO_CONTEXT, ctx_attribs);
- if (!egl_context_) {
- Log::error("eglCreateContext() failed with error: 0x%x\n",
- eglGetError());
- return false;
- }
-
- return true;
-}
-
-bool
-CanvasX11EGL::ensure_egl_surface()
-{
- if (egl_surface_)
- return true;
-
- if (!ensure_egl_display())
- return false;
-
-#ifdef USE_GLESv2
- eglBindAPI(EGL_OPENGL_ES_API);
-#elif USE_GL
- eglBindAPI(EGL_OPENGL_API);
-#endif
-
- egl_surface_ = eglCreateWindowSurface(egl_display_, egl_config_,
- (EGLNativeWindowType) xwin_,
- NULL);
- if (!egl_surface_) {
- Log::error("eglCreateWindowSurface failed with error: %d\n",
- eglGetError());
- return false;
- }
-
- return true;
+ return egl_.reset();
}
void
@@ -296,45 +116,3 @@ CanvasX11EGL::init_gl_extensions()
GLExtensions::UnmapBuffer = glUnmapBuffer;
#endif
}
-
-void
-CanvasX11EGL::get_glvisualconfig_egl(EGLConfig config, GLVisualConfig &visual_config)
-{
- eglGetConfigAttrib(egl_display_, config, EGL_BUFFER_SIZE, &visual_config.buffer);
- eglGetConfigAttrib(egl_display_, config, EGL_RED_SIZE, &visual_config.red);
- eglGetConfigAttrib(egl_display_, config, EGL_GREEN_SIZE, &visual_config.green);
- eglGetConfigAttrib(egl_display_, config, EGL_BLUE_SIZE, &visual_config.blue);
- eglGetConfigAttrib(egl_display_, config, EGL_ALPHA_SIZE, &visual_config.alpha);
- eglGetConfigAttrib(egl_display_, config, EGL_DEPTH_SIZE, &visual_config.depth);
-}
-
-EGLConfig
-CanvasX11EGL::select_best_config(std::vector<EGLConfig> configs)
-{
- int best_score(INT_MIN);
- EGLConfig best_config(0);
-
- /*
- * Go through all the configs and choose the one with the best score,
- * i.e., the one better matching the requested config.
- */
- for (std::vector<EGLConfig>::const_iterator iter = configs.begin();
- iter != configs.end();
- iter++)
- {
- const EGLConfig config(*iter);
- GLVisualConfig vc;
- int score;
-
- get_glvisualconfig_egl(config, vc);
-
- score = vc.match_score(visual_config_);
-
- if (score > best_score) {
- best_score = score;
- best_config = config;
- }
- }
-
- return best_config;
-}
diff --git a/src/canvas-x11-egl.h b/src/canvas-x11-egl.h
index d1ebf5f..d5f581c 100644
--- a/src/canvas-x11-egl.h
+++ b/src/canvas-x11-egl.h
@@ -18,14 +18,13 @@
*
* Authors:
* Alexandros Frantzis (glmark2)
+ * Jesse Barker
*/
#ifndef GLMARK2_CANVAS_X11_EGL_H_
#define GLMARK2_CANVAS_X11_EGL_H_
#include "canvas-x11.h"
-
-#include <EGL/egl.h>
-#include <vector>
+#include "egl-state.h"
/**
* Canvas for rendering to an X11 window using EGL.
@@ -34,32 +33,20 @@ class CanvasX11EGL : public CanvasX11
{
public:
CanvasX11EGL(int width, int height) :
- CanvasX11(width, height), egl_display_(EGL_NO_DISPLAY),
- egl_surface_(EGL_NO_SURFACE), egl_config_(0),
- egl_context_(EGL_NO_CONTEXT) {}
+ CanvasX11(width, height) {}
~CanvasX11EGL() {}
protected:
XVisualInfo *get_xvisualinfo();
bool make_current();
bool reset_context();
- void swap_buffers() { eglSwapBuffers(egl_display_, egl_surface_); }
+ void swap_buffers();
void get_glvisualconfig(GLVisualConfig &visual_config);
+ bool init_gl_winsys();
private:
- bool ensure_egl_display();
- bool ensure_egl_config();
- bool ensure_egl_context();
- bool ensure_egl_surface();
void init_gl_extensions();
- void get_glvisualconfig_egl(EGLConfig config, GLVisualConfig &visual_config);
- EGLConfig select_best_config(std::vector<EGLConfig> configs);
-
- EGLDisplay egl_display_;
- EGLSurface egl_surface_;
- EGLConfig egl_config_;
- EGLContext egl_context_;
+ EGLState egl_;
};
#endif
-
diff --git a/src/canvas-x11-glx.h b/src/canvas-x11-glx.h
index 8eb3f93..f787087 100644
--- a/src/canvas-x11-glx.h
+++ b/src/canvas-x11-glx.h
@@ -45,6 +45,7 @@ protected:
bool reset_context();
void swap_buffers() { glXSwapBuffers(xdpy_, xwin_); }
void get_glvisualconfig(GLVisualConfig &visual_config);
+ bool init_gl_winsys() { return true; }
private:
bool check_glx_version();
diff --git a/src/canvas-x11.cpp b/src/canvas-x11.cpp
index 29d7ce6..c1b19c0 100644
--- a/src/canvas-x11.cpp
+++ b/src/canvas-x11.cpp
@@ -70,6 +70,9 @@ CanvasX11::init()
if (!xdpy_)
return false;
+ if (!init_gl_winsys())
+ return false;
+
resize_no_viewport(width_, height_);
if (!xwin_)
diff --git a/src/canvas-x11.h b/src/canvas-x11.h
index 4bf26bd..7b3b456 100644
--- a/src/canvas-x11.h
+++ b/src/canvas-x11.h
@@ -64,6 +64,15 @@ protected:
virtual XVisualInfo *get_xvisualinfo() = 0;
/**
+ * Initializes window system interfaces for GL rendering.
+ *
+ * This method should be implemented in derived classes.
+ *
+ * @return whether the operation succeeded
+ */
+ virtual bool init_gl_winsys() = 0;
+
+ /**
* Makes the canvas the current target for GL rendering.
*
* This method should be implemented in derived classes.