summaryrefslogtreecommitdiff
path: root/tests/HwAccelerationTest
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2019-01-17 17:01:32 -0800
committerJohn Reck <jreck@google.com>2019-02-08 10:50:14 -0800
commitfe5dfcacfc670f48967472fa87a774d8284ac943 (patch)
treeff79a4d6c3e15d794f679d9885cfcd50133f98b8 /tests/HwAccelerationTest
parent699905e5c77f352a8937720cfa56cf4091e460c9 (diff)
Make HardwareRenderer public API
Bug: 123661129 Test: HardwareRenderer CTS tests Change-Id: Ic7ff69c9489d00e3f525eec761a84d06cf81be7a
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r--tests/HwAccelerationTest/AndroidManifest.xml24
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java76
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/MyLittleTextureView.java87
3 files changed, 185 insertions, 2 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 1a4ec94d77b4..7b8c154dea1e 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -1028,8 +1028,28 @@
</activity>
<activity
- android:name="PositionListenerActivity"
- android:label="RenderNode/PositionListener"
+ 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" />
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..60bd60f0bfd1
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/CustomRenderer.java
@@ -0,0 +1,76 @@
+/*
+ * 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.Color;
+import android.graphics.HardwareRenderer;
+import android.graphics.Paint;
+import android.graphics.RecordingCanvas;
+import android.graphics.RenderNode;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.SurfaceHolder;
+
+public class CustomRenderer extends Activity {
+ private RenderNode mContent = new RenderNode("CustomRenderer");
+ private HardwareRenderer mRenderer = new HardwareRenderer();
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ getWindow().takeSurface(mSurfaceCallbacks);
+ }
+
+ 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) {
+ mContent.setLeftTopRightBottom(0, 0, width, height);
+ RecordingCanvas canvas = mContent.startRecording();
+ canvas.drawColor(Color.WHITE);
+ Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ paint.setColor(Color.BLACK);
+ paint.setTextAlign(Paint.Align.CENTER);
+ paint.setTextSize(Math.min(width, height) * .05f);
+ canvas.drawText("Hello custom renderer!", width / 2, height / 2, paint);
+ mContent.endRecording();
+
+ mRenderer.setContentRoot(mContent);
+ mRenderer.setSurface(holder.getSurface());
+ mRenderer.createRenderRequest()
+ .setVsyncTime(System.nanoTime())
+ .setFrameCommitCallback(Runnable::run, () -> {
+ Log.d("CustomRenderer", "Frame committed!");
+ })
+ .syncAndDraw();
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ mRenderer.destroy();
+ }
+ };
+}
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..8bd7d797aea3
--- /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.startRecording();
+ canvas.drawColor(Color.BLUE);
+ }
+ childNode.endRecording();
+ childNode.setElevation(20f);
+
+ {
+ Canvas canvas = mContent.startRecording();
+ 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();
+ }
+}