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

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

Issue 444173003: aw: Improve idle task scheduling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 6 years, 4 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 | « android_webview/browser/shared_renderer_state.h ('k') | android_webview/native/aw_contents.cc » ('j') | 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/shared_renderer_state.h" 5 #include "android_webview/browser/shared_renderer_state.h"
6 6
7 #include "android_webview/browser/browser_view_renderer_client.h" 7 #include "android_webview/browser/browser_view_renderer_client.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h"
9 #include "base/location.h" 10 #include "base/location.h"
10 11
11 namespace android_webview { 12 namespace android_webview {
12 13
14 namespace internal {
15
16 class RequestDrawGLTracker {
17 public:
18 RequestDrawGLTracker();
19 bool ShouldRequestOnNoneUiThread(SharedRendererState* state);
20 bool ShouldRequestOnUiThread(SharedRendererState* state);
21 void DidRequestOnUiThread();
22 void DidDrawGLProcess();
23
24 private:
25 base::Lock lock_;
26 SharedRendererState* pending_ui_;
27 SharedRendererState* pending_non_ui_;
28 };
29
30 RequestDrawGLTracker::RequestDrawGLTracker()
31 : pending_ui_(NULL), pending_non_ui_(NULL) {
32 }
33
34 bool RequestDrawGLTracker::ShouldRequestOnNoneUiThread(
35 SharedRendererState* state) {
36 base::AutoLock lock(lock_);
37 if (pending_ui_ || pending_non_ui_)
hush (inactive) 2014/08/07 22:14:27 this means there should be only at most one pendin
boliu 2014/08/07 22:21:35 That's the goal. But it's not quite true. Right n
38 return false;
39 pending_non_ui_ = state;
40 return true;
41 }
42
43 bool RequestDrawGLTracker::ShouldRequestOnUiThread(SharedRendererState* state) {
44 base::AutoLock lock(lock_);
45 if (pending_non_ui_) {
46 pending_non_ui_->ResetRequestDrawGLCallback();
47 pending_non_ui_ = NULL;
48 }
49 if (pending_ui_)
50 return false;
51 pending_ui_ = state;
52 return true;
53 }
54
55 void RequestDrawGLTracker::DidDrawGLProcess() {
56 base::AutoLock lock(lock_);
57 pending_non_ui_ = NULL;
58 pending_ui_ = NULL;
59 }
60
61 } // namespace internal
62
63 namespace {
hush (inactive) 2014/08/07 22:14:27 an empty line after this line?
64 base::LazyInstance<internal::RequestDrawGLTracker> g_request_draw_gl_tracker =
65 LAZY_INSTANCE_INITIALIZER;
66 }
67
13 DrawGLInput::DrawGLInput() : width(0), height(0) { 68 DrawGLInput::DrawGLInput() : width(0), height(0) {
14 } 69 }
15 70
16 DrawGLInput::~DrawGLInput() { 71 DrawGLInput::~DrawGLInput() {
17 } 72 }
18 73
19 SharedRendererState::SharedRendererState( 74 SharedRendererState::SharedRendererState(
20 scoped_refptr<base::MessageLoopProxy> ui_loop, 75 scoped_refptr<base::MessageLoopProxy> ui_loop,
21 BrowserViewRendererClient* client) 76 BrowserViewRendererClient* client)
22 : ui_loop_(ui_loop), 77 : ui_loop_(ui_loop),
23 client_on_ui_(client), 78 client_on_ui_(client),
24 weak_factory_on_ui_thread_(this), 79 weak_factory_on_ui_thread_(this),
25 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), 80 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
26 inside_hardware_release_(false), 81 inside_hardware_release_(false),
27 share_context_(NULL) { 82 share_context_(NULL) {
28 DCHECK(ui_loop_->BelongsToCurrentThread()); 83 DCHECK(ui_loop_->BelongsToCurrentThread());
29 DCHECK(client_on_ui_); 84 DCHECK(client_on_ui_);
85 ResetRequestDrawGLCallback();
30 } 86 }
31 87
32 SharedRendererState::~SharedRendererState() { 88 SharedRendererState::~SharedRendererState() {
33 DCHECK(ui_loop_->BelongsToCurrentThread()); 89 DCHECK(ui_loop_->BelongsToCurrentThread());
34 } 90 }
35 91
36 bool SharedRendererState::CurrentlyOnUIThread() { 92 bool SharedRendererState::CurrentlyOnUIThread() {
37 return ui_loop_->BelongsToCurrentThread(); 93 return ui_loop_->BelongsToCurrentThread();
38 } 94 }
39 95
40 void SharedRendererState::ClientRequestDrawGL() { 96 void SharedRendererState::ClientRequestDrawGL() {
41 if (ui_loop_->BelongsToCurrentThread()) { 97 if (ui_loop_->BelongsToCurrentThread()) {
98 if (!g_request_draw_gl_tracker.Get().ShouldRequestOnUiThread(this))
99 return;
42 ClientRequestDrawGLOnUIThread(); 100 ClientRequestDrawGLOnUIThread();
43 } else { 101 } else {
44 ui_loop_->PostTask( 102 if (!g_request_draw_gl_tracker.Get().ShouldRequestOnNoneUiThread(this))
45 FROM_HERE, 103 return;
46 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread, 104 base::Closure callback;
47 ui_thread_weak_ptr_)); 105 {
106 base::AutoLock lock(lock_);
107 callback = request_draw_gl_closure_;
108 }
109 ui_loop_->PostTask(FROM_HERE, callback);
48 } 110 }
49 } 111 }
50 112
113 void SharedRendererState::DidDrawGLProcess() {
114 g_request_draw_gl_tracker.Get().DidDrawGLProcess();
115 }
116
117 void SharedRendererState::ResetRequestDrawGLCallback() {
118 DCHECK(ui_loop_->BelongsToCurrentThread());
119 base::AutoLock lock(lock_);
120 request_draw_gl_cancelable_closure_.Reset(
121 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread,
122 base::Unretained(this)));
123 request_draw_gl_closure_ = request_draw_gl_cancelable_closure_.callback();
124 }
125
51 void SharedRendererState::ClientRequestDrawGLOnUIThread() { 126 void SharedRendererState::ClientRequestDrawGLOnUIThread() {
52 DCHECK(ui_loop_->BelongsToCurrentThread()); 127 DCHECK(ui_loop_->BelongsToCurrentThread());
128 ResetRequestDrawGLCallback();
53 if (!client_on_ui_->RequestDrawGL(NULL, false)) { 129 if (!client_on_ui_->RequestDrawGL(NULL, false)) {
54 LOG(ERROR) << "Failed to request GL process. Deadlock likely"; 130 LOG(ERROR) << "Failed to request GL process. Deadlock likely";
55 } 131 }
56 } 132 }
57 133
58 void SharedRendererState::UpdateParentDrawConstraintsOnUIThread() { 134 void SharedRendererState::UpdateParentDrawConstraintsOnUIThread() {
59 DCHECK(ui_loop_->BelongsToCurrentThread()); 135 DCHECK(ui_loop_->BelongsToCurrentThread());
60 client_on_ui_->UpdateParentDrawConstraints(); 136 client_on_ui_->UpdateParentDrawConstraints();
61 } 137 }
62 138
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 : shared_renderer_state_(shared_renderer_state) { 213 : shared_renderer_state_(shared_renderer_state) {
138 DCHECK(!shared_renderer_state_->IsInsideHardwareRelease()); 214 DCHECK(!shared_renderer_state_->IsInsideHardwareRelease());
139 shared_renderer_state_->SetInsideHardwareRelease(true); 215 shared_renderer_state_->SetInsideHardwareRelease(true);
140 } 216 }
141 217
142 InsideHardwareReleaseReset::~InsideHardwareReleaseReset() { 218 InsideHardwareReleaseReset::~InsideHardwareReleaseReset() {
143 shared_renderer_state_->SetInsideHardwareRelease(false); 219 shared_renderer_state_->SetInsideHardwareRelease(false);
144 } 220 }
145 221
146 } // namespace android_webview 222 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/shared_renderer_state.h ('k') | android_webview/native/aw_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698