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

Commit 9552a623 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Shrink by 0.5 for YUV TextViews"

parents 31392b91 8df7f3c9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ void DeferredLayerUpdater::apply() {
                sk_sp<SkImage> layerImage = mImageSlots[slot].createIfNeeded(
                        hardwareBuffer, dataspace, newContent,
                        mRenderState.getRenderThread().getGrContext());
                AHardwareBuffer_Desc bufferDesc;
                AHardwareBuffer_describe(hardwareBuffer, &bufferDesc);
                // unref to match the ref added by ASurfaceTexture_dequeueBuffer. eglCreateImageKHR
                // (invoked by createIfNeeded) will add a ref to the AHardwareBuffer.
                AHardwareBuffer_release(hardwareBuffer);
@@ -189,6 +191,7 @@ void DeferredLayerUpdater::apply() {
                        maxLuminanceNits =
                                std::max(cta861_3.maxContentLightLevel, maxLuminanceNits);
                    }
                    mLayer->setBufferFormat(bufferDesc.format);
                    updateLayer(forceFilter, layerImage, outTransform, currentCropRect,
                                maxLuminanceNits);
                }
+6 −0
Original line number Diff line number Diff line
@@ -102,6 +102,10 @@ public:

    inline float getMaxLuminanceNits() { return mMaxLuminanceNits; }

    void setBufferFormat(uint32_t format) { mBufferFormat = format; }

    uint32_t getBufferFormat() const { return mBufferFormat; }

    void draw(SkCanvas* canvas);

protected:
@@ -169,6 +173,8 @@ private:
     */
    float mMaxLuminanceNits = -1;

    uint32_t mBufferFormat = 0;

};  // struct Layer

}  // namespace uirenderer
+27 −0
Original line number Diff line number Diff line
@@ -107,6 +107,32 @@ static bool isHdrDataspace(ui::Dataspace dataspace) {
    return transfer == HAL_DATASPACE_TRANSFER_ST2084 || transfer == HAL_DATASPACE_TRANSFER_HLG;
}

static void adjustCropForYUV(uint32_t format, int bufferWidth, int bufferHeight, SkRect* cropRect) {
    // Chroma channels of YUV420 images are subsampled we may need to shrink the crop region by
    // a whole texel on each side. Since skia still adds its own 0.5 inset, we apply an
    // additional 0.5 inset. See GLConsumer::computeTransformMatrix for details.
    float shrinkAmount = 0.0f;
    switch (format) {
        // Use HAL formats since some AHB formats are only available in vndk
        case HAL_PIXEL_FORMAT_YCBCR_420_888:
        case HAL_PIXEL_FORMAT_YV12:
        case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
            shrinkAmount = 0.5f;
            break;
        default:
            break;
    }

    // Shrink the crop if it has more than 1-px and differs from the buffer size.
    if (cropRect->width() > 1 && cropRect->width() < bufferWidth) {
        cropRect->inset(shrinkAmount, 0);
    }

    if (cropRect->height() > 1 && cropRect->height() < bufferHeight) {
        cropRect->inset(0, shrinkAmount);
    }
}

// TODO: Context arg probably doesn't belong here – do debug check at callsite instead.
bool LayerDrawable::DrawLayer(GrRecordingContext* context,
                              SkCanvas* canvas,
@@ -142,6 +168,7 @@ bool LayerDrawable::DrawLayer(GrRecordingContext* context,
        SkRect skiaSrcRect;
        if (srcRect && !srcRect->isEmpty()) {
            skiaSrcRect = *srcRect;
            adjustCropForYUV(layer->getBufferFormat(), imageWidth, imageHeight, &skiaSrcRect);
        } else {
            skiaSrcRect = SkRect::MakeIWH(imageWidth, imageHeight);
        }