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

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: remove prints 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
« no previous file with comments | « src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 apiBound = eglBindAPI(EGL_OPENGL_ES_API);
71 renderableTypeBit = EGL_OPENGL_ES_BIT;
72 contextAttribs = kEGLContextAttribsForOpenGLES;
73 }
74
75 if (!apiBound) {
76 return NULL;
77 }
78
55 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); 79 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
56 80
57 EGLint majorVersion; 81 EGLint majorVersion;
58 EGLint minorVersion; 82 EGLint minorVersion;
59 eglInitialize(fDisplay, &majorVersion, &minorVersion); 83 eglInitialize(fDisplay, &majorVersion, &minorVersion);
60 84
61 EGLint numConfigs; 85 EGLint numConfigs;
62 static const EGLint configAttribs[] = { 86 const EGLint configAttribs[] = {
63 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 87 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
64 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 88 EGL_RENDERABLE_TYPE, renderableTypeBit,
65 EGL_RED_SIZE, 8, 89 EGL_RED_SIZE, 8,
66 EGL_GREEN_SIZE, 8, 90 EGL_GREEN_SIZE, 8,
67 EGL_BLUE_SIZE, 8, 91 EGL_BLUE_SIZE, 8,
68 EGL_ALPHA_SIZE, 8, 92 EGL_ALPHA_SIZE, 8,
69 EGL_NONE 93 EGL_NONE
70 }; 94 };
71 95
72 EGLConfig surfaceConfig; 96 EGLConfig surfaceConfig;
73 eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); 97 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs )) {
98 SkDebugf("eglChooseConfig failed.\n");
99 return NULL;
100 }
74 101
75 static const EGLint contextAttribs[] = { 102 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
76 EGL_CONTEXT_CLIENT_VERSION, 2, 103 if (EGL_NO_CONTEXT == fContext) {
104 SkDebugf("eglCreateContext failed.\n");
105 return NULL;
106 }
107
108 static const EGLint kSurfaceAttribs[] = {
109 EGL_WIDTH, 1,
110 EGL_HEIGHT, 1,
77 EGL_NONE 111 EGL_NONE
78 }; 112 };
79 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
80 113
114 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttribs) ;
115 if (EGL_NO_SURFACE == fSurface) {
116 SkDebugf("eglCreatePbufferSurface failed.\n");
117 this->destroyGLContext();
118 return NULL;
119 }
81 120
82 static const EGLint surfaceAttribs[] = { 121 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
83 EGL_WIDTH, 1, 122 SkDebugf("eglMakeCurrent failed.\n");
84 EGL_HEIGHT, 1, 123 this->destroyGLContext();
85 EGL_NONE 124 return NULL;
86 }; 125 }
87 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
88
89 eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
90 126
91 const GrGLInterface* interface = GrGLCreateNativeInterface(); 127 const GrGLInterface* interface = GrGLCreateNativeInterface();
92 if (!interface) { 128 if (!interface) {
93 SkDebugf("Failed to create gl interface"); 129 SkDebugf("Failed to create gl interface.\n");
94 this->destroyGLContext(); 130 this->destroyGLContext();
95 return NULL; 131 return NULL;
96 } 132 }
133
97 return interface; 134 return interface;
98 } 135 }
99 136
100 void SkNativeGLContext::makeCurrent() const { 137 void SkNativeGLContext::makeCurrent() const {
101 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { 138 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
102 SkDebugf("Could not set the context.\n"); 139 SkDebugf("Could not set the context.\n");
103 } 140 }
104 } 141 }
OLDNEW
« no previous file with comments | « src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698