OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_BROWSER_VIEW_RENDERER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "android_webview/browser/compositor_frame_producer.h" | 13 #include "android_webview/browser/compositor_frame_producer.h" |
| 14 #include "android_webview/browser/compositor_id.h" |
14 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 15 #include "android_webview/browser/parent_compositor_draw_constraints.h" |
15 #include "base/callback.h" | 16 #include "base/callback.h" |
16 #include "base/cancelable_callback.h" | 17 #include "base/cancelable_callback.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
19 #include "content/public/browser/android/synchronous_compositor.h" | 20 #include "content/public/browser/android/synchronous_compositor.h" |
20 #include "content/public/browser/android/synchronous_compositor_client.h" | 21 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 22 #include "content/public/browser/web_contents_observer.h" |
21 #include "third_party/skia/include/core/SkRefCnt.h" | 23 #include "third_party/skia/include/core/SkRefCnt.h" |
22 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
23 #include "ui/gfx/geometry/size_f.h" | 25 #include "ui/gfx/geometry/size_f.h" |
24 #include "ui/gfx/geometry/vector2d_f.h" | 26 #include "ui/gfx/geometry/vector2d_f.h" |
25 | 27 |
26 class SkCanvas; | 28 class SkCanvas; |
27 class SkPicture; | 29 class SkPicture; |
28 | 30 |
29 namespace content { | 31 namespace content { |
| 32 class RenderViewHost; |
30 class WebContents; | 33 class WebContents; |
31 } | 34 } |
32 | 35 |
33 namespace android_webview { | 36 namespace android_webview { |
34 | 37 |
35 class BrowserViewRendererClient; | 38 class BrowserViewRendererClient; |
36 class ChildFrame; | 39 class ChildFrame; |
37 class CompositorFrameConsumer; | 40 class CompositorFrameConsumer; |
38 | 41 |
39 // Interface for all the WebView-specific content rendering operations. | 42 // Interface for all the WebView-specific content rendering operations. |
40 // Provides software and hardware rendering and the Capture Picture API. | 43 // Provides software and hardware rendering and the Capture Picture API. |
41 class BrowserViewRenderer : public content::SynchronousCompositorClient, | 44 class BrowserViewRenderer : public content::SynchronousCompositorClient, |
| 45 public content::WebContentsObserver, |
42 public CompositorFrameProducer { | 46 public CompositorFrameProducer { |
43 public: | 47 public: |
44 static void CalculateTileMemoryPolicy(); | 48 static void CalculateTileMemoryPolicy(); |
45 static BrowserViewRenderer* FromWebContents( | 49 static BrowserViewRenderer* FromWebContents( |
46 content::WebContents* web_contents); | 50 content::WebContents* web_contents); |
47 | 51 |
48 BrowserViewRenderer( | 52 BrowserViewRenderer( |
| 53 content::WebContents* web_contents, |
49 BrowserViewRendererClient* client, | 54 BrowserViewRendererClient* client, |
50 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); | 55 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); |
51 | 56 |
52 ~BrowserViewRenderer() override; | 57 ~BrowserViewRenderer() override; |
53 | 58 |
54 void RegisterWithWebContents(content::WebContents* web_contents); | 59 void RegisterWithWebContents(content::WebContents* web_contents); |
55 | 60 |
56 // The BrowserViewRenderer client is responsible for ensuring that | 61 // The BrowserViewRenderer client is responsible for ensuring that |
57 // the current compositor frame consumer has been set correctly via | 62 // the current compositor frame consumer has been set correctly via |
58 // this method. The consumer is added to the set of registered | 63 // this method. The consumer is added to the set of registered |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // Android views hierarchy gluing. | 106 // Android views hierarchy gluing. |
102 bool IsVisible() const; | 107 bool IsVisible() const; |
103 gfx::Rect GetScreenRect() const; | 108 gfx::Rect GetScreenRect() const; |
104 bool attached_to_window() const { return attached_to_window_; } | 109 bool attached_to_window() const { return attached_to_window_; } |
105 gfx::Size size() const { return size_; } | 110 gfx::Size size() const { return size_; } |
106 | 111 |
107 bool IsClientVisible() const; | 112 bool IsClientVisible() const; |
108 void TrimMemory(); | 113 void TrimMemory(); |
109 | 114 |
110 // SynchronousCompositorClient overrides. | 115 // SynchronousCompositorClient overrides. |
111 void DidInitializeCompositor( | 116 void DidInitializeCompositor(content::SynchronousCompositor* compositor, |
112 content::SynchronousCompositor* compositor) override; | 117 int process_id, |
113 void DidDestroyCompositor( | 118 int routing_id) override; |
114 content::SynchronousCompositor* compositor) override; | 119 void DidDestroyCompositor(content::SynchronousCompositor* compositor, |
115 void DidBecomeCurrent(content::SynchronousCompositor* compositor) override; | 120 int process_id, |
| 121 int routing_id) override; |
116 void PostInvalidate() override; | 122 void PostInvalidate() override; |
117 void DidUpdateContent() override; | 123 void DidUpdateContent() override; |
118 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, | 124 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, |
119 const gfx::Vector2dF& max_scroll_offset_dip, | 125 const gfx::Vector2dF& max_scroll_offset_dip, |
120 const gfx::SizeF& scrollable_size_dip, | 126 const gfx::SizeF& scrollable_size_dip, |
121 float page_scale_factor, | 127 float page_scale_factor, |
122 float min_page_scale_factor, | 128 float min_page_scale_factor, |
123 float max_page_scale_factor) override; | 129 float max_page_scale_factor) override; |
124 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, | 130 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, |
125 const gfx::Vector2dF& latest_overscroll_delta, | 131 const gfx::Vector2dF& latest_overscroll_delta, |
126 const gfx::Vector2dF& current_fling_velocity) override; | 132 const gfx::Vector2dF& current_fling_velocity) override; |
127 | 133 |
| 134 // content::WebContentsObserver overrides |
| 135 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 136 content::RenderViewHost* new_host) override; |
| 137 |
128 // CompositorFrameProducer overrides | 138 // CompositorFrameProducer overrides |
129 void OnParentDrawConstraintsUpdated( | 139 void OnParentDrawConstraintsUpdated( |
130 CompositorFrameConsumer* compositor_frame_consumer) override; | 140 CompositorFrameConsumer* compositor_frame_consumer) override; |
131 void RemoveCompositorFrameConsumer( | 141 void RemoveCompositorFrameConsumer( |
132 CompositorFrameConsumer* compositor_frame_consumer) override; | 142 CompositorFrameConsumer* compositor_frame_consumer) override; |
133 | 143 |
134 private: | 144 private: |
135 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); | 145 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); |
136 bool CanOnDraw(); | 146 bool CanOnDraw(); |
137 bool CompositeSW(SkCanvas* canvas); | 147 bool CompositeSW(SkCanvas* canvas); |
(...skipping 14 matching lines...) Expand all Loading... |
152 // For debug tracing or logging. Return the string representation of this | 162 // For debug tracing or logging. Return the string representation of this |
153 // view renderer's state. | 163 // view renderer's state. |
154 std::string ToString() const; | 164 std::string ToString() const; |
155 | 165 |
156 BrowserViewRendererClient* const client_; | 166 BrowserViewRendererClient* const client_; |
157 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 167 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
158 CompositorFrameConsumer* current_compositor_frame_consumer_; | 168 CompositorFrameConsumer* current_compositor_frame_consumer_; |
159 std::set<CompositorFrameConsumer*> compositor_frame_consumers_; | 169 std::set<CompositorFrameConsumer*> compositor_frame_consumers_; |
160 | 170 |
161 // The current compositor that's owned by the current RVH. | 171 // The current compositor that's owned by the current RVH. |
| 172 // When compositor_ != nullptr, compositor_id_ is the id of compositor_. |
| 173 // When compositor_ == nullptr, compositor_id_ is the id of the future |
| 174 // compositor. |
162 content::SynchronousCompositor* compositor_; | 175 content::SynchronousCompositor* compositor_; |
| 176 CompositorID compositor_id_; |
163 // A map from compositor's per-WebView unique ID to the compositor's raw | 177 // A map from compositor's per-WebView unique ID to the compositor's raw |
164 // pointer. A raw pointer here is fine because the entry will be erased when | 178 // pointer. A raw pointer here is fine because the entry will be erased when |
165 // a compositor is destroyed. | 179 // a compositor is destroyed. |
166 std::map<size_t, content::SynchronousCompositor*> compositor_map_; | 180 std::map<CompositorID, content::SynchronousCompositor*> compositor_map_; |
167 | 181 |
168 bool is_paused_; | 182 bool is_paused_; |
169 bool view_visible_; | 183 bool view_visible_; |
170 bool window_visible_; // Only applicable if |attached_to_window_| is true. | 184 bool window_visible_; // Only applicable if |attached_to_window_| is true. |
171 bool attached_to_window_; | 185 bool attached_to_window_; |
172 bool hardware_enabled_; | 186 bool hardware_enabled_; |
173 float dip_scale_; | 187 float dip_scale_; |
174 float page_scale_factor_; | 188 float page_scale_factor_; |
175 float min_page_scale_factor_; | 189 float min_page_scale_factor_; |
176 float max_page_scale_factor_; | 190 float max_page_scale_factor_; |
(...skipping 16 matching lines...) Expand all Loading... |
193 // Max scroll offset in CSS pixels. | 207 // Max scroll offset in CSS pixels. |
194 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset. | 208 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset. |
195 gfx::Vector2dF max_scroll_offset_dip_; | 209 gfx::Vector2dF max_scroll_offset_dip_; |
196 | 210 |
197 // Used to prevent rounding errors from accumulating enough to generate | 211 // Used to prevent rounding errors from accumulating enough to generate |
198 // visible skew (especially noticeable when scrolling up and down in the same | 212 // visible skew (especially noticeable when scrolling up and down in the same |
199 // spot over a period of time). | 213 // spot over a period of time). |
200 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset. | 214 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset. |
201 gfx::Vector2dF overscroll_rounding_error_; | 215 gfx::Vector2dF overscroll_rounding_error_; |
202 | 216 |
203 uint32_t next_compositor_id_; | |
204 | |
205 ParentCompositorDrawConstraints external_draw_constraints_; | 217 ParentCompositorDrawConstraints external_draw_constraints_; |
206 | 218 |
207 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 219 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
208 }; | 220 }; |
209 | 221 |
210 } // namespace android_webview | 222 } // namespace android_webview |
211 | 223 |
212 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 224 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
OLD | NEW |