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

Side by Side Diff: src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp

Issue 1604993005: Add ability to wire up sharelist in glcontext creation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gl/SkGLContext.h" 8 #include "gl/SkGLContext.h"
9 9
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 28 matching lines...) Expand all
39 #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions) 39 #define NUM_GL_VERSIONS SK_ARRAY_COUNT(gl_versions)
40 40
41 static bool ctxErrorOccurred = false; 41 static bool ctxErrorOccurred = false;
42 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) { 42 static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
43 ctxErrorOccurred = true; 43 ctxErrorOccurred = true;
44 return 0; 44 return 0;
45 } 45 }
46 46
47 class GLXGLContext : public SkGLContext { 47 class GLXGLContext : public SkGLContext {
48 public: 48 public:
49 GLXGLContext(GrGLStandard forcedGpuAPI); 49 GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareList);
50 ~GLXGLContext() override; 50 ~GLXGLContext() override;
51 51
52 private: 52 private:
53 void destroyGLContext(); 53 void destroyGLContext();
54 54
55 void onPlatformMakeCurrent() const override; 55 void onPlatformMakeCurrent() const override;
56 void onPlatformSwapBuffers() const override; 56 void onPlatformSwapBuffers() const override;
57 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; 57 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
58 58
59 GLXContext fContext; 59 GLXContext fContext;
60 Display* fDisplay; 60 Display* fDisplay;
61 Pixmap fPixmap; 61 Pixmap fPixmap;
62 GLXPixmap fGlxPixmap; 62 GLXPixmap fGlxPixmap;
63 }; 63 };
64 64
65 GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI) 65 GLXGLContext::GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareContext )
66 : fContext(nullptr) 66 : fContext(nullptr)
67 , fDisplay(nullptr) 67 , fDisplay(nullptr)
68 , fPixmap(0) 68 , fPixmap(0)
69 , fGlxPixmap(0) { 69 , fGlxPixmap(0) {
70 fDisplay = XOpenDisplay(0);
70 71
71 fDisplay = XOpenDisplay(0); 72 GLXContext glxShareContext = shareContext ? shareContext->fContext : nullptr ;
72 73
73 if (!fDisplay) { 74 if (!fDisplay) {
74 SkDebugf("Failed to open X display.\n"); 75 SkDebugf("Failed to open X display.\n");
75 this->destroyGLContext(); 76 this->destroyGLContext();
76 return; 77 return;
77 } 78 }
78 79
79 // Get a matching FB config 80 // Get a matching FB config
80 static int visual_attribs[] = { 81 static int visual_attribs[] = {
81 GLX_X_RENDERABLE , True, 82 GLX_X_RENDERABLE , True,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 if (kGLES_GrGLStandard == forcedGpuAPI) { 183 if (kGLES_GrGLStandard == forcedGpuAPI) {
183 if (gluCheckExtension( 184 if (gluCheckExtension(
184 reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2 _profile"), 185 reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2 _profile"),
185 reinterpret_cast<const GLubyte*>(glxExts))) { 186 reinterpret_cast<const GLubyte*>(glxExts))) {
186 static const int context_attribs_gles[] = { 187 static const int context_attribs_gles[] = {
187 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, 188 GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
188 GLX_CONTEXT_MINOR_VERSION_ARB, 0, 189 GLX_CONTEXT_MINOR_VERSION_ARB, 0,
189 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EX T, 190 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EX T,
190 None 191 None
191 }; 192 };
192 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True , 193 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, glxShar eContext, True,
193 context_attribs_gles); 194 context_attribs_gles);
194 } 195 }
195 } else { 196 } else {
196 // Well, unfortunately GLX will not just give us the highest context so instead we have 197 // Well, unfortunately GLX will not just give us the highest context so instead we have
197 // to do this nastiness 198 // to do this nastiness
198 for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) { 199 for (i = NUM_GL_VERSIONS - 2; i > 0 ; i--) {
199 /* don't bother below GL 3.0 */ 200 /* don't bother below GL 3.0 */
200 if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) { 201 if (gl_versions[i].major == 3 && gl_versions[i].minor == 0) {
201 break; 202 break;
202 } 203 }
203 // On Nvidia GPUs, to use Nv Path rendering we need a compatibil ity profile for the 204 // On Nvidia GPUs, to use Nv Path rendering we need a compatibil ity profile for the
204 // time being. 205 // time being.
205 // TODO when Nvidia implements NVPR on Core profiles, we should start requesting 206 // TODO when Nvidia implements NVPR on Core profiles, we should start requesting
206 // core here 207 // core here
207 static const int context_attribs_gl[] = { 208 static const int context_attribs_gl[] = {
208 GLX_CONTEXT_MAJOR_VERSION_ARB, gl_versions[i].major, 209 GLX_CONTEXT_MAJOR_VERSION_ARB, gl_versions[i].major,
209 GLX_CONTEXT_MINOR_VERSION_ARB, gl_versions[i].minor, 210 GLX_CONTEXT_MINOR_VERSION_ARB, gl_versions[i].minor,
210 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PR OFILE_BIT_ARB, 211 GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PR OFILE_BIT_ARB,
211 None 212 None
212 }; 213 };
213 fContext = 214 fContext =
214 glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, c ontext_attribs_gl); 215 glXCreateContextAttribsARB(fDisplay, bestFbc, glxShareCo ntext, True,
216 context_attribs_gl);
215 217
216 // Sync to ensure any errors generated are processed. 218 // Sync to ensure any errors generated are processed.
217 XSync(fDisplay, False); 219 XSync(fDisplay, False);
218 220
219 if (!ctxErrorOccurred && fContext) { 221 if (!ctxErrorOccurred && fContext) {
220 break; 222 break;
221 } 223 }
222 // try again 224 // try again
223 ctxErrorOccurred = false; 225 ctxErrorOccurred = false;
224 } 226 }
225 227
226 // Couldn't create GL 3.0 context. 228 // Couldn't create GL 3.0 context.
227 // Fall back to old-style 2.x context. 229 // Fall back to old-style 2.x context.
228 // When a context version below 3.0 is requested, 230 // When a context version below 3.0 is requested,
229 // implementations will return the newest context version 231 // implementations will return the newest context version
230 // compatible with OpenGL versions less than version 3.0. 232 // compatible with OpenGL versions less than version 3.0.
231 if (ctxErrorOccurred || !fContext) { 233 if (ctxErrorOccurred || !fContext) {
232 static const int context_attribs_gl_fallback[] = { 234 static const int context_attribs_gl_fallback[] = {
233 GLX_CONTEXT_MAJOR_VERSION_ARB, 1, 235 GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
234 GLX_CONTEXT_MINOR_VERSION_ARB, 0, 236 GLX_CONTEXT_MINOR_VERSION_ARB, 0,
235 None 237 None
236 }; 238 };
237 239
238 ctxErrorOccurred = false; 240 ctxErrorOccurred = false;
239 241
240 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True , 242 fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, glxShar eContext, True,
241 context_attribs_gl_fallbac k); 243 context_attribs_gl_fallbac k);
242 } 244 }
243 } 245 }
244 } 246 }
245 247
246 // Sync to ensure any errors generated are processed. 248 // Sync to ensure any errors generated are processed.
247 XSync(fDisplay, False); 249 XSync(fDisplay, False);
248 250
249 // Restore the original error handler 251 // Restore the original error handler
250 XSetErrorHandler(oldHandler); 252 XSetErrorHandler(oldHandler);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 void GLXGLContext::onPlatformSwapBuffers() const { 326 void GLXGLContext::onPlatformSwapBuffers() const {
325 glXSwapBuffers(fDisplay, fGlxPixmap); 327 glXSwapBuffers(fDisplay, fGlxPixmap);
326 } 328 }
327 329
328 GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const { 330 GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const {
329 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName)); 331 return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName));
330 } 332 }
331 333
332 } // anonymous namespace 334 } // anonymous namespace
333 335
334 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { 336 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s hareContext) {
335 GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI); 337 GLXGLContext* glxShareContext = reinterpret_cast<GLXGLContext*>(shareContext );
338 GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI, glxShareContext);
336 if (!ctx->isValid()) { 339 if (!ctx->isValid()) {
337 delete ctx; 340 delete ctx;
338 return nullptr; 341 return nullptr;
339 } 342 }
340 return ctx; 343 return ctx;
341 } 344 }
OLDNEW
« no previous file with comments | « src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp ('k') | src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698