Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c9175f4 authored by Ram Indani's avatar Ram Indani Committed by Android (Google) Code Review
Browse files

Merge "Added crop rect to LayerDrawable to not crop TextureView. Verified...

Merge "Added crop rect to LayerDrawable to not crop TextureView. Verified manually with ExoPlayer that TextureView isn't cropping."
parents 1260c6da ef54c038
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
// TODO: Use public SurfaceTexture APIs once available and include public NDK header file instead.
#include <surfacetexture/surface_texture_platform.h>
#include "AutoBackendTextureRelease.h"
#include "Matrix.h"
#include "Properties.h"
#include "renderstate/RenderState.h"
#include "renderthread/EglManager.h"
@@ -145,16 +144,17 @@ void DeferredLayerUpdater::apply() {
        }
        if (mUpdateTexImage) {
            mUpdateTexImage = false;
            float transformMatrix[16];
            android_dataspace dataspace;
            int slot;
            bool newContent = false;
            ARect rect;
            uint32_t textureTransform;
            // Note: ASurfaceTexture_dequeueBuffer discards all but the last frame. This
            // is necessary if the SurfaceTexture queue is in synchronous mode, and we
            // cannot tell which mode it is in.
            AHardwareBuffer* hardwareBuffer = ASurfaceTexture_dequeueBuffer(
                    mSurfaceTexture.get(), &slot, &dataspace, transformMatrix, &newContent,
                    createReleaseFence, fenceWait, this);
                    mSurfaceTexture.get(), &slot, &dataspace, &newContent, createReleaseFence,
                    fenceWait, this, &rect, &textureTransform);

            if (hardwareBuffer) {
                mCurrentSlot = slot;
@@ -165,12 +165,12 @@ void DeferredLayerUpdater::apply() {
                // (invoked by createIfNeeded) will add a ref to the AHardwareBuffer.
                AHardwareBuffer_release(hardwareBuffer);
                if (layerImage.get()) {
                    SkMatrix textureTransform;
                    mat4(transformMatrix).copyTo(textureTransform);
                    // force filtration if buffer size != layer size
                    bool forceFilter =
                            mWidth != layerImage->width() || mHeight != layerImage->height();
                    updateLayer(forceFilter, textureTransform, layerImage);
                    SkRect cropRect =
                            SkRect::MakeLTRB(rect.left, rect.top, rect.right, rect.bottom);
                    updateLayer(forceFilter, textureTransform, cropRect, layerImage);
                }
            }
        }
@@ -182,12 +182,13 @@ void DeferredLayerUpdater::apply() {
    }
}

void DeferredLayerUpdater::updateLayer(bool forceFilter, const SkMatrix& textureTransform,
                                       const sk_sp<SkImage>& layerImage) {
void DeferredLayerUpdater::updateLayer(bool forceFilter, const uint32_t textureTransform,
                                       const SkRect cropRect, const sk_sp<SkImage>& layerImage) {
    mLayer->setBlend(mBlend);
    mLayer->setForceFilter(forceFilter);
    mLayer->setSize(mWidth, mHeight);
    mLayer->getTexTransform() = textureTransform;
    mLayer->setTextureTransform(textureTransform);
    mLayer->setCropRect(cropRect);
    mLayer->setImage(layerImage);
}

+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public:

    void detachSurfaceTexture();

    void updateLayer(bool forceFilter, const SkMatrix& textureTransform,
    void updateLayer(bool forceFilter, const uint32_t textureTransform, const SkRect cropRect,
                     const sk_sp<SkImage>& layerImage);

    void destroyLayer();
+0 −2
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ Layer::Layer(RenderState& renderState, sk_sp<SkColorFilter> colorFilter, int alp
    // preserves the old inc/dec ref locations. This should be changed...
    incStrong(nullptr);
    renderState.registerLayer(this);
    texTransform.setIdentity();
    transform.setIdentity();
}

@@ -101,7 +100,6 @@ void Layer::draw(SkCanvas* canvas) {
    const int layerHeight = getHeight();
    if (layerImage) {
        SkMatrix textureMatrixInv;
        textureMatrixInv = 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;
+19 −6
Original line number Diff line number Diff line
@@ -74,10 +74,18 @@ public:

    void setColorFilter(sk_sp<SkColorFilter> filter) { mColorFilter = filter; };

    inline SkMatrix& getTexTransform() { return texTransform; }

    inline SkMatrix& getTransform() { return transform; }

    inline SkRect getCropRect() { return mCropRect; }

    inline void setCropRect(const SkRect cropRect) { mCropRect = cropRect; }

    inline void setTextureTransform(uint32_t textureTransform) {
        mTextureTransform = textureTransform;
    }

    inline uint32_t getTextureTransform() { return mTextureTransform; }

    /**
     * Posts a decStrong call to the appropriate thread.
     * Thread-safe.
@@ -116,14 +124,19 @@ private:
    SkBlendMode mode;

    /**
     * Optional texture coordinates transform.
     * Optional transform.
     */
    SkMatrix texTransform;
    SkMatrix transform;

    /**
     * Optional transform.
     * Optional crop
     */
    SkMatrix transform;
    SkRect mCropRect;

    /**
     * Optional transform
     */
    uint32_t mTextureTransform;

    /**
     * An image backing the layer.
+0 −5
Original line number Diff line number Diff line
@@ -251,8 +251,6 @@ CopyResult Readback::copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap) {

    Rect srcRect;
    Matrix4 transform;
    transform.loadScale(1, -1, 1);
    transform.translate(0, -1);

    return copyImageInto(hwBitmap->makeImage(), transform, srcRect, bitmap);
}
@@ -280,8 +278,6 @@ CopyResult Readback::copyLayerInto(DeferredLayerUpdater* deferredLayer, SkBitmap
CopyResult Readback::copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap) {
    Rect srcRect;
    Matrix4 transform;
    transform.loadScale(1, -1, 1);
    transform.translate(0, -1);
    return copyImageInto(image, transform, srcRect, bitmap);
}

@@ -320,7 +316,6 @@ CopyResult Readback::copyImageInto(const sk_sp<SkImage>& image, Matrix4& texTran

    Layer layer(mRenderThread.renderState(), nullptr, 255, SkBlendMode::kSrc);
    layer.setSize(displayedWidth, displayedHeight);
    texTransform.copyTo(layer.getTexTransform());
    layer.setImage(image);
    // Scaling filter is not explicitly set here, because it is done inside copyLayerInfo
    // after checking the necessity based on the src/dest rect size and the transformation.
Loading