diff options
Diffstat (limited to 'libs/hwui/pipeline/skia/LayerDrawable.cpp')
-rw-r--r-- | libs/hwui/pipeline/skia/LayerDrawable.cpp | 76 |
1 files changed, 28 insertions, 48 deletions
diff --git a/libs/hwui/pipeline/skia/LayerDrawable.cpp b/libs/hwui/pipeline/skia/LayerDrawable.cpp index ab1d5c2546ed..13d2dae8e281 100644 --- a/libs/hwui/pipeline/skia/LayerDrawable.cpp +++ b/libs/hwui/pipeline/skia/LayerDrawable.cpp @@ -15,8 +15,6 @@ */ #include "LayerDrawable.h" -#include "GlLayer.h" -#include "VkLayer.h" #include "GrBackendSurface.h" #include "SkColorFilter.h" @@ -30,91 +28,73 @@ namespace skiapipeline { void LayerDrawable::onDraw(SkCanvas* canvas) { Layer* layer = mLayerUpdater->backingLayer(); if (layer) { - DrawLayer(canvas->getGrContext(), canvas, layer); + DrawLayer(canvas->getGrContext(), canvas, layer, nullptr, nullptr, true); } } bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer, - const SkRect* dstRect) { + const SkRect* srcRect, const SkRect* dstRect, + bool useLayerTransform) { if (context == nullptr) { SkDEBUGF(("Attempting to draw LayerDrawable into an unsupported surface")); return false; } // transform the matrix based on the layer - SkMatrix layerTransform; - layer->getTransform().copyTo(layerTransform); - sk_sp<SkImage> layerImage; + SkMatrix layerTransform = layer->getTransform(); + sk_sp<SkImage> layerImage = layer->getImage(); const int layerWidth = layer->getWidth(); const int layerHeight = layer->getHeight(); - const int bufferWidth = layer->getBufferWidth(); - const int bufferHeight = layer->getBufferHeight(); - if (bufferWidth <= 0 || bufferHeight <=0) { - return false; - } - if (layer->getApi() == Layer::Api::OpenGL) { - GlLayer* glLayer = static_cast<GlLayer*>(layer); - GrGLTextureInfo externalTexture; - externalTexture.fTarget = glLayer->getRenderTarget(); - externalTexture.fID = glLayer->getTextureId(); - // The format may not be GL_RGBA8, but given the DeferredLayerUpdater and GLConsumer don't - // expose that info we use it as our default. Further, given that we only use this texture - // as a source this will not impact how Skia uses the texture. The only potential affect - // this is anticipated to have is that for some format types if we are not bound as an OES - // texture we may get invalid results for SKP capture if we read back the texture. - externalTexture.fFormat = GL_RGBA8; - GrBackendTexture backendTexture(bufferWidth, bufferHeight, GrMipMapped::kNo, externalTexture); - layerImage = SkImage::MakeFromTexture(context, backendTexture, kTopLeft_GrSurfaceOrigin, - kPremul_SkAlphaType, nullptr); - } else { - SkASSERT(layer->getApi() == Layer::Api::Vulkan); - VkLayer* vkLayer = static_cast<VkLayer*>(layer); - canvas->clear(SK_ColorGREEN); - layerImage = vkLayer->getImage(); - } if (layerImage) { SkMatrix textureMatrixInv; - layer->getTexTransform().copyTo(textureMatrixInv); + textureMatrixInv = layer->getTexTransform(); // 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); textureMatrixInv.preConcat(flipV); textureMatrixInv.preScale(1.0f / layerWidth, 1.0f / layerHeight); - textureMatrixInv.postScale(bufferWidth, bufferHeight); + textureMatrixInv.postScale(layerImage->width(), layerImage->height()); SkMatrix textureMatrix; if (!textureMatrixInv.invert(&textureMatrix)) { textureMatrix = textureMatrixInv; } SkMatrix matrix; - if (dstRect) { - // Destination rectangle is set only when we are trying to read back the content - // of the layer. In this case we don't want to apply layer transform. - matrix = textureMatrix; - } else { + if (useLayerTransform) { matrix = SkMatrix::Concat(layerTransform, textureMatrix); + } else { + matrix = textureMatrix; } SkPaint paint; paint.setAlpha(layer->getAlpha()); paint.setBlendMode(layer->getMode()); paint.setColorFilter(layer->getColorSpaceWithFilter()); - const bool nonIdentityMatrix = !matrix.isIdentity(); if (nonIdentityMatrix) { canvas->save(); canvas->concat(matrix); } const SkMatrix& totalMatrix = canvas->getTotalMatrix(); - if (dstRect) { + if (dstRect || srcRect) { SkMatrix matrixInv; if (!matrix.invert(&matrixInv)) { matrixInv = matrix; } - SkRect srcRect = SkRect::MakeIWH(layerWidth, layerHeight); - matrixInv.mapRect(&srcRect); - SkRect skiaDestRect = *dstRect; + SkRect skiaSrcRect; + if (srcRect) { + skiaSrcRect = *srcRect; + } else { + skiaSrcRect = SkRect::MakeIWH(layerWidth, layerHeight); + } + matrixInv.mapRect(&skiaSrcRect); + SkRect skiaDestRect; + if (dstRect) { + skiaDestRect = *dstRect; + } else { + skiaDestRect = SkRect::MakeIWH(layerWidth, layerHeight); + } matrixInv.mapRect(&skiaDestRect); // If (matrix is identity or an integer translation) and (src/dst buffers size match), // then use nearest neighbor, otherwise use bilerp sampling. @@ -123,13 +103,13 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer // only for SrcOver blending and without color filter (readback uses Src blending). bool isIntegerTranslate = totalMatrix.isTranslate() && SkScalarFraction(skiaDestRect.fLeft + totalMatrix[SkMatrix::kMTransX]) - == SkScalarFraction(srcRect.fLeft) + == SkScalarFraction(skiaSrcRect.fLeft) && SkScalarFraction(skiaDestRect.fTop + totalMatrix[SkMatrix::kMTransY]) - == SkScalarFraction(srcRect.fTop); + == SkScalarFraction(skiaSrcRect.fTop); if (layer->getForceFilter() || !isIntegerTranslate) { paint.setFilterQuality(kLow_SkFilterQuality); } - canvas->drawImageRect(layerImage.get(), srcRect, skiaDestRect, &paint, + canvas->drawImageRect(layerImage.get(), skiaSrcRect, skiaDestRect, &paint, SkCanvas::kFast_SrcRectConstraint); } else { bool isIntegerTranslate = totalMatrix.isTranslate() @@ -146,7 +126,7 @@ bool LayerDrawable::DrawLayer(GrContext* context, SkCanvas* canvas, Layer* layer } } - return layerImage; + return layerImage != nullptr; } }; // namespace skiapipeline |