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