bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 8 | #include "gl/SkGLContext.h" |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 9 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 10 | #include <X11/Xlib.h> |
| 11 | #include <GL/glx.h> |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 12 | #include <GL/glu.h> |
| 13 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 14 | namespace { |
| 15 | |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 16 | /* Note: Skia requires glx 1.3 or newer */ |
robertphillips@google.com | bb89cda | 2012-03-14 18:06:26 +0000 | [diff] [blame] | 17 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 18 | /* This struct is taken from a mesa demo. Please update as required */ |
| 19 | static const struct { int major, minor; } gl_versions[] = { |
| 20 | {1, 0}, |
| 21 | {1, 1}, |
| 22 | {1, 2}, |
| 23 | {1, 3}, |
| 24 | {1, 4}, |
| 25 | {1, 5}, |
| 26 | {2, 0}, |
| 27 | {2, 1}, |
| 28 | {3, 0}, |
| 29 | {3, 1}, |
| 30 | {3, 2}, |
| 31 | {3, 3}, |
| 32 | {4, 0}, |
| 33 | {4, 1}, |
| 34 | {4, 2}, |
| 35 | {4, 3}, |
| 36 | {4, 4}, |
| 37 | {0, 0} /* end of list */ |
| 38 | }; |
| 39 | #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions) |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 40 | |
| 41 | static bool ctxErrorOccurred = false; |
| 42 | static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) { |
| 43 | ctxErrorOccurred = true; |
| 44 | return 0; |
| 45 | } |
| 46 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 47 | class GLXGLContext : public SkGLContext { |
| 48 | public: |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 49 | GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareList); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 50 | ~GLXGLContext() override; |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 53 | void destroyGLContext(); |
| 54 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 55 | void onPlatformMakeCurrent() const override; |
| 56 | void onPlatformSwapBuffers() const override; |
| 57 | GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
| 58 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 59 | GLXContext fContext; |
| 60 | Display* fDisplay; |
| 61 | Pixmap fPixmap; |
| 62 | GLXPixmap fGlxPixmap; |
| 63 | }; |
| 64 | |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 65 | GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareContext) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 66 | : fContext(nullptr) |
| 67 | , fDisplay(nullptr) |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 68 | , fPixmap(0) |
| 69 | , fGlxPixmap(0) { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 70 | fDisplay = XOpenDisplay(0); |
| 71 | |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 72 | GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr; |
| 73 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 74 | if (!fDisplay) { |
| 75 | SkDebugf("Failed to open X display.\n"); |
| 76 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 77 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // Get a matching FB config |
| 81 | static int visual_attribs[] = { |
| 82 | GLX_X_RENDERABLE , True, |
| 83 | GLX_DRAWABLE_TYPE , GLX_PIXMAP_BIT, |
| 84 | None |
| 85 | }; |
| 86 | |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 87 | int glx_major, glx_minor; |
| 88 | |
| 89 | // FBConfigs were added in GLX version 1.3. |
| 90 | if (!glXQueryVersion(fDisplay, &glx_major, &glx_minor) || |
| 91 | ((glx_major == 1) && (glx_minor < 3)) || (glx_major < 1)) { |
| 92 | SkDebugf("GLX version 1.3 or higher required.\n"); |
| 93 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 94 | return; |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 95 | } |
| 96 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 97 | //SkDebugf("Getting matching framebuffer configs.\n"); |
| 98 | int fbcount; |
| 99 | GLXFBConfig *fbc = glXChooseFBConfig(fDisplay, DefaultScreen(fDisplay), |
| 100 | visual_attribs, &fbcount); |
| 101 | if (!fbc) { |
| 102 | SkDebugf("Failed to retrieve a framebuffer config.\n"); |
| 103 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 104 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 105 | } |
| 106 | //SkDebugf("Found %d matching FB configs.\n", fbcount); |
| 107 | |
| 108 | // Pick the FB config/visual with the most samples per pixel |
| 109 | //SkDebugf("Getting XVisualInfos.\n"); |
robertphillips@google.com | bb89cda | 2012-03-14 18:06:26 +0000 | [diff] [blame] | 110 | int best_fbc = -1, best_num_samp = -1; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 111 | |
| 112 | int i; |
| 113 | for (i = 0; i < fbcount; ++i) { |
| 114 | XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, fbc[i]); |
| 115 | if (vi) { |
| 116 | int samp_buf, samples; |
| 117 | glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLE_BUFFERS, &samp_buf); |
| 118 | glXGetFBConfigAttrib(fDisplay, fbc[i], GLX_SAMPLES, &samples); |
| 119 | |
| 120 | //SkDebugf(" Matching fbconfig %d, visual ID 0x%2x: SAMPLE_BUFFERS = %d," |
| 121 | // " SAMPLES = %d\n", |
| 122 | // i, (unsigned int)vi->visualid, samp_buf, samples); |
| 123 | |
| 124 | if (best_fbc < 0 || (samp_buf && samples > best_num_samp)) |
| 125 | best_fbc = i, best_num_samp = samples; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 126 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 127 | XFree(vi); |
| 128 | } |
| 129 | |
| 130 | GLXFBConfig bestFbc = fbc[best_fbc]; |
| 131 | |
| 132 | // Be sure to free the FBConfig list allocated by glXChooseFBConfig() |
| 133 | XFree(fbc); |
| 134 | |
| 135 | // Get a visual |
| 136 | XVisualInfo *vi = glXGetVisualFromFBConfig(fDisplay, bestFbc); |
| 137 | //SkDebugf("Chosen visual ID = 0x%x\n", (unsigned int)vi->visualid); |
| 138 | |
| 139 | fPixmap = XCreatePixmap(fDisplay, RootWindow(fDisplay, vi->screen), 10, 10, vi->depth); |
| 140 | |
| 141 | if (!fPixmap) { |
| 142 | SkDebugf("Failed to create pixmap.\n"); |
| 143 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 144 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | fGlxPixmap = glXCreateGLXPixmap(fDisplay, vi, fPixmap); |
| 148 | |
| 149 | // Done with the visual info data |
| 150 | XFree(vi); |
| 151 | |
| 152 | // Create the context |
| 153 | |
| 154 | // Install an X error handler so the application won't exit if GL 3.0 |
| 155 | // context allocation fails. |
| 156 | // |
| 157 | // Note this error handler is global. |
| 158 | // All display connections in all threads of a process use the same |
| 159 | // error handler, so be sure to guard against other threads issuing |
| 160 | // X commands while this code is running. |
| 161 | ctxErrorOccurred = false; |
| 162 | int (*oldHandler)(Display*, XErrorEvent*) = |
| 163 | XSetErrorHandler(&ctxErrorHandler); |
| 164 | |
| 165 | // Get the default screen's GLX extension list |
| 166 | const char *glxExts = glXQueryExtensionsString( |
| 167 | fDisplay, DefaultScreen(fDisplay) |
| 168 | ); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 169 | |
| 170 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 171 | // Check for the GLX_ARB_create_context extension string and the function. |
| 172 | // If either is not present, use GLX 1.3 context creation method. |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 173 | if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_context"), |
| 174 | reinterpret_cast<const GLubyte*>(glxExts))) { |
| 175 | if (kGLES_GrGLStandard != forcedGpuAPI) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 176 | fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 177 | } |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 178 | } else { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 179 | //SkDebugf("Creating context.\n"); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 180 | PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 181 | (PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*)"glXCreateContextAttribsARB"); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 182 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 183 | if (kGLES_GrGLStandard == forcedGpuAPI) { |
| 184 | if (gluCheckExtension( |
| 185 | reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2_profile"), |
| 186 | reinterpret_cast<const GLubyte*>(glxExts))) { |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 187 | static const int context_attribs_gles[] = { |
| 188 | GLX_CONTEXT_MAJOR_VERSION_ARB, 3, |
| 189 | GLX_CONTEXT_MINOR_VERSION_ARB, 0, |
| 190 | GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT, |
| 191 | None |
| 192 | }; |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 193 | fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, glxShareContext, True, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 194 | context_attribs_gles); |
| 195 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 196 | } else { |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 197 | // Well, unfortunately GLX will not just give us the highest context so instead we have |
| 198 | // to do this nastiness |
| 199 | for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) { |
| 200 | /* don't bother below GL 3.0 */ |
| 201 | if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) { |
| 202 | break; |
| 203 | } |
| 204 | // On Nvidia GPUs, to use Nv Path rendering we need a compatibility profile for the |
| 205 | // time being. |
| 206 | // TODO when Nvidia implements NVPR on Core profiles, we should start requesting |
| 207 | // core here |
| 208 | static const int context_attribs_gl[] = { |
| 209 | GLX_CONTEXT_MAJOR_VERSION_ARB, gl_versions[i].major, |
| 210 | GLX_CONTEXT_MINOR_VERSION_ARB, gl_versions[i].minor, |
| 211 | GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, |
| 212 | None |
| 213 | }; |
| 214 | fContext = |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 215 | glXCreateContextAttribsARB(fDisplay, bestFbc, glxShareContext, True, |
| 216 | context_attribs_gl); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 217 | |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 218 | // Sync to ensure any errors generated are processed. |
| 219 | XSync(fDisplay, False); |
| 220 | |
| 221 | if (!ctxErrorOccurred && fContext) { |
| 222 | break; |
| 223 | } |
| 224 | // try again |
| 225 | ctxErrorOccurred = false; |
| 226 | } |
| 227 | |
| 228 | // Couldn't create GL 3.0 context. |
| 229 | // Fall back to old-style 2.x context. |
| 230 | // When a context version below 3.0 is requested, |
| 231 | // implementations will return the newest context version |
| 232 | // compatible with OpenGL versions less than version 3.0. |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 233 | if (ctxErrorOccurred || !fContext) { |
joshualitt | c863ab0 | 2014-08-07 13:48:49 -0700 | [diff] [blame] | 234 | static const int context_attribs_gl_fallback[] = { |
| 235 | GLX_CONTEXT_MAJOR_VERSION_ARB, 1, |
| 236 | GLX_CONTEXT_MINOR_VERSION_ARB, 0, |
| 237 | None |
| 238 | }; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 239 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 240 | ctxErrorOccurred = false; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 241 | |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 242 | fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, glxShareContext, True, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 243 | context_attribs_gl_fallback); |
| 244 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 245 | } |
| 246 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 247 | |
| 248 | // Sync to ensure any errors generated are processed. |
| 249 | XSync(fDisplay, False); |
| 250 | |
| 251 | // Restore the original error handler |
| 252 | XSetErrorHandler(oldHandler); |
| 253 | |
| 254 | if (ctxErrorOccurred || !fContext) { |
| 255 | SkDebugf("Failed to create an OpenGL context.\n"); |
| 256 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 257 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Verify that context is a direct context |
| 261 | if (!glXIsDirect(fDisplay, fContext)) { |
| 262 | //SkDebugf("Indirect GLX rendering context obtained.\n"); |
| 263 | } else { |
| 264 | //SkDebugf("Direct GLX rendering context obtained.\n"); |
| 265 | } |
| 266 | |
| 267 | //SkDebugf("Making context current.\n"); |
| 268 | if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { |
| 269 | SkDebugf("Could not set the context.\n"); |
| 270 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 271 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 272 | } |
| 273 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 274 | SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 275 | if (nullptr == gl.get()) { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 276 | SkDebugf("Failed to create gl interface"); |
| 277 | this->destroyGLContext(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 278 | return; |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 279 | } |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 280 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 281 | if (!gl->validate()) { |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 282 | SkDebugf("Failed to validate gl interface"); |
| 283 | this->destroyGLContext(); |
| 284 | return; |
| 285 | } |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 286 | |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame^] | 287 | this->init(gl.release()); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | |
| 291 | GLXGLContext::~GLXGLContext() { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 292 | this->teardown(); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 293 | this->destroyGLContext(); |
| 294 | } |
| 295 | |
| 296 | void GLXGLContext::destroyGLContext() { |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 297 | if (fDisplay) { |
| 298 | glXMakeCurrent(fDisplay, 0, 0); |
| 299 | |
| 300 | if (fContext) { |
| 301 | glXDestroyContext(fDisplay, fContext); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 302 | fContext = nullptr; |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | if (fGlxPixmap) { |
| 306 | glXDestroyGLXPixmap(fDisplay, fGlxPixmap); |
| 307 | fGlxPixmap = 0; |
| 308 | } |
| 309 | |
| 310 | if (fPixmap) { |
| 311 | XFreePixmap(fDisplay, fPixmap); |
| 312 | fPixmap = 0; |
| 313 | } |
| 314 | |
| 315 | XCloseDisplay(fDisplay); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 316 | fDisplay = nullptr; |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 317 | } |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 318 | } |
| 319 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 320 | void GLXGLContext::onPlatformMakeCurrent() const { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 321 | if (!glXMakeCurrent(fDisplay, fGlxPixmap, fContext)) { |
| 322 | SkDebugf("Could not set the context.\n"); |
| 323 | } |
| 324 | } |
djsollen@google.com | c9542ca | 2013-10-09 18:25:38 +0000 | [diff] [blame] | 325 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 326 | void GLXGLContext::onPlatformSwapBuffers() const { |
djsollen@google.com | c9542ca | 2013-10-09 18:25:38 +0000 | [diff] [blame] | 327 | glXSwapBuffers(fDisplay, fGlxPixmap); |
| 328 | } |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 329 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 330 | GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const { |
| 331 | return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName)); |
| 332 | } |
| 333 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 334 | } // anonymous namespace |
| 335 | |
joshualitt | b59d1bc | 2016-01-20 08:07:01 -0800 | [diff] [blame] | 336 | SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { |
| 337 | GLXGLContext* glxShareContext = reinterpret_cast<GLXGLContext*>(shareContext); |
| 338 | GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI, glxShareContext); |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 339 | if (!ctx->isValid()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 340 | delete ctx; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 341 | return nullptr; |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 342 | } |
| 343 | return ctx; |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 344 | } |