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/compositor_frame_producer.h" |
12 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 13 #include "android_webview/browser/parent_compositor_draw_constraints.h" |
13 #include "android_webview/browser/render_thread_manager.h" | |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/cancelable_callback.h" | 15 #include "base/cancelable_callback.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.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 |
28 namespace content { | 28 namespace content { |
29 class WebContents; | 29 class WebContents; |
30 } | 30 } |
31 | 31 |
32 namespace android_webview { | 32 namespace android_webview { |
33 | 33 |
34 class BrowserViewRendererClient; | 34 class BrowserViewRendererClient; |
35 class ChildFrame; | 35 class ChildFrame; |
| 36 class CompositorFrameConsumer; |
36 | 37 |
37 // Interface for all the WebView-specific content rendering operations. | 38 // Interface for all the WebView-specific content rendering operations. |
38 // Provides software and hardware rendering and the Capture Picture API. | 39 // Provides software and hardware rendering and the Capture Picture API. |
39 class BrowserViewRenderer : public content::SynchronousCompositorClient { | 40 class BrowserViewRenderer : public content::SynchronousCompositorClient, |
| 41 public CompositorFrameProducer { |
40 public: | 42 public: |
41 static void CalculateTileMemoryPolicy(); | 43 static void CalculateTileMemoryPolicy(); |
42 static BrowserViewRenderer* FromWebContents( | 44 static BrowserViewRenderer* FromWebContents( |
43 content::WebContents* web_contents); | 45 content::WebContents* web_contents); |
44 | 46 |
45 BrowserViewRenderer( | 47 BrowserViewRenderer( |
46 BrowserViewRendererClient* client, | 48 BrowserViewRendererClient* client, |
47 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, | 49 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
48 bool disable_page_visibility); | 50 bool disable_page_visibility); |
49 | 51 |
50 ~BrowserViewRenderer() override; | 52 ~BrowserViewRenderer() override; |
51 | 53 |
52 void RegisterWithWebContents(content::WebContents* web_contents); | 54 void RegisterWithWebContents(content::WebContents* web_contents); |
53 | 55 |
54 // The BrowserViewRenderer client is responsible for ensuring that the | 56 // The BrowserViewRenderer client is responsible for ensuring that the |
55 // RenderThreadManager has been set correctly via this method. | 57 // CompositorFrameConsumer has been set correctly via this method. |
56 void SetRenderThreadManager(RenderThreadManager* render_thread_manager); | 58 void SetCompositorFrameConsumer( |
| 59 CompositorFrameConsumer* compositor_frame_consumer); |
57 | 60 |
58 // Called before either OnDrawHardware or OnDrawSoftware to set the view | 61 // Called before either OnDrawHardware or OnDrawSoftware to set the view |
59 // state of this frame. |scroll| is the view's current scroll offset. | 62 // state of this frame. |scroll| is the view's current scroll offset. |
60 // |global_visible_rect| is the intersection of the view size and the window | 63 // |global_visible_rect| is the intersection of the view size and the window |
61 // in window coordinates. | 64 // in window coordinates. |
62 void PrepareToDraw(const gfx::Vector2d& scroll, | 65 void PrepareToDraw(const gfx::Vector2d& scroll, |
63 const gfx::Rect& global_visible_rect); | 66 const gfx::Rect& global_visible_rect); |
64 | 67 |
65 // Main handlers for view drawing. A false return value indicates no new | 68 // Main handlers for view drawing. A false return value indicates no new |
66 // frame is produced. | 69 // frame is produced. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, | 117 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, |
115 const gfx::Vector2dF& max_scroll_offset_dip, | 118 const gfx::Vector2dF& max_scroll_offset_dip, |
116 const gfx::SizeF& scrollable_size_dip, | 119 const gfx::SizeF& scrollable_size_dip, |
117 float page_scale_factor, | 120 float page_scale_factor, |
118 float min_page_scale_factor, | 121 float min_page_scale_factor, |
119 float max_page_scale_factor) override; | 122 float max_page_scale_factor) override; |
120 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, | 123 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, |
121 const gfx::Vector2dF& latest_overscroll_delta, | 124 const gfx::Vector2dF& latest_overscroll_delta, |
122 const gfx::Vector2dF& current_fling_velocity) override; | 125 const gfx::Vector2dF& current_fling_velocity) override; |
123 | 126 |
124 void OnParentDrawConstraintsUpdated(); | 127 // CompositorFrameProducer overrides |
125 void DetachFunctorFromView(); | 128 void OnParentDrawConstraintsUpdated() override; |
| 129 void OnCompositorFrameConsumerWillDestroy() override; |
126 | 130 |
127 private: | 131 private: |
128 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); | 132 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); |
129 bool CanOnDraw(); | 133 bool CanOnDraw(); |
130 void UpdateCompositorIsActive(); | 134 void UpdateCompositorIsActive(); |
131 bool CompositeSW(SkCanvas* canvas); | 135 bool CompositeSW(SkCanvas* canvas); |
132 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 136 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
133 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, | 137 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, |
134 const gfx::SizeF& scrollable_size_dip); | 138 const gfx::SizeF& scrollable_size_dip); |
135 | 139 |
136 void ReturnUnusedResource(std::unique_ptr<ChildFrame> frame); | 140 void ReturnUnusedResource(std::unique_ptr<ChildFrame> frame); |
137 void ReturnResourceFromParent(); | 141 void ReturnResourceFromParent( |
| 142 CompositorFrameConsumer* compositor_frame_consumer); |
138 void ReleaseHardware(); | 143 void ReleaseHardware(); |
139 | 144 |
140 gfx::Vector2d max_scroll_offset() const; | 145 gfx::Vector2d max_scroll_offset() const; |
141 | 146 |
142 void UpdateMemoryPolicy(); | 147 void UpdateMemoryPolicy(); |
143 | 148 |
144 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); | 149 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); |
145 // For debug tracing or logging. Return the string representation of this | 150 // For debug tracing or logging. Return the string representation of this |
146 // view renderer's state. | 151 // view renderer's state. |
147 std::string ToString() const; | 152 std::string ToString() const; |
148 | 153 |
149 BrowserViewRendererClient* const client_; | 154 BrowserViewRendererClient* const client_; |
150 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 155 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
151 RenderThreadManager* render_thread_manager_; | 156 CompositorFrameConsumer* compositor_frame_consumer_; |
152 bool disable_page_visibility_; | 157 bool disable_page_visibility_; |
153 | 158 |
154 // The current compositor that's owned by the current RVH. | 159 // The current compositor that's owned by the current RVH. |
155 content::SynchronousCompositor* compositor_; | 160 content::SynchronousCompositor* compositor_; |
156 // A map from compositor's per-WebView unique ID to the compositor's raw | 161 // A map from compositor's per-WebView unique ID to the compositor's raw |
157 // pointer. A raw pointer here is fine because the entry will be erased when | 162 // pointer. A raw pointer here is fine because the entry will be erased when |
158 // a compositor is destroyed. | 163 // a compositor is destroyed. |
159 std::map<size_t, content::SynchronousCompositor*> compositor_map_; | 164 std::map<size_t, content::SynchronousCompositor*> compositor_map_; |
160 | 165 |
161 bool is_paused_; | 166 bool is_paused_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 uint32_t next_compositor_id_; | 201 uint32_t next_compositor_id_; |
197 | 202 |
198 ParentCompositorDrawConstraints external_draw_constraints_; | 203 ParentCompositorDrawConstraints external_draw_constraints_; |
199 | 204 |
200 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 205 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
201 }; | 206 }; |
202 | 207 |
203 } // namespace android_webview | 208 } // namespace android_webview |
204 | 209 |
205 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 210 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
OLD | NEW |