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

Unified Diff: src/image/SkImage_Raster.cpp

Issue 1778393002: add Make variations to return SkImage by sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: roll in fmalitas comments Created 4 years, 9 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
Index: src/image/SkImage_Raster.cpp
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 5bd0e1d8f17b2977f860759c3496e6558b60fdc2..7f2f5c07ef71ed0e14348c72e4c71bb0d46b7fe9 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -63,7 +63,7 @@ public:
return true;
}
- SkImage_Raster(const SkImageInfo&, SkData*, size_t rb, SkColorTable*);
+ SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*);
virtual ~SkImage_Raster();
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
@@ -71,7 +71,7 @@ public:
SkData* onRefEncoded(GrContext*) const override;
bool getROPixels(SkBitmap*, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
- SkImage* onNewSubset(const SkIRect&) const override;
+ sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size_t rowBytes);
@@ -110,14 +110,13 @@ static void release_data(void* addr, void* context) {
data->unref();
}
-SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
+SkImage_Raster::SkImage_Raster(const Info& info, sk_sp<SkData> data, size_t rowBytes,
SkColorTable* ctable)
: INHERITED(info.width(), info.height(), kNeedNewImageUniqueID)
{
- data->ref();
void* addr = const_cast<void*>(data->data());
- fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data);
+ fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data.release());
fBitmap.setImmutable();
fBitmap.lockPixels();
}
@@ -173,7 +172,7 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrTextureParams& p
return nullptr;
}
-SkImage* SkImage_Raster::onNewSubset(const SkIRect& subset) const {
+sk_sp<SkImage> SkImage_Raster::onMakeSubset(const SkIRect& subset) const {
// TODO : could consider heurist of sharing pixels, if subset is pretty close to complete
SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), fBitmap.alphaType());
@@ -184,25 +183,26 @@ SkImage* SkImage_Raster::onNewSubset(const SkIRect& subset) const {
surface->getCanvas()->clear(0);
surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToScalar(-subset.y()),
nullptr);
- return surface->newImageSnapshot();
+ return sk_sp<SkImage>(surface->newImageSnapshot());
}
///////////////////////////////////////////////////////////////////////////////
-SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes,
- SkColorTable* ctable) {
+sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) {
size_t size;
- if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable != nullptr, &size) || !pixels) {
+ if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(),
+ pmap.ctable() != nullptr, &size) || !pmap.addr()) {
return nullptr;
}
// Here we actually make a copy of the caller's pixel data
- SkAutoDataUnref data(SkData::NewWithCopy(pixels, size));
- return new SkImage_Raster(info, data, rowBytes, ctable);
+ sk_sp<SkData> data(SkData::NewWithCopy(pmap.addr(), size));
+ return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes(), pmap.ctable());
}
-SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t rowBytes) {
+sk_sp<SkImage> SkImage::MakeRasterData(const SkImageInfo& info, sk_sp<SkData> data,
+ size_t rowBytes) {
size_t size;
if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) {
return nullptr;
@@ -214,30 +214,29 @@ SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro
}
SkColorTable* ctable = nullptr;
- return new SkImage_Raster(info, data, rowBytes, ctable);
+ return sk_make_sp<SkImage_Raster>(info, std::move(data), rowBytes, ctable);
}
-SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, size_t rowBytes,
- RasterReleaseProc proc, ReleaseContext ctx) {
+sk_sp<SkImage> SkImage::MakeFromRaster(const SkPixmap& pmap, RasterReleaseProc proc,
+ ReleaseContext ctx) {
size_t size;
- if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !pixels) {
+ if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), false, &size) || !pmap.addr()) {
return nullptr;
}
- SkColorTable* ctable = nullptr;
- SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx));
- return new SkImage_Raster(info, data, rowBytes, ctable);
+ sk_sp<SkData> data(SkData::NewWithProc(pmap.addr(), size, proc, ctx));
+ return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes(), pmap.ctable());
}
-SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
- const SkIPoint& pixelRefOrigin, size_t rowBytes) {
+sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
+ const SkIPoint& pixelRefOrigin, size_t rowBytes) {
if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) {
return nullptr;
}
- return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes);
+ return sk_make_sp<SkImage_Raster>(info, pr, pixelRefOrigin, rowBytes);
}
-SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
+sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
SkASSERT(nullptr == bm.getTexture());
bool hasColorTable = false;
@@ -250,16 +249,16 @@ SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy)
return nullptr;
}
- SkImage* image = nullptr;
+ sk_sp<SkImage> image;
if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
SkBitmap tmp(bm);
tmp.lockPixels();
- if (tmp.getPixels()) {
- image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowBytes(),
- tmp.getColorTable());
+ SkPixmap pmap;
+ if (tmp.getPixels() && tmp.peekPixels(&pmap)) {
+ image = SkImage::MakeRasterCopy(pmap);
}
} else {
- image = new SkImage_Raster(bm);
+ image = sk_make_sp<SkImage_Raster>(bm);
}
return image;
}

Powered by Google App Engine
This is Rietveld 408576698