summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Leon Scroggins III <scroggo@google.com> 2018-03-26 15:00:49 -0400
committer Stan Iliev <stani@google.com> 2018-03-29 19:30:28 +0000
commit1a12ab26d419bad8e5c3c121d98114199e05f47c (patch)
tree44ae7781ac684a360d9e85d482b336036e89ec3e
parent407932ebc0fab40dccd7298f179639b8b9f93460 (diff)
Fix Skia's impl for TextureView.getBitmap
Bug: 73392905 Test: New test added with I2d4ef440f943a50b9367976ba1444f4350071bfd When providing a width and height, getBitmap should scale to the destination. Add a parameter to LayerDrawable::DrawLayer for a destination rectangle to scale to. Pass the size of the bitmap in SkiaOpenGLPipeline::copyLayerInto down to DrawLayer. The only other caller of DrawLayer is unaffected. Change-Id: I7aa192181c2d15bc8fd4de2fb15c4d276b05d2ac
-rw-r--r--libs/hwui/pipeline/skia/LayerDrawable.cpp40
-rw-r--r--libs/hwui/pipeline/skia/LayerDrawable.h3
-rw-r--r--libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp4
3 files changed, 32 insertions, 15 deletions
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.cpp b/libs/hwui/pipeline/skia/LayerDrawable.cpp
index d9584db2df9d..293e45f2273f 100644
--- a/libs/hwui/pipeline/skia/LayerDrawable.cpp
+++ b/libs/hwui/pipeline/skia/LayerDrawable.cpp
@@ -34,7 +34,8 @@ void LayerDrawable::onDraw(SkCanvas* canvas) {
}
}
-bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer) {
+bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer,
+ const SkRect* dstRect) {
if (context == nullptr) {
SkDEBUGF(("Attempting to draw LayerDrawable into an unsupported surface"));
return false;
@@ -43,8 +44,8 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
SkMatrix layerTransform;
layer->getTransform().copyTo(layerTransform);
sk_sp<SkImage> layerImage;
- int layerWidth = layer->getWidth();
- int layerHeight = layer->getHeight();
+ const int layerWidth = layer->getWidth();
+ const int layerHeight = layer->getHeight();
if (layer->getApi() == Layer::Api::OpenGL) {
GlLayer* glLayer = static_cast<GlLayer*>(layer);
GrGLTextureInfo externalTexture;
@@ -62,21 +63,21 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
}
if (layerImage) {
- SkMatrix textureMatrix;
- layer->getTexTransform().copyTo(textureMatrix);
+ SkMatrix textureMatrixInv;
+ layer->getTexTransform().copyTo(textureMatrixInv);
// TODO: after skia bug https://bugs.chromium.org/p/skia/issues/detail?id=7075 is fixed
// use bottom left origin and remove flipV and invert transformations.
SkMatrix flipV;
flipV.setAll(1, 0, 0, 0, -1, 1, 0, 0, 1);
- textureMatrix.preConcat(flipV);
- textureMatrix.preScale(1.0f / layerWidth, 1.0f / layerHeight);
- textureMatrix.postScale(layerWidth, layerHeight);
- SkMatrix textureMatrixInv;
- if (!textureMatrix.invert(&textureMatrixInv)) {
- textureMatrixInv = textureMatrix;
+ textureMatrixInv.preConcat(flipV);
+ textureMatrixInv.preScale(1.0f / layerWidth, 1.0f / layerHeight);
+ textureMatrixInv.postScale(layerWidth, layerHeight);
+ SkMatrix textureMatrix;
+ if (!textureMatrixInv.invert(&textureMatrix)) {
+ textureMatrix = textureMatrixInv;
}
- SkMatrix matrix = SkMatrix::Concat(layerTransform, textureMatrixInv);
+ SkMatrix matrix = SkMatrix::Concat(layerTransform, textureMatrix);
SkPaint paint;
paint.setAlpha(layer->getAlpha());
@@ -88,7 +89,20 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer
canvas->save();
canvas->concat(matrix);
}
- canvas->drawImage(layerImage.get(), 0, 0, &paint);
+ if (dstRect) {
+ SkMatrix matrixInv;
+ if (!matrix.invert(&matrixInv)) {
+ matrixInv = matrix;
+ }
+ SkRect srcRect = SkRect::MakeIWH(layerWidth, layerHeight);
+ matrixInv.mapRect(&srcRect);
+ SkRect skiaDestRect = *dstRect;
+ matrixInv.mapRect(&skiaDestRect);
+ canvas->drawImageRect(layerImage.get(), srcRect, skiaDestRect, &paint,
+ SkCanvas::kFast_SrcRectConstraint);
+ } else {
+ canvas->drawImage(layerImage.get(), 0, 0, &paint);
+ }
// restore the original matrix
if (nonIdentityMatrix) {
canvas->restore();
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.h b/libs/hwui/pipeline/skia/LayerDrawable.h
index 345038769306..18d118405a39 100644
--- a/libs/hwui/pipeline/skia/LayerDrawable.h
+++ b/libs/hwui/pipeline/skia/LayerDrawable.h
@@ -32,7 +32,8 @@ class LayerDrawable : public SkDrawable {
public:
explicit LayerDrawable(DeferredLayerUpdater* layerUpdater) : mLayerUpdater(layerUpdater) {}
- static bool DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer);
+ static bool DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer,
+ const SkRect* dstRect = nullptr);
protected:
virtual SkRect onGetBounds() override {
diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
index 365d7403e046..74cfb2854e62 100644
--- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
@@ -138,7 +138,9 @@ bool SkiaOpenGLPipeline::copyLayerInto(DeferredLayerUpdater* deferredLayer, SkBi
SkBudgeted::kYes, bitmap->info());
Layer* layer = deferredLayer->backingLayer();
- if (LayerDrawable::DrawLayer(mRenderThread.getGrContext(), tmpSurface->getCanvas(), layer)) {
+ const SkRect dstRect = SkRect::MakeIWH(bitmap->width(), bitmap->height());
+ if (LayerDrawable::DrawLayer(mRenderThread.getGrContext(), tmpSurface->getCanvas(), layer,
+ &dstRect)) {
sk_sp<SkImage> tmpImage = tmpSurface->makeImageSnapshot();
if (tmpImage->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
bitmap->notifyPixelsChanged();