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

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

Issue 1480333002: egl/x11: Created a child window to control resizes and prevent flashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved up the call to InitializeNativeWindow() Created 5 years 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 | « ui/gl/gl_surface_egl.h ('k') | ui/gl/gl_surface_egl_x11.h » ('j') | 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 #include "ui/gl/gl_surface_egl.h" 5 #include "ui/gl/gl_surface_egl.h"
6 6
7 #if defined(OS_ANDROID) 7 #if defined(OS_ANDROID)
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #endif 9 #endif
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gl/egl_util.h" 20 #include "ui/gl/egl_util.h"
21 #include "ui/gl/gl_context.h" 21 #include "ui/gl/gl_context.h"
22 #include "ui/gl/gl_image.h" 22 #include "ui/gl/gl_image.h"
23 #include "ui/gl/gl_implementation.h" 23 #include "ui/gl/gl_implementation.h"
24 #include "ui/gl/gl_surface_stub.h" 24 #include "ui/gl/gl_surface_stub.h"
25 #include "ui/gl/gl_switches.h" 25 #include "ui/gl/gl_switches.h"
26 #include "ui/gl/scoped_make_current.h" 26 #include "ui/gl/scoped_make_current.h"
27 #include "ui/gl/sync_control_vsync_provider.h" 27 #include "ui/gl/sync_control_vsync_provider.h"
28 28
29 #if defined(USE_X11)
30 extern "C" {
31 #include <X11/Xlib.h>
32 }
33 #endif
34
35 #if defined (USE_OZONE) 29 #if defined (USE_OZONE)
36 #include "ui/ozone/public/ozone_platform.h" 30 #include "ui/ozone/public/ozone_platform.h"
37 #include "ui/ozone/public/surface_factory_ozone.h" 31 #include "ui/ozone/public/surface_factory_ozone.h"
38 #endif 32 #endif
39 33
40 #if defined(USE_X11) && !defined(OS_CHROMEOS) 34 #if defined(USE_X11) && !defined(OS_CHROMEOS)
41 #include "ui/gfx/x/x11_switches.h" 35 #include "ui/gfx/x/x11_switches.h"
42 #endif 36 #endif
43 37
44 #if !defined(EGL_FIXED_SIZE_ANGLE) 38 #if !defined(EGL_FIXED_SIZE_ANGLE)
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 g_display = display; 459 g_display = display;
466 break; 460 break;
467 } 461 }
468 } 462 }
469 463
470 return g_display; 464 return g_display;
471 } 465 }
472 466
473 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window) 467 NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window)
474 : window_(window), 468 : window_(window),
469 config_(NULL),
470 size_(1, 1),
475 surface_(NULL), 471 surface_(NULL),
476 supports_post_sub_buffer_(false), 472 supports_post_sub_buffer_(false),
477 config_(NULL),
478 size_(1, 1),
479 swap_interval_(1) { 473 swap_interval_(1) {
480 #if defined(OS_ANDROID) 474 #if defined(OS_ANDROID)
481 if (window) 475 if (window)
482 ANativeWindow_acquire(window); 476 ANativeWindow_acquire(window);
483 #endif 477 #endif
484 478
485 #if defined(OS_WIN) 479 #if defined(OS_WIN)
486 vsync_override_ = false; 480 vsync_override_ = false;
487 swap_generation_ = 0; 481 swap_generation_ = 0;
488 RECT windowRect; 482 RECT windowRect;
489 if (GetClientRect(window_, &windowRect)) 483 if (GetClientRect(window_, &windowRect))
490 size_ = gfx::Rect(windowRect).size(); 484 size_ = gfx::Rect(windowRect).size();
491 #endif 485 #endif
492 } 486 }
493 487
494 bool NativeViewGLSurfaceEGL::Initialize() { 488 bool NativeViewGLSurfaceEGL::Initialize() {
495 return Initialize(nullptr); 489 return Initialize(nullptr);
496 } 490 }
497 491
498 bool NativeViewGLSurfaceEGL::Initialize( 492 bool NativeViewGLSurfaceEGL::Initialize(
499 scoped_ptr<VSyncProvider> sync_provider) { 493 scoped_ptr<VSyncProvider> sync_provider) {
500 DCHECK(!surface_); 494 DCHECK(!surface_);
501 495
502 if (!GetDisplay()) { 496 if (!GetDisplay()) {
503 LOG(ERROR) << "Trying to create surface with invalid display."; 497 LOG(ERROR) << "Trying to create surface with invalid display.";
504 return false; 498 return false;
505 } 499 }
506 500
501 // We need to make sure that window_ is correctly initialized with all
502 // the platform-dependant quirks, if any, before creating the surface.
503 if (!InitializeNativeWindow()) {
504 LOG(ERROR) << "Error trying to initialize the native window.";
505 return false;
506 }
507
507 std::vector<EGLint> egl_window_attributes; 508 std::vector<EGLint> egl_window_attributes;
508 509
509 if (g_egl_window_fixed_size_supported) { 510 if (g_egl_window_fixed_size_supported) {
510 egl_window_attributes.push_back(EGL_FIXED_SIZE_ANGLE); 511 egl_window_attributes.push_back(EGL_FIXED_SIZE_ANGLE);
511 egl_window_attributes.push_back(EGL_TRUE); 512 egl_window_attributes.push_back(EGL_TRUE);
512 egl_window_attributes.push_back(EGL_WIDTH); 513 egl_window_attributes.push_back(EGL_WIDTH);
513 egl_window_attributes.push_back(size_.width()); 514 egl_window_attributes.push_back(size_.width());
514 egl_window_attributes.push_back(EGL_HEIGHT); 515 egl_window_attributes.push_back(EGL_HEIGHT);
515 egl_window_attributes.push_back(size_.height()); 516 egl_window_attributes.push_back(size_.height());
516 } 517 }
(...skipping 22 matching lines...) Expand all
539 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE; 540 supports_post_sub_buffer_ = (surfaceVal && retVal) == EGL_TRUE;
540 } 541 }
541 542
542 if (sync_provider) 543 if (sync_provider)
543 vsync_provider_.reset(sync_provider.release()); 544 vsync_provider_.reset(sync_provider.release());
544 else if (g_egl_sync_control_supported) 545 else if (g_egl_sync_control_supported)
545 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_)); 546 vsync_provider_.reset(new EGLSyncControlVSyncProvider(surface_));
546 return true; 547 return true;
547 } 548 }
548 549
550 bool NativeViewGLSurfaceEGL::InitializeNativeWindow() {
551 return true;
552 }
553
549 void NativeViewGLSurfaceEGL::Destroy() { 554 void NativeViewGLSurfaceEGL::Destroy() {
550 if (surface_) { 555 if (surface_) {
551 if (!eglDestroySurface(GetDisplay(), surface_)) { 556 if (!eglDestroySurface(GetDisplay(), surface_)) {
552 LOG(ERROR) << "eglDestroySurface failed with error " 557 LOG(ERROR) << "eglDestroySurface failed with error "
553 << GetLastEGLErrorString(); 558 << GetLastEGLErrorString();
554 } 559 }
555 surface_ = NULL; 560 surface_ = NULL;
556 } 561 }
557 } 562 }
558 563
559 EGLConfig NativeViewGLSurfaceEGL::GetConfig() { 564 EGLConfig NativeViewGLSurfaceEGL::GetConfig() {
560 #if !defined(USE_X11)
561 return g_config; 565 return g_config;
562 #else
563 if (!config_) {
564 // Get a config compatible with the window
565 DCHECK(window_);
566 XWindowAttributes win_attribs;
567 if (!XGetWindowAttributes(GetNativeDisplay(), window_, &win_attribs)) {
568 return NULL;
569 }
570
571 // Try matching the window depth with an alpha channel,
572 // because we're worried the destination alpha width could
573 // constrain blending precision.
574 const int kBufferSizeOffset = 1;
575 const int kAlphaSizeOffset = 3;
576 EGLint config_attribs[] = {
577 EGL_BUFFER_SIZE, ~0,
578 EGL_ALPHA_SIZE, 8,
579 EGL_BLUE_SIZE, 8,
580 EGL_GREEN_SIZE, 8,
581 EGL_RED_SIZE, 8,
582 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
583 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
584 EGL_NONE
585 };
586 config_attribs[kBufferSizeOffset] = win_attribs.depth;
587
588 EGLint num_configs;
589 if (!eglChooseConfig(g_display,
590 config_attribs,
591 &config_,
592 1,
593 &num_configs)) {
594 LOG(ERROR) << "eglChooseConfig failed with error "
595 << GetLastEGLErrorString();
596 return NULL;
597 }
598
599 if (num_configs) {
600 EGLint config_depth;
601 if (!eglGetConfigAttrib(g_display,
602 config_,
603 EGL_BUFFER_SIZE,
604 &config_depth)) {
605 LOG(ERROR) << "eglGetConfigAttrib failed with error "
606 << GetLastEGLErrorString();
607 return NULL;
608 }
609
610 if (config_depth == win_attribs.depth) {
611 return config_;
612 }
613 }
614
615 // Try without an alpha channel.
616 config_attribs[kAlphaSizeOffset] = 0;
617 if (!eglChooseConfig(g_display,
618 config_attribs,
619 &config_,
620 1,
621 &num_configs)) {
622 LOG(ERROR) << "eglChooseConfig failed with error "
623 << GetLastEGLErrorString();
624 return NULL;
625 }
626
627 if (num_configs == 0) {
628 LOG(ERROR) << "No suitable EGL configs found.";
629 return NULL;
630 }
631 }
632 return config_;
633 #endif
634 } 566 }
635 567
636 bool NativeViewGLSurfaceEGL::IsOffscreen() { 568 bool NativeViewGLSurfaceEGL::IsOffscreen() {
637 return false; 569 return false;
638 } 570 }
639 571
640 gfx::SwapResult NativeViewGLSurfaceEGL::SwapBuffers() { 572 gfx::SwapResult NativeViewGLSurfaceEGL::SwapBuffers() {
641 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers", 573 TRACE_EVENT2("gpu", "NativeViewGLSurfaceEGL:RealSwapBuffers",
642 "width", GetSize().width(), 574 "width", GetSize().width(),
643 "height", GetSize().height()); 575 "height", GetSize().height());
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 } 887 }
956 888
957 void* SurfacelessEGL::GetShareHandle() { 889 void* SurfacelessEGL::GetShareHandle() {
958 return NULL; 890 return NULL;
959 } 891 }
960 892
961 SurfacelessEGL::~SurfacelessEGL() { 893 SurfacelessEGL::~SurfacelessEGL() {
962 } 894 }
963 895
964 } // namespace gfx 896 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_surface_egl.h ('k') | ui/gl/gl_surface_egl_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698