diff options
author | Mike Reed <reed@google.com> | 2017-02-15 15:14:16 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-15 20:51:28 +0000 |
commit | 185130c643f0f6b20dcf14c200074748be282a7e (patch) | |
tree | 049a9162c7ed7c298a4966000b9aa805f75282ad /gm/image_pict.cpp | |
parent | eb62829a83a0a4f4fdd1230a3c08140e38052602 (diff) |
return and take SkImageGenerator as unique_ptr
BUG=skia:
Change-Id: I4bc11042dd1dbf1eabd40af206027bc65acc3186
Reviewed-on: https://skia-review.googlesource.com/8444
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Diffstat (limited to 'gm/image_pict.cpp')
-rw-r--r-- | gm/image_pict.cpp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index 286470d1e9..387ceb8d41 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -9,6 +9,7 @@ #include "SkCanvas.h" #include "SkImage.h" #include "SkImageCacherator.h" +#include "SkMakeUnique.h" #include "SkPictureRecorder.h" #include "SkSurface.h" @@ -107,10 +108,10 @@ DEF_GM( return new ImagePictGM; ) /////////////////////////////////////////////////////////////////////////////////////////////////// -static SkImageGenerator* make_pic_generator(GrContext*, SkPicture* pic) { +static std::unique_ptr<SkImageGenerator> make_pic_generator(GrContext*, sk_sp<SkPicture> pic) { SkMatrix matrix; matrix.setTranslate(-100, -100); - return SkImageGenerator::NewFromPicture(SkISize::Make(100, 100), pic, &matrix, nullptr, + return SkImageGenerator::MakeFromPicture({ 100, 100 }, std::move(pic), &matrix, nullptr, SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); } @@ -150,14 +151,14 @@ protected: private: SkBitmap fBM; }; -static SkImageGenerator* make_ras_generator(GrContext*, SkPicture* pic) { +static std::unique_ptr<SkImageGenerator> make_ras_generator(GrContext*, sk_sp<SkPicture> pic) { SkBitmap bm; bm.allocN32Pixels(100, 100); SkCanvas canvas(bm); canvas.clear(0); canvas.translate(-100, -100); canvas.drawPicture(pic); - return new RasterGenerator(bm); + return skstd::make_unique<RasterGenerator>(bm); } // so we can create a color-table @@ -181,7 +182,7 @@ static int find_closest(SkPMColor c, const SkPMColor table[], int count) { return index; } -static SkImageGenerator* make_ctable_generator(GrContext*, SkPicture* pic) { +static std::unique_ptr<SkImageGenerator> make_ctable_generator(GrContext*, sk_sp<SkPicture> pic) { SkBitmap bm; bm.allocN32Pixels(100, 100); SkCanvas canvas(bm); @@ -205,7 +206,7 @@ static SkImageGenerator* make_ctable_generator(GrContext*, SkPicture* pic) { *bm2.getAddr8(x, y) = find_closest(*bm.getAddr32(x, y), colors, count); } } - return new RasterGenerator(bm2); + return skstd::make_unique<RasterGenerator>(bm2); } class EmptyGenerator : public SkImageGenerator { @@ -216,7 +217,7 @@ public: #if SK_SUPPORT_GPU class TextureGenerator : public SkImageGenerator { public: - TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic) + TextureGenerator(GrContext* ctx, const SkImageInfo& info, sk_sp<SkPicture> pic) : SkImageGenerator(info) , fCtx(SkRef(ctx)) { @@ -276,25 +277,26 @@ private: sk_sp<GrContext> fCtx; sk_sp<GrSurfaceProxy> fProxy; }; -static SkImageGenerator* make_tex_generator(GrContext* ctx, SkPicture* pic) { +static std::unique_ptr<SkImageGenerator> make_tex_generator(GrContext* ctx, sk_sp<SkPicture> pic) { const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); if (!ctx) { - return new EmptyGenerator(info); + return skstd::make_unique<EmptyGenerator>(info); } - return new TextureGenerator(ctx, info, pic); + return skstd::make_unique<TextureGenerator>(ctx, info, pic); } #endif class ImageCacheratorGM : public skiagm::GM { SkString fName; - SkImageGenerator* (*fFactory)(GrContext*, SkPicture*); + std::unique_ptr<SkImageGenerator> (*fFactory)(GrContext*, sk_sp<SkPicture>); sk_sp<SkPicture> fPicture; std::unique_ptr<SkImageCacherator> fCache; std::unique_ptr<SkImageCacherator> fCacheSubset; public: - ImageCacheratorGM(const char suffix[], SkImageGenerator* (*factory)(GrContext*, SkPicture*)) + ImageCacheratorGM(const char suffix[], + std::unique_ptr<SkImageGenerator> (*factory)(GrContext*, sk_sp<SkPicture>)) : fFactory(factory) { fName.printf("image-cacherator-from-%s", suffix); @@ -317,15 +319,15 @@ protected: } void makeCaches(GrContext* ctx) { - auto gen = fFactory(ctx, fPicture.get()); + auto gen = fFactory(ctx, fPicture); SkDEBUGCODE(const uint32_t genID = gen->uniqueID();) - fCache.reset(SkImageCacherator::NewFromGenerator(gen)); + fCache.reset(SkImageCacherator::NewFromGenerator(std::move(gen))); const SkIRect subset = SkIRect::MakeLTRB(50, 50, 100, 100); - gen = fFactory(ctx, fPicture.get()); + gen = fFactory(ctx, fPicture); SkDEBUGCODE(const uint32_t genSubsetID = gen->uniqueID();) - fCacheSubset.reset(SkImageCacherator::NewFromGenerator(gen, &subset)); + fCacheSubset.reset(SkImageCacherator::NewFromGenerator(std::move(gen), &subset)); // whole caches should have the same ID as the generator. Subsets should be diff SkASSERT(fCache->uniqueID() == genID); |