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/renderer/gpu/compositor_output_surface.h" | 5 #include "content/renderer/gpu/compositor_output_surface.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
12 #include "cc/output/compositor_frame_ack.h" | 12 #include "cc/output/compositor_frame_ack.h" |
13 #include "cc/output/managed_memory_policy.h" | 13 #include "cc/output/managed_memory_policy.h" |
14 #include "cc/output/output_surface_client.h" | 14 #include "cc/output/output_surface_client.h" |
15 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 15 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
16 #include "content/common/gpu/client/context_provider_command_buffer.h" | 16 #include "content/common/gpu/client/context_provider_command_buffer.h" |
17 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 17 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
18 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "content/renderer/gpu/frame_swap_message_queue.h" | 20 #include "content/renderer/gpu/frame_swap_message_queue.h" |
21 #include "content/renderer/render_thread_impl.h" | 21 #include "content/renderer/render_thread_impl.h" |
22 #include "gpu/command_buffer/client/context_support.h" | 22 #include "gpu/command_buffer/client/context_support.h" |
23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
24 #include "ipc/ipc_sync_channel.h" | 24 #include "ipc/ipc_sync_channel.h" |
25 | 25 |
26 namespace { | |
27 // There are several compositor surfaces in a process, but they share the same | |
28 // compositor thread, so we use a simple int here to track prefer-smoothness. | |
29 int g_prefer_smoothness_count = 0; | |
30 } // namespace | |
31 | |
32 namespace content { | 26 namespace content { |
33 | 27 |
34 CompositorOutputSurface::CompositorOutputSurface( | 28 CompositorOutputSurface::CompositorOutputSurface( |
35 int32 routing_id, | 29 int32 routing_id, |
36 uint32 output_surface_id, | 30 uint32 output_surface_id, |
37 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 31 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
38 const scoped_refptr<ContextProviderCommandBuffer>& worker_context_provider, | 32 const scoped_refptr<ContextProviderCommandBuffer>& worker_context_provider, |
39 scoped_ptr<cc::SoftwareOutputDevice> software_device, | 33 scoped_ptr<cc::SoftwareOutputDevice> software_device, |
40 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, | 34 scoped_refptr<FrameSwapMessageQueue> swap_frame_message_queue, |
41 bool use_swap_compositor_frame_message) | 35 bool use_swap_compositor_frame_message) |
42 : OutputSurface(context_provider, | 36 : OutputSurface(context_provider, |
43 worker_context_provider, | 37 worker_context_provider, |
44 software_device.Pass()), | 38 software_device.Pass()), |
45 output_surface_id_(output_surface_id), | 39 output_surface_id_(output_surface_id), |
46 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), | 40 use_swap_compositor_frame_message_(use_swap_compositor_frame_message), |
47 output_surface_filter_( | 41 output_surface_filter_( |
48 RenderThreadImpl::current()->compositor_message_filter()), | 42 RenderThreadImpl::current()->compositor_message_filter()), |
49 frame_swap_message_queue_(swap_frame_message_queue), | 43 frame_swap_message_queue_(swap_frame_message_queue), |
50 routing_id_(routing_id), | 44 routing_id_(routing_id), |
| 45 #if defined(OS_ANDROID) |
51 prefers_smoothness_(false), | 46 prefers_smoothness_(false), |
52 #if defined(OS_WIN) | 47 main_thread_runner_(base::MessageLoop::current()->task_runner()), |
53 // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. | |
54 main_thread_handle_(base::PlatformThreadHandle()), | |
55 #else | |
56 main_thread_handle_(base::PlatformThread::CurrentHandle()), | |
57 #endif | 48 #endif |
58 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), | 49 layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), |
59 weak_ptrs_(this) { | 50 weak_ptrs_(this) { |
60 DCHECK(output_surface_filter_.get()); | 51 DCHECK(output_surface_filter_.get()); |
61 DCHECK(frame_swap_message_queue_.get()); | 52 DCHECK(frame_swap_message_queue_.get()); |
62 DetachFromThread(); | 53 DetachFromThread(); |
63 capabilities_.max_frames_pending = 1; | 54 capabilities_.max_frames_pending = 1; |
64 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); | 55 message_sender_ = RenderThreadImpl::current()->sync_message_filter(); |
65 DCHECK(message_sender_.get()); | 56 DCHECK(message_sender_.get()); |
66 } | 57 } |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 // (e.g. after a lost context). | 197 // (e.g. after a lost context). |
207 if (output_surface_id != output_surface_id_) | 198 if (output_surface_id != output_surface_id_) |
208 return; | 199 return; |
209 ReclaimResources(&ack); | 200 ReclaimResources(&ack); |
210 } | 201 } |
211 | 202 |
212 bool CompositorOutputSurface::Send(IPC::Message* message) { | 203 bool CompositorOutputSurface::Send(IPC::Message* message) { |
213 return message_sender_->Send(message); | 204 return message_sender_->Send(message); |
214 } | 205 } |
215 | 206 |
| 207 #if defined(OS_ANDROID) |
216 namespace { | 208 namespace { |
217 #if defined(OS_ANDROID) | 209 void SetThreadPriorityToIdle() { |
218 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { | 210 base::PlatformThread::SetCurrentThreadPriority( |
219 base::PlatformThread::SetThreadPriority(handle, | 211 base::ThreadPriority::BACKGROUND); |
220 base::ThreadPriority::BACKGROUND); | |
221 } | |
222 void SetThreadPriorityToDefault(base::PlatformThreadHandle handle) { | |
223 base::PlatformThread::SetThreadPriority(handle, | |
224 base::ThreadPriority::NORMAL); | |
225 } | |
226 #else | |
227 void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) {} | |
228 void SetThreadPriorityToDefault(base::PlatformThreadHandle handle) {} | |
229 #endif | |
230 } | 212 } |
| 213 void SetThreadPriorityToDefault() { |
| 214 base::PlatformThread::SetCurrentThreadPriority( |
| 215 base::ThreadPriority::NORMAL); |
| 216 } |
| 217 } // namespace |
231 | 218 |
232 void CompositorOutputSurface::UpdateSmoothnessTakesPriority( | 219 void CompositorOutputSurface::UpdateSmoothnessTakesPriority( |
233 bool prefers_smoothness) { | 220 bool prefers_smoothness) { |
234 #ifndef NDEBUG | |
235 // If we use different compositor threads, we need to | |
236 // use an atomic int to track prefer smoothness count. | |
237 base::PlatformThreadId g_last_thread = base::PlatformThread::CurrentId(); | |
238 DCHECK_EQ(g_last_thread, base::PlatformThread::CurrentId()); | |
239 #endif | |
240 if (prefers_smoothness_ == prefers_smoothness) | 221 if (prefers_smoothness_ == prefers_smoothness) |
241 return; | 222 return; |
242 // If this is the first surface to start preferring smoothness, | 223 prefers_smoothness_ = prefers_smoothness; |
243 // Throttle the main thread's priority. | 224 if (prefers_smoothness) { |
244 if (prefers_smoothness_ == false && | 225 main_thread_runner_->PostTask( |
245 ++g_prefer_smoothness_count == 1) { | 226 FROM_HERE, base::Bind(&SetThreadPriorityToIdle)); |
246 SetThreadPriorityToIdle(main_thread_handle_); | 227 } else { |
| 228 main_thread_runner_->PostTask( |
| 229 FROM_HERE, base::Bind(&SetThreadPriorityToDefault)); |
247 } | 230 } |
248 // If this is the last surface to stop preferring smoothness, | |
249 // Reset the main thread's priority to the default. | |
250 if (prefers_smoothness_ == true && | |
251 --g_prefer_smoothness_count == 0) { | |
252 SetThreadPriorityToDefault(main_thread_handle_); | |
253 } | |
254 prefers_smoothness_ = prefers_smoothness; | |
255 } | 231 } |
| 232 #endif |
256 | 233 |
257 } // namespace content | 234 } // namespace content |
OLD | NEW |