Skip to content

Commit

Permalink
[Android WebView] Fix up invalidate path
Browse files Browse the repository at this point in the history
A bunch of changes mashed together:

1) Switch to calling View.postInvalidateOnAnimation in
AwContents. Update method names as well.
2) For invalidates at end of DrawGL, use AwDrawGLInfo::status_mask.
3) With above two combined, there is no reason to post a task to
call Invalidate anymore so remove that.

NOTRY=true
TBR=joth
BUG=243409

Review URL: https://chromiumcodereview.appspot.com/16655003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206638 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
boliu@chromium.org committed Jun 16, 2013
1 parent 722bf2b commit 6ccfa73
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion android_webview/browser/browser_view_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BrowserViewRenderer {
virtual void OnNewPicture() = 0;

// Called to trigger view invalidations.
virtual void Invalidate() = 0;
virtual void PostInvalidate() = 0;

// Called to get view's absolute location on the screen.
virtual gfx::Point GetLocationOnScreen() = 0;
Expand Down
41 changes: 23 additions & 18 deletions android_webview/browser/in_process_view_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,13 @@ InProcessViewRenderer::InProcessViewRenderer(
compositor_(NULL),
view_visible_(false),
continuous_invalidate_(false),
continuous_invalidate_task_pending_(false),
block_invalidates_(false),
width_(0),
height_(0),
attached_to_window_(false),
hardware_initialized_(false),
hardware_failed_(false),
egl_context_at_init_(NULL),
weak_factory_(this) {
egl_context_at_init_(NULL) {
CHECK(web_contents_);
web_contents_->SetUserData(kUserDataKey, new UserData(this));
content::SynchronousCompositor::SetClientForWebContents(web_contents_, this);
Expand Down Expand Up @@ -351,8 +350,10 @@ bool InProcessViewRenderer::OnDraw(jobject java_canvas,
return true;
}
// Perform a software draw
block_invalidates_ = true;
bool result = DrawSWInternal(java_canvas, clip);
EnsureContinuousInvalidation();
block_invalidates_ = false;
EnsureContinuousInvalidation(NULL);
return result;
}

Expand Down Expand Up @@ -393,20 +394,23 @@ void InProcessViewRenderer::DrawGL(AwDrawGLInfo* draw_info) {
if (!compositor_)
return;


gfx::Transform transform;
transform.matrix().setColMajorf(draw_info->transform);
transform.Translate(scroll_at_start_of_frame_.x(),
scroll_at_start_of_frame_.y());
// TODO(joth): Check return value.
block_invalidates_ = true;
compositor_->DemandDrawHw(
gfx::Size(draw_info->width, draw_info->height),
transform,
gfx::Rect(draw_info->clip_left,
draw_info->clip_top,
draw_info->clip_right - draw_info->clip_left,
draw_info->clip_bottom - draw_info->clip_top));
block_invalidates_ = false;

EnsureContinuousInvalidation();
EnsureContinuousInvalidation(draw_info);
}

bool InProcessViewRenderer::DrawSWInternal(jobject java_canvas,
Expand Down Expand Up @@ -594,7 +598,7 @@ void InProcessViewRenderer::SetContinuousInvalidate(bool invalidate) {

continuous_invalidate_ = invalidate;
// TODO(boliu): Handle if not attached to window case.
EnsureContinuousInvalidation();
EnsureContinuousInvalidation(NULL);
}

void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
Expand All @@ -607,18 +611,19 @@ gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() {
return scroll_offset_;
}

void InProcessViewRenderer::Invalidate() {
continuous_invalidate_task_pending_ = false;
if (continuous_invalidate_)
client_->Invalidate();
}

void InProcessViewRenderer::EnsureContinuousInvalidation() {
if (continuous_invalidate_ && !continuous_invalidate_task_pending_) {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&InProcessViewRenderer::Invalidate,
weak_factory_.GetWeakPtr()));
continuous_invalidate_task_pending_ = true;
void InProcessViewRenderer::EnsureContinuousInvalidation(
AwDrawGLInfo* draw_info) {
if (continuous_invalidate_ && !block_invalidates_) {
if (draw_info) {
draw_info->dirty_left = draw_info->clip_left;
draw_info->dirty_top = draw_info->clip_top;
draw_info->dirty_right = draw_info->clip_right;
draw_info->dirty_bottom = draw_info->clip_bottom;
draw_info->status_mask |= AwDrawGLInfo::kStatusMaskDraw;
} else {
client_->PostInvalidate();
}
block_invalidates_ = true;
}
}

Expand Down
11 changes: 5 additions & 6 deletions android_webview/browser/in_process_view_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
void WebContentsGone();

private:
void Invalidate();
void EnsureContinuousInvalidation();
void EnsureContinuousInvalidation(AwDrawGLInfo* draw_info);
bool DrawSWInternal(jobject java_canvas,
const gfx::Rect& clip_bounds);
bool RenderSW(SkCanvas* canvas);
Expand All @@ -79,8 +78,10 @@ class InProcessViewRenderer : public BrowserViewRenderer,
// When true, we should continuously invalidate and keep drawing, for example
// to drive animation.
bool continuous_invalidate_;
// True while an asynchronous invalidation task is pending.
bool continuous_invalidate_task_pending_;
// Used to block additional invalidates while one is already pending or before
// compositor draw which may switch continuous_invalidate on and off in the
// process.
bool block_invalidates_;

int width_;
int height_;
Expand All @@ -98,8 +99,6 @@ class InProcessViewRenderer : public BrowserViewRenderer,

gfx::Vector2dF scroll_offset_;

base::WeakPtrFactory<InProcessViewRenderer> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(InProcessViewRenderer);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,9 +1359,16 @@ private boolean requestDrawGL(Canvas canvas) {
return mInternalAccessAdapter.requestDrawGL(canvas);
}

private static final boolean SUPPORTS_ON_ANIMATION =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;

@CalledByNative
private void invalidate() {
mContainerView.invalidate();
private void postInvalidateOnAnimation() {
if (SUPPORTS_ON_ANIMATION) {
mContainerView.postInvalidateOnAnimation();
} else {
mContainerView.postInvalidate();
}
}

@CalledByNative
Expand Down
4 changes: 2 additions & 2 deletions android_webview/native/aw_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,11 @@ bool AwContents::RequestDrawGL(jobject canvas) {
return Java_AwContents_requestDrawGL(env, obj.obj(), canvas);
}

void AwContents::Invalidate() {
void AwContents::PostInvalidate() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (!obj.is_null())
Java_AwContents_invalidate(env, obj.obj());
Java_AwContents_postInvalidateOnAnimation(env, obj.obj());
}

void AwContents::OnNewPicture() {
Expand Down
2 changes: 1 addition & 1 deletion android_webview/native/aw_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class AwContents : public FindHelper::Listener,

// BrowserViewRenderer::Client implementation.
virtual bool RequestDrawGL(jobject canvas) OVERRIDE;
virtual void Invalidate() OVERRIDE;
virtual void PostInvalidate() OVERRIDE;
virtual void OnNewPicture() OVERRIDE;
virtual gfx::Point GetLocationOnScreen() OVERRIDE;

Expand Down

0 comments on commit 6ccfa73

Please sign in to comment.