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

Commit 3d334d81 authored by Leon Scroggins III's avatar Leon Scroggins III Committed by Leon Scroggins
Browse files

Make Bitmap::createFrom() account for zero stride

Bug: 143470518
Test: android.graphics.cts.ImageDecoderTest#testConserveMemoryPlusHardware

Follow up to ag/10045682, which was resolving a merge conflict. The
original fix (https://android-review.googlesource.com/1203783) was
on the single Bitmap constructor which took a GraphicBuffer parameter.
The conflict was with ag/9130111, which switched the input to an
AHardwareBuffer and split this version of Bitmap::createFrom into two
methods. The constructor no longer has access to the information
regarding the buffer stride, so that got moved into Bitmap::createFrom.
But both versions should have the fix. (In fact, it appears that the
version that did *not* have the fix is the one being called in
testConserveMemoryPlusHardware.)

Move the rowBytes computation into a common method so that both will
have the fix.

Change-Id: I16f77528abdb331af556bbe5d0485fe342f2325e
parent b96b334d
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -150,11 +150,7 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, sk_sp<SkColorS
    AHardwareBuffer_Desc bufferDesc;
    AHardwareBuffer_describe(hardwareBuffer, &bufferDesc);
    SkImageInfo info = uirenderer::BufferDescriptionToImageInfo(bufferDesc, colorSpace);

    // 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));
    return createFrom(hardwareBuffer, info, bufferDesc, palette);
}

sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, SkColorType colorType,
@@ -164,8 +160,14 @@ sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, SkColorType co
    AHardwareBuffer_describe(hardwareBuffer, &bufferDesc);
    SkImageInfo info = SkImageInfo::Make(bufferDesc.width, bufferDesc.height,
                                         colorType, alphaType, colorSpace);
    return createFrom(hardwareBuffer, info, bufferDesc, palette);
}

    const size_t rowBytes = info.bytesPerPixel() * bufferDesc.stride;
sk_sp<Bitmap> Bitmap::createFrom(AHardwareBuffer* hardwareBuffer, const SkImageInfo& info,
                                 const AHardwareBuffer_Desc& bufferDesc, BitmapPalette palette) {
    // 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));
}
#endif
+6 −0
Original line number Diff line number Diff line
@@ -169,6 +169,12 @@ private:
#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
    Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes,
           BitmapPalette palette);

    // Common code for the two public facing createFrom(AHardwareBuffer*, ...)
    // methods.
    // bufferDesc is only used to compute rowBytes.
    static sk_sp<Bitmap> createFrom(AHardwareBuffer* hardwareBuffer, const SkImageInfo& info,
                                    const AHardwareBuffer_Desc& bufferDesc, BitmapPalette palette);
#endif

    virtual ~Bitmap();