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

Commit d354e11a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Simplify Bitmap a bit"

parents df873621 d0a79555
Loading
Loading
Loading
Loading
+8 −31
Original line number Diff line number Diff line
@@ -131,15 +131,8 @@ sk_sp<Bitmap> Bitmap::allocateHeapBitmap(size_t size, const SkImageInfo& info, s
    return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes));
}

void FreePixelRef(void* addr, void* context) {
    auto pixelRef = (SkPixelRef*)context;
    pixelRef->unref();
}

sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, SkPixelRef& pixelRef) {
    pixelRef.ref();
    return sk_sp<Bitmap>(new Bitmap((void*)pixelRef.pixels(), (void*)&pixelRef, FreePixelRef, info,
                                    pixelRef.rowBytes()));
    return sk_sp<Bitmap>(new Bitmap(pixelRef, info));
}


@@ -232,14 +225,12 @@ Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBy
    mPixelStorage.heap.size = size;
}

Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info,
               size_t rowBytes)
        : SkPixelRef(info.width(), info.height(), address, rowBytes)
Bitmap::Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info)
        : SkPixelRef(info.width(), info.height(), pixelRef.pixels(), pixelRef.rowBytes())
        , mInfo(validateAlpha(info))
        , mPixelStorageType(PixelStorageType::External) {
    mPixelStorage.external.address = address;
    mPixelStorage.external.context = context;
    mPixelStorage.external.freeFunc = freeFunc;
        , mPixelStorageType(PixelStorageType::WrappedPixelRef) {
    pixelRef.ref();
    mPixelStorage.wrapped.pixelRef = &pixelRef;
}

Bitmap::Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes)
@@ -268,9 +259,8 @@ Bitmap::Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes

Bitmap::~Bitmap() {
    switch (mPixelStorageType) {
        case PixelStorageType::External:
            mPixelStorage.external.freeFunc(mPixelStorage.external.address,
                                            mPixelStorage.external.context);
        case PixelStorageType::WrappedPixelRef:
            mPixelStorage.wrapped.pixelRef->unref();
            break;
        case PixelStorageType::Ashmem:
#ifndef _WIN32 // ashmem not implemented on Windows
@@ -302,19 +292,6 @@ void Bitmap::setHasHardwareMipMap(bool hasMipMap) {
    mHasHardwareMipMap = hasMipMap;
}

void* Bitmap::getStorage() const {
    switch (mPixelStorageType) {
        case PixelStorageType::External:
            return mPixelStorage.external.address;
        case PixelStorageType::Ashmem:
            return mPixelStorage.ashmem.address;
        case PixelStorageType::Heap:
            return mPixelStorage.heap.address;
        case PixelStorageType::Hardware:
            return nullptr;
    }
}

int Bitmap::getAshmemFd() const {
    switch (mPixelStorageType) {
        case PixelStorageType::Ashmem:
+4 −8
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class SkWStream;
namespace android {

enum class PixelStorageType {
    External,
    WrappedPixelRef,
    Heap,
    Ashmem,
    Hardware,
@@ -163,8 +163,7 @@ private:
    static sk_sp<Bitmap> allocateAshmemBitmap(size_t size, const SkImageInfo& i, size_t rowBytes);

    Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes);
    Bitmap(void* address, void* context, FreeFunc freeFunc, const SkImageInfo& info,
           size_t rowBytes);
    Bitmap(SkPixelRef& pixelRef, const SkImageInfo& info);
    Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info, size_t rowBytes);
#ifdef __ANDROID__ // Layoutlib does not support hardware acceleration
    Bitmap(AHardwareBuffer* buffer, const SkImageInfo& info, size_t rowBytes,
@@ -178,7 +177,6 @@ private:
#endif

    virtual ~Bitmap();
    void* getStorage() const;

    SkImageInfo mInfo;

@@ -191,10 +189,8 @@ private:

    union {
        struct {
            void* address;
            void* context;
            FreeFunc freeFunc;
        } external;
            SkPixelRef* pixelRef;
        } wrapped;
        struct {
            void* address;
            int fd;