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_consumer.h" | |
boliu
2016/04/21 17:05:39
should only need a forward declaration in header
Tobias Sargeant
2016/04/21 17:48:27
Done.
| |
13 #include "android_webview/browser/compositor_frame_producer.h" | |
12 #include "android_webview/browser/parent_compositor_draw_constraints.h" | 14 #include "android_webview/browser/parent_compositor_draw_constraints.h" |
13 #include "android_webview/browser/render_thread_manager.h" | |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/cancelable_callback.h" | 16 #include "base/cancelable_callback.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 #include "content/public/browser/android/synchronous_compositor.h" | 19 #include "content/public/browser/android/synchronous_compositor.h" |
19 #include "content/public/browser/android/synchronous_compositor_client.h" | 20 #include "content/public/browser/android/synchronous_compositor_client.h" |
20 #include "skia/ext/refptr.h" | 21 #include "skia/ext/refptr.h" |
21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
22 #include "ui/gfx/geometry/size_f.h" | 23 #include "ui/gfx/geometry/size_f.h" |
23 #include "ui/gfx/geometry/vector2d_f.h" | 24 #include "ui/gfx/geometry/vector2d_f.h" |
24 | 25 |
25 class SkCanvas; | 26 class SkCanvas; |
26 class SkPicture; | 27 class SkPicture; |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 class WebContents; | 30 class WebContents; |
30 } | 31 } |
31 | 32 |
32 namespace android_webview { | 33 namespace android_webview { |
33 | 34 |
34 class BrowserViewRendererClient; | 35 class BrowserViewRendererClient; |
35 class ChildFrame; | 36 class ChildFrame; |
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( |
129 CompositorFrameConsumer* compositor_frame_consumer) override; | |
130 void OnCompositorFrameConsumerWillDestroy( | |
131 CompositorFrameConsumer* compositor_frame_consumer) override; | |
126 | 132 |
127 private: | 133 private: |
128 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); | 134 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); |
129 bool CanOnDraw(); | 135 bool CanOnDraw(); |
130 void UpdateCompositorIsActive(); | 136 void UpdateCompositorIsActive(); |
131 bool CompositeSW(SkCanvas* canvas); | 137 bool CompositeSW(SkCanvas* canvas); |
132 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 138 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
133 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, | 139 RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, |
134 const gfx::SizeF& scrollable_size_dip); | 140 const gfx::SizeF& scrollable_size_dip); |
135 | 141 |
136 void ReturnUnusedResource(std::unique_ptr<ChildFrame> frame); | 142 void ReturnUnusedResource(std::unique_ptr<ChildFrame> frame); |
137 void ReturnResourceFromParent(); | 143 void ReturnResourceFromParent( |
138 void ReleaseHardware(); | 144 CompositorFrameConsumer* compositor_frame_consumer); |
145 void ReleaseHardware(CompositorFrameConsumer* compositor_frame_consumer); | |
139 | 146 |
140 gfx::Vector2d max_scroll_offset() const; | 147 gfx::Vector2d max_scroll_offset() const; |
141 | 148 |
142 void UpdateMemoryPolicy(); | 149 void UpdateMemoryPolicy(); |
143 | 150 |
144 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); | 151 uint32_t GetCompositorID(content::SynchronousCompositor* compositor); |
145 // For debug tracing or logging. Return the string representation of this | 152 // For debug tracing or logging. Return the string representation of this |
146 // view renderer's state. | 153 // view renderer's state. |
147 std::string ToString() const; | 154 std::string ToString() const; |
148 | 155 |
149 BrowserViewRendererClient* const client_; | 156 BrowserViewRendererClient* const client_; |
150 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 157 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
151 RenderThreadManager* render_thread_manager_; | 158 CompositorFrameConsumer* compositor_frame_consumer_; |
152 bool disable_page_visibility_; | 159 bool disable_page_visibility_; |
153 | 160 |
154 // The current compositor that's owned by the current RVH. | 161 // The current compositor that's owned by the current RVH. |
155 content::SynchronousCompositor* compositor_; | 162 content::SynchronousCompositor* compositor_; |
156 // A map from compositor's per-WebView unique ID to the compositor's raw | 163 // 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 | 164 // pointer. A raw pointer here is fine because the entry will be erased when |
158 // a compositor is destroyed. | 165 // a compositor is destroyed. |
159 std::map<size_t, content::SynchronousCompositor*> compositor_map_; | 166 std::map<size_t, content::SynchronousCompositor*> compositor_map_; |
160 | 167 |
161 bool is_paused_; | 168 bool is_paused_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 uint32_t next_compositor_id_; | 203 uint32_t next_compositor_id_; |
197 | 204 |
198 ParentCompositorDrawConstraints external_draw_constraints_; | 205 ParentCompositorDrawConstraints external_draw_constraints_; |
199 | 206 |
200 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); | 207 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); |
201 }; | 208 }; |
202 | 209 |
203 } // namespace android_webview | 210 } // namespace android_webview |
204 | 211 |
205 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ | 212 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ |
OLD | NEW |