Skip to content

Commit

Permalink
Make Android WebView filtering depend on scrolling status.
Browse files Browse the repository at this point in the history
This patch makes bilinear filtering of software images enabled only when
there is no scrolling or CSS animation active, which matches the
policy of classic WebView.  In the long run, we'll likely want to support
software tiling to avoid this kind of hack, but for now this maintains
bugwards compatibility.

Most of this patch is to solve the problem that CC was not aware whether
or not WebView-handled fling is active.  I added a new getter 
ScrollOffsetDelegate::IsExternalFlingActive for this.  This also
enables prefer-smoothness mode for these flings.

New test RendererPixelTest.PictureDrawQuadDisableImageFiltering

NOTRY=true
BUG= internal b/10706494

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227629 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aelias@chromium.org committed Oct 9, 2013
1 parent 77439eb commit 251699b
Show file tree
Hide file tree
Showing 34 changed files with 236 additions and 54 deletions.
3 changes: 3 additions & 0 deletions android_webview/browser/browser_view_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class BrowserViewRenderer {
// Set the view's scroll offset cap to |new_value|.
virtual void SetMaxContainerViewScrollOffset(gfx::Vector2d new_value) = 0;

// Is a WebView-managed fling in progress?
virtual bool IsFlingActive() const = 0;

// Set the current page scale to |page_scale_factor|.
virtual void SetPageScaleFactor(float page_scale_factor) = 0;

Expand Down
4 changes: 4 additions & 0 deletions android_webview/browser/in_process_view_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,10 @@ gfx::Vector2dF InProcessViewRenderer::GetTotalRootLayerScrollOffset() {
return scroll_offset_dip_;
}

bool InProcessViewRenderer::IsExternalFlingActive() const {
return client_->IsFlingActive();
}

void InProcessViewRenderer::SetRootLayerPageScaleFactor(
float page_scale_factor) {
page_scale_factor_ = page_scale_factor;
Expand Down
1 change: 1 addition & 0 deletions android_webview/browser/in_process_view_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
gfx::Vector2dF new_value_css) OVERRIDE;
virtual void DidUpdateContent() OVERRIDE;
virtual gfx::Vector2dF GetTotalRootLayerScrollOffset() OVERRIDE;
virtual bool IsExternalFlingActive() const OVERRIDE;
virtual void SetRootLayerPageScaleFactor(float page_scale_factor) OVERRIDE;
virtual void SetRootLayerScrollableSize(gfx::SizeF scrollable_size) OVERRIDE;
virtual void DidOverscroll(gfx::Vector2dF accumulated_overscroll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,11 @@ private void scrollContainerViewTo(int x, int y) {
mScrollOffsetManager.scrollContainerViewTo(x, y);
}

@CalledByNative
private boolean isFlingActive() {
return mScrollOffsetManager.isFlingActive();
}

@CalledByNative
private void setContentsSize(int widthDip, int heightDip) {
mContentWidthDip = widthDip;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void overScrollContainerViewBy(int deltaX, int deltaY, int scrollX, int scrollY,
// Whether we're in the middle of processing a touch event.
private boolean mProcessingTouchEvent;

private boolean mFlinging;

// Whether (and to what value) to update the native side scroll offset after we've finished
// processing a touch event.
private boolean mApplyDeferredNativeScroll;
Expand Down Expand Up @@ -156,6 +158,10 @@ public void scrollContainerViewTo(int x, int y) {
scrollRangeX, scrollRangeY, mProcessingTouchEvent);
}

public boolean isFlingActive() {
return mFlinging;
}

// Called by the native side to over-scroll the container view.
public void overScrollBy(int deltaX, int deltaY) {
// TODO(mkosiba): Once http://crbug.com/260663 and http://crbug.com/261239 are fixed it
Expand Down Expand Up @@ -269,13 +275,17 @@ public void flingScroll(int velocityX, int velocityY) {

mScroller.fling(scrollX, scrollY, velocityX, velocityY,
0, scrollRangeX, 0, scrollRangeY);
mFlinging = true;
mDelegate.invalidate();
}

// Called immediately before the draw to update the scroll offset.
public void computeScrollAndAbsorbGlow(OverScrollGlow overScrollGlow) {
final boolean stillAnimating = mScroller.computeScrollOffset();
if (!stillAnimating) return;
if (!stillAnimating) {
mFlinging = false;
return;
}

final int oldX = mDelegate.getContainerViewScrollX();
final int oldY = mDelegate.getContainerViewScrollY();
Expand Down
8 changes: 8 additions & 0 deletions android_webview/native/aw_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@ void AwContents::ScrollContainerViewTo(gfx::Vector2d new_value) {
env, obj.obj(), new_value.x(), new_value.y());
}

bool AwContents::IsFlingActive() const {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return false;
return Java_AwContents_isFlingActive(env, obj.obj());
}

void AwContents::SetPageScaleFactor(float page_scale_factor) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
Expand Down
1 change: 1 addition & 0 deletions android_webview/native/aw_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class AwContents : public FindHelper::Listener,
virtual void SetMaxContainerViewScrollOffset(
gfx::Vector2d new_value) OVERRIDE;
virtual void ScrollContainerViewTo(gfx::Vector2d new_value) OVERRIDE;
virtual bool IsFlingActive() const OVERRIDE;
virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE;
virtual void SetContentsSize(gfx::SizeF contents_size_dip) OVERRIDE;
virtual void DidOverscroll(gfx::Vector2d overscroll_delta) OVERRIDE;
Expand Down
4 changes: 4 additions & 0 deletions cc/input/layer_scroll_offset_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class LayerScrollOffsetDelegate {
// more than the value passed to the most recent SetMaxScrollOffset call.
virtual gfx::Vector2dF GetTotalScrollOffset() = 0;

// This is called by the compositor to check whether a delegate-managed fling
// is active or not.
virtual bool IsExternalFlingActive() const = 0;

// This is called by the compositor to notify the delegate what is the current
// page scale factor is.
virtual void SetPageScaleFactor(float page_scale_factor) = 0;
Expand Down
5 changes: 5 additions & 0 deletions cc/layers/layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,11 @@ void LayerImpl::SetScrollOffsetDelegate(
}
}

bool LayerImpl::IsExternalFlingActive() const {
return scroll_offset_delegate_ &&
scroll_offset_delegate_->IsExternalFlingActive();
}

void LayerImpl::SetScrollOffset(gfx::Vector2d scroll_offset) {
SetScrollOffsetAndDelta(scroll_offset, ScrollDelta());
}
Expand Down
2 changes: 2 additions & 0 deletions cc/layers/layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ class CC_EXPORT LayerImpl : LayerAnimationValueObserver {

void SetScrollOffsetDelegate(
LayerScrollOffsetDelegate* scroll_offset_delegate);
bool IsExternalFlingActive() const;

void SetScrollOffset(gfx::Vector2d scroll_offset);
void SetScrollOffsetAndDelta(gfx::Vector2d scroll_offset,
gfx::Vector2dF scroll_delta);
Expand Down
2 changes: 2 additions & 0 deletions cc/layers/layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ class ScrollDelegateIgnore : public LayerScrollOffsetDelegate {
virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE {
return fixed_offset_;
}
virtual bool IsExternalFlingActive() const OVERRIDE { return false; }

void set_fixed_offset(gfx::Vector2dF fixed_offset) {
fixed_offset_ = fixed_offset;
Expand Down Expand Up @@ -432,6 +433,7 @@ class ScrollDelegateAccept : public LayerScrollOffsetDelegate {
virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE {
return current_offset_;
}
virtual bool IsExternalFlingActive() const OVERRIDE { return false; }
virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE {}
virtual void SetScrollableSize(gfx::SizeF scrollable_size) OVERRIDE {}

Expand Down
3 changes: 2 additions & 1 deletion cc/output/delegating_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ static ResourceProvider::ResourceId AppendToArray(
void DelegatingRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
ContextProvider* offscreen_context_provider,
float device_scale_factor,
bool allow_partial_swap) {
bool allow_partial_swap,
bool disable_picture_quad_image_filtering) {
TRACE_EVENT0("cc", "DelegatingRenderer::DrawFrame");

DCHECK(!frame_for_swap_buffers_.delegated_frame_data);
Expand Down
3 changes: 2 additions & 1 deletion cc/output/delegating_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class CC_EXPORT DelegatingRenderer : public Renderer {
virtual void DrawFrame(RenderPassList* render_passes_in_draw_order,
ContextProvider* offscreen_context_provider,
float device_scale_factor,
bool allow_partial_swap) OVERRIDE;
bool allow_partial_swap,
bool disable_picture_quad_image_filtering) OVERRIDE;

virtual void Finish() OVERRIDE {}

Expand Down
5 changes: 4 additions & 1 deletion cc/output/direct_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ void DirectRenderer::DecideRenderPassAllocationsForFrame(
void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
ContextProvider* offscreen_context_provider,
float device_scale_factor,
bool allow_partial_swap) {
bool allow_partial_swap,
bool disable_picture_quad_image_filtering) {
TRACE_EVENT0("cc", "DirectRenderer::DrawFrame");
UMA_HISTOGRAM_COUNTS("Renderer4.renderPassCount",
render_passes_in_draw_order->size());
Expand All @@ -214,6 +215,8 @@ void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order,
: root_render_pass->output_rect;
frame.root_damage_rect.Intersect(gfx::Rect(client_->DeviceViewport().size()));
frame.offscreen_context_provider = offscreen_context_provider;
frame.disable_picture_quad_image_filtering =
disable_picture_quad_image_filtering;

EnsureBackbuffer();

Expand Down
5 changes: 4 additions & 1 deletion cc/output/direct_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class CC_EXPORT DirectRenderer : public Renderer {
virtual void DrawFrame(RenderPassList* render_passes_in_draw_order,
ContextProvider* offscreen_context_provider,
float device_scale_factor,
bool allow_partial_swap) OVERRIDE;
bool allow_partial_swap,
bool disable_picture_quad_image_filtering) OVERRIDE;

struct CC_EXPORT DrawingFrame {
DrawingFrame();
Expand All @@ -50,6 +51,8 @@ class CC_EXPORT DirectRenderer : public Renderer {
gfx::Transform window_matrix;

ContextProvider* offscreen_context_provider;

bool disable_picture_quad_image_filtering;
};

void SetEnlargePassTextureAmountForTesting(gfx::Vector2d amount);
Expand Down
Loading

0 comments on commit 251699b

Please sign in to comment.