Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Unified Diff: src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp

Issue 1410593002: Use common display initialization logic for Unix (Closed) Base URL: https://skia.googlesource.com/skia.git@vbnvpr
Patch Set: minor tidy Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
diff --git a/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
index 8c58a53702b44dd4dfd05be8790afe344d4aedab..dc1c135bdffb6ad666dc9926a916b678b3b33915 100644
--- a/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
+++ b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
@@ -11,6 +11,8 @@
#include <GL/glx.h>
#include <GL/glu.h>
+#include "GrNativeDisplay_glx.h"
+
namespace {
/* Note: Skia requires glx 1.3 or newer */
@@ -67,7 +69,6 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
, fDisplay(nullptr)
, fPixmap(0)
, fGlxPixmap(0) {
-
fDisplay = XOpenDisplay(0);
if (!fDisplay) {
@@ -83,56 +84,14 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
None
};
- int glx_major, glx_minor;
-
- // FBConfigs were added in GLX version 1.3.
- if (!glXQueryVersion(fDisplay, &glx_major, &glx_minor) ||
- ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) {
- SkDebugf("GLX version 1.3 or higher required.\n");
+ GLXFBConfig bestFbConfig;
+ if (!GrNativeDisplay::Initialize(visual_attribs, fDisplay, &bestFbConfig)) {
this->destroyGLContext();
return;
}
- //SkDebugf("Getting matching framebuffer configs.\n");
- int fbcount;
- GLXFBConfig *fbc = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay),
- visual_attribs, &fbcount);
- if (!fbc) {
- SkDebugf("Failed to retrieve a framebuffer config.\n");
- this->destroyGLContext();
- return;
- }
- //SkDebugf("Found %d matching FB configs.\n", fbcount);
-
- // Pick the FB config/visual with the most samples per pixel
- //SkDebugf("Getting XVisualInfos.\n");
- int best_fbc = -1, best_num_samp = -1;
-
- int i;
- for (i = 0; i < fbcount; ++i) {
- XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, fbc[i]);
- if (vi) {
- int samp_buf, samples;
- glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf);
- glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLES, &samples);
-
- //SkDebugf(" Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d,"
- // " SAMPLES = %d\n",
- // i, (unsigned int)vi->visualid, samp_buf, samples);
-
- if (best_fbc < 0 || (samp_buf && samples > best_num_samp))
- best_fbc = i, best_num_samp = samples;
- }
- XFree(vi);
- }
-
- GLXFBConfig bestFbc = fbc[best_fbc];
-
- // Be sure to free the FBConfig list allocated by glXChooseFBConfig()
- XFree(fbc);
-
// Get a visual
- XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, bestFbc);
+ XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, bestFbConfig);
//SkDebugf("Chosen visual ID = 0x%x\n", (unsigned int)vi->visualid);
fPixmap = XCreatePixmap(fDisplay, RootWindow(fDisplay, vi->screen), 10, 10, vi->depth);
@@ -158,13 +117,10 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
// error handler, so be sure to guard against other threads issuing
// X commands while this code is running.
ctxErrorOccurred = false;
- int (*oldHandler)(Display*, XErrorEvent*) =
- XSetErrorHandler(&ctxErrorHandler);
+ int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler);
// Get the default screen's GLX extension list
- const char *glxExts = glXQueryExtensionsString(
- fDisplay, DefaultScreen(fDisplay)
- );
+ const char *glxExts = glXQueryExtensionsString(fDisplay, DefaultScreen(fDisplay));
// Check for the GLX_ARB_create_context extension string and the function.
@@ -172,7 +128,7 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_context"),
reinterpret_cast<const GLubyte*>(glxExts))) {
if (kGLES_GrGLStandard != forcedGpuAPI) {
- fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
+ fContext = glXCreateNewContext(fDisplay, bestFbConfig, GLX_RGBA_TYPE, 0, True);
}
} else {
//SkDebugf("Creating context.\n");
@@ -189,13 +145,13 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
None
};
- fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
+ fContext = glXCreateContextAttribsARB(fDisplay, bestFbConfig, 0, True,
context_attribs_gles);
}
} else {
// Well, unfortunately GLX will not just give us the highest context so instead we have
// to do this nastiness
- for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) {
+ for (int i = NUM_GL_VERSIONS - 2; i > 0 ; i--) {
/* don't bother below GL 3.0 */
if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) {
break;
@@ -211,7 +167,8 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
None
};
fContext =
- glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, context_attribs_gl);
+ glXCreateContextAttribsARB(fDisplay, bestFbConfig, 0, True,
+ context_attribs_gl);
// Sync to ensure any errors generated are processed.
XSync(fDisplay, False);
@@ -237,7 +194,7 @@ GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI)
ctxErrorOccurred = false;
- fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
+ fContext = glXCreateContextAttribsARB(fDisplay, bestFbConfig, 0, True,
context_attribs_gl_fallback);
}
}

Powered by Google App Engine
This is Rietveld 408576698