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

Unified Diff: gfx/gtk_native_view_id_manager.cc

Issue 5275009: Defer window destruction until GPU finished drawing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with reference counting. Created 10 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
« no previous file with comments | « gfx/gtk_native_view_id_manager.h ('k') | gfx/gtk_preserve_window.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gfx/gtk_native_view_id_manager.cc
diff --git a/gfx/gtk_native_view_id_manager.cc b/gfx/gtk_native_view_id_manager.cc
index 6aa460c6c90ac41ada1a6b05cf4832fa21ce0b5d..8d9334dbcf2ddbbfafd0c1acc5076549539f6380 100644
--- a/gfx/gtk_native_view_id_manager.cc
+++ b/gfx/gtk_native_view_id_manager.cc
@@ -63,7 +63,7 @@ gfx::NativeViewId GtkNativeViewManager::GetIdForWidget(gfx::NativeView widget) {
info.widget = widget;
if (GTK_WIDGET_REALIZED(widget)) {
GdkWindow *gdk_window = widget->window;
- CHECK(gdk_window);
+ DCHECK(gdk_window);
info.x_window_id = GDK_WINDOW_XID(gdk_window);
}
@@ -102,17 +102,52 @@ bool GtkNativeViewManager::GetPermanentXIDForId(XID* output,
// 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;
-
+ DCHECK(GTK_IS_PRESERVE_WINDOW(i->second.widget));
GtkPreserveWindow* widget =
reinterpret_cast<GtkPreserveWindow*>(i->second.widget);
gtk_preserve_window_set_preserve(widget, TRUE);
*output = GDK_WINDOW_XID(i->second.widget->window);
+
+ // Update the reference count on the permanent XID.
+ PermanentXIDInfo info;
+ info.widget = widget;
+ info.ref_count = 1;
+ std::pair<std::map<XID, PermanentXIDInfo>::iterator, bool> ret =
+ perm_xid_to_info_.insert(std::make_pair(*output, info));
+
+ if (!ret.second) {
+ DCHECK(ret.first->second.widget == widget);
+ ret.first->second.ref_count++;
+ }
+
return true;
}
+void GtkNativeViewManager::ReleasePermanentXID(XID xid) {
+ AutoLock locked(lock_);
+
+ std::map<XID, PermanentXIDInfo>::iterator i =
+ perm_xid_to_info_.find(xid);
+
+ if (i == perm_xid_to_info_.end())
+ return;
+
+ if (i->second.ref_count > 1) {
+ i->second.ref_count--;
+ } else {
+ if (i->second.widget) {
+ gtk_preserve_window_set_preserve(i->second.widget, FALSE);
+ } else {
+ GdkWindow* window = reinterpret_cast<GdkWindow*>(
+ gdk_xid_table_lookup(xid));
+ DCHECK(window);
+ gdk_window_destroy(window);
+ }
+ perm_xid_to_info_.erase(i);
+ }
+}
+
// -----------------------------------------------------------------------------
@@ -151,8 +186,6 @@ void GtkNativeViewManager::OnUnrealize(gfx::NativeView widget) {
id_to_info_.find(id);
CHECK(i != id_to_info_.end());
-
- i->second.x_window_id = 0;
}
void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
@@ -166,6 +199,18 @@ void GtkNativeViewManager::OnDestroy(gfx::NativeView widget) {
id_to_info_.find(i->second);
CHECK(j != id_to_info_.end());
+ // If the XID is supposed to outlive the widget, mark it
+ // in the lookup table.
+ if (GTK_IS_PRESERVE_WINDOW(widget) &&
+ gtk_preserve_window_get_preserve(
+ reinterpret_cast<GtkPreserveWindow*>(widget))) {
+ std::map<XID, PermanentXIDInfo>::iterator k =
+ perm_xid_to_info_.find(GDK_WINDOW_XID(widget->window));
+
+ if (k != perm_xid_to_info_.end())
+ k->second.widget = NULL;
+ }
+
native_view_to_id_.erase(i);
id_to_info_.erase(j);
}
« no previous file with comments | « gfx/gtk_native_view_id_manager.h ('k') | gfx/gtk_preserve_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698