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

Side by Side Diff: content/browser/gpu/gpu_process_host_ui_shim.cc

Issue 7054005: Fix gpu acceleration with --in-process-gpu (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: add comment Created 9 years, 7 months 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 | « content/browser/gpu/gpu_process_host_ui_shim.h ('k') | content/gpu/gpu_child_thread.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 5 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
6 6
7 #include "base/command_line.h"
8 #include "base/id_map.h" 7 #include "base/id_map.h"
9 #include "base/process_util.h" 8 #include "base/process_util.h"
10 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
11 #include "chrome/browser/browser_process.h"
12 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
13 #include "content/browser/gpu/gpu_data_manager.h" 11 #include "content/browser/gpu/gpu_data_manager.h"
14 #include "content/browser/gpu/gpu_process_host.h" 12 #include "content/browser/gpu/gpu_process_host.h"
15 #include "content/browser/renderer_host/render_process_host.h" 13 #include "content/browser/renderer_host/render_process_host.h"
16 #include "content/browser/renderer_host/render_view_host.h" 14 #include "content/browser/renderer_host/render_view_host.h"
17 #include "content/browser/renderer_host/render_widget_host_view.h" 15 #include "content/browser/renderer_host/render_widget_host_view.h"
18 #include "content/common/content_switches.h"
19 #include "content/common/gpu/gpu_messages.h" 16 #include "content/common/gpu/gpu_messages.h"
20 17
21 #if defined(OS_LINUX) 18 #if defined(OS_LINUX)
22 // These two #includes need to come after gpu_messages.h. 19 // These two #includes need to come after gpu_messages.h.
23 #include <gdk/gdkwindow.h> // NOLINT 20 #include <gdk/gdkwindow.h> // NOLINT
24 #include <gdk/gdkx.h> // NOLINT 21 #include <gdk/gdkx.h> // NOLINT
25 #include "ui/base/x/x11_util.h" 22 #include "ui/base/x/x11_util.h"
26 #include "ui/gfx/gtk_native_view_id_manager.h"
27 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
28 #endif // defined(OS_LINUX) 24 #endif // defined(OS_LINUX)
29 namespace { 25 namespace {
30 26
31 // One of the linux specific headers defines this as a macro. 27 // One of the linux specific headers defines this as a macro.
32 #ifdef DestroyAll 28 #ifdef DestroyAll
33 #undef DestroyAll 29 #undef DestroyAll
34 #endif 30 #endif
35 31
36 IDMap<GpuProcessHostUIShim> g_hosts_by_id; 32 IDMap<GpuProcessHostUIShim> g_hosts_by_id;
37 33
38 class SendOnIOThreadTask : public Task { 34 class SendOnIOThreadTask : public Task {
39 public: 35 public:
40 SendOnIOThreadTask(int host_id, IPC::Message* msg) 36 SendOnIOThreadTask(int host_id, IPC::Message* msg)
41 : host_id_(host_id), 37 : host_id_(host_id),
42 msg_(msg) { 38 msg_(msg) {
43 } 39 }
44 40
45 private: 41 private:
46 void Run() { 42 void Run() {
47 GpuProcessHost* host = GpuProcessHost::FromID(host_id_); 43 GpuProcessHost* host = GpuProcessHost::FromID(host_id_);
48 if (host) 44 if (host)
49 host->Send(msg_.release()); 45 host->Send(msg_.release());
50 } 46 }
51 47
52 int host_id_; 48 int host_id_;
53 scoped_ptr<IPC::Message> msg_; 49 scoped_ptr<IPC::Message> msg_;
54 }; 50 };
55 51
56 class UIThreadSender : public IPC::Channel::Sender {
57 public:
58 virtual bool Send(IPC::Message* msg) {
59 // The GPU process must never send a synchronous IPC message to the browser
60 // process. This could result in deadlock. Unfortunately linux does this for
61 // GpuHostMsg_ResizeXID. TODO(apatrick): fix this before issuing any GL calls
62 // on the browser process' GPU thread.
63 #if !defined(OS_LINUX)
64 DCHECK(!msg->is_sync());
65 #endif
66
67 // When the GpuChannelManager sends an IPC, post it to the UI thread without
68 // using IPC.
69 bool success = BrowserThread::PostTask(
70 BrowserThread::UI,
71 FROM_HERE,
72 new RouteToGpuProcessHostUIShimTask(0, *msg));
73
74 delete msg;
75 return success;
76 }
77 };
78
79 void ForwardMessageToGpuThread(GpuChannelManager* gpu_channel_manager,
80 IPC::Message* msg) {
81 bool success = gpu_channel_manager->OnMessageReceived(*msg);
82
83 // If the message was not handled, it is likely it was intended for the
84 // GpuChildThread, which does not exist in single process and in process GPU
85 // mode.
86 DCHECK(success);
87
88 delete msg;
89 }
90
91 } // namespace 52 } // namespace
92 53
93 RouteToGpuProcessHostUIShimTask::RouteToGpuProcessHostUIShimTask( 54 RouteToGpuProcessHostUIShimTask::RouteToGpuProcessHostUIShimTask(
94 int host_id, 55 int host_id,
95 const IPC::Message& msg) 56 const IPC::Message& msg)
96 : host_id_(host_id), 57 : host_id_(host_id),
97 msg_(msg) { 58 msg_(msg) {
98 } 59 }
99 60
100 RouteToGpuProcessHostUIShimTask::~RouteToGpuProcessHostUIShimTask() { 61 RouteToGpuProcessHostUIShimTask::~RouteToGpuProcessHostUIShimTask() {
101 } 62 }
102 63
103 void RouteToGpuProcessHostUIShimTask::Run() { 64 void RouteToGpuProcessHostUIShimTask::Run() {
104 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_); 65 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_);
105 if (ui_shim) 66 if (ui_shim)
106 ui_shim->OnMessageReceived(msg_); 67 ui_shim->OnMessageReceived(msg_);
107 } 68 }
108 69
109 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) 70 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id)
110 : host_id_(host_id), 71 : host_id_(host_id) {
111 gpu_channel_manager_(NULL),
112 ui_thread_sender_(NULL) {
113 g_hosts_by_id.AddWithID(this, host_id_); 72 g_hosts_by_id.AddWithID(this, host_id_);
114 if (host_id == 0) {
115 ui_thread_sender_ = new UIThreadSender;
116 gpu_channel_manager_ = new GpuChannelManager(
117 ui_thread_sender_,
118 NULL,
119 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
120 g_browser_process->shutdown_event());
121 }
122 } 73 }
123 74
124 // static 75 // static
125 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { 76 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) {
126 DCHECK(!FromID(host_id)); 77 DCHECK(!FromID(host_id));
127 return new GpuProcessHostUIShim(host_id); 78 return new GpuProcessHostUIShim(host_id);
128 } 79 }
129 80
130 // static 81 // static
131 void GpuProcessHostUIShim::Destroy(int host_id) { 82 void GpuProcessHostUIShim::Destroy(int host_id) {
(...skipping 11 matching lines...) Expand all
143 } 94 }
144 95
145 // static 96 // static
146 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { 97 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 return g_hosts_by_id.Lookup(host_id); 99 return g_hosts_by_id.Lookup(host_id);
149 } 100 }
150 101
151 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { 102 bool GpuProcessHostUIShim::Send(IPC::Message* msg) {
152 DCHECK(CalledOnValidThread()); 103 DCHECK(CalledOnValidThread());
153 104 return BrowserThread::PostTask(BrowserThread::IO,
154 bool success; 105 FROM_HERE,
155 106 new SendOnIOThreadTask(host_id_, msg));
156 if (host_id_ == 0) {
157 success = BrowserThread::PostTask(
158 BrowserThread::GPU,
159 FROM_HERE,
160 NewRunnableFunction(ForwardMessageToGpuThread,
161 gpu_channel_manager_,
162 msg));
163 } else {
164 success = BrowserThread::PostTask(
165 BrowserThread::IO,
166 FROM_HERE,
167 new SendOnIOThreadTask(host_id_, msg));
168 }
169
170 return success;
171 } 107 }
172 108
173 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { 109 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) {
174 DCHECK(CalledOnValidThread()); 110 DCHECK(CalledOnValidThread());
175 111
176 if (message.routing_id() != MSG_ROUTING_CONTROL) 112 if (message.routing_id() != MSG_ROUTING_CONTROL)
177 return false; 113 return false;
178 114
179 return OnControlMessageReceived(message); 115 return OnControlMessageReceived(message);
180 } 116 }
(...skipping 12 matching lines...) Expand all
193 return; 129 return;
194 130
195 ui_shim->Send(msg); 131 ui_shim->Send(msg);
196 } 132 }
197 133
198 #endif 134 #endif
199 135
200 GpuProcessHostUIShim::~GpuProcessHostUIShim() { 136 GpuProcessHostUIShim::~GpuProcessHostUIShim() {
201 DCHECK(CalledOnValidThread()); 137 DCHECK(CalledOnValidThread());
202 g_hosts_by_id.Remove(host_id_); 138 g_hosts_by_id.Remove(host_id_);
203
204 // Ensure these are destroyed on the GPU thread.
205 if (gpu_channel_manager_) {
206 BrowserThread::DeleteSoon(BrowserThread::GPU,
207 FROM_HERE,
208 gpu_channel_manager_);
209 gpu_channel_manager_ = NULL;
210 }
211 if (ui_thread_sender_) {
212 BrowserThread::DeleteSoon(BrowserThread::GPU,
213 FROM_HERE,
214 ui_thread_sender_);
215 ui_thread_sender_ = NULL;
216 }
217 } 139 }
218 140
219 bool GpuProcessHostUIShim::OnControlMessageReceived( 141 bool GpuProcessHostUIShim::OnControlMessageReceived(
220 const IPC::Message& message) { 142 const IPC::Message& message) {
221 DCHECK(CalledOnValidThread()); 143 DCHECK(CalledOnValidThread());
222 144
223 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) 145 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message)
224 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, 146 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage,
225 OnLogMessage) 147 OnLogMessage)
226 #if defined(OS_LINUX) && !defined(TOUCH_UI) || defined(OS_WIN) 148 #if defined(OS_LINUX) && !defined(TOUCH_UI) || defined(OS_WIN)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 params.window, 244 params.window,
323 params.surface_id, 245 params.surface_id,
324 // Parameters needed to formulate an acknowledgment. 246 // Parameters needed to formulate an acknowledgment.
325 params.renderer_id, 247 params.renderer_id,
326 params.route_id, 248 params.route_id,
327 host_id_, 249 host_id_,
328 params.swap_buffers_count); 250 params.swap_buffers_count);
329 } 251 }
330 252
331 #endif 253 #endif
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_process_host_ui_shim.h ('k') | content/gpu/gpu_child_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698