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

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: PS7 comments 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 SetCurrentCompositorFrameConsumer(nullptr);
114 } 114 while (compositor_frame_consumers_.size()) {
115 115 RemoveCompositorFrameConsumer(*compositor_frame_consumers_.begin());
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 } 116 }
132 } 117 }
133 118
119 void BrowserViewRenderer::SetCurrentCompositorFrameConsumer(
120 CompositorFrameConsumer* compositor_frame_consumer) {
121 if (compositor_frame_consumer == current_compositor_frame_consumer_) {
122 return;
123 }
124 current_compositor_frame_consumer_ = compositor_frame_consumer;
125 if (current_compositor_frame_consumer_) {
126 compositor_frame_consumers_.insert(current_compositor_frame_consumer_);
127 current_compositor_frame_consumer_->SetCompositorFrameProducer(this);
128 OnParentDrawConstraintsUpdated(current_compositor_frame_consumer_);
129 }
130 }
131
134 void BrowserViewRenderer::RegisterWithWebContents( 132 void BrowserViewRenderer::RegisterWithWebContents(
135 content::WebContents* web_contents) { 133 content::WebContents* web_contents) {
136 web_contents->SetUserData(kBrowserViewRendererUserDataKey, 134 web_contents->SetUserData(kBrowserViewRendererUserDataKey,
137 new BrowserViewRendererUserData(this)); 135 new BrowserViewRendererUserData(this));
138 } 136 }
139 137
140 void BrowserViewRenderer::TrimMemory() { 138 void BrowserViewRenderer::TrimMemory() {
141 DCHECK(ui_task_runner_->BelongsToCurrentThread()); 139 DCHECK(ui_task_runner_->BelongsToCurrentThread());
142 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory"); 140 TRACE_EVENT0("android_webview", "BrowserViewRenderer::TrimMemory");
143 // Just set the memory limit to 0 and drop all tiles. This will be reset to 141 // 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_) { 191 if (clear_view_) {
194 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView", 192 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_ClearView",
195 TRACE_EVENT_SCOPE_THREAD); 193 TRACE_EVENT_SCOPE_THREAD);
196 return false; 194 return false;
197 } 195 }
198 196
199 return true; 197 return true;
200 } 198 }
201 199
202 bool BrowserViewRenderer::OnDrawHardware() { 200 bool BrowserViewRenderer::OnDrawHardware() {
203 DCHECK(compositor_frame_consumer_); 201 DCHECK(current_compositor_frame_consumer_);
204 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware"); 202 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnDrawHardware");
205 203
206 compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI(); 204 current_compositor_frame_consumer_->InitializeHardwareDrawIfNeededOnUI();
207 205
208 if (!CanOnDraw()) { 206 if (!CanOnDraw()) {
209 return false; 207 return false;
210 } 208 }
211 209
212 compositor_frame_consumer_->SetScrollOffsetOnUI(last_on_draw_scroll_offset_); 210 current_compositor_frame_consumer_->SetScrollOffsetOnUI(
211 last_on_draw_scroll_offset_);
213 hardware_enabled_ = true; 212 hardware_enabled_ = true;
214 213
215 external_draw_constraints_ = 214 external_draw_constraints_ =
216 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 215 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
217 216
218 ReturnResourceFromParent(compositor_frame_consumer_); 217 ReturnResourceFromParent(current_compositor_frame_consumer_);
219 UpdateMemoryPolicy(); 218 UpdateMemoryPolicy();
220 219
221 gfx::Size surface_size(size_); 220 gfx::Size surface_size(size_);
222 gfx::Rect viewport(surface_size); 221 gfx::Rect viewport(surface_size);
223 gfx::Rect clip = viewport; 222 gfx::Rect clip = viewport;
224 gfx::Transform transform_for_tile_priority = 223 gfx::Transform transform_for_tile_priority =
225 external_draw_constraints_.transform; 224 external_draw_constraints_.transform;
226 225
227 // If the WebView is on a layer, WebView does not know what transform is 226 // 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. 227 // applied onto the layer so global visible rect does not make sense here.
229 // In this case, just use the surface rect for tiling. 228 // In this case, just use the surface rect for tiling.
230 gfx::Rect viewport_rect_for_tile_priority; 229 gfx::Rect viewport_rect_for_tile_priority;
231 230
232 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on. 231 // Leave viewport_rect_for_tile_priority empty if offscreen_pre_raster_ is on.
233 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) { 232 if (!offscreen_pre_raster_ && !external_draw_constraints_.is_layer) {
234 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 233 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
235 } 234 }
236 235
237 content::SynchronousCompositor::Frame frame = 236 content::SynchronousCompositor::Frame frame =
238 compositor_->DemandDrawHw(surface_size, 237 compositor_->DemandDrawHw(surface_size,
239 gfx::Transform(), 238 gfx::Transform(),
240 viewport, 239 viewport,
241 clip, 240 clip,
242 viewport_rect_for_tile_priority, 241 viewport_rect_for_tile_priority,
243 transform_for_tile_priority); 242 transform_for_tile_priority);
244 if (!frame.frame.get()) { 243 if (!frame.frame.get()) {
245 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame", 244 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
246 TRACE_EVENT_SCOPE_THREAD); 245 TRACE_EVENT_SCOPE_THREAD);
247 hardware_enabled_ = compositor_frame_consumer_->HasFrameOnUI(); 246 hardware_enabled_ = current_compositor_frame_consumer_->HasFrameOnUI();
248 if (!hardware_enabled_) 247 if (!hardware_enabled_)
249 UpdateMemoryPolicy(); 248 UpdateMemoryPolicy();
250 return hardware_enabled_; 249 return hardware_enabled_;
251 } 250 }
252 251
253 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame( 252 std::unique_ptr<ChildFrame> child_frame = base::WrapUnique(new ChildFrame(
254 frame.output_surface_id, std::move(frame.frame), 253 frame.output_surface_id, std::move(frame.frame),
255 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(), 254 GetCompositorID(compositor_), viewport_rect_for_tile_priority.IsEmpty(),
256 transform_for_tile_priority, offscreen_pre_raster_, 255 transform_for_tile_priority, offscreen_pre_raster_,
257 external_draw_constraints_.is_layer)); 256 external_draw_constraints_.is_layer));
258 257
259 ReturnUnusedResource(compositor_frame_consumer_->PassUncommittedFrameOnUI()); 258 ReturnUnusedResource(
260 compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame)); 259 current_compositor_frame_consumer_->PassUncommittedFrameOnUI());
260 current_compositor_frame_consumer_->SetFrameOnUI(std::move(child_frame));
261 return true; 261 return true;
262 } 262 }
263 263
264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated() { 264 void BrowserViewRenderer::OnParentDrawConstraintsUpdated(
265 DCHECK(compositor_frame_consumer_); 265 CompositorFrameConsumer* compositor_frame_consumer) {
266 DCHECK(compositor_frame_consumer);
267 if (compositor_frame_consumer != current_compositor_frame_consumer_)
268 return;
266 PostInvalidate(); 269 PostInvalidate();
267 external_draw_constraints_ = 270 external_draw_constraints_ =
268 compositor_frame_consumer_->GetParentDrawConstraintsOnUI(); 271 current_compositor_frame_consumer_->GetParentDrawConstraintsOnUI();
269 UpdateMemoryPolicy(); 272 UpdateMemoryPolicy();
270 } 273 }
271 274
272 void BrowserViewRenderer::OnCompositorFrameConsumerWillDestroy() { 275 void BrowserViewRenderer::RemoveCompositorFrameConsumer(
273 DCHECK(compositor_frame_consumer_); 276 CompositorFrameConsumer* compositor_frame_consumer) {
274 SetCompositorFrameConsumer(nullptr); 277 DCHECK(compositor_frame_consumers_.count(compositor_frame_consumer));
278 DCHECK(current_compositor_frame_consumer_ != compositor_frame_consumer);
boliu 2016/05/05 21:40:32 Err, yeah, my comment was not about adding this DC
Tobias Sargeant 2016/05/06 12:41:09 In answer to your question, AwContents::SetAwGLFun
boliu 2016/05/06 15:53:13 This belongs to a comment somewhere, that BVR::Cur
279 compositor_frame_consumers_.erase(compositor_frame_consumer);
280
281 // At this point the compositor frame consumer has to hand back all resources
282 // to the child compositor.
283 compositor_frame_consumer->DeleteHardwareRendererOnUI();
284 ReturnUnusedResource(compositor_frame_consumer->PassUncommittedFrameOnUI());
285 ReturnResourceFromParent(compositor_frame_consumer);
286 compositor_frame_consumer->SetCompositorFrameProducer(nullptr);
275 } 287 }
276 288
277 void BrowserViewRenderer::ReturnUnusedResource( 289 void BrowserViewRenderer::ReturnUnusedResource(
278 std::unique_ptr<ChildFrame> child_frame) { 290 std::unique_ptr<ChildFrame> child_frame) {
279 if (!child_frame.get() || !child_frame->frame.get()) 291 if (!child_frame.get() || !child_frame->frame.get())
280 return; 292 return;
281 293
282 cc::CompositorFrameAck frame_ack; 294 cc::CompositorFrameAck frame_ack;
283 cc::TransferableResource::ReturnResources( 295 cc::TransferableResource::ReturnResources(
284 child_frame->frame->delegated_frame_data->resource_list, 296 child_frame->frame->delegated_frame_data->resource_list,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 443 }
432 444
433 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) { 445 void BrowserViewRenderer::OnComputeScroll(base::TimeTicks animation_time) {
434 if (!compositor_) 446 if (!compositor_)
435 return; 447 return;
436 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll"); 448 TRACE_EVENT0("android_webview", "BrowserViewRenderer::OnComputeScroll");
437 compositor_->OnComputeScroll(animation_time); 449 compositor_->OnComputeScroll(animation_time);
438 } 450 }
439 451
440 void BrowserViewRenderer::ReleaseHardware() { 452 void BrowserViewRenderer::ReleaseHardware() {
441 if (compositor_frame_consumer_) { 453 for (auto compositor_frame_consumer_ : compositor_frame_consumers_) {
442 ReturnUnusedResource( 454 ReturnUnusedResource(
443 compositor_frame_consumer_->PassUncommittedFrameOnUI()); 455 compositor_frame_consumer_->PassUncommittedFrameOnUI());
444 ReturnResourceFromParent(compositor_frame_consumer_); 456 ReturnResourceFromParent(compositor_frame_consumer_);
445 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI()); 457 DCHECK(compositor_frame_consumer_->ReturnedResourcesEmptyOnUI());
446 } 458 }
447 hardware_enabled_ = false; 459 hardware_enabled_ = false;
448 UpdateMemoryPolicy(); 460 UpdateMemoryPolicy();
449 } 461 }
450 462
451 bool BrowserViewRenderer::IsVisible() const { 463 bool BrowserViewRenderer::IsVisible() const {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 base::StringAppendF(&str, 732 base::StringAppendF(&str,
721 "overscroll_rounding_error_: %s ", 733 "overscroll_rounding_error_: %s ",
722 overscroll_rounding_error_.ToString().c_str()); 734 overscroll_rounding_error_.ToString().c_str());
723 base::StringAppendF( 735 base::StringAppendF(
724 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 736 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
725 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 737 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
726 return str; 738 return str;
727 } 739 }
728 740
729 } // namespace android_webview 741 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698