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

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_frame_consumers_(),
boliu 2016/05/04 16:58:52 not necessary
Tobias Sargeant 2016/05/05 18:36:56 Removed.
96 compositor_(NULL), 97 compositor_(NULL),
97 is_paused_(false), 98 is_paused_(false),
98 view_visible_(false), 99 view_visible_(false),
99 window_visible_(false), 100 window_visible_(false),
100 attached_to_window_(false), 101 attached_to_window_(false),
101 hardware_enabled_(false), 102 hardware_enabled_(false),
102 dip_scale_(0.f), 103 dip_scale_(0.f),
103 page_scale_factor_(1.f), 104 page_scale_factor_(1.f),
104 min_page_scale_factor_(0.f), 105 min_page_scale_factor_(0.f),
105 max_page_scale_factor_(0.f), 106 max_page_scale_factor_(0.f),
106 on_new_picture_enable_(false), 107 on_new_picture_enable_(false),
107 clear_view_(false), 108 clear_view_(false),
108 offscreen_pre_raster_(false), 109 offscreen_pre_raster_(false),
109 next_compositor_id_(1) {} 110 next_compositor_id_(1) {}
110 111
111 BrowserViewRenderer::~BrowserViewRenderer() { 112 BrowserViewRenderer::~BrowserViewRenderer() {
112 DCHECK(compositor_map_.empty()); 113 DCHECK(compositor_map_.empty());
113 SetCompositorFrameConsumer(nullptr); 114 while (compositor_frame_consumers_.size()) {
115 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin());
116 }
114 } 117 }
115 118
116 void BrowserViewRenderer::SetCompositorFrameConsumer( 119 void BrowserViewRenderer::SetCompositorFrameConsumer(
boliu 2016/05/04 16:58:52 Feels like "AddToSet" and "MakeCurrent" should be
Tobias Sargeant 2016/05/05 13:53:19 I thought about breaking it into two methods, but
117 CompositorFrameConsumer* compositor_frame_consumer) { 120 CompositorFrameConsumer* compositor_frame_consumer) {
118 if (compositor_frame_consumer == compositor_frame_consumer_) { 121 if (compositor_frame_consumer == current_compositor_frame_consumer_) {
119 return; 122 return;
120 } 123 }
121 if (compositor_frame_consumer_) { 124 current_compositor_frame_consumer_ = compositor_frame_consumer;
boliu 2016/05/04 16:58:52 should update parent draw constraints if the curre
Tobias Sargeant 2016/05/05 13:53:19 Done.
122 compositor_frame_consumer_->DeleteHardwareRendererOnUI(); 125 LOG(WARNING) << "XXX Setting current_compositor_frame_consumer_ to "
123 ReturnUnusedResource( 126 << current_compositor_frame_consumer_;
124 compositor_frame_consumer_->PassUncommittedFrameOnUI()); 127 if (current_compositor_frame_consumer_) {
125 ReturnResourceFromParent(compositor_frame_consumer_); 128 compositor_frame_consumers_.insert(current_compositor_frame_consumer_);
boliu 2016/05/04 16:58:52 dcheck for duplicates?
Tobias Sargeant 2016/05/05 13:53:19 Insertion of the same value may happen if (for exa
126 compositor_frame_consumer_->SetCompositorFrameProducer(nullptr); 129 current_compositor_frame_consumer_->SetCompositorFrameProducer(this);
127 }
128 compositor_frame_consumer_ = compositor_frame_consumer;
129 if (compositor_frame_consumer_) {
130 compositor_frame_consumer_->SetCompositorFrameProducer(this);
131 } 130 }
132 } 131 }
133 132
134 void BrowserViewRenderer::RegisterWithWebContents( 133 void BrowserViewRenderer::RegisterWithWebContents(
135 content::WebContents* web_contents) { 134 content::WebContents* web_contents) {
136 web_contents->SetUserData(kBrowserViewRendererUserDataKey, 135 web_contents->SetUserData(kBrowserViewRendererUserDataKey,
137 new BrowserViewRendererUserData(this)); 136 new BrowserViewRendererUserData(this));
138 } 137 }
139 138
140 void BrowserViewRenderer::TrimMemory() { 139 void BrowserViewRenderer::TrimMemory() {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (clear_view_) { 192 if (clear_view_) {
194 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", 193 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView",
195 TRACE_EVENT_SCOPE_THREAD); 194 TRACE_EVENT_SCOPE_THREAD);
196 return false; 195 return false;
197 } 196 }
198 197
199 return true; 198 return true;
200 } 199 }
201 200
202 bool BrowserViewRenderer::OnDrawHardware() { 201 bool BrowserViewRenderer::OnDrawHardware() {
203 DCHECK(compositor_frame_consumer_); 202 DCHECK(current_compositor_frame_consumer_);
204 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); 203 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware");
205 204
206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); 205 current_compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI();
207 206
208 if (!CanOnDraw()) { 207 if (!CanOnDraw()) {
209 return false; 208 return false;
210 } 209 }
211 210
212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); 211 current_compositor_frame_consumer_->SetScrollOffsetOnUI(
212 last_on_draw_scroll_offset_);
213 hardware_enabled_ = true; 213 hardware_enabled_ = true;
214 214
215 external_draw_constraints_ = 215 external_draw_constraints_ =
216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 216 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
217 217
218 ReturnResourceFromParent(compositor_frame_consumer_); 218 ReturnResourceFromParent(current_compositor_frame_consumer_);
219 UpdateMemoryPolicy(); 219 UpdateMemoryPolicy();
220 220
221 gfx::Size surface_size(size_); 221 gfx::Size surface_size(size_);
222 gfx::Rect viewport(surface_size); 222 gfx::Rect viewport(surface_size);
223 gfx::Rect clip = viewport; 223 gfx::Rect clip = viewport;
224 gfx::Transform transform_for_tile_priority = 224 gfx::Transform transform_for_tile_priority =
225 external_draw_constraints_.transform; 225 external_draw_constraints_.transform;
226 226
227 // If the WebView is on a layer, WebView does not know what transform is 227 // 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. 228 // applied onto the layer so global visible rect does not make sense here.
229 // In this case, just use the surface rect for tiling. 229 // In this case, just use the surface rect for tiling.
230 gfx::Rect viewport_rect_for_tile_priority; 230 gfx::Rect viewport_rect_for_tile_priority;
231 231
232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. 232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on.
233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { 233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
235 } 235 }
236 236
237 content::SynchronousCompositor::Frame frame = 237 content::SynchronousCompositor::Frame frame =
238 compositor_->DemandDrawHw(surface_size, 238 compositor_->DemandDrawHw(surface_size,
239 gfx::Transform(), 239 gfx::Transform(),
240 viewport, 240 viewport,
241 clip, 241 clip,
242 viewport_rect_for_tile_priority, 242 viewport_rect_for_tile_priority,
243 transform_for_tile_priority); 243 transform_for_tile_priority);
244 if (!frame.frame.get()) { 244 if (!frame.frame.get()) {
245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", 245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
246 TRACE_EVENT_SCOPE_THREAD); 246 TRACE_EVENT_SCOPE_THREAD);
247 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); 247 hardware_enabled_ = current_compositor_frame_consumer_->HasFrameOnUI();
248 if (!hardware_enabled_) 248 if (!hardware_enabled_)
249 UpdateMemoryPolicy(); 249 UpdateMemoryPolicy();
250 return hardware_enabled_; 250 return hardware_enabled_;
251 } 251 }
252 252
253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( 253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame(
254 frame.output_surface_id, std::move(frame.frame), 254 frame.output_surface_id, std::move(frame.frame),
255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), 255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(),
256 transform_for_tile_priority, offscreen_pre_raster_, 256 transform_for_tile_priority, offscreen_pre_raster_,
257 external_draw_constraints_.is_layer)); 257 external_draw_constraints_.is_layer));
258 258
259 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); 259 ReturnUnusedResource(
260 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); 260 current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
261 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
261 return true; 262 return true;
262 } 263 }
263 264
264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { 265 void BrowserViewRenderer::OnParentDrawConstraintsUpdated(
265 DCHECK(compositor_frame_consumer_); 266 CompositorFrameConsumer* compositor_frame_consumer) {
267 DCHECK(current_compositor_frame_consumer_);
266 PostInvalidate(); 268 PostInvalidate();
267 external_draw_constraints_ = 269 external_draw_constraints_ =
268 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 270 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
boliu 2016/05/04 16:58:52 what if compositor_frame_consumer != current?
Tobias Sargeant 2016/05/05 13:53:19 Should be NOP in that case.
269 UpdateMemoryPolicy(); 271 UpdateMemoryPolicy();
270 } 272 }
271 273
272 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { 274 void BrowserViewRenderer::RemoveCompositorFrameConsumer(
273 DCHECK(compositor_frame_consumer_); 275 CompositorFrameConsumer* compositor_frame_consumer) {
274 SetCompositorFrameConsumer(nullptr); 276 DCHECK(compositor_frame_consumers_.count(compositor_frame_consumer) == 1);
boliu 2016/05/04 16:58:52 == 1 part is redundant
Tobias Sargeant 2016/05/05 13:53:19 Removed.
277 compositor_frame_consumers_.erase(compositor_frame_consumer);
278 if (current_compositor_frame_consumer_ == compositor_frame_consumer) {
279 current_compositor_frame_consumer_ = nullptr;
boliu 2016/05/04 16:58:52 SetCompositorFrameConsumer(nullptr), maybe that on
Tobias Sargeant 2016/05/05 18:36:56 Removed the need for this.
280 LOG(WARNING) << "XXX Setting current_compositor_frame_consumer_ to null";
boliu 2016/05/04 16:58:52 So yeah, what's responsible for setting the curren
boliu 2016/05/05 14:09:34 Didn't really resolve this one
Tobias Sargeant 2016/05/05 18:36:56 I think it's actually reasonable to enforce that y
boliu 2016/05/05 21:40:31 I'm not suggesting don't allow destroying the curr
281 }
282
283 // At this point the compositor frame consumer has to hand back all resources
284 // to the child compositor.
285 compositor_frame_consumer->DeleteHardwareRendererOnUI();
286 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI());
287 ReturnResourceFromParent(compositor_frame_consumer);
288 compositor_frame_consumer->SetCompositorFrameProducer(nullptr);
275 } 289 }
276 290
277 void BrowserViewRenderer::ReturnUnusedResource( 291 void BrowserViewRenderer::ReturnUnusedResource(
278 std::unique_ptr<ChildFrame> child_frame) { 292 std::unique_ptr<ChildFrame> child_frame) {
279 if (!child_frame.get() || !child_frame->frame.get()) 293 if (!child_frame.get() || !child_frame->frame.get())
280 return; 294 return;
281 295
282 cc::CompositorFrameAck frame_ack; 296 cc::CompositorFrameAck frame_ack;
283 cc::TransferableResource::ReturnResources( 297 cc::TransferableResource::ReturnResources(
284 child_frame->frame->delegated_frame_data->resource_list, 298 child_frame->frame->delegated_frame_data->resource_list,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 445 }
432 446
433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { 447 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) {
434 if (!compositor_) 448 if (!compositor_)
435 return; 449 return;
436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); 450 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll");
437 compositor_->OnComputeScroll(animation_time); 451 compositor_->OnComputeScroll(animation_time);
438 } 452 }
439 453
440 void BrowserViewRenderer::ReleaseHardware() { 454 void BrowserViewRenderer::ReleaseHardware() {
441 if (compositor_frame_consumer_) { 455 for (auto compositor_frame_consumer_ : compositor_frame_consumers_) {
442 ReturnUnusedResource( 456 if (compositor_frame_consumer_) {
boliu 2016/05/04 16:58:52 make sure null is never inserted instead of having
Tobias Sargeant 2016/05/05 18:36:56 Done.
443 compositor_frame_consumer_->PassUncommittedFrameOnUI()); 457 ReturnUnusedResource(
444 ReturnResourceFromParent(compositor_frame_consumer_); 458 compositor_frame_consumer_->PassUncommittedFrameOnUI());
445 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); 459 ReturnResourceFromParent(compositor_frame_consumer_);
460 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI());
461 }
446 } 462 }
447 hardware_enabled_ = false; 463 hardware_enabled_ = false;
448 UpdateMemoryPolicy(); 464 UpdateMemoryPolicy();
449 } 465 }
450 466
451 bool BrowserViewRenderer::IsVisible() const { 467 bool BrowserViewRenderer::IsVisible() const {
452 // Ignore |window_visible_| if |attached_to_window_| is false. 468 // Ignore |window_visible_| if |attached_to_window_| is false.
453 return view_visible_ && (!attached_to_window_ || window_visible_); 469 return view_visible_ && (!attached_to_window_ || window_visible_);
454 } 470 }
455 471
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 base::StringAppendF(&str, 736 base::StringAppendF(&str,
721 "overscroll_rounding_error_: %s ", 737 "overscroll_rounding_error_: %s ",
722 overscroll_rounding_error_.ToString().c_str()); 738 overscroll_rounding_error_.ToString().c_str());
723 base::StringAppendF( 739 base::StringAppendF(
724 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 740 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
725 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 741 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
726 return str; 742 return str;
727 } 743 }
728 744
729 } // namespace android_webview 745 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698