| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/id_map.h" | 12 #include "base/id_map.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "content/browser/gpu/gpu_data_manager_impl.h" | 15 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 16 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
| 17 #include "content/browser/gpu/gpu_surface_tracker.h" | 17 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 18 #include "content/browser/renderer_host/render_process_host_impl.h" | 18 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 21 #include "content/common/gpu/gpu_messages.h" | 21 #include "content/common/gpu/gpu_messages.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "ui/gl/gl_switches.h" | 23 #include "ui/gl/gl_switches.h" |
| 24 | 24 |
| 25 #if defined(USE_OZONE) |
| 26 #include "ui/ozone/gpu/gpu_platform_support_host.h" |
| 27 #endif |
| 28 |
| 25 namespace content { | 29 namespace content { |
| 26 | 30 |
| 27 namespace { | 31 namespace { |
| 28 | 32 |
| 29 // One of the linux specific headers defines this as a macro. | 33 // One of the linux specific headers defines this as a macro. |
| 30 #ifdef DestroyAll | 34 #ifdef DestroyAll |
| 31 #undef DestroyAll | 35 #undef DestroyAll |
| 32 #endif | 36 #endif |
| 33 | 37 |
| 34 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = | 38 base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id = |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 105 } |
| 102 | 106 |
| 103 // static | 107 // static |
| 104 void GpuProcessHostUIShim::Destroy(int host_id, const std::string& message) { | 108 void GpuProcessHostUIShim::Destroy(int host_id, const std::string& message) { |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 106 | 110 |
| 107 GpuDataManagerImpl::GetInstance()->AddLogMessage( | 111 GpuDataManagerImpl::GetInstance()->AddLogMessage( |
| 108 logging::LOG_ERROR, "GpuProcessHostUIShim", | 112 logging::LOG_ERROR, "GpuProcessHostUIShim", |
| 109 message); | 113 message); |
| 110 | 114 |
| 115 #if defined(USE_OZONE) |
| 116 ui::GpuPlatformSupportHost::GetInstance()->OnHostDestroyed(host_id); |
| 117 #endif |
| 118 |
| 111 delete FromID(host_id); | 119 delete FromID(host_id); |
| 112 } | 120 } |
| 113 | 121 |
| 114 // static | 122 // static |
| 115 void GpuProcessHostUIShim::DestroyAll() { | 123 void GpuProcessHostUIShim::DestroyAll() { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 117 while (!g_hosts_by_id.Pointer()->IsEmpty()) { | 125 while (!g_hosts_by_id.Pointer()->IsEmpty()) { |
| 118 IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer()); | 126 IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer()); |
| 119 delete it.GetCurrentValue(); | 127 delete it.GetCurrentValue(); |
| 120 } | 128 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 return BrowserThread::PostTask(BrowserThread::IO, | 148 return BrowserThread::PostTask(BrowserThread::IO, |
| 141 FROM_HERE, | 149 FROM_HERE, |
| 142 base::Bind(&SendOnIOThreadTask, | 150 base::Bind(&SendOnIOThreadTask, |
| 143 host_id_, | 151 host_id_, |
| 144 msg)); | 152 msg)); |
| 145 } | 153 } |
| 146 | 154 |
| 147 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { | 155 bool GpuProcessHostUIShim::OnMessageReceived(const IPC::Message& message) { |
| 148 DCHECK(CalledOnValidThread()); | 156 DCHECK(CalledOnValidThread()); |
| 149 | 157 |
| 150 if (message.routing_id() != MSG_ROUTING_CONTROL) | 158 if (message.routing_id() == MSG_ROUTING_CONTROL) |
| 159 return OnControlMessageReceived(message); |
| 160 |
| 161 IPC::Listener* listener = routes_.Lookup(message.routing_id()); |
| 162 if (!listener) |
| 151 return false; | 163 return false; |
| 152 | 164 |
| 153 return OnControlMessageReceived(message); | 165 listener->OnMessageReceived(message); |
| 166 return true; |
| 154 } | 167 } |
| 155 | 168 |
| 156 void GpuProcessHostUIShim::SimulateRemoveAllContext() { | 169 void GpuProcessHostUIShim::SimulateRemoveAllContext() { |
| 157 Send(new GpuMsg_Clean()); | 170 Send(new GpuMsg_Clean()); |
| 158 } | 171 } |
| 159 | 172 |
| 160 void GpuProcessHostUIShim::SimulateCrash() { | 173 void GpuProcessHostUIShim::SimulateCrash() { |
| 161 Send(new GpuMsg_Crash()); | 174 Send(new GpuMsg_Crash()); |
| 162 } | 175 } |
| 163 | 176 |
| 164 void GpuProcessHostUIShim::SimulateHang() { | 177 void GpuProcessHostUIShim::SimulateHang() { |
| 165 Send(new GpuMsg_Hang()); | 178 Send(new GpuMsg_Hang()); |
| 166 } | 179 } |
| 167 | 180 |
| 181 void GpuProcessHostUIShim::AddRoute(int32 routing_id, IPC::Listener* listener) { |
| 182 routes_.AddWithID(listener, routing_id); |
| 183 } |
| 184 |
| 168 GpuProcessHostUIShim::~GpuProcessHostUIShim() { | 185 GpuProcessHostUIShim::~GpuProcessHostUIShim() { |
| 169 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
| 170 g_hosts_by_id.Pointer()->Remove(host_id_); | 187 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 171 } | 188 } |
| 172 | 189 |
| 173 bool GpuProcessHostUIShim::OnControlMessageReceived( | 190 bool GpuProcessHostUIShim::OnControlMessageReceived( |
| 174 const IPC::Message& message) { | 191 const IPC::Message& message) { |
| 175 DCHECK(CalledOnValidThread()); | 192 DCHECK(CalledOnValidThread()); |
| 176 | 193 |
| 177 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) | 194 IPC_BEGIN_MESSAGE_MAP(GpuProcessHostUIShim, message) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 OnAcceleratedSurfaceSuspend) | 205 OnAcceleratedSurfaceSuspend) |
| 189 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, | 206 IPC_MESSAGE_HANDLER(GpuHostMsg_GraphicsInfoCollected, |
| 190 OnGraphicsInfoCollected) | 207 OnGraphicsInfoCollected) |
| 191 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, | 208 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceRelease, |
| 192 OnAcceleratedSurfaceRelease) | 209 OnAcceleratedSurfaceRelease) |
| 193 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, | 210 IPC_MESSAGE_HANDLER(GpuHostMsg_VideoMemoryUsageStats, |
| 194 OnVideoMemoryUsageStatsReceived); | 211 OnVideoMemoryUsageStatsReceived); |
| 195 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters, | 212 IPC_MESSAGE_HANDLER(GpuHostMsg_UpdateVSyncParameters, |
| 196 OnUpdateVSyncParameters) | 213 OnUpdateVSyncParameters) |
| 197 IPC_MESSAGE_HANDLER(GpuHostMsg_FrameDrawn, OnFrameDrawn) | 214 IPC_MESSAGE_HANDLER(GpuHostMsg_FrameDrawn, OnFrameDrawn) |
| 215 IPC_MESSAGE_HANDLER(GpuHostMsg_PlatformSupportInitialized, |
| 216 OnPlatformSupportInitialized); |
| 198 | 217 |
| 199 IPC_MESSAGE_UNHANDLED_ERROR() | 218 IPC_MESSAGE_UNHANDLED_ERROR() |
| 200 IPC_END_MESSAGE_MAP() | 219 IPC_END_MESSAGE_MAP() |
| 201 | 220 |
| 202 return true; | 221 return true; |
| 203 } | 222 } |
| 204 | 223 |
| 205 void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id, | 224 void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id, |
| 206 base::TimeTicks timebase, | 225 base::TimeTicks timebase, |
| 207 base::TimeDelta interval) { | 226 base::TimeDelta interval) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 299 } |
| 281 | 300 |
| 282 void GpuProcessHostUIShim::OnFrameDrawn( | 301 void GpuProcessHostUIShim::OnFrameDrawn( |
| 283 const std::vector<ui::LatencyInfo>& latency_info) { | 302 const std::vector<ui::LatencyInfo>& latency_info) { |
| 284 if (!ui::LatencyInfo::Verify(latency_info, | 303 if (!ui::LatencyInfo::Verify(latency_info, |
| 285 "GpuProcessHostUIShim::OnFrameDrawn")) | 304 "GpuProcessHostUIShim::OnFrameDrawn")) |
| 286 return; | 305 return; |
| 287 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 306 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
| 288 } | 307 } |
| 289 | 308 |
| 309 void GpuProcessHostUIShim::OnPlatformSupportInitialized(int32 host_route_id, |
| 310 int32 gpu_route_id) { |
| 311 #if defined(USE_OZONE) |
| 312 ui::GpuPlatformSupportHost* platform_support_host = |
| 313 ui::GpuPlatformSupportHost::GetInstance(); |
| 314 AddRoute(host_route_id, platform_support_host); |
| 315 platform_support_host->OnChannelEstablished(host_id_, gpu_route_id, this); |
| 316 #endif |
| 317 } |
| 318 |
| 290 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( | 319 void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( |
| 291 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { | 320 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params) { |
| 292 TRACE_EVENT0("renderer", | 321 TRACE_EVENT0("renderer", |
| 293 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); | 322 "GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer"); |
| 294 if (!ui::LatencyInfo::Verify(params.latency_info, | 323 if (!ui::LatencyInfo::Verify(params.latency_info, |
| 295 "GpuHostMsg_AcceleratedSurfacePostSubBuffer")) | 324 "GpuHostMsg_AcceleratedSurfacePostSubBuffer")) |
| 296 return; | 325 return; |
| 297 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 326 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 298 ack_params.mailbox = params.mailbox; | 327 ack_params.mailbox = params.mailbox; |
| 299 ack_params.sync_point = 0; | 328 ack_params.sync_point = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 view->AcceleratedSurfaceRelease(); | 371 view->AcceleratedSurfaceRelease(); |
| 343 } | 372 } |
| 344 | 373 |
| 345 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( | 374 void GpuProcessHostUIShim::OnVideoMemoryUsageStatsReceived( |
| 346 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { | 375 const GPUVideoMemoryUsageStats& video_memory_usage_stats) { |
| 347 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( | 376 GpuDataManagerImpl::GetInstance()->UpdateVideoMemoryUsageStats( |
| 348 video_memory_usage_stats); | 377 video_memory_usage_stats); |
| 349 } | 378 } |
| 350 | 379 |
| 351 } // namespace content | 380 } // namespace content |
| OLD | NEW |