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

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

Issue 2616723002: Refactor GL surface format handling (Closed)
Patch Set: Created 3 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
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 #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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 LOG(ERROR) << "eglChooseConfig failed with error " 232 LOG(ERROR) << "eglChooseConfig failed with error "
233 << GetLastEGLErrorString(); 233 << GetLastEGLErrorString();
234 return false; 234 return false;
235 } 235 }
236 if (*num_configs == 0) { 236 if (*num_configs == 0) {
237 return false; 237 return false;
238 } 238 }
239 return true; 239 return true;
240 } 240 }
241 241
242 EGLConfig ChooseConfig(GLSurface::Format format) { 242 EGLConfig ChooseConfig(GLSurfaceFormat format) {
243 // Choose an EGL configuration. 243 // Choose an EGL configuration.
244 // On X this is only used for PBuffer surfaces. 244 // On X this is only used for PBuffer surfaces.
245 std::vector<EGLint> renderable_types; 245 std::vector<EGLint> renderable_types;
246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 246 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
247 switches::kDisableES3GLContext)) { 247 switches::kDisableES3GLContext)) {
248 renderable_types.push_back(EGL_OPENGL_ES3_BIT); 248 renderable_types.push_back(EGL_OPENGL_ES3_BIT);
249 } 249 }
250 renderable_types.push_back(EGL_OPENGL_ES2_BIT); 250 renderable_types.push_back(EGL_OPENGL_ES2_BIT);
251 251
252 EGLint buffer_size = 32; 252 EGLint buffer_size = format.GetBufferSize();
253 EGLint alpha_size = 8; 253 EGLint alpha_size = 8;
254 bool want_rgb565 = buffer_size == 16;
254 255
255 #if defined(USE_X11) && !defined(OS_CHROMEOS) 256 #if defined(USE_X11) && !defined(OS_CHROMEOS)
256 // If we're using ANGLE_NULL, we may not have a display, in which case we 257 // If we're using ANGLE_NULL, we may not have a display, in which case we
257 // can't use XVisualManager. 258 // can't use XVisualManager.
258 if (g_native_display) { 259 if (g_native_display) {
259 ui::XVisualManager::GetInstance()->ChooseVisualForWindow( 260 ui::XVisualManager::GetInstance()->ChooseVisualForWindow(
260 true, nullptr, &buffer_size, nullptr, nullptr); 261 true, nullptr, &buffer_size, nullptr, nullptr);
261 alpha_size = buffer_size == 32 ? 8 : 0; 262 alpha_size = buffer_size == 32 ? 8 : 0;
262 } 263 }
263 #endif 264 #endif
264 265
265 EGLint surface_type = (format == GLSurface::SURFACE_SURFACELESS) 266 EGLint surface_type = (format.IsSurfaceless()
266 ? EGL_DONT_CARE 267 ? EGL_DONT_CARE
267 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT; 268 : EGL_WINDOW_BIT | EGL_PBUFFER_BIT);
268 269
269 for (auto renderable_type : renderable_types) { 270 for (auto renderable_type : renderable_types) {
270 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE, 271 EGLint config_attribs_8888[] = {EGL_BUFFER_SIZE,
271 buffer_size, 272 buffer_size,
272 EGL_ALPHA_SIZE, 273 EGL_ALPHA_SIZE,
273 alpha_size, 274 alpha_size,
274 EGL_BLUE_SIZE, 275 EGL_BLUE_SIZE,
275 8, 276 8,
276 EGL_GREEN_SIZE, 277 EGL_GREEN_SIZE,
277 8, 278 8,
(...skipping 13 matching lines...) Expand all
291 6, 292 6,
292 EGL_RED_SIZE, 293 EGL_RED_SIZE,
293 5, 294 5,
294 EGL_RENDERABLE_TYPE, 295 EGL_RENDERABLE_TYPE,
295 renderable_type, 296 renderable_type,
296 EGL_SURFACE_TYPE, 297 EGL_SURFACE_TYPE,
297 surface_type, 298 surface_type,
298 EGL_NONE}; 299 EGL_NONE};
299 300
300 EGLint* choose_attributes = config_attribs_8888; 301 EGLint* choose_attributes = config_attribs_8888;
301 if (format == GLSurface::SURFACE_RGB565) { 302 if (want_rgb565) {
302 choose_attributes = config_attribs_565; 303 choose_attributes = config_attribs_565;
303 } 304 }
304 305
305 EGLint num_configs; 306 EGLint num_configs;
306 EGLint config_size = 1; 307 EGLint config_size = 1;
307 EGLConfig config = nullptr; 308 EGLConfig config = nullptr;
308 EGLConfig* config_data = &config; 309 EGLConfig* config_data = &config;
309 // Validate if there are any configs for given attribs. 310 // Validate if there are any configs for given attribs.
310 if (!ValidateEglConfig(g_display, choose_attributes, &num_configs)) { 311 if (!ValidateEglConfig(g_display, choose_attributes, &num_configs)) {
311 // Try the next renderable_type 312 // Try the next renderable_type
312 continue; 313 continue;
313 } 314 }
314 315
315 std::unique_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]); 316 std::unique_ptr<EGLConfig[]> matching_configs(new EGLConfig[num_configs]);
316 if (format == GLSurface::SURFACE_RGB565) { 317 if (want_rgb565) {
317 config_size = num_configs; 318 config_size = num_configs;
318 config_data = matching_configs.get(); 319 config_data = matching_configs.get();
319 } 320 }
320 321
321 if (!eglChooseConfig(g_display, choose_attributes, config_data, config_size, 322 if (!eglChooseConfig(g_display, choose_attributes, config_data, config_size,
322 &num_configs)) { 323 &num_configs)) {
323 LOG(ERROR) << "eglChooseConfig failed with error " 324 LOG(ERROR) << "eglChooseConfig failed with error "
324 << GetLastEGLErrorString(); 325 << GetLastEGLErrorString();
325 return config; 326 return config;
326 } 327 }
327 328
328 if (format == GLSurface::SURFACE_RGB565) { 329 if (want_rgb565) {
329 // Because of the EGL config sort order, we have to iterate 330 // Because of the EGL config sort order, we have to iterate
330 // through all of them (it'll put higher sum(R,G,B) bits 331 // through all of them (it'll put higher sum(R,G,B) bits
331 // first with the above attribs). 332 // first with the above attribs).
332 bool match_found = false; 333 bool match_found = false;
333 for (int i = 0; i < num_configs; i++) { 334 for (int i = 0; i < num_configs; i++) {
334 EGLint red, green, blue, alpha; 335 EGLint red, green, blue, alpha;
335 // Read the relevant attributes of the EGLConfig. 336 // Read the relevant attributes of the EGLConfig.
336 if (eglGetConfigAttrib(g_display, matching_configs[i], EGL_RED_SIZE, 337 if (eglGetConfigAttrib(g_display, matching_configs[i], EGL_RED_SIZE,
337 &red) && 338 &red) &&
338 eglGetConfigAttrib(g_display, matching_configs[i], EGL_BLUE_SIZE, 339 eglGetConfigAttrib(g_display, matching_configs[i], EGL_BLUE_SIZE,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 return result; 455 return result;
455 } 456 }
456 457
457 bool EGLSyncControlVSyncProvider::GetMscRate(int32_t* numerator, 458 bool EGLSyncControlVSyncProvider::GetMscRate(int32_t* numerator,
458 int32_t* denominator) { 459 int32_t* denominator) {
459 return false; 460 return false;
460 } 461 }
461 462
462 GLSurfaceEGL::GLSurfaceEGL() {} 463 GLSurfaceEGL::GLSurfaceEGL() {}
463 464
464 GLSurface::Format GLSurfaceEGL::GetFormat() { 465 GLSurfaceFormat GLSurfaceEGL::GetFormat() {
465 return format_; 466 return format_;
466 } 467 }
467 468
468 EGLDisplay GLSurfaceEGL::GetDisplay() { 469 EGLDisplay GLSurfaceEGL::GetDisplay() {
469 return g_display; 470 return g_display;
470 } 471 }
471 472
472 EGLConfig GLSurfaceEGL::GetConfig() { 473 EGLConfig GLSurfaceEGL::GetConfig() {
473 if (!config_) { 474 if (!config_) {
474 config_ = ChooseConfig(format_); 475 config_ = ChooseConfig(format_);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 703
703 #if defined(OS_WIN) 704 #if defined(OS_WIN)
704 vsync_override_ = false; 705 vsync_override_ = false;
705 swap_generation_ = 0; 706 swap_generation_ = 0;
706 RECT windowRect; 707 RECT windowRect;
707 if (GetClientRect(window_, &windowRect)) 708 if (GetClientRect(window_, &windowRect))
708 size_ = gfx::Rect(windowRect).size(); 709 size_ = gfx::Rect(windowRect).size();
709 #endif 710 #endif
710 } 711 }
711 712
712 bool NativeViewGLSurfaceEGL::Initialize(GLSurface::Format format) { 713 bool NativeViewGLSurfaceEGL::Initialize(GLSurfaceFormat format) {
713 format_ = format; 714 format_ = format;
714 return Initialize(nullptr); 715 return Initialize(nullptr);
715 } 716 }
716 717
717 bool NativeViewGLSurfaceEGL::Initialize( 718 bool NativeViewGLSurfaceEGL::Initialize(
718 std::unique_ptr<gfx::VSyncProvider> sync_provider) { 719 std::unique_ptr<gfx::VSyncProvider> sync_provider) {
719 DCHECK(!surface_); 720 DCHECK(!surface_);
720 721
721 if (!GetDisplay()) { 722 if (!GetDisplay()) {
722 LOG(ERROR) << "Trying to create surface with invalid display."; 723 LOG(ERROR) << "Trying to create surface with invalid display.";
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 1058
1058 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size) 1059 PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size)
1059 : size_(size), 1060 : size_(size),
1060 surface_(NULL) { 1061 surface_(NULL) {
1061 // Some implementations of Pbuffer do not support having a 0 size. For such 1062 // Some implementations of Pbuffer do not support having a 0 size. For such
1062 // cases use a (1, 1) surface. 1063 // cases use a (1, 1) surface.
1063 if (size_.GetArea() == 0) 1064 if (size_.GetArea() == 0)
1064 size_.SetSize(1, 1); 1065 size_.SetSize(1, 1);
1065 } 1066 }
1066 1067
1067 bool PbufferGLSurfaceEGL::Initialize() { 1068 bool PbufferGLSurfaceEGL::Initialize(GLSurfaceFormat format) {
1068 GLSurface::Format format = SURFACE_DEFAULT; 1069 EGLSurface old_surface = surface_;
1070
1069 #if defined(OS_ANDROID) 1071 #if defined(OS_ANDROID)
1070 // This is to allow context virtualization which requires on- and offscreen 1072 // This is to allow context virtualization which requires on- and offscreen
1071 // to use a compatible config. We expect the client to request RGB565 1073 // to use a compatible config. We expect the client to request RGB565
1072 // onscreen surface also for this to work (with the exception of 1074 // onscreen surface also for this to work (with the exception of
1073 // fullscreen video). 1075 // fullscreen video).
1074 if (base::SysInfo::IsLowEndDevice()) 1076 if (format.IsDefault() && base::SysInfo::IsLowEndDevice())
1075 format = SURFACE_RGB565; 1077 format = GLSurfaceFormat(GLSurfaceFormat::SURFACE_RGB565);
1076 #endif 1078 #endif
1077 return Initialize(format);
1078 }
1079 1079
1080 bool PbufferGLSurfaceEGL::Initialize(GLSurface::Format format) {
1081 EGLSurface old_surface = surface_;
1082 format_ = format; 1080 format_ = format;
1083 1081
1084 EGLDisplay display = GetDisplay(); 1082 EGLDisplay display = GetDisplay();
1085 if (!display) { 1083 if (!display) {
1086 LOG(ERROR) << "Trying to create surface with invalid display."; 1084 LOG(ERROR) << "Trying to create surface with invalid display.";
1087 return false; 1085 return false;
1088 } 1086 }
1089 1087
1090 // Allocate the new pbuffer surface before freeing the old one to ensure 1088 // Allocate the new pbuffer surface before freeing the old one to ensure
1091 // they have different addresses. If they have the same address then a 1089 // they have different addresses. If they have the same address then a
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 return handle; 1192 return handle;
1195 #endif 1193 #endif
1196 } 1194 }
1197 1195
1198 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() { 1196 PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
1199 Destroy(); 1197 Destroy();
1200 } 1198 }
1201 1199
1202 SurfacelessEGL::SurfacelessEGL(const gfx::Size& size) 1200 SurfacelessEGL::SurfacelessEGL(const gfx::Size& size)
1203 : size_(size) { 1201 : size_(size) {
1204 format_ = GLSurface::SURFACE_SURFACELESS; 1202 format_ = GLSurfaceFormat(GLSurfaceFormat::SURFACE_SURFACELESS);
1205 } 1203 }
1206 1204
1207 bool SurfacelessEGL::Initialize() { 1205 bool SurfacelessEGL::Initialize(GLSurfaceFormat format) {
1208 return Initialize(SURFACE_SURFACELESS); 1206 if (format.IsDefault()) {
bajones 2017/01/04 22:31:55 This feels weird, though I can certainly see how y
klausw 2017/01/05 00:55:13 Changed to set surfaceless unconditionally.
1209 } 1207 format = GLSurfaceFormat(GLSurfaceFormat::SURFACE_SURFACELESS);
1210 1208 }
1211 bool SurfacelessEGL::Initialize(GLSurface::Format format) {
1212 format_ = format; 1209 format_ = format;
1213 return true; 1210 return true;
1214 } 1211 }
1215 1212
1216 void SurfacelessEGL::Destroy() { 1213 void SurfacelessEGL::Destroy() {
1217 } 1214 }
1218 1215
1219 bool SurfacelessEGL::IsOffscreen() { 1216 bool SurfacelessEGL::IsOffscreen() {
1220 return true; 1217 return true;
1221 } 1218 }
(...skipping 23 matching lines...) Expand all
1245 } 1242 }
1246 1243
1247 void* SurfacelessEGL::GetShareHandle() { 1244 void* SurfacelessEGL::GetShareHandle() {
1248 return NULL; 1245 return NULL;
1249 } 1246 }
1250 1247
1251 SurfacelessEGL::~SurfacelessEGL() { 1248 SurfacelessEGL::~SurfacelessEGL() {
1252 } 1249 }
1253 1250
1254 } // namespace gl 1251 } // namespace gl
OLDNEW
« ui/gl/gl_surface.cc ('K') | « ui/gl/gl_surface_egl.h ('k') | ui/gl/gl_surface_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698