diff options
author | John Reck <jreck@google.com> | 2016-12-07 16:36:15 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2016-12-08 11:22:31 -0800 |
commit | 912bebeb7488f498954282a1eb82a4b641e6418e (patch) | |
tree | 7c11751a6f0f7056c6aa759bfd42a01b8379a63c /tests/HwAccelerationTest | |
parent | ea98e436002a8f2c51370edc134c9e3a137b9cc5 (diff) |
Fix window copy for rotation = 90/270
Bug: 33421965
Test: Manual via PixelCopyWindow test in HwAccelerationTest
Change-Id: I2a59fd6a26499635a22444e124cd1ec6f82f6e31
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 10 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/PixelCopyWindow.java | 98 |
2 files changed, 108 insertions, 0 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index 3785cdc44b0c..b4f3d6964bef 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -989,5 +989,15 @@ </intent-filter> </activity> + <activity + android:name="PixelCopyWindow" + android:label="Readback/Window" + 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/PixelCopyWindow.java b/tests/HwAccelerationTest/src/com/android/test/hwui/PixelCopyWindow.java new file mode 100644 index 000000000000..a039fba14f65 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/PixelCopyWindow.java @@ -0,0 +1,98 @@ +package com.android.test.hwui; + +import android.app.Activity; +import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; +import android.graphics.Paint.Style; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.Paint; +import android.graphics.PixelFormat; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Handler; +import android.util.Log; +import android.view.PixelCopy; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class PixelCopyWindow extends Activity { + + private Handler mHandler; + private ImageView mImage; + private TextView mText; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mHandler = new Handler(); + + LinearLayout layout = new LinearLayout(this); + TextView text = new TextView(this); + text.setText("Hello, World!"); + Button btn = new Button(this); + btn.setText("Screenshot!"); + btn.setOnClickListener((v) -> takeScreenshot()); + mImage = new ImageView(this); + mText = new TextView(this); + + layout.setOrientation(LinearLayout.VERTICAL); + layout.addView(text); + layout.addView(btn); + layout.addView(mImage); + layout.addView(mText); + final float density = getResources().getDisplayMetrics().density; + layout.setBackground(new Drawable() { + Paint mPaint = new Paint(); + + @Override + public void draw(Canvas canvas) { + mPaint.setStyle(Style.STROKE); + mPaint.setStrokeWidth(4 * density); + mPaint.setColor(Color.BLUE); + final Rect bounds = getBounds(); + canvas.drawRect(bounds, mPaint); + mPaint.setColor(Color.RED); + canvas.drawLine(bounds.centerX(), 0, bounds.centerX(), bounds.height(), mPaint); + mPaint.setColor(Color.GREEN); + canvas.drawLine(0, bounds.centerY(), bounds.width(), bounds.centerY(), mPaint); + } + + @Override + public void setAlpha(int alpha) { + } + + @Override + public void setColorFilter(ColorFilter colorFilter) { + } + + @Override + public int getOpacity() { + return PixelFormat.TRANSLUCENT; + } + }); + setContentView(layout); + } + + private void takeScreenshot() { + View decor = getWindow().getDecorView(); + Rect srcRect = new Rect(); + decor.getGlobalVisibleRect(srcRect); + final Bitmap bitmap = Bitmap.createBitmap( + (int) (srcRect.width() * .25), (int) (srcRect.height() * .25), Config.ARGB_8888); + PixelCopy.request(getWindow(), srcRect, bitmap, (result) -> { + if (result != PixelCopy.SUCCESS) { + mText.setText("Copy failed, result: " + result); + mImage.setImageBitmap(null); + } else { + mText.setText(""); + mImage.setImageBitmap(bitmap); + } + }, mHandler); + } +} |