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

Commit dbbc74cf authored by Ben Wagner's avatar Ben Wagner
Browse files

Clean up Bitmap allocation size computation.

In addition to making this do what is intended in both debug and
release, this removes some of the last uses of sk_64_isS32 and
sk_64_asS32 so that they can be removed.

Test: refactoring CL. Existing unit tests still pass.
Change-Id: I4cd9fb124719f8e7e23db6bf268cbda64c29d283
parent 38628f3f
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -33,17 +33,16 @@
#include <SkImagePriv.h>
#include <SkToSRGBColorFilter.h>

#include <limits>

namespace android {

// returns true if rowBytes * height can be represented by a positive int32_t value
// and places that value in size.
static bool computeAllocationSize(size_t rowBytes, int height, size_t* size) {
    int32_t rowBytes32 = SkToS32(rowBytes);
    int64_t bigSize = (int64_t)height * rowBytes32;
    if (rowBytes32 < 0 || !sk_64_isS32(bigSize)) {
        return false;  // allocation will be too large
    }

    *size = sk_64_asS32(bigSize);
    return true;
    return 0 <= height && height <= std::numeric_limits<size_t>::max() &&
           !__builtin_mul_overflow(rowBytes, (size_t)height, size) &&
           *size <= std::numeric_limits<int32_t>::max();
}

typedef sk_sp<Bitmap> (*AllocPixelRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes);