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

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

Merge "use sk_sp to manage colortables"

parents bcc7cebc 0a8fb522
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -1058,7 +1058,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
        return NULL;
    }

    SkColorTable* ctable = NULL;
    sk_sp<SkColorTable> ctable = NULL;
    if (colorType == kIndex_8_SkColorType) {
        int count = p->readInt32();
        if (count < 0 || count > 256) {
@@ -1072,7 +1072,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
            if (src == NULL) {
                return NULL;
            }
            ctable = new SkColorTable(src, count);
            ctable = SkColorTable::Make(src, count);
        }
    }

@@ -1081,7 +1081,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
    android::Parcel::ReadableBlob blob;
    android::status_t status = p->readBlob(size, &blob);
    if (status) {
        SkSafeUnref(ctable);
        doThrowRE(env, "Could not read bitmap blob.");
        return NULL;
    }
@@ -1102,15 +1101,13 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
        if (dupFd < 0) {
            ALOGE("Error allocating dup fd. Error:%d", errno);
            blob.release();
            SkSafeUnref(ctable);
            doThrowRE(env, "Could not allocate dup blob fd.");
            return NULL;
        }

        // Map the pixels in place and take ownership of the ashmem region.
        nativeBitmap = sk_sp<Bitmap>(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(),
                ctable, dupFd, const_cast<void*>(blob.data()), size, !isMutable));
        SkSafeUnref(ctable);
                ctable.get(), dupFd, const_cast<void*>(blob.data()), size, !isMutable));
        if (!nativeBitmap) {
            close(dupFd);
            blob.release();
@@ -1136,7 +1133,6 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {

        // Copy the pixels into a new buffer.
        nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get(), ctable);
        SkSafeUnref(ctable);
        if (!nativeBitmap) {
            blob.release();
            doThrowRE(env, "Could not allocate java pixel ref.");
+1 −1
Original line number Diff line number Diff line
@@ -195,7 +195,7 @@ public:
            return false;
        }

        mBitmap->reconfigure(info, bitmap->rowBytes(), ctable);
        mBitmap->reconfigure(info, bitmap->rowBytes(), sk_ref_sp(ctable));
        bitmap->setPixelRef(sk_ref_sp(mBitmap), 0, 0);

        // since we're already allocated, we lockPixels right away
+4 −4
Original line number Diff line number Diff line
@@ -456,7 +456,7 @@ android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap,
    // attempting to compute our own.
    const size_t rowBytes = bitmap->rowBytes();

    auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, ctable);
    auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, sk_ref_sp(ctable));
    wrapper->getSkBitmap(bitmap);
    if (readOnly) {
        bitmap->pixelRef()->setImmutable();
@@ -614,7 +614,7 @@ jobject GraphicsJNI::getColorSpace(JNIEnv* env, sk_sp<SkColorSpace>& decodeColor

///////////////////////////////////////////////////////////////////////////////
bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
    mStorage = android::Bitmap::allocateHeapBitmap(bitmap, ctable);
    mStorage = android::Bitmap::allocateHeapBitmap(bitmap, sk_ref_sp(ctable));
    return !!mStorage;
}

@@ -658,7 +658,7 @@ bool RecyclingClippingPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTab
        // mRecycledBitmap->info() for the SkImageInfo.  According to the
        // specification for BitmapRegionDecoder, we are not allowed to change
        // the SkImageInfo.
        mRecycledBitmap->reconfigure(mRecycledBitmap->info(), rowBytes, ctable);
        mRecycledBitmap->reconfigure(mRecycledBitmap->info(), rowBytes, sk_ref_sp(ctable));

        // Give the bitmap the same pixelRef as mRecycledBitmap.
        // skbug.com/4538: We also need to make sure that the rowBytes on the pixel ref
@@ -718,7 +718,7 @@ AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) {
}

bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
    mStorage = android::Bitmap::allocateAshmemBitmap(bitmap, ctable);
    mStorage = android::Bitmap::allocateAshmemBitmap(bitmap, sk_ref_sp(ctable));
    return !!mStorage;
}

+23 −23
Original line number Diff line number Diff line
@@ -51,9 +51,9 @@ static bool computeAllocationSize(size_t rowBytes, int height, size_t* size) {
}

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

static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, SkColorTable* ctable, AllocPixeRef alloc) {
static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable, AllocPixeRef alloc) {
    const SkImageInfo& info = bitmap->info();
    if (info.colorType() == kUnknown_SkColorType) {
        LOG_ALWAYS_FATAL("unknown bitmap configuration");
@@ -69,7 +69,7 @@ static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, SkColorTable* ctable, Allo
        return nullptr;
    }

    auto wrapper = alloc(size, info, rowBytes, ctable);
    auto wrapper = alloc(size, info, rowBytes, std::move(ctable));
    if (wrapper) {
        wrapper->getSkBitmap(bitmap);
        // since we're already allocated, we lockPixels right away
@@ -79,17 +79,17 @@ static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, SkColorTable* ctable, Allo
    return wrapper;
}

sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable) {
   return allocateBitmap(bitmap, ctable, &Bitmap::allocateAshmemBitmap);
sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable) {
   return allocateBitmap(bitmap, std::move(ctable), &Bitmap::allocateAshmemBitmap);
}

static sk_sp<Bitmap> allocateHeapBitmap(size_t size, const SkImageInfo& info, size_t rowBytes,
        SkColorTable* ctable) {
        sk_sp<SkColorTable> ctable) {
    void* addr = calloc(size, 1);
    if (!addr) {
        return nullptr;
    }
    return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes, ctable));
    return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes, std::move(ctable)));
}

#define FENCE_TIMEOUT 2000000000
@@ -262,8 +262,8 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(SkBitmap& bitmap) {
    return uirenderer::renderthread::RenderProxy::allocateHardwareBitmap(bitmap);
}

sk_sp<Bitmap> Bitmap::allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable) {
   return allocateBitmap(bitmap, ctable, &android::allocateHeapBitmap);
sk_sp<Bitmap> Bitmap::allocateHeapBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable) {
   return allocateBitmap(bitmap, std::move(ctable), &android::allocateHeapBitmap);
}

sk_sp<Bitmap> Bitmap::allocateHeapBitmap(const SkImageInfo& info) {
@@ -276,7 +276,7 @@ sk_sp<Bitmap> Bitmap::allocateHeapBitmap(const SkImageInfo& info) {
}

sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info,
        size_t rowBytes, SkColorTable* ctable) {
        size_t rowBytes, sk_sp<SkColorTable> ctable) {
    // Create new ashmem region with read/write priv
    int fd = ashmem_create_region("bitmap", size);
    if (fd < 0) {
@@ -294,7 +294,7 @@ sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info,
        close(fd);
        return nullptr;
    }
    return sk_sp<Bitmap>(new Bitmap(addr, fd, size, info, rowBytes, ctable));
    return sk_sp<Bitmap>(new Bitmap(addr, fd, size, info, rowBytes, std::move(ctable)));
}

void FreePixelRef(void* addr, void* context) {
@@ -307,7 +307,7 @@ sk_sp<Bitmap> Bitmap::createFrom(const SkImageInfo& info, SkPixelRef& pixelRef)
    pixelRef.ref();
    pixelRef.lockPixels();
    return sk_sp<Bitmap>(new Bitmap((void*) pixelRef.pixels(), (void*) &pixelRef, FreePixelRef,
            info, pixelRef.rowBytes(), pixelRef.colorTable()));
            info, pixelRef.rowBytes(), sk_ref_sp(pixelRef.colorTable())));
}

sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer) {
@@ -323,10 +323,10 @@ sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer) {
}

void Bitmap::setColorSpace(sk_sp<SkColorSpace> colorSpace) {
    reconfigure(info().makeColorSpace(std::move(colorSpace)), rowBytes(), colorTable());
    reconfigure(info().makeColorSpace(std::move(colorSpace)), rowBytes(), sk_ref_sp(colorTable()));
}

void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) {
void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, sk_sp<SkColorTable> ctable) {
    if (kIndex_8_SkColorType != newInfo.colorType()) {
        ctable = nullptr;
    }
@@ -343,26 +343,26 @@ void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTab
    // really hard to work with. Skia really, really wants immutable objects,
    // but with the nested-ref-count hackery going on that's just not
    // feasible without going insane trying to figure it out
    this->android_only_reset(newInfo.makeAlphaType(alphaType), rowBytes, sk_ref_sp(ctable));
    this->android_only_reset(newInfo.makeAlphaType(alphaType), rowBytes, std::move(ctable));
}

static sk_sp<SkColorTable> sanitize(const SkImageInfo& info, SkColorTable* ctable) {
static sk_sp<SkColorTable> sanitize(const SkImageInfo& info, sk_sp<SkColorTable> ctable) {
    if (info.colorType() == kIndex_8_SkColorType) {
        SkASSERT(ctable);
        return sk_ref_sp(ctable);
        return ctable;
    }
    return nullptr; // drop the ctable if we're not indexed
}
Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, std::move(ctable)))
            , mPixelStorageType(PixelStorageType::Heap) {
    mPixelStorage.heap.address = address;
    mPixelStorage.heap.size = size;
}

Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
                const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, std::move(ctable)))
            , mPixelStorageType(PixelStorageType::External) {
    mPixelStorage.external.address = address;
    mPixelStorage.external.context = context;
@@ -370,8 +370,8 @@ Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
}

Bitmap::Bitmap(void* address, int fd, size_t mappedSize,
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
                const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable)
            : SkPixelRef(info, address, rowBytes, sanitize(info, std::move(ctable)))
            , mPixelStorageType(PixelStorageType::Ashmem) {
    mPixelStorage.ashmem.address = address;
    mPixelStorage.ashmem.fd = fd;
+7 −7
Original line number Diff line number Diff line
@@ -44,14 +44,14 @@ typedef void (*FreeFunc)(void* addr, void* context);

class ANDROID_API Bitmap : public SkPixelRef {
public:
    static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable);
    static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable);
    static sk_sp<Bitmap> allocateHeapBitmap(const SkImageInfo& info);

    static sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& bitmap);

    static sk_sp<Bitmap> allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable);
    static sk_sp<Bitmap> allocateAshmemBitmap(SkBitmap* bitmap, sk_sp<SkColorTable> ctable);
    static sk_sp<Bitmap> allocateAshmemBitmap(size_t allocSize, const SkImageInfo& info,
        size_t rowBytes, SkColorTable* ctable);
        size_t rowBytes, sk_sp<SkColorTable> ctable);

    static sk_sp<Bitmap> createFrom(sp<GraphicBuffer> graphicBuffer);

@@ -61,11 +61,11 @@ public:
            SkBitmap& bitmap);

    Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes,
            SkColorTable* ctable);
            sk_sp<SkColorTable> ctable);
    Bitmap(void* address, void* context, FreeFunc freeFunc,
            const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
            const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable);
    Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info,
            size_t rowBytes, SkColorTable* ctable);
            size_t rowBytes, sk_sp<SkColorTable> ctable);

    int width() const { return info().width(); }
    int height() const { return info().height(); }
@@ -74,7 +74,7 @@ public:
        return rowBytes() >> info().shiftPerPixel();
    }

    void reconfigure(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
    void reconfigure(const SkImageInfo& info, size_t rowBytes, sk_sp<SkColorTable> ctable);
    void reconfigure(const SkImageInfo& info);
    void setColorSpace(sk_sp<SkColorSpace> colorSpace);
    void setAlphaType(SkAlphaType alphaType);
Loading