Chromium Code Reviews| Index: content/renderer/gpu/compositor_output_surface.cc |
| diff --git a/content/renderer/gpu/compositor_output_surface.cc b/content/renderer/gpu/compositor_output_surface.cc |
| index c8270a68c73dcfd298b713f9f7d382ab86b4affb..fa4302e924f98e7324bcb8674c590b6a0c72e1b1 100644 |
| --- a/content/renderer/gpu/compositor_output_surface.cc |
| +++ b/content/renderer/gpu/compositor_output_surface.cc |
| @@ -23,12 +23,6 @@ |
| #include "gpu/command_buffer/client/gles2_interface.h" |
| #include "ipc/ipc_sync_channel.h" |
| -namespace { |
| -// There are several compositor surfaces in a process, but they share the same |
| -// compositor thread, so we use a simple int here to track prefer-smoothness. |
| -int g_prefer_smoothness_count = 0; |
| -} // namespace |
| - |
| namespace content { |
| CompositorOutputSurface::CompositorOutputSurface( |
| @@ -48,12 +42,9 @@ CompositorOutputSurface::CompositorOutputSurface( |
| RenderThreadImpl::current()->compositor_message_filter()), |
| frame_swap_message_queue_(swap_frame_message_queue), |
| routing_id_(routing_id), |
| +#if defined(OS_ANDROID) |
| prefers_smoothness_(false), |
| -#if defined(OS_WIN) |
| - // TODO(epenner): Implement PlatformThread::CurrentHandle() on windows. |
| - main_thread_handle_(base::PlatformThreadHandle()), |
| -#else |
| - main_thread_handle_(base::PlatformThread::CurrentHandle()), |
| + main_thread_runner_(base::MessageLoop::current()->task_runner()), |
| #endif |
| layout_test_mode_(RenderThreadImpl::current()->layout_test_mode()), |
| weak_ptrs_(this) { |
| @@ -213,45 +204,33 @@ bool CompositorOutputSurface::Send(IPC::Message* message) { |
| return message_sender_->Send(message); |
| } |
| -namespace { |
| #if defined(OS_ANDROID) |
| - void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) { |
| - base::PlatformThread::SetThreadPriority(handle, |
| - base::ThreadPriority::BACKGROUND); |
| - } |
| - void SetThreadPriorityToDefault(base::PlatformThreadHandle handle) { |
| - base::PlatformThread::SetThreadPriority(handle, |
| - base::ThreadPriority::NORMAL); |
| - } |
| -#else |
| - void SetThreadPriorityToIdle(base::PlatformThreadHandle handle) {} |
| - void SetThreadPriorityToDefault(base::PlatformThreadHandle handle) {} |
| -#endif |
| +namespace { |
| +void SetThreadPriorityToIdle() { |
| + base::PlatformThread::SetThreadPriority( |
| + base::PlatformThread::CurrentHandle(), |
| + base::ThreadPriority::BACKGROUND); |
| } |
| +void SetThreadPriorityToDefault() { |
| + base::PlatformThread::SetThreadPriority( |
| + base::PlatformThread::CurrentHandle(), |
| + base::ThreadPriority::NORMAL); |
| +} |
| +} // namespace |
| void CompositorOutputSurface::UpdateSmoothnessTakesPriority( |
| bool prefers_smoothness) { |
| -#ifndef NDEBUG |
| - // If we use different compositor threads, we need to |
| - // use an atomic int to track prefer smoothness count. |
| - base::PlatformThreadId g_last_thread = base::PlatformThread::CurrentId(); |
| - DCHECK_EQ(g_last_thread, base::PlatformThread::CurrentId()); |
|
Takashi Toyoshima
2015/06/24 02:24:00
This is DCHECK_EQ(base::PlatformThread::CurrentId(
|
| -#endif |
| if (prefers_smoothness_ == prefers_smoothness) |
|
Takashi Toyoshima
2015/06/24 02:24:00
Because of this shortcut, following g_prefer_smoot
|
| return; |
| - // If this is the first surface to start preferring smoothness, |
| - // Throttle the main thread's priority. |
| - if (prefers_smoothness_ == false && |
| - ++g_prefer_smoothness_count == 1) { |
| - SetThreadPriorityToIdle(main_thread_handle_); |
| - } |
| - // If this is the last surface to stop preferring smoothness, |
| - // Reset the main thread's priority to the default. |
| - if (prefers_smoothness_ == true && |
| - --g_prefer_smoothness_count == 0) { |
| - SetThreadPriorityToDefault(main_thread_handle_); |
| - } |
| prefers_smoothness_ = prefers_smoothness; |
| + if (prefers_smoothness) { |
| + main_thread_runner_->PostTask( |
| + FROM_HERE, base::Bind(&SetThreadPriorityToIdle)); |
| + } else { |
| + main_thread_runner_->PostTask( |
| + FROM_HERE, base::Bind(&SetThreadPriorityToDefault)); |
| + } |
| } |
| +#endif |
| } // namespace content |