summaryrefslogtreecommitdiffstats
path: root/tests/HwAccelerationTest
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-12-21 01:33:04 -0800
committerXavier Ducrohet <xav@android.com>2010-12-21 10:43:18 -0800
commit63fd87113cea6abec97a6cd966e090e9b590fc3b (patch)
tree1cbdd623cdac465fc3a648b4afc93b4212a213f7 /tests/HwAccelerationTest
parentd348b6eaa98e23cb38d90906df109aaa2d20ea7f (diff)
downloadframeworks_base-63fd87113cea6abec97a6cd966e090e9b590fc3b.zip
frameworks_base-63fd87113cea6abec97a6cd966e090e9b590fc3b.tar.gz
frameworks_base-63fd87113cea6abec97a6cd966e090e9b590fc3b.tar.bz2
LayoutLib: Misc rendering fixes.
- always set up the stroke. Paint may not have the proper style when drawing lines. stroke should still be setup. - Fixed vertical linear gradient. Old code generated a gradient ratio of NaN - Fixed alpha rendering when using shaders. In that case the alpha channel from the paint color should be used in conjunction with the shader. - Fixed miter limit. Java expects the value to be multiplied by the stroke width - Fixed support for drawing ALPHA_8 bitmaps. Java2D doesn't have bitmaps with only alpha channels, so we keep using ARGB bitmaps but when drawing them into a bitmap we erase the color information. Change-Id: I4f04341fc843e3f7dadd1fdbf709b11a4f1e24b9
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r--tests/HwAccelerationTest/res/layout/_lines.xml6
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java16
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ShadersActivity.java27
3 files changed, 29 insertions, 20 deletions
diff --git a/tests/HwAccelerationTest/res/layout/_lines.xml b/tests/HwAccelerationTest/res/layout/_lines.xml
new file mode 100644
index 0000000..00f2556
--- /dev/null
+++ b/tests/HwAccelerationTest/res/layout/_lines.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.android.test.hwui.LinesActivity.LinesView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+</com.android.test.hwui.LinesActivity.LinesView>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java
index 6afbb01..91e3b84 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java
@@ -35,7 +35,7 @@ public class LinesActivity extends Activity {
setContentView(view);
}
- static class LinesView extends View {
+ public static class LinesView extends View {
private static final boolean LINE_AA = false;
private final Bitmap mBitmap1;
@@ -47,7 +47,7 @@ public class LinesActivity extends Activity {
private final Paint mAlphaPaint;
private final Paint mHairLinePaint;
- LinesView(Context c) {
+ public LinesView(Context c) {
super(c);
mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
@@ -71,7 +71,7 @@ public class LinesActivity extends Activity {
mAlphaPaint.setAntiAlias(LINE_AA);
mAlphaPaint.setColor(0x7fff0050);
mAlphaPaint.setStrokeWidth(10.0f);
-
+
mHairLinePaint = new Paint();
mHairLinePaint.setAntiAlias(LINE_AA);
mHairLinePaint.setColor(0xff0000ff);
@@ -99,11 +99,11 @@ public class LinesActivity extends Activity {
canvas.drawLine(0.0f, 0.0f, 40.0f, 400.0f, mSmallPaint);
canvas.drawLine(5.0f, 0.0f, 95.0f, 400.0f, mMediumPaint);
canvas.drawLine(22.0f, 0.0f, 162.0f, 400.0f, mLargePaint);
-
+
mLargePaint.setShader(mShader);
canvas.drawLine(42.0f, 0.0f, 222.0f, 400.0f, mLargePaint);
mLargePaint.setShader(null);
-
+
canvas.drawLines(mPoints, mAlphaPaint);
mSmallPaint.setAntiAlias(false);
@@ -111,14 +111,14 @@ public class LinesActivity extends Activity {
mSmallPaint.setAntiAlias(LINE_AA);
canvas.drawLine(0.0f, 0.0f, 0.0f, 400.0f, mSmallPaint);
canvas.drawLine(0.0f, 400.0f, 400.0f, 400.0f, mSmallPaint);
-
+
canvas.translate(120.0f, 0.0f);
- mAlphaPaint.setShader(mShader);
+ mAlphaPaint.setShader(mShader);
canvas.drawLines(mPoints, mAlphaPaint);
mAlphaPaint.setShader(null);
canvas.restore();
-
+
canvas.scale(10.0f, 10.0f);
canvas.drawLine(50.0f, 40.0f, 10.0f, 40.0f, mSmallPaint);
canvas.drawLine(10.0f, 50.0f, 50.0f, 50.0f, mSmallPaint);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ShadersActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ShadersActivity.java
index f89e184..1d18f61 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ShadersActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ShadersActivity.java
@@ -52,6 +52,9 @@ public class ShadersActivity extends Activity {
private LinearGradient mDiagGradient;
private LinearGradient mVertGradient;
private Bitmap mTexture;
+ private Matrix mMtx1;
+ private Matrix mMtx2;
+ private Matrix mMtx3;
public ShadersView(Context c) {
super(c);
@@ -67,24 +70,24 @@ public class ShadersActivity extends Activity {
mTranslatedShader = new BitmapShader(mTexture, Shader.TileMode.REPEAT,
Shader.TileMode.REPEAT);
- Matrix m1 = new Matrix();
- m1.setTranslate(mTexWidth / 2.0f, mTexHeight / 2.0f);
- m1.postRotate(45, 0, 0);
- mTranslatedShader.setLocalMatrix(m1);
+ mMtx1 = new Matrix();
+ mMtx1.setTranslate(mTexWidth / 2.0f, mTexHeight / 2.0f);
+ mMtx1.postRotate(45, 0, 0);
+ mTranslatedShader.setLocalMatrix(mMtx1);
mScaledShader = new BitmapShader(mTexture, Shader.TileMode.MIRROR,
Shader.TileMode.MIRROR);
- Matrix m2 = new Matrix();
- m2.setScale(0.5f, 0.5f);
- mScaledShader.setLocalMatrix(m2);
+ mMtx2 = new Matrix();
+ mMtx2.setScale(0.5f, 0.5f);
+ mScaledShader.setLocalMatrix(mMtx2);
mHorGradient = new LinearGradient(0.0f, 0.0f, 1.0f, 0.0f,
Color.RED, Color.GREEN, Shader.TileMode.CLAMP);
- Matrix m3 = new Matrix();
- m3.setScale(mDrawHeight, 1.0f);
- m3.postRotate(-90.0f);
- m3.postTranslate(0.0f, mDrawHeight);
- mHorGradient.setLocalMatrix(m3);
+ mMtx3 = new Matrix();
+ mMtx3.setScale(mDrawHeight, 1.0f);
+ mMtx3.postRotate(-90.0f);
+ mMtx3.postTranslate(0.0f, mDrawHeight);
+ mHorGradient.setLocalMatrix(mMtx3);
mDiagGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth / 1.5f, mDrawHeight,
Color.BLUE, Color.MAGENTA, Shader.TileMode.CLAMP);