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

Unified Diff: src/image/SkImage.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
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/image/SkImagePriv.h » ('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 a41ac83d1906aa6f59f7c2a28b95b51ec2543069..ee4491e0b15c38bee1704e4d322f46b6a6565446 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -15,6 +15,7 @@
#include "SkImageShader.h"
#include "SkImage_Base.h"
#include "SkNextID.h"
+#include "SkPicture.h"
#include "SkPixelRef.h"
#include "SkPixelSerializer.h"
#include "SkReadPixelsRec.h"
@@ -150,12 +151,12 @@ SkData* SkImage::refEncoded() const {
return as_IB(this)->onRefEncoded(ctx);
}
-SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
+sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
if (nullptr == encoded || 0 == encoded->size()) {
return nullptr;
}
- SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded);
- return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
+ SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded.get());
+ return SkImage::MakeFromGenerator(generator, subset);
}
const char* SkImage::toString(SkString* str) const {
@@ -164,7 +165,7 @@ const char* SkImage::toString(SkString* str) const {
return str->c_str();
}
-SkImage* SkImage::newSubset(const SkIRect& subset) const {
+sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
if (subset.isEmpty()) {
return nullptr;
}
@@ -176,9 +177,9 @@ SkImage* SkImage::newSubset(const SkIRect& subset) const {
// optimization : return self if the subset == our bounds
if (bounds == subset) {
- return SkRef(const_cast<SkImage*>(this));
+ return sk_ref_sp(const_cast<SkImage*>(this));
}
- return as_IB(this)->onNewSubset(subset);
+ return as_IB(this)->onMakeSubset(subset);
}
#if SK_SUPPORT_GPU
@@ -283,7 +284,7 @@ bool SkImage::readYUV8Planes(const SkISize sizes[3], void* const planes[3],
///////////////////////////////////////////////////////////////////////////////////////////////////
-SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
+sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
SkPixelRef* pr = bm.pixelRef();
if (nullptr == pr) {
return nullptr;
@@ -300,13 +301,13 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
- return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
- tex, SkBudgeted::kNo);
+ return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenerationID(),
+ info.alphaType(), tex, SkBudgeted::kNo);
}
#endif
// This will check for immutable (share or copy)
- return SkNewImageFromRasterBitmap(bm);
+ return SkMakeImageFromRasterBitmap(bm);
}
bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
@@ -332,12 +333,13 @@ bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con
return true;
}
-SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimensions,
- const SkMatrix* matrix, const SkPaint* paint) {
+sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
+ const SkMatrix* matrix, const SkPaint* paint) {
if (!picture) {
return nullptr;
}
- return NewFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture, matrix, paint));
+ return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture.release(),
f(malita) 2016/03/11 13:58:35 Yeah, I think this needs to be picture.get() as Sk
+ matrix, paint));
}
bool SkImage::isLazyGenerated() const {
@@ -348,25 +350,95 @@ bool SkImage::isLazyGenerated() const {
#if !SK_SUPPORT_GPU
-SkImage* SkImage::NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
+sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted) {
+ return nullptr;
+}
+
+sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
+ TextureReleaseProc, ReleaseContext) {
return nullptr;
}
-SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
- TextureReleaseProc, ReleaseContext) {
+sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
+ SkAlphaType) {
return nullptr;
}
-SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
+sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
return nullptr;
}
-SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
+sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
+ const GrBackendObject yuvTextureHandles[3],
+ const SkISize yuvSizes[3],
+ GrSurfaceOrigin origin) {
return nullptr;
}
-SkImage* SkImage::newTextureImage(GrContext*) const {
+sk_sp<SkImage> SkImage::makeTextureImage(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
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/image/SkImagePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698