OLD | NEW |
---|---|
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 #include "ui/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 if (!eglChooseConfig(display, | 242 if (!eglChooseConfig(display, |
243 config_attribs, | 243 config_attribs, |
244 NULL, | 244 NULL, |
245 0, | 245 0, |
246 num_configs)) { | 246 num_configs)) { |
247 LOG(ERROR) << "eglChooseConfig failed with error " | 247 LOG(ERROR) << "eglChooseConfig failed with error " |
248 << GetLastEGLErrorString(); | 248 << GetLastEGLErrorString(); |
249 return false; | 249 return false; |
250 } | 250 } |
251 if (*num_configs == 0) { | 251 if (*num_configs == 0) { |
252 LOG(ERROR) << "No suitable EGL configs found."; | |
253 return false; | 252 return false; |
254 } | 253 } |
255 return true; | 254 return true; |
256 } | 255 } |
257 | 256 |
258 EGLConfig ChooseConfig(GLSurface::Format format) { | 257 EGLConfig ChooseConfig(GLSurface::Format format) { |
259 static std::map<GLSurface::Format, EGLConfig> config_map; | 258 static std::map<GLSurface::Format, EGLConfig> config_map; |
260 | 259 |
261 if (config_map.find(format) != config_map.end()) { | 260 if (config_map.find(format) != config_map.end()) { |
262 return config_map[format]; | 261 return config_map[format]; |
263 } | 262 } |
264 | 263 |
265 // Choose an EGL configuration. | 264 // Choose an EGL configuration. |
266 // On X this is only used for PBuffer surfaces. | 265 // On X this is only used for PBuffer surfaces. |
267 EGLint renderable_type = EGL_OPENGL_ES2_BIT; | 266 std::vector<EGLint> renderable_types; |
268 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 267 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
269 switches::kEnableUnsafeES3APIs)) { | 268 switches::kEnableUnsafeES3APIs)) { |
270 renderable_type = EGL_OPENGL_ES3_BIT; | 269 renderable_types.push_back(EGL_OPENGL_ES3_BIT); |
271 } | 270 } |
271 renderable_types.push_back(EGL_OPENGL_ES2_BIT); | |
272 | 272 |
273 EGLint buffer_size = 32; | 273 EGLint buffer_size = 32; |
274 EGLint alpha_size = 8; | 274 EGLint alpha_size = 8; |
275 | 275 |
276 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 276 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
277 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 277 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
278 switches::kWindowDepth)) { | 278 switches::kWindowDepth)) { |
279 std::string depth = | 279 std::string depth = |
280 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 280 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
281 switches::kWindowDepth); | 281 switches::kWindowDepth); |
282 | 282 |
283 bool succeed = base::StringToInt(depth, &buffer_size); | 283 bool succeed = base::StringToInt(depth, &buffer_size); |
284 DCHECK(succeed); | 284 DCHECK(succeed); |
285 | 285 |
286 alpha_size = buffer_size == 32 ? 8 : 0; | 286 alpha_size = buffer_size == 32 ? 8 : 0; |
287 } | 287 } |
288 #endif | 288 #endif |
289 | 289 |
290 EGLint surface_type = (format == GLSurface::SURFACE_SURFACELESS) | 290 EGLint surface_type = (format == GLSurface::SURFACE_SURFACELESS) |
291 ? EGL_DONT_CARE | 291 ? EGL_DONT_CARE |
292 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT; | 292 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT; |
293 | 293 |
294 EGLint config_attribs_8888[] = { | 294 for (auto renderable_type : renderable_types) { |
295 EGL_BUFFER_SIZE, buffer_size, | 295 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, |
Geoff Lang
2016/09/07 14:56:14
This block produced a pretty bad diff, no changes
| |
296 EGL_ALPHA_SIZE, alpha_size, | 296 buffer_size, |
297 EGL_BLUE_SIZE, 8, | 297 EGL_ALPHA_SIZE, |
298 EGL_GREEN_SIZE, 8, | 298 alpha_size, |
299 EGL_RED_SIZE, 8, | 299 EGL_BLUE_SIZE, |
300 EGL_RENDERABLE_TYPE, renderable_type, | 300 8, |
301 EGL_SURFACE_TYPE, surface_type, | 301 EGL_GREEN_SIZE, |
302 EGL_NONE | 302 8, |
303 }; | 303 EGL_RED_SIZE, |
304 8, | |
305 EGL_RENDERABLE_TYPE, | |
306 renderable_type, | |
307 EGL_SURFACE_TYPE, | |
308 surface_type, | |
309 EGL_NONE}; | |
304 | 310 |
305 EGLint* choose_attributes = config_attribs_8888; | 311 EGLint config_attribs_565[] = {EGL_BUFFER_SIZE, |
306 EGLint config_attribs_565[] = { | 312 16, |
307 EGL_BUFFER_SIZE, 16, | 313 EGL_BLUE_SIZE, |
308 EGL_BLUE_SIZE, 5, | 314 5, |
309 EGL_GREEN_SIZE, 6, | 315 EGL_GREEN_SIZE, |
310 EGL_RED_SIZE, 5, | 316 6, |
311 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 317 EGL_RED_SIZE, |
312 EGL_SURFACE_TYPE, surface_type, | 318 5, |
313 EGL_NONE | 319 EGL_RENDERABLE_TYPE, |
314 }; | 320 renderable_type, |
315 if (format == GLSurface::SURFACE_RGB565) { | 321 EGL_SURFACE_TYPE, |
316 choose_attributes = config_attribs_565; | 322 surface_type, |
317 } | 323 EGL_NONE}; |
318 | 324 |
319 EGLint num_configs; | 325 EGLint* choose_attributes = config_attribs_8888; |
320 EGLint config_size = 1; | 326 if (format == GLSurface::SURFACE_RGB565) { |
321 EGLConfig config = nullptr; | 327 choose_attributes = config_attribs_565; |
322 EGLConfig* config_data = &config; | 328 } |
323 // Validate if there are any configs for given attribs. | 329 |
324 if (!ValidateEglConfig(g_display, choose_attributes, &num_configs)) { | 330 EGLint num_configs; |
331 EGLint config_size = 1; | |
332 EGLConfig config = nullptr; | |
333 EGLConfig* config_data = &config; | |
334 // Validate if there are any configs for given attribs. | |
335 if (!ValidateEglConfig(g_display, choose_attributes, &num_configs)) { | |
336 // Try the next renderable_type | |
337 continue; | |
338 } | |
339 | |
340 std::unique_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); | |
341 if (format == GLSurface::SURFACE_RGB565) { | |
342 config_size = num_configs; | |
343 config_data = matching_configs.get(); | |
344 } | |
345 | |
346 if (!eglChooseConfig(g_display, choose_attributes, config_data, config_size, | |
347 &num_configs)) { | |
348 LOG(ERROR) << "eglChooseConfig failed with error " | |
349 << GetLastEGLErrorString(); | |
350 return config; | |
351 } | |
352 | |
353 if (format == GLSurface::SURFACE_RGB565) { | |
354 // Because of the EGL config sort order, we have to iterate | |
355 // through all of them (it'll put higher sum(R,G,B) bits | |
356 // first with the above attribs). | |
357 bool match_found = false; | |
358 for (int i = 0; i < num_configs; i++) { | |
359 EGLint red, green, blue, alpha; | |
360 // Read the relevant attributes of the EGLConfig. | |
361 if (eglGetConfigAttrib(g_display, matching_configs[i], EGL_RED_SIZE, | |
362 &red) && | |
363 eglGetConfigAttrib(g_display, matching_configs[i], EGL_BLUE_SIZE, | |
364 &blue) && | |
365 eglGetConfigAttrib(g_display, matching_configs[i], EGL_GREEN_SIZE, | |
366 &green) && | |
367 eglGetConfigAttrib(g_display, matching_configs[i], EGL_ALPHA_SIZE, | |
368 &alpha) && | |
369 alpha == 0 && red == 5 && green == 6 && blue == 5) { | |
370 config = matching_configs[i]; | |
371 match_found = true; | |
372 break; | |
373 } | |
374 } | |
375 if (!match_found) { | |
376 // To fall back to default 32 bit format, choose with | |
377 // the right attributes again. | |
378 if (!ValidateEglConfig(g_display, config_attribs_8888, &num_configs)) { | |
379 // Try the next renderable_type | |
380 continue; | |
381 } | |
382 if (!eglChooseConfig(g_display, config_attribs_8888, &config, 1, | |
383 &num_configs)) { | |
384 LOG(ERROR) << "eglChooseConfig failed with error " | |
385 << GetLastEGLErrorString(); | |
386 return config; | |
387 } | |
388 } | |
389 } | |
390 config_map[format] = config; | |
325 return config; | 391 return config; |
326 } | 392 } |
327 | 393 |
328 std::unique_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); | 394 LOG(ERROR) << "No suitable EGL configs found."; |
329 if (format == GLSurface::SURFACE_RGB565) { | 395 return nullptr; |
330 config_size = num_configs; | |
331 config_data = matching_configs.get(); | |
332 } | |
333 | |
334 if (!eglChooseConfig(g_display, choose_attributes, config_data, config_size, | |
335 &num_configs)) { | |
336 LOG(ERROR) << "eglChooseConfig failed with error " | |
337 << GetLastEGLErrorString(); | |
338 return config; | |
339 } | |
340 | |
341 if (format == GLSurface::SURFACE_RGB565) { | |
342 // Because of the EGL config sort order, we have to iterate | |
343 // through all of them (it'll put higher sum(R,G,B) bits | |
344 // first with the above attribs). | |
345 bool match_found = false; | |
346 for (int i = 0; i < num_configs; i++) { | |
347 EGLint red, green, blue, alpha; | |
348 // Read the relevant attributes of the EGLConfig. | |
349 if (eglGetConfigAttrib(g_display, matching_configs[i], | |
350 EGL_RED_SIZE, &red) && | |
351 eglGetConfigAttrib(g_display, matching_configs[i], | |
352 EGL_BLUE_SIZE, &blue) && | |
353 eglGetConfigAttrib(g_display, matching_configs[i], | |
354 EGL_GREEN_SIZE, &green) && | |
355 eglGetConfigAttrib(g_display, matching_configs[i], | |
356 EGL_ALPHA_SIZE, &alpha) && | |
357 alpha == 0 && | |
358 red == 5 && | |
359 green == 6 && | |
360 blue == 5) { | |
361 config = matching_configs[i]; | |
362 match_found = true; | |
363 break; | |
364 } | |
365 } | |
366 if (!match_found) { | |
367 // To fall back to default 32 bit format, choose with | |
368 // the right attributes again. | |
369 if (!ValidateEglConfig(g_display, | |
370 config_attribs_8888, | |
371 &num_configs)) { | |
372 return config; | |
373 } | |
374 if (!eglChooseConfig(g_display, | |
375 config_attribs_8888, | |
376 &config, | |
377 1, | |
378 &num_configs)) { | |
379 LOG(ERROR) << "eglChooseConfig failed with error " | |
380 << GetLastEGLErrorString(); | |
381 return config; | |
382 } | |
383 } | |
384 } | |
385 config_map[format] = config; | |
386 return config; | |
387 } | 396 } |
388 | 397 |
389 } // namespace | 398 } // namespace |
390 | 399 |
391 void GetEGLInitDisplays(bool supports_angle_d3d, | 400 void GetEGLInitDisplays(bool supports_angle_d3d, |
392 bool supports_angle_opengl, | 401 bool supports_angle_opengl, |
393 const base::CommandLine* command_line, | 402 const base::CommandLine* command_line, |
394 std::vector<DisplayType>* init_displays) { | 403 std::vector<DisplayType>* init_displays) { |
395 // SwiftShader does not use the platform extensions | 404 // SwiftShader does not use the platform extensions |
396 if (command_line->GetSwitchValueASCII(switches::kUseGL) == | 405 if (command_line->GetSwitchValueASCII(switches::kUseGL) == |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 } | 1155 } |
1147 | 1156 |
1148 void* SurfacelessEGL::GetShareHandle() { | 1157 void* SurfacelessEGL::GetShareHandle() { |
1149 return NULL; | 1158 return NULL; |
1150 } | 1159 } |
1151 | 1160 |
1152 SurfacelessEGL::~SurfacelessEGL() { | 1161 SurfacelessEGL::~SurfacelessEGL() { |
1153 } | 1162 } |
1154 | 1163 |
1155 } // namespace gl | 1164 } // namespace gl |
OLD | NEW |