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

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

Issue 914103004: (NOT FOR COMMIT) Remove BVR cruft (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "android_webview/browser/browser_view_renderer_client.h" 7 #include "android_webview/browser/browser_view_renderer_client.h"
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 compositor_(NULL), 61 compositor_(NULL),
62 is_paused_(false), 62 is_paused_(false),
63 view_visible_(false), 63 view_visible_(false),
64 window_visible_(false), 64 window_visible_(false),
65 attached_to_window_(false), 65 attached_to_window_(false),
66 hardware_enabled_(false), 66 hardware_enabled_(false),
67 dip_scale_(0.0), 67 dip_scale_(0.0),
68 page_scale_factor_(1.0), 68 page_scale_factor_(1.0),
69 on_new_picture_enable_(false), 69 on_new_picture_enable_(false),
70 clear_view_(false), 70 clear_view_(false),
71 invalidate_after_composite_(false),
72 block_invalidates_(false), 71 block_invalidates_(false),
73 fallback_tick_pending_(false) { 72 fallback_tick_pending_(false) {
74 } 73 }
75 74
76 BrowserViewRenderer::~BrowserViewRenderer() { 75 BrowserViewRenderer::~BrowserViewRenderer() {
77 } 76 }
78 77
79 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() { 78 SharedRendererState* BrowserViewRenderer::GetAwDrawGLViewContext() {
80 return &shared_renderer_state_; 79 return &shared_renderer_state_;
81 } 80 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 if (!hardware_enabled_) { 169 if (!hardware_enabled_) {
171 TRACE_EVENT0("android_webview", "InitializeHwDraw"); 170 TRACE_EVENT0("android_webview", "InitializeHwDraw");
172 hardware_enabled_ = compositor_->InitializeHwDraw(); 171 hardware_enabled_ = compositor_->InitializeHwDraw();
173 } 172 }
174 if (!hardware_enabled_) { 173 if (!hardware_enabled_) {
175 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_HardwareNotEnabled", 174 TRACE_EVENT_INSTANT0("android_webview", "EarlyOut_HardwareNotEnabled",
176 TRACE_EVENT_SCOPE_THREAD); 175 TRACE_EVENT_SCOPE_THREAD);
177 return false; 176 return false;
178 } 177 }
179 178
180 if (last_on_draw_global_visible_rect_.IsEmpty() && 179 return CompositeHw();
181 parent_draw_constraints_.surface_rect.IsEmpty()) {
182 TRACE_EVENT_INSTANT0("android_webview",
183 "EarlyOut_EmptyVisibleRect",
184 TRACE_EVENT_SCOPE_THREAD);
185 shared_renderer_state_.SetForceInvalidateOnNextDrawGLOnUI(true);
186 return true;
187 }
188
189 ReturnResourceFromParent();
190 if (shared_renderer_state_.HasCompositorFrameOnUI()) {
191 TRACE_EVENT_INSTANT0("android_webview",
192 "EarlyOut_PreviousFrameUnconsumed",
193 TRACE_EVENT_SCOPE_THREAD);
194 DidSkipCompositeInDraw();
195 return true;
196 }
197
198 scoped_ptr<cc::CompositorFrame> frame = CompositeHw();
199 if (!frame.get()) {
200 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
201 TRACE_EVENT_SCOPE_THREAD);
202 return false;
203 }
204
205 shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass(), false);
206 return true;
207 } 180 }
208 181
209 scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() { 182 bool BrowserViewRenderer::CompositeHw() {
183 ReturnResourceFromParent();
184
210 compositor_->SetMemoryPolicy(CalculateDesiredMemoryPolicy()); 185 compositor_->SetMemoryPolicy(CalculateDesiredMemoryPolicy());
211 186
212 parent_draw_constraints_ = 187 parent_draw_constraints_ =
213 shared_renderer_state_.GetParentDrawConstraintsOnUI(); 188 shared_renderer_state_.GetParentDrawConstraintsOnUI();
214 gfx::Size surface_size(size_); 189 gfx::Size surface_size(size_);
215 gfx::Rect viewport(surface_size); 190 gfx::Rect viewport(surface_size);
216 gfx::Rect clip = viewport; 191 gfx::Rect clip = viewport;
217 gfx::Transform transform_for_tile_priority = 192 gfx::Transform transform_for_tile_priority =
218 parent_draw_constraints_.transform; 193 parent_draw_constraints_.transform;
219 194
220 // If the WebView is on a layer, WebView does not know what transform is 195 // If the WebView is on a layer, WebView does not know what transform is
221 // applied onto the layer so global visible rect does not make sense here. 196 // applied onto the layer so global visible rect does not make sense here.
222 // In this case, just use the surface rect for tiling. 197 // In this case, just use the surface rect for tiling.
223 gfx::Rect viewport_rect_for_tile_priority; 198 gfx::Rect viewport_rect_for_tile_priority;
224 if (parent_draw_constraints_.is_layer || 199 if (parent_draw_constraints_.is_layer) {
225 last_on_draw_global_visible_rect_.IsEmpty()) {
226 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect; 200 viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect;
227 } else { 201 } else {
228 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_; 202 viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
229 } 203 }
230 204
231 scoped_ptr<cc::CompositorFrame> frame = 205 scoped_ptr<cc::CompositorFrame> frame =
232 compositor_->DemandDrawHw(surface_size, 206 compositor_->DemandDrawHw(surface_size,
233 gfx::Transform(), 207 gfx::Transform(),
234 viewport, 208 viewport,
235 clip, 209 clip,
236 viewport_rect_for_tile_priority, 210 viewport_rect_for_tile_priority,
237 transform_for_tile_priority); 211 transform_for_tile_priority);
238 if (frame.get()) 212
239 DidComposite(); 213 if (!frame.get()) {
240 return frame.Pass(); 214 TRACE_EVENT_INSTANT0("android_webview", "NoNewFrame",
215 TRACE_EVENT_SCOPE_THREAD);
216 return false;
217 }
218
219 DidComposite();
220 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI());
221 shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass());
222 return true;
241 } 223 }
242 224
243 void BrowserViewRenderer::ForceCompositeHw() { 225 void BrowserViewRenderer::UpdateParentDrawConstraints() {
244 ReturnResourceFromParent(); 226 if (!parent_draw_constraints_.Equals(
245 ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); 227 shared_renderer_state_.GetParentDrawConstraintsOnUI())) {
246 scoped_ptr<cc::CompositorFrame> frame = CompositeHw(); 228 PostInvalidateWithFallback();
247 if (frame.get()) {
248 shared_renderer_state_.SetCompositorFrameOnUI(frame.Pass(), true);
249 } 229 }
250 } 230 }
251 231
252 void BrowserViewRenderer::UpdateParentDrawConstraints() {
253 // Post an invalidate if the parent draw constraints are stale and there is
254 // no pending invalidate.
255 bool needs_force_invalidate =
256 shared_renderer_state_.NeedsForceInvalidateOnNextDrawGLOnUI();
257 if (needs_force_invalidate ||
258 !parent_draw_constraints_.Equals(
259 shared_renderer_state_.GetParentDrawConstraintsOnUI())) {
260 shared_renderer_state_.SetForceInvalidateOnNextDrawGLOnUI(false);
261 PostInvalidateWithFallback(needs_force_invalidate);
262 }
263 }
264
265 void BrowserViewRenderer::ReturnUnusedResource( 232 void BrowserViewRenderer::ReturnUnusedResource(
266 scoped_ptr<cc::CompositorFrame> frame) { 233 scoped_ptr<cc::CompositorFrame> frame) {
267 if (!frame.get()) 234 if (!frame.get())
268 return; 235 return;
269 236
270 cc::CompositorFrameAck frame_ack; 237 cc::CompositorFrameAck frame_ack;
271 cc::TransferableResource::ReturnResources( 238 cc::TransferableResource::ReturnResources(
272 frame->delegated_frame_data->resource_list, &frame_ack.resources); 239 frame->delegated_frame_data->resource_list, &frame_ack.resources);
273 if (compositor_ && !frame_ack.resources.empty()) 240 if (compositor_ && !frame_ack.resources.empty())
274 compositor_->ReturnResources(frame_ack); 241 compositor_->ReturnResources(frame_ack);
275 } 242 }
276 243
277 void BrowserViewRenderer::ReturnResourceFromParent() { 244 void BrowserViewRenderer::ReturnResourceFromParent() {
278 cc::CompositorFrameAck frame_ack; 245 cc::CompositorFrameAck frame_ack;
279 shared_renderer_state_.SwapReturnedResourcesOnUI(&frame_ack.resources); 246 shared_renderer_state_.SwapReturnedResourcesOnUI(&frame_ack.resources);
280 if (compositor_ && !frame_ack.resources.empty()) { 247 if (compositor_ && !frame_ack.resources.empty()) {
281 compositor_->ReturnResources(frame_ack); 248 compositor_->ReturnResources(frame_ack);
282 } 249 }
283 } 250 }
284 251
285 void BrowserViewRenderer::DidSkipCommitFrame() {
286 // Treat it the same way as skipping onDraw.
287 DidSkipCompositeInDraw();
288 }
289
290 void BrowserViewRenderer::InvalidateOnFunctorDestroy() { 252 void BrowserViewRenderer::InvalidateOnFunctorDestroy() {
291 client_->InvalidateOnFunctorDestroy(); 253 client_->InvalidateOnFunctorDestroy();
292 } 254 }
293 255
294 bool BrowserViewRenderer::OnDrawSoftware(SkCanvas* canvas) { 256 bool BrowserViewRenderer::OnDrawSoftware(SkCanvas* canvas) {
295 return CanOnDraw() && CompositeSW(canvas); 257 return CanOnDraw() && CompositeSW(canvas);
296 } 258 }
297 259
298 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width, 260 skia::RefPtr<SkPicture> BrowserViewRenderer::CapturePicture(int width,
299 int height) { 261 int height) {
(...skipping 24 matching lines...) Expand all
324 286
325 void BrowserViewRenderer::ClearView() { 287 void BrowserViewRenderer::ClearView() {
326 TRACE_EVENT_INSTANT0("android_webview", 288 TRACE_EVENT_INSTANT0("android_webview",
327 "BrowserViewRenderer::ClearView", 289 "BrowserViewRenderer::ClearView",
328 TRACE_EVENT_SCOPE_THREAD); 290 TRACE_EVENT_SCOPE_THREAD);
329 if (clear_view_) 291 if (clear_view_)
330 return; 292 return;
331 293
332 clear_view_ = true; 294 clear_view_ = true;
333 // Always invalidate ignoring the compositor to actually clear the webview. 295 // Always invalidate ignoring the compositor to actually clear the webview.
334 PostInvalidateWithFallback(false); 296 PostInvalidateWithFallback();
335 } 297 }
336 298
337 void BrowserViewRenderer::SetIsPaused(bool paused) { 299 void BrowserViewRenderer::SetIsPaused(bool paused) {
338 TRACE_EVENT_INSTANT1("android_webview", 300 TRACE_EVENT_INSTANT1("android_webview",
339 "BrowserViewRenderer::SetIsPaused", 301 "BrowserViewRenderer::SetIsPaused",
340 TRACE_EVENT_SCOPE_THREAD, 302 TRACE_EVENT_SCOPE_THREAD,
341 "paused", 303 "paused",
342 paused); 304 paused);
343 is_paused_ = paused; 305 is_paused_ = paused;
344 UpdateCompositorIsActive(); 306 UpdateCompositorIsActive();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d( 558 gfx::Vector2d rounded_overscroll_delta = gfx::ToRoundedVector2d(
597 scaled_overscroll_delta + overscroll_rounding_error_); 559 scaled_overscroll_delta + overscroll_rounding_error_);
598 overscroll_rounding_error_ = 560 overscroll_rounding_error_ =
599 scaled_overscroll_delta - rounded_overscroll_delta; 561 scaled_overscroll_delta - rounded_overscroll_delta;
600 client_->DidOverscroll(rounded_overscroll_delta); 562 client_->DidOverscroll(rounded_overscroll_delta);
601 } 563 }
602 564
603 void BrowserViewRenderer::PostInvalidate() { 565 void BrowserViewRenderer::PostInvalidate() {
604 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", 566 TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate",
605 TRACE_EVENT_SCOPE_THREAD); 567 TRACE_EVENT_SCOPE_THREAD);
606 PostInvalidateWithFallback(false); 568 PostInvalidateWithFallback();
607 } 569 }
608 570
609 void BrowserViewRenderer::PostInvalidateWithFallback( 571 void BrowserViewRenderer::PostInvalidateWithFallback() {
610 bool skip_reschedule_tick) {
611 if (block_invalidates_) { 572 if (block_invalidates_) {
612 invalidate_after_composite_ = true;
613 return; 573 return;
614 } 574 }
615 575
616 // Always call view invalidate. We rely the Android framework to ignore the 576 // Always call view invalidate. We rely the Android framework to ignore the
617 // invalidate when it's not needed such as when view is not visible. 577 // invalidate when it's not needed such as when view is not visible.
618 client_->PostInvalidate(); 578 client_->PostInvalidate();
619 579
620 // Always clear any queued invalidates when posting a new one.
621 invalidate_after_composite_ = false;
622
623 // Stop fallback ticks when one of these is true. 580 // Stop fallback ticks when one of these is true.
624 // 1) Webview is paused. Also need to check we are not in clear view since 581 // 1) Webview is paused. Also need to check we are not in clear view since
625 // paused, offscreen still expect clear view to recover. 582 // paused, offscreen still expect clear view to recover.
626 // 2) If we are attached to window and the window is not visible (eg when 583 // 2) If we are attached to window and the window is not visible (eg when
627 // app is in the background). We are sure in this case the webview is used 584 // app is in the background). We are sure in this case the webview is used
628 // "on-screen" but that updates are not needed when in the background. 585 // "on-screen" but that updates are not needed when in the background.
629 bool throttle_fallback_tick = 586 bool throttle_fallback_tick =
630 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_); 587 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_);
631 588
632 if (throttle_fallback_tick) 589 if (throttle_fallback_tick)
633 return; 590 return;
634 591
635 // Start blocking any invalidates posted. Eventually DidComposite or 592 // Start blocking any invalidates posted. Eventually DidComposite or
636 // DidSkipCompositeInDraw will be called either via onDraw or the fallback 593 // DidSkipCompositeInDraw will be called either via onDraw or the fallback
637 // tick and invalidates will be unblocked. 594 // tick and invalidates will be unblocked.
638 block_invalidates_ = true; 595 block_invalidates_ = true;
639 596
640 if (skip_reschedule_tick && fallback_tick_pending_) 597 if (fallback_tick_pending_)
641 return; 598 return;
642 599
643 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick, 600 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick,
644 base::Unretained(this))); 601 base::Unretained(this)));
645 fallback_tick_fired_.Cancel(); 602 fallback_tick_fired_.Cancel();
646 603
647 fallback_tick_pending_ = true; 604 fallback_tick_pending_ = true;
648 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback()); 605 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback());
649 } 606 }
650 607
(...skipping 12 matching lines...) Expand all
663 } 620 }
664 621
665 void BrowserViewRenderer::FallbackTickFired() { 622 void BrowserViewRenderer::FallbackTickFired() {
666 TRACE_EVENT0("android_webview", "BrowserViewRenderer::FallbackTickFired"); 623 TRACE_EVENT0("android_webview", "BrowserViewRenderer::FallbackTickFired");
667 // This should only be called if OnDraw or DrawGL did not come in time, which 624 // This should only be called if OnDraw or DrawGL did not come in time, which
668 // means block_invalidates_ must still be true. 625 // means block_invalidates_ must still be true.
669 DCHECK(block_invalidates_); 626 DCHECK(block_invalidates_);
670 fallback_tick_pending_ = false; 627 fallback_tick_pending_ = false;
671 if (compositor_) { 628 if (compositor_) {
672 if (hardware_enabled_) { 629 if (hardware_enabled_) {
673 ForceCompositeHw(); 630 CompositeHw();
674 } else { 631 } else {
675 ForceFakeCompositeSW(); 632 ForceFakeCompositeSW();
676 } 633 }
677 } 634 }
678 // Pretend we just composited to unblock further invalidates. 635 // Pretend we just composited to unblock further invalidates.
679 DidComposite(); 636 DidComposite();
680 } 637 }
681 638
682 void BrowserViewRenderer::ForceFakeCompositeSW() { 639 void BrowserViewRenderer::ForceFakeCompositeSW() {
683 DCHECK(compositor_); 640 DCHECK(compositor_);
(...skipping 11 matching lines...) Expand all
695 DidComposite(); 652 DidComposite();
696 return result; 653 return result;
697 } 654 }
698 655
699 void BrowserViewRenderer::DidComposite() { 656 void BrowserViewRenderer::DidComposite() {
700 block_invalidates_ = false; 657 block_invalidates_ = false;
701 658
702 post_fallback_tick_.Cancel(); 659 post_fallback_tick_.Cancel();
703 fallback_tick_fired_.Cancel(); 660 fallback_tick_fired_.Cancel();
704 fallback_tick_pending_ = false; 661 fallback_tick_pending_ = false;
705
706 if (invalidate_after_composite_)
707 PostInvalidateWithFallback(false);
708 }
709
710 void BrowserViewRenderer::DidSkipCompositeInDraw() {
711 block_invalidates_ = false;
712 PostInvalidateWithFallback(true);
713 } 662 }
714 663
715 void BrowserViewRenderer::UpdateCompositorIsActive() { 664 void BrowserViewRenderer::UpdateCompositorIsActive() {
716 if (compositor_) 665 if (compositor_)
717 compositor_->SetIsActive(!is_paused_ && 666 compositor_->SetIsActive(!is_paused_ &&
718 (!attached_to_window_ || window_visible_)); 667 (!attached_to_window_ || window_visible_));
719 } 668 }
720 669
721 std::string BrowserViewRenderer::ToString() const { 670 std::string BrowserViewRenderer::ToString() const {
722 std::string str; 671 std::string str;
723 base::StringAppendF(&str, "is_paused: %d ", is_paused_); 672 base::StringAppendF(&str, "is_paused: %d ", is_paused_);
724 base::StringAppendF(&str, "view_visible: %d ", view_visible_); 673 base::StringAppendF(&str, "view_visible: %d ", view_visible_);
725 base::StringAppendF(&str, "window_visible: %d ", window_visible_); 674 base::StringAppendF(&str, "window_visible: %d ", window_visible_);
726 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); 675 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_);
727 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); 676 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_);
728 base::StringAppendF(&str, "invalidate_after_composite: %d ",
729 invalidate_after_composite_);
730 base::StringAppendF(&str, "block_invalidates: %d ", block_invalidates_); 677 base::StringAppendF(&str, "block_invalidates: %d ", block_invalidates_);
731 base::StringAppendF(&str, "fallback_tick_pending: %d ", 678 base::StringAppendF(&str, "fallback_tick_pending: %d ",
732 fallback_tick_pending_); 679 fallback_tick_pending_);
733 base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str()); 680 base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str());
734 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_); 681 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
735 base::StringAppendF(&str, 682 base::StringAppendF(&str,
736 "global visible rect: %s ", 683 "global visible rect: %s ",
737 last_on_draw_global_visible_rect_.ToString().c_str()); 684 last_on_draw_global_visible_rect_.ToString().c_str());
738 base::StringAppendF( 685 base::StringAppendF(
739 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str()); 686 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str());
740 base::StringAppendF(&str, 687 base::StringAppendF(&str,
741 "overscroll_rounding_error_: %s ", 688 "overscroll_rounding_error_: %s ",
742 overscroll_rounding_error_.ToString().c_str()); 689 overscroll_rounding_error_.ToString().c_str());
743 base::StringAppendF( 690 base::StringAppendF(
744 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 691 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
745 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 692 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
746 return str; 693 return str;
747 } 694 }
748 695
749 } // namespace android_webview 696 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/browser_view_renderer.h ('k') | android_webview/browser/hardware_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698