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

Commit ffd8cb89 authored by Anders Frostad Pedersen's avatar Anders Frostad Pedersen Committed by John Reck
Browse files

Allow zero stride

For some pixel formats, stride has no meaning.
Take this into account and use buffer width instead.

Bug: 143470518
Change-Id: I728b40803e80c4e534504c5b9db55921bb5e7dbc
Test: android.graphics.cts.ImageDecoderTest#testConserveMemoryPlusHardware
parent df1b6de0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -152,7 +152,9 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, sk_sp<SkColorS
    AHardwareBuffer_describe(hardwareBuffer, &bufferDesc);
    SkImageInfo info = uirenderer::BufferDescriptionToImageInfo(bufferDesc, colorSpace);

    const size_t rowBytes = info.bytesPerPixel() * bufferDesc.stride;
    // If the stride is 0 we have to use the width as an approximation (eg, compressed buffer)
    const auto bufferStride = bufferDesc.stride > 0 ? bufferDesc.stride : bufferDesc.width;
    const size_t rowBytes = info.bytesPerPixel() * bufferStride;
    return sk_sp<Bitmap>(new Bitmap(hardwareBuffer, info, rowBytes, palette));
}