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

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: Fallback to default format when there is no lowend support. 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
97 } // namespace 98 } // namespace
98 99
99 GLSurfaceEGL::GLSurfaceEGL() {} 100 GLSurfaceEGL::GLSurfaceEGL() {}
100 101
102 static bool ValidateEglConfig(EGLDisplay display,
103 const EGLint* config_attribs,
104 EGLint* num_configs) {
no sievers 2014/01/23 18:16:18 Can you put this in the anonymous namespace above?
sivag 2014/01/24 06:25:17 Done.
105 if (!eglChooseConfig(display,
106 config_attribs,
107 NULL,
108 0,
109 num_configs)) {
110 LOG(ERROR) << "eglChooseConfig failed with error "
111 << GetLastEGLErrorString();
112 return false;
113 }
114 if (*num_configs == 0) {
115 LOG(ERROR) << "No suitable EGL configs found.";
116 return false;
117 }
118 return true;
119 }
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)
107 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay(); 127 g_native_display = base::MessagePumpForUI::GetDefaultXDisplay();
108 #elif defined(OS_WIN) 128 #elif defined(OS_WIN)
109 g_native_display = EGL_DEFAULT_DISPLAY; 129 g_native_display = EGL_DEFAULT_DISPLAY;
110 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) && 130 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableD3D11) &&
(...skipping 19 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 bool config_status = ValidateEglConfig(g_display,
202 config_attribs,
203 &num_configs);
no sievers 2014/01/23 18:16:18 nit: if (!ValidateEglConfig(...)) return f
sivag 2014/01/24 06:25:17 Done.
204 if(!config_status){
205 return false;
206 }
207
208 #if defined(OS_ANDROID)
209 scoped_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]);
210 if (base::android::SysUtils::IsLowEndDevice()) {
211 config_size = num_configs;
212 config_data = matching_configs.get();
213 }
214 #endif
215
159 if (!eglChooseConfig(g_display, 216 if (!eglChooseConfig(g_display,
160 config_attribs, 217 config_attribs,
161 NULL, 218 config_data,
162 0, 219 config_size,
163 &num_configs)) { 220 &num_configs)) {
164 LOG(ERROR) << "eglChooseConfig failed with error " 221 LOG(ERROR) << "eglChooseConfig failed with error "
165 << GetLastEGLErrorString(); 222 << GetLastEGLErrorString();
166 return false; 223 return false;
167 } 224 }
168 225
169 if (num_configs == 0) { 226 #if defined(OS_ANDROID)
170 LOG(ERROR) << "No suitable EGL configs found."; 227 if (base::android::SysUtils::IsLowEndDevice()) {
171 return false; 228 // Because of the EGL config sort order, we have to iterate
229 // through all of them (it'll put higher sum(R,G,B) bits
230 // first with the above attribs).
231 bool match_found = false;
232 for (int i = 0; i < num_configs; i++) {
233 EGLBoolean success;
234 EGLint red, green, blue, alpha;
235 // Read the relevent attributes of the EGLConfig.
236 success = eglGetConfigAttrib(g_display, matching_configs[i],
237 EGL_RED_SIZE, &red);
238 success &= eglGetConfigAttrib(g_display, matching_configs[i],
239 EGL_BLUE_SIZE, &blue);
240 success &= eglGetConfigAttrib(g_display, matching_configs[i],
241 EGL_GREEN_SIZE, &green);
242 success &= eglGetConfigAttrib(g_display, matching_configs[i],
243 EGL_ALPHA_SIZE, &alpha);
244 if ((success == EGL_TRUE) && (red == 5) &&
245 (green == 6) && (blue == 5)) {
246 g_config = matching_configs[i];
247 match_found = true;
248 break;
249 }
250 }
251 if (!match_found) {
252 // To fall back to default 32 bit format, choose with
253 // the right attributes again.
254 config_status = ValidateEglConfig(g_display,
255 config_attribs_8888,
256 &num_configs);
257 if (!config_status) {
no sievers 2014/01/23 18:16:18 nit: same here and no need for |config_status| var
sivag 2014/01/24 06:25:17 Done.
258 return false;
259 }
260 if (!eglChooseConfig(g_display,
261 config_attribs_8888,
262 &g_config,
263 1,
264 &num_configs)) {
265 LOG(ERROR) << "eglChooseConfig failed with error "
266 << GetLastEGLErrorString();
267 return false;
268 }
269 }
172 } 270 }
173 271
174 if (!eglChooseConfig(g_display, 272 #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 273
184 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); 274 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS);
185 g_egl_create_context_robustness_supported = 275 g_egl_create_context_robustness_supported =
186 HasEGLExtension("EGL_EXT_create_context_robustness"); 276 HasEGLExtension("EGL_EXT_create_context_robustness");
187 g_egl_sync_control_supported = 277 g_egl_sync_control_supported =
188 HasEGLExtension("EGL_CHROMIUM_sync_control"); 278 HasEGLExtension("EGL_CHROMIUM_sync_control");
189 279
190 // Check if SurfacelessEGL is supported. 280 // Check if SurfacelessEGL is supported.
191 g_egl_surfaceless_context_supported = 281 g_egl_surfaceless_context_supported =
192 HasEGLExtension("EGL_KHR_surfaceless_context"); 282 HasEGLExtension("EGL_KHR_surfaceless_context");
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 856 }
767 default: 857 default:
768 NOTREACHED(); 858 NOTREACHED();
769 return NULL; 859 return NULL;
770 } 860 }
771 } 861 }
772 862
773 #endif 863 #endif
774 864
775 } // namespace gfx 865 } // 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