| 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(scoped_ptr<ChildFrame> frame) { | 
| 161   base::AutoLock lock(lock_); | 160   base::AutoLock lock(lock_); | 
| 162   return compositor_frame_.get(); | 161   DCHECK(!child_frame_.get()); | 
|  | 162   child_frame_ = frame.Pass(); | 
| 163 } | 163 } | 
| 164 | 164 | 
| 165 void SharedRendererState::SetCompositorFrameOnUI( | 165 scoped_ptr<ChildFrame> SharedRendererState::PassCompositorFrameOnRT() { | 
| 166     scoped_ptr<cc::CompositorFrame> frame, |  | 
| 167     bool force_commit) { |  | 
| 168   base::AutoLock lock(lock_); | 166   base::AutoLock lock(lock_); | 
| 169   DCHECK(!compositor_frame_.get()); | 167   return child_frame_.Pass(); | 
| 170   compositor_frame_ = frame.Pass(); |  | 
| 171   force_commit_ = force_commit; |  | 
| 172 } | 168 } | 
| 173 | 169 | 
| 174 scoped_ptr<cc::CompositorFrame> SharedRendererState::PassCompositorFrameOnRT() { | 170 scoped_ptr<ChildFrame> SharedRendererState::PassUncommittedFrameOnUI() { | 
| 175   base::AutoLock lock(lock_); | 171   base::AutoLock lock(lock_); | 
| 176   return compositor_frame_.Pass(); | 172   return child_frame_.Pass(); | 
| 177 } |  | 
| 178 |  | 
| 179 scoped_ptr<cc::CompositorFrame> |  | 
| 180 SharedRendererState::PassUncommittedFrameOnUI() { |  | 
| 181   base::AutoLock lock(lock_); |  | 
| 182   return compositor_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 } | 173 } | 
| 201 | 174 | 
| 202 void SharedRendererState::PostExternalDrawConstraintsToChildCompositorOnRT( | 175 void SharedRendererState::PostExternalDrawConstraintsToChildCompositorOnRT( | 
| 203     const ParentCompositorDrawConstraints& parent_draw_constraints) { | 176     const ParentCompositorDrawConstraints& parent_draw_constraints) { | 
| 204   if (UpdateDrawConstraintsOnRT(parent_draw_constraints)) { | 177   { | 
| 205     // No need to hold the lock_ during the post task. | 178     base::AutoLock lock(lock_); | 
| 206     ui_loop_->PostTask( | 179     parent_draw_constraints_ = parent_draw_constraints; | 
| 207         FROM_HERE, |  | 
| 208         base::Bind(&SharedRendererState::UpdateParentDrawConstraintsOnUI, |  | 
| 209                    ui_thread_weak_ptr_)); |  | 
| 210   } | 180   } | 
| 211 } |  | 
| 212 | 181 | 
| 213 void SharedRendererState::DidSkipCommitFrameOnRT() { | 182   // No need to hold the lock_ during the post task. | 
| 214   ui_loop_->PostTask(FROM_HERE, | 183   ui_loop_->PostTask( | 
| 215                      base::Bind(&SharedRendererState::DidSkipCommitFrameOnUI, | 184       FROM_HERE, | 
| 216                                 ui_thread_weak_ptr_)); | 185       base::Bind(&SharedRendererState::UpdateParentDrawConstraintsOnUI, | 
| 217 } | 186                  ui_thread_weak_ptr_)); | 
| 218 |  | 
| 219 void SharedRendererState::DidSkipCommitFrameOnUI() { |  | 
| 220   DCHECK(ui_loop_->BelongsToCurrentThread()); |  | 
| 221   browser_view_renderer_->DidSkipCommitFrame(); |  | 
| 222 } | 187 } | 
| 223 | 188 | 
| 224 ParentCompositorDrawConstraints | 189 ParentCompositorDrawConstraints | 
| 225 SharedRendererState::GetParentDrawConstraintsOnUI() const { | 190 SharedRendererState::GetParentDrawConstraintsOnUI() const { | 
| 226   base::AutoLock lock(lock_); | 191   base::AutoLock lock(lock_); | 
| 227   return parent_draw_constraints_; | 192   return parent_draw_constraints_; | 
| 228 } | 193 } | 
| 229 | 194 | 
| 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) { | 195 void SharedRendererState::SetInsideHardwareRelease(bool inside) { | 
| 243   base::AutoLock lock(lock_); | 196   base::AutoLock lock(lock_); | 
| 244   inside_hardware_release_ = inside; | 197   inside_hardware_release_ = inside; | 
| 245 } | 198 } | 
| 246 | 199 | 
| 247 bool SharedRendererState::IsInsideHardwareRelease() const { | 200 bool SharedRendererState::IsInsideHardwareRelease() const { | 
| 248   base::AutoLock lock(lock_); | 201   base::AutoLock lock(lock_); | 
| 249   return inside_hardware_release_; | 202   return inside_hardware_release_; | 
| 250 } | 203 } | 
| 251 | 204 | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 382     : shared_renderer_state_(shared_renderer_state) { | 335     : shared_renderer_state_(shared_renderer_state) { | 
| 383   DCHECK(!shared_renderer_state_->IsInsideHardwareRelease()); | 336   DCHECK(!shared_renderer_state_->IsInsideHardwareRelease()); | 
| 384   shared_renderer_state_->SetInsideHardwareRelease(true); | 337   shared_renderer_state_->SetInsideHardwareRelease(true); | 
| 385 } | 338 } | 
| 386 | 339 | 
| 387 SharedRendererState::InsideHardwareReleaseReset::~InsideHardwareReleaseReset() { | 340 SharedRendererState::InsideHardwareReleaseReset::~InsideHardwareReleaseReset() { | 
| 388   shared_renderer_state_->SetInsideHardwareRelease(false); | 341   shared_renderer_state_->SetInsideHardwareRelease(false); | 
| 389 } | 342 } | 
| 390 | 343 | 
| 391 }  // namespace android_webview | 344 }  // namespace android_webview | 
| OLD | NEW | 
|---|