diff options
-rw-r--r-- | libs/hwui/OpenGLReadback.cpp | 11 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 10 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/PixelCopyWindow.java | 98 |
3 files changed, 117 insertions, 2 deletions
diff --git a/libs/hwui/OpenGLReadback.cpp b/libs/hwui/OpenGLReadback.cpp index 408159b8f33a..74a8395f9fff 100644 --- a/libs/hwui/OpenGLReadback.cpp +++ b/libs/hwui/OpenGLReadback.cpp @@ -82,8 +82,15 @@ CopyResult OpenGLReadback::copyGraphicBufferInto(GraphicBuffer* graphicBuffer, return CopyResult::UnknownError; } - CopyResult copyResult = copyImageInto(sourceImage, texTransform, graphicBuffer->getWidth(), - graphicBuffer->getHeight(), srcRect, bitmap); + uint32_t width = graphicBuffer->getWidth(); + uint32_t height = graphicBuffer->getHeight(); + // If this is a 90 or 270 degree rotation we need to swap width/height + // This is a fuzzy way of checking that. + if (texTransform[Matrix4::kSkewX] >= 0.5f || texTransform[Matrix4::kSkewX] <= -0.5f) { + std::swap(width, height); + } + CopyResult copyResult = copyImageInto(sourceImage, texTransform, width, height, + srcRect, bitmap); // All we're flushing & finishing is the deletion of the texture since // copyImageInto already did a major flush & finish as an implicit 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); + } +} |