Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: android_webview/browser/browser_view_renderer.h

Issue 2036023002: Rewire Android WebView's compositor changed signal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <set> 11 #include <set>
12 12
13 #include "android_webview/browser/compositor_frame_producer.h" 13 #include "android_webview/browser/compositor_frame_producer.h"
14 #include "android_webview/browser/compositor_id.h"
14 #include "android_webview/browser/parent_compositor_draw_constraints.h" 15 #include "android_webview/browser/parent_compositor_draw_constraints.h"
15 #include "base/callback.h" 16 #include "base/callback.h"
16 #include "base/cancelable_callback.h" 17 #include "base/cancelable_callback.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
19 #include "content/public/browser/android/synchronous_compositor.h" 20 #include "content/public/browser/android/synchronous_compositor.h"
20 #include "content/public/browser/android/synchronous_compositor_client.h" 21 #include "content/public/browser/android/synchronous_compositor_client.h"
22 #include "content/public/browser/web_contents_observer.h"
21 #include "third_party/skia/include/core/SkRefCnt.h" 23 #include "third_party/skia/include/core/SkRefCnt.h"
22 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/geometry/size_f.h" 25 #include "ui/gfx/geometry/size_f.h"
24 #include "ui/gfx/geometry/vector2d_f.h" 26 #include "ui/gfx/geometry/vector2d_f.h"
25 27
26 class SkCanvas; 28 class SkCanvas;
27 class SkPicture; 29 class SkPicture;
28 30
29 namespace content { 31 namespace content {
32 class RenderViewHost;
30 class WebContents; 33 class WebContents;
31 } 34 }
32 35
33 namespace android_webview { 36 namespace android_webview {
34 37
35 class BrowserViewRendererClient; 38 class BrowserViewRendererClient;
36 class ChildFrame; 39 class ChildFrame;
37 class CompositorFrameConsumer; 40 class CompositorFrameConsumer;
38 41
39 // Interface for all the WebView-specific content rendering operations. 42 // Interface for all the WebView-specific content rendering operations.
40 // Provides software and hardware rendering and the Capture Picture API. 43 // Provides software and hardware rendering and the Capture Picture API.
41 class BrowserViewRenderer : public content::SynchronousCompositorClient, 44 class BrowserViewRenderer : public content::SynchronousCompositorClient,
45 public content::WebContentsObserver,
42 public CompositorFrameProducer { 46 public CompositorFrameProducer {
43 public: 47 public:
44 static void CalculateTileMemoryPolicy(); 48 static void CalculateTileMemoryPolicy();
45 static BrowserViewRenderer* FromWebContents( 49 static BrowserViewRenderer* FromWebContents(
46 content::WebContents* web_contents); 50 content::WebContents* web_contents);
47 51
48 BrowserViewRenderer( 52 BrowserViewRenderer(
53 content::WebContents* web_contents,
49 BrowserViewRendererClient* client, 54 BrowserViewRendererClient* client,
50 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); 55 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner);
51 56
52 ~BrowserViewRenderer() override; 57 ~BrowserViewRenderer() override;
53 58
54 void RegisterWithWebContents(content::WebContents* web_contents); 59 void RegisterWithWebContents(content::WebContents* web_contents);
55 60
56 // The BrowserViewRenderer client is responsible for ensuring that 61 // The BrowserViewRenderer client is responsible for ensuring that
57 // the current compositor frame consumer has been set correctly via 62 // the current compositor frame consumer has been set correctly via
58 // this method. The consumer is added to the set of registered 63 // this method. The consumer is added to the set of registered
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Android views hierarchy gluing. 106 // Android views hierarchy gluing.
102 bool IsVisible() const; 107 bool IsVisible() const;
103 gfx::Rect GetScreenRect() const; 108 gfx::Rect GetScreenRect() const;
104 bool attached_to_window() const { return attached_to_window_; } 109 bool attached_to_window() const { return attached_to_window_; }
105 gfx::Size size() const { return size_; } 110 gfx::Size size() const { return size_; }
106 111
107 bool IsClientVisible() const; 112 bool IsClientVisible() const;
108 void TrimMemory(); 113 void TrimMemory();
109 114
110 // SynchronousCompositorClient overrides. 115 // SynchronousCompositorClient overrides.
111 void DidInitializeCompositor( 116 void DidInitializeCompositor(content::SynchronousCompositor* compositor,
112 content::SynchronousCompositor* compositor) override; 117 int process_id,
113 void DidDestroyCompositor( 118 int routing_id) override;
114 content::SynchronousCompositor* compositor) override; 119 void DidDestroyCompositor(content::SynchronousCompositor* compositor,
115 void DidBecomeCurrent(content::SynchronousCompositor* compositor) override; 120 int process_id,
121 int routing_id) override;
116 void PostInvalidate() override; 122 void PostInvalidate() override;
117 void DidUpdateContent() override; 123 void DidUpdateContent() override;
118 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip, 124 void UpdateRootLayerState(const gfx::Vector2dF& total_scroll_offset_dip,
119 const gfx::Vector2dF& max_scroll_offset_dip, 125 const gfx::Vector2dF& max_scroll_offset_dip,
120 const gfx::SizeF& scrollable_size_dip, 126 const gfx::SizeF& scrollable_size_dip,
121 float page_scale_factor, 127 float page_scale_factor,
122 float min_page_scale_factor, 128 float min_page_scale_factor,
123 float max_page_scale_factor) override; 129 float max_page_scale_factor) override;
124 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, 130 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll,
125 const gfx::Vector2dF& latest_overscroll_delta, 131 const gfx::Vector2dF& latest_overscroll_delta,
126 const gfx::Vector2dF& current_fling_velocity) override; 132 const gfx::Vector2dF& current_fling_velocity) override;
127 133
134 // content::WebContentsObserver overrides
135 void RenderViewHostChanged(content::RenderViewHost* old_host,
136 content::RenderViewHost* new_host) override;
137
128 // CompositorFrameProducer overrides 138 // CompositorFrameProducer overrides
129 void OnParentDrawConstraintsUpdated( 139 void OnParentDrawConstraintsUpdated(
130 CompositorFrameConsumer* compositor_frame_consumer) override; 140 CompositorFrameConsumer* compositor_frame_consumer) override;
131 void RemoveCompositorFrameConsumer( 141 void RemoveCompositorFrameConsumer(
132 CompositorFrameConsumer* compositor_frame_consumer) override; 142 CompositorFrameConsumer* compositor_frame_consumer) override;
133 143
134 private: 144 private:
135 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); 145 void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip);
136 bool CanOnDraw(); 146 bool CanOnDraw();
137 void UpdateCompositorIsActive(); 147 void UpdateCompositorIsActive();
(...skipping 15 matching lines...) Expand all
153 // For debug tracing or logging. Return the string representation of this 163 // For debug tracing or logging. Return the string representation of this
154 // view renderer's state. 164 // view renderer's state.
155 std::string ToString() const; 165 std::string ToString() const;
156 166
157 BrowserViewRendererClient* const client_; 167 BrowserViewRendererClient* const client_;
158 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 168 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
159 CompositorFrameConsumer* current_compositor_frame_consumer_; 169 CompositorFrameConsumer* current_compositor_frame_consumer_;
160 std::set<CompositorFrameConsumer*> compositor_frame_consumers_; 170 std::set<CompositorFrameConsumer*> compositor_frame_consumers_;
161 171
162 // The current compositor that's owned by the current RVH. 172 // The current compositor that's owned by the current RVH.
173 // When compositor_ != nullptr, compositor_id_ is the id of compositor_.
174 // When compositor_ == nullptr, compositor_id_ is the id of the future
175 // compositor.
163 content::SynchronousCompositor* compositor_; 176 content::SynchronousCompositor* compositor_;
177 CompositorID compositor_id_;
164 // A map from compositor's per-WebView unique ID to the compositor's raw 178 // A map from compositor's per-WebView unique ID to the compositor's raw
165 // pointer. A raw pointer here is fine because the entry will be erased when 179 // pointer. A raw pointer here is fine because the entry will be erased when
166 // a compositor is destroyed. 180 // a compositor is destroyed.
167 std::map<size_t, content::SynchronousCompositor*> compositor_map_; 181 std::map<CompositorID, content::SynchronousCompositor*> compositor_map_;
168 182
169 bool is_paused_; 183 bool is_paused_;
170 bool view_visible_; 184 bool view_visible_;
171 bool window_visible_; // Only applicable if |attached_to_window_| is true. 185 bool window_visible_; // Only applicable if |attached_to_window_| is true.
172 bool attached_to_window_; 186 bool attached_to_window_;
173 bool hardware_enabled_; 187 bool hardware_enabled_;
174 float dip_scale_; 188 float dip_scale_;
175 float page_scale_factor_; 189 float page_scale_factor_;
176 float min_page_scale_factor_; 190 float min_page_scale_factor_;
177 float max_page_scale_factor_; 191 float max_page_scale_factor_;
(...skipping 16 matching lines...) Expand all
194 // Max scroll offset in CSS pixels. 208 // Max scroll offset in CSS pixels.
195 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset. 209 // TODO(miletus): Make max_scroll_offset_dip_ a gfx::ScrollOffset.
196 gfx::Vector2dF max_scroll_offset_dip_; 210 gfx::Vector2dF max_scroll_offset_dip_;
197 211
198 // Used to prevent rounding errors from accumulating enough to generate 212 // Used to prevent rounding errors from accumulating enough to generate
199 // visible skew (especially noticeable when scrolling up and down in the same 213 // visible skew (especially noticeable when scrolling up and down in the same
200 // spot over a period of time). 214 // spot over a period of time).
201 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset. 215 // TODO(miletus): Make overscroll_rounding_error_ a gfx::ScrollOffset.
202 gfx::Vector2dF overscroll_rounding_error_; 216 gfx::Vector2dF overscroll_rounding_error_;
203 217
204 uint32_t next_compositor_id_;
205
206 ParentCompositorDrawConstraints external_draw_constraints_; 218 ParentCompositorDrawConstraints external_draw_constraints_;
207 219
208 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer); 220 DISALLOW_COPY_AND_ASSIGN(BrowserViewRenderer);
209 }; 221 };
210 222
211 } // namespace android_webview 223 } // namespace android_webview
212 224
213 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_ 225 #endif // ANDROID_WEBVIEW_BROWSER_BROWSER_VIEW_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698