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

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

Issue 1943963003: WIP Handle AwContents needing multiple live functors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "android_webview/browser/browser_view_renderer.h" 5 #include "android_webview/browser/browser_view_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/browser_view_renderer_client.h" 9 #include "android_webview/browser/browser_view_renderer_client.h"
10 #include "android_webview/browser/child_frame.h" 10 #include "android_webview/browser/child_frame.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 BrowserViewRenderer* BrowserViewRenderer::FromWebContents( 85 BrowserViewRenderer* BrowserViewRenderer::FromWebContents(
86 content::WebContents* web_contents) { 86 content::WebContents* web_contents) {
87 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents); 87 return BrowserViewRendererUserData::GetBrowserViewRenderer(web_contents);
88 } 88 }
89 89
90 BrowserViewRenderer::BrowserViewRenderer( 90 BrowserViewRenderer::BrowserViewRenderer(
91 BrowserViewRendererClient* client, 91 BrowserViewRendererClient* client,
92 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) 92 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner)
93 : client_(client), 93 : client_(client),
94 ui_task_runner_(ui_task_runner), 94 ui_task_runner_(ui_task_runner),
95 compositor_frame_consumer_(nullptr), 95 current_compositor_frame_consumer_(nullptr),
96 compositor_(NULL), 96 compositor_(NULL),
97 is_paused_(false), 97 is_paused_(false),
98 view_visible_(false), 98 view_visible_(false),
99 window_visible_(false), 99 window_visible_(false),
100 attached_to_window_(false), 100 attached_to_window_(false),
101 hardware_enabled_(false), 101 hardware_enabled_(false),
102 dip_scale_(0.f), 102 dip_scale_(0.f),
103 page_scale_factor_(1.f), 103 page_scale_factor_(1.f),
104 min_page_scale_factor_(0.f), 104 min_page_scale_factor_(0.f),
105 max_page_scale_factor_(0.f), 105 max_page_scale_factor_(0.f),
106 on_new_picture_enable_(false), 106 on_new_picture_enable_(false),
107 clear_view_(false), 107 clear_view_(false),
108 offscreen_pre_raster_(false), 108 offscreen_pre_raster_(false),
109 next_compositor_id_(1) {} 109 next_compositor_id_(1) {}
110 110
111 BrowserViewRenderer::~BrowserViewRenderer() { 111 BrowserViewRenderer::~BrowserViewRenderer() {
112 DCHECK(compositor_map_.empty()); 112 DCHECK(compositor_map_.empty());
113 SetCompositorFrameConsumer(nullptr); 113 while (compositor_frame_consumers_.size()) {
114 } 114 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin());
115
116 void BrowserViewRenderer::SetCompositorFrameConsumer(
117 CompositorFrameConsumer* compositor_frame_consumer) {
118 if (compositor_frame_consumer == compositor_frame_consumer_) {
119 return;
120 }
121 if (compositor_frame_consumer_) {
122 compositor_frame_consumer_->DeleteHardwareRendererOnUI();
123 ReturnUnusedResource(
124 compositor_frame_consumer_->PassUncommittedFrameOnUI());
125 ReturnResourceFromParent(compositor_frame_consumer_);
126 compositor_frame_consumer_->SetCompositorFrameProducer(nullptr);
127 }
128 compositor_frame_consumer_ = compositor_frame_consumer;
129 if (compositor_frame_consumer_) {
130 compositor_frame_consumer_->SetCompositorFrameProducer(this);
131 } 115 }
132 } 116 }
133 117
118 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer(
119 CompositorFrameConsumer* compositor_frame_consumer) {
120 if (compositor_frame_consumer == current_compositor_frame_consumer_) {
121 return;
122 }
123 current_compositor_frame_consumer_ = compositor_frame_consumer;
124 if (current_compositor_frame_consumer_) {
125 compositor_frame_consumers_.insert(current_compositor_frame_consumer_);
126 if (current_compositor_frame_consumer_->GetCompositorFrameProducer() !=
127 this) {
128 if (current_compositor_frame_consumer_->GetCompositorFrameProducer()) {
boliu 2016/05/05 14:09:34 this can't happen? we destroy the previous BVR bef
Tobias Sargeant 2016/05/05 19:06:46 You're right. I've cleaned this up.
129 current_compositor_frame_consumer_->GetCompositorFrameProducer()
130 ->RemoveCompositorFrameConsumer(current_compositor_frame_consumer_);
131 }
132 current_compositor_frame_consumer_->SetCompositorFrameProducer(this);
133 }
134 OnParentDrawConstraintsUpdated(current_compositor_frame_consumer_);
135 }
136 }
137
134 void BrowserViewRenderer::RegisterWithWebContents( 138 void BrowserViewRenderer::RegisterWithWebContents(
135 content::WebContents* web_contents) { 139 content::WebContents* web_contents) {
136 web_contents->SetUserData(kBrowserViewRendererUserDataKey, 140 web_contents->SetUserData(kBrowserViewRendererUserDataKey,
137 new BrowserViewRendererUserData(this)); 141 new BrowserViewRendererUserData(this));
138 } 142 }
139 143
140 void BrowserViewRenderer::TrimMemory() { 144 void BrowserViewRenderer::TrimMemory() {
141 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 145 DCHECK(ui_task_runner_->BelongsToCurrentThread());
142 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); 146 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory");
143 // Just set the memory limit to 0 and drop all tiles. This will be reset to 147 // Just set the memory limit to 0 and drop all tiles. This will be reset to
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (clear_view_) { 197 if (clear_view_) {
194 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", 198 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView",
195 TRACE_EVENT_SCOPE_THREAD); 199 TRACE_EVENT_SCOPE_THREAD);
196 return false; 200 return false;
197 } 201 }
198 202
199 return true; 203 return true;
200 } 204 }
201 205
202 bool BrowserViewRenderer::OnDrawHardware() { 206 bool BrowserViewRenderer::OnDrawHardware() {
203 DCHECK(compositor_frame_consumer_); 207 DCHECK(current_compositor_frame_consumer_);
204 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); 208 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware");
205 209
206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); 210 current_compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI();
207 211
208 if (!CanOnDraw()) { 212 if (!CanOnDraw()) {
209 return false; 213 return false;
210 } 214 }
211 215
212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); 216 current_compositor_frame_consumer_->SetScrollOffsetOnUI(
217 last_on_draw_scroll_offset_);
213 hardware_enabled_ = true; 218 hardware_enabled_ = true;
214 219
215 external_draw_constraints_ = 220 external_draw_constraints_ =
216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 221 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
217 222
218 ReturnResourceFromParent(compositor_frame_consumer_); 223 ReturnResourceFromParent(current_compositor_frame_consumer_);
219 UpdateMemoryPolicy(); 224 UpdateMemoryPolicy();
220 225
221 gfx::Size surface_size(size_); 226 gfx::Size surface_size(size_);
222 gfx::Rect viewport(surface_size); 227 gfx::Rect viewport(surface_size);
223 gfx::Rect clip = viewport; 228 gfx::Rect clip = viewport;
224 gfx::Transform transform_for_tile_priority = 229 gfx::Transform transform_for_tile_priority =
225 external_draw_constraints_.transform; 230 external_draw_constraints_.transform;
226 231
227 // If the WebView is on a layer, WebView does not know what transform is 232 // If the WebView is on a layer, WebView does not know what transform is
228 // applied onto the layer so global visible rect does not make sense here. 233 // applied onto the layer so global visible rect does not make sense here.
229 // In this case, just use the surface rect for tiling. 234 // In this case, just use the surface rect for tiling.
230 gfx::Rect viewport_rect_for_tile_priority; 235 gfx::Rect viewport_rect_for_tile_priority;
231 236
232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. 237 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on.
233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { 238 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 239 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
235 } 240 }
236 241
237 content::SynchronousCompositor::Frame frame = 242 content::SynchronousCompositor::Frame frame =
238 compositor_->DemandDrawHw(surface_size, 243 compositor_->DemandDrawHw(surface_size,
239 gfx::Transform(), 244 gfx::Transform(),
240 viewport, 245 viewport,
241 clip, 246 clip,
242 viewport_rect_for_tile_priority, 247 viewport_rect_for_tile_priority,
243 transform_for_tile_priority); 248 transform_for_tile_priority);
244 if (!frame.frame.get()) { 249 if (!frame.frame.get()) {
245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", 250 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
246 TRACE_EVENT_SCOPE_THREAD); 251 TRACE_EVENT_SCOPE_THREAD);
247 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); 252 hardware_enabled_ = current_compositor_frame_consumer_->HasFrameOnUI();
248 if (!hardware_enabled_) 253 if (!hardware_enabled_)
249 UpdateMemoryPolicy(); 254 UpdateMemoryPolicy();
250 return hardware_enabled_; 255 return hardware_enabled_;
251 } 256 }
252 257
253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( 258 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame(
254 frame.output_surface_id, std::move(frame.frame), 259 frame.output_surface_id, std::move(frame.frame),
255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), 260 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(),
256 transform_for_tile_priority, offscreen_pre_raster_, 261 transform_for_tile_priority, offscreen_pre_raster_,
257 external_draw_constraints_.is_layer)); 262 external_draw_constraints_.is_layer));
258 263
259 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); 264 ReturnUnusedResource(
260 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); 265 current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
266 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
261 return true; 267 return true;
262 } 268 }
263 269
264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { 270 void BrowserViewRenderer::OnParentDrawConstraintsUpdated(
265 DCHECK(compositor_frame_consumer_); 271 CompositorFrameConsumer* compositor_frame_consumer) {
266 PostInvalidate(); 272 DCHECK(compositor_frame_consumer);
boliu 2016/05/05 14:09:34 DCHECK compositor frame is in set
Tobias Sargeant 2016/05/05 19:06:45 Don't need to, because being equal to the current
boliu 2016/05/06 15:53:13 Well, you are DCHECK-ing that guarantee.
267 external_draw_constraints_ = 273 if (compositor_frame_consumer == current_compositor_frame_consumer_) {
boliu 2016/05/05 14:09:34 nit: we usually prefer if (foo) return; since
Tobias Sargeant 2016/05/05 19:06:46 Done.
268 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 274 PostInvalidate();
269 UpdateMemoryPolicy(); 275 external_draw_constraints_ =
276 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
277 UpdateMemoryPolicy();
278 }
270 } 279 }
271 280
272 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { 281 void BrowserViewRenderer::RemoveCompositorFrameConsumer(
273 DCHECK(compositor_frame_consumer_); 282 CompositorFrameConsumer* compositor_frame_consumer) {
274 SetCompositorFrameConsumer(nullptr); 283 DCHECK(compositor_frame_consumers_.count(compositor_frame_consumer));
284 compositor_frame_consumers_.erase(compositor_frame_consumer);
285 if (current_compositor_frame_consumer_ == compositor_frame_consumer) {
286 SetCurrentCompositorFrameConsumer(nullptr);
287 }
288
289 // At this point the compositor frame consumer has to hand back all resources
290 // to the child compositor.
291 compositor_frame_consumer->DeleteHardwareRendererOnUI();
292 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI());
293 ReturnResourceFromParent(compositor_frame_consumer);
294 compositor_frame_consumer->SetCompositorFrameProducer(nullptr);
275 } 295 }
276 296
277 void BrowserViewRenderer::ReturnUnusedResource( 297 void BrowserViewRenderer::ReturnUnusedResource(
278 std::unique_ptr<ChildFrame> child_frame) { 298 std::unique_ptr<ChildFrame> child_frame) {
279 if (!child_frame.get() || !child_frame->frame.get()) 299 if (!child_frame.get() || !child_frame->frame.get())
280 return; 300 return;
281 301
282 cc::CompositorFrameAck frame_ack; 302 cc::CompositorFrameAck frame_ack;
283 cc::TransferableResource::ReturnResources( 303 cc::TransferableResource::ReturnResources(
284 child_frame->frame->delegated_frame_data->resource_list, 304 child_frame->frame->delegated_frame_data->resource_list,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 451 }
432 452
433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { 453 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) {
434 if (!compositor_) 454 if (!compositor_)
435 return; 455 return;
436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); 456 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll");
437 compositor_->OnComputeScroll(animation_time); 457 compositor_->OnComputeScroll(animation_time);
438 } 458 }
439 459
440 void BrowserViewRenderer::ReleaseHardware() { 460 void BrowserViewRenderer::ReleaseHardware() {
441 if (compositor_frame_consumer_) { 461 for (auto compositor_frame_consumer_ : compositor_frame_consumers_) {
442 ReturnUnusedResource( 462 ReturnUnusedResource(
443 compositor_frame_consumer_->PassUncommittedFrameOnUI()); 463 compositor_frame_consumer_->PassUncommittedFrameOnUI());
444 ReturnResourceFromParent(compositor_frame_consumer_); 464 ReturnResourceFromParent(compositor_frame_consumer_);
445 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); 465 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI());
446 } 466 }
447 hardware_enabled_ = false; 467 hardware_enabled_ = false;
448 UpdateMemoryPolicy(); 468 UpdateMemoryPolicy();
449 } 469 }
450 470
451 bool BrowserViewRenderer::IsVisible() const { 471 bool BrowserViewRenderer::IsVisible() const {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 base::StringAppendF(&str, 740 base::StringAppendF(&str,
721 "overscroll_rounding_error_: %s ", 741 "overscroll_rounding_error_: %s ",
722 overscroll_rounding_error_.ToString().c_str()); 742 overscroll_rounding_error_.ToString().c_str());
723 base::StringAppendF( 743 base::StringAppendF(
724 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 744 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
725 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 745 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
726 return str; 746 return str;
727 } 747 }
728 748
729 } // namespace android_webview 749 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698