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

Side by Side Diff: src/gpu/gl/mesa/SkMesaGLContext.cpp

Issue 640283004: Refactor SkGLContext to be actually extendable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: win compile fix. Created 6 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 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 8
9 #include <GL/osmesa.h> 9 #include <GL/osmesa.h>
10 10
11 #include "gl/SkMesaGLContext.h" 11 #include "gl/SkMesaGLContext.h"
12 #include "gl/GrGLDefines.h" 12 #include "gl/GrGLDefines.h"
13 13
14 static const GrGLint gBOGUS_SIZE = 16;
15
14 SkMesaGLContext::SkMesaGLContext() 16 SkMesaGLContext::SkMesaGLContext()
15 : fContext(static_cast<Context>(NULL)) 17 : fContext(static_cast<Context>(NULL))
16 , fImage(NULL) { 18 , fImage(NULL) {
17 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext)); 19 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
18 }
19
20 SkMesaGLContext::~SkMesaGLContext() {
21 this->destroyGLContext();
22 }
23
24 void SkMesaGLContext::destroyGLContext() {
25 if (fImage) {
26 sk_free(fImage);
27 fImage = NULL;
28 }
29
30 if (fContext) {
31 OSMesaDestroyContext((OSMesaContext)fContext);
32 fContext = static_cast<Context>(NULL);
33 }
34 }
35
36 static const GrGLint gBOGUS_SIZE = 16;
37
38 const GrGLInterface* SkMesaGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
39 if (kGLES_GrGLStandard == forcedGpuAPI) {
40 return NULL;
41 }
42 20
43 /* Create an RGBA-mode context */ 21 /* Create an RGBA-mode context */
44 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305 22 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
45 /* specify Z, stencil, accum sizes */ 23 /* specify Z, stencil, accum sizes */
46 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL); 24 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
47 #else 25 #else
48 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL); 26 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
49 #endif 27 #endif
50 if (!fContext) { 28 if (!fContext) {
51 SkDebugf("OSMesaCreateContext failed!\n"); 29 SkDebugf("OSMesaCreateContext failed!\n");
52 this->destroyGLContext(); 30 this->destroyGLContext();
53 return NULL; 31 return;
54 } 32 }
55 // Allocate the image buffer 33 // Allocate the image buffer
56 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE * 34 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
57 4 * sizeof(GrGLubyte)); 35 4 * sizeof(GrGLubyte));
58 if (!fImage) { 36 if (!fImage) {
59 SkDebugf("Alloc image buffer failed!\n"); 37 SkDebugf("Alloc image buffer failed!\n");
60 this->destroyGLContext(); 38 this->destroyGLContext();
61 return NULL; 39 return;
62 } 40 }
63 41
64 // Bind the buffer to the context and make it current 42 // Bind the buffer to the context and make it current
65 if (!OSMesaMakeCurrent((OSMesaContext)fContext, 43 if (!OSMesaMakeCurrent((OSMesaContext)fContext,
66 fImage, 44 fImage,
67 GR_GL_UNSIGNED_BYTE, 45 GR_GL_UNSIGNED_BYTE,
68 gBOGUS_SIZE, 46 gBOGUS_SIZE,
69 gBOGUS_SIZE)) { 47 gBOGUS_SIZE)) {
70 SkDebugf("OSMesaMakeCurrent failed!\n"); 48 SkDebugf("OSMesaMakeCurrent failed!\n");
71 this->destroyGLContext(); 49 this->destroyGLContext();
72 return NULL; 50 return;
73 } 51 }
74 52
75 const GrGLInterface* interface = GrGLCreateMesaInterface(); 53 fGL.reset(GrGLCreateMesaInterface());
76 if (!interface) { 54 if (NULL == fGL.get()) {
77 SkDebugf("Could not create GL interface!\n"); 55 SkDebugf("Could not create GL interface!\n");
78 this->destroyGLContext(); 56 this->destroyGLContext();
79 return NULL; 57 return;
80 } 58 }
81 return interface;
82 59
60 if (!fGL->validate()) {
61 SkDebugf("Could not validate GL interface!\n");
62 this->destroyGLContext();
63 return;
64 }
83 } 65 }
84 66
67 SkMesaGLContext::~SkMesaGLContext() {
68 this->destroyGLContext();
69 }
70
71 void SkMesaGLContext::destroyGLContext() {
72 fGL.reset(NULL);
73 if (fImage) {
74 sk_free(fImage);
75 fImage = NULL;
76 }
77
78 if (fContext) {
79 OSMesaDestroyContext((OSMesaContext)fContext);
80 fContext = static_cast<Context>(NULL);
81 }
82 }
83
84
85
85 void SkMesaGLContext::makeCurrent() const { 86 void SkMesaGLContext::makeCurrent() const {
86 if (fContext) { 87 if (fContext) {
87 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, 88 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
88 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) { 89 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
89 SkDebugf("Could not make MESA context current."); 90 SkDebugf("Could not make MESA context current.");
90 } 91 }
91 } 92 }
92 } 93 }
93 94
94 void SkMesaGLContext::swapBuffers() const { } 95 void SkMesaGLContext::swapBuffers() const { }
OLDNEW
« no previous file with comments | « src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp ('k') | src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698