Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1033)

Side by Side Diff: android_webview/browser/shared_renderer_state.h

Issue 1816283005: Move SharedRendererState ownership to AwContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map> 8 #include <map>
9 9
10 #include "android_webview/browser/gl_view_renderer_manager.h" 10 #include "android_webview/browser/gl_view_renderer_manager.h"
11 #include "android_webview/browser/parent_compositor_draw_constraints.h" 11 #include "android_webview/browser/parent_compositor_draw_constraints.h"
12 #include "base/cancelable_callback.h" 12 #include "base/cancelable_callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "cc/output/compositor_frame_ack.h" 17 #include "cc/output/compositor_frame_ack.h"
18 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/vector2d.h" 19 #include "ui/gfx/geometry/vector2d.h"
20 20
21 struct AwDrawGLInfo; 21 struct AwDrawGLInfo;
22
23 namespace android_webview { 22 namespace android_webview {
24 23
25 namespace internal { 24 namespace internal {
26 class RequestDrawGLTracker; 25 class RequestDrawGLTracker;
27 } 26 }
28 27
29 class BrowserViewRenderer; 28 class SharedRendererStateClient;
30 class ChildFrame; 29 class ChildFrame;
31 class HardwareRenderer; 30 class HardwareRenderer;
32 class InsideHardwareReleaseReset; 31 class InsideHardwareReleaseReset;
33 32
34 // This class is used to pass data between UI thread and RenderThread. 33 // This class is used to pass data between UI thread and RenderThread.
35 class SharedRendererState { 34 class SharedRendererState {
36 public: 35 public:
37 struct ReturnedResources { 36 struct ReturnedResources {
38 ReturnedResources(); 37 ReturnedResources();
39 ~ReturnedResources(); 38 ~ReturnedResources();
40 39
41 uint32_t output_surface_id; 40 uint32_t output_surface_id;
42 cc::ReturnedResourceArray resources; 41 cc::ReturnedResourceArray resources;
43 }; 42 };
44 using ReturnedResourcesMap = std::map<uint32_t, ReturnedResources>; 43 using ReturnedResourcesMap = std::map<uint32_t, ReturnedResources>;
45 44
46 SharedRendererState( 45 SharedRendererState(
47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop, 46 SharedRendererStateClient* client,
48 BrowserViewRenderer* browser_view_renderer); 47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_loop);
49 ~SharedRendererState(); 48 ~SharedRendererState();
50 49
51 // This function can be called from any thread. 50 // This function can be called from any thread.
52 void ClientRequestDrawGL(bool for_idle); 51 void ClientRequestDrawGL(bool for_idle);
53 52
54 // UI thread methods. 53 // UI thread methods.
55 void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset); 54 void SetScrollOffsetOnUI(gfx::Vector2d scroll_offset);
56 void SetCompositorFrameOnUI(scoped_ptr<ChildFrame> frame); 55 void SetFrameOnUI(scoped_ptr<ChildFrame> frame);
57 void InitializeHardwareDrawIfNeededOnUI(); 56 void InitializeHardwareDrawIfNeededOnUI();
58 void ReleaseHardwareDrawIfNeededOnUI();
59 ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const; 57 ParentCompositorDrawConstraints GetParentDrawConstraintsOnUI() const;
60 void SwapReturnedResourcesOnUI(ReturnedResourcesMap* returned_resource_map); 58 void SwapReturnedResourcesOnUI(ReturnedResourcesMap* returned_resource_map);
61 bool ReturnedResourcesEmptyOnUI() const; 59 bool ReturnedResourcesEmptyOnUI() const;
62 scoped_ptr<ChildFrame> PassUncommittedFrameOnUI(); 60 scoped_ptr<ChildFrame> PassUncommittedFrameOnUI();
61 bool HasFrameOnUI() const;
62 void TrimMemoryOnUI(int level);
63 void DeleteHardwareRendererOnUI(); 63 void DeleteHardwareRendererOnUI();
64 bool HasFrameOnUI() const;
65 64
66 // RT thread methods. 65 // RT thread methods.
67 gfx::Vector2d GetScrollOffsetOnRT(); 66 gfx::Vector2d GetScrollOffsetOnRT();
68 scoped_ptr<ChildFrame> PassCompositorFrameOnRT(); 67 scoped_ptr<ChildFrame> PassFrameOnRT();
69 void DrawGL(AwDrawGLInfo* draw_info); 68 void DrawGL(AwDrawGLInfo* draw_info);
70 void PostExternalDrawConstraintsToChildCompositorOnRT( 69 void PostExternalDrawConstraintsToChildCompositorOnRT(
71 const ParentCompositorDrawConstraints& parent_draw_constraints); 70 const ParentCompositorDrawConstraints& parent_draw_constraints);
72 void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources, 71 void InsertReturnedResourcesOnRT(const cc::ReturnedResourceArray& resources,
73 uint32_t compositor_id, 72 uint32_t compositor_id,
74 uint32_t output_surface_id); 73 uint32_t output_surface_id);
75 74
76 private: 75 private:
77 friend class internal::RequestDrawGLTracker; 76 friend class internal::RequestDrawGLTracker;
78 class InsideHardwareReleaseReset { 77 class InsideHardwareReleaseReset {
79 public: 78 public:
80 explicit InsideHardwareReleaseReset( 79 explicit InsideHardwareReleaseReset(
81 SharedRendererState* shared_renderer_state); 80 SharedRendererState* shared_renderer_state);
82 ~InsideHardwareReleaseReset(); 81 ~InsideHardwareReleaseReset();
83 82
84 private: 83 private:
85 SharedRendererState* shared_renderer_state_; 84 SharedRendererState* shared_renderer_state_;
86 }; 85 };
87 86
88 // RT thread method. 87 // RT thread method.
89 void DidDrawGLProcess(); 88 void DidDrawGLProcess();
90 89
91 // UI thread methods. 90 // UI thread methods.
92 void ResetRequestDrawGLCallback(); 91 void ResetRequestDrawGLCallback();
93 void ClientRequestDrawGLOnUI(); 92 void ClientRequestDrawGLOnUI();
94 void UpdateParentDrawConstraintsOnUI(); 93 void UpdateParentDrawConstraintsOnUI();
95 bool IsInsideHardwareRelease() const; 94 bool IsInsideHardwareRelease() const;
96 void SetInsideHardwareRelease(bool inside); 95 void SetInsideHardwareRelease(bool inside);
97 void ReleaseCompositorResourcesIfNeededOnUI(bool release_hardware_draw);
98 96
99 // Accessed by UI thread. 97 // Accessed by UI thread.
100 scoped_refptr<base::SingleThreadTaskRunner> ui_loop_; 98 scoped_refptr<base::SingleThreadTaskRunner> ui_loop_;
101 BrowserViewRenderer* browser_view_renderer_; 99 SharedRendererStateClient* client_;
boliu 2016/03/24 17:34:45 SRSC* const client_
102 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_; 100 base::WeakPtr<SharedRendererState> ui_thread_weak_ptr_;
103 base::CancelableClosure request_draw_gl_cancelable_closure_; 101 base::CancelableClosure request_draw_gl_cancelable_closure_;
104 102
105 // Accessed by RT thread. 103 // Accessed by RT thread.
106 scoped_ptr<HardwareRenderer> hardware_renderer_; 104 scoped_ptr<HardwareRenderer> hardware_renderer_;
107 105
108 // This is accessed by both UI and RT now. TODO(hush): move to RT only. 106 // This is accessed by both UI and RT now. TODO(hush): move to RT only.
109 GLViewRendererManager::Key renderer_manager_key_; 107 GLViewRendererManager::Key renderer_manager_key_;
110 108
111 // Accessed by both UI and RT thread. 109 // Accessed by both UI and RT thread.
112 mutable base::Lock lock_; 110 mutable base::Lock lock_;
113 bool hardware_renderer_has_frame_; 111 bool hardware_renderer_has_frame_;
114 gfx::Vector2d scroll_offset_; 112 gfx::Vector2d scroll_offset_;
115 scoped_ptr<ChildFrame> child_frame_; 113 scoped_ptr<ChildFrame> child_frame_;
116 bool inside_hardware_release_; 114 bool inside_hardware_release_;
117 ParentCompositorDrawConstraints parent_draw_constraints_; 115 ParentCompositorDrawConstraints parent_draw_constraints_;
118 ReturnedResourcesMap returned_resources_map_; 116 ReturnedResourcesMap returned_resources_map_;
119 base::Closure request_draw_gl_closure_; 117 base::Closure request_draw_gl_closure_;
120 118
121 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_; 119 base::WeakPtrFactory<SharedRendererState> weak_factory_on_ui_thread_;
122 120
123 DISALLOW_COPY_AND_ASSIGN(SharedRendererState); 121 DISALLOW_COPY_AND_ASSIGN(SharedRendererState);
124 }; 122 };
125 123
126 } // namespace android_webview 124 } // namespace android_webview
127 125
128 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_ 126 #endif // ANDROID_WEBVIEW_BROWSER_SHARED_RENDERER_STATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698