| 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.h" | 7 #include "android_webview/browser/browser_view_renderer.h" |
| 8 #include "android_webview/browser/child_frame.h" |
| 8 #include "android_webview/browser/deferred_gpu_command_service.h" | 9 #include "android_webview/browser/deferred_gpu_command_service.h" |
| 9 #include "android_webview/browser/hardware_renderer.h" | 10 #include "android_webview/browser/hardware_renderer.h" |
| 10 #include "android_webview/browser/scoped_app_gl_state_restore.h" | 11 #include "android_webview/browser/scoped_app_gl_state_restore.h" |
| 11 #include "android_webview/public/browser/draw_gl.h" | 12 #include "android_webview/public/browser/draw_gl.h" |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
| 16 | 17 |
| 17 namespace android_webview { | 18 namespace android_webview { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 LAZY_INSTANCE_INITIALIZER; | 82 LAZY_INSTANCE_INITIALIZER; |
| 82 | 83 |
| 83 } | 84 } |
| 84 | 85 |
| 85 SharedRendererState::SharedRendererState( | 86 SharedRendererState::SharedRendererState( |
| 86 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, | 87 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, |
| 87 BrowserViewRenderer* browser_view_renderer) | 88 BrowserViewRenderer* browser_view_renderer) |
| 88 : ui_loop_(ui_loop), | 89 : ui_loop_(ui_loop), |
| 89 browser_view_renderer_(browser_view_renderer), | 90 browser_view_renderer_(browser_view_renderer), |
| 90 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()), | 91 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()), |
| 91 force_commit_(false), | |
| 92 inside_hardware_release_(false), | 92 inside_hardware_release_(false), |
| 93 needs_force_invalidate_on_next_draw_gl_(false), | |
| 94 weak_factory_on_ui_thread_(this) { | 93 weak_factory_on_ui_thread_(this) { |
| 95 DCHECK(ui_loop_->BelongsToCurrentThread()); | 94 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 96 DCHECK(browser_view_renderer_); | 95 DCHECK(browser_view_renderer_); |
| 97 ui_thread_weak_ptr_ = weak_factory_on_ui_thread_.GetWeakPtr(); | 96 ui_thread_weak_ptr_ = weak_factory_on_ui_thread_.GetWeakPtr(); |
| 98 ResetRequestDrawGLCallback(); | 97 ResetRequestDrawGLCallback(); |
| 99 } | 98 } |
| 100 | 99 |
| 101 SharedRendererState::~SharedRendererState() { | 100 SharedRendererState::~SharedRendererState() { |
| 102 DCHECK(ui_loop_->BelongsToCurrentThread()); | 101 DCHECK(ui_loop_->BelongsToCurrentThread()); |
| 103 DCHECK(!hardware_renderer_.get()); | 102 DCHECK(!hardware_renderer_.get()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void SharedRendererState::SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) { | 149 void SharedRendererState::SetScrollOffsetOnUI(gfx::Vector2d scroll_offset) { |
| 151 base::AutoLock lock(lock_); | 150 base::AutoLock lock(lock_); |
| 152 scroll_offset_ = scroll_offset; | 151 scroll_offset_ = scroll_offset; |
| 153 } | 152 } |
| 154 | 153 |
| 155 gfx::Vector2d SharedRendererState::GetScrollOffsetOnRT() { | 154 gfx::Vector2d SharedRendererState::GetScrollOffsetOnRT() { |
| 156 base::AutoLock lock(lock_); | 155 base::AutoLock lock(lock_); |
| 157 return scroll_offset_; | 156 return scroll_offset_; |
| 158 } | 157 } |
| 159 | 158 |
| 160 bool SharedRendererState::HasCompositorFrameOnUI() const { | 159 void SharedRendererState::SetCompositorFrameOnUI( |
| 160 scoped_ptr<ChildFrame> frame) { |
| 161 base::AutoLock lock(lock_); | 161 base::AutoLock lock(lock_); |
| 162 return compositor_frame_.get(); | 162 DCHECK(!child_frame_.get()); |
| 163 child_frame_ = frame.Pass(); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void SharedRendererState::SetCompositorFrameOnUI( | 166 scoped_ptr<ChildFrame> SharedRendererState::PassCompositorFrameOnRT() { |
| 166 scoped_ptr<cc::CompositorFrame> frame, | |
| 167 bool force_commit) { | |
| 168 base::AutoLock lock(lock_); | 167 base::AutoLock lock(lock_); |
| 169 DCHECK(!compositor_frame_.get()); | 168 return child_frame_.Pass(); |
| 170 compositor_frame_ = frame.Pass(); | |
| 171 force_commit_ = force_commit; | |
| 172 } | 169 } |
| 173 | 170 |
| 174 scoped_ptr<cc::CompositorFrame> SharedRendererState::PassCompositorFrameOnRT() { | 171 scoped_ptr<ChildFrame> |
| 175 base::AutoLock lock(lock_); | |
| 176 return compositor_frame_.Pass(); | |
| 177 } | |
| 178 | |
| 179 scoped_ptr<cc::CompositorFrame> | |
| 180 SharedRendererState::PassUncommittedFrameOnUI() { | 172 SharedRendererState::PassUncommittedFrameOnUI() { |
| 181 base::AutoLock lock(lock_); | 173 base::AutoLock lock(lock_); |
| 182 return compositor_frame_.Pass(); | 174 return child_frame_.Pass(); |
| 183 } | |
| 184 | |
| 185 bool SharedRendererState::ForceCommitOnRT() const { | |
| 186 base::AutoLock lock(lock_); | |
| 187 return force_commit_; | |
| 188 } | |
| 189 | |
| 190 bool SharedRendererState::UpdateDrawConstraintsOnRT( | |
| 191 const ParentCompositorDrawConstraints& parent_draw_constraints) { | |
| 192 base::AutoLock lock(lock_); | |
| 193 if (needs_force_invalidate_on_next_draw_gl_ || | |
| 194 !parent_draw_constraints_.Equals(parent_draw_constraints)) { | |
| 195 parent_draw_constraints_ = parent_draw_constraints; | |
| 196 return true; | |
| 197 } | |
| 198 | |
| 199 return false; | |
| 200 } | 175 } |
| 201 | 176 |
| 202 void SharedRendererState::PostExternalDrawConstraintsToChildCompositorOnRT( | 177 void SharedRendererState::PostExternalDrawConstraintsToChildCompositorOnRT( |
| 203 const ParentCompositorDrawConstraints& parent_draw_constraints) { | 178 const ParentCompositorDrawConstraints& parent_draw_constraints) { |
| 204 if (UpdateDrawConstraintsOnRT(parent_draw_constraints)) { | 179 { |
| 205 // No need to hold the lock_ during the post task. | 180 base::AutoLock lock(lock_); |
| 206 ui_loop_->PostTask( | 181 parent_draw_constraints_ = parent_draw_constraints; |
| 207 FROM_HERE, | |
| 208 base::Bind(&SharedRendererState::UpdateParentDrawConstraintsOnUI, | |
| 209 ui_thread_weak_ptr_)); | |
| 210 } | 182 } |
| 211 } | |
| 212 | 183 |
| 213 void SharedRendererState::DidSkipCommitFrameOnRT() { | 184 // No need to hold the lock_ during the post task. |
| 214 ui_loop_->PostTask(FROM_HERE, | 185 ui_loop_->PostTask( |
| 215 base::Bind(&SharedRendererState::DidSkipCommitFrameOnUI, | 186 FROM_HERE, |
| 216 ui_thread_weak_ptr_)); | 187 base::Bind(&SharedRendererState::UpdateParentDrawConstraintsOnUI, |
| 217 } | 188 ui_thread_weak_ptr_)); |
| 218 | |
| 219 void SharedRendererState::DidSkipCommitFrameOnUI() { | |
| 220 DCHECK(ui_loop_->BelongsToCurrentThread()); | |
| 221 browser_view_renderer_->DidSkipCommitFrame(); | |
| 222 } | 189 } |
| 223 | 190 |
| 224 ParentCompositorDrawConstraints | 191 ParentCompositorDrawConstraints |
| 225 SharedRendererState::GetParentDrawConstraintsOnUI() const { | 192 SharedRendererState::GetParentDrawConstraintsOnUI() const { |
| 226 base::AutoLock lock(lock_); | 193 base::AutoLock lock(lock_); |
| 227 return parent_draw_constraints_; | 194 return parent_draw_constraints_; |
| 228 } | 195 } |
| 229 | 196 |
| 230 void SharedRendererState::SetForceInvalidateOnNextDrawGLOnUI( | |
| 231 bool needs_force_invalidate_on_next_draw_gl) { | |
| 232 base::AutoLock lock(lock_); | |
| 233 needs_force_invalidate_on_next_draw_gl_ = | |
| 234 needs_force_invalidate_on_next_draw_gl; | |
| 235 } | |
| 236 | |
| 237 bool SharedRendererState::NeedsForceInvalidateOnNextDrawGLOnUI() const { | |
| 238 base::AutoLock lock(lock_); | |
| 239 return needs_force_invalidate_on_next_draw_gl_; | |
| 240 } | |
| 241 | |
| 242 void SharedRendererState::SetInsideHardwareRelease(bool inside) { | 197 void SharedRendererState::SetInsideHardwareRelease(bool inside) { |
| 243 base::AutoLock lock(lock_); | 198 base::AutoLock lock(lock_); |
| 244 inside_hardware_release_ = inside; | 199 inside_hardware_release_ = inside; |
| 245 } | 200 } |
| 246 | 201 |
| 247 bool SharedRendererState::IsInsideHardwareRelease() const { | 202 bool SharedRendererState::IsInsideHardwareRelease() const { |
| 248 base::AutoLock lock(lock_); | 203 base::AutoLock lock(lock_); |
| 249 return inside_hardware_release_; | 204 return inside_hardware_release_; |
| 250 } | 205 } |
| 251 | 206 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 : shared_renderer_state_(shared_renderer_state) { | 337 : shared_renderer_state_(shared_renderer_state) { |
| 383 DCHECK(!shared_renderer_state_->IsInsideHardwareRelease()); | 338 DCHECK(!shared_renderer_state_->IsInsideHardwareRelease()); |
| 384 shared_renderer_state_->SetInsideHardwareRelease(true); | 339 shared_renderer_state_->SetInsideHardwareRelease(true); |
| 385 } | 340 } |
| 386 | 341 |
| 387 SharedRendererState::InsideHardwareReleaseReset::~InsideHardwareReleaseReset() { | 342 SharedRendererState::InsideHardwareReleaseReset::~InsideHardwareReleaseReset() { |
| 388 shared_renderer_state_->SetInsideHardwareRelease(false); | 343 shared_renderer_state_->SetInsideHardwareRelease(false); |
| 389 } | 344 } |
| 390 | 345 |
| 391 } // namespace android_webview | 346 } // namespace android_webview |
| OLD | NEW |