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

Side by Side Diff: android_webview/browser/deferred_gpu_command_service.cc

Issue 299363003: aw: Improve DeferredGpuCommandService scheduling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "android_webview/browser/deferred_gpu_command_service.h" 5 #include "android_webview/browser/deferred_gpu_command_service.h"
6 6
7 #include "android_webview/browser/gl_view_renderer_manager.h" 7 #include "android_webview/browser/gl_view_renderer_manager.h"
8 #include "android_webview/browser/shared_renderer_state.h" 8 #include "android_webview/browser/shared_renderer_state.h"
9 #include "base/synchronization/lock.h"
9 #include "content/public/browser/android/synchronous_compositor.h" 10 #include "content/public/browser/android/synchronous_compositor.h"
10 #include "gpu/command_buffer/service/shader_translator_cache.h" 11 #include "gpu/command_buffer/service/shader_translator_cache.h"
11 12
12 namespace android_webview { 13 namespace android_webview {
13 14
14 namespace { 15 namespace {
16
17 // TODO(boliu): Consider using base/atomicops.h.
18 class ThreadSafeBool {
19 public:
20 ThreadSafeBool();
21 void Set(bool boolean);
22 bool Get();
23
24 private:
25 base::Lock lock_;
26 bool boolean_;
27 DISALLOW_COPY_AND_ASSIGN(ThreadSafeBool);
28 };
29
30 ThreadSafeBool::ThreadSafeBool() : boolean_(false) {
31 }
32
33 void ThreadSafeBool::Set(bool boolean) {
34 base::AutoLock lock(lock_);
35 boolean_ = boolean;
36 }
37
38 bool ThreadSafeBool::Get() {
39 base::AutoLock lock(lock_);
40 return boolean_;
41 }
42
43 base::LazyInstance<ThreadSafeBool> g_request_pending =
44 LAZY_INSTANCE_INITIALIZER;
45
15 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> > 46 base::LazyInstance<scoped_refptr<DeferredGpuCommandService> >
16 g_service = LAZY_INSTANCE_INITIALIZER; 47 g_service = LAZY_INSTANCE_INITIALIZER;
17 } // namespace 48 } // namespace
18 49
19 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl; 50 base::LazyInstance<base::ThreadLocalBoolean> ScopedAllowGL::allow_gl;
20 51
21 // static 52 // static
22 bool ScopedAllowGL::IsAllowed() { 53 bool ScopedAllowGL::IsAllowed() {
23 return allow_gl.Get().Get(); 54 return allow_gl.Get().Get();
24 } 55 }
25 56
26 ScopedAllowGL::ScopedAllowGL() { 57 ScopedAllowGL::ScopedAllowGL() {
27 DCHECK(!allow_gl.Get().Get()); 58 DCHECK(!allow_gl.Get().Get());
28 allow_gl.Get().Set(true); 59 allow_gl.Get().Set(true);
29 60
30 if (g_service.Get()) 61 if (g_service.Get())
31 g_service.Get()->RunTasks(); 62 g_service.Get()->RunTasks();
32 } 63 }
33 64
34 ScopedAllowGL::~ScopedAllowGL() { allow_gl.Get().Set(false); } 65 ScopedAllowGL::~ScopedAllowGL() {
66 allow_gl.Get().Set(false);
67 g_request_pending.Get().Set(false);
68
69 if (g_service.Get())
70 g_service.Get()->RunTasks();
71 }
35 72
36 // static 73 // static
37 void DeferredGpuCommandService::SetInstance() { 74 void DeferredGpuCommandService::SetInstance() {
38 if (!g_service.Get()) { 75 if (!g_service.Get()) {
39 g_service.Get() = new DeferredGpuCommandService; 76 g_service.Get() = new DeferredGpuCommandService;
40 content::SynchronousCompositor::SetGpuService(g_service.Get()); 77 content::SynchronousCompositor::SetGpuService(g_service.Get());
78
79 // Initialize global booleans.
80 g_request_pending.Get().Set(false);
41 } 81 }
42 } 82 }
43 83
44 // static 84 // static
45 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() { 85 DeferredGpuCommandService* DeferredGpuCommandService::GetInstance() {
46 DCHECK(g_service.Get().get()); 86 DCHECK(g_service.Get().get());
47 return g_service.Get().get(); 87 return g_service.Get().get();
48 } 88 }
49 89
50 DeferredGpuCommandService::DeferredGpuCommandService() {} 90 DeferredGpuCommandService::DeferredGpuCommandService() {}
51 91
52 DeferredGpuCommandService::~DeferredGpuCommandService() { 92 DeferredGpuCommandService::~DeferredGpuCommandService() {
53 base::AutoLock lock(tasks_lock_); 93 base::AutoLock lock(tasks_lock_);
54 DCHECK(tasks_.empty()); 94 DCHECK(tasks_.empty());
55 } 95 }
56 96
57 // This method can be called on any thread. 97 // This method can be called on any thread.
58 // static 98 // static
59 void DeferredGpuCommandService::RequestProcessGL() { 99 void DeferredGpuCommandService::RequestProcessGL() {
60 SharedRendererState* renderer_state = 100 SharedRendererState* renderer_state =
61 GLViewRendererManager::GetInstance()->GetMostRecentlyDrawn(); 101 GLViewRendererManager::GetInstance()->GetMostRecentlyDrawn();
62 if (!renderer_state) { 102 if (!renderer_state) {
63 LOG(ERROR) << "No hardware renderer. Deadlock likely"; 103 LOG(ERROR) << "No hardware renderer. Deadlock likely";
64 return; 104 return;
65 } 105 }
66 renderer_state->ClientRequestDrawGL(); 106
107 if (!g_request_pending.Get().Get()) {
108 g_request_pending.Get().Set(true);
109 renderer_state->ClientRequestDrawGL();
110 }
67 } 111 }
68 112
69 // Called from different threads! 113 // Called from different threads!
70 void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) { 114 void DeferredGpuCommandService::ScheduleTask(const base::Closure& task) {
71 { 115 {
72 base::AutoLock lock(tasks_lock_); 116 base::AutoLock lock(tasks_lock_);
73 tasks_.push(task); 117 tasks_.push(task);
74 } 118 }
75 if (ScopedAllowGL::IsAllowed()) { 119 if (ScopedAllowGL::IsAllowed()) {
76 RunTasks(); 120 RunTasks();
77 } else { 121 } else {
78 // TODO(boliu): Improve this to avoid PostTask storm.
79 RequestProcessGL(); 122 RequestProcessGL();
80 } 123 }
81 } 124 }
82 125
83 void DeferredGpuCommandService::ScheduleIdleWork( 126 void DeferredGpuCommandService::ScheduleIdleWork(
84 const base::Closure& callback) { 127 const base::Closure& callback) {
85 // TODO(sievers): Should this do anything? 128 // TODO(sievers): Should this do anything?
86 } 129 }
87 130
88 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; } 131 bool DeferredGpuCommandService::UseVirtualizedGLContexts() { return true; }
(...skipping 29 matching lines...) Expand all
118 161
119 void DeferredGpuCommandService::AddRef() const { 162 void DeferredGpuCommandService::AddRef() const {
120 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef(); 163 base::RefCountedThreadSafe<DeferredGpuCommandService>::AddRef();
121 } 164 }
122 165
123 void DeferredGpuCommandService::Release() const { 166 void DeferredGpuCommandService::Release() const {
124 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release(); 167 base::RefCountedThreadSafe<DeferredGpuCommandService>::Release();
125 } 168 }
126 169
127 } // namespace android_webview 170 } // namespace android_webview
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698