Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Unified Diff: src/image/SkImage.cpp

Issue 1738513002: start on pre-upload data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: stuff Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698