summaryrefslogtreecommitdiffstats
path: root/tests/HwAccelerationTest
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2013-01-15 18:51:42 -0800
committerRomain Guy <romainguy@google.com>2013-01-17 15:39:31 -0800
commit8ce00301a023eecaeb8891ce906f67b513ebb42a (patch)
tree3b14c80a49cbec537aad39aa4bb266cac41102f7 /tests/HwAccelerationTest
parent0f8d155363c361199a9d9aa5dcdbc4088990f893 (diff)
downloadframeworks_base-8ce00301a023eecaeb8891ce906f67b513ebb42a.zip
frameworks_base-8ce00301a023eecaeb8891ce906f67b513ebb42a.tar.gz
frameworks_base-8ce00301a023eecaeb8891ce906f67b513ebb42a.tar.bz2
Implement clipRect with a transform, clipRegion & clipPath
Bug #7146141 When non-rectangular clipping occurs in a layer the render buffer used as the stencil buffer is not cached. If this happens on a View's hardware layer the render buffer will live for as long as the layer is bound to the view. When a stencil buffer is required because of a call to Canvas.saveLayer() it will be allocated on every frame. A future change will address this problem. If "show GPU overdraw" is enabled, non-rectangular clips are not supported anymore and we fall back to rectangular clips instead. This is a limitation imposed by OpenGL ES that cannot be worked around at this time. This change also improves the Matrix4 implementation to easily detect when a rect remains a rect after transform. Change-Id: I0e69fb901792d38bc0c4ca1bf9fdb02d7db415b9
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r--tests/HwAccelerationTest/AndroidManifest.xml11
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegion2Activity.java86
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegionActivity.java63
3 files changed, 147 insertions, 13 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 7d2ba19..57ce1d6 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -148,7 +148,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-
+
+ <activity
+ android:name="ClipRegion2Activity"
+ android:label="_ClipRegion2">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
<activity
android:name="DisplayListLayersActivity"
android:label="__DisplayListLayers">
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegion2Activity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegion2Activity.java
new file mode 100644
index 0000000..066e35c
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegion2Activity.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.android.test.hwui;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Region;
+import android.os.Bundle;
+import android.widget.FrameLayout;
+import android.widget.TextView;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class ClipRegion2Activity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final RegionView group = new RegionView(this);
+
+ final TextView text = new TextView(this);
+ text.setText(buildText());
+ group.addView(text);
+
+ setContentView(group);
+ }
+
+ private static CharSequence buildText() {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < 10; i++) {
+ buffer.append(LOREM_IPSUM);
+ }
+ return buffer;
+ }
+
+ public static class RegionView extends FrameLayout {
+ private final Region mRegion = new Region();
+ private float mClipPosition = 0.0f;
+
+ public RegionView(Context c) {
+ super(c);
+ }
+
+ public float getClipPosition() {
+ return mClipPosition;
+ }
+
+ public void setClipPosition(float clipPosition) {
+ mClipPosition = clipPosition;
+ invalidate();
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+
+ canvas.save();
+
+ mRegion.setEmpty();
+ mRegion.op(0, 0, getWidth(), getHeight(),
+ Region.Op.REPLACE);
+ mRegion.op(getWidth() / 4, getHeight() / 4, 3 * getWidth() / 4, 3 * getHeight() / 4,
+ Region.Op.DIFFERENCE);
+
+ canvas.clipRegion(mRegion);
+ super.dispatchDraw(canvas);
+
+ canvas.restore();
+ }
+ }
+
+ private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sagittis molestie aliquam. Donec metus metus, laoreet nec sagittis vitae, ultricies sit amet eros. Suspendisse sed massa sit amet felis consectetur gravida. In vitae erat mi, in egestas nisl. Phasellus quis ipsum massa, at scelerisque arcu. Nam lectus est, pellentesque eget lacinia non, congue vitae augue. Aliquam erat volutpat. Pellentesque bibendum tincidunt viverra. Aliquam erat volutpat. Maecenas pretium vulputate placerat. Nulla varius elementum rutrum. Aenean mollis blandit imperdiet. Pellentesque interdum fringilla ligula.";
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegionActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegionActivity.java
index d5daa5f..3d3d709 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegionActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ClipRegionActivity.java
@@ -16,38 +16,77 @@
package com.android.test.hwui;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
-import android.graphics.Region;
+import android.graphics.Path;
import android.os.Bundle;
-import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.TextView;
@SuppressWarnings({"UnusedDeclaration"})
public class ClipRegionActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- final RegionView view = new RegionView(this);
- setContentView(view);
+
+ final RegionView group = new RegionView(this);
+
+ final TextView text = new TextView(this);
+ text.setText(buildText());
+ group.addView(text);
+
+ setContentView(group);
+
+ ObjectAnimator animator = ObjectAnimator.ofFloat(group, "clipPosition", 0.0f, 1.0f);
+ animator.setDuration(3000);
+ animator.setRepeatCount(ValueAnimator.INFINITE);
+ animator.setRepeatMode(ValueAnimator.REVERSE);
+ animator.start();
+ }
+
+ private static CharSequence buildText() {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < 10; i++) {
+ buffer.append(LOREM_IPSUM);
+ }
+ return buffer;
}
- public static class RegionView extends View {
+ public static class RegionView extends FrameLayout {
+ private final Path mClipPath = new Path();
+ private float mClipPosition = 0.0f;
+
public RegionView(Context c) {
super(c);
}
+ public float getClipPosition() {
+ return mClipPosition;
+ }
+
+ public void setClipPosition(float clipPosition) {
+ mClipPosition = clipPosition;
+ invalidate();
+ }
+
@Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
+ protected void dispatchDraw(Canvas canvas) {
canvas.save();
- canvas.clipRect(100.0f, 100.0f, getWidth() - 100.0f, getHeight() - 100.0f,
- Region.Op.DIFFERENCE);
- canvas.drawARGB(128, 255, 0, 0);
- canvas.restore();
- invalidate();
+ mClipPath.reset();
+ mClipPath.addCircle(mClipPosition * getWidth(), getHeight() / 2.0f,
+ getWidth() / 4.0f, Path.Direction.CW);
+
+ canvas.clipPath(mClipPath);
+ super.dispatchDraw(canvas);
+
+ canvas.restore();
}
}
+
+ private static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sagittis molestie aliquam. Donec metus metus, laoreet nec sagittis vitae, ultricies sit amet eros. Suspendisse sed massa sit amet felis consectetur gravida. In vitae erat mi, in egestas nisl. Phasellus quis ipsum massa, at scelerisque arcu. Nam lectus est, pellentesque eget lacinia non, congue vitae augue. Aliquam erat volutpat. Pellentesque bibendum tincidunt viverra. Aliquam erat volutpat. Maecenas pretium vulputate placerat. Nulla varius elementum rutrum. Aenean mollis blandit imperdiet. Pellentesque interdum fringilla ligula.";
}