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

Unified 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: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« ui/gl/gl_surface_egl.h ('K') | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_surface_egl.cc
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
index 8352ff6b1f501b4a7091092720272ccd4ce7476a..a9e029181a6d0d51a842f53cf5f9a975fa4c5531 100644
--- a/ui/gl/gl_surface_egl.cc
+++ b/ui/gl/gl_surface_egl.cc
@@ -30,6 +30,7 @@
extern "C" {
#include <X11/Xlib.h>
}
+#include "ui/events/platform/platform_event_source.h"
#endif
#if defined (USE_OZONE)
@@ -472,6 +473,9 @@ EGLDisplay GLSurfaceEGL::InitializeDisplay() {
NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window)
: window_(window),
+#if defined(USE_X11)
+ parent_window_(0),
+#endif
surface_(NULL),
supports_post_sub_buffer_(false),
config_(NULL),
@@ -489,6 +493,12 @@ NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(EGLNativeWindowType window)
if (GetClientRect(window_, &windowRect))
size_ = gfx::Rect(windowRect).size();
#endif
+
+#if defined(USE_X11)
+ // We use a child XWindow for X11, to help avoiding artifacts while resizing.
+ parent_window_ = window_;
+ window_ = 0;
+#endif
}
bool NativeViewGLSurfaceEGL::Initialize() {
@@ -504,6 +514,39 @@ bool NativeViewGLSurfaceEGL::Initialize(
return false;
}
+#if defined(USE_X11)
+ Display* x11_display = GetNativeDisplay();
+ XWindowAttributes attributes;
+ if (!XGetWindowAttributes(x11_display, parent_window_, &attributes)) {
+ LOG(ERROR) << "XGetWindowAttributes failed for window " << parent_window_
+ << ".";
+ return false;
+ }
+
+ size_ = gfx::Size(attributes.width, attributes.height);
+
+ // Create a child window, with a CopyFromParent visual (to avoid inducing
+ // extra blits in the driver), that we can resize exactly in Resize(),
+ // correctly ordered with GL, so that we don't have invalid transient states.
+ // See https://crbug.com/326995.
+ XSetWindowAttributes swa;
+ memset(&swa, 0, sizeof(swa));
+ swa.background_pixmap = 0;
+ swa.bit_gravity = NorthWestGravity;
+ window_ = XCreateWindow(x11_display, parent_window_, 0, 0, size_.width(),
+ size_.height(), 0, CopyFromParent, InputOutput,
+ CopyFromParent, CWBackPixmap | CWBitGravity, &swa);
+ XMapWindow(x11_display, window_);
+
+ ui::PlatformEventSource* source = ui::PlatformEventSource::GetInstance();
+ // The event source can be nullptr in tests, when we don't care about Exposes.
+ if (source) {
+ XSelectInput(x11_display, window_, ExposureMask);
+ source->AddPlatformEventDispatcher(this);
+ }
+ XFlush(x11_display);
+#endif // USE_X11
+
std::vector<EGLint> egl_window_attributes;
if (g_egl_window_fixed_size_supported) {
@@ -554,6 +597,19 @@ void NativeViewGLSurfaceEGL::Destroy() {
}
surface_ = NULL;
}
+
+#if defined(USE_X11)
+ if (window_) {
+ ui::PlatformEventSource* source = ui::PlatformEventSource::GetInstance();
+ if (source)
+ source->RemovePlatformEventDispatcher(this);
+
+ Display* x11_display = GetNativeDisplay();
+ XDestroyWindow(x11_display, window_);
+ window_ = 0;
+ XFlush(x11_display);
+ }
+#endif
}
EGLConfig NativeViewGLSurfaceEGL::GetConfig() {
@@ -705,6 +761,11 @@ bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size, float scale_factor) {
size_ = size;
+#if defined(USE_X11)
+ eglWaitGL();
+ XResizeWindow(GetNativeDisplay(), window_, size.width(), size.height());
+ eglWaitNative(EGL_CORE_NATIVE_ENGINE);
+#else
scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
GLContext* current_context = GLContext::GetCurrent();
bool was_current =
@@ -721,6 +782,7 @@ bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size, float scale_factor) {
LOG(ERROR) << "Failed to resize window.";
return false;
}
+#endif
return true;
}
@@ -788,6 +850,22 @@ NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
#endif
}
+#if defined(USE_X11)
+bool NativeViewGLSurfaceEGL::CanDispatchEvent(const ui::PlatformEvent& event) {
+ return event->type == Expose && event->xexpose.window == window_;
+}
+
+uint32_t NativeViewGLSurfaceEGL::DispatchEvent(const ui::PlatformEvent& event) {
+ XEvent x_event = *event;
+ x_event.xexpose.window = parent_window_;
+
+ Display* x11_display = GetNativeDisplay();
+ XSendEvent(x11_display, parent_window_, False, ExposureMask, &x_event);
+ XFlush(x11_display);
+ return ui::POST_DISPATCH_STOP_PROPAGATION;
+}
+#endif
+
PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size)
: size_(size),
surface_(NULL) {
« ui/gl/gl_surface_egl.h ('K') | « ui/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698