Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/location.h" | 9 #include "base/location.h" |
| 10 | 10 |
| 11 namespace android_webview { | 11 namespace android_webview { |
| 12 | 12 |
| 13 DrawGLInput::DrawGLInput() : frame_id(0), width(0), height(0) {} | 13 DrawGLInput::DrawGLInput() : width(0), height(0) { |
| 14 } | |
| 14 | 15 |
| 15 DrawGLResult::DrawGLResult() : frame_id(0), clip_contains_visible_rect(false) {} | 16 DrawGLInput::~DrawGLInput() { |
| 17 } | |
| 18 | |
| 19 DrawGLResult::DrawGLResult() : clip_contains_visible_rect(false) { | |
| 20 } | |
| 16 | 21 |
| 17 SharedRendererState::SharedRendererState( | 22 SharedRendererState::SharedRendererState( |
| 18 scoped_refptr<base::MessageLoopProxy> ui_loop, | 23 scoped_refptr<base::MessageLoopProxy> ui_loop, |
| 19 BrowserViewRendererClient* client) | 24 BrowserViewRendererClient* client) |
| 20 : ui_loop_(ui_loop), | 25 : ui_loop_(ui_loop), |
| 21 client_on_ui_(client), | 26 client_on_ui_(client), |
| 22 weak_factory_on_ui_thread_(this), | 27 weak_factory_on_ui_thread_(this), |
| 23 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), | 28 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), |
| 24 compositor_(NULL), | 29 compositor_(NULL), |
| 25 memory_policy_dirty_(false), | 30 memory_policy_dirty_(false), |
| 26 hardware_initialized_(false) { | 31 hardware_initialized_(false), |
| 32 share_context_(NULL) { | |
| 27 DCHECK(ui_loop_->BelongsToCurrentThread()); | 33 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 28 DCHECK(client_on_ui_); | 34 DCHECK(client_on_ui_); |
| 29 } | 35 } |
| 30 | 36 |
| 31 SharedRendererState::~SharedRendererState() {} | 37 SharedRendererState::~SharedRendererState() {} |
| 32 | 38 |
| 33 void SharedRendererState::ClientRequestDrawGL() { | 39 void SharedRendererState::ClientRequestDrawGL() { |
| 34 if (ui_loop_->BelongsToCurrentThread()) { | 40 if (ui_loop_->BelongsToCurrentThread()) { |
|
no sievers
2014/05/20 20:48:26
Does this request a draw on the UI or RenderThread
boliu
2014/05/21 01:33:26
The ClientRequestDrawGLOnUIThread call has to happ
| |
| 35 ClientRequestDrawGLOnUIThread(); | 41 ClientRequestDrawGLOnUIThread(); |
| 36 } else { | 42 } else { |
| 37 ui_loop_->PostTask( | 43 ui_loop_->PostTask( |
| 38 FROM_HERE, | 44 FROM_HERE, |
| 39 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread, | 45 base::Bind(&SharedRendererState::ClientRequestDrawGLOnUIThread, |
| 40 ui_thread_weak_ptr_)); | 46 ui_thread_weak_ptr_)); |
| 41 } | 47 } |
| 42 } | 48 } |
| 43 | 49 |
| 44 void SharedRendererState::ClientRequestDrawGLOnUIThread() { | 50 void SharedRendererState::ClientRequestDrawGLOnUIThread() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 69 memory_policy_dirty_ = true; | 75 memory_policy_dirty_ = true; |
| 70 } | 76 } |
| 71 } | 77 } |
| 72 | 78 |
| 73 content::SynchronousCompositorMemoryPolicy | 79 content::SynchronousCompositorMemoryPolicy |
| 74 SharedRendererState::GetMemoryPolicy() const { | 80 SharedRendererState::GetMemoryPolicy() const { |
| 75 base::AutoLock lock(lock_); | 81 base::AutoLock lock(lock_); |
| 76 return memory_policy_; | 82 return memory_policy_; |
| 77 } | 83 } |
| 78 | 84 |
| 79 void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) { | 85 void SharedRendererState::SetDrawGLInput(scoped_ptr<DrawGLInput> input) { |
| 80 base::AutoLock lock(lock_); | 86 base::AutoLock lock(lock_); |
| 81 draw_gl_input_ = input; | 87 DCHECK(!draw_gl_input_.get()); |
| 88 draw_gl_input_ = input.Pass(); | |
| 82 } | 89 } |
| 83 | 90 |
| 84 DrawGLInput SharedRendererState::GetDrawGLInput() const { | 91 scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() { |
| 85 base::AutoLock lock(lock_); | 92 base::AutoLock lock(lock_); |
| 86 return draw_gl_input_; | 93 return draw_gl_input_.Pass(); |
| 87 } | 94 } |
| 88 | 95 |
| 89 void SharedRendererState::ClearClosureQueue() { | 96 void SharedRendererState::ClearClosureQueue() { |
| 90 base::AutoLock lock(lock_); | 97 base::AutoLock lock(lock_); |
| 91 std::queue<base::Closure> empty; | 98 std::queue<base::Closure> empty; |
| 92 std::swap(closure_queue_, empty); | 99 std::swap(closure_queue_, empty); |
| 93 } | 100 } |
| 94 | 101 |
| 95 void SharedRendererState::AppendClosure(const base::Closure& closure) { | 102 void SharedRendererState::AppendClosure(const base::Closure& closure) { |
| 96 base::AutoLock lock(lock_); | 103 base::AutoLock lock(lock_); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 112 void SharedRendererState::SetHardwareInitialized(bool initialized) { | 119 void SharedRendererState::SetHardwareInitialized(bool initialized) { |
| 113 base::AutoLock lock(lock_); | 120 base::AutoLock lock(lock_); |
| 114 hardware_initialized_ = initialized; | 121 hardware_initialized_ = initialized; |
| 115 } | 122 } |
| 116 | 123 |
| 117 bool SharedRendererState::IsHardwareInitialized() const { | 124 bool SharedRendererState::IsHardwareInitialized() const { |
| 118 base::AutoLock lock(lock_); | 125 base::AutoLock lock(lock_); |
| 119 return hardware_initialized_; | 126 return hardware_initialized_; |
| 120 } | 127 } |
| 121 | 128 |
| 129 void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) { | |
| 130 DCHECK(!share_context_ || !context); | |
| 131 share_context_ = context; | |
|
no sievers
2014/05/20 20:48:26
This looks like it might not be thread-safe. Set/G
boliu
2014/05/21 01:33:26
Ehh...that's because I forgot the lock :p
Fixed.
| |
| 132 } | |
| 133 | |
| 134 gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const { | |
| 135 DCHECK(share_context_); | |
| 136 return share_context_; | |
| 137 } | |
| 138 | |
| 122 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { | 139 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { |
| 123 base::AutoLock lock(lock_); | 140 base::AutoLock lock(lock_); |
| 124 memory_policy_dirty_ = is_dirty; | 141 memory_policy_dirty_ = is_dirty; |
| 125 } | 142 } |
| 126 | 143 |
| 127 bool SharedRendererState::IsMemoryPolicyDirty() const { | 144 bool SharedRendererState::IsMemoryPolicyDirty() const { |
| 128 base::AutoLock lock(lock_); | 145 base::AutoLock lock(lock_); |
| 129 return memory_policy_dirty_; | 146 return memory_policy_dirty_; |
| 130 } | 147 } |
| 131 | 148 |
| 149 void SharedRendererState::ReturnResources( | |
| 150 const cc::TransferableResourceArray& input) { | |
| 151 base::AutoLock lock(lock_); | |
| 152 cc::TransferableResource::ReturnResources(input, &returned_resources_); | |
| 153 } | |
| 154 | |
| 155 void SharedRendererState::InsertReturnedResources( | |
| 156 const cc::ReturnedResourceArray& resources) { | |
| 157 base::AutoLock lock(lock_); | |
| 158 returned_resources_.insert( | |
| 159 returned_resources_.end(), resources.begin(), resources.end()); | |
| 160 } | |
| 161 | |
| 162 void SharedRendererState::SwapReturnedResources( | |
| 163 cc::ReturnedResourceArray* resources) { | |
| 164 base::AutoLock lock(lock_); | |
| 165 resources->swap(returned_resources_); | |
| 166 } | |
| 167 | |
| 168 bool SharedRendererState::ReturnedResourcesEmpty() const { | |
| 169 base::AutoLock lock(lock_); | |
| 170 return returned_resources_.empty(); | |
| 171 } | |
| 172 | |
| 132 } // namespace android_webview | 173 } // namespace android_webview |
| OLD | NEW |