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

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

Merge "lockPixels is no longer virtual"

parents 293ac8ce 2cb0826d
Loading
Loading
Loading
Loading
+16 −31
Original line number Original line Diff line number Diff line
@@ -323,19 +323,13 @@ sk_sp<Bitmap> Bitmap::createFrom(sp<GraphicBuffer> graphicBuffer) {
}
}


void Bitmap::setColorSpace(sk_sp<SkColorSpace> colorSpace) {
void Bitmap::setColorSpace(sk_sp<SkColorSpace> colorSpace) {
    // TODO: See todo in reconfigure() below
    reconfigure(info().makeColorSpace(std::move(colorSpace)), rowBytes(), colorTable());
    SkImageInfo* myInfo = const_cast<SkImageInfo*>(&this->info());
    *myInfo = info().makeColorSpace(std::move(colorSpace));
}
}


void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) {
void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) {
    if (kIndex_8_SkColorType != newInfo.colorType()) {
    if (kIndex_8_SkColorType != newInfo.colorType()) {
        ctable = nullptr;
        ctable = nullptr;
    }
    }
    mRowBytes = rowBytes;
    if (mColorTable.get() != ctable) {
        mColorTable.reset(SkSafeRef(ctable));
    }


    // Need to validate the alpha type to filter against the color type
    // Need to validate the alpha type to filter against the color type
    // to prevent things like a non-opaque RGB565 bitmap
    // to prevent things like a non-opaque RGB565 bitmap
@@ -349,50 +343,48 @@ void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTab
    // really hard to work with. Skia really, really wants immutable objects,
    // really hard to work with. Skia really, really wants immutable objects,
    // but with the nested-ref-count hackery going on that's just not
    // but with the nested-ref-count hackery going on that's just not
    // feasible without going insane trying to figure it out
    // feasible without going insane trying to figure it out
    SkImageInfo* myInfo = const_cast<SkImageInfo*>(&this->info());
    this->android_only_reset(newInfo.makeAlphaType(alphaType), rowBytes, sk_ref_sp(ctable));
    *myInfo = newInfo;
    changeAlphaType(alphaType);

    // Docs say to only call this in the ctor, but we're going to call
    // it anyway even if this isn't always the ctor.
    // TODO: Fix this too as part of the above TODO
    setPreLocked(getStorage(), mRowBytes, mColorTable.get());
}
}


static sk_sp<SkColorTable> sanitize(const SkImageInfo& info, SkColorTable* ctable) {
    if (info.colorType() == kIndex_8_SkColorType) {
        SkASSERT(ctable);
        return sk_ref_sp(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)
Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
            , mPixelStorageType(PixelStorageType::Heap) {
            , mPixelStorageType(PixelStorageType::Heap) {
    mPixelStorage.heap.address = address;
    mPixelStorage.heap.address = address;
    mPixelStorage.heap.size = size;
    mPixelStorage.heap.size = size;
    reconfigure(info, rowBytes, ctable);
}
}


Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
            , mPixelStorageType(PixelStorageType::External) {
            , mPixelStorageType(PixelStorageType::External) {
    mPixelStorage.external.address = address;
    mPixelStorage.external.address = address;
    mPixelStorage.external.context = context;
    mPixelStorage.external.context = context;
    mPixelStorage.external.freeFunc = freeFunc;
    mPixelStorage.external.freeFunc = freeFunc;
    reconfigure(info, rowBytes, ctable);
}
}


Bitmap::Bitmap(void* address, int fd, size_t mappedSize,
Bitmap::Bitmap(void* address, int fd, size_t mappedSize,
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
                const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
            : SkPixelRef(info)
            : SkPixelRef(info, address, rowBytes, sanitize(info, ctable))
            , mPixelStorageType(PixelStorageType::Ashmem) {
            , mPixelStorageType(PixelStorageType::Ashmem) {
    mPixelStorage.ashmem.address = address;
    mPixelStorage.ashmem.address = address;
    mPixelStorage.ashmem.fd = fd;
    mPixelStorage.ashmem.fd = fd;
    mPixelStorage.ashmem.size = mappedSize;
    mPixelStorage.ashmem.size = mappedSize;
    reconfigure(info, rowBytes, ctable);
}
}


Bitmap::Bitmap(GraphicBuffer* buffer, const SkImageInfo& info)
Bitmap::Bitmap(GraphicBuffer* buffer, const SkImageInfo& info)
        : SkPixelRef(info)
        : SkPixelRef(info, nullptr,
                     bytesPerPixel(buffer->getPixelFormat()) * buffer->getStride(),
                     nullptr)
        , mPixelStorageType(PixelStorageType::Hardware) {
        , mPixelStorageType(PixelStorageType::Hardware) {
    mPixelStorage.hardware.buffer = buffer;
    mPixelStorage.hardware.buffer = buffer;
    buffer->incStrong(buffer);
    buffer->incStrong(buffer);
    mRowBytes = bytesPerPixel(buffer->getPixelFormat()) * buffer->getStride();
}
}


Bitmap::~Bitmap() {
Bitmap::~Bitmap() {
@@ -442,15 +434,8 @@ void* Bitmap::getStorage() const {
    }
    }
}
}


bool Bitmap::onNewLockPixels(LockRec* rec) {
    rec->fPixels = getStorage();
    rec->fRowBytes = mRowBytes;
    rec->fColorTable = mColorTable.get();
    return true;
}

size_t Bitmap::getAllocatedSizeInBytes() const {
size_t Bitmap::getAllocatedSizeInBytes() const {
    return info().getSafeSize(mRowBytes);
    return info().getSafeSize(this->rowBytes());
}
}


int Bitmap::getAshmemFd() const {
int Bitmap::getAshmemFd() const {
+2 −13
Original line number Original line Diff line number Diff line
@@ -70,15 +70,8 @@ public:
    int width() const { return info().width(); }
    int width() const { return info().width(); }
    int height() const { return info().height(); }
    int height() const { return info().height(); }


    // Can't mark as override since SkPixelRef::rowBytes isn't virtual
    // but that's OK since we just want Bitmap to be able to rely
    // on calling rowBytes() on an unlocked pixelref, which it will be
    // doing on a Bitmap type, not a SkPixelRef, so static
    // dispatching will do what we want.
    size_t rowBytes() const { return mRowBytes; }

    int rowBytesAsPixels() const {
    int rowBytesAsPixels() const {
        return mRowBytes >> info().shiftPerPixel();
        return rowBytes() >> info().shiftPerPixel();
    }
    }


    void reconfigure(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
    void reconfigure(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
@@ -103,7 +96,7 @@ public:
    void getBounds(SkRect* bounds) const;
    void getBounds(SkRect* bounds) const;


    bool readyToDraw() const {
    bool readyToDraw() const {
        return this->colorType() != kIndex_8_SkColorType || mColorTable;
        return this->colorType() != kIndex_8_SkColorType || this->colorTable();
    }
    }


    bool isHardware() const {
    bool isHardware() const {
@@ -112,8 +105,6 @@ public:


    GraphicBuffer* graphicBuffer();
    GraphicBuffer* graphicBuffer();
protected:
protected:
    virtual bool onNewLockPixels(LockRec* rec) override;
    virtual void onUnlockPixels() override { };
    virtual size_t getAllocatedSizeInBytes() const override;
    virtual size_t getAllocatedSizeInBytes() const override;
private:
private:
    Bitmap(GraphicBuffer* buffer, const SkImageInfo& info);
    Bitmap(GraphicBuffer* buffer, const SkImageInfo& info);
@@ -122,8 +113,6 @@ private:


    const PixelStorageType mPixelStorageType;
    const PixelStorageType mPixelStorageType;


    size_t mRowBytes = 0;
    sk_sp<SkColorTable> mColorTable;
    bool mHasHardwareMipMap = false;
    bool mHasHardwareMipMap = false;


    union {
    union {