OLD | NEW |
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/SkNativeGLContext.h" | 8 #include "gl/SkNativeGLContext.h" |
9 | 9 |
10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { | 10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 if (fSurface) { | 44 if (fSurface) { |
45 eglDestroySurface(fDisplay, fSurface); | 45 eglDestroySurface(fDisplay, fSurface); |
46 fSurface = EGL_NO_SURFACE; | 46 fSurface = EGL_NO_SURFACE; |
47 } | 47 } |
48 | 48 |
49 //TODO should we close the display? | 49 //TODO should we close the display? |
50 fDisplay = EGL_NO_DISPLAY; | 50 fDisplay = EGL_NO_DISPLAY; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 const GrGLInterface* SkNativeGLContext::createGLContext() { | 54 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedStand
ard) { |
55 static const EGLint kEGLContextAttribsForOpenGL[] = { | 55 static const EGLint kEGLContextAttribsForOpenGL[] = { |
56 EGL_NONE | 56 EGL_NONE |
57 }; | 57 }; |
58 | 58 |
59 static const EGLint kEGLContextAttribsForOpenGLES[] = { | 59 static const EGLint kEGLContextAttribsForOpenGLES[] = { |
60 EGL_CONTEXT_CLIENT_VERSION, 2, | 60 EGL_CONTEXT_CLIENT_VERSION, 2, |
61 EGL_NONE | 61 EGL_NONE |
62 }; | 62 }; |
63 | 63 |
64 static const struct { | 64 static const struct { |
65 const EGLint* fContextAttribs; | 65 const EGLint* fContextAttribs; |
66 EGLenum fAPI; | 66 EGLenum fAPI; |
67 EGLint fRenderableTypeBit; | 67 EGLint fRenderableTypeBit; |
68 GrGLStandard fStandard; | 68 GrGLStandard fStandard; |
69 } kAPIs[] = { | 69 } kAPIs[] = { |
70 { // OpenGL | 70 { // OpenGL |
71 kEGLContextAttribsForOpenGL, | 71 kEGLContextAttribsForOpenGL, |
72 EGL_OPENGL_API, | 72 EGL_OPENGL_API, |
73 EGL_OPENGL_BIT, | 73 EGL_OPENGL_BIT, |
74 kGL_GrGLStandard | 74 kGL_GrGLStandard |
75 }, | 75 }, |
76 { // OpenGL ES. This seems to work for both ES2 and 3 (when available)
. | 76 { // OpenGL ES. This seems to work for both ES2 and 3 (when available)
. |
77 kEGLContextAttribsForOpenGLES, | 77 kEGLContextAttribsForOpenGLES, |
78 EGL_OPENGL_ES_API, | 78 EGL_OPENGL_ES_API, |
79 EGL_OPENGL_ES2_BIT, | 79 EGL_OPENGL_ES2_BIT, |
80 kGLES_GrGLStandard | 80 kGLES_GrGLStandard |
81 }, | 81 }, |
82 }; | 82 }; |
83 | 83 |
| 84 size_t apiLimit = SK_ARRAY_COUNT(kAPIs); |
| 85 size_t api = 0; |
| 86 if (forcedStandard == kGL_GrGLStandard) { |
| 87 apiLimit = 1; |
| 88 } else if (forcedStandard == kGLES_GrGLStandard) { |
| 89 api = 1; |
| 90 } |
| 91 SkASSERT(forcedStandard == kNone_GrGLStandard || kAPIs[api].fStandard == for
cedStandard); |
| 92 |
84 const GrGLInterface* interface = NULL; | 93 const GrGLInterface* interface = NULL; |
85 | 94 |
86 for (size_t api = 0; NULL == interface && api < SK_ARRAY_COUNT(kAPIs); ++api
) { | 95 for (size_t i = 0; NULL == interface && i < apiLimit; ++api) { |
87 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 96 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
88 | 97 |
89 EGLint majorVersion; | 98 EGLint majorVersion; |
90 EGLint minorVersion; | 99 EGLint minorVersion; |
91 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 100 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
92 | 101 |
93 #if 0 | 102 #if 0 |
94 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); | 103 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); |
95 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); | 104 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); |
96 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); | 105 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 173 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
165 SkDebugf("Could not set the context.\n"); | 174 SkDebugf("Could not set the context.\n"); |
166 } | 175 } |
167 } | 176 } |
168 | 177 |
169 void SkNativeGLContext::swapBuffers() const { | 178 void SkNativeGLContext::swapBuffers() const { |
170 if (!eglSwapBuffers(fDisplay, fSurface)) { | 179 if (!eglSwapBuffers(fDisplay, fSurface)) { |
171 SkDebugf("Could not complete eglSwapBuffers.\n"); | 180 SkDebugf("Could not complete eglSwapBuffers.\n"); |
172 } | 181 } |
173 } | 182 } |
OLD | NEW |