Fix window copy for rotation = 90/270
Bug: 33421965 Test: Manual via PixelCopyWindow test in HwAccelerationTest Change-Id: I2a59fd6a26499635a22444e124cd1ec6f82f6e31
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user