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

Side by Side Diff: ui/gl/gl_surface_egl.cc

Issue 136583006: Add 16-bit support for browser compositor surface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Unused alpha variable. Created 6 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This include must be here so that the includes provided transitively 5 // This include must be here so that the includes provided transitively
6 // by gl_surface_egl.h don't make it impossible to compile this code. 6 // by gl_surface_egl.h don't make it impossible to compile this code.
7 #include "third_party/mesa/src/include/GL/osmesa.h" 7 #include "third_party/mesa/src/include/GL/osmesa.h"
8 8
9 #include "ui/gl/gl_surface_egl.h" 9 #include "ui/gl/gl_surface_egl.h"
10 10
11 #if defined(OS_ANDROID) 11 #if defined(OS_ANDROID)
12 #include <android/native_window_jni.h> 12 #include <android/native_window_jni.h>
13 #include "base/android/sys_utils.h"
13 #endif 14 #endif
14 15
15 #include "base/command_line.h" 16 #include "base/command_line.h"
16 #include "base/debug/trace_event.h" 17 #include "base/debug/trace_event.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "ui/gl/egl_util.h" 22 #include "ui/gl/egl_util.h"
22 #include "ui/gl/gl_context.h" 23 #include "ui/gl/gl_context.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 virtual bool GetMscRate(int32* numerator, int32* denominator) OVERRIDE { 88 virtual bool GetMscRate(int32* numerator, int32* denominator) OVERRIDE {
88 return false; 89 return false;
89 } 90 }
90 91
91 private: 92 private:
92 EGLSurface surface_; 93 EGLSurface surface_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider); 95 DISALLOW_COPY_AND_ASSIGN(EGLSyncControlVSyncProvider);
95 }; 96 };
96 97
98 bool ValidateEglConfig(EGLDisplay display,
99 const EGLint* config_attribs,
100 EGLint* num_configs) {
101 if (!eglChooseConfig(display,
102 config_attribs,
103 NULL,
104 0,
105 num_configs)) {
106 LOG(ERROR) << "eglChooseConfig failed with error "
107 << GetLastEGLErrorString();
108 return false;
109 }
110 if (*num_configs == 0) {
111 LOG(ERROR) << "No suitable EGL configs found.";
112 return false;
113 }
114 return true;
115 }
116
97 } // namespace 117 } // namespace
98 118
99 GLSurfaceEGL::GLSurfaceEGL() {} 119 GLSurfaceEGL::GLSurfaceEGL() {}
100 120
101 bool GLSurfaceEGL::InitializeOneOff() { 121 bool GLSurfaceEGL::InitializeOneOff() {
102 static bool initialized = false; 122 static bool initialized = false;
103 if (initialized) 123 if (initialized)
104 return true; 124 return true;
105 125
106 #if defined(USE_X11) 126 #if defined(USE_X11)
(...skipping 23 matching lines...) Expand all
130 return false; 150 return false;
131 } 151 }
132 152
133 if (!eglInitialize(g_display, NULL, NULL)) { 153 if (!eglInitialize(g_display, NULL, NULL)) {
134 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); 154 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString();
135 return false; 155 return false;
136 } 156 }
137 157
138 // Choose an EGL configuration. 158 // Choose an EGL configuration.
139 // On X this is only used for PBuffer surfaces. 159 // On X this is only used for PBuffer surfaces.
140 static const EGLint kConfigAttribs[] = { 160 static EGLint config_attribs_8888[] = {
141 EGL_BUFFER_SIZE, 32, 161 EGL_BUFFER_SIZE, 32,
142 EGL_ALPHA_SIZE, 8, 162 EGL_ALPHA_SIZE, 8,
143 EGL_BLUE_SIZE, 8, 163 EGL_BLUE_SIZE, 8,
144 EGL_GREEN_SIZE, 8, 164 EGL_GREEN_SIZE, 8,
145 EGL_RED_SIZE, 8, 165 EGL_RED_SIZE, 8,
146 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 166 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
147 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, 167 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
148 EGL_NONE 168 EGL_NONE
149 }; 169 };
150 170
171 #if defined(OS_ANDROID)
172 static EGLint config_attribs_565[] = {
173 EGL_BUFFER_SIZE, 16,
174 EGL_BLUE_SIZE, 5,
175 EGL_GREEN_SIZE, 6,
176 EGL_RED_SIZE, 5,
177 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
178 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
179 EGL_NONE
180 };
181 #endif
182 EGLint* choose_attributes = config_attribs_8888;
183
184 #if defined(OS_ANDROID)
185 if (base::android::SysUtils::IsLowEndDevice()) {
186 choose_attributes = config_attribs_565;
187 }
188 #endif
189
151 #if defined(USE_OZONE) 190 #if defined(USE_OZONE)
152 const EGLint* config_attribs = 191 const EGLint* config_attribs =
153 surface_factory->GetEGLSurfaceProperties(kConfigAttribs); 192 surface_factory->GetEGLSurfaceProperties(choose_attributes);
154 #else 193 #else
155 const EGLint* config_attribs = kConfigAttribs; 194 const EGLint* config_attribs = choose_attributes;
156 #endif 195 #endif
157 196
158 EGLint num_configs; 197 EGLint num_configs;
198 EGLint config_size = 1;
199 EGLConfig* config_data = &g_config;
200 // Validate if there are any configs for given atrribs.
201 if (!ValidateEglConfig(g_display,
202 config_attribs,
203 &num_configs)) {
204 return false;
205 }
206
207 #if defined(OS_ANDROID)
208 scoped_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]);
209 if (base::android::SysUtils::IsLowEndDevice()) {
210 config_size = num_configs;
211 config_data = matching_configs.get();
212 }
213 #endif
214
159 if (!eglChooseConfig(g_display, 215 if (!eglChooseConfig(g_display,
160 config_attribs, 216 config_attribs,
161 NULL, 217 config_data,
162 0, 218 config_size,
163 &num_configs)) { 219 &num_configs)) {
164 LOG(ERROR) << "eglChooseConfig failed with error " 220 LOG(ERROR) << "eglChooseConfig failed with error "
165 << GetLastEGLErrorString(); 221 << GetLastEGLErrorString();
166 return false; 222 return false;
167 } 223 }
168 224
169 if (num_configs == 0) { 225 #if defined(OS_ANDROID)
170 LOG(ERROR) << "No suitable EGL configs found."; 226 if (base::android::SysUtils::IsLowEndDevice()) {
171 return false; 227 // Because of the EGL config sort order, we have to iterate
228 // through all of them (it'll put higher sum(R,G,B) bits
229 // first with the above attribs).
230 bool match_found = false;
231 for (int i = 0; i < num_configs; i++) {
232 EGLBoolean success;
233 EGLint red, green, blue;
234 // Read the relevent attributes of the EGLConfig.
235 success = eglGetConfigAttrib(g_display, matching_configs[i],
236 EGL_RED_SIZE, &red);
237 success &= eglGetConfigAttrib(g_display, matching_configs[i],
238 EGL_BLUE_SIZE, &blue);
239 success &= eglGetConfigAttrib(g_display, matching_configs[i],
240 EGL_GREEN_SIZE, &green);
241 if ((success == EGL_TRUE) && (red == 5) &&
242 (green == 6) && (blue == 5)) {
243 g_config = matching_configs[i];
244 match_found = true;
245 break;
246 }
247 }
248 if (!match_found) {
249 // To fall back to default 32 bit format, choose with
250 // the right attributes again.
251 if (!ValidateEglConfig(g_display,
252 config_attribs_8888,
253 &num_configs)) {
254 return false;
255 }
256 if (!eglChooseConfig(g_display,
257 config_attribs_8888,
258 &g_config,
259 1,
260 &num_configs)) {
261 LOG(ERROR) << "eglChooseConfig failed with error "
262 << GetLastEGLErrorString();
263 return false;
264 }
265 }
172 } 266 }
173 267
174 if (!eglChooseConfig(g_display, 268 #endif
175 config_attribs,
176 &g_config,
177 1,
178 &num_configs)) {
179 LOG(ERROR) << "eglChooseConfig failed with error "
180 << GetLastEGLErrorString();
181 return false;
182 }
183 269
184 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); 270 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS);
185 g_egl_create_context_robustness_supported = 271 g_egl_create_context_robustness_supported =
186 HasEGLExtension("EGL_EXT_create_context_robustness"); 272 HasEGLExtension("EGL_EXT_create_context_robustness");
187 g_egl_sync_control_supported = 273 g_egl_sync_control_supported =
188 HasEGLExtension("EGL_CHROMIUM_sync_control"); 274 HasEGLExtension("EGL_CHROMIUM_sync_control");
189 275
190 // Check if SurfacelessEGL is supported. 276 // Check if SurfacelessEGL is supported.
191 g_egl_surfaceless_context_supported = 277 g_egl_surfaceless_context_supported =
192 HasEGLExtension("EGL_KHR_surfaceless_context"); 278 HasEGLExtension("EGL_KHR_surfaceless_context");
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 852 }
767 default: 853 default:
768 NOTREACHED(); 854 NOTREACHED();
769 return NULL; 855 return NULL;
770 } 856 }
771 } 857 }
772 858
773 #endif 859 #endif
774 860
775 } // namespace gfx 861 } // namespace gfx
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