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

Side by Side Diff: src/gpu/gl/android/SkNativeGLContext_android.cpp

Issue 23702015: Add OpenGL 4.4 support to SkNativeGLContext and GrGLCreateNativeInterface android versions. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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/SkNativeGLContext.h" 8 #include "gl/SkNativeGLContext.h"
9 9
10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 10 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
55 static const EGLint kEGLContextAttribsForOpenGL[] = {
56 EGL_NONE
57 };
58
59 static const EGLint kEGLContextAttribsForOpenGLES[] = {
60 EGL_CONTEXT_CLIENT_VERSION, 2,
61 EGL_NONE
62 };
63
64 // Try first for OpenGL, then fall back to OpenGL ES.
65 EGLint renderableTypeBit = EGL_OPENGL_BIT;
66 const EGLint* contextAttribs = kEGLContextAttribsForOpenGL;
67 EGLBoolean apiBound = eglBindAPI(EGL_OPENGL_API);
68
69 if (!apiBound) {
70 SkDebugf("\n\n\tES\n\n");
71 apiBound = eglBindAPI(EGL_OPENGL_ES_API);
72 renderableTypeBit = EGL_OPENGL_ES_BIT;
73 contextAttribs = kEGLContextAttribsForOpenGLES;
74 } else {
75 SkDebugf("\n\n\t4.4\n\n");
76 }
77 if (!apiBound) {
78 return NULL;
79 }
80
55 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); 81 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
56 82
57 EGLint majorVersion; 83 EGLint majorVersion;
58 EGLint minorVersion; 84 EGLint minorVersion;
59 eglInitialize(fDisplay, &majorVersion, &minorVersion); 85 eglInitialize(fDisplay, &majorVersion, &minorVersion);
60 86
61 EGLint numConfigs; 87 EGLint numConfigs;
62 static const EGLint configAttribs[] = { 88 const EGLint configAttribs[] = {
63 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 89 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
64 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 90 EGL_RENDERABLE_TYPE, renderableTypeBit,
65 EGL_RED_SIZE, 8, 91 EGL_RED_SIZE, 8,
66 EGL_GREEN_SIZE, 8, 92 EGL_GREEN_SIZE, 8,
67 EGL_BLUE_SIZE, 8, 93 EGL_BLUE_SIZE, 8,
68 EGL_ALPHA_SIZE, 8, 94 EGL_ALPHA_SIZE, 8,
69 EGL_NONE 95 EGL_NONE
70 }; 96 };
71 97
72 EGLConfig surfaceConfig; 98 EGLConfig surfaceConfig;
73 eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); 99 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs )) {
100 SkDebugf("eglChooseConfig failed.\n");
101 return NULL;
102 }
74 103
75 static const EGLint contextAttribs[] = { 104 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
76 EGL_CONTEXT_CLIENT_VERSION, 2, 105 if (EGL_NO_CONTEXT == fContext) {
106 SkDebugf("eglCreateContext failed.\n");
107 return NULL;
108 }
109
110 static const EGLint kSurfaceAttribs[] = {
111 EGL_WIDTH, 1,
112 EGL_HEIGHT, 1,
77 EGL_NONE 113 EGL_NONE
78 }; 114 };
79 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
80 115
116 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttribs) ;
117 if (EGL_NO_SURFACE == fSurface) {
118 SkDebugf("eglCreatePbufferSurface failed.\n");
119 this->destroyGLContext();
120 return NULL;
121 }
81 122
82 static const EGLint surfaceAttribs[] = { 123 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
83 EGL_WIDTH, 1, 124 SkDebugf("eglMakeCurrent failed.\n");
84 EGL_HEIGHT, 1, 125 this->destroyGLContext();
85 EGL_NONE 126 return NULL;
86 }; 127 }
87 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
88
89 eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
90 128
91 const GrGLInterface* interface = GrGLCreateNativeInterface(); 129 const GrGLInterface* interface = GrGLCreateNativeInterface();
92 if (!interface) { 130 if (!interface) {
93 SkDebugf("Failed to create gl interface"); 131 SkDebugf("Failed to create gl interface.\n");
94 this->destroyGLContext(); 132 this->destroyGLContext();
95 return NULL; 133 return NULL;
96 } 134 }
135
97 return interface; 136 return interface;
98 } 137 }
99 138
100 void SkNativeGLContext::makeCurrent() const { 139 void SkNativeGLContext::makeCurrent() const {
101 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { 140 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
102 SkDebugf("Could not set the context.\n"); 141 SkDebugf("Could not set the context.\n");
103 } 142 }
104 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698