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

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

Issue 1377593003: Refactor BrowserViewRenderer to support page visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 "android_webview/browser/child_frame.h" 8 #include "android_webview/browser/child_frame.h"
9 #include "android_webview/common/aw_switches.h"
9 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
10 #include "base/command_line.h" 11 #include "base/command_line.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
15 #include "base/trace_event/trace_event_argument.h" 16 #include "base/trace_event/trace_event_argument.h"
16 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 window_visible_(false), 95 window_visible_(false),
95 attached_to_window_(false), 96 attached_to_window_(false),
96 hardware_enabled_(false), 97 hardware_enabled_(false),
97 dip_scale_(0.f), 98 dip_scale_(0.f),
98 page_scale_factor_(1.f), 99 page_scale_factor_(1.f),
99 min_page_scale_factor_(0.f), 100 min_page_scale_factor_(0.f),
100 max_page_scale_factor_(0.f), 101 max_page_scale_factor_(0.f),
101 on_new_picture_enable_(false), 102 on_new_picture_enable_(false),
102 clear_view_(false), 103 clear_view_(false),
103 offscreen_pre_raster_(false), 104 offscreen_pre_raster_(false),
104 fallback_tick_pending_(false) {} 105 fallback_tick_pending_(false),
106 disable_page_visibility_(
107 base::CommandLine::ForCurrentProcess()
boliu 2015/09/28 21:31:31 nit: Do the CommandLine check in AwContents, and p
108 ->HasSwitch(switches::kDisablePageVisibility)) {}
105 109
106 BrowserViewRenderer::~BrowserViewRenderer() { 110 BrowserViewRenderer::~BrowserViewRenderer() {
107 } 111 }
108 112
109 void BrowserViewRenderer::RegisterWithWebContents( 113 void BrowserViewRenderer::RegisterWithWebContents(
110 content::WebContents* web_contents) { 114 content::WebContents* web_contents) {
111 web_contents->SetUserData(kBrowserViewRendererUserDataKey, 115 web_contents->SetUserData(kBrowserViewRendererUserDataKey,
112 new BrowserViewRendererUserData(this)); 116 new BrowserViewRendererUserData(this));
113 } 117 }
114 118
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 437
434 if (compositor_) { 438 if (compositor_) {
435 compositor_->SetMemoryPolicy(0u); 439 compositor_->SetMemoryPolicy(0u);
436 } 440 }
437 441
438 hardware_enabled_ = false; 442 hardware_enabled_ = false;
439 } 443 }
440 444
441 bool BrowserViewRenderer::IsVisible() const { 445 bool BrowserViewRenderer::IsVisible() const {
442 // Ignore |window_visible_| if |attached_to_window_| is false. 446 // Ignore |window_visible_| if |attached_to_window_| is false.
447 if (disable_page_visibility_)
448 return !attached_to_window_ || window_visible_;
boliu 2015/09/28 21:31:31 This... makes zero sense. This is IsWindowVisible.
449
443 return view_visible_ && (!attached_to_window_ || window_visible_); 450 return view_visible_ && (!attached_to_window_ || window_visible_);
444 } 451 }
445 452
446 gfx::Rect BrowserViewRenderer::GetScreenRect() const { 453 gfx::Rect BrowserViewRenderer::GetScreenRect() const {
447 return gfx::Rect(client_->GetLocationOnScreen(), size_); 454 return gfx::Rect(client_->GetLocationOnScreen(), size_);
448 } 455 }
449 456
450 void BrowserViewRenderer::DidInitializeCompositor( 457 void BrowserViewRenderer::DidInitializeCompositor(
451 content::SynchronousCompositor* compositor) { 458 content::SynchronousCompositor* compositor) {
452 TRACE_EVENT0("android_webview", 459 TRACE_EVENT0("android_webview",
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // Always call view invalidate. We rely the Android framework to ignore the 650 // Always call view invalidate. We rely the Android framework to ignore the
644 // invalidate when it's not needed such as when view is not visible. 651 // invalidate when it's not needed such as when view is not visible.
645 client_->PostInvalidate(); 652 client_->PostInvalidate();
646 653
647 // Stop fallback ticks when one of these is true. 654 // Stop fallback ticks when one of these is true.
648 // 1) Webview is paused. Also need to check we are not in clear view since 655 // 1) Webview is paused. Also need to check we are not in clear view since
649 // paused, offscreen still expect clear view to recover. 656 // paused, offscreen still expect clear view to recover.
650 // 2) If we are attached to window and the window is not visible (eg when 657 // 2) If we are attached to window and the window is not visible (eg when
651 // app is in the background). We are sure in this case the webview is used 658 // app is in the background). We are sure in this case the webview is used
652 // "on-screen" but that updates are not needed when in the background. 659 // "on-screen" but that updates are not needed when in the background.
653 bool throttle_fallback_tick = 660 bool throttle_fallback_tick = (is_paused_ && !clear_view_) || !IsVisible();
boliu 2015/09/28 21:39:39 Not everything need to be refactor. This was check
654 (is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_);
655 661
656 if (throttle_fallback_tick || fallback_tick_pending_) 662 if (throttle_fallback_tick || fallback_tick_pending_)
657 return; 663 return;
658 664
659 DCHECK(post_fallback_tick_.IsCancelled()); 665 DCHECK(post_fallback_tick_.IsCancelled());
660 DCHECK(fallback_tick_fired_.IsCancelled()); 666 DCHECK(fallback_tick_fired_.IsCancelled());
661 667
662 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick, 668 post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick,
663 base::Unretained(this))); 669 base::Unretained(this)));
664 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback()); 670 ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 715
710 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { 716 bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
711 DCHECK(compositor_); 717 DCHECK(compositor_);
712 CancelFallbackTick(); 718 CancelFallbackTick();
713 ReturnResourceFromParent(); 719 ReturnResourceFromParent();
714 return compositor_->DemandDrawSw(canvas); 720 return compositor_->DemandDrawSw(canvas);
715 } 721 }
716 722
717 void BrowserViewRenderer::UpdateCompositorIsActive() { 723 void BrowserViewRenderer::UpdateCompositorIsActive() {
718 if (compositor_) 724 if (compositor_)
719 compositor_->SetIsActive(!is_paused_ && 725 compositor_->SetIsActive(!is_paused_ && IsVisible());
720 (!attached_to_window_ || window_visible_));
721 } 726 }
722 727
723 std::string BrowserViewRenderer::ToString() const { 728 std::string BrowserViewRenderer::ToString() const {
724 std::string str; 729 std::string str;
725 base::StringAppendF(&str, "is_paused: %d ", is_paused_); 730 base::StringAppendF(&str, "is_paused: %d ", is_paused_);
726 base::StringAppendF(&str, "view_visible: %d ", view_visible_); 731 base::StringAppendF(&str, "view_visible: %d ", view_visible_);
727 base::StringAppendF(&str, "window_visible: %d ", window_visible_); 732 base::StringAppendF(&str, "window_visible: %d ", window_visible_);
728 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); 733 base::StringAppendF(&str, "dip_scale: %f ", dip_scale_);
729 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); 734 base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_);
730 base::StringAppendF(&str, "fallback_tick_pending: %d ", 735 base::StringAppendF(&str, "fallback_tick_pending: %d ",
731 fallback_tick_pending_); 736 fallback_tick_pending_);
732 base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str()); 737 base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str());
733 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_); 738 base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
734 base::StringAppendF(&str, 739 base::StringAppendF(&str,
735 "global visible rect: %s ", 740 "global visible rect: %s ",
736 last_on_draw_global_visible_rect_.ToString().c_str()); 741 last_on_draw_global_visible_rect_.ToString().c_str());
737 base::StringAppendF( 742 base::StringAppendF(
738 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str()); 743 &str, "scroll_offset_dip: %s ", scroll_offset_dip_.ToString().c_str());
739 base::StringAppendF(&str, 744 base::StringAppendF(&str,
740 "overscroll_rounding_error_: %s ", 745 "overscroll_rounding_error_: %s ",
741 overscroll_rounding_error_.ToString().c_str()); 746 overscroll_rounding_error_.ToString().c_str());
742 base::StringAppendF( 747 base::StringAppendF(
743 &str, "on_new_picture_enable: %d ", on_new_picture_enable_); 748 &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
744 base::StringAppendF(&str, "clear_view: %d ", clear_view_); 749 base::StringAppendF(&str, "clear_view: %d ", clear_view_);
745 return str; 750 return str;
746 } 751 }
747 752
748 } // namespace android_webview 753 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/browser_view_renderer.h ('k') | android_webview/java/src/org/chromium/android_webview/AwContents.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698