Revert "Revert of add Make variations to return SkImage by sk_sp (patchset #5 id:80001 of https://codereview.chromium.org/1778393002/ )"

Fix was to call get() instead of release() when passing the sp to a bare-ptr method.

This reverts commit e683c56115.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1789443002

TBR=

Review URL: https://codereview.chromium.org/1789443002
This commit is contained in:
reed 2016-03-11 04:33:52 -08:00 committed by Commit bot
parent db6bd3239f
commit 7fb4f8bd03
16 changed files with 257 additions and 148 deletions

View File

@ -27,6 +27,8 @@ class SkSurface;
class GrContext;
class GrTexture;
#define SK_SUPPORT_LEGACY_IMAGEFACTORY
/**
* SkImage is an abstraction for drawing a rectagle of pixels, though the
* particular type of image could be actually storing its data on the GPU, or
@ -46,9 +48,8 @@ public:
typedef SkImageInfo Info;
typedef void* ReleaseContext;
static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes,
SkColorTable* ctable = NULL);
static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
static sk_sp<SkImage> MakeRasterCopy(const SkPixmap&);
static sk_sp<SkImage> MakeRasterData(const Info&, sk_sp<SkData> pixels, size_t rowBytes);
typedef void (*RasterReleaseProc)(const void* pixels, ReleaseContext);
@ -57,36 +58,31 @@ public:
* until the specified release-proc is called, indicating that Skia no longer has a reference
* to the pixels.
*
* Returns NULL if the requested Info is unsupported.
* Returns NULL if the requested pixmap info is unsupported.
*/
static SkImage* NewFromRaster(const Info&, const void* pixels, size_t rowBytes,
RasterReleaseProc, ReleaseContext);
static sk_sp<SkImage> MakeFromRaster(const SkPixmap&, RasterReleaseProc, ReleaseContext);
/**
* Construct a new image from the specified bitmap. If the bitmap is marked immutable, and
* its pixel memory is shareable, it may be shared instead of copied.
*/
static SkImage* NewFromBitmap(const SkBitmap&);
static sk_sp<SkImage> MakeFromBitmap(const SkBitmap&);
/**
* Construct a new SkImage based on the given ImageGenerator.
* This function will always take ownership of the passed
* ImageGenerator. Returns NULL on error.
* Construct a new SkImage based on the given ImageGenerator. Returns NULL on error.
* This function will always take ownership of the passed generator.
*
* If a subset is specified, it must be contained within the generator's bounds.
*/
static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL);
static sk_sp<SkImage> MakeFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL);
/**
* Construct a new SkImage based on the specified encoded data. Returns NULL on failure,
* which can mean that the format of the encoded data was not recognized/supported.
*
* If a subset is specified, it must be contained within the encoded data's bounds.
*
* Regardless of success or failure, the caller is responsible for managing their ownership
* of the data.
*/
static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = NULL);
static sk_sp<SkImage> MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset = NULL);
/**
* Create a new image from the specified descriptor. Note - the caller is responsible for
@ -94,12 +90,13 @@ public:
*
* Will return NULL if the specified descriptor is unsupported.
*/
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) {
return NewFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL);
static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) {
return MakeFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL);
}
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& de, SkAlphaType at) {
return NewFromTexture(ctx, de, at, NULL, NULL);
static sk_sp<SkImage> MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& de,
SkAlphaType at) {
return MakeFromTexture(ctx, de, at, NULL, NULL);
}
typedef void (*TextureReleaseProc)(ReleaseContext);
@ -111,8 +108,8 @@ public:
*
* Will return NULL if the specified descriptor is unsupported.
*/
static SkImage* NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
TextureReleaseProc, ReleaseContext);
static sk_sp<SkImage> MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
TextureReleaseProc, ReleaseContext);
/**
* Create a new image from the specified descriptor. Note - Skia will delete or recycle the
@ -120,8 +117,8 @@ public:
*
* Will return NULL if the specified descriptor is unsupported.
*/
static SkImage* NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
static sk_sp<SkImage> MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
/**
* Create a new image by copying the pixels from the specified descriptor. No reference is
@ -129,23 +126,23 @@ public:
*
* Will return NULL if the specified descriptor is unsupported.
*/
static SkImage* NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
static sk_sp<SkImage> MakeFromTextureCopy(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
/**
* Create a new image by copying the pixels from the specified y, u, v textures. The data
* from the textures is immediately ingested into the image and the textures can be modified or
* deleted after the function returns. The image will have the dimensions of the y texture.
*/
static SkImage* NewFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin);
static sk_sp<SkImage> MakeFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin);
static SkImage* NewFromPicture(const SkPicture*, const SkISize& dimensions,
const SkMatrix*, const SkPaint*);
static sk_sp<SkImage> MakeFromPicture(sk_sp<SkPicture>, const SkISize& dimensions,
const SkMatrix*, const SkPaint*);
static SkImage* NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
static sk_sp<SkImage> MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
///////////////////////////////////////////////////////////////////////////////////////////////
@ -315,14 +312,14 @@ public:
* If subset does not intersect the bounds of this image, or the copy/share cannot be made,
* NULL will be returned.
*/
SkImage* newSubset(const SkIRect& subset) const;
sk_sp<SkImage> makeSubset(const SkIRect& subset) const;
/**
* Ensures that an image is backed by a texture (when GrContext is non-null). If no
* transformation is required, the returned image may be the same as this image. If the this
* image is from a different GrContext, this will fail.
*/
SkImage* newTextureImage(GrContext*) const;
sk_sp<SkImage> makeTextureImage(GrContext*) const;
// Helper functions to convert to SkBitmap
@ -348,6 +345,41 @@ public:
*/
bool isLazyGenerated() const;
#ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes,
SkColorTable* ctable = nullptr);
static SkImage* NewRasterData(const Info&, SkData* pixels, size_t rowBytes);
static SkImage* NewFromRaster(const Info&, const void* pixels, size_t rowBytes,
RasterReleaseProc, ReleaseContext);
static SkImage* NewFromBitmap(const SkBitmap&);
static SkImage* NewFromGenerator(SkImageGenerator*, const SkIRect* subset = NULL);
static SkImage* NewFromEncoded(SkData* encoded, const SkIRect* subset = NULL);
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc) {
return NewFromTexture(ctx, desc, kPremul_SkAlphaType, NULL, NULL);
}
static SkImage* NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& de, SkAlphaType at) {
return NewFromTexture(ctx, de, at, NULL, NULL);
}
static SkImage* NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
TextureReleaseProc, ReleaseContext);
static SkImage* NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
static SkImage* NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&,
SkAlphaType = kPremul_SkAlphaType);
static SkImage* NewFromYUVTexturesCopy(GrContext*, SkYUVColorSpace,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin);
static SkImage* NewFromPicture(const SkPicture*, const SkISize& dimensions,
const SkMatrix*, const SkPaint*);
static SkImage* NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted budgeted);
SkImage* newSubset(const SkIRect& subset) const { return this->makeSubset(subset).release(); }
SkImage* newTextureImage(GrContext* ctx) const { return this->makeTextureImage(ctx).release(); }
#endif
protected:
SkImage(int width, int height, uint32_t uniqueID);

View File

@ -411,7 +411,7 @@ public:
* bounds.
* @return Returns a new shader object. Note: this function never returns null.
*/
static sk_sp<SkShader> MakePictureShader(sk_sp<const SkPicture> src, TileMode tmx, TileMode tmy,
static sk_sp<SkShader> MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile);
/**

View File

@ -224,12 +224,12 @@ sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pi
if (!from_c_info(*cinfo, &info)) {
return NULL;
}
return (sk_image_t*)SkImage::NewRasterCopy(info, pixels, rowBytes);
return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(info, pixels, rowBytes)).release();
}
sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata, const sk_irect_t* subset) {
return ToImage(SkImage::NewFromEncoded(AsData(cdata),
reinterpret_cast<const SkIRect*>(subset)));
return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata)),
reinterpret_cast<const SkIRect*>(subset)).release());
}
sk_data_t* sk_image_encode(const sk_image_t* cimage) {

View File

@ -93,7 +93,7 @@ struct BitmapShaderRec : public SkResourceCache::Rec {
} // namespace
SkPictureShader::SkPictureShader(sk_sp<const SkPicture> picture, TileMode tmx, TileMode tmy,
SkPictureShader::SkPictureShader(sk_sp<SkPicture> picture, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile)
: INHERITED(localMatrix)
, fPicture(std::move(picture))
@ -102,7 +102,7 @@ SkPictureShader::SkPictureShader(sk_sp<const SkPicture> picture, TileMode tmx, T
, fTmy(tmy) {
}
sk_sp<SkShader> SkPictureShader::Make(sk_sp<const SkPicture> picture, TileMode tmx, TileMode tmy,
sk_sp<SkShader> SkPictureShader::Make(sk_sp<SkPicture> picture, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile) {
if (!picture || picture->cullRect().isEmpty() || (tile && tile->isEmpty())) {
return SkShader::MakeEmptyShader();
@ -223,8 +223,8 @@ sk_sp<SkShader> SkPictureShader::refBitmapShader(const SkMatrix& viewMatrix, con
tileMatrix.setRectToRect(fTile, SkRect::MakeIWH(tileSize.width(), tileSize.height()),
SkMatrix::kFill_ScaleToFit);
SkAutoTUnref<SkImage> tileImage(
SkImage::NewFromPicture(fPicture.get(), tileSize, &tileMatrix, nullptr));
sk_sp<SkImage> tileImage(
SkImage::MakeFromPicture(fPicture, tileSize, &tileMatrix, nullptr));
if (!tileImage) {
return nullptr;
}

View File

@ -22,7 +22,7 @@ class SkPicture;
*/
class SkPictureShader : public SkShader {
public:
static sk_sp<SkShader> Make(sk_sp<const SkPicture>, TileMode, TileMode, const SkMatrix*,
static sk_sp<SkShader> Make(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*,
const SkRect*);
SK_TO_STRING_OVERRIDE()
@ -42,14 +42,14 @@ protected:
Context* onCreateContext(const ContextRec&, void* storage) const override;
private:
SkPictureShader(sk_sp<const SkPicture>, TileMode, TileMode, const SkMatrix*, const SkRect*);
SkPictureShader(sk_sp<SkPicture>, TileMode, TileMode, const SkMatrix*, const SkRect*);
sk_sp<SkShader> refBitmapShader(const SkMatrix&, const SkMatrix* localMatrix,
const int maxTextureSize = 0) const;
sk_sp<const SkPicture> fPicture;
SkRect fTile;
TileMode fTmx, fTmy;
sk_sp<SkPicture> fPicture;
SkRect fTile;
TileMode fTmx, fTmy;
class PictureShaderContext : public SkShader::Context {
public:

View File

@ -298,11 +298,11 @@ SkImage* SkReadBuffer::readImage() {
return nullptr;
}
SkAutoTUnref<SkData> encoded(this->readByteArrayAsData());
sk_sp<SkData> encoded(this->readByteArrayAsData());
if (encoded->size() == 0) {
// The image could not be encoded at serialization time - return an empty placeholder.
return SkImage::NewFromGenerator(
new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height)));
return SkImage::MakeFromGenerator(
new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))).release();
}
int originX = this->read32();
@ -313,13 +313,13 @@ SkImage* SkReadBuffer::readImage() {
}
const SkIRect subset = SkIRect::MakeXYWH(originX, originY, width, height);
SkImage* image = SkImage::NewFromEncoded(encoded, &subset);
SkImage* image = SkImage::MakeFromEncoded(std::move(encoded), &subset).release();
if (image) {
return image;
}
return SkImage::NewFromGenerator(
new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height)));
return SkImage::MakeFromGenerator(
new EmptyImageGenerator(SkImageInfo::MakeN32Premul(width, height))).release();
}
SkTypeface* SkReadBuffer::readTypeface() {

View File

@ -238,7 +238,7 @@ sk_sp<SkShader> SkShader::MakeBitmapShader(const SkBitmap& src, TileMode tmx, Ti
return SkMakeBitmapShader(src, tmx, tmy, localMatrix, nullptr);
}
sk_sp<SkShader> SkShader::MakePictureShader(sk_sp<const SkPicture> src, TileMode tmx, TileMode tmy,
sk_sp<SkShader> SkShader::MakePictureShader(sk_sp<SkPicture> src, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile) {
return SkPictureShader::Make(std::move(src), tmx, tmy, localMatrix, tile);
}
@ -388,6 +388,7 @@ SkShader* SkShader::CreateComposeShader(SkShader* dst, SkShader* src, SkXfermode
}
SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy,
const SkMatrix* localMatrix, const SkRect* tile) {
return MakePictureShader(sk_ref_sp(src), tmx, tmy, localMatrix, tile).release();
return MakePictureShader(sk_ref_sp(const_cast<SkPicture*>(src)), tmx, tmy,
localMatrix, tile).release();
}
#endif

View File

@ -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.get(),
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;
}
SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
TextureReleaseProc, ReleaseContext) {
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
TextureReleaseProc, ReleaseContext) {
return nullptr;
}
SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&,
SkAlphaType) {
return nullptr;
}
SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
return nullptr;
}
SkImage* SkImage::newTextureImage(GrContext*) const {
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin origin) {
return nullptr;
}
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

View File

@ -12,9 +12,9 @@
#include "SkSurface.h"
// Call this if you explicitly want to use/share this pixelRef in the image
extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
const SkIPoint& pixelRefOrigin,
size_t rowBytes);
extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
const SkIPoint& pixelRefOrigin,
size_t rowBytes);
/**
* Examines the bitmap to decide if it can share the existing pixelRef, or
@ -38,7 +38,8 @@ enum ForceCopyMode {
kNo_ForceCopyMode,
kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable
};
extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, ForceCopyMode = kNo_ForceCopyMode);
extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(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,

View File

@ -46,7 +46,7 @@ public:
// Caller must call unref when they are done.
virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const = 0;
virtual SkImage* onNewSubset(const SkIRect&) const = 0;
virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
// If a ctx is specified, then only gpu-specific formats are requested.
virtual SkData* onRefEncoded(GrContext*) const { return nullptr; }

View File

@ -25,7 +25,7 @@ public:
SkImageCacherator* peekCacherator() const override { return fCache; }
SkData* onRefEncoded(GrContext*) const override;
bool isOpaque() const override { return fCache->info().isOpaque(); }
SkImage* onNewSubset(const SkIRect&) const override;
sk_sp<SkImage> onMakeSubset(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);
}
SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const {
sk_sp<SkImage> SkImage_Generator::onMakeSubset(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,13 +86,16 @@ SkImage* SkImage_Generator::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::NewFromGenerator(SkImageGenerator* generator, const SkIRect* subset) {
sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkIRect* subset) {
if (!generator) {
return nullptr;
}
SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, subset);
if (!cache) {
return nullptr;
}
return new SkImage_Generator(cache);
return sk_make_sp<SkImage_Generator>(cache);
}

View File

@ -134,7 +134,7 @@ bool SkImage_Gpu::onReadPixels(const SkImageInfo& info, void* pixels, size_t row
return true;
}
SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const {
GrContext* ctx = fTexture->getContext();
GrSurfaceDesc desc = fTexture->desc();
desc.fWidth = subset.width();
@ -145,16 +145,16 @@ SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
return nullptr;
}
ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAlphaType, subTx,
fBudgeted);
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
fAlphaType, subTx, fBudgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, GrWrapOwnership ownership,
SkImage::TextureReleaseProc releaseProc,
SkImage::ReleaseContext releaseCtx) {
static sk_sp<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,21 +167,23 @@ static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur
}
const SkBudgeted budgeted = SkBudgeted::kNo;
return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
at, tex, budgeted);
}
SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at, TextureReleaseProc releaseP,
ReleaseContext releaseC) {
return new_wrapped_texture_common(ctx, desc, at, kBorrow_GrWrapOwnership, releaseP, releaseC);
}
SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at) {
sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at) {
return new_wrapped_texture_common(ctx, desc, at, kAdopt_GrWrapOwnership, nullptr, nullptr);
}
SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at) {
sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
SkAlphaType at) {
if (desc.fWidth <= 0 || desc.fHeight <= 0) {
return nullptr;
}
@ -197,14 +199,14 @@ SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
return nullptr;
}
return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
SkBudgeted::kYes);
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
SkBudgeted::kYes);
}
SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin origin) {
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(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 ||
@ -275,25 +277,25 @@ SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(dst);
return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
kOpaque_SkAlphaType, dst, budgeted);
return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
kOpaque_SkAlphaType, dst, budgeted);
}
static SkImage* create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::ClampNoFilter()));
if (!texture) {
return nullptr;
}
return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
SkBudgeted::kNo);
return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
SkBudgeted::kNo);
}
SkImage* SkImage::newTextureImage(GrContext *context) const {
sk_sp<SkImage> SkImage::makeTextureImage(GrContext *context) const {
if (!context) {
return nullptr;
}
if (GrTexture* peek = as_IB(this)->peekTexture()) {
return peek->getContext() == context ? SkRef(const_cast<SkImage*>(this)) : nullptr;
return peek->getContext() == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr;
}
// No way to check whether a image is premul or not?
SkAlphaType at = this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
@ -310,8 +312,8 @@ SkImage* SkImage::newTextureImage(GrContext *context) const {
return create_image_from_maker(&maker, at, this->uniqueID());
}
SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
SkBudgeted budgeted) {
sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
SkBudgeted budgeted) {
if (!ctx) {
return nullptr;
}
@ -319,8 +321,8 @@ SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pixmap,
if (!texture) {
return nullptr;
}
return new SkImage_Gpu(texture->width(), texture->height(), kNeedNewImageUniqueID,
pixmap.alphaType(), texture, budgeted);
return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID,
pixmap.alphaType(), texture, budgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -35,7 +35,7 @@ public:
bool getROPixels(SkBitmap*, CachingHint) const override;
GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override;
SkImage* onNewSubset(const SkIRect&) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
GrTexture* peekTexture() const override { return fTexture; }
bool isOpaque() const override;

View File

@ -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;
}

View File

@ -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 SkNewImageFromRasterBitmap(fBitmap, forceCopyMode);
return SkMakeImageFromRasterBitmap(fBitmap, forceCopyMode).release();
}
void SkSurface_Raster::onRestoreBackingMutability() {

View File

@ -29,6 +29,5 @@ SkFlattenable* SkBitmapSourceDeserializer::CreateProc(SkReadBuffer& buffer) {
}
bitmap.setImmutable();
SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(bitmap));
return SkImageSource::Create(image, src, dst, filterQuality);
return SkImageSource::Create(SkImage::MakeFromBitmap(bitmap).get(), src, dst, filterQuality);
}