diff options
author | Nader Jawad <njawad@google.com> | 2020-09-24 21:35:03 -0700 |
---|---|---|
committer | Nader Jawad <njawad@google.com> | 2020-09-29 14:20:02 -0700 |
commit | 390d6e8586c276716b693be0594328e6debea5c7 (patch) | |
tree | d683df303b927623991320052af6a2bf0aabc6f5 /tests/HwAccelerationTest | |
parent | 3f9f18eaf18b9cd172df5a7504c59e1b20c76740 (diff) |
Added RenderEffect property on RenderNode
Introduced RenderEffect API to handle consuming
SkImageFilter parameters on RenderNode objects
in order to support blur.
Updated SilkFX demo to use RenderEffect
APIs on RenderNode instead of BlurShader
Bug: 168549524
Test: Added tests to RenderNode CTS test cases
Change-Id: I5005a322a6d75438dd104e6915630264406cf771
Diffstat (limited to 'tests/HwAccelerationTest')
3 files changed, 98 insertions, 18 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 05a59ef7fc72..9a2def935f5d 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -745,7 +745,7 @@ </activity> <activity android:name="BlurActivity" - android:label="Shaders/Blur" + android:label="RenderEffect/Blur" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN"/> diff --git a/tests/HwAccelerationTest/res/layout/image_filter_activity.xml b/tests/HwAccelerationTest/res/layout/image_filter_activity.xml new file mode 100644 index 000000000000..a0ee67ae0bef --- /dev/null +++ b/tests/HwAccelerationTest/res/layout/image_filter_activity.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2020 The Android Open Source Project + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center"> + + <ImageView + android:id="@+id/image_filter_test_view" + android:background="#FF0000" + android:layout_width="200dp" + android:layout_height="200dp" /> +</FrameLayout>
\ No newline at end of file diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/BlurActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/BlurActivity.java index 033fb0ec35d2..e4ca7881f796 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/BlurActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/BlurActivity.java @@ -18,11 +18,12 @@ package com.android.test.hwui; import android.app.Activity; import android.content.Context; -import android.graphics.BlurShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.LinearGradient; import android.graphics.Paint; +import android.graphics.RenderEffect; +import android.graphics.RenderNode; import android.graphics.Shader; import android.os.Bundle; import android.view.Gravity; @@ -51,16 +52,27 @@ public class BlurActivity extends Activity { } public static class BlurGradientView extends View { - private BlurShader mBlurShader = null; - private Paint mPaint; + private final float mBlurRadius = 25f; + private final Paint mPaint; + private final RenderNode mRenderNode; public BlurGradientView(Context c) { super(c); + mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); + mRenderNode = new RenderNode("BlurGradientView"); + mRenderNode.setRenderEffect( + RenderEffect.createBlurEffect( + mBlurRadius, + mBlurRadius, + null, + Shader.TileMode.DECAL + ) + ); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - if (changed || mBlurShader == null) { + if (changed) { LinearGradient gradient = new LinearGradient( 0f, 0f, @@ -70,41 +82,81 @@ public class BlurActivity extends Activity { Color.YELLOW, Shader.TileMode.CLAMP ); - mBlurShader = new BlurShader(30f, 40f, gradient); - mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mPaint.setShader(mBlurShader); + + mPaint.setShader(gradient); + + final int width = right - left; + final int height = bottom - top; + mRenderNode.setPosition(0, 0, width, height); + + Canvas canvas = mRenderNode.beginRecording(); + canvas.drawRect( + mBlurRadius * 2, + mBlurRadius * 2, + width - mBlurRadius * 2, + height - mBlurRadius * 2, + mPaint + ); + mRenderNode.endRecording(); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); + canvas.drawRenderNode(mRenderNode); } } public static class BlurView extends View { - private final BlurShader mBlurShader; private final Paint mPaint; + private final RenderNode mRenderNode; + private final float mBlurRadius = 20f; public BlurView(Context c) { super(c); - mBlurShader = new BlurShader(20f, 20f, null); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mPaint.setShader(mBlurShader); + mRenderNode = new RenderNode("blurNode"); + mRenderNode.setRenderEffect( + RenderEffect.createBlurEffect( + mBlurRadius, + mBlurRadius, + null, + Shader.TileMode.DECAL + ) + ); } @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (changed) { + int width = right - left; + int height = bottom - top; + mRenderNode.setPosition(0, 0, width, height); + Canvas canvas = mRenderNode.beginRecording(width, height); + mPaint.setColor(Color.BLUE); + + canvas.drawRect( + mBlurRadius * 2, + mBlurRadius * 2, + width - mBlurRadius * 2, + height - mBlurRadius * 2, + mPaint + ); - mPaint.setColor(Color.BLUE); - canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint); + mPaint.setColor(Color.RED); + canvas.drawCircle((right - left) / 2f, (bottom - top) / 2f, 50f, mPaint); + + mRenderNode.endRecording(); + } + } - mPaint.setColor(Color.RED); - canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, 50f, mPaint); + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + canvas.drawRenderNode(mRenderNode); } } } |