Commit 9212bcc0 authored by boliu@chromium.org's avatar boliu@chromium.org

aw: Move clearView implementaiton to native

Also untangle clearView implementation from picture listener enabled.
Add some comments and removed some error logs.

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248595 0039d316-1c4b-4281-b951-d872f2087c98
parent 41329e4d
...@@ -124,6 +124,8 @@ class BrowserViewRenderer { ...@@ -124,6 +124,8 @@ class BrowserViewRenderer {
virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0; virtual skia::RefPtr<SkPicture> CapturePicture(int width, int height) = 0;
virtual void EnableOnNewPicture(bool enabled) = 0; virtual void EnableOnNewPicture(bool enabled) = 0;
virtual void ClearView() = 0;
// View update notifications. // View update notifications.
virtual void SetIsPaused(bool paused) = 0; virtual void SetIsPaused(bool paused) = 0;
virtual void SetViewVisibility(bool visible) = 0; virtual void SetViewVisibility(bool visible) = 0;
......
...@@ -229,6 +229,7 @@ InProcessViewRenderer::InProcessViewRenderer( ...@@ -229,6 +229,7 @@ InProcessViewRenderer::InProcessViewRenderer(
dip_scale_(0.0), dip_scale_(0.0),
page_scale_factor_(1.0), page_scale_factor_(1.0),
on_new_picture_enable_(false), on_new_picture_enable_(false),
clear_view_(false),
compositor_needs_continuous_invalidate_(false), compositor_needs_continuous_invalidate_(false),
block_invalidates_(false), block_invalidates_(false),
width_(0), width_(0),
...@@ -375,6 +376,8 @@ bool InProcessViewRenderer::OnDraw(jobject java_canvas, ...@@ -375,6 +376,8 @@ bool InProcessViewRenderer::OnDraw(jobject java_canvas,
const gfx::Vector2d& scroll, const gfx::Vector2d& scroll,
const gfx::Rect& clip) { const gfx::Rect& clip) {
scroll_at_start_of_frame_ = scroll; scroll_at_start_of_frame_ = scroll;
if (clear_view_)
return false;
if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) { if (is_hardware_canvas && attached_to_window_ && HardwareEnabled()) {
// We should be performing a hardware draw here. If we don't have the // We should be performing a hardware draw here. If we don't have the
// comositor yet or if RequestDrawGL fails, it means we failed this draw and // comositor yet or if RequestDrawGL fails, it means we failed this draw and
...@@ -627,6 +630,18 @@ void InProcessViewRenderer::EnableOnNewPicture(bool enabled) { ...@@ -627,6 +630,18 @@ void InProcessViewRenderer::EnableOnNewPicture(bool enabled) {
EnsureContinuousInvalidation(NULL, false); EnsureContinuousInvalidation(NULL, false);
} }
void InProcessViewRenderer::ClearView() {
TRACE_EVENT_INSTANT0("android_webview",
"InProcessViewRenderer::ClearView",
TRACE_EVENT_SCOPE_THREAD);
if (clear_view_)
return;
clear_view_ = true;
// Always invalidate ignoring the compositor to actually clear the webview.
EnsureContinuousInvalidation(NULL, true);
}
void InProcessViewRenderer::SetIsPaused(bool paused) { void InProcessViewRenderer::SetIsPaused(bool paused) {
TRACE_EVENT_INSTANT1("android_webview", TRACE_EVENT_INSTANT1("android_webview",
"InProcessViewRenderer::SetIsPaused", "InProcessViewRenderer::SetIsPaused",
...@@ -792,6 +807,11 @@ void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) { ...@@ -792,6 +807,11 @@ void InProcessViewRenderer::ScrollTo(gfx::Vector2d scroll_offset) {
} }
void InProcessViewRenderer::DidUpdateContent() { void InProcessViewRenderer::DidUpdateContent() {
TRACE_EVENT_INSTANT0("android_webview",
"InProcessViewRenderer::DidUpdateContent",
TRACE_EVENT_SCOPE_THREAD);
clear_view_ = false;
EnsureContinuousInvalidation(NULL, false);
if (on_new_picture_enable_) if (on_new_picture_enable_)
client_->OnNewPicture(); client_->OnNewPicture();
} }
...@@ -883,6 +903,8 @@ void InProcessViewRenderer::EnsureContinuousInvalidation( ...@@ -883,6 +903,8 @@ void InProcessViewRenderer::EnsureContinuousInvalidation(
if (!need_invalidate || block_invalidates_) if (!need_invalidate || block_invalidates_)
return; return;
// 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.
if (draw_info) { if (draw_info) {
draw_info->dirty_left = cached_global_visible_rect_.x(); draw_info->dirty_left = cached_global_visible_rect_.x();
draw_info->dirty_top = cached_global_visible_rect_.y(); draw_info->dirty_top = cached_global_visible_rect_.y();
...@@ -893,8 +915,14 @@ void InProcessViewRenderer::EnsureContinuousInvalidation( ...@@ -893,8 +915,14 @@ void InProcessViewRenderer::EnsureContinuousInvalidation(
client_->PostInvalidate(); client_->PostInvalidate();
} }
bool throttle_fallback_tick = (is_paused_ && !on_new_picture_enable_) || // Stop fallback ticks when one of these is true.
(attached_to_window_ && !window_visible_); // 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) if (throttle_fallback_tick)
return; return;
...@@ -977,6 +1005,7 @@ std::string InProcessViewRenderer::ToString(AwDrawGLInfo* draw_info) const { ...@@ -977,6 +1005,7 @@ std::string InProcessViewRenderer::ToString(AwDrawGLInfo* draw_info) const {
overscroll_rounding_error_.ToString().c_str()); overscroll_rounding_error_.ToString().c_str());
base::StringAppendF( base::StringAppendF(
&str, "on_new_picture_enable: %d ", on_new_picture_enable_); &str, "on_new_picture_enable: %d ", on_new_picture_enable_);
base::StringAppendF(&str, "clear_view: %d ", clear_view_);
if (draw_info) { if (draw_info) {
base::StringAppendF(&str, base::StringAppendF(&str,
"clip left top right bottom: [%d %d %d %d] ", "clip left top right bottom: [%d %d %d %d] ",
......
...@@ -61,6 +61,7 @@ class InProcessViewRenderer : public BrowserViewRenderer, ...@@ -61,6 +61,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
virtual skia::RefPtr<SkPicture> CapturePicture(int width, virtual skia::RefPtr<SkPicture> CapturePicture(int width,
int height) OVERRIDE; int height) OVERRIDE;
virtual void EnableOnNewPicture(bool enabled) OVERRIDE; virtual void EnableOnNewPicture(bool enabled) OVERRIDE;
virtual void ClearView() OVERRIDE;
virtual void SetIsPaused(bool paused) OVERRIDE; virtual void SetIsPaused(bool paused) OVERRIDE;
virtual void SetViewVisibility(bool visible) OVERRIDE; virtual void SetViewVisibility(bool visible) OVERRIDE;
virtual void SetWindowVisibility(bool visible) OVERRIDE; virtual void SetWindowVisibility(bool visible) OVERRIDE;
...@@ -137,6 +138,7 @@ class InProcessViewRenderer : public BrowserViewRenderer, ...@@ -137,6 +138,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
float dip_scale_; float dip_scale_;
float page_scale_factor_; float page_scale_factor_;
bool on_new_picture_enable_; bool on_new_picture_enable_;
bool clear_view_;
// When true, we should continuously invalidate and keep drawing, for example // When true, we should continuously invalidate and keep drawing, for example
// to drive animation. This value is set by the compositor and should always // to drive animation. This value is set by the compositor and should always
......
...@@ -182,9 +182,6 @@ public class AwContents { ...@@ -182,9 +182,6 @@ public class AwContents {
private boolean mContainerViewFocused; private boolean mContainerViewFocused;
private boolean mWindowFocused; private boolean mWindowFocused;
private boolean mClearViewActive;
private boolean mPictureListenerEnabled;
// These come from the compositor and are updated immediately (in contrast to the values in // These come from the compositor and are updated immediately (in contrast to the values in
// ContentViewCore, which are updated at end of every frame). // ContentViewCore, which are updated at end of every frame).
private float mPageScaleFactor = 1.0f; private float mPageScaleFactor = 1.0f;
...@@ -742,13 +739,12 @@ public class AwContents { ...@@ -742,13 +739,12 @@ public class AwContents {
mScrollOffsetManager.syncScrollOffsetFromOnDraw(); mScrollOffsetManager.syncScrollOffsetFromOnDraw();
canvas.getClipBounds(mClipBoundsTemporary); canvas.getClipBounds(mClipBoundsTemporary);
if (mClearViewActive) { if (!nativeOnDraw(mNativeAwContents, canvas, canvas.isHardwareAccelerated(),
canvas.drawColor(getEffectiveBackgroundColor());
} else if (!nativeOnDraw(mNativeAwContents, canvas, canvas.isHardwareAccelerated(),
mContainerView.getScrollX(), mContainerView.getScrollY(), mContainerView.getScrollX(), mContainerView.getScrollY(),
mClipBoundsTemporary.left, mClipBoundsTemporary.top, mClipBoundsTemporary.left, mClipBoundsTemporary.top,
mClipBoundsTemporary.right, mClipBoundsTemporary.bottom)) { mClipBoundsTemporary.right, mClipBoundsTemporary.bottom)) {
Log.w(TAG, "nativeOnDraw failed; clearing to background color."); // Can happen during initialization when compositor is not set up. Or when clearView
// is in effect. Just draw background color instead.
canvas.drawColor(getEffectiveBackgroundColor()); canvas.drawColor(getEffectiveBackgroundColor());
} }
...@@ -779,9 +775,8 @@ public class AwContents { ...@@ -779,9 +775,8 @@ public class AwContents {
} }
public void clearView() { public void clearView() {
mClearViewActive = true; if (mNativeAwContents == 0) return;
syncOnNewPictureStateToNative(); nativeClearView(mNativeAwContents);
mContainerView.invalidate();
} }
/** /**
...@@ -801,13 +796,7 @@ public class AwContents { ...@@ -801,13 +796,7 @@ public class AwContents {
} }
}; };
} }
mPictureListenerEnabled = enabled; nativeEnableOnNewPicture(mNativeAwContents, enabled);
syncOnNewPictureStateToNative();
}
private void syncOnNewPictureStateToNative() {
if (mNativeAwContents == 0) return;
nativeEnableOnNewPicture(mNativeAwContents, mPictureListenerEnabled || mClearViewActive);
} }
public void findAllAsync(String searchString) { public void findAllAsync(String searchString) {
...@@ -1835,13 +1824,6 @@ public class AwContents { ...@@ -1835,13 +1824,6 @@ public class AwContents {
@CalledByNative @CalledByNative
public void onNewPicture() { public void onNewPicture() {
// Clear up any results from a previous clearView call
if (mClearViewActive) {
mClearViewActive = false;
mContainerView.invalidate();
syncOnNewPictureStateToNative();
}
// Don't call capturePicture() here but instead defer it until the posted task runs within // Don't call capturePicture() here but instead defer it until the posted task runs within
// the callback helper, to avoid doubling back into the renderer compositor in the middle // the callback helper, to avoid doubling back into the renderer compositor in the middle
// of the notification it is sending up to here. // of the notification it is sending up to here.
...@@ -2066,6 +2048,7 @@ public class AwContents { ...@@ -2066,6 +2048,7 @@ public class AwContents {
private native int nativeGetAwDrawGLViewContext(long nativeAwContents); private native int nativeGetAwDrawGLViewContext(long nativeAwContents);
private native long nativeCapturePicture(long nativeAwContents, int width, int height); private native long nativeCapturePicture(long nativeAwContents, int width, int height);
private native void nativeEnableOnNewPicture(long nativeAwContents, boolean enabled); private native void nativeEnableOnNewPicture(long nativeAwContents, boolean enabled);
private native void nativeClearView(long nativeAwContents);
private native void nativeSetExtraHeadersForUrl(long nativeAwContents, private native void nativeSetExtraHeadersForUrl(long nativeAwContents,
String url, String extraHeaders); String url, String extraHeaders);
......
...@@ -983,6 +983,11 @@ void AwContents::EnableOnNewPicture(JNIEnv* env, ...@@ -983,6 +983,11 @@ void AwContents::EnableOnNewPicture(JNIEnv* env,
browser_view_renderer_->EnableOnNewPicture(enabled); browser_view_renderer_->EnableOnNewPicture(enabled);
} }
void AwContents::ClearView(JNIEnv* env, jobject obj) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
browser_view_renderer_->ClearView();
}
void AwContents::SetExtraHeadersForUrl(JNIEnv* env, jobject obj, void AwContents::SetExtraHeadersForUrl(JNIEnv* env, jobject obj,
jstring url, jstring jextra_headers) { jstring url, jstring jextra_headers) {
std::string extra_headers; std::string extra_headers;
......
...@@ -120,6 +120,7 @@ class AwContents : public FindHelper::Listener, ...@@ -120,6 +120,7 @@ class AwContents : public FindHelper::Listener,
jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj); jint GetAwDrawGLViewContext(JNIEnv* env, jobject obj);
jlong CapturePicture(JNIEnv* env, jobject obj, int width, int height); jlong CapturePicture(JNIEnv* env, jobject obj, int width, int height);
void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled); void EnableOnNewPicture(JNIEnv* env, jobject obj, jboolean enabled);
void ClearView(JNIEnv* env, jobject obj);
void SetExtraHeadersForUrl(JNIEnv* env, jobject obj, void SetExtraHeadersForUrl(JNIEnv* env, jobject obj,
jstring url, jstring extra_headers); jstring url, jstring extra_headers);
......
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