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

Side by Side Diff: platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp

Issue 1582313002: VisualBench: Use first succeeding EGL API (Closed) Base URL: https://skia.googlesource.com/skia.git@android-sampleapp-paths
Patch Set: 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
« no previous file with comments | « no previous file | 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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkOSWindow_Android.h" 8 #include "SkOSWindow_Android.h"
9 9
10 #include <GLES/gl.h> 10 #include <GLES/gl.h>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 EGL_OPENGL_API, 43 EGL_OPENGL_API,
44 EGL_OPENGL_BIT, 44 EGL_OPENGL_BIT,
45 }, 45 },
46 { // OpenGL ES. This seems to work for both ES2 and 3 (when available) . 46 { // OpenGL ES. This seems to work for both ES2 and 3 (when available) .
47 kEGLContextAttribsForOpenGLES, 47 kEGLContextAttribsForOpenGLES,
48 EGL_OPENGL_ES_API, 48 EGL_OPENGL_ES_API,
49 EGL_OPENGL_ES2_BIT, 49 EGL_OPENGL_ES2_BIT,
50 }, 50 },
51 }; 51 };
52 52
53 size_t apiLimit = SK_ARRAY_COUNT(kAPIs); 53 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
54 if (EGL_NO_DISPLAY == display) {
55 return false;
56 }
54 57
55 for (size_t api = 0; api < apiLimit; ++api) { 58 EGLint majorVersion;
56 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); 59 EGLint minorVersion;
60 if (!eglInitialize(display, &majorVersion, &minorVersion)) {
61 return false;
62 }
57 63
58 EGLint majorVersion; 64 for (size_t api = 0; api < SK_ARRAY_COUNT(kAPIs); ++api) {
59 EGLint minorVersion; 65 if (!eglBindAPI(kAPIs[api].fAPI)) {
60 eglInitialize(display, &majorVersion, &minorVersion); 66 continue;
61 67 }
62 #if 0 68 #if 0
63 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); 69 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR));
64 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); 70 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS));
65 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); 71 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION));
66 SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS)); 72 SkDebugf("EXTENSIONS %s\n", eglQueryString(fDisplay, EGL_EXTENSIONS));
67 #endif 73 #endif
68 74
69 if (!eglBindAPI(kAPIs[api].fAPI)) {
70 continue;
71 }
72
73 const EGLint configAttribs[] = { 75 const EGLint configAttribs[] = {
74 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 76 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
75 EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit, 77 EGL_RENDERABLE_TYPE, kAPIs[api].fRenderableTypeBit,
76 EGL_RED_SIZE, 8, 78 EGL_RED_SIZE, 8,
77 EGL_GREEN_SIZE, 8, 79 EGL_GREEN_SIZE, 8,
78 EGL_BLUE_SIZE, 8, 80 EGL_BLUE_SIZE, 8,
79 EGL_ALPHA_SIZE, 8, 81 EGL_ALPHA_SIZE, 8,
80 EGL_NONE 82 EGL_NONE
81 }; 83 };
82 84
83 EGLint format; 85 EGLint format;
84 EGLint numConfigs; 86 EGLint numConfigs;
85 EGLConfig config; 87 EGLConfig config;
86 EGLSurface surface; 88 EGLSurface surface;
87 EGLContext context; 89 EGLContext context;
88 90
89 /* Here, the application chooses the configuration it desires. In this 91 /* Here, the application chooses the configuration it desires. In this
90 * sample, we have a very simplified selection process, where we pick 92 * sample, we have a very simplified selection process, where we pick
91 * the first EGLConfig that matches our criteria */ 93 * the first EGLConfig that matches our criteria */
92 eglChooseConfig(display, configAttribs, &config, 1, &numConfigs); 94 if (!eglChooseConfig(display, configAttribs, &config, 1, &numConfigs) ||
95 numConfigs != 1) {
96 continue;
97 }
93 98
94 /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is 99 /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
95 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). 100 * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
96 * As soon as we picked a EGLConfig, we can safely reconfigure the 101 * As soon as we picked a EGLConfig, we can safely reconfigure the
97 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ 102 * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
98 eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); 103 if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
104 continue;
105 }
99 106
100 ANativeWindow_setBuffersGeometry(fNativeWindow, 0, 0, format); 107 ANativeWindow_setBuffersGeometry(fNativeWindow, 0, 0, format);
101 108
102 surface = eglCreateWindowSurface(display, config, fNativeWindow, nullptr ); 109 surface = eglCreateWindowSurface(display, config, fNativeWindow, nullptr );
110 if (EGL_NO_SURFACE == surface) {
111 SkDebugf("eglCreateWindowSurface failed. EGL Error: 0x%08x\n", eglG etError());
112 continue;
113 }
103 context = eglCreateContext(display, config, nullptr, kAPIs[api].fContext Attribs); 114 context = eglCreateContext(display, config, nullptr, kAPIs[api].fContext Attribs);
104 if (EGL_NO_CONTEXT == context) { 115 if (EGL_NO_CONTEXT == context) {
105 SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetErro r()); 116 SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetErro r());
117 eglDestroySurface(display, surface);
106 continue; 118 continue;
107 } 119 }
108 120
109 if (!eglMakeCurrent(display, surface, surface, context)) { 121 if (!eglMakeCurrent(display, surface, surface, context)) {
110 SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError( )); 122 SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError( ));
123 eglDestroyContext(display, context);
124 eglDestroySurface(display, surface);
111 continue; 125 continue;
112 } 126 }
113 127
114 fWindow.fDisplay = display; 128 fWindow.fDisplay = display;
115 fWindow.fContext = context; 129 fWindow.fContext = context;
116 fWindow.fSurface = surface; 130 fWindow.fSurface = surface;
131 break;
117 } 132 }
118 133
119 if (fWindow.fDisplay && fWindow.fContext && fWindow.fSurface) { 134 if (fWindow.fDisplay && fWindow.fContext && fWindow.fSurface) {
120 EGLint w, h; 135 EGLint w, h;
121 eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_WIDTH, &w); 136 eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_WIDTH, &w);
122 eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_HEIGHT, &h); 137 eglQuerySurface(fWindow.fDisplay, fWindow.fSurface, EGL_HEIGHT, &h);
123 138
124 glViewport(0, 0, w, h); 139 glViewport(0, 0, w, h);
125 glClearColor(0.0, 0, 0, 0.0); 140 glClearColor(0.0, 0, 0, 0.0);
126 glClearStencil(0); 141 glClearStencil(0);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 193
179 /////////////////////////////////////////// 194 ///////////////////////////////////////////
180 /////////////// SkEvent impl ////////////// 195 /////////////// SkEvent impl //////////////
181 /////////////////////////////////////////// 196 ///////////////////////////////////////////
182 197
183 void SkEvent::SignalQueueTimer(SkMSec ms) { 198 void SkEvent::SignalQueueTimer(SkMSec ms) {
184 } 199 }
185 200
186 void SkEvent::SignalNonEmptyQueue() { 201 void SkEvent::SignalNonEmptyQueue() {
187 } 202 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698