Chromium Code Reviews| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 << GetLastEGLErrorString(); | 244 << GetLastEGLErrorString(); |
| 245 return false; | 245 return false; |
| 246 } | 246 } |
| 247 if (*num_configs == 0) { | 247 if (*num_configs == 0) { |
| 248 LOG(ERROR) << "No suitable EGL configs found."; | 248 LOG(ERROR) << "No suitable EGL configs found."; |
| 249 return false; | 249 return false; |
| 250 } | 250 } |
| 251 return true; | 251 return true; |
| 252 } | 252 } |
| 253 | 253 |
| 254 EGLConfig ChooseConfig(GLSurface::Format format) { | 254 EGLConfig ChooseConfig(GLSurface::Format format, bool is_surfaceless) { |
| 255 static std::map<GLSurface::Format, EGLConfig> config_map; | 255 static std::map<std::pair<GLSurface::Format, bool>, EGLConfig> config_map; |
|
no sievers
2016/03/08 22:02:00
It seems odd that surfaceless even cares about |Fo
kylechar
2016/03/09 15:07:30
This is all sort of black magic to me (and documen
| |
| 256 | 256 |
| 257 if (config_map.find(format) != config_map.end()) { | 257 auto config_type = std::make_pair(format, is_surfaceless); |
| 258 return config_map[format]; | 258 if (config_map.find(config_type) != config_map.end()) { |
| 259 return config_map[config_type]; | |
| 259 } | 260 } |
| 260 | 261 |
| 261 // Choose an EGL configuration. | 262 // Choose an EGL configuration. |
| 262 // On X this is only used for PBuffer surfaces. | 263 // On X this is only used for PBuffer surfaces. |
| 263 EGLint renderable_type = EGL_OPENGL_ES2_BIT; | 264 EGLint renderable_type = EGL_OPENGL_ES2_BIT; |
| 264 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 265 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 265 switches::kEnableUnsafeES3APIs)) { | 266 switches::kEnableUnsafeES3APIs)) { |
| 266 renderable_type = EGL_OPENGL_ES3_BIT; | 267 renderable_type = EGL_OPENGL_ES3_BIT; |
| 267 } | 268 } |
| 268 | 269 |
| 269 EGLint buffer_size = 32; | 270 EGLint buffer_size = 32; |
| 270 EGLint alpha_size = 8; | 271 EGLint alpha_size = 8; |
| 271 | 272 |
| 272 #if defined(USE_X11) && !defined(OS_CHROMEOS) | 273 #if defined(USE_X11) && !defined(OS_CHROMEOS) |
| 273 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 274 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 274 switches::kWindowDepth)) { | 275 switches::kWindowDepth)) { |
| 275 std::string depth = | 276 std::string depth = |
| 276 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 277 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 277 switches::kWindowDepth); | 278 switches::kWindowDepth); |
| 278 | 279 |
| 279 bool succeed = base::StringToInt(depth, &buffer_size); | 280 bool succeed = base::StringToInt(depth, &buffer_size); |
| 280 DCHECK(succeed); | 281 DCHECK(succeed); |
| 281 | 282 |
| 282 alpha_size = buffer_size == 32 ? 8 : 0; | 283 alpha_size = buffer_size == 32 ? 8 : 0; |
| 283 } | 284 } |
| 284 #endif | 285 #endif |
| 285 | 286 |
| 287 EGLint surface_type = | |
| 288 is_surfaceless ? EGL_DONT_CARE : EGL_WINDOW_BIT | EGL_PBUFFER_BIT; | |
| 289 | |
| 286 EGLint config_attribs_8888[] = { | 290 EGLint config_attribs_8888[] = { |
| 287 EGL_BUFFER_SIZE, buffer_size, | 291 EGL_BUFFER_SIZE, buffer_size, |
| 288 EGL_ALPHA_SIZE, alpha_size, | 292 EGL_ALPHA_SIZE, alpha_size, |
| 289 EGL_BLUE_SIZE, 8, | 293 EGL_BLUE_SIZE, 8, |
| 290 EGL_GREEN_SIZE, 8, | 294 EGL_GREEN_SIZE, 8, |
| 291 EGL_RED_SIZE, 8, | 295 EGL_RED_SIZE, 8, |
| 292 EGL_RENDERABLE_TYPE, renderable_type, | 296 EGL_RENDERABLE_TYPE, renderable_type, |
| 293 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 297 EGL_SURFACE_TYPE, surface_type, |
| 294 EGL_NONE | 298 EGL_NONE |
| 295 }; | 299 }; |
| 296 | 300 |
| 297 EGLint* choose_attributes = config_attribs_8888; | 301 EGLint* choose_attributes = config_attribs_8888; |
| 298 EGLint config_attribs_565[] = { | 302 EGLint config_attribs_565[] = { |
| 299 EGL_BUFFER_SIZE, 16, | 303 EGL_BUFFER_SIZE, 16, |
| 300 EGL_BLUE_SIZE, 5, | 304 EGL_BLUE_SIZE, 5, |
| 301 EGL_GREEN_SIZE, 6, | 305 EGL_GREEN_SIZE, 6, |
| 302 EGL_RED_SIZE, 5, | 306 EGL_RED_SIZE, 5, |
| 303 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 307 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 304 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 308 EGL_SURFACE_TYPE, surface_type, |
| 305 EGL_NONE | 309 EGL_NONE |
| 306 }; | 310 }; |
| 307 if (format == GLSurface::SURFACE_RGB565) { | 311 if (format == GLSurface::SURFACE_RGB565) { |
| 308 choose_attributes = config_attribs_565; | 312 choose_attributes = config_attribs_565; |
| 309 } | 313 } |
| 310 | 314 |
| 311 EGLint num_configs; | 315 EGLint num_configs; |
| 312 EGLint config_size = 1; | 316 EGLint config_size = 1; |
| 313 EGLConfig config = nullptr; | 317 EGLConfig config = nullptr; |
| 314 EGLConfig* config_data = &config; | 318 EGLConfig* config_data = &config; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 config_attribs_8888, | 371 config_attribs_8888, |
| 368 &config, | 372 &config, |
| 369 1, | 373 1, |
| 370 &num_configs)) { | 374 &num_configs)) { |
| 371 LOG(ERROR) << "eglChooseConfig failed with error " | 375 LOG(ERROR) << "eglChooseConfig failed with error " |
| 372 << GetLastEGLErrorString(); | 376 << GetLastEGLErrorString(); |
| 373 return config; | 377 return config; |
| 374 } | 378 } |
| 375 } | 379 } |
| 376 } | 380 } |
| 377 config_map[format] = config; | 381 config_map[config_type] = config; |
| 378 return config; | 382 return config; |
| 379 } | 383 } |
| 380 | 384 |
| 381 } // namespace | 385 } // namespace |
| 382 | 386 |
| 383 void GetEGLInitDisplays(bool supports_angle_d3d, | 387 void GetEGLInitDisplays(bool supports_angle_d3d, |
| 384 bool supports_angle_opengl, | 388 bool supports_angle_opengl, |
| 385 const base::CommandLine* command_line, | 389 const base::CommandLine* command_line, |
| 386 std::vector<DisplayType>* init_displays) { | 390 std::vector<DisplayType>* init_displays) { |
| 387 // SwiftShader does not use the platform extensions | 391 // SwiftShader does not use the platform extensions |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 | 503 |
| 500 return true; | 504 return true; |
| 501 } | 505 } |
| 502 | 506 |
| 503 EGLDisplay GLSurfaceEGL::GetDisplay() { | 507 EGLDisplay GLSurfaceEGL::GetDisplay() { |
| 504 return g_display; | 508 return g_display; |
| 505 } | 509 } |
| 506 | 510 |
| 507 EGLConfig GLSurfaceEGL::GetConfig() { | 511 EGLConfig GLSurfaceEGL::GetConfig() { |
| 508 if (!config_) { | 512 if (!config_) { |
| 509 config_ = ChooseConfig(format_); | 513 config_ = ChooseConfig(format_, IsSurfaceless()); |
| 510 } | 514 } |
| 511 return config_; | 515 return config_; |
| 512 } | 516 } |
| 513 | 517 |
| 514 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { | 518 EGLDisplay GLSurfaceEGL::GetHardwareDisplay() { |
| 515 return g_display; | 519 return g_display; |
| 516 } | 520 } |
| 517 | 521 |
| 518 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { | 522 EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() { |
| 519 return g_native_display; | 523 return g_native_display; |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 } | 1111 } |
| 1108 | 1112 |
| 1109 void* SurfacelessEGL::GetShareHandle() { | 1113 void* SurfacelessEGL::GetShareHandle() { |
| 1110 return NULL; | 1114 return NULL; |
| 1111 } | 1115 } |
| 1112 | 1116 |
| 1113 SurfacelessEGL::~SurfacelessEGL() { | 1117 SurfacelessEGL::~SurfacelessEGL() { |
| 1114 } | 1118 } |
| 1115 | 1119 |
| 1116 } // namespace gfx | 1120 } // namespace gfx |
| OLD | NEW |