summaryrefslogtreecommitdiff
path: root/tests/HwAccelerationTest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r--tests/HwAccelerationTest/Android.bp1
-rw-r--r--tests/HwAccelerationTest/AndroidManifest.xml39
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java6
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java2
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java128
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/DrawIntoHwBitmapActivity.java12
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/MultiProducerActivity.java8
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/MyLittleTextureView.java87
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/PictureCaptureDemo.java153
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/PositionListenerActivity.java98
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionActivity.java3
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionClippingActivity.java6
12 files changed, 515 insertions, 28 deletions
diff --git a/tests/HwAccelerationTest/Android.bp b/tests/HwAccelerationTest/Android.bp
index abcd73b115af..37d3f5d4d97f 100644
--- a/tests/HwAccelerationTest/Android.bp
+++ b/tests/HwAccelerationTest/Android.bp
@@ -18,4 +18,5 @@ android_test {
name: "HwAccelerationTest",
srcs: ["**/*.java"],
platform_apis: true,
+ certificate: "platform",
}
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index c8f96c9f0670..7b8c154dea1e 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -310,6 +310,15 @@
<category android:name="com.android.test.hwui.TEST" />
</intent-filter>
</activity>
+
+ <activity
+ android:name="PictureCaptureDemo"
+ android:label="Debug/Picture Capture">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
<activity
android:name="SmallCircleActivity"
@@ -1018,5 +1027,35 @@
</intent-filter>
</activity>
+ <activity
+ android:name="PositionListenerActivity"
+ android:label="RenderNode/PositionListener"
+ android:screenOrientation="fullSensor">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="CustomRenderer"
+ android:label="HardwareRenderer/HelloTakeSurface"
+ android:screenOrientation="fullSensor">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="MyLittleTextureView"
+ android:label="HardwareRenderer/MyLittleTextureView"
+ android:screenOrientation="fullSensor">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.android.test.hwui.TEST" />
+ </intent-filter>
+ </activity>
+
</application>
</manifest>
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java
index 5bc8934279d6..571f623aea99 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/CirclePropActivity.java
@@ -22,9 +22,9 @@ import android.graphics.Canvas;
import android.graphics.CanvasProperty;
import android.graphics.Paint;
import android.graphics.Paint.Style;
+import android.graphics.RecordingCanvas;
import android.os.Bundle;
import android.os.Trace;
-import android.view.DisplayListCanvas;
import android.view.RenderNodeAnimator;
import android.view.View;
import android.widget.LinearLayout;
@@ -88,8 +88,8 @@ public class CirclePropActivity extends Activity {
super.onDraw(canvas);
if (canvas.isHardwareAccelerated()) {
- DisplayListCanvas displayListCanvas = (DisplayListCanvas) canvas;
- displayListCanvas.drawCircle(mX, mY, mRadius, mPaint);
+ RecordingCanvas recordingCanvas = (RecordingCanvas) canvas;
+ recordingCanvas.drawCircle(mX, mY, mRadius, mPaint);
}
}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
index a7bdabd64684..0787d823756c 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
@@ -106,7 +106,7 @@ public class ColorFiltersMutateActivity extends Activity {
mPorterDuffColor = porterDuffColor;
final PorterDuffColorFilter filter =
(PorterDuffColorFilter) mBlendPaint.getColorFilter();
- filter.setColor(mPorterDuffColor);
+ mBlendPaint.setColorFilter(new PorterDuffColorFilter(porterDuffColor, filter.getMode()));
invalidate();
}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java b/tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java
new file mode 100644
index 000000000000..5ad7fb9027a2
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2019 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.graphics.Color;
+import android.graphics.HardwareRenderer;
+import android.graphics.Paint;
+import android.graphics.RecordingCanvas;
+import android.graphics.RenderNode;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.SurfaceHolder;
+
+public class CustomRenderer extends Activity {
+ private RenderNode mRootNode = new RenderNode("CustomRenderer");
+ private RenderNode mChildNode = new RenderNode("RedBox");
+ private HardwareRenderer mRenderer = new HardwareRenderer();
+ private ObjectAnimator mAnimator;
+ private Handler mRedrawHandler = new Handler(true);
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().takeSurface(mSurfaceCallbacks);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mAnimator = ObjectAnimator.ofFloat(mChildNode, "translationY", 0, 300);
+ mAnimator.setRepeatMode(ObjectAnimator.REVERSE);
+ mAnimator.setRepeatCount(ObjectAnimator.INFINITE);
+ final Runnable redraw = this::draw;
+ mAnimator.addUpdateListener(animation -> {
+ mRedrawHandler.post(redraw);
+ });
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mAnimator.end();
+ mAnimator = null;
+ }
+
+ private void setupRoot(int width, int height) {
+ mRootNode.setPosition(0, 0, width, height);
+
+ RecordingCanvas canvas = mRootNode.beginRecording();
+ canvas.drawColor(Color.WHITE);
+ Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ paint.setColor(Color.BLACK);
+ paint.setTextAlign(Paint.Align.CENTER);
+ float textSize = Math.min(width, height) * .05f;
+ paint.setTextSize(textSize);
+ canvas.drawText("Hello custom renderer!", width / 2, textSize * 2, paint);
+
+ canvas.translate(0, height / 4);
+ canvas.drawRenderNode(mChildNode);
+ canvas.translate(width / 2, 0);
+ canvas.drawRenderNode(mChildNode);
+ mRootNode.endRecording();
+
+ setupChild(width / 2, height / 2);
+ }
+
+ private void setupChild(int width, int height) {
+ mChildNode.setPosition(0, 0, width, height);
+ mChildNode.setScaleX(.5f);
+ mChildNode.setScaleY(.5f);
+
+ RecordingCanvas canvas = mChildNode.beginRecording();
+ canvas.drawColor(Color.RED);
+ mChildNode.endRecording();
+ }
+
+ private void draw() {
+ // Since we are constantly pumping frames between onStart & onStop we don't really
+ // care about any errors that may happen. They will self-correct.
+ mRenderer.createRenderRequest()
+ .setVsyncTime(System.nanoTime())
+ .syncAndDraw();
+ }
+
+ private SurfaceHolder.Callback2 mSurfaceCallbacks = new SurfaceHolder.Callback2() {
+
+ @Override
+ public void surfaceRedrawNeeded(SurfaceHolder holder) {
+ }
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ setupRoot(width, height);
+
+ mRenderer.setContentRoot(mRootNode);
+ mRenderer.setSurface(holder.getSurface());
+ draw();
+ if (!mAnimator.isStarted()) {
+ mAnimator.start();
+ }
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ mRenderer.destroy();
+ }
+ };
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/DrawIntoHwBitmapActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/DrawIntoHwBitmapActivity.java
index af8e10bc07ae..220016aa8ab7 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/DrawIntoHwBitmapActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/DrawIntoHwBitmapActivity.java
@@ -16,25 +16,13 @@
package com.android.test.hwui;
-import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
-import static android.graphics.GraphicBuffer.USAGE_SW_READ_NEVER;
-import static android.graphics.GraphicBuffer.USAGE_SW_WRITE_NEVER;
-import static android.graphics.GraphicBuffer.USAGE_SW_WRITE_RARELY;
-
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
-import android.graphics.GraphicBuffer;
import android.graphics.Paint;
import android.graphics.Picture;
-import android.graphics.PixelFormat;
-import android.graphics.SurfaceTexture;
import android.os.Bundle;
-import android.view.DisplayListCanvas;
-import android.view.RenderNode;
-import android.view.Surface;
-import android.view.ThreadedRenderer;
import android.widget.ImageView;
public class DrawIntoHwBitmapActivity extends Activity {
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/MultiProducerActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/MultiProducerActivity.java
index 7713f5da36ed..e7d7f2b11801 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/MultiProducerActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/MultiProducerActivity.java
@@ -21,12 +21,12 @@ import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
+import android.graphics.RecordingCanvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
-import android.view.DisplayListCanvas;
import android.view.ThreadedRenderer;
-import android.view.RenderNode;
+import android.graphics.RenderNode;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
@@ -206,7 +206,7 @@ public class MultiProducerActivity extends Activity implements OnClickListener {
}
// Draw frame
- DisplayListCanvas canvas = nodeFrame.start(currentFrameBounds.width(),
+ RecordingCanvas canvas = nodeFrame.start(currentFrameBounds.width(),
currentFrameBounds.height());
mFrameContent.draw(canvas);
nodeFrame.end(canvas);
@@ -228,7 +228,7 @@ public class MultiProducerActivity extends Activity implements OnClickListener {
}
// Draw Backdrop
- DisplayListCanvas canvas = nodeBack.start(currentBackBounds.width(),
+ RecordingCanvas canvas = nodeBack.start(currentBackBounds.width(),
currentBackBounds.height());
mBackContent.draw(canvas);
nodeBack.end(canvas);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/MyLittleTextureView.java b/tests/HwAccelerationTest/src/com/android/test/hwui/MyLittleTextureView.java
new file mode 100644
index 000000000000..08d5d4fff50a
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/MyLittleTextureView.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2019 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.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorSpace;
+import android.graphics.HardwareRenderer;
+import android.graphics.Outline;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.RenderNode;
+import android.hardware.HardwareBuffer;
+import android.media.Image;
+import android.media.ImageReader;
+import android.os.Bundle;
+import android.widget.ImageView;
+
+public class MyLittleTextureView extends Activity {
+ private RenderNode mContent = new RenderNode("CustomRenderer");
+ private HardwareRenderer mRenderer = new HardwareRenderer();
+ private ImageView mImageView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mImageView = new ImageView(this);
+ mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
+ setContentView(mImageView);
+
+ ImageReader reader = ImageReader.newInstance(100, 100, PixelFormat.RGBA_8888, 3,
+ HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE | HardwareBuffer.USAGE_GPU_COLOR_OUTPUT);
+ mRenderer.setSurface(reader.getSurface());
+ mRenderer.setLightSourceAlpha(0.0f, 1.0f);
+ mRenderer.setLightSourceGeometry(100 / 2f, 0f, 800.0f, 20.0f);
+ mContent.setLeftTopRightBottom(0, 0, 100, 100);
+
+ Rect childRect = new Rect(25, 25, 65, 65);
+ RenderNode childNode = new RenderNode("shadowCaster");
+ childNode.setLeftTopRightBottom(childRect.left, childRect.top,
+ childRect.right, childRect.bottom);
+ Outline outline = new Outline();
+ outline.setRect(new Rect(0, 0, childRect.width(), childRect.height()));
+ outline.setAlpha(1f);
+ childNode.setOutline(outline);
+ {
+ Canvas canvas = childNode.beginRecording();
+ canvas.drawColor(Color.BLUE);
+ }
+ childNode.endRecording();
+ childNode.setElevation(20f);
+
+ {
+ Canvas canvas = mContent.beginRecording();
+ canvas.drawColor(Color.WHITE);
+ canvas.enableZ();
+ canvas.drawRenderNode(childNode);
+ canvas.disableZ();
+ }
+ mContent.endRecording();
+ mRenderer.setContentRoot(mContent);
+ mRenderer.createRenderRequest()
+ .setWaitForPresent(true)
+ .syncAndDraw();
+ Image image = reader.acquireNextImage();
+ Bitmap bitmap = Bitmap.wrapHardwareBuffer(image.getHardwareBuffer(),
+ ColorSpace.get(ColorSpace.Named.SRGB));
+ mImageView.setImageBitmap(bitmap);
+ image.close();
+ }
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PictureCaptureDemo.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PictureCaptureDemo.java
new file mode 100644
index 000000000000..029e302d0382
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PictureCaptureDemo.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2019 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.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Picture;
+import android.os.Bundle;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.ViewDebug;
+import android.webkit.WebChromeClient;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.LinearLayout.LayoutParams;
+import android.widget.ProgressBar;
+
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+public class PictureCaptureDemo extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final LinearLayout layout = new LinearLayout(this);
+ layout.setOrientation(LinearLayout.VERTICAL);
+
+ final LinearLayout inner = new LinearLayout(this);
+ inner.setOrientation(LinearLayout.HORIZONTAL);
+ ProgressBar spinner = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
+ inner.addView(spinner,
+ new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+
+ inner.addView(new View(this), new LayoutParams(50, 1));
+
+ Picture picture = new Picture();
+ Canvas canvas = picture.beginRecording(100, 100);
+ canvas.drawColor(Color.RED);
+ Paint paint = new Paint();
+ paint.setTextSize(32);
+ paint.setColor(Color.BLACK);
+ canvas.drawText("Hello", 0, 50, paint);
+ picture.endRecording();
+
+ ImageView iv1 = new ImageView(this);
+ iv1.setImageBitmap(Bitmap.createBitmap(picture, 100, 100, Bitmap.Config.ARGB_8888));
+ inner.addView(iv1, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+
+ inner.addView(new View(this), new LayoutParams(50, 1));
+
+ ImageView iv2 = new ImageView(this);
+ iv2.setImageBitmap(Bitmap.createBitmap(picture, 100, 100, Bitmap.Config.HARDWARE));
+ inner.addView(iv2, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+
+ layout.addView(inner,
+ new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
+ // For testing with a functor in the tree
+ WebView wv = new WebView(this);
+ wv.setWebViewClient(new WebViewClient());
+ wv.setWebChromeClient(new WebChromeClient());
+ wv.loadUrl("https://google.com");
+ layout.addView(wv, new LayoutParams(LayoutParams.MATCH_PARENT, 400));
+
+ SurfaceView mySurfaceView = new SurfaceView(this);
+ layout.addView(mySurfaceView,
+ new LayoutParams(LayoutParams.MATCH_PARENT, 600));
+
+ setContentView(layout);
+
+ mySurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
+ private AutoCloseable mStopCapture;
+
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ final Random rand = new Random();
+ mStopCapture = ViewDebug.startRenderingCommandsCapture(mySurfaceView,
+ mCaptureThread, (picture) -> {
+ if (rand.nextInt(20) == 0) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+ Canvas canvas = holder.lockCanvas();
+ if (canvas == null) {
+ return false;
+ }
+ canvas.drawPicture(picture);
+ holder.unlockCanvasAndPost(canvas);
+ picture.close();
+ return true;
+ });
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ if (mStopCapture != null) {
+ try {
+ mStopCapture.close();
+ } catch (Exception e) {
+ }
+ mStopCapture = null;
+ }
+ }
+ });
+ }
+
+ ExecutorService mCaptureThread = Executors.newSingleThreadExecutor();
+ ExecutorService mExecutor = Executors.newSingleThreadExecutor();
+
+ Picture deepCopy(Picture src) {
+ try {
+ PipedInputStream inputStream = new PipedInputStream();
+ PipedOutputStream outputStream = new PipedOutputStream(inputStream);
+ Future<Picture> future = mExecutor.submit(() -> Picture.createFromStream(inputStream));
+ src.writeToStream(outputStream);
+ outputStream.close();
+ return future.get();
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/PositionListenerActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PositionListenerActivity.java
new file mode 100644
index 000000000000..818d899413de
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PositionListenerActivity.java
@@ -0,0 +1,98 @@
+/*
+ * 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.RenderNode;
+import android.os.Bundle;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class PositionListenerActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final LinearLayout layout = new LinearLayout(this);
+ layout.setOrientation(LinearLayout.VERTICAL);
+
+ ProgressBar spinner = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
+ layout.addView(spinner);
+
+ ScrollView scrollingThing = new ScrollView(this);
+ scrollingThing.addView(new MyPositionReporter(this));
+ layout.addView(scrollingThing);
+
+ setContentView(layout);
+ }
+
+ static class MyPositionReporter extends TextView implements RenderNode.PositionUpdateListener {
+ RenderNode mNode;
+ int mCurrentCount = 0;
+ int mTranslateY = 0;
+
+ MyPositionReporter(Context c) {
+ super(c);
+ mNode = new RenderNode("positionListener");
+ mNode.addPositionUpdateListener(this);
+ setTextAlignment(TEXT_ALIGNMENT_VIEW_START);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ setMeasuredDimension(getMeasuredWidth(), 10000);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ mNode.setLeftTopRightBottom(left, top, right, bottom);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ ScrollView parent = (ScrollView) getParent();
+ canvas.translate(0, parent.getScrollY());
+ super.onDraw(canvas);
+ canvas.translate(0, -parent.getScrollY());
+ // Inject our listener proxy
+ canvas.drawRenderNode(mNode);
+ }
+
+ @Override
+ public void positionChanged(long frameNumber, int left, int top, int right, int bottom) {
+ post(() -> {
+ mCurrentCount++;
+ setText(String.format("%d: Position [%d, %d, %d, %d]", mCurrentCount,
+ left, top, right, bottom));
+ });
+ }
+
+ @Override
+ public void positionLost(long frameNumber) {
+ post(() -> {
+ mCurrentCount++;
+ setText(mCurrentCount + " No position");
+ });
+ }
+ }
+}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionActivity.java
index be5d7f98783d..4eb40722f6dd 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionActivity.java
@@ -8,9 +8,8 @@ import android.os.Bundle;
import android.app.Activity;
import android.util.AttributeSet;
-import android.view.RenderNode;
+import android.graphics.RenderNode;
import android.view.View;
-import android.widget.LinearLayout;
public class ProjectionActivity extends Activity {
/**
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionClippingActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionClippingActivity.java
index 2ae960bd08db..9abd7ea5f361 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionClippingActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ProjectionClippingActivity.java
@@ -1,13 +1,7 @@
package com.android.test.hwui;
import android.app.Activity;
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.RectF;
import android.os.Bundle;
-import android.util.AttributeSet;
-import android.view.RenderNode;
import android.view.View;
public class ProjectionClippingActivity extends Activity {