From 185130c643f0f6b20dcf14c200074748be282a7e Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Wed, 15 Feb 2017 15:14:16 -0500 Subject: return and take SkImageGenerator as unique_ptr BUG=skia: Change-Id: I4bc11042dd1dbf1eabd40af206027bc65acc3186 Reviewed-on: https://skia-review.googlesource.com/8444 Commit-Queue: Mike Reed Reviewed-by: Matt Sarett Reviewed-by: Brian Osman --- include/core/SkGraphics.h | 14 +++++++++++--- include/core/SkImage.h | 4 ++++ include/core/SkImageGenerator.h | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h index d5a730d9e0..bf8228b9cc 100644 --- a/include/core/SkGraphics.h +++ b/include/core/SkGraphics.h @@ -8,7 +8,7 @@ #ifndef SkGraphics_DEFINED #define SkGraphics_DEFINED -#include "SkTypes.h" +#include "SkRefCnt.h" class SkData; class SkImageGenerator; @@ -157,7 +157,8 @@ public: */ static void SetTLSFontCacheLimit(size_t bytes); - typedef SkImageGenerator* (*ImageGeneratorFromEncodedFactory)(SkData*); + typedef std::unique_ptr + (*ImageGeneratorFromEncodedDataFactory)(sk_sp); /** * To instantiate images from encoded data, first looks at this runtime function-ptr. If it @@ -166,8 +167,15 @@ public: * * Returns the previous factory (which could be NULL). */ + static ImageGeneratorFromEncodedDataFactory + SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory); + +#ifdef SK_SUPPORT_BARE_PTR_IMAGEGENERATOR + typedef SkImageGenerator* (*ImageGeneratorFromEncodedFactory)(SkData*); static ImageGeneratorFromEncodedFactory - SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory); + SetImageGeneratorFromEncodedFactory(ImageGeneratorFromEncodedFactory); +#endif + }; class SkAutoGraphics { diff --git a/include/core/SkImage.h b/include/core/SkImage.h index aaafb44c42..444ce6815e 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -73,7 +73,11 @@ public: * * If a subset is specified, it must be contained within the generator's bounds. */ + static sk_sp MakeFromGenerator(std::unique_ptr, + const SkIRect* subset = nullptr); +#ifdef SK_SUPPORT_BARE_PTR_IMAGEGENERATOR static sk_sp MakeFromGenerator(SkImageGenerator*, const SkIRect* subset = nullptr); +#endif /** * Construct a new SkImage based on the specified encoded data. Returns NULL on failure, diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index a8a858d6da..44d59438ee 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -146,18 +146,27 @@ public: * this returns a new ImageGenerator for it. Otherwise this returns NULL. Either way * the caller is still responsible for managing their ownership of the data. */ - static SkImageGenerator* NewFromEncoded(SkData*); + static std::unique_ptr MakeFromEncoded(sk_sp); /** Return a new image generator backed by the specified picture. If the size is empty or * the picture is NULL, this returns NULL. * The optional matrix and paint arguments are passed to drawPicture() at rasterization * time. */ - static SkImageGenerator* NewFromPicture(const SkISize&, const SkPicture*, const SkMatrix*, - const SkPaint*, SkImage::BitDepth, sk_sp); + static std::unique_ptr MakeFromPicture(const SkISize&, sk_sp, + const SkMatrix*, const SkPaint*, + SkImage::BitDepth, + sk_sp); bool tryGenerateBitmap(SkBitmap* bm, const SkImageInfo& info, SkBitmap::Allocator* allocator); +#ifdef SK_SUPPORT_BARE_PTR_IMAGEGENERATOR + static SkImageGenerator* NewFromPicture(const SkISize& size, const SkPicture* picture, + const SkMatrix* matrix, const SkPaint* paint, + SkImage::BitDepth depth, sk_sp cs); + static SkImageGenerator* NewFromEncoded(SkData* data); +#endif + protected: enum { kNeedNewImageUniqueID = 0 @@ -188,7 +197,7 @@ private: // This is our default impl, which may be different on different platforms. // It is called from NewFromEncoded() after it has checked for any runtime factory. // The SkData will never be NULL, as that will have been checked by NewFromEncoded. - static SkImageGenerator* NewFromEncodedImpl(SkData*); + static std::unique_ptr MakeFromEncodedImpl(sk_sp); }; #endif // SkImageGenerator_DEFINED -- cgit v1.2.3