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/common/gpu/gpu_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.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" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "gpu/command_buffer/service/mailbox_manager.h" | 22 #include "gpu/command_buffer/service/mailbox_manager.h" |
23 #include "gpu/command_buffer/service/memory_program_cache.h" | 23 #include "gpu/command_buffer/service/memory_program_cache.h" |
24 #include "gpu/command_buffer/service/shader_translator_cache.h" | 24 #include "gpu/command_buffer/service/shader_translator_cache.h" |
25 #include "gpu/command_buffer/service/sync_point_manager.h" | 25 #include "gpu/command_buffer/service/sync_point_manager.h" |
26 #include "ipc/message_filter.h" | 26 #include "ipc/message_filter.h" |
27 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
28 #include "ui/gl/gl_share_group.h" | 28 #include "ui/gl/gl_share_group.h" |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 namespace { | |
33 #if defined(OS_ANDROID) | |
34 // Amount of time the GPU is allowed to idle before it powers down. | |
no sievers
2015/09/23 19:32:33
nit: while you're at it, can you rephrase it since
piman
2015/09/23 22:32:32
Done.
| |
35 const int kMaxGpuIdleTimeMs = 40; | |
36 // Maximum amount of time we keep pinging the GPU waiting for the client to | |
37 // draw. | |
38 const int kMaxKeepAliveTimeMs = 200; | |
39 #endif | |
40 | |
41 } | |
42 | |
32 GpuChannelManager::GpuChannelManager( | 43 GpuChannelManager::GpuChannelManager( |
33 IPC::SyncChannel* channel, | 44 IPC::SyncChannel* channel, |
34 GpuWatchdog* watchdog, | 45 GpuWatchdog* watchdog, |
35 base::SingleThreadTaskRunner* task_runner, | 46 base::SingleThreadTaskRunner* task_runner, |
36 base::SingleThreadTaskRunner* io_task_runner, | 47 base::SingleThreadTaskRunner* io_task_runner, |
37 base::WaitableEvent* shutdown_event, | 48 base::WaitableEvent* shutdown_event, |
38 gpu::SyncPointManager* sync_point_manager, | 49 gpu::SyncPointManager* sync_point_manager, |
39 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 50 GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
40 : task_runner_(task_runner), | 51 : task_runner_(task_runner), |
41 io_task_runner_(io_task_runner), | 52 io_task_runner_(io_task_runner), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 bool GpuChannelManager::OnControlMessageReceived(const IPC::Message& msg) { | 124 bool GpuChannelManager::OnControlMessageReceived(const IPC::Message& msg) { |
114 bool handled = true; | 125 bool handled = true; |
115 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 126 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
116 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 127 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
117 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 128 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
118 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 129 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
119 OnCreateViewCommandBuffer) | 130 OnCreateViewCommandBuffer) |
120 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 131 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
121 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 132 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
122 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) | 133 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState) |
134 #if defined(OS_ANDROID) | |
135 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu); | |
136 #endif | |
123 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
124 IPC_END_MESSAGE_MAP() | 138 IPC_END_MESSAGE_MAP() |
125 return handled; | 139 return handled; |
126 } | 140 } |
127 | 141 |
128 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 142 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
129 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 143 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
130 return OnControlMessageReceived(msg); | 144 return OnControlMessageReceived(msg); |
131 | 145 |
132 return router_.RouteMessage(msg); | 146 return router_.RouteMessage(msg); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 } | 294 } |
281 | 295 |
282 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 296 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
283 if (!default_offscreen_surface_.get()) { | 297 if (!default_offscreen_surface_.get()) { |
284 default_offscreen_surface_ = | 298 default_offscreen_surface_ = |
285 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 299 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
286 } | 300 } |
287 return default_offscreen_surface_.get(); | 301 return default_offscreen_surface_.get(); |
288 } | 302 } |
289 | 303 |
304 #if defined(OS_ANDROID) | |
305 void GpuChannelManager::DidAccessGpu() { | |
306 last_gpu_access_time_ = base::TimeTicks::Now(); | |
307 } | |
308 | |
309 void GpuChannelManager::OnWakeUpGpu() { | |
310 begin_wake_up_time_ = base::TimeTicks::Now(); | |
311 ScheduleWakeUpGpu(); | |
312 } | |
313 | |
314 void GpuChannelManager::ScheduleWakeUpGpu() { | |
315 base::TimeTicks now = base::TimeTicks::Now(); | |
316 TRACE_EVENT2("gpu", "ImageTransportSurfaceAndroid::ScheduleWakeUp", | |
no sievers
2015/09/23 19:32:33
nit: ImageTransportSurface->GpuChannelManager
piman
2015/09/23 22:32:32
Done.
| |
317 "idle_time", (now - last_gpu_access_time_).InMilliseconds(), | |
318 "keep_awake_time", (now - begin_wake_up_time_).InMilliseconds()); | |
319 if (now - last_gpu_access_time_ < | |
320 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)) | |
321 return; | |
322 if (now - begin_wake_up_time_ > | |
323 base::TimeDelta::FromMilliseconds(kMaxKeepAliveTimeMs)) | |
324 return; | |
325 | |
326 DoWakeUpGpu(); | |
327 | |
328 base::MessageLoop::current()->PostDelayedTask( | |
329 FROM_HERE, base::Bind(&GpuChannelManager::ScheduleWakeUpGpu, | |
330 weak_factory_.GetWeakPtr()), | |
331 base::TimeDelta::FromMilliseconds(kMaxGpuIdleTimeMs)); | |
332 } | |
333 | |
334 void GpuChannelManager::DoWakeUpGpu() { | |
335 const GpuCommandBufferStub* stub = nullptr; | |
336 for (const auto& kv : gpu_channels_) { | |
337 const GpuChannel* channel = kv.second; | |
338 stub = channel->GetOneStub(); | |
339 if (stub) { | |
340 DCHECK(stub->decoder()); | |
341 break; | |
342 } | |
343 } | |
344 if (!stub || !stub->decoder()->MakeCurrent()) | |
345 return; | |
346 glFinish(); | |
347 DidAccessGpu(); | |
348 } | |
349 #endif | |
350 | |
290 } // namespace content | 351 } // namespace content |
OLD | NEW |