| Index: src/image/SkImage.cpp
|
| diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
|
| index 5521b6e305fddf0cc54663f82df30ff712c12aab..453ecb08ee150ed0956cd554df87b56429d03d31 100644
|
| --- a/src/image/SkImage.cpp
|
| +++ b/src/image/SkImage.cpp
|
| @@ -89,6 +89,55 @@ void SkImage::preroll(GrContext* ctx) const {
|
| }
|
| }
|
|
|
| +SkImageTextureData* SkImage::newImageTextureData(
|
| + const GrContextThreadSafeProxy& proxy,
|
| + const std::function<void*(size_t, const SkImage*)>& allocate) const {
|
| + SkPixmap pixmap;
|
| + if (!this->peekPixels(&pixmap)) {
|
| + return nullptr;
|
| + }
|
| + size_t size = 0;
|
| + size_t itdSize = SkAlign8(sizeof(SkImageTextureData));
|
| + size += itdSize;
|
| + size_t pixelOffset = size;
|
| + size_t pixelSize = SkAlign8(pixmap.getSafeSize());
|
| + size += pixelSize;
|
| + size_t ctOffset = size;
|
| + int ctCount = 0;
|
| + size_t ctSize = 0;
|
| + if (pixmap.ctable()) {
|
| + ctCount = pixmap.ctable()->count();
|
| + ctSize = SkAlign8(pixmap.ctable()->count() * 4);
|
| + size += ctSize;
|
| + }
|
| + intptr_t allocation = reinterpret_cast<intptr_t>(allocate(size, this));
|
| + void* itd = reinterpret_cast<void*>(allocation);
|
| + void* pixels = reinterpret_cast<void*>(allocation + pixelOffset);
|
| + SkPMColor* ct = nullptr;
|
| + if (ctSize) {
|
| + ct = reinterpret_cast<SkPMColor*>(allocation + ctOffset);
|
| + }
|
| +
|
| + memcpy(pixels, pixmap.addr(), pixmap.getSafeSize());
|
| + if (ctSize) {
|
| + memcpy(ct, pixmap.ctable()->readColors(), ctSize);
|
| + }
|
| +
|
| + const SkImageInfo& info = pixmap.info();
|
| + size_t rowBytes = pixmap.rowBytes();
|
| + SkImageTextureData* textureData = new (itd) SkImageTextureData();
|
| + textureData->fContextUniqueID = proxy.fContextUniqueID;
|
| + textureData->fImageUniqueID = this->uniqueID();
|
| + textureData->fPixmapGenerator = [info, pixels, rowBytes, ct, ctCount] (SkPixmap* pixmap) {
|
| + SkAutoTUnref<SkColorTable> colorTable;
|
| + if (ct) {
|
| + colorTable.reset(new SkColorTable(ct, ctCount));
|
| + }
|
| + pixmap->reset(info, pixels, rowBytes, colorTable.get());
|
| + };
|
| + return textureData;
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
| SkShader* SkImage::newShader(SkShader::TileMode tileX,
|
|
|