Commit ca9bf2c9 authored by Vasiliy Telezhnikov's avatar Vasiliy Telezhnikov Committed by Commit Bot

aw: Add stencil test to WebView System Shell

This CL adds checkbox to animation tests inside WebView system shell
that enables external stencil by adding rounded corners clip path to
WebView.

Bug: 956709

Change-Id: Ia918bf2fa6af522bdda90d559eddf24c48172dbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2075970
Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745068}
parent f87822ab
...@@ -33,6 +33,7 @@ android_apk("system_webview_shell_apk") { ...@@ -33,6 +33,7 @@ android_apk("system_webview_shell_apk") {
"apk/src/org/chromium/webview_shell/WebViewPackageHelper.java", "apk/src/org/chromium/webview_shell/WebViewPackageHelper.java",
"apk/src/org/chromium/webview_shell/WebViewThreadTestActivity.java", "apk/src/org/chromium/webview_shell/WebViewThreadTestActivity.java",
"apk/src/org/chromium/webview_shell/WebViewTracingActivity.java", "apk/src/org/chromium/webview_shell/WebViewTracingActivity.java",
"apk/src/org/chromium/webview_shell/WebViewWithClipPath.java",
] ]
android_manifest = "apk/AndroidManifest.xml" android_manifest = "apk/AndroidManifest.xml"
target_sdk_version = 29 target_sdk_version = 29
......
...@@ -34,6 +34,12 @@ ...@@ -34,6 +34,12 @@
android:checked="false" android:checked="false"
android:text="@string/layer_button" /> android:text="@string/layer_button" />
</LinearLayout> </LinearLayout>
<CheckBox
android:id="@+id/use_stencil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/stencil_button" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
...@@ -56,7 +62,7 @@ ...@@ -56,7 +62,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1"> android:layout_weight="1">
<WebView <org.chromium.webview_shell.WebViewWithClipPath
android:id="@+id/webview" android:id="@+id/webview"
android:layout_width="300dp" android:layout_width="300dp"
android:layout_height="300dp" android:layout_height="300dp"
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<string name="layer_button">Layer</string> <string name="layer_button">Layer</string>
<string name="rotate_button">Rotate</string> <string name="rotate_button">Rotate</string>
<string name="scale_button">Scale</string> <string name="scale_button">Scale</string>
<string name="stencil_button">Rounded corner</string>
<string name="translate_button">Translate</string> <string name="translate_button">Translate</string>
<!-- activity_web_platform_tests strings --> <!-- activity_web_platform_tests strings -->
......
...@@ -9,7 +9,6 @@ import android.os.Bundle; ...@@ -9,7 +9,6 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.WindowManager; import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.SeekBar; import android.widget.SeekBar;
...@@ -66,7 +65,7 @@ public class WebViewAnimationTestActivity extends Activity { ...@@ -66,7 +65,7 @@ public class WebViewAnimationTestActivity extends Activity {
+ " </body>" + " </body>"
+ "</html>"; + "</html>";
private WebView mWebView; private WebViewWithClipPath mWebView;
private boolean mIsWindowHardwareAccelerated; private boolean mIsWindowHardwareAccelerated;
/** Called when the activity is first created. */ /** Called when the activity is first created. */
...@@ -74,7 +73,7 @@ public class WebViewAnimationTestActivity extends Activity { ...@@ -74,7 +73,7 @@ public class WebViewAnimationTestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview_animation_test); setContentView(R.layout.activity_webview_animation_test);
mWebView = (WebView) findViewById(R.id.webview); mWebView = (WebViewWithClipPath) findViewById(R.id.webview);
mIsWindowHardwareAccelerated = mIsWindowHardwareAccelerated =
(getWindow().getAttributes().flags (getWindow().getAttributes().flags
...@@ -115,10 +114,15 @@ public class WebViewAnimationTestActivity extends Activity { ...@@ -115,10 +114,15 @@ public class WebViewAnimationTestActivity extends Activity {
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) {}
}); });
CheckBox checkBox = ((CheckBox) findViewById(R.id.use_layer)); CheckBox layerCheckBox = ((CheckBox) findViewById(R.id.use_layer));
checkBox.setOnCheckedChangeListener( layerCheckBox.setOnCheckedChangeListener(
(CompoundButton arg0, boolean checked) -> { setWebViewLayer(checked); }); (CompoundButton arg0, boolean checked) -> { setWebViewLayer(checked); });
setWebViewLayer(checkBox.isChecked()); setWebViewLayer(layerCheckBox.isChecked());
CheckBox stencilCheckBox = ((CheckBox) findViewById(R.id.use_stencil));
stencilCheckBox.setOnCheckedChangeListener(
(CompoundButton arg0, boolean checked) -> { setUseExternalStencil(checked); });
setUseExternalStencil(stencilCheckBox.isChecked());
} }
private void runTranslate() { private void runTranslate() {
...@@ -154,4 +158,8 @@ public class WebViewAnimationTestActivity extends Activity { ...@@ -154,4 +158,8 @@ public class WebViewAnimationTestActivity extends Activity {
mWebView.setLayerType(View.LAYER_TYPE_NONE, null); mWebView.setLayerType(View.LAYER_TYPE_NONE, null);
} }
} }
private void setUseExternalStencil(boolean useStecil) {
mWebView.setEnableClipPath(useStecil);
}
} }
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.webview_shell;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.webkit.WebView;
/**
* WebView subclass that can add Clip to canvas inside onDraw to trigger External Stencil behaviour.
*/
public class WebViewWithClipPath extends WebView {
private Path mClipPath;
private boolean mShouldClip;
public WebViewWithClipPath(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setEnableClipPath(boolean shouldClip) {
this.mShouldClip = shouldClip;
invalidate();
}
@Override
protected void onSizeChanged(int newWidth, int newHeight, int oldWidth, int oldHeight) {
int radius = 150;
mClipPath = new Path();
mClipPath.addRoundRect(
new RectF(0, 0, newWidth, newHeight), radius, radius, Path.Direction.CW);
super.onSizeChanged(newWidth, newHeight, oldWidth, oldHeight);
}
@Override
protected void onDraw(Canvas canvas) {
if (mShouldClip && mClipPath != null) {
canvas.translate(getScrollX(), getScrollY());
canvas.clipPath(mClipPath);
canvas.translate(-getScrollX(), -getScrollY());
}
super.onDraw(canvas);
}
}
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