aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-10 16:18:46 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-10 16:18:46 -0800
commite683c56115a210b5993df9294260bb147b408bfa (patch)
treea544048de0c2e3e693953cc1e5319fff108a68ae /src/image
parentdd67e3d1b3c1e9f400f1ddd37e9e52c8a2952eec (diff)
Revert of add Make variations to return SkImage by sk_sp (patchset #5 id:80001 of https://codereview.chromium.org/1778393002/ )
Reason for revert: Experimental revert to try to clear up ASAN failures Original issue's description: > add Make variations to return SkImage by sk_sp > > some internal call-sites update, but not. Will follow-up in future to complete that. > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1778393002 > > Committed: https://skia.googlesource.com/skia/+/bd73ffb83022f1f6b1997e2a91c049949e88a8a2 TBR=fmalita@chromium.org,bsalomon@google.com,reed@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1783063002
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage.cpp110
-rw-r--r--src/image/SkImagePriv.h9
-rw-r--r--src/image/SkImage_Base.h2
-rw-r--r--src/image/SkImage_Generator.cpp13
-rw-r--r--src/image/SkImage_Gpu.cpp64
-rw-r--r--src/image/SkImage_Gpu.h2
-rw-r--r--src/image/SkImage_Raster.cpp57
-rw-r--r--src/image/SkSurface_Raster.cpp2
8 files changed, 91 insertions, 168 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index ee4491e0b1..a41ac83d19 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -15,7 +15,6 @@
#include "SkImageShader.h"
#include "SkImage_Base.h"
#include "SkNextID.h"
-#include "SkPicture.h"
#include "SkPixelRef.h"
#include "SkPixelSerializer.h"
#include "SkReadPixelsRec.h"
@@ -151,12 +150,12 @@ SkData* SkImage::refEncoded() const {
return as_IB(this)->onRefEncoded(ctx);
}
-sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
+SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
if (nullptr == encoded || 0 == encoded->size()) {
return nullptr;
}
- SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded.get());
- return SkImage::MakeFromGenerator(generator, subset);
+ SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded);
+ return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
}
const char* SkImage::toString(SkString* str) const {
@@ -165,7 +164,7 @@ const char* SkImage::toString(SkString* str) const {
return str->c_str();
}
-sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
+SkImage* SkImage::newSubset(const SkIRect& subset) const {
if (subset.isEmpty()) {
return nullptr;
}
@@ -177,9 +176,9 @@ sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
// optimization : return self if the subset == our bounds
if (bounds == subset) {
- return sk_ref_sp(const_cast<SkImage*>(this));
+ return SkRef(const_cast<SkImage*>(this));
}
- return as_IB(this)->onMakeSubset(subset);
+ return as_IB(this)->onNewSubset(subset);
}
#if SK_SUPPORT_GPU
@@ -284,7 +283,7 @@ bool SkImage::readYUV8Planes(const SkISize sizes[3], void* const planes[3],
///////////////////////////////////////////////////////////////////////////////////////////////////
-sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
+SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
SkPixelRef* pr = bm.pixelRef();
if (nullptr == pr) {
return nullptr;
@@ -301,13 +300,13 @@ sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
- return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenerationID(),
- info.alphaType(), tex, SkBudgeted::kNo);
+ return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
+ tex, SkBudgeted::kNo);
}
#endif
// This will check for immutable (share or copy)
- return SkMakeImageFromRasterBitmap(bm);
+ return SkNewImageFromRasterBitmap(bm);
}
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
@@ -333,13 +332,12 @@ bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
return true;
}
-sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
- const SkMatrix* matrix, const SkPaint* paint) {
+SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimensions,
+ const SkMatrix* matrix, const SkPaint* paint) {
if (!picture) {
return nullptr;
}
- return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture.release(),
- matrix, paint));
+ return NewFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture, matrix, paint));
}
bool SkImage::isLazyGenerated() const {
@@ -350,95 +348,25 @@ bool SkImage::isLazyGenerated() const {
#if !SK_SUPPORT_GPU
-sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
- return nullptr;
-}
-
-sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
- TextureReleaseProc, ReleaseContext) {
+SkImage* SkImage::NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
return nullptr;
}
-sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
- SkAlphaType) {
+SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
+ TextureReleaseProc, ReleaseContext) {
return nullptr;
}
-sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
+SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
return nullptr;
}
-sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
- const GrBackendObject yuvTextureHandles[3],
- const SkISize yuvSizes[3],
- GrSurfaceOrigin origin) {
+SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
return nullptr;
}
-sk_sp<SkImage> SkImage::makeTextureImage(GrContext*) const {
+SkImage* SkImage::newTextureImage(GrContext*) const {
return nullptr;
}
#endif
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
-SkImage* SkImage::NewRasterCopy(const Info& info, const void* pixels, size_t rowBytes,
- SkColorTable* ctable) {
- return MakeRasterCopy(SkPixmap(info, pixels, rowBytes, ctable)).release();
-}
-
-SkImage* SkImage::NewRasterData(const Info& info, SkData* pixels, size_t rowBytes) {
- return MakeRasterData(info, sk_ref_sp(pixels), rowBytes).release();
-}
-
-SkImage* SkImage::NewFromRaster(const Info& info, const void* pixels, size_t rowBytes,
- RasterReleaseProc proc, ReleaseContext releasectx) {
- return MakeFromRaster(SkPixmap(info, pixels, rowBytes), proc, releasectx).release();
-}
-
-SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
- return MakeFromBitmap(bm).release();
-}
-
-SkImage* SkImage::NewFromGenerator(SkImageGenerator* gen, const SkIRect* subset) {
- return MakeFromGenerator(gen, subset).release();
-}
-
-SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
- return MakeFromEncoded(sk_ref_sp(encoded), subset).release();
-}
-
-SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
- TextureReleaseProc proc, ReleaseContext releasectx) {
- return MakeFromTexture(ctx, desc, at, proc, releasectx).release();
-}
-
-SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
- return MakeFromAdoptedTexture(ctx, desc, at).release();
-}
-
-SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
- return MakeFromTextureCopy(ctx, desc, at).release();
-}
-
-SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
- const GrBackendObject yuvTextureHandles[3],
- const SkISize yuvSizes[3],
- GrSurfaceOrigin origin) {
- return MakeFromYUVTexturesCopy(ctx, space, yuvTextureHandles, yuvSizes, origin).release();
-}
-
-SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimensions,
- const SkMatrix* matrix, const SkPaint* paint) {
- return MakeFromPicture(sk_ref_sp(const_cast<SkPicture*>(picture)), dimensions,
- matrix, paint).release();
-}
-
-SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pmap, SkBudgeted budgeted) {
- return MakeTextureFromPixmap(ctx, pmap, budgeted).release();
-}
-#endif
diff --git a/src/image/SkImagePriv.h b/src/image/SkImagePriv.h
index a625472eaa..acd0beb475 100644
--- a/src/image/SkImagePriv.h
+++ b/src/image/SkImagePriv.h
@@ -12,9 +12,9 @@
#include "SkSurface.h"
// Call this if you explicitly want to use/share this pixelRef in the image
-extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
- const SkIPoint& pixelRefOrigin,
- size_t rowBytes);
+extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
+ const SkIPoint& pixelRefOrigin,
+ size_t rowBytes);
/**
* Examines the bitmap to decide if it can share the existing pixelRef, or
@@ -38,8 +38,7 @@ enum ForceCopyMode {
kNo_ForceCopyMode,
kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable
};
-extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&,
- ForceCopyMode = kNo_ForceCopyMode);
+extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, ForceCopyMode = kNo_ForceCopyMode);
// Given an image created from SkNewImageFromBitmap, return its pixelref. This
// may be called to see if the surface and the image share the same pixelref,
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index ade891f4cb..9e2efe98b5 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -46,7 +46,7 @@ public:
// Caller must call unref when they are done.
virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const = 0;
- virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
+ virtual SkImage* onNewSubset(const SkIRect&) const = 0;
// If a ctx is specified, then only gpu-specific formats are requested.
virtual SkData* onRefEncoded(GrContext*) const { return nullptr; }
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index 62b492e288..95cc426a43 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -25,7 +25,7 @@ public:
SkImageCacherator* peekCacherator() const override { return fCache; }
SkData* onRefEncoded(GrContext*) const override;
bool isOpaque() const override { return fCache->info().isOpaque(); }
- sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
+ SkImage* onNewSubset(const SkIRect&) const override;
bool getROPixels(SkBitmap*, CachingHint) const override;
GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override;
bool onIsLazyGenerated() const override { return true; }
@@ -73,7 +73,7 @@ GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams
return fCache->lockAsTexture(ctx, params, this);
}
-sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
+SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const {
// TODO: make this lazy, by wrapping the subset inside a new generator or something
// For now, we do effectively what we did before, make it a raster
@@ -86,16 +86,13 @@ sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
surface->getCanvas()->clear(0);
surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToScalar(-subset.y()),
nullptr);
- return sk_sp<SkImage>(surface->newImageSnapshot());
+ return surface->newImageSnapshot();
}
-sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkIRect* subset) {
- if (!generator) {
- return nullptr;
- }
+SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* subset) {
SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, subset);
if (!cache) {
return nullptr;
}
- return sk_make_sp<SkImage_Generator>(cache);
+ return new SkImage_Generator(cache);
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 6494fd1a17..b87e50ba0a 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -134,7 +134,7 @@ bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t row
return true;
}
-sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
+SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
GrContext* ctx = fTexture->getContext();
GrSurfaceDesc desc = fTexture->desc();
desc.fWidth = subset.width();
@@ -145,16 +145,16 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
return nullptr;
}
ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
- return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
- fAlphaType, subTx, fBudgeted);
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAlphaType, subTx,
+ fBudgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at, GrWrapOwnership ownership,
- SkImage::TextureReleaseProc releaseProc,
- SkImage::ReleaseContext releaseCtx) {
+static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at, GrWrapOwnership ownership,
+ SkImage::TextureReleaseProc releaseProc,
+ SkImage::ReleaseContext releaseCtx) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
@@ -167,23 +167,21 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend
}
const SkBudgeted budgeted = SkBudgeted::kNo;
- return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
- at, tex, budgeted);
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
}
-sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at, TextureReleaseProc releaseP,
- ReleaseContext releaseC) {
+SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
+ TextureReleaseProc releaseP, ReleaseContext releaseC) {
return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, releaseP, releaseC);
}
-sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
+SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at) {
return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nullptr, nullptr);
}
-sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
- SkAlphaType at) {
+SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
+ SkAlphaType at) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
@@ -199,14 +197,14 @@ sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext* ctx, const GrBackendTextu
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
- SkBudgeted::kYes);
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
+ SkBudgeted::kYes);
}
-sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
- const GrBackendObject yuvTextureHandles[3],
- const SkISize yuvSizes[3],
- GrSurfaceOrigin origin) {
+SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
+ const GrBackendObject yuvTextureHandles[3],
+ const SkISize yuvSizes[3],
+ GrSurfaceOrigin origin) {
const SkBudgeted budgeted = SkBudgeted::kYes;
if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
@@ -277,25 +275,25 @@ sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace
drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(dst);
- return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
- kOpaque_SkAlphaType, dst, budgeted);
+ return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
+ kOpaque_SkAlphaType, dst, budgeted);
}
-static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
+static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter()));
if (!texture) {
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
- SkBudgeted::kNo);
+ return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
+ SkBudgeted::kNo);
}
-sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
+SkImage* SkImage::newTextureImage(GrContext *context) const {
if (!context) {
return nullptr;
}
if (GrTexture* peek = as_IB(this)->peekTexture()) {
- return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr;
+ return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr;
}
// No way to check whether a image is premul or not?
SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
@@ -312,8 +310,8 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
return create_image_from_maker(&maker, at, this->uniqueID());
}
-sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
- SkBudgeted budgeted) {
+SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
+ SkBudgeted budgeted) {
if (!ctx) {
return nullptr;
}
@@ -321,8 +319,8 @@ sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pi
if (!texture) {
return nullptr;
}
- return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID,
- pixmap.alphaType(), texture, budgeted);
+ return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUniqueID,
+ pixmap.alphaType(), texture, budgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 8f59af14a4..c640322a65 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -35,7 +35,7 @@ public:
bool getROPixels(SkBitmap*, CachingHint) const override;
GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override;
- sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
+ SkImage* onNewSubset(const SkIRect&) const override;
GrTexture* peekTexture() const override { return fTexture; }
bool isOpaque() const override;
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 7f2f5c07ef..5bd0e1d8f1 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -63,7 +63,7 @@ public:
return true;
}
- SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*);
+ SkImage_Raster(const SkImageInfo&, 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;
- sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
+ SkImage* onNewSubset(const SkIRect&) const override;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size_t rowBytes);
@@ -110,13 +110,14 @@ static void release_data(void* addr, void* context) {
data->unref();
}
-SkImage_Raster::SkImage_Raster(const Info& info, sk_sp<SkData> data, size_t rowBytes,
+SkImage_Raster::SkImage_Raster(const Info& info, 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.release());
+ fBitmap.installPixels(info, addr, rowBytes, ctable, release_data, data);
fBitmap.setImmutable();
fBitmap.lockPixels();
}
@@ -172,7 +173,7 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrTextureParams& p
return nullptr;
}
-sk_sp<SkImage> SkImage_Raster::onMakeSubset(const SkIRect& subset) const {
+SkImage* SkImage_Raster::onNewSubset(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());
@@ -183,26 +184,25 @@ sk_sp<SkImage> SkImage_Raster::onMakeSubset(const SkIRect& subset) const {
surface->getCanvas()->clear(0);
surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToScalar(-subset.y()),
nullptr);
- return sk_sp<SkImage>(surface->newImageSnapshot());
+ return surface->newImageSnapshot();
}
///////////////////////////////////////////////////////////////////////////////
-sk_sp<SkImage> SkImage::MakeRasterCopy(const SkPixmap& pmap) {
+SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, size_t rowBytes,
+ SkColorTable* ctable) {
size_t size;
- if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(),
- pmap.ctable() != nullptr, &size) || !pmap.addr()) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable != nullptr, &size) || !pixels) {
return nullptr;
}
// Here we actually make a copy of the caller's pixel data
- sk_sp<SkData> data(SkData::NewWithCopy(pmap.addr(), size));
- return sk_make_sp<SkImage_Raster>(pmap.info(), std::move(data), pmap.rowBytes(), pmap.ctable());
+ SkAutoDataUnref data(SkData::NewWithCopy(pixels, size));
+ return new SkImage_Raster(info, data, rowBytes, ctable);
}
-sk_sp<SkImage> SkImage::MakeRasterData(const SkImageInfo& info, sk_sp<SkData> data,
- size_t rowBytes) {
+SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t rowBytes) {
size_t size;
if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !data) {
return nullptr;
@@ -214,29 +214,30 @@ sk_sp<SkImage> SkImage::MakeRasterData(const SkImageInfo& info, sk_sp<SkData> da
}
SkColorTable* ctable = nullptr;
- return sk_make_sp<SkImage_Raster>(info, std::move(data), rowBytes, ctable);
+ return new SkImage_Raster(info, data, rowBytes, ctable);
}
-sk_sp<SkImage> SkImage::MakeFromRaster(const SkPixmap& pmap, RasterReleaseProc proc,
- ReleaseContext ctx) {
+SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, size_t rowBytes,
+ RasterReleaseProc proc, ReleaseContext ctx) {
size_t size;
- if (!SkImage_Raster::ValidArgs(pmap.info(), pmap.rowBytes(), false, &size) || !pmap.addr()) {
+ if (!SkImage_Raster::ValidArgs(info, rowBytes, false, &size) || !pixels) {
return nullptr;
}
- 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());
+ SkColorTable* ctable = nullptr;
+ SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx));
+ return new SkImage_Raster(info, data, rowBytes, ctable);
}
-sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
- const SkIPoint& pixelRefOrigin, size_t rowBytes) {
+SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
+ const SkIPoint& pixelRefOrigin, size_t rowBytes) {
if (!SkImage_Raster::ValidArgs(info, rowBytes, false, nullptr)) {
return nullptr;
}
- return sk_make_sp<SkImage_Raster>(info, pr, pixelRefOrigin, rowBytes);
+ return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes);
}
-sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
+SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode forceCopy) {
SkASSERT(nullptr == bm.getTexture());
bool hasColorTable = false;
@@ -249,16 +250,16 @@ sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap& bm, ForceCopyMode for
return nullptr;
}
- sk_sp<SkImage> image;
+ SkImage* image = nullptr;
if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
SkBitmap tmp(bm);
tmp.lockPixels();
- SkPixmap pmap;
- if (tmp.getPixels() && tmp.peekPixels(&pmap)) {
- image = SkImage::MakeRasterCopy(pmap);
+ if (tmp.getPixels()) {
+ image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowBytes(),
+ tmp.getColorTable());
}
} else {
- image = sk_make_sp<SkImage_Raster>(bm);
+ image = new SkImage_Raster(bm);
}
return image;
}
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 192415341f..d07e94998f 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -131,7 +131,7 @@ SkImage* SkSurface_Raster::onNewImageSnapshot(SkBudgeted, ForceCopyMode forceCop
// Our pixels are in memory, so read access on the snapshot SkImage could be cheap.
// Lock the shared pixel ref to ensure peekPixels() is usable.
- return SkMakeImageFromRasterBitmap(fBitmap, forceCopyMode).release();
+ return SkNewImageFromRasterBitmap(fBitmap, forceCopyMode);
}
void SkSurface_Raster::onRestoreBackingMutability() {