| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 gfx::Size size() const { return size_; } | 77 gfx::Size size() const { return size_; } |
| 78 void ReleaseHardware(); | 78 void ReleaseHardware(); |
| 79 | 79 |
| 80 void TrimMemory(const int level, const bool visible); | 80 void TrimMemory(const int level, const bool visible); |
| 81 | 81 |
| 82 // SynchronousCompositorClient overrides. | 82 // SynchronousCompositorClient overrides. |
| 83 void DidInitializeCompositor( | 83 void DidInitializeCompositor( |
| 84 content::SynchronousCompositor* compositor) override; | 84 content::SynchronousCompositor* compositor) override; |
| 85 void DidDestroyCompositor( | 85 void DidDestroyCompositor( |
| 86 content::SynchronousCompositor* compositor) override; | 86 content::SynchronousCompositor* compositor) override; |
| 87 void SetContinuousInvalidate(bool invalidate) override; | 87 void PostInvalidate() override; |
| 88 void DidUpdateContent() override; | 88 void DidUpdateContent() override; |
| 89 gfx::Vector2dF GetTotalRootLayerScrollOffset() override; | 89 gfx::Vector2dF GetTotalRootLayerScrollOffset() override; |
| 90 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, | 90 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, |
| 91 const gfx::Vector2dF& max_scroll_offset_dip, | 91 const gfx::Vector2dF& max_scroll_offset_dip, |
| 92 const gfx::SizeF& scrollable_size_dip, | 92 const gfx::SizeF& scrollable_size_dip, |
| 93 float page_scale_factor, | 93 float page_scale_factor, |
| 94 float min_page_scale_factor, | 94 float min_page_scale_factor, |
| 95 float max_page_scale_factor) override; | 95 float max_page_scale_factor) override; |
| 96 bool IsExternalFlingActive() const override; | 96 bool IsExternalFlingActive() const override; |
| 97 void DidOverscroll(gfx::Vector2dF accumulated_overscroll, | 97 void DidOverscroll(gfx::Vector2dF accumulated_overscroll, |
| 98 gfx::Vector2dF latest_overscroll_delta, | 98 gfx::Vector2dF latest_overscroll_delta, |
| 99 gfx::Vector2dF current_fling_velocity) override; | 99 gfx::Vector2dF current_fling_velocity) override; |
| 100 | 100 |
| 101 void UpdateParentDrawConstraints(); | 101 void UpdateParentDrawConstraints(); |
| 102 void DidSkipCommitFrame(); | 102 void DidSkipCommitFrame(); |
| 103 void InvalidateOnFunctorDestroy(); | 103 void InvalidateOnFunctorDestroy(); |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip); | 106 void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip); |
| 107 bool CanOnDraw(); | 107 bool CanOnDraw(); |
| 108 // Checks the continuous invalidate and block invalidate state, and schedule | 108 // Posts an invalidate with fallback tick. All invalidates posted while an |
| 109 // invalidates appropriately. If |force_invalidate| is true, then send a view | 109 // invalidate is pending will be posted as a single invalidate after the |
| 110 // invalidate regardless of compositor expectation. If |skip_reschedule_tick| | 110 // pending invalidate is done. If |skip_reschedule_tick| is true a fallback |
| 111 // is true and if there is already a pending fallback tick, don't reschedule | 111 // tick won't be scheduled if there's one already pending. |
| 112 // them. | 112 void PostInvalidateWithFallback(bool skip_reschedule_tick); |
| 113 void EnsureContinuousInvalidation(bool force_invalidate, | 113 void UpdateCompositorIsActive(); |
| 114 bool skip_reschedule_tick); | |
| 115 bool CompositeSW(SkCanvas* canvas); | 114 bool CompositeSW(SkCanvas* canvas); |
| 116 void DidComposite(); | 115 void DidComposite(); |
| 117 void DidSkipCompositeInDraw(); | 116 void DidSkipCompositeInDraw(); |
| 118 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 117 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 119 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, | 118 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, |
| 120 const gfx::SizeF& scrollable_size_dip); | 119 const gfx::SizeF& scrollable_size_dip); |
| 121 | 120 |
| 122 scoped_ptr<cc::CompositorFrame> CompositeHw(); | 121 scoped_ptr<cc::CompositorFrame> CompositeHw(); |
| 122 void ForceCompositeHw(); |
| 123 void ReturnUnusedResource(scoped_ptr<cc::CompositorFrame> frame); | 123 void ReturnUnusedResource(scoped_ptr<cc::CompositorFrame> frame); |
| 124 void ReturnResourceFromParent(); | 124 void ReturnResourceFromParent(); |
| 125 | 125 |
| 126 // If we call up view invalidate and OnDraw is not called before a deadline, | 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. | 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, | 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. | 129 // so ensure delayed task is inserted only after the draw task returns. |
| 130 void PostFallbackTick(); | 130 void PostFallbackTick(); |
| 131 void FallbackTickFired(); | 131 void FallbackTickFired(); |
| 132 | 132 |
| 133 // Force invoke the compositor to run produce a 1x1 software frame that is | 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 | 134 // immediately discarded. This is a hack to force invoke parts of the |
| 135 // compositor that are not directly exposed here. | 135 // compositor that are not directly exposed here. |
| 136 void ForceFakeCompositeSW(); | 136 void ForceFakeCompositeSW(); |
| 137 | 137 |
| 138 gfx::Vector2d max_scroll_offset() const; | 138 gfx::Vector2d max_scroll_offset() const; |
| 139 | 139 |
| 140 size_t CalculateDesiredMemoryPolicy(); | 140 size_t CalculateDesiredMemoryPolicy(); |
| 141 |
| 141 // For debug tracing or logging. Return the string representation of this | 142 // For debug tracing or logging. Return the string representation of this |
| 142 // view renderer's state. | 143 // view renderer's state. |
| 143 std::string ToString() const; | 144 std::string ToString() const; |
| 144 | 145 |
| 145 BrowserViewRendererClient* client_; | 146 BrowserViewRendererClient* client_; |
| 146 SharedRendererState shared_renderer_state_; | 147 SharedRendererState shared_renderer_state_; |
| 147 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 148 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 148 | 149 |
| 149 content::SynchronousCompositor* compositor_; | 150 content::SynchronousCompositor* compositor_; |
| 150 | 151 |
| 151 bool is_paused_; | 152 bool is_paused_; |
| 152 bool view_visible_; | 153 bool view_visible_; |
| 153 bool window_visible_; // Only applicable if |attached_to_window_| is true. | 154 bool window_visible_; // Only applicable if |attached_to_window_| is true. |
| 154 bool attached_to_window_; | 155 bool attached_to_window_; |
| 155 bool hardware_enabled_; | 156 bool hardware_enabled_; |
| 156 float dip_scale_; | 157 float dip_scale_; |
| 157 float page_scale_factor_; | 158 float page_scale_factor_; |
| 158 bool on_new_picture_enable_; | 159 bool on_new_picture_enable_; |
| 159 bool clear_view_; | 160 bool clear_view_; |
| 160 | 161 |
| 161 gfx::Vector2d last_on_draw_scroll_offset_; | 162 gfx::Vector2d last_on_draw_scroll_offset_; |
| 162 gfx::Rect last_on_draw_global_visible_rect_; | 163 gfx::Rect last_on_draw_global_visible_rect_; |
| 163 | 164 |
| 164 // The draw constraints from the parent compositor. These are only used for | 165 // The draw constraints from the parent compositor. These are only used for |
| 165 // tiling priority. | 166 // tiling priority. |
| 166 ParentCompositorDrawConstraints parent_draw_constraints_; | 167 ParentCompositorDrawConstraints parent_draw_constraints_; |
| 167 | 168 |
| 168 // When true, we should continuously invalidate and keep drawing, for example | 169 // Used to run invalidate after the pending invalidate is done. |
| 169 // 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 | |
| 171 // states. | |
| 172 bool compositor_needs_continuous_invalidate_; | |
| 173 | |
| 174 bool invalidate_after_composite_; | 170 bool invalidate_after_composite_; |
| 175 | 171 |
| 176 // Used to block additional invalidates while one is already pending. | 172 // Used to block additional invalidates while one is pending. |
| 177 bool block_invalidates_; | 173 bool block_invalidates_; |
| 178 | 174 |
| 179 base::CancelableClosure post_fallback_tick_; | 175 base::CancelableClosure post_fallback_tick_; |
| 180 base::CancelableClosure fallback_tick_fired_; | 176 base::CancelableClosure fallback_tick_fired_; |
| 181 bool fallback_tick_pending_; | 177 bool fallback_tick_pending_; |
| 182 | 178 |
| 183 gfx::Size size_; | 179 gfx::Size size_; |
| 184 | 180 |
| 185 // Current scroll offset in CSS pixels. | 181 // Current scroll offset in CSS pixels. |
| 186 gfx::Vector2dF scroll_offset_dip_; | 182 gfx::Vector2dF scroll_offset_dip_; |
| 187 | 183 |
| 188 // Max scroll offset in CSS pixels. | 184 // Max scroll offset in CSS pixels. |
| 189 gfx::Vector2dF max_scroll_offset_dip_; | 185 gfx::Vector2dF max_scroll_offset_dip_; |
| 190 | 186 |
| 191 // Used to prevent rounding errors from accumulating enough to generate | 187 // Used to prevent rounding errors from accumulating enough to generate |
| 192 // visible skew (especially noticeable when scrolling up and down in the same | 188 // visible skew (especially noticeable when scrolling up and down in the same |
| 193 // spot over a period of time). | 189 // spot over a period of time). |
| 194 gfx::Vector2dF overscroll_rounding_error_; | 190 gfx::Vector2dF overscroll_rounding_error_; |
| 195 | 191 |
| 196 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 192 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
| 197 }; | 193 }; |
| 198 | 194 |
| 199 } // namespace android_webview | 195 } // namespace android_webview |
| 200 | 196 |
| 201 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 197 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
| OLD | NEW |