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 "android_webview/browser/parent_compositor_draw_constraints.h" | 8 #include "android_webview/browser/parent_compositor_draw_constraints.h" |
9 #include "android_webview/browser/shared_renderer_state.h" | 9 #include "android_webview/browser/shared_renderer_state.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // |global_visible_rect| is the intersection of the view size and the window | 42 // |global_visible_rect| is the intersection of the view size and the window |
43 // in window coordinates. | 43 // in window coordinates. |
44 void PrepareToDraw(const gfx::Vector2d& scroll, | 44 void PrepareToDraw(const gfx::Vector2d& scroll, |
45 const gfx::Rect& global_visible_rect); | 45 const gfx::Rect& global_visible_rect); |
46 | 46 |
47 // Main handlers for view drawing. A false return value indicates no new | 47 // Main handlers for view drawing. A false return value indicates no new |
48 // frame is produced. | 48 // frame is produced. |
49 bool OnDrawHardware(); | 49 bool OnDrawHardware(); |
50 bool OnDrawSoftware(SkCanvas* canvas); | 50 bool OnDrawSoftware(SkCanvas* canvas); |
51 | 51 |
| 52 void OnVSync(base::TimeTicks frame_time, base::TimeDelta vsync_period); |
| 53 |
52 // CapturePicture API methods. | 54 // CapturePicture API methods. |
53 skia::RefPtr<SkPicture> CapturePicture(int width, int height); | 55 skia::RefPtr<SkPicture> CapturePicture(int width, int height); |
54 void EnableOnNewPicture(bool enabled); | 56 void EnableOnNewPicture(bool enabled); |
55 | 57 |
56 void ClearView(); | 58 void ClearView(); |
57 | 59 |
58 // View update notifications. | 60 // View update notifications. |
59 void SetIsPaused(bool paused); | 61 void SetIsPaused(bool paused); |
60 void SetViewVisibility(bool visible); | 62 void SetViewVisibility(bool visible); |
61 void SetWindowVisibility(bool visible); | 63 void SetWindowVisibility(bool visible); |
(...skipping 15 matching lines...) Expand all Loading... |
77 gfx::Size size() const { return size_; } | 79 gfx::Size size() const { return size_; } |
78 void ReleaseHardware(); | 80 void ReleaseHardware(); |
79 | 81 |
80 void TrimMemory(const int level, const bool visible); | 82 void TrimMemory(const int level, const bool visible); |
81 | 83 |
82 // SynchronousCompositorClient overrides. | 84 // SynchronousCompositorClient overrides. |
83 virtual void DidInitializeCompositor( | 85 virtual void DidInitializeCompositor( |
84 content::SynchronousCompositor* compositor) override; | 86 content::SynchronousCompositor* compositor) override; |
85 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) | 87 virtual void DidDestroyCompositor(content::SynchronousCompositor* compositor) |
86 override; | 88 override; |
87 virtual void SetContinuousInvalidate(bool invalidate) override; | 89 virtual void SetNeedsVSyncs(bool needs_vsyncs) override; |
| 90 virtual void PostInvalidate() override; |
88 virtual void DidUpdateContent() override; | 91 virtual void DidUpdateContent() override; |
89 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() override; | 92 virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() override; |
90 virtual void UpdateRootLayerState( | 93 virtual void UpdateRootLayerState( |
91 const gfx::Vector2dF& total_scroll_offset_dip, | 94 const gfx::Vector2dF& total_scroll_offset_dip, |
92 const gfx::Vector2dF& max_scroll_offset_dip, | 95 const gfx::Vector2dF& max_scroll_offset_dip, |
93 const gfx::SizeF& scrollable_size_dip, | 96 const gfx::SizeF& scrollable_size_dip, |
94 float page_scale_factor, | 97 float page_scale_factor, |
95 float min_page_scale_factor, | 98 float min_page_scale_factor, |
96 float max_page_scale_factor) override; | 99 float max_page_scale_factor) override; |
97 virtual bool IsExternalFlingActive() const override; | 100 virtual bool IsExternalFlingActive() const override; |
98 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 101 virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
99 gfx::Vector2dF latest_overscroll_delta, | 102 gfx::Vector2dF latest_overscroll_delta, |
100 gfx::Vector2dF current_fling_velocity) override; | 103 gfx::Vector2dF current_fling_velocity) override; |
101 | 104 |
102 void UpdateParentDrawConstraints(); | 105 void UpdateParentDrawConstraints(); |
103 void DidSkipCommitFrame(); | |
104 void InvalidateOnFunctorDestroy(); | 106 void InvalidateOnFunctorDestroy(); |
105 | 107 |
106 private: | 108 private: |
| 109 bool CompositeSW(SkCanvas* canvas); |
| 110 scoped_ptr<cc::CompositorFrame> CompositeHw(); |
| 111 |
107 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip); | 112 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip); |
108 // Checks the continuous invalidate and block invalidate state, and schedule | |
109 // invalidates appropriately. If |force_invalidate| is true, then send a view | |
110 // invalidate regardless of compositor expectation. If |skip_reschedule_tick| | |
111 // is true and if there is already a pending fallback tick, don't reschedule | |
112 // them. | |
113 void EnsureContinuousInvalidation(bool force_invalidate, | |
114 bool skip_reschedule_tick); | |
115 bool CompositeSW(SkCanvas* canvas); | |
116 void DidComposite(); | |
117 void DidSkipCompositeInDraw(); | |
118 scoped_refptr<base::debug::ConvertableToTraceFormat> RootLayerStateAsValue( | 113 scoped_refptr<base::debug::ConvertableToTraceFormat> RootLayerStateAsValue( |
119 const gfx::Vector2dF& total_scroll_offset_dip, | 114 const gfx::Vector2dF& total_scroll_offset_dip, |
120 const gfx::SizeF& scrollable_size_dip); | 115 const gfx::SizeF& scrollable_size_dip); |
121 | 116 |
122 scoped_ptr<cc::CompositorFrame> CompositeHw(); | |
123 void ReturnUnusedResource(scoped_ptr<cc::CompositorFrame> frame); | 117 void ReturnUnusedResource(scoped_ptr<cc::CompositorFrame> frame); |
124 void ReturnResourceFromParent(); | 118 void ReturnResourceFromParent(); |
125 | 119 |
126 // If we call up view invalidate and OnDraw is not called before a deadline, | |
127 // then we keep ticking the SynchronousCompositor so it can make progress. | |
128 // Do this in a two stage tick due to native MessageLoop favors delayed task, | |
129 // so ensure delayed task is inserted only after the draw task returns. | |
130 void PostFallbackTick(); | |
131 void FallbackTickFired(); | |
132 | |
133 // Force invoke the compositor to run produce a 1x1 software frame that is | |
134 // immediately discarded. This is a hack to force invoke parts of the | |
135 // compositor that are not directly exposed here. | |
136 void ForceFakeCompositeSW(); | |
137 | |
138 gfx::Vector2d max_scroll_offset() const; | 120 gfx::Vector2d max_scroll_offset() const; |
139 | 121 |
140 size_t CalculateDesiredMemoryPolicy(); | 122 size_t CalculateDesiredMemoryPolicy(); |
| 123 |
| 124 void UpdateNeedsVSyncs(); |
| 125 |
141 // For debug tracing or logging. Return the string representation of this | 126 // For debug tracing or logging. Return the string representation of this |
142 // view renderer's state. | 127 // view renderer's state. |
143 std::string ToString() const; | 128 std::string ToString() const; |
144 | 129 |
145 BrowserViewRendererClient* client_; | 130 BrowserViewRendererClient* client_; |
146 SharedRendererState shared_renderer_state_; | 131 SharedRendererState shared_renderer_state_; |
147 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 132 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
148 | 133 |
149 content::SynchronousCompositor* compositor_; | 134 content::SynchronousCompositor* compositor_; |
150 | 135 |
151 bool is_paused_; | 136 bool is_paused_; |
152 bool view_visible_; | 137 bool view_visible_; |
153 bool window_visible_; // Only applicable if |attached_to_window_| is true. | 138 bool window_visible_; // Only applicable if |attached_to_window_| is true. |
154 bool attached_to_window_; | 139 bool attached_to_window_; |
155 bool hardware_enabled_; | 140 bool hardware_enabled_; |
156 float dip_scale_; | 141 float dip_scale_; |
157 float page_scale_factor_; | 142 float page_scale_factor_; |
158 bool on_new_picture_enable_; | 143 bool on_new_picture_enable_; |
159 bool clear_view_; | 144 bool clear_view_; |
160 | 145 |
161 gfx::Vector2d last_on_draw_scroll_offset_; | 146 gfx::Vector2d last_on_draw_scroll_offset_; |
162 gfx::Rect last_on_draw_global_visible_rect_; | 147 gfx::Rect last_on_draw_global_visible_rect_; |
163 | 148 |
164 // The draw constraints from the parent compositor. These are only used for | 149 // The draw constraints from the parent compositor. These are only used for |
165 // tiling priority. | 150 // tiling priority. |
166 ParentCompositorDrawConstraints parent_draw_constraints_; | 151 ParentCompositorDrawConstraints parent_draw_constraints_; |
167 | 152 |
168 // When true, we should continuously invalidate and keep drawing, for example | 153 // When true, we should ask for vsyncs and pass them on, for example |
169 // to drive animation. This value is set by the compositor and should always | 154 // to drive animation. This value is set by the compositor and should always |
170 // reflect the expectation of the compositor and not be reused for other | 155 // reflect the expectation of the compositor and not be reused for other |
171 // states. | 156 // states. |
172 bool compositor_needs_continuous_invalidate_; | 157 bool compositor_needs_vsyncs_; |
173 | 158 |
174 bool invalidate_after_composite_; | 159 // This is actually used to decide if we're asking for vsyncs. Sometimes we |
175 | 160 // want to stop vsync callbacks even if the compositor is asking for them. |
176 // Used to block additional invalidates while one is already pending. | 161 // e.g. when paused (backgrounded) or window not visible. |
177 bool block_invalidates_; | 162 bool needs_vsyncs_; |
178 | |
179 base::CancelableClosure post_fallback_tick_; | |
180 base::CancelableClosure fallback_tick_fired_; | |
181 bool fallback_tick_pending_; | |
182 | 163 |
183 gfx::Size size_; | 164 gfx::Size size_; |
184 | 165 |
185 // Current scroll offset in CSS pixels. | 166 // Current scroll offset in CSS pixels. |
186 gfx::Vector2dF scroll_offset_dip_; | 167 gfx::Vector2dF scroll_offset_dip_; |
187 | 168 |
188 // Max scroll offset in CSS pixels. | 169 // Max scroll offset in CSS pixels. |
189 gfx::Vector2dF max_scroll_offset_dip_; | 170 gfx::Vector2dF max_scroll_offset_dip_; |
190 | 171 |
191 // Used to prevent rounding errors from accumulating enough to generate | 172 // Used to prevent rounding errors from accumulating enough to generate |
192 // visible skew (especially noticeable when scrolling up and down in the same | 173 // visible skew (especially noticeable when scrolling up and down in the same |
193 // spot over a period of time). | 174 // spot over a period of time). |
194 gfx::Vector2dF overscroll_rounding_error_; | 175 gfx::Vector2dF overscroll_rounding_error_; |
195 | 176 |
196 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 177 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
197 }; | 178 }; |
198 | 179 |
199 } // namespace android_webview | 180 } // namespace android_webview |
200 | 181 |
201 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 182 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
OLD | NEW |