summaryrefslogtreecommitdiffstats
path: root/gfx
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
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')
-rw-r--r--gfx/gfx.gyp2
-rw-r--r--gfx/gtk_native_view_id_manager.cc114
-rw-r--r--gfx/gtk_native_view_id_manager.h22
-rw-r--r--gfx/gtk_preserve_window.cc164
-rw-r--r--gfx/gtk_preserve_window.h58
5 files changed, 245 insertions, 115 deletions
diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp
index 0d3b3d0..f655bdd 100644
--- a/gfx/gfx.gyp
+++ b/gfx/gfx.gyp
@@ -168,6 +168,8 @@
'sources': [
'gtk_native_view_id_manager.cc',
'gtk_native_view_id_manager.h',
+ 'gtk_preserve_window.cc',
+ 'gtk_preserve_window.h',
'gtk_util.cc',
'gtk_util.h',
'native_theme_linux.cc',
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);
- }
-}
-
// -----------------------------------------------------------------------------
diff --git a/gfx/gtk_native_view_id_manager.h b/gfx/gtk_native_view_id_manager.h
index 439d843..513537a 100644
--- a/gfx/gtk_native_view_id_manager.h
+++ b/gfx/gtk_native_view_id_manager.h
@@ -6,7 +6,6 @@
#define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_
#pragma once
-#include <gtk/gtk.h>
#include <map>
#include "base/singleton.h"
@@ -60,16 +59,11 @@ class GtkNativeViewManager {
// |*xid| is set to 0.
bool GetXIDForId(XID* xid, gfx::NativeViewId id);
- // Generate an XID that doesn't change.
+ // Must be called from the UI thread because we may need the associated
+ // widget to create a window.
//
- // The GPU process assumes that the XID associated with a GL context
- // does not change. To maintain this invariant we create and overlay
- // whose XID is static. This requires reparenting as the underlying
- // window comes and goes. It incurs a bit of overhead, so a permanent
- // XID must be requested.
- //
- // Must be called from the UI thread so that the widget that we
- // overlay does not change while we construct the overlay.
+ // Keeping the XID permanent requires a bit of overhead, so it must
+ // be explicitly requested.
//
// xid: (output) the resulting X window
// id: a value previously returned from GetIdForWidget
@@ -80,7 +74,6 @@ class GtkNativeViewManager {
void OnRealize(gfx::NativeView widget);
void OnUnrealize(gfx::NativeView widget);
void OnDestroy(gfx::NativeView widget);
- void OnSizeAllocate(gfx::NativeView widget, GtkAllocation *alloc);
Lock& unrealize_lock() { return unrealize_lock_; }
@@ -91,11 +84,10 @@ class GtkNativeViewManager {
friend struct DefaultSingletonTraits<GtkNativeViewManager>;
struct NativeViewInfo {
- NativeViewInfo() : x_window_id(0), permanent_window_id(0) { }
- // XID associated with GTK widget.
+ NativeViewInfo() : widget(NULL), x_window_id(0) {
+ }
+ gfx::NativeView widget;
XID x_window_id;
- // Permanent overlay (0 if not requested yet).
- XID permanent_window_id;
};
gfx::NativeViewId GetWidgetId(gfx::NativeView id);
diff --git a/gfx/gtk_preserve_window.cc b/gfx/gtk_preserve_window.cc
new file mode 100644
index 0000000..576ddfa
--- /dev/null
+++ b/gfx/gtk_preserve_window.cc
@@ -0,0 +1,164 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "gfx/gtk_preserve_window.h"
+
+#include <gdk/gdkwindow.h>
+#include <gtk/gtk.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkfixed.h>
+
+G_BEGIN_DECLS
+
+#define GTK_PRESERVE_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+ GTK_TYPE_PRESERVE_WINDOW, \
+ GtkPreserveWindowPrivate))
+
+typedef struct _GtkPreserveWindowPrivate GtkPreserveWindowPrivate;
+
+struct _GtkPreserveWindowPrivate {
+ // If true, don't create/destroy windows on realize/unrealize.
+ gboolean preserve_window;
+};
+
+G_DEFINE_TYPE(GtkPreserveWindow, gtk_preserve_window, GTK_TYPE_FIXED)
+
+static void gtk_preserve_window_destroy(GtkObject* object);
+static void gtk_preserve_window_realize(GtkWidget* widget);
+static void gtk_preserve_window_unrealize(GtkWidget* widget);
+
+static void gtk_preserve_window_class_init(GtkPreserveWindowClass *klass) {
+ GtkWidgetClass* widget_class = reinterpret_cast<GtkWidgetClass*>(klass);
+ widget_class->realize = gtk_preserve_window_realize;
+ widget_class->unrealize = gtk_preserve_window_unrealize;
+
+ GtkObjectClass* object_class = reinterpret_cast<GtkObjectClass*>(klass);
+ object_class->destroy = gtk_preserve_window_destroy;
+
+ GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
+ g_type_class_add_private(gobject_class, sizeof(GtkPreserveWindowPrivate));
+}
+
+static void gtk_preserve_window_init(GtkPreserveWindow* widget) {
+ GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(widget);
+ priv->preserve_window = FALSE;
+
+ // These widgets always have their own window.
+ gtk_fixed_set_has_window(GTK_FIXED(widget), TRUE);
+}
+
+GtkWidget* gtk_preserve_window_new() {
+ return GTK_WIDGET(g_object_new(GTK_TYPE_PRESERVE_WINDOW, NULL));
+}
+
+static void gtk_preserve_window_destroy(GtkObject* object) {
+ GtkWidget* widget = reinterpret_cast<GtkWidget*>(object);
+
+ if (widget->window) {
+ gdk_window_set_user_data(widget->window, NULL);
+ gdk_window_destroy(widget->window);
+ widget->window = NULL;
+ }
+
+ GTK_OBJECT_CLASS(gtk_preserve_window_parent_class)->destroy(object);
+}
+
+static void gtk_preserve_window_realize(GtkWidget* widget) {
+ g_return_if_fail(GTK_IS_PRESERVE_WINDOW(widget));
+
+ if (widget->window) {
+ gdk_window_reparent(widget->window,
+ gtk_widget_get_parent_window(widget),
+ widget->allocation.x,
+ widget->allocation.y);
+ widget->style = gtk_style_attach(widget->style, widget->window);
+ gdk_window_set_user_data(widget->window, widget);
+
+ // Deprecated as of GTK 2.22. Used for compatibility.
+ // It should be: gtk_widget_set_realized(widget, TRUE)
+ GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
+ } else {
+ GTK_WIDGET_CLASS(gtk_preserve_window_parent_class)->realize(widget);
+ }
+}
+
+static void gtk_preserve_window_unrealize(GtkWidget* widget) {
+ g_return_if_fail(GTK_IS_PRESERVE_WINDOW(widget));
+
+ GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(widget);
+ if (priv->preserve_window) {
+ GtkWidgetClass* widget_class =
+ GTK_WIDGET_CLASS(gtk_preserve_window_parent_class);
+ GtkContainerClass* container_class =
+ GTK_CONTAINER_CLASS(gtk_preserve_window_parent_class);
+
+ // Deprecated as of GTK 2.22. Used for compatibility.
+ // It should be: gtk_widget_get_mapped()
+ if (GTK_WIDGET_MAPPED(widget)) {
+ widget_class->unmap(widget);
+
+ // Deprecated as of GTK 2.22. Used for compatibility.
+ // It should be: gtk_widget_set_mapped(widget, FALSE)
+ GTK_WIDGET_UNSET_FLAGS(widget, GTK_MAPPED);
+ }
+
+ // This is the behavior from GtkWidget, inherited by GtkFixed.
+ // It is unclear why we should not call the potentially overridden
+ // unrealize method (via the callback), but doing so causes errors.
+ container_class->forall(
+ GTK_CONTAINER(widget), FALSE,
+ reinterpret_cast<GtkCallback>(gtk_widget_unrealize), NULL);
+
+ gtk_style_detach(widget->style);
+ gdk_window_reparent(widget->window, gdk_get_default_root_window(), 0, 0);
+ gtk_selection_remove_all(widget);
+ gdk_window_set_user_data(widget->window, NULL);
+
+ // Deprecated as of GTK 2.22. Used for compatibility.
+ // It should be: gtk_widget_set_realized(widget, FALSE)
+ GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED);
+ } else {
+ GTK_WIDGET_CLASS(gtk_preserve_window_parent_class)->unrealize(widget);
+ }
+}
+
+gboolean gtk_preserve_window_get_preserve(GtkPreserveWindow* window) {
+ g_return_val_if_fail(GTK_IS_PRESERVE_WINDOW(window), FALSE);
+ GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(window);
+
+ return priv->preserve_window;
+}
+
+void gtk_preserve_window_set_preserve(GtkPreserveWindow* window,
+ gboolean value) {
+ g_return_if_fail(GTK_IS_PRESERVE_WINDOW(window));
+ GtkPreserveWindowPrivate* priv = GTK_PRESERVE_WINDOW_GET_PRIVATE(window);
+ priv->preserve_window = value;
+
+ GtkWidget* widget = GTK_WIDGET(window);
+ if (value && !widget->window) {
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+
+ // We may not know the width and height, so we rely on the fact
+ // that a size-allocation will resize it later.
+ attributes.width = 1;
+ attributes.height = 1;
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+
+ attributes.visual = gtk_widget_get_visual(widget);
+ attributes.colormap = gtk_widget_get_colormap(widget);
+
+ attributes.event_mask = gtk_widget_get_events(widget);
+ attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
+
+ attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ widget->window = gdk_window_new(
+ gdk_get_default_root_window(), &attributes, attributes_mask);
+ }
+}
+
+G_END_DECLS
diff --git a/gfx/gtk_preserve_window.h b/gfx/gtk_preserve_window.h
new file mode 100644
index 0000000..285d82c
--- /dev/null
+++ b/gfx/gtk_preserve_window.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef GFX_GTK_PRESERVE_WINDOW_H_
+#define GFX_GTK_PRESERVE_WINDOW_H_
+#pragma once
+
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+
+// GtkFixed creates an X window when realized and destroys an X window
+// when unrealized. GtkPreserveWindow allows overrides this
+// behaviour. When preserve is set (via gtk_preserve_window_set_preserve),
+// the X window is only destroyed when the widget is destroyed.
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_PRESERVE_WINDOW \
+ (gtk_preserve_window_get_type())
+#define GTK_PRESERVE_WINDOW(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_PERSERVE_WINDOW, \
+ GtkPreserveWindow))
+#define GTK_PRESERVE_WINDOW_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_PRESERVE_WINDOW, \
+ GtkPreserveWindowClass))
+#define GTK_IS_PRESERVE_WINDOW(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_PRESERVE_WINDOW))
+#define GTK_IS_PRESERVE_WINDOW_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_PRESERVE_WINDOW))
+#define GTK_PRESERVE_WINDOW_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_PRESERVE_WINDOW, \
+ GtkPreserveWindowClass))
+
+typedef struct _GtkPreserveWindow GtkPreserveWindow;
+typedef struct _GtkPreserveWindowClass GtkPreserveWindowClass;
+
+struct _GtkPreserveWindow {
+ // Parent class.
+ GtkFixed fixed;
+};
+
+struct _GtkPreserveWindowClass {
+ GtkFixedClass parent_class;
+};
+
+GType gtk_preserve_window_get_type() G_GNUC_CONST;
+GtkWidget* gtk_preserve_window_new();
+
+// Whether or not we should preserve associated windows as the widget
+// is realized or unrealized.
+gboolean gtk_preserve_window_get_preserve(GtkPreserveWindow* widget);
+void gtk_preserve_window_set_preserve(GtkPreserveWindow* widget,
+ gboolean value);
+
+G_END_DECLS
+
+#endif // GFX_GTK_PRESERVE_WINDOW_H_