Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / browser / shared_renderer_state.cc
index 596f994..3483d63 100644 (file)
@@ -8,27 +8,22 @@
 #include "base/bind.h"
 #include "base/location.h"
 
-using base::AutoLock;
-
 namespace android_webview {
 
-DrawGLInput::DrawGLInput() : frame_id(0) {}
+DrawGLInput::DrawGLInput() : frame_id(0), width(0), height(0) {}
 
 DrawGLResult::DrawGLResult() : frame_id(0), clip_contains_visible_rect(false) {}
 
-namespace internal {
-
-BothThreads::BothThreads() : compositor(NULL) {}
-
-}  // namespace internal
-
 SharedRendererState::SharedRendererState(
     scoped_refptr<base::MessageLoopProxy> ui_loop,
     BrowserViewRendererClient* client)
     : ui_loop_(ui_loop),
       client_on_ui_(client),
       weak_factory_on_ui_thread_(this),
-      ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()) {
+      ui_thread_weak_ptr_(weak_factory_on_ui_thread_.GetWeakPtr()),
+      compositor_(NULL),
+      memory_policy_dirty_(false),
+      hardware_initialized_(false) {
   DCHECK(ui_loop_->BelongsToCurrentThread());
   DCHECK(client_on_ui_);
 }
@@ -48,80 +43,90 @@ void SharedRendererState::ClientRequestDrawGL() {
 
 void SharedRendererState::ClientRequestDrawGLOnUIThread() {
   DCHECK(ui_loop_->BelongsToCurrentThread());
-  if (!client_on_ui_->RequestDrawGL(NULL)) {
+  if (!client_on_ui_->RequestDrawGL(NULL, false)) {
     LOG(ERROR) << "Failed to request GL process. Deadlock likely";
   }
 }
 
 void SharedRendererState::SetCompositorOnUiThread(
     content::SynchronousCompositor* compositor) {
-  AutoLock lock(lock_);
+  base::AutoLock lock(lock_);
   DCHECK(ui_loop_->BelongsToCurrentThread());
-  both().compositor = compositor;
+  compositor_ = compositor;
 }
 
-bool SharedRendererState::CompositorInitializeHwDraw(
-    scoped_refptr<gfx::GLSurface> surface) {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  return both().compositor->InitializeHwDraw(surface);
+content::SynchronousCompositor* SharedRendererState::GetCompositor() {
+  base::AutoLock lock(lock_);
+  DCHECK(compositor_);
+  return compositor_;
 }
 
-void SharedRendererState::CompositorReleaseHwDraw() {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  both().compositor->ReleaseHwDraw();
+void SharedRendererState::SetMemoryPolicy(
+    const content::SynchronousCompositorMemoryPolicy new_policy) {
+  base::AutoLock lock(lock_);
+  if (memory_policy_ != new_policy) {
+    memory_policy_ = new_policy;
+    memory_policy_dirty_ = true;
+  }
 }
 
-bool SharedRendererState::CompositorDemandDrawHw(
-    gfx::Size surface_size,
-    const gfx::Transform& transform,
-    gfx::Rect viewport,
-    gfx::Rect clip,
-    bool stencil_enabled) {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  return both().compositor->DemandDrawHw(
-      surface_size, transform, viewport, clip, stencil_enabled);
+content::SynchronousCompositorMemoryPolicy
+SharedRendererState::GetMemoryPolicy() const {
+  base::AutoLock lock(lock_);
+  return memory_policy_;
 }
 
-bool SharedRendererState::CompositorDemandDrawSw(SkCanvas* canvas) {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  return both().compositor->DemandDrawSw(canvas);
+void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) {
+  base::AutoLock lock(lock_);
+  draw_gl_input_ = input;
 }
 
-void SharedRendererState::CompositorSetMemoryPolicy(
-    const content::SynchronousCompositorMemoryPolicy& policy) {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  return both().compositor->SetMemoryPolicy(policy);
+DrawGLInput SharedRendererState::GetDrawGLInput() const {
+  base::AutoLock lock(lock_);
+  return draw_gl_input_;
 }
 
-void SharedRendererState::CompositorDidChangeRootLayerScrollOffset() {
-  AutoLock lock(lock_);
-  DCHECK(both().compositor);
-  both().compositor->DidChangeRootLayerScrollOffset();
+void SharedRendererState::ClearClosureQueue() {
+  base::AutoLock lock(lock_);
+  std::queue<base::Closure> empty;
+  std::swap(closure_queue_, empty);
 }
 
-void SharedRendererState::SetDrawGLInput(const DrawGLInput& input) {
-  AutoLock lock(lock_);
-  both().draw_gl_input = input;
+void SharedRendererState::AppendClosure(const base::Closure& closure) {
+  base::AutoLock lock(lock_);
+  closure_queue_.push(closure);
 }
 
-DrawGLInput SharedRendererState::GetDrawGLInput() const {
-  AutoLock lock(lock_);
-  return both().draw_gl_input;
+base::Closure SharedRendererState::PopFrontClosure() {
+  base::Closure closure;
+
+  base::AutoLock lock(lock_);
+  if (!closure_queue_.empty()) {
+    closure = closure_queue_.front();
+    closure_queue_.pop();
+  }
+
+  return closure;
+}
+
+void SharedRendererState::SetHardwareInitialized(bool initialized) {
+  base::AutoLock lock(lock_);
+  hardware_initialized_ = initialized;
+}
+
+bool SharedRendererState::IsHardwareInitialized() const {
+  base::AutoLock lock(lock_);
+  return hardware_initialized_;
 }
 
-internal::BothThreads& SharedRendererState::both() {
-  lock_.AssertAcquired();
-  return both_threads_;
+void SharedRendererState::SetMemoryPolicyDirty(bool is_dirty) {
+  base::AutoLock lock(lock_);
+  memory_policy_dirty_ = is_dirty;
 }
 
-const internal::BothThreads& SharedRendererState::both() const {
-  lock_.AssertAcquired();
-  return both_threads_;
+bool SharedRendererState::IsMemoryPolicyDirty() const {
+  base::AutoLock lock(lock_);
+  return memory_policy_dirty_;
 }
 
 }  // namespace android_webview