| 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 DrawGLResult::DrawGLResult() : frame_id(0), clip_contains_visible_rect(false) {} | 15 DrawGLInput::~DrawGLInput() { |
| 16 } |
| 17 |
| 18 DrawGLResult::DrawGLResult() : clip_contains_visible_rect(false) {} |
| 16 | 19 |
| 17 SharedRendererState::SharedRendererState( | 20 SharedRendererState::SharedRendererState( |
| 18 scoped_refptr<base::MessageLoopProxy> ui_loop, | 21 scoped_refptr<base::MessageLoopProxy> ui_loop, |
| 19 BrowserViewRendererClient* client) | 22 BrowserViewRendererClient* client) |
| 20 : ui_loop_(ui_loop), | 23 : ui_loop_(ui_loop), |
| 21 client_on_ui_(client), | 24 client_on_ui_(client), |
| 22 weak_factory_on_ui_thread_(this), | 25 weak_factory_on_ui_thread_(this), |
| 23 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), | 26 ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()), |
| 24 compositor_(NULL), | 27 compositor_(NULL), |
| 25 memory_policy_dirty_(false), | 28 memory_policy_dirty_(false), |
| 26 hardware_initialized_(false) { | 29 hardware_initialized_(false), |
| 30 share_context_(NULL) { |
| 27 DCHECK(ui_loop_->BelongsToCurrentThread()); | 31 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 28 DCHECK(client_on_ui_); | 32 DCHECK(client_on_ui_); |
| 29 } | 33 } |
| 30 | 34 |
| 31 SharedRendererState::~SharedRendererState() {} | 35 SharedRendererState::~SharedRendererState() {} |
| 32 | 36 |
| 33 void SharedRendererState::ClientRequestDrawGL() { | 37 void SharedRendererState::ClientRequestDrawGL() { |
| 34 if (ui_loop_->BelongsToCurrentThread()) { | 38 if (ui_loop_->BelongsToCurrentThread()) { |
| 35 ClientRequestDrawGLOnUIThread(); | 39 ClientRequestDrawGLOnUIThread(); |
| 36 } else { | 40 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 memory_policy_dirty_ = true; | 73 memory_policy_dirty_ = true; |
| 70 } | 74 } |
| 71 } | 75 } |
| 72 | 76 |
| 73 content::SynchronousCompositorMemoryPolicy | 77 content::SynchronousCompositorMemoryPolicy |
| 74 SharedRendererState::GetMemoryPolicy() const { | 78 SharedRendererState::GetMemoryPolicy() const { |
| 75 base::AutoLock lock(lock_); | 79 base::AutoLock lock(lock_); |
| 76 return memory_policy_; | 80 return memory_policy_; |
| 77 } | 81 } |
| 78 | 82 |
| 79 void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) { | 83 void SharedRendererState::SetDrawGLInput( |
| 84 scoped_ptr<DrawGLInput> input) { |
| 80 base::AutoLock lock(lock_); | 85 base::AutoLock lock(lock_); |
| 81 draw_gl_input_ = input; | 86 DCHECK(!draw_gl_input_.get()); |
| 87 draw_gl_input_ = input.Pass(); |
| 82 } | 88 } |
| 83 | 89 |
| 84 DrawGLInput SharedRendererState::GetDrawGLInput() const { | 90 scoped_ptr<DrawGLInput> SharedRendererState::PassDrawGLInput() { |
| 85 base::AutoLock lock(lock_); | 91 base::AutoLock lock(lock_); |
| 86 return draw_gl_input_; | 92 return draw_gl_input_.Pass(); |
| 87 } | 93 } |
| 88 | 94 |
| 89 void SharedRendererState::ClearClosureQueue() { | 95 void SharedRendererState::ClearClosureQueue() { |
| 90 base::AutoLock lock(lock_); | 96 base::AutoLock lock(lock_); |
| 91 std::queue<base::Closure> empty; | 97 std::queue<base::Closure> empty; |
| 92 std::swap(closure_queue_, empty); | 98 std::swap(closure_queue_, empty); |
| 93 } | 99 } |
| 94 | 100 |
| 95 void SharedRendererState::AppendClosure(const base::Closure& closure) { | 101 void SharedRendererState::AppendClosure(const base::Closure& closure) { |
| 96 base::AutoLock lock(lock_); | 102 base::AutoLock lock(lock_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 void SharedRendererState::SetHardwareInitialized(bool initialized) { | 118 void SharedRendererState::SetHardwareInitialized(bool initialized) { |
| 113 base::AutoLock lock(lock_); | 119 base::AutoLock lock(lock_); |
| 114 hardware_initialized_ = initialized; | 120 hardware_initialized_ = initialized; |
| 115 } | 121 } |
| 116 | 122 |
| 117 bool SharedRendererState::IsHardwareInitialized() const { | 123 bool SharedRendererState::IsHardwareInitialized() const { |
| 118 base::AutoLock lock(lock_); | 124 base::AutoLock lock(lock_); |
| 119 return hardware_initialized_; | 125 return hardware_initialized_; |
| 120 } | 126 } |
| 121 | 127 |
| 128 void SharedRendererState::SetSharedContext(gpu::GLInProcessContext* context) { |
| 129 DCHECK(!share_context_ || !context); |
| 130 share_context_ = context; |
| 131 } |
| 132 |
| 133 gpu::GLInProcessContext* SharedRendererState::GetSharedContext() const { |
| 134 DCHECK(share_context_); |
| 135 return share_context_; |
| 136 } |
| 137 |
| 122 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { | 138 void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) { |
| 123 base::AutoLock lock(lock_); | 139 base::AutoLock lock(lock_); |
| 124 memory_policy_dirty_ = is_dirty; | 140 memory_policy_dirty_ = is_dirty; |
| 125 } | 141 } |
| 126 | 142 |
| 127 bool SharedRendererState::IsMemoryPolicyDirty() const { | 143 bool SharedRendererState::IsMemoryPolicyDirty() const { |
| 128 base::AutoLock lock(lock_); | 144 base::AutoLock lock(lock_); |
| 129 return memory_policy_dirty_; | 145 return memory_policy_dirty_; |
| 130 } | 146 } |
| 131 | 147 |
| 148 void SharedRendererState::ReturnResources( |
| 149 const cc::TransferableResourceArray& input) { |
| 150 base::AutoLock lock(lock_); |
| 151 cc::TransferableResource::ReturnResources(input, &returned_resources_); |
| 152 } |
| 153 |
| 154 void SharedRendererState::InsertReturnedResources( |
| 155 const cc::ReturnedResourceArray& resources) { |
| 156 base::AutoLock lock(lock_); |
| 157 returned_resources_.insert( |
| 158 returned_resources_.end(), resources.begin(), resources.end()); |
| 159 } |
| 160 |
| 161 void SharedRendererState::SwapReturnedResources( |
| 162 cc::ReturnedResourceArray* resources) { |
| 163 base::AutoLock lock(lock_); |
| 164 resources->swap(returned_resources_); |
| 165 } |
| 166 |
| 167 bool SharedRendererState::ReturnedResourcesEmpty() const { |
| 168 base::AutoLock lock(lock_); |
| 169 return returned_resources_.empty(); |
| 170 } |
| 171 |
| 132 } // namespace android_webview | 172 } // namespace android_webview |
| OLD | NEW |