Fix various hw-accelerated line/point bugs
All accelerated lines are now rendered as quads. Hairlines used to
be rendered as GL_LINES, but these lines don't render the same as our
non-accelerated lines, so we're using quads for everything. Also, fixed
a bug in the way that we were offsetting quads (and not offseting points)
to ensure that our lines/points actuall start on the same pixels as
Skia's.
Change-Id: I51b923cc08a9858444c430ba07bc8aa0c83cbe6a
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index c763b1d..31b2ddd 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -406,6 +406,15 @@
</activity>
<activity
+ android:name="PointsActivity"
+ android:label="_Points">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity
android:name="Transform3dActivity"
android:label="_3d">
<intent-filter>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java
index ccf0631..55fab3f 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/Lines2Activity.java
@@ -42,8 +42,9 @@
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);
+ // Don't actually need to render to a hw layer, but it's a good sanity-check that
+ // we're rendering to/from layers correctly
+ 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);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PointsActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PointsActivity.java
new file mode 100644
index 0000000..b3fb7a1
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PointsActivity.java
@@ -0,0 +1,128 @@
+/*
+ * 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;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.SeekBar;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class PointsActivity extends Activity {
+
+ float mSeekValue = .5f;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000));
+ SeekBar slider = new SeekBar(this);
+ LinearLayout container = new LinearLayout(this);
+ container.setOrientation(LinearLayout.VERTICAL);
+ setContentView(container);
+
+ container.addView(slider);
+ slider.setMax(100);
+ slider.setProgress(50);
+ FrameLayout frame = new FrameLayout(this);
+ final RenderingView gpuView = new RenderingView(this, Color.GREEN);
+ frame.addView(gpuView);
+ final RenderingView swView = new RenderingView(this, Color.RED);
+ swView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ frame.addView(swView);
+ container.addView(frame);
+
+ slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ mSeekValue = (float)progress / 100.0f;
+ float gpuAlpha = Math.min(2.0f * mSeekValue, 1f);
+ gpuView.setAlpha(gpuAlpha);
+ float swAlpha = Math.min((1 - mSeekValue) * 2.0f, 1f);
+ System.out.println("(gpuAlpha, swAlpha = " + gpuAlpha + ", " + swAlpha);
+ swView.setAlpha(swAlpha);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ public static class RenderingView extends View {
+
+ private int mColor;
+
+ public RenderingView(Context c, int color) {
+ super(c);
+ mColor = color;
+ }
+
+ private void drawPoints(Canvas canvas, Paint p, float xOffset, float yOffset) {
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ Paint p = new Paint();
+ p.setColor(mColor);
+
+ float yOffset = 0;
+ for (int i = 0; i < 2; ++i) {
+ float xOffset = 0;
+
+ p.setStrokeWidth(0f);
+ p.setStrokeCap(Paint.Cap.SQUARE);
+ canvas.drawPoint(100 + xOffset, 100 + yOffset, p);
+ xOffset += 5;
+
+ p.setStrokeWidth(1f);
+ canvas.drawPoint(100 + xOffset, 100 + yOffset, p);
+ xOffset += 15;
+
+ p.setStrokeWidth(20);
+ canvas.drawPoint(100 + xOffset, 100 + yOffset, p);
+ xOffset += 30;
+
+ p.setStrokeCap(Paint.Cap.ROUND);
+ canvas.drawPoint(100 + xOffset, 100 + yOffset, p);
+
+ p.setAntiAlias(true);
+ yOffset += 30;
+ }
+
+ }
+ }
+}