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

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: cleanup 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
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_message_hub.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 {
39 public:
40 SendOnIOThreadTask(int host_id, IPC::Message* msg)
41 : host_id_(host_id),
42 msg_(msg) {
43 }
44
45 private:
46 void Run() {
47 GpuProcessHost* host = GpuProcessHost::FromID(host_id_);
48 if (host)
49 host->Send(msg_.release());
50 }
51
52 int host_id_;
53 scoped_ptr<IPC::Message> msg_;
54 };
55
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 34 } // namespace
92 35
93 RouteToGpuProcessHostUIShimTask::RouteToGpuProcessHostUIShimTask(
94 int host_id,
95 const IPC::Message& msg)
96 : host_id_(host_id),
97 msg_(msg) {
98 }
99
100 RouteToGpuProcessHostUIShimTask::~RouteToGpuProcessHostUIShimTask() {
101 }
102
103 void RouteToGpuProcessHostUIShimTask::Run() {
104 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_);
105 if (ui_shim)
106 ui_shim->OnMessageReceived(msg_);
107 }
108
109 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) 36 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id)
110 : host_id_(host_id), 37 : host_id_(host_id) {
111 gpu_channel_manager_(NULL),
112 ui_thread_sender_(NULL) {
113 g_hosts_by_id.AddWithID(this, host_id_); 38 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 } 39 }
123 40
124 // static 41 // static
125 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { 42 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) {
126 DCHECK(!FromID(host_id)); 43 DCHECK(!FromID(host_id));
127 return new GpuProcessHostUIShim(host_id); 44 return new GpuProcessHostUIShim(host_id);
128 } 45 }
129 46
130 // static 47 // static
131 void GpuProcessHostUIShim::Destroy(int host_id) { 48 void GpuProcessHostUIShim::Destroy(int host_id) {
(...skipping 11 matching lines...) Expand all
143 } 60 }
144 61
145 // static 62 // static
146 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) { 63 GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) {
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
148 return g_hosts_by_id.Lookup(host_id); 65 return g_hosts_by_id.Lookup(host_id);
149 } 66 }
150 67
151 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { 68 bool GpuProcessHostUIShim::Send(IPC::Message* msg) {
152 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
153 70 return GpuMessageHub::SendToGPU(host_id_, msg);
154 bool success;
155
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 } 71 }
172 72
173 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { 73 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) {
174 DCHECK(CalledOnValidThread()); 74 DCHECK(CalledOnValidThread());
175 75
176 if (message.routing_id() != MSG_ROUTING_CONTROL) 76 if (message.routing_id() != MSG_ROUTING_CONTROL)
177 return false; 77 return false;
178 78
179 return OnControlMessageReceived(message); 79 return OnControlMessageReceived(message);
180 } 80 }
(...skipping 12 matching lines...) Expand all
193 return; 93 return;
194 94
195 ui_shim->Send(msg); 95 ui_shim->Send(msg);
196 } 96 }
197 97
198 #endif 98 #endif
199 99
200 GpuProcessHostUIShim::~GpuProcessHostUIShim() { 100 GpuProcessHostUIShim::~GpuProcessHostUIShim() {
201 DCHECK(CalledOnValidThread()); 101 DCHECK(CalledOnValidThread());
202 g_hosts_by_id.Remove(host_id_); 102 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 } 103 }
218 104
219 bool GpuProcessHostUIShim::OnControlMessageReceived( 105 bool GpuProcessHostUIShim::OnControlMessageReceived(
220 const IPC::Message& message) { 106 const IPC::Message& message) {
221 DCHECK(CalledOnValidThread()); 107 DCHECK(CalledOnValidThread());
222 108
223 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) 109 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message)
224 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage, 110 IPC_MESSAGE_HANDLER(GpuHostMsg_OnLogMessage,
225 OnLogMessage) 111 OnLogMessage)
226 #if defined(OS_LINUX) && !defined(TOUCH_UI) || defined(OS_WIN) 112 #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, 208 params.window,
323 params.surface_id, 209 params.surface_id,
324 // Parameters needed to formulate an acknowledgment. 210 // Parameters needed to formulate an acknowledgment.
325 params.renderer_id, 211 params.renderer_id,
326 params.route_id, 212 params.route_id,
327 host_id_, 213 host_id_,
328 params.swap_buffers_count); 214 params.swap_buffers_count);
329 } 215 }
330 216
331 #endif 217 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698