| 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 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 
| 6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 
| 7 | 7 | 
| 8 #include "android_webview/browser/gl_view_renderer_manager.h" | 8 #include "android_webview/browser/gl_view_renderer_manager.h" | 
| 9 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 9 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 
| 10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" | 
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" | 
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" | 
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" | 
| 14 #include "cc/output/compositor_frame.h" |  | 
| 15 #include "cc/output/compositor_frame_ack.h" | 14 #include "cc/output/compositor_frame_ack.h" | 
| 16 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" | 
| 17 #include "ui/gfx/geometry/vector2d.h" | 16 #include "ui/gfx/geometry/vector2d.h" | 
| 18 | 17 | 
| 19 struct AwDrawGLInfo; | 18 struct AwDrawGLInfo; | 
| 20 | 19 | 
| 21 namespace android_webview { | 20 namespace android_webview { | 
| 22 | 21 | 
| 23 namespace internal { | 22 namespace internal { | 
| 24 class RequestDrawGLTracker; | 23 class RequestDrawGLTracker; | 
| 25 } | 24 } | 
| 26 | 25 | 
| 27 class BrowserViewRenderer; | 26 class BrowserViewRenderer; | 
|  | 27 class ChildFrame; | 
| 28 class HardwareRenderer; | 28 class HardwareRenderer; | 
| 29 class InsideHardwareReleaseReset; | 29 class InsideHardwareReleaseReset; | 
| 30 | 30 | 
| 31 // This class is used to pass data between UI thread and RenderThread. | 31 // This class is used to pass data between UI thread and RenderThread. | 
| 32 class SharedRendererState { | 32 class SharedRendererState { | 
| 33  public: | 33  public: | 
| 34   SharedRendererState( | 34   SharedRendererState( | 
| 35       const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, | 35       const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, | 
| 36       BrowserViewRenderer* browser_view_renderer); | 36       BrowserViewRenderer* browser_view_renderer); | 
| 37   ~SharedRendererState(); | 37   ~SharedRendererState(); | 
| 38 | 38 | 
| 39   // This function can be called from any thread. | 39   // This function can be called from any thread. | 
| 40   void ClientRequestDrawGL(); | 40   void ClientRequestDrawGL(); | 
| 41 | 41 | 
| 42   // UI thread methods. | 42   // UI thread methods. | 
| 43   void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset); | 43   void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset); | 
| 44   bool HasCompositorFrameOnUI() const; | 44   void SetCompositorFrameOnUI(scoped_ptr<ChildFrame> frame); | 
| 45   void SetCompositorFrameOnUI(scoped_ptr<cc::CompositorFrame> frame, |  | 
| 46                               bool force_commit); |  | 
| 47   void InitializeHardwareDrawIfNeededOnUI(); | 45   void InitializeHardwareDrawIfNeededOnUI(); | 
| 48   void ReleaseHardwareDrawIfNeededOnUI(); | 46   void ReleaseHardwareDrawIfNeededOnUI(); | 
| 49   ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const; | 47   ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const; | 
| 50   void SetForceInvalidateOnNextDrawGLOnUI( |  | 
| 51       bool needs_force_invalidate_on_next_draw_gl); |  | 
| 52   bool NeedsForceInvalidateOnNextDrawGLOnUI() const; |  | 
| 53   void SwapReturnedResourcesOnUI(cc::ReturnedResourceArray* resources); | 48   void SwapReturnedResourcesOnUI(cc::ReturnedResourceArray* resources); | 
| 54   bool ReturnedResourcesEmptyOnUI() const; | 49   bool ReturnedResourcesEmptyOnUI() const; | 
| 55   scoped_ptr<cc::CompositorFrame> PassUncommittedFrameOnUI(); | 50   scoped_ptr<ChildFrame> PassUncommittedFrameOnUI(); | 
| 56 | 51 | 
| 57   // RT thread methods. | 52   // RT thread methods. | 
| 58   gfx::Vector2d GetScrollOffsetOnRT(); | 53   gfx::Vector2d GetScrollOffsetOnRT(); | 
| 59   scoped_ptr<cc::CompositorFrame> PassCompositorFrameOnRT(); | 54   scoped_ptr<ChildFrame> PassCompositorFrameOnRT(); | 
| 60   bool ForceCommitOnRT() const; |  | 
| 61   void DrawGL(AwDrawGLInfo* draw_info); | 55   void DrawGL(AwDrawGLInfo* draw_info); | 
| 62   // Returns true if the draw constraints are updated. |  | 
| 63   bool UpdateDrawConstraintsOnRT( |  | 
| 64       const ParentCompositorDrawConstraints& parent_draw_constraints); |  | 
| 65   void PostExternalDrawConstraintsToChildCompositorOnRT( | 56   void PostExternalDrawConstraintsToChildCompositorOnRT( | 
| 66       const ParentCompositorDrawConstraints& parent_draw_constraints); | 57       const ParentCompositorDrawConstraints& parent_draw_constraints); | 
| 67   void DidSkipCommitFrameOnRT(); |  | 
| 68   void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources); | 58   void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources); | 
| 69 | 59 | 
| 70  private: | 60  private: | 
| 71   friend class internal::RequestDrawGLTracker; | 61   friend class internal::RequestDrawGLTracker; | 
| 72   class InsideHardwareReleaseReset { | 62   class InsideHardwareReleaseReset { | 
| 73    public: | 63    public: | 
| 74     explicit InsideHardwareReleaseReset( | 64     explicit InsideHardwareReleaseReset( | 
| 75         SharedRendererState* shared_renderer_state); | 65         SharedRendererState* shared_renderer_state); | 
| 76     ~InsideHardwareReleaseReset(); | 66     ~InsideHardwareReleaseReset(); | 
| 77 | 67 | 
| 78    private: | 68    private: | 
| 79     SharedRendererState* shared_renderer_state_; | 69     SharedRendererState* shared_renderer_state_; | 
| 80   }; | 70   }; | 
| 81 | 71 | 
| 82   // RT thread method. | 72   // RT thread method. | 
| 83   void DidDrawGLProcess(); | 73   void DidDrawGLProcess(); | 
| 84 | 74 | 
| 85   // UI thread methods. | 75   // UI thread methods. | 
| 86   void ResetRequestDrawGLCallback(); | 76   void ResetRequestDrawGLCallback(); | 
| 87   void ClientRequestDrawGLOnUI(); | 77   void ClientRequestDrawGLOnUI(); | 
| 88   void UpdateParentDrawConstraintsOnUI(); | 78   void UpdateParentDrawConstraintsOnUI(); | 
| 89   void DidSkipCommitFrameOnUI(); |  | 
| 90   bool IsInsideHardwareRelease() const; | 79   bool IsInsideHardwareRelease() const; | 
| 91   void SetInsideHardwareRelease(bool inside); | 80   void SetInsideHardwareRelease(bool inside); | 
| 92 | 81 | 
| 93   // Accessed by UI thread. | 82   // Accessed by UI thread. | 
| 94   scoped_refptr<base::SingleThreadTaskRunner> ui_loop_; | 83   scoped_refptr<base::SingleThreadTaskRunner> ui_loop_; | 
| 95   BrowserViewRenderer* browser_view_renderer_; | 84   BrowserViewRenderer* browser_view_renderer_; | 
| 96   base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; | 85   base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; | 
| 97   base::CancelableClosure request_draw_gl_cancelable_closure_; | 86   base::CancelableClosure request_draw_gl_cancelable_closure_; | 
| 98 | 87 | 
| 99   // Accessed by RT thread. | 88   // Accessed by RT thread. | 
| 100   scoped_ptr<HardwareRenderer> hardware_renderer_; | 89   scoped_ptr<HardwareRenderer> hardware_renderer_; | 
| 101 | 90 | 
| 102   // This is accessed by both UI and RT now. TODO(hush): move to RT only. | 91   // This is accessed by both UI and RT now. TODO(hush): move to RT only. | 
| 103   GLViewRendererManager::Key renderer_manager_key_; | 92   GLViewRendererManager::Key renderer_manager_key_; | 
| 104 | 93 | 
| 105   // Accessed by both UI and RT thread. | 94   // Accessed by both UI and RT thread. | 
| 106   mutable base::Lock lock_; | 95   mutable base::Lock lock_; | 
| 107   gfx::Vector2d scroll_offset_; | 96   gfx::Vector2d scroll_offset_; | 
| 108   scoped_ptr<cc::CompositorFrame> compositor_frame_; | 97   scoped_ptr<ChildFrame> child_frame_; | 
| 109   bool force_commit_; |  | 
| 110   bool inside_hardware_release_; | 98   bool inside_hardware_release_; | 
| 111   bool needs_force_invalidate_on_next_draw_gl_; |  | 
| 112   ParentCompositorDrawConstraints parent_draw_constraints_; | 99   ParentCompositorDrawConstraints parent_draw_constraints_; | 
| 113   cc::ReturnedResourceArray returned_resources_; | 100   cc::ReturnedResourceArray returned_resources_; | 
| 114   base::Closure request_draw_gl_closure_; | 101   base::Closure request_draw_gl_closure_; | 
| 115 | 102 | 
| 116   base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; | 103   base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; | 
| 117 | 104 | 
| 118   DISALLOW_COPY_AND_ASSIGN(SharedRendererState); | 105   DISALLOW_COPY_AND_ASSIGN(SharedRendererState); | 
| 119 }; | 106 }; | 
| 120 | 107 | 
| 121 }  // namespace android_webview | 108 }  // namespace android_webview | 
| 122 | 109 | 
| 123 #endif  // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 110 #endif  // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ | 
| OLD | NEW | 
|---|