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 "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/cancelable_callback.h" | |
11 #include "content/public/browser/android/synchronous_compositor_client.h" | |
10 #include "skia/ext/refptr.h" | 12 #include "skia/ext/refptr.h" |
11 #include "ui/gfx/point.h" | 13 #include "ui/gfx/point.h" |
12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
13 #include "ui/gfx/vector2d_f.h" | 15 #include "ui/gfx/vector2d_f.h" |
14 | 16 |
15 class SkCanvas; | 17 class SkCanvas; |
16 class SkPicture; | 18 class SkPicture; |
17 struct AwDrawGLInfo; | 19 struct AwDrawGLInfo; |
18 struct AwDrawSWFunctionTable; | 20 struct AwDrawSWFunctionTable; |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 class ContentViewCore; | 23 class ContentViewCore; |
24 class SynchronousCompositor; | |
25 class WebContents; | |
22 } | 26 } |
23 | 27 |
28 class SkCanvas; | |
sgurun-gerrit only
2014/02/25 06:56:36
remove. already forward declared in line 17 above
| |
29 | |
24 namespace android_webview { | 30 namespace android_webview { |
25 | 31 |
32 class HardwareRenderer; | |
33 | |
34 class BrowserViewRendererClient { | |
35 public: | |
36 // Request DrawGL be called. Passing null canvas implies the request | |
benm (inactive)
2014/02/25 12:48:01
nit: |canvas|
| |
37 // will be of AwDrawGLInfo::kModeProcess type. The callback | |
38 // may never be made, and the mode may be promoted to kModeDraw. | |
39 virtual bool RequestDrawGL(jobject canvas) = 0; | |
40 | |
41 // Called when a new Picture is available. Needs to be enabled | |
42 // via the EnableOnNewPicture method. | |
43 virtual void OnNewPicture() = 0; | |
44 | |
45 // Called to trigger view invalidations. | |
benm (inactive)
2014/02/25 12:48:01
nit: "trigger a view invalidation"?
| |
46 virtual void PostInvalidate() = 0; | |
47 | |
48 // Synchronously call back to SetGlobalVisibleRect with current value. | |
49 virtual void UpdateGlobalVisibleRect() = 0; | |
50 | |
51 // Called to get view's absolute location on the screen. | |
52 virtual gfx::Point GetLocationOnScreen() = 0; | |
53 | |
54 // Try to set the view's scroll offset to |new_value|. | |
55 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) = 0; | |
56 | |
57 // Set the view's scroll offset cap to |new_value|. | |
58 virtual void SetMaxContainerViewScrollOffset(gfx::Vector2d new_value) = 0; | |
59 | |
60 // Is a WebView-managed fling in progress? | |
benm (inactive)
2014/02/25 12:48:01
s/WebView/Android View system/ ?
| |
61 virtual bool IsFlingActive() const = 0; | |
62 | |
63 // Set the current page scale to |page_scale_factor| and page scale limits | |
64 // to |min_page_scale_factor|..|max_page_scale_factor|. | |
65 virtual void SetPageScaleFactorAndLimits(float page_scale_factor, | |
66 float min_page_scale_factor, | |
67 float max_page_scale_factor) = 0; | |
68 | |
69 // Set the current contents_size to |contents_size_dip|. | |
70 virtual void SetContentsSize(gfx::SizeF contents_size_dip) = 0; | |
71 | |
72 // Handle overscroll. | |
73 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0; | |
74 | |
75 protected: | |
76 virtual ~BrowserViewRendererClient() {} | |
77 }; | |
78 | |
79 // Delegate to perform rendering actions involving Java objects. | |
80 class BrowserViewRendererJavaHelper { | |
81 public: | |
82 static BrowserViewRendererJavaHelper* GetInstance(); | |
83 | |
84 typedef base::Callback<bool(SkCanvas*)> RenderMethod; | |
85 virtual bool RenderViaAuxilaryBitmapIfNeeded( | |
benm (inactive)
2014/02/25 12:48:01
docs?
| |
86 jobject java_canvas, | |
87 const gfx::Vector2d& scroll_correction, | |
88 const gfx::Rect& clip, | |
89 RenderMethod render_source) = 0; | |
90 | |
91 protected: | |
92 virtual ~BrowserViewRendererJavaHelper() {} | |
93 }; | |
94 | |
26 // Interface for all the WebView-specific content rendering operations. | 95 // Interface for all the WebView-specific content rendering operations. |
27 // Provides software and hardware rendering and the Capture Picture API. | 96 // Provides software and hardware rendering and the Capture Picture API. |
28 class BrowserViewRenderer { | 97 class BrowserViewRenderer : public content::SynchronousCompositorClient { |
29 public: | 98 public: |
30 class Client { | 99 BrowserViewRenderer(BrowserViewRendererClient* client, |
31 public: | 100 content::WebContents* web_contents); |
32 // Request DrawGL be called. Passing null canvas implies the request | 101 |
33 // will be of AwDrawGLInfo::kModeProcess type. The callback | 102 virtual ~BrowserViewRenderer(); |
34 // may never be made, and the mode may be promoted to kModeDraw. | |
35 virtual bool RequestDrawGL(jobject canvas) = 0; | |
36 | |
37 // Called when a new Picture is available. Needs to be enabled | |
38 // via the EnableOnNewPicture method. | |
39 virtual void OnNewPicture() = 0; | |
40 | |
41 // Called to trigger view invalidations. | |
42 virtual void PostInvalidate() = 0; | |
43 | |
44 // Synchronously call back to SetGlobalVisibleRect with current value. | |
45 virtual void UpdateGlobalVisibleRect() = 0; | |
46 | |
47 // Called to get view's absolute location on the screen. | |
48 virtual gfx::Point GetLocationOnScreen() = 0; | |
49 | |
50 // Try to set the view's scroll offset to |new_value|. | |
51 virtual void ScrollContainerViewTo(gfx::Vector2d new_value) = 0; | |
52 | |
53 // Set the view's scroll offset cap to |new_value|. | |
54 virtual void SetMaxContainerViewScrollOffset(gfx::Vector2d new_value) = 0; | |
55 | |
56 // Is a WebView-managed fling in progress? | |
57 virtual bool IsFlingActive() const = 0; | |
58 | |
59 // Set the current page scale to |page_scale_factor| and page scale limits | |
60 // to |min_page_scale_factor|..|max_page_scale_factor|. | |
61 virtual void SetPageScaleFactorAndLimits(float page_scale_factor, | |
62 float min_page_scale_factor, | |
63 float max_page_scale_factor) = 0; | |
64 | |
65 // Set the current contents_size to |contents_size_dip|. | |
66 virtual void SetContentsSize(gfx::SizeF contents_size_dip) = 0; | |
67 | |
68 // Handle overscroll. | |
69 virtual void DidOverscroll(gfx::Vector2d overscroll_delta) = 0; | |
70 | |
71 protected: | |
72 virtual ~Client() {} | |
73 }; | |
74 | |
75 // Delegate to perform rendering actions involving Java objects. | |
76 class JavaHelper { | |
77 public: | |
78 static JavaHelper* GetInstance(); | |
79 | |
80 typedef base::Callback<bool(SkCanvas*)> RenderMethod; | |
81 virtual bool RenderViaAuxilaryBitmapIfNeeded( | |
82 jobject java_canvas, | |
83 const gfx::Vector2d& scroll_correction, | |
84 const gfx::Rect& clip, | |
85 RenderMethod render_source) = 0; | |
86 | |
87 protected: | |
88 virtual ~JavaHelper() {} | |
89 }; | |
90 | |
91 // Global hookup methods. | |
92 static void SetAwDrawSWFunctionTable(AwDrawSWFunctionTable* table); | |
93 | |
94 // Rendering methods. | |
95 | 103 |
96 // Main handler for view drawing: performs a SW draw immediately, or sets up | 104 // Main handler for view drawing: performs a SW draw immediately, or sets up |
97 // a subsequent GL Draw (via Client::RequestDrawGL) and returns true. A false | 105 // a subsequent GL Draw (via BrowserViewRendererClient::RequestDrawGL) and |
106 // returns true. A false | |
98 // return value indicates nothing was or will be drawn. | 107 // return value indicates nothing was or will be drawn. |
sgurun-gerrit only
2014/02/25 06:56:36
nit: combine with line above.
| |
99 // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates | 108 // |java_canvas| is the target of the draw. |is_hardware_canvas| indicates |
100 // a GL Draw maybe possible on this canvas. |scroll| if the view's current | 109 // a GL Draw maybe possible on this canvas. |scroll| if the view's current |
101 // scroll offset. |clip| is the canvas's clip bounds. |visible_rect| is the | 110 // scroll offset. |clip| is the canvas's clip bounds. |visible_rect| is the |
102 // intersection of the view size and the window in window coordinates. | 111 // intersection of the view size and the window in window coordinates. |
103 virtual bool OnDraw(jobject java_canvas, | 112 bool OnDraw(jobject java_canvas, |
104 bool is_hardware_canvas, | 113 bool is_hardware_canvas, |
105 const gfx::Vector2d& scroll, | 114 const gfx::Vector2d& scroll, |
106 const gfx::Rect& clip) = 0; | 115 const gfx::Rect& clip); |
107 | 116 |
108 // Called in response to a prior Client::RequestDrawGL() call. See | 117 // Called in response to a prior BrowserViewRendererClient::RequestDrawGL() |
118 // call. See | |
109 // AwDrawGLInfo documentation for more details of the contract. | 119 // AwDrawGLInfo documentation for more details of the contract. |
sgurun-gerrit only
2014/02/25 06:56:36
nit: continue from line above
| |
110 virtual void DrawGL(AwDrawGLInfo* draw_info) = 0; | 120 void DrawGL(AwDrawGLInfo* draw_info); |
111 | 121 |
112 // The global visible rect changed and this is the new value. | 122 // The global visible rect changed and this is the new value. |
113 virtual void SetGlobalVisibleRect(const gfx::Rect& visible_rect) = 0; | 123 void SetGlobalVisibleRect(const gfx::Rect& visible_rect); |
114 | 124 |
115 // CapturePicture API methods. | 125 // CapturePicture API methods. |
116 virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0; | 126 skia::RefPtr<SkPicture> CapturePicture(int width, int height); |
117 virtual void EnableOnNewPicture(bool enabled) = 0; | 127 void EnableOnNewPicture(bool enabled); |
118 | 128 |
119 virtual void ClearView() = 0; | 129 void ClearView(); |
120 | 130 |
121 // View update notifications. | 131 // View update notifications. |
122 virtual void SetIsPaused(bool paused) = 0; | 132 void SetIsPaused(bool paused); |
123 virtual void SetViewVisibility(bool visible) = 0; | 133 void SetViewVisibility(bool visible); |
124 virtual void SetWindowVisibility(bool visible) = 0; | 134 void SetWindowVisibility(bool visible); |
125 virtual void OnSizeChanged(int width, int height) = 0; | 135 void OnSizeChanged(int width, int height); |
126 virtual void OnAttachedToWindow(int width, int height) = 0; | 136 void OnAttachedToWindow(int width, int height); |
127 virtual void OnDetachedFromWindow() = 0; | 137 void OnDetachedFromWindow(); |
128 | 138 |
129 // Sets the scale for logical<->physical pixel conversions. | 139 // Sets the scale for logical<->physical pixel conversions. |
130 virtual void SetDipScale(float dip_scale) = 0; | 140 void SetDipScale(float dip_scale); |
131 | 141 |
132 // Set the root layer scroll offset to |new_value|. | 142 // Set the root layer scroll offset to |new_value|. |
133 virtual void ScrollTo(gfx::Vector2d new_value) = 0; | 143 void ScrollTo(gfx::Vector2d new_value); |
134 | 144 |
135 // Android views hierarchy gluing. | 145 // Android views hierarchy gluing. |
136 virtual bool IsAttachedToWindow() = 0; | 146 bool IsAttachedToWindow() const; |
137 virtual bool IsVisible() = 0; | 147 bool IsVisible() const; |
138 virtual gfx::Rect GetScreenRect() = 0; | 148 gfx::Rect GetScreenRect() const; |
139 | 149 |
140 // ComponentCallbacks2.onTrimMemory callback. | 150 // ComponentCallbacks2.onTrimMemory callback. |
141 virtual void TrimMemory(int level) = 0; | 151 void TrimMemory(int level); |
142 | 152 |
143 virtual ~BrowserViewRenderer() {} | 153 // SynchronousCompositorClient overrides |
154 virtual void DidInitializeCompositor( | |
155 content::SynchronousCompositor* compositor) OVERRIDE; | |
156 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) | |
157 OVERRIDE; | |
158 virtual void SetContinuousInvalidate(bool invalidate) OVERRIDE; | |
159 virtual void SetMaxRootLayerScrollOffset(gfx::Vector2dF new_value) OVERRIDE; | |
160 virtual void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_css) | |
161 OVERRIDE; | |
162 virtual void DidUpdateContent() OVERRIDE; | |
163 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE; | |
164 virtual bool IsExternalFlingActive() const OVERRIDE; | |
165 virtual void SetRootLayerPageScaleFactorAndLimits(float page_scale_factor, | |
166 float min_page_scale_factor, | |
167 float max_page_scale_factor) | |
168 OVERRIDE; | |
169 virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE; | |
170 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, | |
171 gfx::Vector2dF latest_overscroll_delta, | |
172 gfx::Vector2dF current_fling_velocity) OVERRIDE; | |
173 | |
174 private: | |
175 // Checks the continuous invalidate and block invalidate state, and schedule | |
176 // invalidates appropriately. If |invalidate_ignore_compositor| is true, | |
177 // then send a view invalidate regardless of compositor expectation. | |
178 void EnsureContinuousInvalidation(AwDrawGLInfo* draw_info, | |
179 bool invalidate_ignore_compositor); | |
180 bool DrawSWInternal(jobject java_canvas, const gfx::Rect& clip_bounds); | |
181 bool CompositeSW(SkCanvas* canvas); | |
182 | |
183 // If we call up view invalidate and OnDraw is not called before a deadline, | |
184 // then we keep ticking the SynchronousCompositor so it can make progress. | |
185 void FallbackTickFired(); | |
186 void ForceFakeCompositeSW(); | |
187 | |
188 gfx::Vector2d max_scroll_offset() const; | |
189 | |
190 // For debug tracing or logging. Return the string representation of this | |
191 // view renderer's state and the |draw_info| if provided. | |
192 std::string ToString(AwDrawGLInfo* draw_info) const; | |
193 | |
194 BrowserViewRendererClient* client_; | |
195 content::WebContents* web_contents_; | |
196 content::SynchronousCompositor* compositor_; | |
197 | |
198 scoped_ptr<HardwareRenderer> hardware_renderer_; | |
199 | |
200 bool is_paused_; | |
201 bool view_visible_; | |
202 bool window_visible_; // Only applicable if |attached_to_window_| is true. | |
203 bool attached_to_window_; | |
204 float dip_scale_; | |
205 float page_scale_factor_; | |
206 bool on_new_picture_enable_; | |
207 bool clear_view_; | |
208 | |
209 // When true, we should continuously invalidate and keep drawing, for example | |
210 // to drive animation. This value is set by the compositor and should always | |
211 // reflect the expectation of the compositor and not be reused for other | |
212 // states. | |
213 bool compositor_needs_continuous_invalidate_; | |
214 | |
215 // Used to block additional invalidates while one is already pending or before | |
216 // compositor draw which may switch continuous_invalidate on and off in the | |
217 // process. | |
218 bool block_invalidates_; | |
219 | |
220 // Holds a callback to FallbackTickFired while it is pending. | |
221 base::CancelableClosure fallback_tick_; | |
222 | |
223 int width_; | |
224 int height_; | |
225 | |
226 // Should always call UpdateGlobalVisibleRect before using this. | |
227 gfx::Rect cached_global_visible_rect_; | |
228 | |
229 // Last View scroll when View.onDraw() was called. | |
230 gfx::Vector2d scroll_at_start_of_frame_; | |
231 | |
232 // Current scroll offset in CSS pixels. | |
233 gfx::Vector2dF scroll_offset_dip_; | |
234 | |
235 // Max scroll offset in CSS pixels. | |
236 gfx::Vector2dF max_scroll_offset_dip_; | |
237 | |
238 // Used to prevent rounding errors from accumulating enough to generate | |
239 // visible skew (especially noticeable when scrolling up and down in the same | |
240 // spot over a period of time). | |
241 gfx::Vector2dF overscroll_rounding_error_; | |
242 | |
243 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | |
144 }; | 244 }; |
145 | 245 |
146 } // namespace android_webview | 246 } // namespace android_webview |
147 | 247 |
148 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 248 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
OLD | NEW |