diff options
author | John Reck <jreck@google.com> | 2016-04-27 14:36:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-04-27 14:36:53 +0000 |
commit | 7f209d37f17d4df09475137c38b84a3338c84023 (patch) | |
tree | 07856ff96c1e32df08aef9ad73b7b8216d16f9c0 /tests/HwAccelerationTest | |
parent | 9fa8b54589b68dc6da3a7201cad1fc43e01e59e3 (diff) | |
parent | e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1 (diff) |
Merge "API tweaks to PixelCopy and make it public" into nyc-dev
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/GetBitmapSurfaceViewActivity.java | 47 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/HardwareCanvasSurfaceViewActivity.java | 48 |
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()); |