Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 6b96a04

Browse files
boliuCommit bot
boliu
authored and
Commit bot
committed
aw: Ensure invalidation when pipeline is stalled
* If CommitFrame is skipped to to stall, ensure we invalidate. * Make sure force_invalidate does not get cancelled by a pending fallback tick. * Allow hardware initialization even when visible rect is empty, so fallback tick is always in the right mode. * Fix visible rect empty checks. BUG=425372 Review URL: https://codereview.chromium.org/654403006 Cr-Commit-Position: refs/heads/master@{#300566}
1 parent 05bc9c8 commit 6b96a04

File tree

8 files changed

+62
-17
lines changed

8 files changed

+62
-17
lines changed

android_webview/browser/browser_view_renderer.cc

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ BrowserViewRenderer::BrowserViewRenderer(
8585
on_new_picture_enable_(false),
8686
clear_view_(false),
8787
compositor_needs_continuous_invalidate_(false),
88+
invalidate_after_composite_(false),
8889
block_invalidates_(false),
8990
fallback_tick_pending_(false),
9091
width_(0),
@@ -211,13 +212,6 @@ bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) {
211212
return false;
212213

213214
shared_renderer_state_->SetScrollOffset(last_on_draw_scroll_offset_);
214-
if (last_on_draw_global_visible_rect_.IsEmpty()) {
215-
TRACE_EVENT_INSTANT0("android_webview",
216-
"EarlyOut_EmptyVisibleRect",
217-
TRACE_EVENT_SCOPE_THREAD);
218-
shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true);
219-
return client_->RequestDrawGL(java_canvas, false);
220-
}
221215

222216
if (!hardware_enabled_) {
223217
hardware_enabled_ = compositor_->InitializeHwDraw();
@@ -228,12 +222,21 @@ bool BrowserViewRenderer::OnDrawHardware(jobject java_canvas) {
228222
if (!hardware_enabled_)
229223
return false;
230224

225+
if (last_on_draw_global_visible_rect_.IsEmpty() &&
226+
parent_draw_constraints_.surface_rect.IsEmpty()) {
227+
TRACE_EVENT_INSTANT0("android_webview",
228+
"EarlyOut_EmptyVisibleRect",
229+
TRACE_EVENT_SCOPE_THREAD);
230+
shared_renderer_state_->SetForceInvalidateOnNextDrawGL(true);
231+
return client_->RequestDrawGL(java_canvas, false);
232+
}
233+
231234
ReturnResourceFromParent();
232235
if (shared_renderer_state_->HasCompositorFrame()) {
233236
TRACE_EVENT_INSTANT0("android_webview",
234237
"EarlyOut_PreviousFrameUnconsumed",
235238
TRACE_EVENT_SCOPE_THREAD);
236-
SkippedCompositeInDraw();
239+
DidSkipCompositeInDraw();
237240
return client_->RequestDrawGL(java_canvas, false);
238241
}
239242

@@ -262,10 +265,12 @@ scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() {
262265
// applied onto the layer so global visible rect does not make sense here.
263266
// In this case, just use the surface rect for tiling.
264267
gfx::Rect viewport_rect_for_tile_priority;
265-
if (parent_draw_constraints_.is_layer)
268+
if (parent_draw_constraints_.is_layer ||
269+
last_on_draw_global_visible_rect_.IsEmpty()) {
266270
viewport_rect_for_tile_priority = parent_draw_constraints_.surface_rect;
267-
else
271+
} else {
268272
viewport_rect_for_tile_priority = last_on_draw_global_visible_rect_;
273+
}
269274

270275
scoped_ptr<cc::CompositorFrame> frame =
271276
compositor_->DemandDrawHw(surface_size,
@@ -282,11 +287,13 @@ scoped_ptr<cc::CompositorFrame> BrowserViewRenderer::CompositeHw() {
282287
void BrowserViewRenderer::UpdateParentDrawConstraints() {
283288
// Post an invalidate if the parent draw constraints are stale and there is
284289
// no pending invalidate.
285-
if (shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL() ||
290+
bool needs_force_invalidate =
291+
shared_renderer_state_->NeedsForceInvalidateOnNextDrawGL();
292+
if (needs_force_invalidate ||
286293
!parent_draw_constraints_.Equals(
287-
shared_renderer_state_->ParentDrawConstraints())) {
294+
shared_renderer_state_->ParentDrawConstraints())) {
288295
shared_renderer_state_->SetForceInvalidateOnNextDrawGL(false);
289-
EnsureContinuousInvalidation(true, false);
296+
EnsureContinuousInvalidation(true, needs_force_invalidate);
290297
}
291298
}
292299

@@ -310,6 +317,11 @@ void BrowserViewRenderer::ReturnResourceFromParent() {
310317
}
311318
}
312319

320+
void BrowserViewRenderer::DidSkipCommitFrame() {
321+
// Treat it the same way as skipping onDraw.
322+
DidSkipCompositeInDraw();
323+
}
324+
313325
bool BrowserViewRenderer::OnDrawSoftware(jobject java_canvas) {
314326
if (!compositor_) {
315327
TRACE_EVENT_INSTANT0(
@@ -656,12 +668,18 @@ void BrowserViewRenderer::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
656668
void BrowserViewRenderer::EnsureContinuousInvalidation(
657669
bool force_invalidate,
658670
bool skip_reschedule_tick) {
671+
if (force_invalidate)
672+
invalidate_after_composite_ = true;
673+
659674
// This method should be called again when any of these conditions change.
660675
bool need_invalidate =
661-
compositor_needs_continuous_invalidate_ || force_invalidate;
676+
compositor_needs_continuous_invalidate_ || invalidate_after_composite_;
662677
if (!need_invalidate || block_invalidates_)
663678
return;
664679

680+
if (!compositor_needs_continuous_invalidate_ && invalidate_after_composite_)
681+
invalidate_after_composite_ = false;
682+
665683
// Always call view invalidate. We rely the Android framework to ignore the
666684
// invalidate when it's not needed such as when view is not visible.
667685
client_->PostInvalidate();
@@ -764,9 +782,9 @@ void BrowserViewRenderer::DidComposite() {
764782
EnsureContinuousInvalidation(false, false);
765783
}
766784

767-
void BrowserViewRenderer::SkippedCompositeInDraw() {
785+
void BrowserViewRenderer::DidSkipCompositeInDraw() {
768786
block_invalidates_ = false;
769-
EnsureContinuousInvalidation(false, true);
787+
EnsureContinuousInvalidation(true, true);
770788
}
771789

772790
std::string BrowserViewRenderer::ToString() const {

android_webview/browser/browser_view_renderer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
141141
bool effective_immediately) override;
142142

143143
void UpdateParentDrawConstraints();
144+
void DidSkipCommitFrame();
144145

145146
private:
146147
void SetTotalRootLayerScrollOffset(gfx::Vector2dF new_value_dip);
@@ -154,7 +155,7 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
154155
bool OnDrawSoftware(jobject java_canvas);
155156
bool CompositeSW(SkCanvas* canvas);
156157
void DidComposite();
157-
void SkippedCompositeInDraw();
158+
void DidSkipCompositeInDraw();
158159
scoped_refptr<base::debug::ConvertableToTraceFormat> RootLayerStateAsValue(
159160
const gfx::Vector2dF& total_scroll_offset_dip,
160161
const gfx::SizeF& scrollable_size_dip);
@@ -216,6 +217,8 @@ class BrowserViewRenderer : public content::SynchronousCompositorClient,
216217
// states.
217218
bool compositor_needs_continuous_invalidate_;
218219

220+
bool invalidate_after_composite_;
221+
219222
// Used to block additional invalidates while one is already pending.
220223
bool block_invalidates_;
221224

android_webview/browser/browser_view_renderer_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class BrowserViewRendererClient {
3131
// Called to update the parent draw constraints in browser view renderer.
3232
virtual void UpdateParentDrawConstraints() = 0;
3333

34+
// Called if commit is skipped due to pipeline stall.
35+
virtual void DidSkipCommitFrame() = 0;
36+
3437
// Called to get view's absolute location on the screen.
3538
virtual gfx::Point GetLocationOnScreen() = 0;
3639

android_webview/browser/hardware_renderer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void HardwareRenderer::CommitFrame() {
144144
TRACE_EVENT_INSTANT0("android_webview",
145145
"EarlyOut_PreviousFrameUnconsumed",
146146
TRACE_EVENT_SCOPE_THREAD);
147+
shared_renderer_state_->DidSkipCommitFrame();
147148
return;
148149
}
149150

android_webview/browser/shared_renderer_state.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ void SharedRendererState::PostExternalDrawConstraintsToChildCompositor(
186186
}
187187
}
188188

189+
void SharedRendererState::DidSkipCommitFrame() {
190+
ui_loop_->PostTask(
191+
FROM_HERE,
192+
base::Bind(&SharedRendererState::DidSkipCommitFrameOnUIThread,
193+
ui_thread_weak_ptr_));
194+
}
195+
196+
void SharedRendererState::DidSkipCommitFrameOnUIThread() {
197+
DCHECK(ui_loop_->BelongsToCurrentThread());
198+
client_on_ui_->DidSkipCommitFrame();
199+
}
200+
189201
const ParentCompositorDrawConstraints
190202
SharedRendererState::ParentDrawConstraints() const {
191203
base::AutoLock lock(lock_);

android_webview/browser/shared_renderer_state.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SharedRendererState {
4949
const ParentCompositorDrawConstraints& parent_draw_constraints);
5050
void PostExternalDrawConstraintsToChildCompositor(
5151
const ParentCompositorDrawConstraints& parent_draw_constraints);
52+
void DidSkipCommitFrame();
5253

5354
const ParentCompositorDrawConstraints ParentDrawConstraints() const;
5455

@@ -67,6 +68,7 @@ class SharedRendererState {
6768
void ResetRequestDrawGLCallback();
6869
void ClientRequestDrawGLOnUIThread();
6970
void UpdateParentDrawConstraintsOnUIThread();
71+
void DidSkipCommitFrameOnUIThread();
7072
void SetInsideHardwareRelease(bool inside);
7173

7274
scoped_refptr<base::MessageLoopProxy> ui_loop_;

android_webview/native/aw_contents.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ void AwContents::UpdateParentDrawConstraints() {
774774
browser_view_renderer_.UpdateParentDrawConstraints();
775775
}
776776

777+
void AwContents::DidSkipCommitFrame() {
778+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
779+
browser_view_renderer_.DidSkipCommitFrame();
780+
}
781+
777782
void AwContents::OnNewPicture() {
778783
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
779784
JNIEnv* env = AttachCurrentThread();

android_webview/native/aw_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class AwContents : public FindHelper::Listener,
192192
virtual bool RequestDrawGL(jobject canvas, bool wait_for_completion) override;
193193
virtual void PostInvalidate() override;
194194
virtual void UpdateParentDrawConstraints() override;
195+
virtual void DidSkipCommitFrame() override;
195196
virtual void OnNewPicture() override;
196197
virtual gfx::Point GetLocationOnScreen() override;
197198
virtual void ScrollContainerViewTo(gfx::Vector2d new_value) override;

0 commit comments

Comments
 (0)