Commit 30da41a6 authored by tobiasjs's avatar tobiasjs Committed by Commit bot

Revert of Remove fallback tick software draw. (patchset #3 id:100001 of...

Revert of Remove fallback tick software draw. (patchset #3 id:100001 of https://codereview.chromium.org/1428263003/ )

Reason for revert:
Causes scheduler to stop activating after clearView is called. PrepareTiles is required to advance the scheduler, so draws are currently needed.

crbug.com/558743

Original issue's description:
> Remove fallback tick software draw.
>
> The fallback software draw was needed to allow the scheduler to advance
> in cases where the WebView is detached or offscreen. Because it is now
> possible for the pending tree to activate without a draw, the fallback
> tick is no longer needed in order for VisualStateListener callbacks
> to fire.
>
> BUG=431166
>
> Committed: https://crrev.com/9addff46d3bc49f8d04e43eeb3f55e01a4982a00
> Cr-Commit-Position: refs/heads/master@{#358156}

TBR=boliu@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=431166

Review URL: https://codereview.chromium.org/1474653002

Cr-Commit-Position: refs/heads/master@{#361334}
parent f7ead8f5
...@@ -30,6 +30,8 @@ namespace { ...@@ -30,6 +30,8 @@ namespace {
const double kEpsilon = 1e-8; const double kEpsilon = 1e-8;
const int64 kFallbackTickTimeoutInMilliseconds = 100;
// Used to calculate memory allocation. Determined experimentally. // Used to calculate memory allocation. Determined experimentally.
const size_t kMemoryMultiplier = 20; const size_t kMemoryMultiplier = 20;
const size_t kBytesPerPixel = 4; const size_t kBytesPerPixel = 4;
...@@ -101,7 +103,8 @@ BrowserViewRenderer::BrowserViewRenderer( ...@@ -101,7 +103,8 @@ BrowserViewRenderer::BrowserViewRenderer(
max_page_scale_factor_(0.f), max_page_scale_factor_(0.f),
on_new_picture_enable_(false), on_new_picture_enable_(false),
clear_view_(false), clear_view_(false),
offscreen_pre_raster_(false) {} offscreen_pre_raster_(false),
fallback_tick_pending_(false) {}
BrowserViewRenderer::~BrowserViewRenderer() { BrowserViewRenderer::~BrowserViewRenderer() {
} }
...@@ -222,6 +225,12 @@ bool BrowserViewRenderer::OnDrawHardware() { ...@@ -222,6 +225,12 @@ bool BrowserViewRenderer::OnDrawHardware() {
shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_); shared_renderer_state_.SetScrollOffsetOnUI(last_on_draw_scroll_offset_);
hardware_enabled_ = true; hardware_enabled_ = true;
return CompositeHw();
}
bool BrowserViewRenderer::CompositeHw() {
CancelFallbackTick();
ReturnResourceFromParent(); ReturnResourceFromParent();
UpdateMemoryPolicy(); UpdateMemoryPolicy();
...@@ -261,16 +270,14 @@ bool BrowserViewRenderer::OnDrawHardware() { ...@@ -261,16 +270,14 @@ bool BrowserViewRenderer::OnDrawHardware() {
transform_for_tile_priority, offscreen_pre_raster_, transform_for_tile_priority, offscreen_pre_raster_,
parent_draw_constraints.is_layer)); parent_draw_constraints.is_layer));
// If we haven't received a kModeSync functor call since the last // Uncommitted frame can happen with consecutive fallback ticks.
// CompositeHw then we need to discard the resources that are being
// held onto by the previously prepared frame.
ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI()); ReturnUnusedResource(shared_renderer_state_.PassUncommittedFrameOnUI());
shared_renderer_state_.SetCompositorFrameOnUI(child_frame.Pass()); shared_renderer_state_.SetCompositorFrameOnUI(child_frame.Pass());
return true; return true;
} }
void BrowserViewRenderer::UpdateParentDrawConstraints() { void BrowserViewRenderer::UpdateParentDrawConstraints() {
PostInvalidate(); PostInvalidateWithFallback();
ParentCompositorDrawConstraints parent_draw_constraints = ParentCompositorDrawConstraints parent_draw_constraints =
shared_renderer_state_.GetParentDrawConstraintsOnUI(); shared_renderer_state_.GetParentDrawConstraintsOnUI();
client_->ParentDrawConstraintsUpdated(parent_draw_constraints); client_->ParentDrawConstraintsUpdated(parent_draw_constraints);
...@@ -344,7 +351,7 @@ void BrowserViewRenderer::ClearView() { ...@@ -344,7 +351,7 @@ void BrowserViewRenderer::ClearView() {
clear_view_ = true; clear_view_ = true;
// Always invalidate ignoring the compositor to actually clear the webview. // Always invalidate ignoring the compositor to actually clear the webview.
PostInvalidate(); PostInvalidateWithFallback();
} }
void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) { void BrowserViewRenderer::SetOffscreenPreRaster(bool enable) {
...@@ -642,11 +649,80 @@ void BrowserViewRenderer::DidOverscroll( ...@@ -642,11 +649,80 @@ void BrowserViewRenderer::DidOverscroll(
void BrowserViewRenderer::PostInvalidate() { void BrowserViewRenderer::PostInvalidate() {
TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate", TRACE_EVENT_INSTANT0("android_webview", "BrowserViewRenderer::PostInvalidate",
TRACE_EVENT_SCOPE_THREAD); TRACE_EVENT_SCOPE_THREAD);
PostInvalidateWithFallback();
}
void BrowserViewRenderer::PostInvalidateWithFallback() {
// Always call view invalidate. We rely the Android framework to ignore the
// invalidate when it's not needed such as when view is not visible.
client_->PostInvalidate(); client_->PostInvalidate();
// Stop fallback ticks when one of these is true.
// 1) Webview is paused. Also need to check we are not in clear view since
// paused, offscreen still expect clear view to recover.
// 2) If we are attached to window and the window is not visible (eg when
// app is in the background). We are sure in this case the webview is used
// "on-screen" but that updates are not needed when in the background.
bool throttle_fallback_tick =
(is_paused_ && !clear_view_) || (attached_to_window_ && !window_visible_);
if (throttle_fallback_tick || fallback_tick_pending_)
return;
DCHECK(post_fallback_tick_.IsCancelled());
DCHECK(fallback_tick_fired_.IsCancelled());
post_fallback_tick_.Reset(base::Bind(&BrowserViewRenderer::PostFallbackTick,
base::Unretained(this)));
ui_task_runner_->PostTask(FROM_HERE, post_fallback_tick_.callback());
fallback_tick_pending_ = true;
}
void BrowserViewRenderer::CancelFallbackTick() {
post_fallback_tick_.Cancel();
fallback_tick_fired_.Cancel();
fallback_tick_pending_ = false;
}
void BrowserViewRenderer::PostFallbackTick() {
DCHECK(fallback_tick_fired_.IsCancelled());
TRACE_EVENT0("android_webview", "BrowserViewRenderer::PostFallbackTick");
post_fallback_tick_.Cancel();
fallback_tick_fired_.Reset(base::Bind(&BrowserViewRenderer::FallbackTickFired,
base::Unretained(this)));
ui_task_runner_->PostDelayedTask(
FROM_HERE, fallback_tick_fired_.callback(),
base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
}
void BrowserViewRenderer::FallbackTickFired() {
TRACE_EVENT0("android_webview", "BrowserViewRenderer::FallbackTickFired");
// This should only be called if OnDraw or DrawGL did not come in time, which
// means fallback_tick_pending_ must still be true.
DCHECK(fallback_tick_pending_);
fallback_tick_fired_.Cancel();
fallback_tick_pending_ = false;
if (compositor_) {
if (hardware_enabled_ && !size_.IsEmpty()) {
CompositeHw();
} else {
ForceFakeCompositeSW();
}
}
}
void BrowserViewRenderer::ForceFakeCompositeSW() {
DCHECK(compositor_);
SkBitmap bitmap;
bitmap.allocN32Pixels(1, 1);
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
CompositeSW(&canvas);
} }
bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) { bool BrowserViewRenderer::CompositeSW(SkCanvas* canvas) {
DCHECK(compositor_); DCHECK(compositor_);
CancelFallbackTick();
ReturnResourceFromParent(); ReturnResourceFromParent();
return compositor_->DemandDrawSw(canvas); return compositor_->DemandDrawSw(canvas);
} }
...@@ -668,6 +744,8 @@ std::string BrowserViewRenderer::ToString() const { ...@@ -668,6 +744,8 @@ std::string BrowserViewRenderer::ToString() const {
base::StringAppendF(&str, "window_visible: %d ", window_visible_); base::StringAppendF(&str, "window_visible: %d ", window_visible_);
base::StringAppendF(&str, "dip_scale: %f ", dip_scale_); base::StringAppendF(&str, "dip_scale: %f ", dip_scale_);
base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_); base::StringAppendF(&str, "page_scale_factor: %f ", page_scale_factor_);
base::StringAppendF(&str, "fallback_tick_pending: %d ",
fallback_tick_pending_);
base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str()); base::StringAppendF(&str, "view size: %s ", size_.ToString().c_str());
base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_); base::StringAppendF(&str, "attached_to_window: %d ", attached_to_window_);
base::StringAppendF(&str, base::StringAppendF(&str,
......
...@@ -120,12 +120,18 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient { ...@@ -120,12 +120,18 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient {
private: private:
void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip); void SetTotalRootLayerScrollOffset(const gfx::Vector2dF& new_value_dip);
bool CanOnDraw(); bool CanOnDraw();
// Posts an invalidate with fallback tick. All invalidates posted while an
// invalidate is pending will be posted as a single invalidate after the
// pending invalidate is done.
void PostInvalidateWithFallback();
void CancelFallbackTick();
void UpdateCompositorIsActive(); void UpdateCompositorIsActive();
bool CompositeSW(SkCanvas* canvas); bool CompositeSW(SkCanvas* canvas);
scoped_refptr<base::trace_event::ConvertableToTraceFormat> scoped_refptr<base::trace_event::ConvertableToTraceFormat>
RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip, RootLayerStateAsValue(const gfx::Vector2dF& total_scroll_offset_dip,
const gfx::SizeF& scrollable_size_dip); const gfx::SizeF& scrollable_size_dip);
bool CompositeHw();
void ReturnUnusedResource(scoped_ptr<ChildFrame> frame); void ReturnUnusedResource(scoped_ptr<ChildFrame> frame);
void ReturnResourceFromParent(); void ReturnResourceFromParent();
...@@ -136,6 +142,11 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient { ...@@ -136,6 +142,11 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient {
void PostFallbackTick(); void PostFallbackTick();
void FallbackTickFired(); void FallbackTickFired();
// Force invoke the compositor to run produce a 1x1 software frame that is
// immediately discarded. This is a hack to force invoke parts of the
// compositor that are not directly exposed here.
void ForceFakeCompositeSW();
gfx::Vector2d max_scroll_offset() const; gfx::Vector2d max_scroll_offset() const;
void UpdateMemoryPolicy(); void UpdateMemoryPolicy();
...@@ -168,6 +179,10 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient { ...@@ -168,6 +179,10 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient {
gfx::Vector2d last_on_draw_scroll_offset_; gfx::Vector2d last_on_draw_scroll_offset_;
gfx::Rect last_on_draw_global_visible_rect_; gfx::Rect last_on_draw_global_visible_rect_;
base::CancelableClosure post_fallback_tick_;
base::CancelableClosure fallback_tick_fired_;
bool fallback_tick_pending_;
gfx::Size size_; gfx::Size size_;
gfx::SizeF scrollable_size_dip_; gfx::SizeF scrollable_size_dip_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment