Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1689)

Unified Diff: content/renderer/gpu/compositor_output_surface.cc

Issue 1193303002: base/threading: restrict to set only current thread priority (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: two more android fix and review #2 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..014648e08aab42b12b26f9416d7aaf047e1353b0 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,31 @@ 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::SetCurrentThreadPriority(
+ base::ThreadPriority::BACKGROUND);
}
+void SetThreadPriorityToDefault() {
+ base::PlatformThread::SetCurrentThreadPriority(
+ 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());
-#endif
if (prefers_smoothness_ == prefers_smoothness)
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

Powered by Google App Engine
This is Rietveld 408576698