OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
10 #include "base/id_map.h" | 11 #include "base/id_map.h" |
11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
12 #include "base/process_util.h" | 13 #include "base/process_util.h" |
13 #include "content/browser/gpu/gpu_data_manager.h" | 14 #include "content/browser/gpu/gpu_data_manager.h" |
14 #include "content/browser/gpu/gpu_process_host.h" | 15 #include "content/browser/gpu/gpu_process_host.h" |
15 #include "content/browser/renderer_host/render_process_host_impl.h" | 16 #include "content/browser/renderer_host/render_process_host_impl.h" |
16 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
17 #include "content/browser/renderer_host/render_widget_host_view.h" | 18 #include "content/browser/renderer_host/render_widget_host_view.h" |
18 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
(...skipping 12 matching lines...) Expand all Loading... |
31 namespace { | 32 namespace { |
32 | 33 |
33 // One of the linux specific headers defines this as a macro. | 34 // One of the linux specific headers defines this as a macro. |
34 #ifdef DestroyAll | 35 #ifdef DestroyAll |
35 #undef DestroyAll | 36 #undef DestroyAll |
36 #endif | 37 #endif |
37 | 38 |
38 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = | 39 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = |
39 LAZY_INSTANCE_INITIALIZER; | 40 LAZY_INSTANCE_INITIALIZER; |
40 | 41 |
41 class SendOnIOThreadTask : public Task { | 42 void SendOnIOThreadTask(int host_id, IPC::Message* msg) { |
42 public: | 43 GpuProcessHost* host = GpuProcessHost::FromID(host_id); |
43 SendOnIOThreadTask(int host_id, IPC::Message* msg) | 44 if (host) |
44 : host_id_(host_id), | 45 host->Send(msg); |
45 msg_(msg) { | 46 else |
46 } | 47 delete msg; |
47 | 48 } |
48 private: | |
49 void Run() { | |
50 GpuProcessHost* host = GpuProcessHost::FromID(host_id_); | |
51 if (host) | |
52 host->Send(msg_.release()); | |
53 } | |
54 | |
55 int host_id_; | |
56 scoped_ptr<IPC::Message> msg_; | |
57 }; | |
58 | 49 |
59 class ScopedSendOnIOThread { | 50 class ScopedSendOnIOThread { |
60 public: | 51 public: |
61 ScopedSendOnIOThread(int host_id, IPC::Message* msg) | 52 ScopedSendOnIOThread(int host_id, IPC::Message* msg) |
62 : host_id_(host_id), | 53 : host_id_(host_id), |
63 msg_(msg), | 54 msg_(msg), |
64 cancelled_(false) { | 55 cancelled_(false) { |
65 } | 56 } |
66 | 57 |
67 ~ScopedSendOnIOThread() { | 58 ~ScopedSendOnIOThread() { |
68 if (!cancelled_) { | 59 if (!cancelled_) { |
69 BrowserThread::PostTask(BrowserThread::IO, | 60 BrowserThread::PostTask(BrowserThread::IO, |
70 FROM_HERE, | 61 FROM_HERE, |
71 new SendOnIOThreadTask(host_id_, | 62 base::Bind(&SendOnIOThreadTask, |
72 msg_.release())); | 63 host_id_, |
| 64 msg_.release())); |
73 } | 65 } |
74 } | 66 } |
75 | 67 |
76 void Cancel() { cancelled_ = true; } | 68 void Cancel() { cancelled_ = true; } |
77 | 69 |
78 private: | 70 private: |
79 int host_id_; | 71 int host_id_; |
80 scoped_ptr<IPC::Message> msg_; | 72 scoped_ptr<IPC::Message> msg_; |
81 bool cancelled_; | 73 bool cancelled_; |
82 }; | 74 }; |
83 | 75 |
84 RenderWidgetHostView* GetRenderWidgetHostViewFromID(int render_process_id, | 76 RenderWidgetHostView* GetRenderWidgetHostViewFromID(int render_process_id, |
85 int render_widget_id) { | 77 int render_widget_id) { |
86 content::RenderProcessHost* process = | 78 content::RenderProcessHost* process = |
87 content::RenderProcessHost::FromID(render_process_id); | 79 content::RenderProcessHost::FromID(render_process_id); |
88 if (!process) | 80 if (!process) |
89 return NULL; | 81 return NULL; |
90 | 82 |
91 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( | 83 RenderWidgetHost* host = static_cast<RenderWidgetHost*>( |
92 process->GetListenerByID(render_widget_id)); | 84 process->GetListenerByID(render_widget_id)); |
93 return host ? host->view() : NULL; | 85 return host ? host->view() : NULL; |
94 } | 86 } |
95 | 87 |
96 } // namespace | 88 } // namespace |
97 | 89 |
98 RouteToGpuProcessHostUIShimTask::RouteToGpuProcessHostUIShimTask( | 90 void RouteToGpuProcessHostUIShimTask(int host_id, const IPC::Message& msg) { |
99 int host_id, | 91 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id); |
100 const IPC::Message& msg) | |
101 : host_id_(host_id), | |
102 msg_(msg) { | |
103 } | |
104 | |
105 RouteToGpuProcessHostUIShimTask::~RouteToGpuProcessHostUIShimTask() { | |
106 } | |
107 | |
108 void RouteToGpuProcessHostUIShimTask::Run() { | |
109 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(host_id_); | |
110 if (ui_shim) | 92 if (ui_shim) |
111 ui_shim->OnMessageReceived(msg_); | 93 ui_shim->OnMessageReceived(msg); |
112 } | 94 } |
113 | 95 |
114 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) | 96 GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id) |
115 : host_id_(host_id) { | 97 : host_id_(host_id) { |
116 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); | 98 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); |
117 } | 99 } |
118 | 100 |
119 // static | 101 // static |
120 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { | 102 GpuProcessHostUIShim* GpuProcessHostUIShim::Create(int host_id) { |
121 DCHECK(!FromID(host_id)); | 103 DCHECK(!FromID(host_id)); |
(...skipping 27 matching lines...) Expand all Loading... |
149 if (g_hosts_by_id.Pointer()->IsEmpty()) | 131 if (g_hosts_by_id.Pointer()->IsEmpty()) |
150 return NULL; | 132 return NULL; |
151 IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer()); | 133 IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer()); |
152 return it.GetCurrentValue(); | 134 return it.GetCurrentValue(); |
153 } | 135 } |
154 | 136 |
155 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { | 137 bool GpuProcessHostUIShim::Send(IPC::Message* msg) { |
156 DCHECK(CalledOnValidThread()); | 138 DCHECK(CalledOnValidThread()); |
157 return BrowserThread::PostTask(BrowserThread::IO, | 139 return BrowserThread::PostTask(BrowserThread::IO, |
158 FROM_HERE, | 140 FROM_HERE, |
159 new SendOnIOThreadTask(host_id_, msg)); | 141 base::Bind(&SendOnIOThreadTask, |
| 142 host_id_, |
| 143 msg)); |
160 } | 144 } |
161 | 145 |
162 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { | 146 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { |
163 DCHECK(CalledOnValidThread()); | 147 DCHECK(CalledOnValidThread()); |
164 | 148 |
165 if (message.routing_id() != MSG_ROUTING_CONTROL) | 149 if (message.routing_id() != MSG_ROUTING_CONTROL) |
166 return false; | 150 return false; |
167 | 151 |
168 return OnControlMessageReceived(message); | 152 return OnControlMessageReceived(message); |
169 } | 153 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( | 361 void GpuProcessHostUIShim::OnAcceleratedSurfaceRelease( |
378 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { | 362 const GpuHostMsg_AcceleratedSurfaceRelease_Params& params) { |
379 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( | 363 RenderWidgetHostView* view = GetRenderWidgetHostViewFromID( |
380 params.renderer_id, params.render_view_id); | 364 params.renderer_id, params.render_view_id); |
381 if (!view) | 365 if (!view) |
382 return; | 366 return; |
383 view->AcceleratedSurfaceRelease(params.identifier); | 367 view->AcceleratedSurfaceRelease(params.identifier); |
384 } | 368 } |
385 | 369 |
386 #endif | 370 #endif |
OLD | NEW |