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

Side by Side Diff: gfx/gtk_native_view_id_manager.h

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 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 | Annotate | Revision Log
« no previous file with comments | « chrome/gpu/gpu_command_buffer_stub.cc ('k') | gfx/gtk_native_view_id_manager.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ 5 #ifndef GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_
6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ 6 #define GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/singleton.h" 11 #include "base/singleton.h"
12 #include "gfx/native_widget_types.h" 12 #include "gfx/native_widget_types.h"
13 13
14 typedef unsigned long XID; 14 typedef unsigned long XID;
15 struct _GtkPreserveWindow;
15 16
16 // NativeViewIds are the opaque values which the renderer holds as a reference 17 // NativeViewIds are the opaque values which the renderer holds as a reference
17 // to a window. These ids are often used in sync calls from the renderer and 18 // to a window. These ids are often used in sync calls from the renderer and
18 // one cannot terminate sync calls on the UI thread as that can lead to 19 // one cannot terminate sync calls on the UI thread as that can lead to
19 // deadlocks. 20 // deadlocks.
20 // 21 //
21 // Because of this, we have the BACKGROUND_X11 thread for these calls and this 22 // Because of this, we have the BACKGROUND_X11 thread for these calls and this
22 // thread has a separate X connection in order to answer them. But one cannot 23 // thread has a separate X connection in order to answer them. But one cannot
23 // use GTK on multiple threads, so the BACKGROUND_X11 thread deals only in Xlib 24 // use GTK on multiple threads, so the BACKGROUND_X11 thread deals only in Xlib
24 // calls and, thus, XIDs. 25 // calls and, thus, XIDs.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // widget to create a window. 64 // widget to create a window.
64 // 65 //
65 // Keeping the XID permanent requires a bit of overhead, so it must 66 // Keeping the XID permanent requires a bit of overhead, so it must
66 // be explicitly requested. 67 // be explicitly requested.
67 // 68 //
68 // xid: (output) the resulting X window 69 // xid: (output) the resulting X window
69 // id: a value previously returned from GetIdForWidget 70 // id: a value previously returned from GetIdForWidget
70 // returns: true if |id| is a valid id, false otherwise. 71 // returns: true if |id| is a valid id, false otherwise.
71 bool GetPermanentXIDForId(XID* xid, gfx::NativeViewId id); 72 bool GetPermanentXIDForId(XID* xid, gfx::NativeViewId id);
72 73
74 // Must be called from the UI thread because we may need to access a
75 // GtkWidget or destroy a GdkWindow.
76 //
77 // If the widget associated with the XID is still alive, allow the widget
78 // to destroy the associated XID when it wants. Otherwise, destroy the
79 // GdkWindow associated with the XID.
80 void ReleasePermanentXID(XID xid);
81
73 // These are actually private functions, but need to be called from statics. 82 // These are actually private functions, but need to be called from statics.
74 void OnRealize(gfx::NativeView widget); 83 void OnRealize(gfx::NativeView widget);
75 void OnUnrealize(gfx::NativeView widget); 84 void OnUnrealize(gfx::NativeView widget);
76 void OnDestroy(gfx::NativeView widget); 85 void OnDestroy(gfx::NativeView widget);
77 86
78 Lock& unrealize_lock() { return unrealize_lock_; } 87 Lock& unrealize_lock() { return unrealize_lock_; }
79 88
80 private: 89 private:
81 // This object is a singleton: 90 // This object is a singleton:
82 GtkNativeViewManager(); 91 GtkNativeViewManager();
(...skipping 15 matching lines...) Expand all
98 Lock unrealize_lock_; 107 Lock unrealize_lock_;
99 108
100 // protects native_view_to_id_ and id_to_info_ 109 // protects native_view_to_id_ and id_to_info_
101 Lock lock_; 110 Lock lock_;
102 111
103 // If asked for an id for the same widget twice, we want to return the same 112 // If asked for an id for the same widget twice, we want to return the same
104 // id. So this records the current mapping. 113 // id. So this records the current mapping.
105 std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_; 114 std::map<gfx::NativeView, gfx::NativeViewId> native_view_to_id_;
106 std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_; 115 std::map<gfx::NativeViewId, NativeViewInfo> id_to_info_;
107 116
117 struct PermanentXIDInfo {
118 PermanentXIDInfo() : widget(NULL), ref_count(0) {
119 }
120 _GtkPreserveWindow* widget;
121 int ref_count;
122 };
123
124 // Used to maintain the reference count for permanent XIDs
125 // (referenced by GetPermanentXIDForId and dereferenced by
126 // ReleasePermanentXID). Only those XIDs with a positive reference count
127 // will be in the table.
128 //
129 // In general, several GTK widgets may share the same X window. We assume
130 // that is not true of the widgets stored in this registry.
131 //
132 // An XID will map to NULL, if there is an outstanding reference but the
133 // widget was destroyed. In this case, the destruction of the X window
134 // is deferred to the dropping of all references.
135 std::map<XID, PermanentXIDInfo> perm_xid_to_info_;
136
108 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager); 137 DISALLOW_COPY_AND_ASSIGN(GtkNativeViewManager);
109 }; 138 };
110 139
111 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_ 140 #endif // GFX_GTK_NATIVE_VIEW_ID_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_command_buffer_stub.cc ('k') | gfx/gtk_native_view_id_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698