Chromium Code Reviews| 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 | 11 |
| 12 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 12 #include "android_webview/browser/parent_compositor_draw_constraints.h" |
| 13 #include "android_webview/browser/shared_renderer_state.h" | |
| 14 #include "base/callback.h" | 13 #include "base/callback.h" |
| 15 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
| 16 #include "base/macros.h" | 15 #include "base/macros.h" |
| 17 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "cc/resources/returned_resource.h" | |
| 18 #include "content/public/browser/android/synchronous_compositor.h" | 18 #include "content/public/browser/android/synchronous_compositor.h" |
| 19 #include "content/public/browser/android/synchronous_compositor_client.h" | 19 #include "content/public/browser/android/synchronous_compositor_client.h" |
| 20 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/gfx/geometry/size_f.h" | 22 #include "ui/gfx/geometry/size_f.h" |
| 23 #include "ui/gfx/geometry/vector2d_f.h" | 23 #include "ui/gfx/geometry/vector2d_f.h" |
| 24 | 24 |
| 25 class SkCanvas; | 25 class SkCanvas; |
| 26 class SkPicture; | 26 class SkPicture; |
| 27 | 27 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 44 | 44 |
| 45 BrowserViewRenderer( | 45 BrowserViewRenderer( |
| 46 BrowserViewRendererClient* client, | 46 BrowserViewRendererClient* client, |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
| 48 bool disable_page_visibility); | 48 bool disable_page_visibility); |
| 49 | 49 |
| 50 ~BrowserViewRenderer() override; | 50 ~BrowserViewRenderer() override; |
| 51 | 51 |
| 52 void RegisterWithWebContents(content::WebContents* web_contents); | 52 void RegisterWithWebContents(content::WebContents* web_contents); |
| 53 | 53 |
| 54 SharedRendererState* GetAwDrawGLViewContext(); | |
| 55 bool RequestDrawGL(bool wait_for_completion); | 54 bool RequestDrawGL(bool wait_for_completion); |
| 56 | 55 |
| 57 // Called before either OnDrawHardware or OnDrawSoftware to set the view | 56 // Called before either OnDrawHardware or OnDrawSoftware to set the view |
| 58 // state of this frame. |scroll| is the view's current scroll offset. | 57 // state of this frame. |
| 59 // |global_visible_rect| is the intersection of the view size and the window | 58 // |global_visible_rect| is the intersection of the view size and the window |
| 60 // in window coordinates. | 59 // in window coordinates. |
| 61 void PrepareToDraw(const gfx::Vector2d& scroll, | 60 void PrepareToDraw(const gfx::Rect& global_visible_rect); |
| 62 const gfx::Rect& global_visible_rect); | |
| 63 | 61 |
| 64 // Main handlers for view drawing. A false return value indicates no new | 62 // Main handlers for view drawing. A false/null return value indicates no new |
| 65 // frame is produced. | 63 // frame is produced. |
| 66 bool OnDrawHardware(); | 64 scoped_ptr<ChildFrame> OnDrawHardware(); |
| 67 bool OnDrawSoftware(SkCanvas* canvas); | 65 bool OnDrawSoftware(SkCanvas* canvas); |
| 68 | 66 |
| 69 // CapturePicture API methods. | 67 // CapturePicture API methods. |
| 70 skia::RefPtr<SkPicture> CapturePicture(int width, int height); | 68 skia::RefPtr<SkPicture> CapturePicture(int width, int height); |
| 71 void EnableOnNewPicture(bool enabled); | 69 void EnableOnNewPicture(bool enabled); |
| 72 | 70 |
| 73 void ClearView(); | 71 void ClearView(); |
| 74 | 72 |
| 75 void SetOffscreenPreRaster(bool enabled); | 73 void SetOffscreenPreRaster(bool enabled); |
| 74 bool offscreen_pre_raster() { return offscreen_pre_raster_; } | |
|
boliu
2016/03/24 17:34:45
remove
| |
| 75 | |
| 76 void SetExternalDrawConstraints(const ParentCompositorDrawConstraints&); | |
|
boliu
2016/03/24 17:34:45
remove
| |
| 76 | 77 |
| 77 // View update notifications. | 78 // View update notifications. |
| 78 void SetIsPaused(bool paused); | 79 void SetIsPaused(bool paused); |
| 79 void SetViewVisibility(bool visible); | 80 void SetViewVisibility(bool visible); |
| 80 void SetWindowVisibility(bool visible); | 81 void SetWindowVisibility(bool visible); |
| 81 void OnSizeChanged(int width, int height); | 82 void OnSizeChanged(int width, int height); |
| 82 void OnAttachedToWindow(int width, int height); | 83 void OnAttachedToWindow(int width, int height); |
| 83 void OnDetachedFromWindow(); | 84 void OnDetachedFromWindow(); |
| 84 void OnComputeScroll(base::TimeTicks animation_time); | 85 void OnComputeScroll(base::TimeTicks animation_time); |
| 85 | 86 |
| 86 // Sets the scale for logical<->physical pixel conversions. | 87 // Sets the scale for logical<->physical pixel conversions. |
| 87 void SetDipScale(float dip_scale); | 88 void SetDipScale(float dip_scale); |
| 88 float dip_scale() const { return dip_scale_; } | 89 float dip_scale() const { return dip_scale_; } |
| 89 float page_scale_factor() const { return page_scale_factor_; } | 90 float page_scale_factor() const { return page_scale_factor_; } |
| 90 | 91 |
| 91 // Set the root layer scroll offset to |new_value|. | 92 // Set the root layer scroll offset to |new_value|. |
| 92 void ScrollTo(const gfx::Vector2d& new_value); | 93 void ScrollTo(const gfx::Vector2d& new_value); |
| 93 | 94 |
| 94 // Android views hierarchy gluing. | 95 // Android views hierarchy gluing. |
| 95 bool IsVisible() const; | 96 bool IsVisible() const; |
| 96 gfx::Rect GetScreenRect() const; | 97 gfx::Rect GetScreenRect() const; |
| 97 bool attached_to_window() const { return attached_to_window_; } | 98 bool attached_to_window() const { return attached_to_window_; } |
| 98 bool hardware_enabled() const { return hardware_enabled_; } | 99 bool hardware_enabled() const { return hardware_enabled_; } |
| 99 gfx::Size size() const { return size_; } | 100 gfx::Size size() const { return size_; } |
| 100 void ReleaseHardware(); | |
| 101 | 101 |
| 102 bool IsClientVisible() const; | 102 bool IsClientVisible() const; |
| 103 void TrimMemory(const int level, const bool visible); | 103 void TrimMemory(const int level); |
| 104 | 104 |
| 105 // SynchronousCompositorClient overrides. | 105 // SynchronousCompositorClient overrides. |
| 106 void DidInitializeCompositor( | 106 void DidInitializeCompositor( |
| 107 content::SynchronousCompositor* compositor) override; | 107 content::SynchronousCompositor* compositor) override; |
| 108 void DidDestroyCompositor( | 108 void DidDestroyCompositor( |
| 109 content::SynchronousCompositor* compositor) override; | 109 content::SynchronousCompositor* compositor) override; |
| 110 void DidBecomeCurrent(content::SynchronousCompositor* compositor) override; | 110 void DidBecomeCurrent(content::SynchronousCompositor* compositor) override; |
| 111 void PostInvalidate() override; | 111 void PostInvalidate() override; |
| 112 void DidUpdateContent() override; | 112 void DidUpdateContent() override; |
| 113 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, | 113 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, |
| 114 const gfx::Vector2dF& max_scroll_offset_dip, | 114 const gfx::Vector2dF& max_scroll_offset_dip, |
| 115 const gfx::SizeF& scrollable_size_dip, | 115 const gfx::SizeF& scrollable_size_dip, |
| 116 float page_scale_factor, | 116 float page_scale_factor, |
| 117 float min_page_scale_factor, | 117 float min_page_scale_factor, |
| 118 float max_page_scale_factor) override; | 118 float max_page_scale_factor) override; |
| 119 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, | 119 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, |
| 120 const gfx::Vector2dF& latest_overscroll_delta, | 120 const gfx::Vector2dF& latest_overscroll_delta, |
| 121 const gfx::Vector2dF& current_fling_velocity) override; | 121 const gfx::Vector2dF& current_fling_velocity) override; |
| 122 | 122 |
| 123 void UpdateParentDrawConstraints(); | 123 void UpdateParentDrawConstraints(const ParentCompositorDrawConstraints&); |
|
boliu
2016/03/24 17:34:45
style: param needs a name
| |
| 124 void DetachFunctorFromView(); | 124 void DetachFunctorFromView(); |
| 125 | 125 |
| 126 void ReturnUnusedResource(scoped_ptr<ChildFrame> frame); | |
| 127 void ReturnResourceFromParent(uint32_t compositor_id, | |
| 128 uint32_t output_surface_id, | |
| 129 cc::ReturnedResourceArray* resources); | |
| 130 | |
| 126 private: | 131 private: |
| 127 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); | 132 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); |
| 128 bool CanOnDraw(); | 133 bool CanOnDraw(); |
| 129 void UpdateCompositorIsActive(); | 134 void UpdateCompositorIsActive(); |
| 130 bool CompositeSW(SkCanvas* canvas); | 135 bool CompositeSW(SkCanvas* canvas); |
| 131 scoped_ptr<base::trace_event::ConvertableToTraceFormat> RootLayerStateAsValue( | 136 scoped_ptr<base::trace_event::ConvertableToTraceFormat> RootLayerStateAsValue( |
| 132 const gfx::Vector2dF& total_scroll_offset_dip, | 137 const gfx::Vector2dF& total_scroll_offset_dip, |
| 133 const gfx::SizeF& scrollable_size_dip); | 138 const gfx::SizeF& scrollable_size_dip); |
| 134 | 139 |
| 135 void ReturnUnusedResource(scoped_ptr<ChildFrame> frame); | |
| 136 void ReturnResourceFromParent(); | |
| 137 | |
| 138 gfx::Vector2d max_scroll_offset() const; | 140 gfx::Vector2d max_scroll_offset() const; |
| 139 | 141 |
| 140 void UpdateMemoryPolicy(); | 142 void UpdateMemoryPolicy(); |
| 141 | 143 |
| 142 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); | 144 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); |
| 143 // For debug tracing or logging. Return the string representation of this | 145 // For debug tracing or logging. Return the string representation of this |
| 144 // view renderer's state. | 146 // view renderer's state. |
| 145 std::string ToString() const; | 147 std::string ToString() const; |
| 146 | 148 |
| 147 BrowserViewRendererClient* client_; | 149 BrowserViewRendererClient* client_; |
| 148 SharedRendererState shared_renderer_state_; | |
| 149 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 150 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 150 bool disable_page_visibility_; | 151 bool disable_page_visibility_; |
| 151 | 152 |
| 152 // The current compositor that's owned by the current RVH. | 153 // The current compositor that's owned by the current RVH. |
| 153 content::SynchronousCompositor* compositor_; | 154 content::SynchronousCompositor* compositor_; |
| 154 // A map from compositor's per-WebView unique ID to the compositor's raw | 155 // A map from compositor's per-WebView unique ID to the compositor's raw |
| 155 // pointer. A raw pointer here is fine because the entry will be erased when | 156 // pointer. A raw pointer here is fine because the entry will be erased when |
| 156 // a compositor is destroyed. | 157 // a compositor is destroyed. |
| 157 std::map<size_t, content::SynchronousCompositor*> compositor_map_; | 158 std::map<size_t, content::SynchronousCompositor*> compositor_map_; |
| 158 | 159 |
| 159 bool is_paused_; | 160 bool is_paused_; |
| 160 bool view_visible_; | 161 bool view_visible_; |
| 161 bool window_visible_; // Only applicable if |attached_to_window_| is true. | 162 bool window_visible_; // Only applicable if |attached_to_window_| is true. |
| 162 bool attached_to_window_; | 163 bool attached_to_window_; |
| 163 bool hardware_enabled_; | 164 bool hardware_enabled_; |
| 164 float dip_scale_; | 165 float dip_scale_; |
| 165 float page_scale_factor_; | 166 float page_scale_factor_; |
| 166 float min_page_scale_factor_; | 167 float min_page_scale_factor_; |
| 167 float max_page_scale_factor_; | 168 float max_page_scale_factor_; |
| 168 bool on_new_picture_enable_; | 169 bool on_new_picture_enable_; |
| 169 bool clear_view_; | 170 bool clear_view_; |
| 170 | 171 |
| 171 bool offscreen_pre_raster_; | 172 bool offscreen_pre_raster_; |
| 172 | 173 |
| 173 gfx::Vector2d last_on_draw_scroll_offset_; | |
| 174 gfx::Rect last_on_draw_global_visible_rect_; | 174 gfx::Rect last_on_draw_global_visible_rect_; |
| 175 | 175 |
| 176 gfx::Size size_; | 176 gfx::Size size_; |
| 177 | 177 |
| 178 gfx::SizeF scrollable_size_dip_; | 178 gfx::SizeF scrollable_size_dip_; |
| 179 | 179 |
| 180 // Current scroll offset in CSS pixels. | 180 // Current scroll offset in CSS pixels. |
| 181 // TODO(miletus): Make scroll_offset_dip_ a gfx::ScrollOffset. | 181 // TODO(miletus): Make scroll_offset_dip_ a gfx::ScrollOffset. |
| 182 gfx::Vector2dF scroll_offset_dip_; | 182 gfx::Vector2dF scroll_offset_dip_; |
| 183 | 183 |
| 184 // Max scroll offset in CSS pixels. | 184 // Max scroll offset in CSS pixels. |
| 185 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset. | 185 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset. |
| 186 gfx::Vector2dF max_scroll_offset_dip_; | 186 gfx::Vector2dF max_scroll_offset_dip_; |
| 187 | 187 |
| 188 // Used to prevent rounding errors from accumulating enough to generate | 188 // Used to prevent rounding errors from accumulating enough to generate |
| 189 // visible skew (especially noticeable when scrolling up and down in the same | 189 // visible skew (especially noticeable when scrolling up and down in the same |
| 190 // spot over a period of time). | 190 // spot over a period of time). |
| 191 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset. | 191 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset. |
| 192 gfx::Vector2dF overscroll_rounding_error_; | 192 gfx::Vector2dF overscroll_rounding_error_; |
| 193 | 193 |
| 194 uint32_t next_compositor_id_; | 194 uint32_t next_compositor_id_; |
| 195 | 195 |
| 196 ParentCompositorDrawConstraints external_draw_constraints_; | |
| 197 | |
| 196 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 198 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 } // namespace android_webview | 201 } // namespace android_webview |
| 200 | 202 |
| 201 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 203 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
| OLD | NEW |