summaryrefslogtreecommitdiff
path: root/tests/HwAccelerationTest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java47
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java48
2 files changed, 38 insertions, 57 deletions
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java
index d3cd7db7d46a..f658b7c05e66 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java
@@ -18,13 +18,11 @@ package com.android.test.hwui;
import android.app.Activity;
import android.graphics.Bitmap;
-import android.graphics.PixelCopy;
-import android.graphics.PixelCopy.OnPixelCopyFinished;
-import android.graphics.PixelCopy.Response;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
+import android.view.PixelCopy;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
@@ -32,7 +30,6 @@ import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -52,12 +49,25 @@ public class GetBitmapSurfaceViewActivity extends Activity implements SurfaceHol
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/surfaceview.png");
button.setOnClickListener((View v) -> {
- Bitmap b = Bitmap.createBitmap(
- mSurfaceView.getWidth(),
- mSurfaceView.getHeight(),
- Bitmap.Config.ARGB_8888);
+ final Bitmap b = Bitmap.createBitmap(
+ mSurfaceView.getWidth(), mSurfaceView.getHeight(),
+ Bitmap.Config.ARGB_8888);
PixelCopy.request(mSurfaceView, b,
- mOnCopyFinished, mSurfaceView.getHandler());
+ (int result) -> {
+ if (result != PixelCopy.SUCCESS) {
+ Toast.makeText(GetBitmapSurfaceViewActivity.this,
+ "Failed to copy", Toast.LENGTH_SHORT).show();
+ return;
+ }
+ try {
+ try (FileOutputStream out = new FileOutputStream(
+ Environment.getExternalStorageDirectory() + "/surfaceview.png");) {
+ b.compress(Bitmap.CompressFormat.PNG, 100, out);
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ }, mSurfaceView.getHandler());
});
content.addView(mSurfaceView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
@@ -67,25 +77,6 @@ public class GetBitmapSurfaceViewActivity extends Activity implements SurfaceHol
setContentView(content);
}
- private final OnPixelCopyFinished mOnCopyFinished = new OnPixelCopyFinished() {
- @Override
- public void onPixelCopyFinished(Response response) {
- if (!response.success) {
- Toast.makeText(GetBitmapSurfaceViewActivity.this,
- "Failed to copy", Toast.LENGTH_SHORT).show();
- return;
- }
- try {
- try (FileOutputStream out = new FileOutputStream(
- Environment.getExternalStorageDirectory() + "/surfaceview.png");) {
- response.bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
- }
- } catch (Exception e) {
- // Ignore
- }
- }
- };
-
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java
index 5c30faba3d18..086a8f0126b3 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java
@@ -20,12 +20,10 @@ import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
-import android.graphics.PixelCopy;
-import android.graphics.PixelCopy.OnPixelCopyFinished;
-import android.graphics.PixelCopy.Response;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.os.Environment;
+import android.view.PixelCopy;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
@@ -36,9 +34,7 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.IOException;
public class HardwareCanvasSurfaceViewActivity extends Activity implements Callback {
private SurfaceView mSurfaceView;
@@ -56,12 +52,25 @@ public class HardwareCanvasSurfaceViewActivity extends Activity implements Callb
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/surfaceview.png");
button.setOnClickListener((View v) -> {
- Bitmap b = Bitmap.createBitmap(
- mSurfaceView.getWidth(),
- mSurfaceView.getHeight(),
- Bitmap.Config.ARGB_8888);
+ final Bitmap b = Bitmap.createBitmap(
+ mSurfaceView.getWidth(), mSurfaceView.getHeight(),
+ Bitmap.Config.ARGB_8888);
PixelCopy.request(mSurfaceView, b,
- mOnCopyFinished, mSurfaceView.getHandler());
+ (int result) -> {
+ if (result != PixelCopy.SUCCESS) {
+ Toast.makeText(HardwareCanvasSurfaceViewActivity.this,
+ "Failed to copy", Toast.LENGTH_SHORT).show();
+ return;
+ }
+ try {
+ try (FileOutputStream out = new FileOutputStream(
+ Environment.getExternalStorageDirectory() + "/surfaceview.png");) {
+ b.compress(Bitmap.CompressFormat.PNG, 100, out);
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ }, mSurfaceView.getHandler());
});
LinearLayout layout = new LinearLayout(this);
@@ -77,25 +86,6 @@ public class HardwareCanvasSurfaceViewActivity extends Activity implements Callb
setContentView(content);
}
- private final OnPixelCopyFinished mOnCopyFinished = new OnPixelCopyFinished() {
- @Override
- public void onPixelCopyFinished(Response response) {
- if (!response.success) {
- Toast.makeText(HardwareCanvasSurfaceViewActivity.this,
- "Failed to copy", Toast.LENGTH_SHORT).show();
- return;
- }
- try {
- try (FileOutputStream out = new FileOutputStream(
- Environment.getExternalStorageDirectory() + "/surfaceview.png");) {
- response.bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
- }
- } catch (Exception e) {
- // Ignore
- }
- }
- };
-
@Override
public void surfaceCreated(SurfaceHolder holder) {
mThread = new RenderingThread(holder.getSurface());