summaryrefslogtreecommitdiffstats
path: root/gfx/gtk_native_view_id_manager.cc
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 19:22:44 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 19:22:44 +0000
commita89a7314517eda116348ae314289cde228fc637b (patch)
treea0247c61a7236df87b7f14ee48160dcf8e4cec2b /gfx/gtk_native_view_id_manager.cc
parent34c190328b287081617fc0f36592ac4a45c2a213 (diff)
downloadchromium_src-a89a7314517eda116348ae314289cde228fc637b.zip
chromium_src-a89a7314517eda116348ae314289cde228fc637b.tar.gz
chromium_src-a89a7314517eda116348ae314289cde228fc637b.tar.bz2
Alternative to overlays on X windows.
Created a new GTK widget that gives us more control over when X windows (associated with GL contexts) are created and destroyed. This achieves the same thing as the overlay code (now reverted). It fixes two regressions with the overlay code: - maps.google.com and html5test.com now work (switching between software and hardware rendering) - expose events now get through in accelerated mode BUG=58862,59887 TEST=Go to html5test.com. Should switch contents to show results. Disable compositing window manager. Go to http://peter.sh/2010/06/chromium-now-features-gpu-acceleration-and-css-3d-transforms/. Adjust the rotate z slider to enable accelerated compositing. Drag a different window over top. Redraws should happen. Review URL: http://codereview.chromium.org/3973009 Patch from Jonathan Backer <backer@chromium.org>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64291 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/gtk_native_view_id_manager.cc')
-rw-r--r--gfx/gtk_native_view_id_manager.cc114
1 files changed, 14 insertions, 100 deletions
diff --git a/gfx/gtk_native_view_id_manager.cc b/gfx/gtk_native_view_id_manager.cc
index 680ec13..6aa460c 100644
--- a/gfx/gtk_native_view_id_manager.cc
+++ b/gfx/gtk_native_view_id_manager.cc
@@ -6,16 +6,13 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
-#include <gdk/gdk.h>
-#include <X11/Xlib.h>
#include "base/logging.h"
#include "base/rand_util.h"
-#include "gfx/rect.h"
+#include "gfx/gtk_preserve_window.h"
// -----------------------------------------------------------------------------
// Bounce functions for GTK to callback into a C++ object...
-namespace {
void OnRealize(gfx::NativeView widget, void* arg) {
GtkNativeViewManager* manager = reinterpret_cast<GtkNativeViewManager*>(arg);
@@ -27,64 +24,11 @@ void OnUnrealize(gfx::NativeView widget, void *arg) {
manager->OnUnrealize(widget);
}
-void OnDestroy(GtkObject* obj, void* arg) {
+static void OnDestroy(GtkObject* obj, void* arg) {
GtkNativeViewManager* manager = reinterpret_cast<GtkNativeViewManager*>(arg);
manager->OnDestroy(reinterpret_cast<GtkWidget*>(obj));
}
-void OnSizeAllocate(gfx::NativeView widget,
- GtkAllocation* alloc,
- void* arg) {
- GtkNativeViewManager* manager = reinterpret_cast<GtkNativeViewManager*>(arg);
- manager->OnSizeAllocate(widget, alloc);
-}
-
-XID CreateOverlay(XID underlying) {
- XID overlay = 0;
- Display* dpy = gdk_x11_get_default_xdisplay();
-
- // Prevent interference with reparenting/mapping of overlay
- XSetWindowAttributes attr;
- attr.override_redirect = True;
-
- if (underlying) {
- XID root;
- int x, y;
- unsigned int width, height;
- unsigned int border_width;
- unsigned int depth;
- XGetGeometry(
- dpy, underlying, &root, &x, &y,
- &width, &height, &border_width, &depth);
- overlay = XCreateWindow(
- dpy, // display
- underlying, // parent
- 0, 0, width, height, // x, y, width, height
- 0, // border width
- CopyFromParent, // depth
- InputOutput, // class
- CopyFromParent, // visual
- CWOverrideRedirect, // value mask
- &attr); // value attributes
- XMapWindow(dpy, overlay);
- } else {
- overlay = XCreateWindow(
- dpy, // display
- gdk_x11_get_default_root_xwindow(), // parent
- 0, 0, 1, 1, // x, y, width, height
- 0, // border width
- CopyFromParent, // depth
- InputOutput, // class
- CopyFromParent, // visual
- CWOverrideRedirect, // value mask
- &attr); // value attributes
- }
- XSync(dpy, False);
- return overlay;
-}
-
-}
-
// -----------------------------------------------------------------------------
@@ -116,19 +60,19 @@ gfx::NativeViewId GtkNativeViewManager::GetIdForWidget(gfx::NativeView widget) {
new_id = static_cast<gfx::NativeViewId>(base::RandUint64());
NativeViewInfo info;
+ info.widget = widget;
if (GTK_WIDGET_REALIZED(widget)) {
GdkWindow *gdk_window = widget->window;
CHECK(gdk_window);
info.x_window_id = GDK_WINDOW_XID(gdk_window);
}
+
native_view_to_id_[widget] = new_id;
id_to_info_[new_id] = info;
g_signal_connect(widget, "realize", G_CALLBACK(::OnRealize), this);
g_signal_connect(widget, "unrealize", G_CALLBACK(::OnUnrealize), this);
g_signal_connect(widget, "destroy", G_CALLBACK(::OnDestroy), this);
- g_signal_connect(
- widget, "size-allocate", G_CALLBACK(::OnSizeAllocate), this);
return new_id;
}
@@ -151,16 +95,21 @@ bool GtkNativeViewManager::GetPermanentXIDForId(XID* output,
AutoLock locked(lock_);
std::map<gfx::NativeViewId, NativeViewInfo>::iterator i =
- id_to_info_.find(id);
+ id_to_info_.find(id);
if (i == id_to_info_.end())
return false;
- if (!i->second.permanent_window_id) {
- i->second.permanent_window_id = CreateOverlay(i->second.x_window_id);
- }
+ // We only return permanent XIDs for widgets that allow us to guarantee that
+ // the XID will not change.
+ if (!GTK_IS_PRESERVE_WINDOW(i->second.widget))
+ return false;
+
+ GtkPreserveWindow* widget =
+ reinterpret_cast<GtkPreserveWindow*>(i->second.widget);
+ gtk_preserve_window_set_preserve(widget, TRUE);
- *output = i->second.permanent_window_id;
+ *output = GDK_WINDOW_XID(i->second.widget->window);
return true;
}
@@ -191,14 +140,6 @@ void GtkNativeViewManager::OnRealize(gfx::NativeView widget) {
CHECK(widget->window);
i->second.x_window_id = GDK_WINDOW_XID(widget->window);
-
- if (i->second.permanent_window_id) {
- Display* dpy = gdk_x11_get_default_xdisplay();
- XReparentWindow(
- dpy, i->second.permanent_window_id, i->second.x_window_id, 0, 0);
- XMapWindow(dpy, i->second.permanent_window_id);
- XSync(dpy, False);
- }
}
void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) {
@@ -212,13 +153,6 @@ void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) {
CHECK(i != id_to_info_.end());
i->second.x_window_id = 0;
- if (i->second.permanent_window_id) {
- Display* dpy = gdk_x11_get_default_xdisplay();
- XUnmapWindow(dpy, i->second.permanent_window_id);
- XReparentWindow(dpy, i->second.permanent_window_id,
- gdk_x11_get_default_root_xwindow(), 0, 0);
- XSync(dpy, False);
- }
}
void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
@@ -232,28 +166,8 @@ void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
id_to_info_.find(i->second);
CHECK(j != id_to_info_.end());
- if (j->second.permanent_window_id) {
- XDestroyWindow(gdk_x11_get_default_xdisplay(),
- j->second.permanent_window_id);
- }
-
native_view_to_id_.erase(i);
id_to_info_.erase(j);
}
-void GtkNativeViewManager::OnSizeAllocate(
- gfx::NativeView widget, GtkAllocation *alloc) {
- AutoLock locked(lock_);
-
- const gfx::NativeViewId id = GetWidgetId(widget);
- std::map<gfx::NativeViewId, NativeViewInfo>::iterator i =
- id_to_info_.find(id);
-
- if (i->second.permanent_window_id) {
- XResizeWindow(gdk_x11_get_default_xdisplay(),
- i->second.permanent_window_id,
- alloc->width, alloc->height);
- }
-}
-
// -----------------------------------------------------------------------------