diff options
author | Chet Haase <chet@google.com> | 2011-04-21 11:52:59 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-04-21 11:52:59 -0700 |
commit | bf96c356c02c430153c281fb81dc1a00f7ad0b43 (patch) | |
tree | ae1ac4bbd2c2c28b1b498dc87d47564806155c3a /tests | |
parent | 52c03d2cb9a782366e804d1910a7c8f072b05353 (diff) | |
parent | 5b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82 (diff) | |
download | frameworks_base-bf96c356c02c430153c281fb81dc1a00f7ad0b43.zip frameworks_base-bf96c356c02c430153c281fb81dc1a00f7ad0b43.tar.gz frameworks_base-bf96c356c02c430153c281fb81dc1a00f7ad0b43.tar.bz2 |
Merge "Enable anti-aliasing for hw-accelerated lines"
Diffstat (limited to 'tests')
3 files changed, 159 insertions, 1 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 2afc935..c763b1d 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -388,6 +388,15 @@ </activity> <activity + android:name="Lines2Activity" + android:label="_Lines2"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="PathsActivity" android:label="_Paths"> <intent-filter> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java new file mode 100644 index 0000000..ccf0631 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2011 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.animation.ObjectAnimator; +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.View; +import android.widget.FrameLayout; + +@SuppressWarnings({"UnusedDeclaration"}) +public class Lines2Activity extends Activity { + private ObjectAnimator mAnimator; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000)); + FrameLayout frame = new FrameLayout(this); + final LinesView gpuView = new LinesView(this, 0, Color.GREEN); + frame.addView(gpuView); + final LinesView swView = new LinesView(this, 400, Color.RED); + swView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + frame.addView(swView); + final LinesView hwBothView = new LinesView(this, 850, Color.GREEN); + // BUG: some lines not drawn or drawn with alpha when enabling hw layers +// hwBothView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + frame.addView(hwBothView); + final LinesView swBothView = new LinesView(this, 854, Color.RED); + swBothView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + frame.addView(swBothView); + setContentView(frame); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } + + public static class LinesView extends View { + + private float mOffset; + private int mColor; + private float[] basePoints = { + 120, 0, 120, 20, 120, 20, 125, 0, 130, 0, 132, 10 + }; + private float[] copyPoints = new float[12]; + + public LinesView(Context c, float offset, int color) { + super(c); + mOffset = offset; + mColor = color; + } + + private void drawLines(Canvas canvas, Paint p, float xOffset, float yOffset) { + canvas.drawLine(10 + xOffset, yOffset, 10 + xOffset, 40 + yOffset, p); + canvas.drawLine(30 + xOffset, yOffset, 40 + xOffset, 40 + yOffset, p); + canvas.drawLine(40 + xOffset, yOffset, 75 + xOffset, 35 + yOffset, p); + canvas.drawLine(50 + xOffset, 5+ yOffset, 100 + xOffset, 15 + yOffset, p); + canvas.drawLine(60 + xOffset, yOffset, 110 + xOffset, 2 + yOffset, p); + canvas.drawLine(60 + xOffset, 40 + yOffset, 110 + xOffset, 40 + yOffset, p); + for (int i = 0; i < 12; i += 2) { + copyPoints[i] = basePoints[i] + xOffset; + copyPoints[i+1] = basePoints[i+1] + yOffset; + } + canvas.drawLines(copyPoints, 0, 12, p); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + Paint p = new Paint(); + p.setColor(mColor); + float yOffset = 10; + + canvas.save(); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + + yOffset +=100; + canvas.save(); + p.setStrokeWidth(1); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + + yOffset += 100; + canvas.save(); + p.setStrokeWidth(2); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + + p.setAntiAlias(true); + p.setStrokeWidth(0); + yOffset += 100; + canvas.save(); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + + yOffset += 100; + canvas.save(); + p.setStrokeWidth(1); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + + yOffset += 100; + canvas.save(); + p.setStrokeWidth(2); + drawLines(canvas, p, mOffset, yOffset); + canvas.scale(2, 2); + canvas.translate(60, 0); + drawLines(canvas, p, mOffset/2, yOffset/2); + canvas.restore(); + } + } +} diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java index 4233367..c3a91ce 100644 --- a/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/LinesActivity.java @@ -53,7 +53,7 @@ public class LinesActivity extends Activity { } public static class LinesView extends View { - private static final boolean LINE_AA = false; + private static final boolean LINE_AA = true; private final Bitmap mBitmap1; private final Paint mSmallPaint; |