From e8f3062a36d3682f4019309a32b5b84dc9eddf8c Mon Sep 17 00:00:00 2001 From: reed Date: Wed, 23 Mar 2016 18:59:25 -0700 Subject: switch surface to sk_sp BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1817383002 CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot Review URL: https://codereview.chromium.org/1817383002 --- bench/DisplacementBench.cpp | 2 +- bench/ImageBench.cpp | 6 +- bench/MergeBench.cpp | 4 +- bench/SKPBench.cpp | 2 +- bench/nanobench.cpp | 10 +- bench/nanobench.h | 2 +- cmake/example.cpp | 6 +- dm/DMGpuSupport.h | 16 +-- dm/DMSrcSink.cpp | 13 ++- example/HelloWorld.h | 4 +- gm/bigtileimagefilter.cpp | 2 +- gm/color4f.cpp | 2 +- gm/complexclip_blur_tiled.cpp | 6 +- gm/dftext.cpp | 5 +- gm/discard.cpp | 4 +- gm/drawatlas.cpp | 4 +- gm/drawatlascolor.cpp | 4 +- gm/drawbitmaprect.cpp | 4 +- gm/drawminibitmaprect.cpp | 4 +- gm/fatpathfill.cpp | 8 +- gm/filterfastbounds.cpp | 2 +- gm/image.cpp | 27 +++-- gm/image_pict.cpp | 3 +- gm/image_shader.cpp | 5 +- gm/imagealphathreshold.cpp | 4 +- gm/imagefilters.cpp | 4 +- gm/imagefiltersclipped.cpp | 2 +- gm/imagefilterscropexpand.cpp | 2 +- gm/imagefiltersscaled.cpp | 2 +- gm/imagefilterstransformed.cpp | 2 +- gm/imagescalealigned.cpp | 2 +- gm/imagesource2.cpp | 2 +- gm/imagetoyuvplanes.cpp | 6 +- gm/lcdblendmodes.cpp | 4 +- gm/localmatriximagefilter.cpp | 4 +- gm/mipmap.cpp | 2 +- gm/multipicturedraw.cpp | 12 +-- gm/ninepatchstretch.cpp | 8 +- gm/perspshaders.cpp | 4 +- gm/resizeimagefilter.cpp | 2 +- gm/srcmode.cpp | 9 +- gm/surface.cpp | 19 ++-- gm/textblobgeometrychange.cpp | 2 +- gm/textblobmixedsizes.cpp | 5 +- gm/textblobrandomfont.cpp | 2 +- gm/transparency.cpp | 2 +- gm/verylargebitmap.cpp | 2 +- gm/xfermodes3.cpp | 10 +- gyp/skia_for_android_framework_defines.gypi | 1 + include/core/SkBitmapDevice.h | 2 +- include/core/SkCanvas.h | 7 +- include/core/SkDevice.h | 2 +- include/core/SkSurface.h | 106 ++++++++++++++----- public.bzl | 1 + samplecode/SampleApp.cpp | 4 +- samplecode/SampleAtlas.cpp | 2 +- samplecode/SampleFatBits.cpp | 16 +-- samplecode/SampleFilterQuality.cpp | 16 +-- samplecode/SampleQuadStroker.cpp | 10 +- samplecode/SampleTextureDomain.cpp | 2 +- src/c/sk_surface.cpp | 4 +- src/core/SkBitmapDevice.cpp | 4 +- src/core/SkCanvas.cpp | 12 ++- src/core/SkDevice.cpp | 3 + src/core/SkPictureImageGenerator.cpp | 5 +- src/core/SkPictureRecord.cpp | 2 +- src/core/SkPictureRecord.h | 2 +- src/core/SkPixmap.cpp | 3 +- src/core/SkRecorder.cpp | 4 + src/core/SkRecorder.h | 2 +- src/core/SkSpecialImage.cpp | 19 ++-- src/gpu/GrLayerHoister.cpp | 4 +- src/gpu/SkGpuDevice.cpp | 6 +- src/gpu/SkGpuDevice.h | 2 +- src/image/SkImage_Base.h | 4 +- src/image/SkImage_Generator.cpp | 2 +- src/image/SkImage_Gpu.h | 4 +- src/image/SkImage_Raster.cpp | 2 +- src/image/SkSurface.cpp | 21 ++-- src/image/SkSurface_Base.h | 6 +- src/image/SkSurface_Gpu.cpp | 51 +++++----- src/image/SkSurface_Gpu.h | 4 +- src/image/SkSurface_Raster.cpp | 36 +++---- src/pdf/SkPDFDevice.cpp | 10 +- src/pdf/SkPDFDevice.h | 2 +- src/utils/SkLua.cpp | 12 +-- src/utils/SkRGBAToYUV.cpp | 2 +- src/views/SkWindow.cpp | 3 +- tests/BlurTest.cpp | 2 +- tests/DrawBitmapRectTest.cpp | 2 +- tests/DrawFilterTest.cpp | 2 +- tests/DrawPathTest.cpp | 19 ++-- tests/GpuDrawPathTest.cpp | 5 +- tests/GrTextureMipMapInvalidationTest.cpp | 3 +- tests/GradientTest.cpp | 6 +- tests/ImageFilterTest.cpp | 11 +- tests/ImageIsOpaqueTest.cpp | 13 ++- tests/ImageNewShaderTest.cpp | 20 ++-- tests/ImageTest.cpp | 13 ++- tests/IndexedPngOverflowTest.cpp | 2 +- tests/PathTest.cpp | 12 +-- tests/ReadPixelsTest.cpp | 14 +-- tests/RecordDrawTest.cpp | 2 +- tests/RecorderTest.cpp | 2 +- tests/ResourceCacheTest.cpp | 3 +- tests/SkResourceCacheTest.cpp | 4 +- tests/SurfaceTest.cpp | 153 +++++++++++++--------------- tests/TextBlobCacheTest.cpp | 5 +- tests/TextureStorageAllocator.cpp | 4 +- tests/WritePixelsTest.cpp | 11 +- tools/VisualBench/VisualBench.cpp | 2 +- tools/VisualBench/WrappedBenchmark.h | 16 +-- tools/android/SkAndroidSDKCanvas.cpp | 7 +- tools/android/SkAndroidSDKCanvas.h | 2 +- tools/kilobench/kilobench.cpp | 6 +- tools/skhello.cpp | 2 +- tools/skiaserve/Request.cpp | 6 +- 117 files changed, 523 insertions(+), 484 deletions(-) diff --git a/bench/DisplacementBench.cpp b/bench/DisplacementBench.cpp index c22b8fd2d1..eadafb6622 100644 --- a/bench/DisplacementBench.cpp +++ b/bench/DisplacementBench.cpp @@ -48,7 +48,7 @@ protected: void makeCheckerboard() { const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(w, h)); + auto surface(SkSurface::MakeRasterN32Premul(w, h)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkPaint darkPaint; diff --git a/bench/ImageBench.cpp b/bench/ImageBench.cpp index b07d267b60..fbfce05a66 100644 --- a/bench/ImageBench.cpp +++ b/bench/ImageBench.cpp @@ -31,12 +31,12 @@ protected: void onPerCanvasPreDraw(SkCanvas* canvas) override { // create an Image reflecting the canvas (gpu or cpu) SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); canvas->drawColor(SK_ColorRED); fImage = surface->makeImageSnapshot(); // create a cpu-backed Surface - fRasterSurface.reset(SkSurface::NewRaster(info)); + fRasterSurface = SkSurface::MakeRaster(info); } void onPerCanvasPostDraw(SkCanvas*) override { @@ -57,7 +57,7 @@ protected: private: SkString fName; sk_sp fImage; - SkAutoTUnref fRasterSurface; + sk_sp fRasterSurface; typedef Benchmark INHERITED; }; diff --git a/bench/MergeBench.cpp b/bench/MergeBench.cpp index b24f988ded..e1f7d97b5e 100644 --- a/bench/MergeBench.cpp +++ b/bench/MergeBench.cpp @@ -51,7 +51,7 @@ private: } void make_bitmap() { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(80, 80)); + auto surface(SkSurface::MakeRasterN32Premul(80, 80)); surface->getCanvas()->clear(0x00000000); SkPaint paint; paint.setAntiAlias(true); @@ -63,7 +63,7 @@ private: } void make_checkerboard() { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(80, 80)); + auto surface(SkSurface::MakeRasterN32Premul(80, 80)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkPaint darkPaint; diff --git a/bench/SKPBench.cpp b/bench/SKPBench.cpp index 1d378b5046..add415dcb8 100644 --- a/bench/SKPBench.cpp +++ b/bench/SKPBench.cpp @@ -72,7 +72,7 @@ void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { for (int x = bounds.fLeft; x < bounds.fRight; x += tileW) { const SkIRect tileRect = SkIRect::MakeXYWH(x, y, tileW, tileH); *fTileRects.append() = tileRect; - *fSurfaces.push() = canvas->newSurface(ii); + *fSurfaces.push() = canvas->makeSurface(ii).release(); // Never want the contents of a tile to include stuff the parent // canvas clips out diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 3a3bca673f..c0f674fc59 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -132,8 +132,8 @@ static SkString humanize(double ms) { bool Target::init(SkImageInfo info, Benchmark* bench) { if (Benchmark::kRaster_Backend == config.backend) { - this->surface.reset(SkSurface::NewRaster(info)); - if (!this->surface.get()) { + this->surface = SkSurface::MakeRaster(info); + if (!this->surface) { return false; } } @@ -183,10 +183,10 @@ struct GPUTarget : public Target { uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType, - this->config.ctxOptions), + this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType, + this->config.ctxOptions), SkBudgeted::kNo, info, - this->config.samples, &props)); + this->config.samples, &props); this->gl = gGrFactory->getContextInfo(this->config.ctxType, this->config.ctxOptions).fGLContext; if (!this->surface.get()) { diff --git a/bench/nanobench.h b/bench/nanobench.h index ad538dd896..5e4efbf077 100644 --- a/bench/nanobench.h +++ b/bench/nanobench.h @@ -44,7 +44,7 @@ struct Target { virtual ~Target() { } const Config config; - SkAutoTDelete surface; + sk_sp surface; /** Called once per target, immediately before any timing or drawing. */ virtual void setup() { } diff --git a/cmake/example.cpp b/cmake/example.cpp index 93611d7c96..96bf4d3ff8 100644 --- a/cmake/example.cpp +++ b/cmake/example.cpp @@ -47,15 +47,15 @@ template std::shared_ptr adopt(T* ptr) { static std::shared_ptr create_raster_surface(int w, int h) { std::cout << "Using raster surface" << std::endl; - return adopt(SkSurface::NewRasterN32Premul(w, h)); + return adopt(SkSurface::MakeRasterN32Premul(w, h).release()); } static std::shared_ptr create_opengl_surface(int w, int h) { std::cout << "Using opengl surface" << std::endl; std::shared_ptr grContext = adopt(GrContext::Create(kOpenGL_GrBackend, 0)); - return adopt(SkSurface::NewRenderTarget(grContext.get(), + return adopt(SkSurface::MakeRenderTarget(grContext.get(), SkBudgeted::kNo, - SkImageInfo::MakeN32Premul(w,h))); + SkImageInfo::MakeN32Premul(w,h)).release()); } int main(int, char**) { diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h index ed276454fb..73adeb0302 100644 --- a/dm/DMGpuSupport.h +++ b/dm/DMGpuSupport.h @@ -28,16 +28,16 @@ namespace DM { static const bool kGPUDisabled = false; -static inline SkSurface* NewGpuSurface(GrContextFactory* grFactory, - GrContextFactory::GLContextType type, - GrContextFactory::GLContextOptions options, - SkImageInfo info, - int samples, - bool useDIText) { +static inline sk_sp NewGpuSurface(GrContextFactory* grFactory, + GrContextFactory::GLContextType type, + GrContextFactory::GLContextOptions options, + SkImageInfo info, + int samples, + bool useDIText) { uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - return SkSurface::NewRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, - info, samples, &props); + return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, + info, samples, &props); } } // namespace DM diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 6fd46c80ed..78782a0866 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -990,7 +990,7 @@ Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) co } #endif - SkAutoTUnref surface( + auto surface( NewGpuSurface(&factory, fContextType, fContextOptions, info, fSampleCount, fUseDIText)); if (!surface) { return "Could not create a surface."; @@ -1309,19 +1309,19 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri const int xTiles = (size.width() + fW - 1) / fW, yTiles = (size.height() + fH - 1) / fH; SkMultiPictureDraw mpd(xTiles*yTiles); - SkTDArray surfaces; - surfaces.setReserve(xTiles*yTiles); + SkTArray> surfaces; +// surfaces.setReserve(xTiles*yTiles); SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); for (int j = 0; j < yTiles; j++) { for (int i = 0; i < xTiles; i++) { // This lets our ultimate Sink determine the best kind of surface. // E.g., if it's a GpuSink, the surfaces and images are textures. - SkSurface* s = canvas->newSurface(info); + auto s = canvas->makeSurface(info); if (!s) { - s = SkSurface::NewRaster(info); // Some canvases can't create surfaces. + s = SkSurface::MakeRaster(info); // Some canvases can't create surfaces. } - surfaces.push(s); + surfaces.push_back(s); SkCanvas* c = s->getCanvas(); c->translate(SkIntToScalar(-i * fW), SkIntToScalar(-j * fH)); // Line up the canvas with this tile. @@ -1335,7 +1335,6 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH)); } } - surfaces.unrefAll(); return ""; }); } diff --git a/example/HelloWorld.h b/example/HelloWorld.h index ef4e417ad6..619ee7cb4d 100644 --- a/example/HelloWorld.h +++ b/example/HelloWorld.h @@ -36,11 +36,11 @@ protected: SkSurface* createSurface() override { SkSurfaceProps props(INHERITED::getSurfaceProps()); if (kGPU_DeviceType == fType) { - return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); + return SkSurface::MakeRenderTargetDirect(fRenderTarget, &props).release(); } static const SkImageInfo info = SkImageInfo::MakeN32Premul( SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height())); - return fSurface = SkSurface::NewRaster(info, &props); + return fSurface = SkSurface::MakeRaster(info, &props).release(); } void draw(SkCanvas* canvas) override; diff --git a/gm/bigtileimagefilter.cpp b/gm/bigtileimagefilter.cpp index 84b9816a83..7d3d3afeed 100644 --- a/gm/bigtileimagefilter.cpp +++ b/gm/bigtileimagefilter.cpp @@ -11,7 +11,7 @@ #include "gm.h" static sk_sp create_circle_texture(int size, SkColor color) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(size, size)); + auto surface(SkSurface::MakeRasterN32Premul(size, size)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0xFF000000); diff --git a/gm/color4f.cpp b/gm/color4f.cpp index ec9bbcbfba..7704dee458 100644 --- a/gm/color4f.cpp +++ b/gm/color4f.cpp @@ -77,7 +77,7 @@ DEF_SIMPLE_GM(color4f, canvas, 1024, 260) { for (auto profile : profiles) { const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType, profile); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); surface->getCanvas()->drawPaint(bg); draw_into_canvas(surface->getCanvas()); surface->draw(canvas, 0, 0, nullptr); diff --git a/gm/complexclip_blur_tiled.cpp b/gm/complexclip_blur_tiled.cpp index b619e67e14..9413e64e07 100644 --- a/gm/complexclip_blur_tiled.cpp +++ b/gm/complexclip_blur_tiled.cpp @@ -40,9 +40,9 @@ protected: } int ts = SkScalarCeilToInt(tile_size); SkImageInfo info = SkImageInfo::MakeN32Premul(ts, ts); - SkAutoTUnref tileSurface(canvas->newSurface(info)); - if (!tileSurface.get()) { - tileSurface.reset(SkSurface::NewRaster(info)); + auto tileSurface(canvas->makeSurface(info)); + if (!tileSurface) { + tileSurface = SkSurface::MakeRaster(info); } SkCanvas* tileCanvas = tileSurface->getCanvas(); for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { diff --git a/gm/dftext.cpp b/gm/dftext.cpp index 545911c26c..0d5b1ff4e9 100644 --- a/gm/dftext.cpp +++ b/gm/dftext.cpp @@ -51,9 +51,8 @@ protected: SkImageInfo info = SkImageInfo::MakeN32Premul(onISize()); SkSurfaceProps props(SkSurfaceProps::kUseDeviceIndependentFonts_Flag, SkSurfaceProps::kLegacyFontHost_InitType); - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, - info, 0, &props)); - SkCanvas* canvas = surface.get() ? surface->getCanvas() : inputCanvas; + auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props)); + SkCanvas* canvas = surface ? surface->getCanvas() : inputCanvas; // init our new canvas with the old canvas's matrix canvas->setMatrix(inputCanvas->getTotalMatrix()); #else diff --git a/gm/discard.cpp b/gm/discard.cpp index 6f64b9c0b9..d75f0ab141 100644 --- a/gm/discard.cpp +++ b/gm/discard.cpp @@ -45,8 +45,7 @@ protected: size.fWidth /= 10; size.fHeight /= 10; SkImageInfo info = SkImageInfo::MakeN32Premul(size); - SkSurface* surface = SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info); - + auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); if (nullptr == surface) { return; } @@ -78,7 +77,6 @@ protected: } surface->getCanvas()->discard(); - surface->unref(); } private: diff --git a/gm/drawatlas.cpp b/gm/drawatlas.cpp index 4d2f6d46f3..334aba7af1 100644 --- a/gm/drawatlas.cpp +++ b/gm/drawatlas.cpp @@ -13,9 +13,9 @@ class DrawAtlasGM : public skiagm::GM { static sk_sp MakeAtlas(SkCanvas* caller, const SkRect& target) { SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surface(caller->newSurface(info)); + auto surface(caller->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* canvas = surface->getCanvas(); // draw red everywhere, but we don't expect to see it in the draw, testing the notion diff --git a/gm/drawatlascolor.cpp b/gm/drawatlascolor.cpp index 85a7a9473a..e8fd23608c 100644 --- a/gm/drawatlascolor.cpp +++ b/gm/drawatlascolor.cpp @@ -19,9 +19,9 @@ static sk_sp make_atlas(SkCanvas* caller, int atlasSize) { const int kBlockSize = atlasSize/2; SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); - SkAutoTUnref surface(caller->newSurface(info)); + auto surface(caller->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* canvas = surface->getCanvas(); diff --git a/gm/drawbitmaprect.cpp b/gm/drawbitmaprect.cpp index 8ec7cee28e..883e81b417 100644 --- a/gm/drawbitmaprect.cpp +++ b/gm/drawbitmaprect.cpp @@ -36,10 +36,10 @@ static SkBitmap make_chessbm(int w, int h) { static sk_sp makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) { SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); - SkAutoTUnref surface(origCanvas->newSurface(info)); + auto surface(origCanvas->makeSurface(info)); if (nullptr == surface) { // picture canvas will return null, so fall-back to raster - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* canvas = surface->getCanvas(); diff --git a/gm/drawminibitmaprect.cpp b/gm/drawminibitmaprect.cpp index c494605daf..f5164f78de 100644 --- a/gm/drawminibitmaprect.cpp +++ b/gm/drawminibitmaprect.cpp @@ -15,9 +15,9 @@ static sk_sp makebm(SkCanvas* caller, int w, int h) { SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); - SkAutoTUnref surface(caller->newSurface(info)); + auto surface(caller->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* canvas = surface->getCanvas(); diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp index d76cd463ad..46e810eeb0 100644 --- a/gm/fatpathfill.cpp +++ b/gm/fatpathfill.cpp @@ -15,8 +15,8 @@ #define SMALL_H 3 #define REPEAT_LOOP 5 -static SkSurface* new_surface(int width, int height) { - return SkSurface::NewRasterN32Premul(width, height); +static sk_sp new_surface(int width, int height) { + return SkSurface::MakeRasterN32Premul(width, height); } static void draw_pixel_centers(SkCanvas* canvas) { @@ -49,7 +49,7 @@ static void draw_fatpath(SkCanvas* canvas, SkSurface* surface, const SkPath& pat DEF_SIMPLE_GM(fatpathfill, canvas, SMALL_W * ZOOM, SMALL_H * ZOOM * REPEAT_LOOP) { - SkAutoTUnref surface(new_surface(SMALL_W, SMALL_H)); + auto surface(new_surface(SMALL_W, SMALL_H)); canvas->scale(ZOOM, ZOOM); @@ -62,7 +62,7 @@ DEF_SIMPLE_GM(fatpathfill, canvas, line.moveTo(1, 2); line.lineTo(SkIntToScalar(4 + i), 1); paint.getFillPath(line, &path); - draw_fatpath(canvas, surface, path); + draw_fatpath(canvas, surface.get(), path); canvas->translate(0, SMALL_H); } diff --git a/gm/filterfastbounds.cpp b/gm/filterfastbounds.cpp index 9dabdcb7df..1de30e5826 100644 --- a/gm/filterfastbounds.cpp +++ b/gm/filterfastbounds.cpp @@ -264,7 +264,7 @@ protected: //----------- // Paints with a SkImageSource as a source - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); { SkPaint p; SkCanvas* temp = surface->getCanvas(); diff --git a/gm/image.cpp b/gm/image.cpp index b32e430e91..8cc3023edf 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -167,21 +167,20 @@ protected: sk_bzero(fBuffer, fBufferSize); SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); - SkAutoTUnref surf0(SkSurface::NewRasterDirect(info, fBuffer, RB)); - SkAutoTUnref surf1(SkSurface::NewRaster(info)); - SkAutoTUnref surf2; // gpu + sk_sp surf0(SkSurface::MakeRasterDirect(info, fBuffer, RB)); + sk_sp surf1(SkSurface::MakeRaster(info)); + sk_sp surf2; // gpu #if SK_SUPPORT_GPU - surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), - SkBudgeted::kNo, info)); + surf2 = SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::kNo, info); #endif - test_surface(canvas, surf0, true); + test_surface(canvas, surf0.get(), true); canvas->translate(80, 0); - test_surface(canvas, surf1, true); + test_surface(canvas, surf1.get(), true); if (surf2) { canvas->translate(80, 0); - test_surface(canvas, surf2, true); + test_surface(canvas, surf2.get(), true); } } @@ -238,7 +237,7 @@ static void draw_contents(SkCanvas* canvas) { } static sk_sp make_raster(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) { - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); draw(surface->getCanvas()); return surface->makeImageSnapshot(); } @@ -258,7 +257,7 @@ static sk_sp make_codec(const SkImageInfo& info, GrContext*, void (*dra static sk_sp make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(SkCanvas*)) { if (!ctx) { return nullptr; } - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info)); + auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); draw(surface->getCanvas()); return surface->makeImageSnapshot(); } @@ -335,7 +334,7 @@ static void draw_opaque_contents(SkCanvas* canvas) { } static SkImageGenerator* gen_raster(const SkImageInfo& info) { - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); draw_opaque_contents(surface->getCanvas()); return new ImageGeneratorFromImage(surface->makeImageSnapshot().get()); } @@ -481,9 +480,9 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { }, // Create a texture image [context, render_image]() -> sk_sp { - SkAutoTUnref surface( - SkSurface::NewRenderTarget(context, SkBudgeted::kYes, - SkImageInfo::MakeN32Premul(kSize, kSize))); + auto surface( + SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, + SkImageInfo::MakeN32Premul(kSize, kSize))); if (!surface) { return nullptr; } diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index b5eb522dfa..32092213dc 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -211,8 +211,7 @@ public: : SkImageGenerator(info) , fCtx(SkRef(ctx)) { - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, - info, 0)); + auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); surface->getCanvas()->clear(0); surface->getCanvas()->translate(-100, -100); surface->getCanvas()->drawPicture(pic); diff --git a/gm/image_shader.cpp b/gm/image_shader.cpp index 061539013e..5fed7d1344 100644 --- a/gm/image_shader.cpp +++ b/gm/image_shader.cpp @@ -27,7 +27,7 @@ static void draw_something(SkCanvas* canvas, const SkRect& bounds) { typedef sk_sp (*ImageMakerProc)(GrContext*, SkPicture*, const SkImageInfo&); static sk_sp make_raster(GrContext*, SkPicture* pic, const SkImageInfo& info) { - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); surface->getCanvas()->clear(0); surface->getCanvas()->drawPicture(pic); return surface->makeImageSnapshot(); @@ -37,8 +37,7 @@ static sk_sp make_texture(GrContext* ctx, SkPicture* pic, const SkImage if (!ctx) { return nullptr; } - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, - info, 0)); + auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); surface->getCanvas()->clear(0); surface->getCanvas()->drawPicture(pic); return surface->makeImageSnapshot(); diff --git a/gm/imagealphathreshold.cpp b/gm/imagealphathreshold.cpp index eafc32f8d6..8d65cf8ee7 100644 --- a/gm/imagealphathreshold.cpp +++ b/gm/imagealphathreshold.cpp @@ -95,9 +95,9 @@ protected: void onDraw(SkCanvas* canvas) override { SkImageInfo info = SkImageInfo::MakeN32(WIDTH, HEIGHT, kOpaque_SkAlphaType); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } surface->getCanvas()->clear(SK_ColorWHITE); draw_rects(surface->getCanvas()); diff --git a/gm/imagefilters.cpp b/gm/imagefilters.cpp index 21ce0fef97..ab9ddf4098 100644 --- a/gm/imagefilters.cpp +++ b/gm/imagefilters.cpp @@ -68,9 +68,9 @@ DEF_SIMPLE_GM(imagefilters_xfermodes, canvas, 480, 480) { static sk_sp make_image(SkCanvas* canvas) { const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); if (!surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } surface->getCanvas()->drawRect(SkRect::MakeXYWH(25, 25, 50, 50), SkPaint()); return surface->makeImageSnapshot(); diff --git a/gm/imagefiltersclipped.cpp b/gm/imagefiltersclipped.cpp index 26ee24b1d4..01b0a43fcb 100644 --- a/gm/imagefiltersclipped.cpp +++ b/gm/imagefiltersclipped.cpp @@ -47,7 +47,7 @@ protected: SkScalar x = SkIntToScalar(width / 2); SkScalar y = SkIntToScalar(height / 2); SkScalar radius = SkMinScalar(x, y) * 0.8f; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + auto surface(SkSurface::MakeRasterN32Premul(width, height)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkColor colors[2]; diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index ada206cea4..450610aded 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -143,7 +143,7 @@ private: SkScalar x = SkIntToScalar(width / 2); SkScalar y = SkIntToScalar(height / 2); SkScalar radius = SkMinScalar(x, y) * 0.8f; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + auto surface(SkSurface::MakeRasterN32Premul(width, height)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkColor colors[2]; diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp index 391f4e5c1c..9c0150001c 100644 --- a/gm/imagefiltersscaled.cpp +++ b/gm/imagefiltersscaled.cpp @@ -139,7 +139,7 @@ private: SkScalar x = SkIntToScalar(width / 2); SkScalar y = SkIntToScalar(height / 2); SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIntToScalar(5)); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + auto surface(SkSurface::MakeRasterN32Premul(width, height)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkColor colors[2]; diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index 4243902efe..e9a6a5da6d 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -29,7 +29,7 @@ static sk_sp make_gradient_circle(int width, int height) { SkScalar y = SkIntToScalar(height / 2); SkScalar radius = SkMinScalar(x, y) * 0.8f; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + auto surface(SkSurface::MakeRasterN32Premul(width, height)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); diff --git a/gm/imagescalealigned.cpp b/gm/imagescalealigned.cpp index 66ad8b62f4..474490fd24 100644 --- a/gm/imagescalealigned.cpp +++ b/gm/imagescalealigned.cpp @@ -73,7 +73,7 @@ private: const SkPoint end = SkPoint::Make(start.x() + vec.x() * (kSegLen - 1), start.y() + vec.y() * (kSegLen - 1)); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(kSegLen, kSegLen)); + auto surface(SkSurface::MakeRasterN32Premul(kSegLen, kSegLen)); surface->getCanvas()->clear(SK_ColorTRANSPARENT); SkPaint paint; diff --git a/gm/imagesource2.cpp b/gm/imagesource2.cpp index 46c42f1d18..db8a9f69c4 100644 --- a/gm/imagesource2.cpp +++ b/gm/imagesource2.cpp @@ -41,7 +41,7 @@ protected: SK_ColorWHITE, SK_ColorGRAY, }; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(kImageSize, kImageSize)); + auto surface(SkSurface::MakeRasterN32Premul(kImageSize, kImageSize)); SkCanvas* canvas = surface->getCanvas(); int curColor = 0; diff --git a/gm/imagetoyuvplanes.cpp b/gm/imagetoyuvplanes.cpp index ddead1be42..63d3fa92da 100644 --- a/gm/imagetoyuvplanes.cpp +++ b/gm/imagetoyuvplanes.cpp @@ -13,12 +13,12 @@ #include "SkImage.h" static sk_sp create_image(GrContext* context, int width, int height) { - SkAutoTUnref surface; + sk_sp surface; SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); if (context) { - surface.reset(SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0)); + surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info); } else { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } if (!surface) { return nullptr; diff --git a/gm/lcdblendmodes.cpp b/gm/lcdblendmodes.cpp index c3fe9ff149..874714b7fc 100644 --- a/gm/lcdblendmodes.cpp +++ b/gm/lcdblendmodes.cpp @@ -61,9 +61,9 @@ protected: canvas->drawRect(r, p); SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* surfCanvas = surface->getCanvas(); diff --git a/gm/localmatriximagefilter.cpp b/gm/localmatriximagefilter.cpp index f99655863e..dd86c967f9 100644 --- a/gm/localmatriximagefilter.cpp +++ b/gm/localmatriximagefilter.cpp @@ -16,9 +16,9 @@ static sk_sp make_image(SkCanvas* rootCanvas) { SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surface(rootCanvas->newSurface(info)); + auto surface(rootCanvas->makeSurface(info)); if (!surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkPaint paint; diff --git a/gm/mipmap.cpp b/gm/mipmap.cpp index 4b1912a99c..9a0f060162 100644 --- a/gm/mipmap.cpp +++ b/gm/mipmap.cpp @@ -13,7 +13,7 @@ static sk_sp make_image() { const SkImageInfo info = SkImageInfo::MakeN32Premul(319, 52); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); SkCanvas* canvas = surface->getCanvas(); canvas->drawColor(sk_tool_utils::color_to_565(0xFFF8F8F8)); diff --git a/gm/multipicturedraw.cpp b/gm/multipicturedraw.cpp index a4b09b2c2f..03934a601d 100644 --- a/gm/multipicturedraw.cpp +++ b/gm/multipicturedraw.cpp @@ -241,15 +241,14 @@ static sk_sp make_sierpinski_picture() { return recorder.finishRecordingAsPicture(); } -static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height) { +static sk_sp create_compat_surface(SkCanvas* canvas, int width, int height) { SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - SkSurface* surface = canvas->newSurface(info); + auto surface = canvas->makeSurface(info); if (nullptr == surface) { // picture canvas returns nullptr so fall back to raster - surface = SkSurface::NewRaster(info); + surface = SkSurface::MakeRaster(info); } - return surface; } @@ -257,13 +256,12 @@ static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height) // fragments potentially generated by the MultiPictureDraw object class ComposeStep { public: - ComposeStep() : fSurf(nullptr), fX(0.0f), fY(0.0f), fPaint(nullptr) { } + ComposeStep() : fX(0.0f), fY(0.0f), fPaint(nullptr) { } ~ComposeStep() { - SkSafeUnref(fSurf); delete fPaint; } - SkSurface* fSurf; + sk_sp fSurf; SkScalar fX; SkScalar fY; SkPaint* fPaint; diff --git a/gm/ninepatchstretch.cpp b/gm/ninepatchstretch.cpp index f269376bb0..9b0b94ec27 100644 --- a/gm/ninepatchstretch.cpp +++ b/gm/ninepatchstretch.cpp @@ -8,11 +8,11 @@ #include "gm.h" #include "SkSurface.h" -static SkSurface* make_surface(SkCanvas* root, int N) { +static sk_sp make_surface(SkCanvas* root, int N) { SkImageInfo info = SkImageInfo::MakeN32Premul(N, N); - SkSurface* surface = root->newSurface(info); + auto surface = root->makeSurface(info); if (!surface) { - surface = SkSurface::NewRaster(info); + surface = SkSurface::MakeRaster(info); } return surface; } @@ -22,7 +22,7 @@ static sk_sp make_image(SkCanvas* root, SkIRect* center) { const int kStretchy = 8; const int kSize = 2*kFixed + kStretchy; - SkAutoTUnref surface(make_surface(root, kSize)); + auto surface(make_surface(root, kSize)); SkCanvas* canvas = surface->getCanvas(); SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize)); diff --git a/gm/perspshaders.cpp b/gm/perspshaders.cpp index b2ac3287f2..2b09cc64e0 100644 --- a/gm/perspshaders.cpp +++ b/gm/perspshaders.cpp @@ -13,9 +13,9 @@ static sk_sp make_image(SkCanvas* origCanvas, int w, int h) { SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); - SkAutoTUnref surface(origCanvas->newSurface(info)); + auto surface(origCanvas->makeSurface(info)); if (nullptr == surface) { - surface.reset(SkSurface::NewRaster(info)); + surface = SkSurface::MakeRaster(info); } SkCanvas* canvas = surface->getCanvas(); diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp index 2236b76b3e..b8ed100548 100644 --- a/gm/resizeimagefilter.cpp +++ b/gm/resizeimagefilter.cpp @@ -87,7 +87,7 @@ protected: deviceSize, kHigh_SkFilterQuality); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(16, 16)); + auto surface(SkSurface::MakeRasterN32Premul(16, 16)); SkCanvas* surfaceCanvas = surface->getCanvas(); surfaceCanvas->clear(0x000000); { diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp index 28bb04bd4e..93a9bc7f05 100644 --- a/gm/srcmode.cpp +++ b/gm/srcmode.cpp @@ -115,7 +115,7 @@ protected: } } - static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size, bool skipGPU) { + static sk_sp compat_surface(SkCanvas* canvas, const SkISize& size, bool skipGPU) { SkImageInfo info = SkImageInfo::MakeN32Premul(size); bool callNewSurface = true; @@ -124,17 +124,16 @@ protected: callNewSurface = false; } #endif - SkSurface* surface = callNewSurface ? canvas->newSurface(info) : nullptr; + sk_sp surface = callNewSurface ? canvas->makeSurface(info) : nullptr; if (nullptr == surface) { // picture canvas will return null, so fall-back to raster - surface = SkSurface::NewRaster(info); + surface = SkSurface::MakeRaster(info); } return surface; } virtual void onDraw(SkCanvas* canvas) { - SkAutoTUnref surf(compat_surface(canvas, this->getISize(), - this->isCanvasDeferred())); + auto surf(compat_surface(canvas, this->getISize(), this->isCanvasDeferred())); surf->getCanvas()->drawColor(SK_ColorWHITE); this->drawContent(surf->getCanvas()); surf->draw(canvas, 0, 0, nullptr); diff --git a/gm/surface.cpp b/gm/surface.cpp index c817f8d63a..436ea95286 100644 --- a/gm/surface.cpp +++ b/gm/surface.cpp @@ -21,8 +21,8 @@ static sk_sp make_shader() { return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode); } -static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo, - int disallowAA, int disallowDither) { +static sk_sp make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo, + int disallowAA, int disallowDither) { uint32_t flags = 0; if (disallowAA) { flags |= SkSurfaceProps::kDisallowAntiAlias_Flag; @@ -33,9 +33,9 @@ static SkSurface* make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelG SkSurfaceProps props(flags, geo); if (ctx) { - return SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props); + return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props); } else { - return SkSurface::NewRaster(info, &props); + return SkSurface::MakeRaster(info, &props); } } @@ -92,8 +92,7 @@ protected: for (int disallowDither = 0; disallowDither <= 1; ++disallowDither) { SkScalar y = 0; for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { - SkAutoTUnref surface(make_surface(ctx, info, rec[i].fGeo, - disallowAA, disallowDither)); + auto surface(make_surface(ctx, info, rec[i].fGeo, disallowAA, disallowDither)); test_draw(surface->getCanvas(), rec[i].fLabel); surface->draw(canvas, x, y, nullptr); y += H; @@ -134,16 +133,16 @@ protected: void onDraw(SkCanvas* canvas) override { SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surf(canvas->newSurface(info, nullptr)); - if (!surf.get()) { - surf.reset(SkSurface::NewRaster(info)); + auto surf(canvas->makeSurface(info, nullptr)); + if (!surf) { + surf = SkSurface::MakeRaster(info); } drawInto(surf->getCanvas()); sk_sp image(surf->makeImageSnapshot()); canvas->drawImage(image, 10, 10, nullptr); - SkAutoTUnref surf2(surf->newSurface(info)); + auto surf2(surf->makeSurface(info)); drawInto(surf2->getCanvas()); // Assert that the props were communicated transitively through the first image diff --git a/gm/textblobgeometrychange.cpp b/gm/textblobgeometrychange.cpp index bae2381b65..0632908dfb 100644 --- a/gm/textblobgeometrychange.cpp +++ b/gm/textblobgeometrychange.cpp @@ -44,7 +44,7 @@ protected: SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - SkAutoTUnref surface(canvas->newSurface(info, &props)); + auto surface(canvas->makeSurface(info, &props)); if (surface) { SkCanvas* c = surface->getCanvas(); diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp index 7923489370..b2697a8cf4 100644 --- a/gm/textblobmixedsizes.cpp +++ b/gm/textblobmixedsizes.cpp @@ -98,7 +98,7 @@ protected: void onDraw(SkCanvas* inputCanvas) override { SkCanvas* canvas = inputCanvas; - SkAutoTUnref surface; + sk_sp surface; if (fUseDFT) { #if SK_SUPPORT_GPU // Create a new Canvas to enable DFT @@ -106,8 +106,7 @@ protected: SkImageInfo info = SkImageInfo::MakeN32Premul(onISize()); SkSurfaceProps props(SkSurfaceProps::kUseDeviceIndependentFonts_Flag, SkSurfaceProps::kLegacyFontHost_InitType); - surface.reset(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, - &props)); + surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props); canvas = surface.get() ? surface->getCanvas() : inputCanvas; // init our new canvas with the old canvas's matrix canvas->setMatrix(inputCanvas->getTotalMatrix()); diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp index f21380ee38..ce726f2e86 100644 --- a/gm/textblobrandomfont.cpp +++ b/gm/textblobrandomfont.cpp @@ -102,7 +102,7 @@ protected: SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - SkAutoTUnref surface(canvas->newSurface(info, &props)); + auto surface(canvas->makeSurface(info, &props)); if (surface) { SkPaint paint; paint.setAntiAlias(true); diff --git a/gm/transparency.cpp b/gm/transparency.cpp index 5e057617d4..5f324605d8 100644 --- a/gm/transparency.cpp +++ b/gm/transparency.cpp @@ -62,7 +62,7 @@ DEF_SIMPLE_GM(transparency_check, canvas, 1792, 1080) { sk_tool_utils::color_to_565(0xFF666666), 8); { SkAutoCanvasRestore autoCanvasRestore(canvas, true); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(256, 9)); + auto surface(SkSurface::MakeRasterN32Premul(256, 9)); make_transparency(surface->getCanvas(), 256.0f, 9.0f); canvas->scale(7.0f, 120.0f); surface->draw(canvas, 0, 0, nullptr); diff --git a/gm/verylargebitmap.cpp b/gm/verylargebitmap.cpp index b3ed5603a6..78f8f59c8a 100644 --- a/gm/verylargebitmap.cpp +++ b/gm/verylargebitmap.cpp @@ -23,7 +23,7 @@ static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) { } static sk_sp make_raster_image(int width, int height, SkColor colors[2]) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(width, height)); + auto surface(SkSurface::MakeRasterN32Premul(width, height)); draw(surface->getCanvas(), width, height, colors); return surface->makeImageSnapshot(); } diff --git a/gm/xfermodes3.cpp b/gm/xfermodes3.cpp index 4cd05df5c4..84bc1e2218 100644 --- a/gm/xfermodes3.cpp +++ b/gm/xfermodes3.cpp @@ -60,7 +60,7 @@ protected: 0x80, }; - SkAutoTUnref tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize)); + auto tempSurface(this->possiblyCreateTempSurface(canvas, kSize, kSize)); int test = 0; int x = 0, y = 0; @@ -83,7 +83,7 @@ protected: modePaint.setStyle(kStrokes[s].fStyle); modePaint.setStrokeWidth(kStrokes[s].fWidth); - this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface); + this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface.get()); ++test; x += kSize + 10; @@ -100,7 +100,7 @@ protected: modePaint.setStyle(kStrokes[s].fStyle); modePaint.setStrokeWidth(kStrokes[s].fWidth); - this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface); + this->drawMode(canvas, x, y, kSize, kSize, modePaint, tempSurface.get()); ++test; x += kSize + 10; @@ -122,13 +122,13 @@ private: * So when running on a GPU canvas we explicitly create a temporary canvas using a texture with * dimensions exactly matching the layer size. */ - SkSurface* possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) { + sk_sp possiblyCreateTempSurface(SkCanvas* baseCanvas, int w, int h) { #if SK_SUPPORT_GPU GrContext* context = baseCanvas->getGrContext(); SkImageInfo baseInfo = baseCanvas->imageInfo(); SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(), baseInfo.profileType()); - return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); + return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); #else return nullptr; #endif diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi index a76108416b..88a9e23452 100644 --- a/gyp/skia_for_android_framework_defines.gypi +++ b/gyp/skia_for_android_framework_defines.gypi @@ -23,6 +23,7 @@ 'SK_SUPPORT_LEGACY_DRAWFILTER', 'SK_SUPPORT_LEGACY_CREATESHADER_PTR', 'SK_SUPPORT_LEGACY_PATHEFFECT_PTR', + 'SK_SUPPORT_LEGACY_NEW_SURFACE_API', ], }, } diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h index d1cb9ad0f8..b53bfd0622 100644 --- a/include/core/SkBitmapDevice.h +++ b/include/core/SkBitmapDevice.h @@ -160,7 +160,7 @@ private: SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; - SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; + sk_sp makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; SkImageFilter::Cache* getImageFilterCache() override; diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index d551031739..bdb2eb0706 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -186,7 +186,10 @@ public: * inherits the properties of the surface that owns this canvas. If this canvas has no parent * surface, then the new surface is created with default properties. */ - SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps* = NULL); + sk_sp makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr); +#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API + SkSurface* newSurface(const SkImageInfo& info, const SkSurfaceProps* props = NULL); +#endif /** * Return the GPU context of the device that is associated with the canvas. @@ -1252,7 +1255,7 @@ public: protected: // default impl defers to getDevice()->newSurface(info) - virtual SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&); + virtual sk_sp onNewSurface(const SkImageInfo&, const SkSurfaceProps&); // default impl defers to its device virtual bool onPeekPixels(SkPixmap*); diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h index cd13d5482e..7339342256 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -296,7 +296,7 @@ protected: } protected: - virtual SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) { return NULL; } + virtual sk_sp makeSurface(const SkImageInfo&, const SkSurfaceProps&); virtual bool onPeekPixels(SkPixmap*) { return false; } /** diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index c420c524c1..ec76d26888 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -37,16 +37,16 @@ public: * If the requested surface cannot be created, or the request is not a * supported configuration, NULL will be returned. */ - static SkSurface* NewRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes, - const SkSurfaceProps* = NULL); + static sk_sp MakeRasterDirect(const SkImageInfo&, void* pixels, size_t rowBytes, + const SkSurfaceProps* = nullptr); /** * The same as NewRasterDirect, but also accepts a call-back routine, which is invoked * when the surface is deleted, and is passed the pixel memory and the specified context. */ - static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo&, void* pixels, size_t rowBytes, + static sk_sp MakeRasterDirectReleaseProc(const SkImageInfo&, void* pixels, size_t rowBytes, void (*releaseProc)(void* pixels, void* context), - void* context, const SkSurfaceProps* = NULL); + void* context, const SkSurfaceProps* = nullptr); /** * Return a new surface, with the memory for the pixels automatically allocated, but respecting @@ -57,30 +57,28 @@ public: * If the requested surface cannot be created, or the request is not a * supported configuration, NULL will be returned. */ - static SkSurface* NewRaster(const SkImageInfo&, size_t rowBytes, const SkSurfaceProps*); + static sk_sp MakeRaster(const SkImageInfo&, size_t rowBytes, const SkSurfaceProps*); /** * Allocate a new surface, automatically computing the rowBytes. */ - static SkSurface* NewRaster(const SkImageInfo&, const SkSurfaceProps* = NULL); + static sk_sp MakeRaster(const SkImageInfo&, const SkSurfaceProps* = nullptr); /** * Helper version of NewRaster. It creates a SkImageInfo with the * specified width and height, and populates the rest of info to match * pixels in SkPMColor format. */ - static SkSurface* NewRasterN32Premul(int width, int height, const SkSurfaceProps* props = NULL) { - return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); + static sk_sp MakeRasterN32Premul(int width, int height, + const SkSurfaceProps* props = nullptr) { + return MakeRaster(SkImageInfo::MakeN32Premul(width, height), props); } /** * Return a new surface using the specified render target. */ - static SkSurface* NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*); - - static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { - return NewRenderTargetDirect(target, NULL); - } + static sk_sp MakeRenderTargetDirect(GrRenderTarget*, + const SkSurfaceProps* = nullptr); /** * Used to wrap a pre-existing backend 3D API texture as a SkSurface. The kRenderTarget flag @@ -88,21 +86,17 @@ public: * of the texture and the client must ensure the texture is valid for the lifetime of the * SkSurface. */ - static SkSurface* NewFromBackendTexture(GrContext*, const GrBackendTextureDesc&, - const SkSurfaceProps*); - // Legacy alias - static SkSurface* NewWrappedRenderTarget(GrContext* ctx, const GrBackendTextureDesc& desc, - const SkSurfaceProps* props) { - return NewFromBackendTexture(ctx, desc, props); - } + static sk_sp MakeFromBackendTexture(GrContext*, const GrBackendTextureDesc&, + const SkSurfaceProps*); /** * Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia will not assume * ownership of the render target and the client must ensure the render target is valid for the * lifetime of the SkSurface. */ - static SkSurface* NewFromBackendRenderTarget(GrContext*, const GrBackendRenderTargetDesc&, - const SkSurfaceProps*); + static sk_sp MakeFromBackendRenderTarget(GrContext*, + const GrBackendRenderTargetDesc&, + const SkSurfaceProps*); /** * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat the texture as @@ -112,7 +106,7 @@ public: * of the texture and the client must ensure the texture is valid for the lifetime of the * SkSurface. */ - static SkSurface* NewFromBackendTextureAsRenderTarget( + static sk_sp MakeFromBackendTextureAsRenderTarget( GrContext*, const GrBackendTextureDesc&, const SkSurfaceProps*); /** @@ -122,13 +116,71 @@ public: * The GrTextureStorageAllocator will be reused if SkImage snapshots create * additional textures. */ - static SkSurface* NewRenderTarget( - GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, - const SkSurfaceProps* = NULL, GrTextureStorageAllocator = GrTextureStorageAllocator()); + static sk_sp MakeRenderTarget( + GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, const SkSurfaceProps*, + GrTextureStorageAllocator = GrTextureStorageAllocator()); + + static sk_sp MakeRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) { + return MakeRenderTarget(gr, b, info, 0, nullptr); + } +#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API + static SkSurface* NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes, + const SkSurfaceProps* props = NULL) { + return MakeRasterDirect(info, pixels, rowBytes, props).release(); + } + static SkSurface* NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, + size_t rowBytes, + void (*releaseProc)(void* pixels, void* context), + void* context, const SkSurfaceProps* props = NULL){ + return MakeRasterDirectReleaseProc(info, pixels, rowBytes, releaseProc, context, + props).release(); + } + static SkSurface* NewRaster(const SkImageInfo& info, size_t rowBytes, + const SkSurfaceProps* props) { + return MakeRaster(info, rowBytes, props).release(); + } + static SkSurface* NewRaster(const SkImageInfo& info, const SkSurfaceProps* props = NULL) { + return MakeRaster(info, props).release(); + } + static SkSurface* NewRasterN32Premul(int width, int height, + const SkSurfaceProps* props = NULL) { + return NewRaster(SkImageInfo::MakeN32Premul(width, height), props); + } + static SkSurface* NewRenderTargetDirect(GrRenderTarget* rt, const SkSurfaceProps* props) { + return MakeRenderTargetDirect(rt, props).release(); + } + static SkSurface* NewRenderTargetDirect(GrRenderTarget* target) { + return NewRenderTargetDirect(target, NULL); + } + static SkSurface* NewFromBackendTexture(GrContext* ctx, const GrBackendTextureDesc& desc, + const SkSurfaceProps* props) { + return MakeFromBackendTexture(ctx, desc, props).release(); + } + // Legacy alias + static SkSurface* NewWrappedRenderTarget(GrContext* ctx, const GrBackendTextureDesc& desc, + const SkSurfaceProps* props) { + return NewFromBackendTexture(ctx, desc, props); + } + static SkSurface* NewFromBackendRenderTarget(GrContext* ctx, const GrBackendRenderTargetDesc& d, + const SkSurfaceProps* props) { + return MakeFromBackendRenderTarget(ctx, d, props).release(); + } + static SkSurface* NewFromBackendTextureAsRenderTarget(GrContext* ctx, + const GrBackendTextureDesc& desc, + const SkSurfaceProps* props) { + return MakeFromBackendTextureAsRenderTarget(ctx, desc, props).release(); + } + static SkSurface* NewRenderTarget(GrContext* ctx, SkBudgeted b, const SkImageInfo& info, + int sampleCount, const SkSurfaceProps* props = NULL, + GrTextureStorageAllocator a = GrTextureStorageAllocator()) { + return MakeRenderTarget(ctx, b, info, sampleCount, props, a).release(); + } static SkSurface* NewRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) { return NewRenderTarget(gr, b, info, 0); } + SkSurface* newSurface(const SkImageInfo& info) { return this->makeSurface(info).release(); } +#endif int width() const { return fWidth; } int height() const { return fHeight; } @@ -223,7 +275,7 @@ public: * ... // draw using canvasB * canvasA->drawSurface(surfaceB); // <--- this will always be optimal! */ - SkSurface* newSurface(const SkImageInfo&); + sk_sp makeSurface(const SkImageInfo&); /** * Returns an image of the current state of the surface pixels up to this diff --git a/public.bzl b/public.bzl index 20914ea69c..f55cd35e17 100644 --- a/public.bzl +++ b/public.bzl @@ -522,6 +522,7 @@ DEFINES_ALL = [ # Chrome DEFINES. "SK_USE_FLOATBITS", "SK_USE_FREETYPE_EMBOLDEN", + "SK_SUPPORT_LEGACY_NEW_SURFACE_API", "SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR", "SK_SUPPORT_LEGACY_PATHEFFECT_PTR", # Turn on a few Google3-specific build fixes. diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index afd942bf1f..3149711d86 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -291,7 +291,7 @@ public: #if SK_SUPPORT_GPU if (IsGpuDeviceType(dType) && fCurContext) { SkSurfaceProps props(win->getSurfaceProps()); - return SkSurface::NewRenderTargetDirect(fCurRenderTarget, &props); + return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, &props).release(); } #endif return nullptr; @@ -1066,7 +1066,7 @@ void SampleWindow::draw(SkCanvas* canvas) { const SkScalar w = SkScalarCeilToScalar(tile.width()); const SkScalar h = SkScalarCeilToScalar(tile.height()); SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarTruncToInt(w), SkScalarTruncToInt(h)); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); SkCanvas* tileCanvas = surface->getCanvas(); for (SkScalar y = 0; y < height(); y += h) { diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp index 1075f4d12e..3061b14281 100644 --- a/samplecode/SampleAtlas.cpp +++ b/samplecode/SampleAtlas.cpp @@ -41,7 +41,7 @@ static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xfo static sk_sp make_atlas(int atlasSize, int cellSize) { SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); SkCanvas* canvas = surface->getCanvas(); SkPaint paint; diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 4b15e370e4..dd588816a0 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp @@ -91,9 +91,9 @@ public: fShader = sk_tool_utils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFFFF, zoom); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - fMinSurface.reset(SkSurface::NewRaster(info)); + fMinSurface = SkSurface::MakeRaster(info); info = info.makeWH(width * zoom, height * zoom); - fMaxSurface.reset(SkSurface::NewRaster(info)); + fMaxSurface = SkSurface::MakeRaster(info); } void drawBG(SkCanvas*); @@ -111,8 +111,8 @@ private: SkMatrix fMatrix, fInverse; SkRect fBounds, fClipRect; sk_sp fShader; - SkAutoTUnref fMinSurface; - SkAutoTUnref fMaxSurface; + sk_sp fMinSurface; + sk_sp fMaxSurface; void setupPaint(SkPaint* paint) { bool aa = this->getAA(); @@ -162,7 +162,7 @@ private: } void copyMinToMax() { - erase(fMaxSurface); + erase(fMaxSurface.get()); SkCanvas* canvas = fMaxSurface->getCanvas(); canvas->save(); canvas->concat(fMatrix); @@ -275,7 +275,7 @@ void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { apply_grid(pts, 2); } - erase(fMinSurface); + erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); if (fUseClip) { @@ -310,7 +310,7 @@ void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) { SkRect r; r.set(pts, 2); - erase(fMinSurface); + erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); { @@ -356,7 +356,7 @@ void FatBits::drawTriangle(SkCanvas* canvas, SkPoint pts[3]) { path.lineTo(pts[2]); path.close(); - erase(fMinSurface); + erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); fMinSurface->getCanvas()->drawPath(path, paint); diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp index 9098901959..ee998456c1 100644 --- a/samplecode/SampleFilterQuality.cpp +++ b/samplecode/SampleFilterQuality.cpp @@ -19,10 +19,10 @@ #include "SkRandom.h" #include "SkTime.h" -static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { - SkSurface* surface = canvas->newSurface(info); +static sk_sp make_surface(SkCanvas* canvas, const SkImageInfo& info) { + auto surface = canvas->makeSurface(info); if (!surface) { - surface = SkSurface::NewRaster(info); + surface = SkSurface::MakeRaster(info); } return surface; } @@ -41,7 +41,7 @@ static sk_sp make_shader(const SkRect& bounds) { static sk_sp make_image() { SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); SkCanvas* canvas = surface->getCanvas(); canvas->drawColor(SK_ColorWHITE); @@ -66,7 +66,7 @@ static sk_sp zoom_up(SkSurface* origSurf, SkImage* orig) { SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D, kOpaque_SkAlphaType); - SkAutoTUnref surface(origSurf->newSurface(info)); + auto surface(origSurf->makeSurface(info)); SkCanvas* canvas = surface->getCanvas(); canvas->drawColor(SK_ColorWHITE); canvas->scale(S, S); @@ -217,12 +217,12 @@ protected: SkISize size = SkISize::Make(fImage->width(), fImage->height()); - SkAutoTUnref surface; + sk_sp surface; if (fShowFatBits) { // scale up so we don't clip rotations SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage->height() * 2, kOpaque_SkAlphaType); - surface.reset(make_surface(canvas, info)); + surface = make_surface(canvas, info); canvas = surface->getCanvas(); canvas->drawColor(SK_ColorWHITE); size.set(info.width(), info.height()); @@ -234,7 +234,7 @@ protected: if (surface) { sk_sp orig(surface->makeImageSnapshot()); - sk_sp zoomed(zoom_up(surface, orig.get())); + sk_sp zoomed(zoom_up(surface.get(), orig.get())); origCanvas->drawImage(zoomed.get(), SkScalarHalf(fCell.width() - zoomed->width()), SkScalarHalf(fCell.height() - zoomed->height())); diff --git a/samplecode/SampleQuadStroker.cpp b/samplecode/SampleQuadStroker.cpp index 48f29f7f50..40f01fd105 100644 --- a/samplecode/SampleQuadStroker.cpp +++ b/samplecode/SampleQuadStroker.cpp @@ -76,7 +76,7 @@ static void getContourCounts(const SkPath& path, SkTArray* contourCounts) { } } -static void erase(SkSurface* surface) { +static void erase(const sk_sp& surface) { SkCanvas* canvas = surface->getCanvas(); if (canvas) { canvas->clear(SK_ColorTRANSPARENT); @@ -110,8 +110,8 @@ class QuadStrokerView : public SampleView { SkRect fBounds; SkMatrix fMatrix, fInverse; sk_sp fShader; - SkAutoTUnref fMinSurface; - SkAutoTUnref fMaxSurface; + sk_sp fMinSurface; + sk_sp fMaxSurface; StrokeTypeButton fCubicButton; StrokeTypeButton fConicButton; StrokeTypeButton fQuadButton; @@ -267,9 +267,9 @@ protected: fShader = sk_tool_utils::create_checkerboard_shader(0xFFCCCCCC, 0xFFFFFFFF, zoom); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - fMinSurface.reset(SkSurface::NewRaster(info)); + fMinSurface = SkSurface::MakeRaster(info); info = info.makeWH(width * zoom, height * zoom); - fMaxSurface.reset(SkSurface::NewRaster(info)); + fMaxSurface = SkSurface::MakeRaster(info); } void draw_points(SkCanvas* canvas, const SkPath& path, SkColor color, diff --git a/samplecode/SampleTextureDomain.cpp b/samplecode/SampleTextureDomain.cpp index 2c6dd64301..59d0822b44 100644 --- a/samplecode/SampleTextureDomain.cpp +++ b/samplecode/SampleTextureDomain.cpp @@ -60,7 +60,7 @@ protected: // Note: GPU-backed bitmaps follow a different rendering path // when copying from one GPU device to another. SkImageInfo info = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); - SkAutoTUnref surface(canvas->newSurface(info)); + auto surface(canvas->makeSurface(info)); srcRect.setXYWH(1, 1, 3, 3); dstRect.setXYWH(1, 1, 3, 3); diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp index 75a1643775..fcc22465c6 100644 --- a/src/c/sk_surface.cpp +++ b/src/c/sk_surface.cpp @@ -433,7 +433,7 @@ sk_surface_t* sk_surface_new_raster(const sk_imageinfo_t* cinfo, } SkSurfaceProps surfProps(0, geo); - return (sk_surface_t*)SkSurface::NewRaster(info, &surfProps); + return (sk_surface_t*)SkSurface::MakeRaster(info, &surfProps).release(); } sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pixels, @@ -449,7 +449,7 @@ sk_surface_t* sk_surface_new_raster_direct(const sk_imageinfo_t* cinfo, void* pi } SkSurfaceProps surfProps(0, geo); - return (sk_surface_t*)SkSurface::NewRasterDirect(info, pixels, rowBytes, &surfProps); + return (sk_surface_t*)SkSurface::MakeRasterDirect(info, pixels, rowBytes, &surfProps).release(); } void sk_surface_unref(sk_surface_t* csurf) { diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index fc0e63e9ae..c8ac8d2d44 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -360,8 +360,8 @@ void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, draw.drawSprite(static_cast(device)->fBitmap, x, y, paint); } -SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { - return SkSurface::NewRaster(info, &props); +sk_sp SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { + return SkSurface::MakeRaster(info, &props); } SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() { diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index f7f870210d..7c1c07b5f2 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1314,16 +1314,16 @@ void SkCanvas::internalRestore() { } } -SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* props) { +sk_sp SkCanvas::makeSurface(const SkImageInfo& info, const SkSurfaceProps* props) { if (nullptr == props) { props = &fProps; } return this->onNewSurface(info, *props); } -SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) { +sk_sp SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) { SkBaseDevice* dev = this->getDevice(); - return dev ? dev->newSurface(info, props) : nullptr; + return dev ? dev->makeSurface(info, props) : nullptr; } SkImageInfo SkCanvas::imageInfo() const { @@ -3043,3 +3043,9 @@ SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatri SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { fCanvas->restoreToCount(fSaveCount); } + +#ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API +SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* props) { + return this->makeSurface(info, props).release(); +} +#endif diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index fb4b48fdbd..d854520a97 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -452,3 +452,6 @@ uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { return flags; } +sk_sp SkBaseDevice::makeSurface(SkImageInfo const&, SkSurfaceProps const&) { + return nullptr; +} diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp index f90ac0f1ee..6f4ffa1f5b 100644 --- a/src/core/SkPictureImageGenerator.cpp +++ b/src/core/SkPictureImageGenerator.cpp @@ -139,9 +139,8 @@ GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, const SkIR // // TODO: respect the usage, by possibly creating a different (pow2) surface // - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kYes, - surfaceInfo)); - if (!surface.get()) { + sk_sp surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, surfaceInfo)); + if (!surface) { return nullptr; } diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 2718ee999d..459402b115 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -791,7 +791,7 @@ void SkPictureRecord::onDrawAnnotation(const SkRect& rect, const char key[], SkD /////////////////////////////////////////////////////////////////////////////// -SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&) { +sk_sp SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&) { return nullptr; } diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 089bc81ee5..129f94f9b3 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -149,7 +149,7 @@ protected: SkASSERT(fWriter.bytesWritten() == initialOffset + size); } - SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; + sk_sp onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; bool onPeekPixels(SkPixmap*) override { return false; } void willSave() override; diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 787c92252e..e73440ed2a 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -259,8 +259,7 @@ bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality quality) const { } bitmap.setIsVolatile(true); // so we don't try to cache it - SkAutoTUnref surface(SkSurface::NewRasterDirect(dst.info(), dst.writable_addr(), - dst.rowBytes())); + auto surface(SkSurface::MakeRasterDirect(dst.info(), dst.writable_addr(), dst.rowBytes())); if (!surface) { return false; } diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 4e23da20cc..ff5c27d7e5 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -11,6 +11,7 @@ #include "SkPicture.h" #include "SkPictureUtils.h" #include "SkRecorder.h" +#include "SkSurface.h" //#define WRAP_BITMAP_AS_IMAGE @@ -381,3 +382,6 @@ void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { APPEND(ClipRegion, this->devBounds(), deviceRgn, op); } +sk_sp SkRecorder::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) { + return nullptr; +} diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h index 44fb839d59..1299efbdd6 100644 --- a/src/core/SkRecorder.h +++ b/src/core/SkRecorder.h @@ -122,7 +122,7 @@ public: void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; void onDrawAnnotation(const SkRect&, const char[], SkData*) override; - SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override { return nullptr; } + sk_sp onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; void flushMiniRecorder(); diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index ecdd910c19..dfbde75dc7 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -41,7 +41,7 @@ public: virtual sk_sp onMakeTightSubset(const SkIRect& subset) const = 0; - virtual SkSurface* onMakeTightSurface(const SkImageInfo& info) const = 0; + virtual sk_sp onMakeTightSurface(const SkImageInfo& info) const = 0; private: typedef SkSpecialImage INHERITED; @@ -105,8 +105,7 @@ sk_sp SkSpecialImage::makeSurface(const SkImageInfo& info) con } sk_sp SkSpecialImage::makeTightSurface(const SkImageInfo& info) const { - sk_sp tmp(as_SIB(this)->onMakeTightSurface(info)); - return tmp; + return as_SIB(this)->onMakeTightSurface(info); } sk_sp SkSpecialImage::makeSubset(const SkIRect& subset) const { @@ -244,14 +243,14 @@ public: return fImage->makeSubset(subset); } - SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { + sk_sp onMakeTightSurface(const SkImageInfo& info) const override { #if SK_SUPPORT_GPU GrTexture* texture = as_IB(fImage.get())->peekTexture(); if (texture) { - return SkSurface::NewRenderTarget(texture->getContext(), SkBudgeted::kYes, info, 0); + return SkSurface::MakeRenderTarget(texture->getContext(), SkBudgeted::kYes, info); } #endif - return SkSurface::NewRaster(info, nullptr); + return SkSurface::MakeRaster(info, nullptr); } private: @@ -369,8 +368,8 @@ public: return SkImage::MakeFromBitmap(subsetBM); } - SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { - return SkSurface::NewRaster(info); + sk_sp onMakeTightSurface(const SkImageInfo& info) const override { + return SkSurface::MakeRaster(info); } private: @@ -512,8 +511,8 @@ public: fAlphaType, subTx, SkBudgeted::kYes); } - SkSurface* onMakeTightSurface(const SkImageInfo& info) const override { - return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info); + sk_sp onMakeTightSurface(const SkImageInfo& info) const override { + return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kYes, info); } private: diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp index 5638d8a6b2..f1a51a8fee 100644 --- a/src/gpu/GrLayerHoister.cpp +++ b/src/gpu/GrLayerHoister.cpp @@ -232,7 +232,7 @@ void GrLayerHoister::DrawLayersToAtlas(GrContext* context, if (atlased.count() > 0) { // All the atlased layers are rendered into the same GrTexture SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - SkAutoTUnref surface(SkSurface::NewRenderTargetDirect( + auto surface(SkSurface::MakeRenderTargetDirect( atlased[0].fLayer->texture()->asRenderTarget(), &props)); SkCanvas* atlasCanvas = surface->getCanvas(); @@ -334,7 +334,7 @@ void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray surface(SkSurface::NewRenderTargetDirect( + auto surface(SkSurface::MakeRenderTargetDirect( layer->texture()->asRenderTarget(), &props)); SkCanvas* layerCanvas = surface->getCanvas(); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 823e9b84ff..f4a1d4ee3e 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1799,12 +1799,12 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint } } -SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { +sk_sp SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { ASSERT_SINGLE_OWNER // TODO: Change the signature of newSurface to take a budgeted parameter. static const SkBudgeted kBudgeted = SkBudgeted::kNo; - return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt, - &props); + return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt, + &props); } bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture* mainPicture, diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index e57da44c69..8d69e4ce8e 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -180,7 +180,7 @@ private: SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) override; - SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; + sk_sp makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; SkImageFilter::Cache* getImageFilterCache() override; diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 8dc2cb6eae..ec5556a50d 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -39,8 +39,8 @@ public: // but only inspect them (or encode them). virtual bool getROPixels(SkBitmap*, CachingHint = kAllow_CachingHint) const = 0; - virtual SkSurface* onNewSurface(const SkImageInfo& info) const { - return SkSurface::NewRaster(info); + virtual sk_sp onNewSurface(const SkImageInfo& info) const { + return SkSurface::MakeRaster(info); } // Caller must call unref when they are done. diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp index f8af12a612..44dd7b11f8 100644 --- a/src/image/SkImage_Generator.cpp +++ b/src/image/SkImage_Generator.cpp @@ -79,7 +79,7 @@ sk_sp SkImage_Generator::onMakeSubset(const SkIRect& subset) const { const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height(), this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); if (!surface) { return nullptr; } diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 8f59af14a4..333a96386e 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -42,8 +42,8 @@ public: bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint) const override; - SkSurface* onNewSurface(const SkImageInfo& info) const override { - return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kNo, info); + sk_sp onNewSurface(const SkImageInfo& info) const override { + return SkSurface::MakeRenderTarget(fTexture->getContext(), SkBudgeted::kNo, info); } bool asBitmapForImageFilters(SkBitmap* bitmap) const override; diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index 764d5eb290..83daab7c44 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -176,7 +176,7 @@ sk_sp 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()); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); if (!surface) { return nullptr; } diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index bb807ba7a5..b3a65fa7b4 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -172,7 +172,7 @@ sk_sp SkSurface::makeImageSnapshot(SkBudgeted budgeted, ForceUnique uni return asSB(this)->refCachedImage(budgeted, unique); } -SkSurface* SkSurface::newSurface(const SkImageInfo& info) { +sk_sp SkSurface::makeSurface(const SkImageInfo& info) { return asSB(this)->onNewSurface(info); } @@ -222,27 +222,28 @@ void SkSurface::prepareForExternalIO() { #if !SK_SUPPORT_GPU -SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*) { +sk_sp SkSurface::MakeRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*) { return nullptr; } -SkSurface* SkSurface::NewRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int, - const SkSurfaceProps*, GrTextureStorageAllocator) { +sk_sp SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int, + const SkSurfaceProps*, GrTextureStorageAllocator) { return nullptr; } -SkSurface* SkSurface::NewFromBackendTexture(GrContext*, const GrBackendTextureDesc&, - const SkSurfaceProps*) { +sk_sp SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTextureDesc&, + const SkSurfaceProps*) { return nullptr; } -SkSurface* SkSurface::NewFromBackendRenderTarget(GrContext*, const GrBackendRenderTargetDesc&, - const SkSurfaceProps*) { +sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext*, + const GrBackendRenderTargetDesc&, + const SkSurfaceProps*) { return nullptr; } -SkSurface* NewFromBackendTextureAsRenderTarget(GrContext*, const GrBackendTextureDesc&, - const SkSurfaceProps*) { +sk_sp MakeFromBackendTextureAsRenderTarget(GrContext*, const GrBackendTextureDesc&, + const SkSurfaceProps*) { return nullptr; } diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h index 96dd305960..7164c884e0 100644 --- a/src/image/SkSurface_Base.h +++ b/src/image/SkSurface_Base.h @@ -35,7 +35,7 @@ public: */ virtual SkCanvas* onNewCanvas() = 0; - virtual SkSurface* onNewSurface(const SkImageInfo&) = 0; + virtual sk_sp onNewSurface(const SkImageInfo&) = 0; /** * Allocate an SkImage that represents the current contents of the surface. @@ -43,7 +43,7 @@ public: * must faithfully represent the current contents, even if the surface * is changed after this called (e.g. it is drawn to via its canvas). */ - virtual SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0; + virtual sk_sp onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0; /** * Default implementation: @@ -124,7 +124,7 @@ sk_sp SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique u } ForceCopyMode fcm = (kYes_ForceUnique == unique) ? kYes_ForceCopyMode : kNo_ForceCopyMode; - snap = this->onNewImageSnapshot(budgeted, fcm); + snap = this->onNewImageSnapshot(budgeted, fcm).release(); if (kNo_ForceUnique == unique) { SkASSERT(!fCachedImage); fCachedImage = SkSafeRef(snap); diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 649db129c3..a023acd9a2 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -68,16 +68,16 @@ SkCanvas* SkSurface_Gpu::onNewCanvas() { return new SkCanvas(fDevice, flags); } -SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { +sk_sp SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { GrRenderTarget* rt = fDevice->accessRenderTarget(); int sampleCount = rt->numColorSamples(); // TODO: Make caller specify this (change virtual signature of onNewSurface). static const SkBudgeted kBudgeted = SkBudgeted::kNo; - return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, - &this->props()); + return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, + &this->props()); } -SkImage* SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) { +sk_sp SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) { GrRenderTarget* rt = fDevice->accessRenderTarget(); SkASSERT(rt); GrTexture* tex = rt->asTexture(); @@ -99,10 +99,10 @@ SkImage* SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode fo tex = copy; } const SkImageInfo info = fDevice->imageInfo(); - SkImage* image = nullptr; + sk_sp image; if (tex) { - image = new SkImage_Gpu(info.width(), info.height(), kNeedNewImageUniqueID, - info.alphaType(), tex, budgeted); + image = sk_make_sp(info.width(), info.height(), kNeedNewImageUniqueID, + info.alphaType(), tex, budgeted); } return image; } @@ -134,29 +134,32 @@ void SkSurface_Gpu::onPrepareForExternalIO() { /////////////////////////////////////////////////////////////////////////////// -SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurfaceProps* props) { +sk_sp SkSurface::MakeRenderTargetDirect(GrRenderTarget* target, + const SkSurfaceProps* props) { SkAutoTUnref device( SkGpuDevice::Create(target, props, SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; } - return new SkSurface_Gpu(device); + return sk_make_sp(device); } -SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, SkBudgeted budgeted, const SkImageInfo& info, - int sampleCount, const SkSurfaceProps* props, - GrTextureStorageAllocator customAllocator) { +sk_sp SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted, + const SkImageInfo& info, int sampleCount, + const SkSurfaceProps* props, + GrTextureStorageAllocator customAllocator) { SkAutoTUnref device(SkGpuDevice::Create( ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitContents, customAllocator)); if (!device) { return nullptr; } - return new SkSurface_Gpu(device); + return sk_make_sp(device); } -SkSurface* SkSurface::NewFromBackendTexture(GrContext* context, const GrBackendTextureDesc& desc, - const SkSurfaceProps* props) { +sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, + const GrBackendTextureDesc& desc, + const SkSurfaceProps* props) { if (nullptr == context) { return nullptr; } @@ -173,12 +176,12 @@ SkSurface* SkSurface::NewFromBackendTexture(GrContext* context, const GrBackendT if (!device) { return nullptr; } - return new SkSurface_Gpu(device); + return sk_make_sp(device); } -SkSurface* SkSurface::NewFromBackendRenderTarget(GrContext* context, - const GrBackendRenderTargetDesc& desc, - const SkSurfaceProps* props) { +sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, + const GrBackendRenderTargetDesc& desc, + const SkSurfaceProps* props) { if (nullptr == context) { return nullptr; } @@ -191,12 +194,12 @@ SkSurface* SkSurface::NewFromBackendRenderTarget(GrContext* context, if (!device) { return nullptr; } - return new SkSurface_Gpu(device); + return sk_make_sp(device); } -SkSurface* SkSurface::NewFromBackendTextureAsRenderTarget(GrContext* context, - const GrBackendTextureDesc& desc, - const SkSurfaceProps* props) { +sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, + const GrBackendTextureDesc& desc, + const SkSurfaceProps* props) { if (nullptr == context) { return nullptr; } @@ -210,7 +213,7 @@ SkSurface* SkSurface::NewFromBackendTextureAsRenderTarget(GrContext* context, if (!device) { return nullptr; } - return new SkSurface_Gpu(device); + return sk_make_sp(device); } #endif diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h index 72e9caf462..1e76f26c2a 100644 --- a/src/image/SkSurface_Gpu.h +++ b/src/image/SkSurface_Gpu.h @@ -22,8 +22,8 @@ public: GrBackendObject onGetTextureHandle(BackendHandleAccess) override; bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) override; SkCanvas* onNewCanvas() override; - SkSurface* onNewSurface(const SkImageInfo&) override; - SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) override; + sk_sp onNewSurface(const SkImageInfo&) override; + sk_sp onNewImageSnapshot(SkBudgeted, ForceCopyMode) override; void onCopyOnWrite(ContentChangeMode) override; void onDiscard() override; void onPrepareForExternalIO() override; diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index b5844d1f5b..8c9c154a9c 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -23,8 +23,8 @@ public: SkSurface_Raster(SkPixelRef*, const SkSurfaceProps*); SkCanvas* onNewCanvas() override; - SkSurface* onNewSurface(const SkImageInfo&) override; - SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) override; + sk_sp onNewSurface(const SkImageInfo&) override; + sk_sp onNewImageSnapshot(SkBudgeted, ForceCopyMode) override; void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override; void onCopyOnWrite(ContentChangeMode) override; void onRestoreBackingMutability() override; @@ -109,8 +109,8 @@ SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props) SkCanvas* SkSurface_Raster::onNewCanvas() { return new SkCanvas(fBitmap, this->props()); } -SkSurface* SkSurface_Raster::onNewSurface(const SkImageInfo& info) { - return SkSurface::NewRaster(info, &this->props()); +sk_sp SkSurface_Raster::onNewSurface(const SkImageInfo& info) { + return SkSurface::MakeRaster(info, &this->props()); } void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, @@ -118,7 +118,7 @@ void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, canvas->drawBitmap(fBitmap, x, y, paint); } -SkImage* SkSurface_Raster::onNewImageSnapshot(SkBudgeted, ForceCopyMode forceCopyMode) { +sk_sp SkSurface_Raster::onNewImageSnapshot(SkBudgeted, ForceCopyMode forceCopyMode) { if (fWeOwnThePixels) { // SkImage_raster requires these pixels are immutable for its full lifetime. // We'll undo this via onRestoreBackingMutability() if we can avoid the COW. @@ -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 SkMakeImageFromRasterBitmap(fBitmap, forceCopyMode); } void SkSurface_Raster::onRestoreBackingMutability() { @@ -169,9 +169,9 @@ void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { /////////////////////////////////////////////////////////////////////////////// -SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, size_t rb, - void (*releaseProc)(void* pixels, void* context), - void* context, const SkSurfaceProps* props) { +sk_sp SkSurface::MakeRasterDirectReleaseProc(const SkImageInfo& info, void* pixels, + size_t rb, void (*releaseProc)(void* pixels, void* context), void* context, + const SkSurfaceProps* props) { if (nullptr == releaseProc) { context = nullptr; } @@ -182,16 +182,16 @@ SkSurface* SkSurface::NewRasterDirectReleaseProc(const SkImageInfo& info, void* return nullptr; } - return new SkSurface_Raster(info, pixels, rb, releaseProc, context, props); + return sk_make_sp(info, pixels, rb, releaseProc, context, props); } -SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes, - const SkSurfaceProps* props) { - return NewRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr, props); +sk_sp SkSurface::MakeRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes, + const SkSurfaceProps* props) { + return MakeRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr, props); } -SkSurface* SkSurface::NewRaster(const SkImageInfo& info, size_t rowBytes, - const SkSurfaceProps* props) { +sk_sp SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes, + const SkSurfaceProps* props) { if (!SkSurface_Raster::Valid(info)) { return nullptr; } @@ -203,9 +203,9 @@ SkSurface* SkSurface::NewRaster(const SkImageInfo& info, size_t rowBytes, if (rowBytes) { SkASSERT(pr->rowBytes() == rowBytes); } - return new SkSurface_Raster(pr, props); + return sk_make_sp(pr, props); } -SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* props) { - return NewRaster(info, 0, props); +sk_sp SkSurface::MakeRaster(const SkImageInfo& info, const SkSurfaceProps* props) { + return MakeRaster(info, 0, props); } diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 66048ff751..9ab3b0d7e0 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1412,8 +1412,8 @@ void SkPDFDevice::onDetachFromCanvas() { fClipStack = nullptr; } -SkSurface* SkPDFDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { - return SkSurface::NewRaster(info, &props); +sk_sp SkPDFDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { + return SkSurface::MakeRaster(info, &props); } ContentEntry* SkPDFDevice::getLastContentEntry() { @@ -2115,8 +2115,7 @@ static SkSize rect_to_size(const SkRect& r) { } static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFilter) { - sk_sp surface(SkSurface::NewRaster( - SkImageInfo::MakeN32Premul(image->dimensions()))); + auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(image->dimensions()))); if (!surface) { return image; } @@ -2194,8 +2193,7 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, SkISize wh = rect_to_size(physicalPerspectiveBounds).toCeil(); - sk_sp surface( - SkSurface::NewRaster(SkImageInfo::MakeN32Premul(wh))); + auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(wh))); if (!surface) { return; } diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index 138ec19b59..cfc2b546e8 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -195,7 +195,7 @@ protected: return fLegacyBitmap; } - SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override; + sk_sp makeSurface(const SkImageInfo&, const SkSurfaceProps&) override; void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override; diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index d0b6a4b1ac..c25bbf4409 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -716,11 +716,11 @@ static int lcanvas_newSurface(lua_State* L) { int width = lua2int_def(L, 2, 0); int height = lua2int_def(L, 3, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - SkSurface* surface = get_ref(L, 1)->newSurface(info); + auto surface = get_ref(L, 1)->makeSurface(info); if (nullptr == surface) { lua_pushnil(L); } else { - push_ref(L, surface)->unref(); + push_ref(L, surface); } return 1; } @@ -1769,11 +1769,11 @@ static int lsurface_newSurface(lua_State* L) { int width = lua2int_def(L, 2, 0); int height = lua2int_def(L, 3, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); - SkSurface* surface = get_ref(L, 1)->newSurface(info); + auto surface = get_ref(L, 1)->makeSurface(info); if (nullptr == surface) { lua_pushnil(L); } else { - push_ref(L, surface)->unref(); + push_ref(L, surface); } return 1; } @@ -2063,11 +2063,11 @@ static int lsk_newRasterSurface(lua_State* L) { int height = lua2int_def(L, 2, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - SkSurface* surface = SkSurface::NewRaster(info, &props); + auto surface = SkSurface::MakeRaster(info, &props); if (nullptr == surface) { lua_pushnil(L); } else { - push_ref(L, surface)->unref(); + push_ref(L, surface); } return 1; } diff --git a/src/utils/SkRGBAToYUV.cpp b/src/utils/SkRGBAToYUV.cpp index eebbda4869..63d9152362 100644 --- a/src/utils/SkRGBAToYUV.cpp +++ b/src/utils/SkRGBAToYUV.cpp @@ -38,7 +38,7 @@ bool SkRGBAToYUV(const SkImage* image, const SkISize sizes[3], void* const plane for (int i = 0; i < 3; ++i) { size_t rb = rowBytes[i] ? rowBytes[i] : sizes[i].fWidth; - SkAutoTUnref surface(SkSurface::NewRasterDirect( + auto surface(SkSurface::MakeRasterDirect( SkImageInfo::MakeA8(sizes[i].fWidth, sizes[i].fHeight), planes[i], rb)); if (!surface) { return false; diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp index 056b3eab50..481a1f9eb2 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -32,7 +32,8 @@ SkWindow::~SkWindow() { SkSurface* SkWindow::createSurface() { const SkBitmap& bm = this->getBitmap(); - return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), &fSurfaceProps); + return SkSurface::MakeRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), + &fSurfaceProps).release(); } void SkWindow::setMatrix(const SkMatrix& matrix) { diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp index 39ef738288..dc3d6c76e3 100644 --- a/tests/BlurTest.cpp +++ b/tests/BlurTest.cpp @@ -564,7 +564,7 @@ DEF_TEST(BlurAsABlur, reporter) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctx) { SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - SkAutoTUnref surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info)); + auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); SkCanvas* canvas = surface->getCanvas(); SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp index 8928d4c909..23fa2448a0 100644 --- a/tests/DrawBitmapRectTest.cpp +++ b/tests/DrawBitmapRectTest.cpp @@ -41,7 +41,7 @@ static void test_faulty_pixelref(skiatest::Reporter* reporter) { bm.setPixelRef(new FailurePixelRef(info), 0, 0)->unref(); // now our bitmap has a pixelref, but we know it will fail to lock - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(200, 200)); + auto surface(SkSurface::MakeRasterN32Premul(200, 200)); SkCanvas* canvas = surface->getCanvas(); const SkFilterQuality levels[] = { diff --git a/tests/DrawFilterTest.cpp b/tests/DrawFilterTest.cpp index f3e0a77306..ed23b701e5 100644 --- a/tests/DrawFilterTest.cpp +++ b/tests/DrawFilterTest.cpp @@ -27,7 +27,7 @@ public: * it was before the save. */ static void test_saverestore(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); SkCanvas* canvas = surface->getCanvas(); SkAutoTUnref df(new TestFilter); diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp index 8c46b100b3..9038406e13 100644 --- a/tests/DrawPathTest.cpp +++ b/tests/DrawPathTest.cpp @@ -18,7 +18,7 @@ static void test_big_aa_rect(skiatest::Reporter* reporter) { SkPMColor pixel[1]; output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4); - SkSurface* surf = SkSurface::NewRasterN32Premul(300, 33300); + auto surf = SkSurface::MakeRasterN32Premul(300, 33300); SkCanvas* canvas = surf->getCanvas(); SkRect r = { 0, 33000, 300, 33300 }; @@ -46,7 +46,6 @@ static void test_big_aa_rect(skiatest::Reporter* reporter) { } else { REPORTER_ASSERT_MESSAGE(reporter, false, "readPixels failed"); } - surf->unref(); } /////////////////////////////////////////////////////////////////////////////// @@ -95,7 +94,7 @@ static void test_crbug131181() { moveToH(&path, &data[0]); cubicToH(&path, &data[2]); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkPaint paint; paint.setAntiAlias(true); @@ -132,7 +131,7 @@ static void test_inversepathwithclip() { SkPaint paint; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkCanvas* canvas = surface->getCanvas(); canvas->save(); canvas->clipRect(SkRect::MakeWH(19, 11)); @@ -171,7 +170,7 @@ static void test_bug533() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); surface->getCanvas()->drawPath(path, paint); } @@ -213,7 +212,7 @@ static void test_bigcubic() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); surface->getCanvas()->drawPath(path, paint); } @@ -241,7 +240,7 @@ static void test_halfway() { m.postTranslate(0.001f, 0.001f); path.transform(m, &p2); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); SkCanvas* canvas = surface->getCanvas(); canvas->translate(-16366, -1383); canvas->drawPath(p2, paint); @@ -262,7 +261,7 @@ static void test_halfway() { static void test_giantaa() { const int W = 400; const int H = 400; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(33000, 10)); + auto surface(SkSurface::MakeRasterN32Premul(33000, 10)); SkPaint paint; paint.setAntiAlias(true); @@ -316,7 +315,7 @@ static void test_crbug_165432(skiatest::Reporter* reporter) { // http://crbug.com/472147 // This is a simplified version from the bug. RRect radii not properly scaled. static void test_crbug_472147_simple(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(1000, 1000)); + auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); SkCanvas* canvas = surface->getCanvas(); SkPaint p; SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); @@ -331,7 +330,7 @@ static void test_crbug_472147_simple(skiatest::Reporter* reporter) { // http://crbug.com/472147 // RRect radii not properly scaled. static void test_crbug_472147_actual(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(1000, 1000)); + auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); SkCanvas* canvas = surface->getCanvas(); SkPaint p; SkRect r = SkRect::MakeLTRB(-246.0f, 33.0f, 848.0f, 33554464.0f); diff --git a/tests/GpuDrawPathTest.cpp b/tests/GpuDrawPathTest.cpp index 1f9361ad1e..bab6d3a89b 100644 --- a/tests/GpuDrawPathTest.cpp +++ b/tests/GpuDrawPathTest.cpp @@ -80,9 +80,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuDrawPath, reporter, context) { for (auto& test_func : { &test_drawPathEmpty, &test_drawSameRectOvals }) { for (auto& sampleCount : {0, 4, 16}) { SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255); - SkAutoTUnref surface( - SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, - sampleCount, nullptr)); + auto surface( + SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, sampleCount, nullptr)); if (!surface) { continue; } diff --git a/tests/GrTextureMipMapInvalidationTest.cpp b/tests/GrTextureMipMapInvalidationTest.cpp index b047550e6d..539a8ce55c 100644 --- a/tests/GrTextureMipMapInvalidationTest.cpp +++ b/tests/GrTextureMipMapInvalidationTest.cpp @@ -41,7 +41,7 @@ DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context) REPORTER_ASSERT(reporter, false == tex->texturePriv().hasMipMaps()); // Painting with downscale and medium filter quality should result in mipmap creation - SkSurface* surface = SkSurface::NewRenderTargetDirect(texRT2->asRenderTarget()); + auto surface = SkSurface::MakeRenderTargetDirect(texRT2->asRenderTarget()); SkPaint paint; paint.setFilterQuality(kMedium_SkFilterQuality); surface->getCanvas()->scale(0.2f, 0.2f); @@ -56,7 +56,6 @@ DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context) REPORTER_ASSERT(reporter, true == tex->texturePriv().hasMipMaps()); REPORTER_ASSERT(reporter, true == tex->texturePriv().mipMapsAreDirty()); - surface->unref(); texRT1->unref(); texRT2->unref(); } diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp index 6521070552..0014089322 100644 --- a/tests/GradientTest.cpp +++ b/tests/GradientTest.cpp @@ -184,7 +184,7 @@ static void TestGradientShaders(skiatest::Reporter* reporter) { } static void test_nearly_vertical(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(200, 200)); + auto surface(SkSurface::MakeRasterN32Premul(200, 200)); const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }}; const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; @@ -200,7 +200,7 @@ static void test_nearly_vertical(skiatest::Reporter* reporter) { // The old code had an assert which this test triggered. // We now explicitly clamp the resulting fx value. static void test_linear_fuzz(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(1300, 630)); + auto surface(SkSurface::MakeRasterN32Premul(1300, 630)); const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }}; const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE }; @@ -216,7 +216,7 @@ static void test_linear_fuzz(skiatest::Reporter* reporter) { // https://bugs.chromium.org/p/skia/issues/detail?id=5023 // We should still shade pixels for which the radius is exactly 0. static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(5, 5)); + auto surface(SkSurface::MakeRasterN32Premul(5, 5)); surface->getCanvas()->clear(SK_ColorRED); const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 3350b4a25f..acdd369ff3 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -231,7 +231,7 @@ void MatrixTestImageFilter::toString(SkString* str) const { #endif static sk_sp make_small_image() { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(kBitmapSize, kBitmapSize)); + auto surface(SkSurface::MakeRasterN32Premul(kBitmapSize, kBitmapSize)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(0x00000000); SkPaint darkPaint; @@ -1495,7 +1495,7 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { // Verify that SkImageSource survives serialization DEF_TEST(ImageFilterImageSourceSerialization, reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); surface->getCanvas()->clear(SK_ColorGREEN); sk_sp image(surface->makeImageSnapshot()); SkAutoTUnref filter(SkImageSource::Create(image.get())); @@ -1562,7 +1562,7 @@ static void test_large_blur_input(skiatest::Reporter* reporter, SkCanvas* canvas } DEF_TEST(BlurLargeImage, reporter) { - SkAutoTUnref surface(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(100, 100))); + auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(100, 100))); test_large_blur_input(reporter, surface->getCanvas()); } @@ -1597,9 +1597,8 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(XfermodeImageFilterCroppedInput_Gpu, reporter, co } DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { - SkAutoTUnref surface( - SkSurface::NewRenderTarget(context, SkBudgeted::kYes, - SkImageInfo::MakeN32Premul(100, 100))); + auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, + SkImageInfo::MakeN32Premul(100, 100))); test_large_blur_input(reporter, surface->getCanvas()); } #endif diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp index 6f13708335..6b8b64ac21 100644 --- a/tests/ImageIsOpaqueTest.cpp +++ b/tests/ImageIsOpaqueTest.cpp @@ -48,18 +48,19 @@ DEF_TEST(ImageInfo_flattening, reporter) { } } -static void check_isopaque(skiatest::Reporter* reporter, SkSurface* surface, bool expectedOpaque) { +static void check_isopaque(skiatest::Reporter* reporter, const sk_sp& surface, + bool expectedOpaque) { sk_sp image(surface->makeImageSnapshot()); REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); } DEF_TEST(ImageIsOpaqueTest, reporter) { SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref surfaceTransparent(SkSurface::NewRaster(infoTransparent)); + auto surfaceTransparent(SkSurface::MakeRaster(infoTransparent)); check_isopaque(reporter, surfaceTransparent, false); SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); - SkAutoTUnref surfaceOpaque(SkSurface::NewRaster(infoOpaque)); + auto surfaceOpaque(SkSurface::MakeRaster(infoOpaque)); check_isopaque(reporter, surfaceOpaque, true); } @@ -67,13 +68,11 @@ DEF_TEST(ImageIsOpaqueTest, reporter) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, context) { SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref surfaceTransparent( - SkSurface::NewRenderTarget(context, SkBudgeted::kNo, infoTransparent)); + auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, infoTransparent)); check_isopaque(reporter, surfaceTransparent, false); SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); - SkAutoTUnref surfaceOpaque( - SkSurface::NewRenderTarget(context,SkBudgeted::kNo, infoOpaque)); + auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, infoOpaque)); check_isopaque(reporter, surfaceOpaque, true); } diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp index b6266ed60d..4ae0b6de8e 100644 --- a/tests/ImageNewShaderTest.cpp +++ b/tests/ImageNewShaderTest.cpp @@ -104,8 +104,8 @@ void runShaderTest(skiatest::Reporter* reporter, SkSurface* sourceSurface, SkSur DEF_TEST(ImageNewShader, reporter) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref sourceSurface(SkSurface::NewRaster(info)); - SkAutoTUnref destinationSurface(SkSurface::NewRaster(info)); + auto sourceSurface(SkSurface::MakeRaster(info)); + auto destinationSurface(SkSurface::MakeRaster(info)); runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info); } @@ -115,10 +115,8 @@ DEF_TEST(ImageNewShader, reporter) { void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref sourceSurface( - SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info)); - SkAutoTUnref destinationSurface( - SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info)); + auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info); } @@ -126,9 +124,8 @@ void gpuToGpu(skiatest::Reporter* reporter, GrContext* context) { void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref sourceSurface(SkSurface::NewRenderTarget(context, - SkBudgeted::kNo, info)); - SkAutoTUnref destinationSurface(SkSurface::NewRaster(info)); + auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto destinationSurface(SkSurface::MakeRaster(info)); runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info); } @@ -136,9 +133,8 @@ void gpuToRaster(skiatest::Reporter* reporter, GrContext* context) { void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - SkAutoTUnref sourceSurface(SkSurface::NewRaster(info)); - SkAutoTUnref destinationSurface(SkSurface::NewRenderTarget(context, - SkBudgeted::kNo, info)); + auto sourceSurface(SkSurface::MakeRaster(info)); + auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info); } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index ce3cb99265..15ee54c000 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -62,13 +62,13 @@ static void draw_image_test_pattern(SkCanvas* canvas) { } static sk_sp create_image() { const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); draw_image_test_pattern(surface->getCanvas()); return surface->makeImageSnapshot(); } static sk_sp create_image_565() { const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOpaque_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); draw_image_test_pattern(surface->getCanvas()); return surface->makeImageSnapshot(); } @@ -146,8 +146,7 @@ static sk_sp create_codec_image() { #if SK_SUPPORT_GPU static sk_sp create_gpu_image(GrContext* context) { const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, - info)); + auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); draw_image_test_pattern(surface->getCanvas()); return surface->makeImageSnapshot(); } @@ -224,7 +223,7 @@ DEF_TEST(Image_Encode_Serializer, reporter) { // Test that image encoding failures do not break picture serialization/deserialization. DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(100, 100)); + auto surface(SkSurface::MakeRasterN32Premul(100, 100)); surface->getCanvas()->clear(SK_ColorGREEN); sk_sp image(surface->makeImageSnapshot()); REPORTER_ASSERT(reporter, image); @@ -287,7 +286,7 @@ DEF_TEST(Image_RetainSnapshot, reporter) { const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); surface->getCanvas()->clear(0xFF00FF00); SkPMColor pixels[4]; @@ -373,7 +372,7 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { sk_sp image(create_gpu_image(context)); const uint32_t uniqueID = image->uniqueID(); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); // now we can test drawing a gpu-backed image into a cpu-backed surface diff --git a/tests/IndexedPngOverflowTest.cpp b/tests/IndexedPngOverflowTest.cpp index f516898a1a..1a48b6499b 100644 --- a/tests/IndexedPngOverflowTest.cpp +++ b/tests/IndexedPngOverflowTest.cpp @@ -33,7 +33,7 @@ DEF_TEST(IndexedPngOverflow, reporter) { bool success = decode_memory(gPng, sizeof(gPng), &image); REPORTER_ASSERT(reporter, success); - SkAutoTUnref surface(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(20, 1))); + auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(20, 1))); SkCanvas* canvas = surface->getCanvas(); SkRect destRect = SkRect::MakeXYWH(0, 0, 20, 1); canvas->drawBitmapRect(image, destRect, nullptr); diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp index 2ba40005d4..dd6f41cbfa 100644 --- a/tests/PathTest.cpp +++ b/tests/PathTest.cpp @@ -99,7 +99,7 @@ static void make_path_crbug364224_simplified(SkPath* path) { static void test_path_crbug364224() { SkPath path; SkPaint paint; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(84, 88)); + auto surface(SkSurface::MakeRasterN32Premul(84, 88)); SkCanvas* canvas = surface->getCanvas(); make_path_crbug364224_simplified(&path); @@ -293,7 +293,7 @@ static void test_bad_cubic_crbug234190() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(84, 88)); + auto surface(SkSurface::MakeRasterN32Premul(84, 88)); surface->getCanvas()->drawPath(path, paint); } @@ -412,7 +412,7 @@ static void test_crbug_170666() { SkPaint paint; paint.setAntiAlias(true); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(1000, 1000)); + auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); build_path_simple_170666(path); surface->getCanvas()->drawPath(path, paint); @@ -553,7 +553,7 @@ static void build_big_path(SkPath* path, bool reducedCase) { } static void test_clipped_cubic() { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(640, 480)); + auto surface(SkSurface::MakeRasterN32Premul(640, 480)); // This path used to assert, because our cubic-chopping code incorrectly // moved control points after the chop. This test should be run in SK_DEBUG @@ -626,9 +626,7 @@ static void test_tricky_cubic() { SkPaint paint; paint.setAntiAlias(true); - SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130); - surface->getCanvas()->drawPath(path, paint); - surface->unref(); + SkSurface::MakeRasterN32Premul(19, 130)->getCanvas()->drawPath(path, paint); } // Inspired by http://code.google.com/p/chromium/issues/detail?id=141651 diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 87e51163da..b538fc8c9b 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -324,7 +324,7 @@ const SkIRect gReadPixelsTestRects[] = { SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), }; -static void test_readpixels(skiatest::Reporter* reporter, SkSurface* surface, +static void test_readpixels(skiatest::Reporter* reporter, const sk_sp& surface, BitmapInit lastBitmapInit) { SkCanvas* canvas = surface->getCanvas(); fill_src_canvas(canvas); @@ -382,7 +382,7 @@ static void test_readpixels(skiatest::Reporter* reporter, SkSurface* surface, } DEF_TEST(ReadPixels, reporter) { const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); // SW readback fails a premul check when reading back to an unaligned rowbytes. test_readpixels(reporter, surface, kLastAligned_BitmapInit); } @@ -397,7 +397,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) { desc.fOrigin = origin; SkAutoTUnref surfaceTexture( context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); - SkAutoTUnref surface(SkSurface::NewRenderTargetDirect(surfaceTexture->asRenderTarget())); + auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget())); desc.fFlags = kNone_GrSurfaceFlags; test_readpixels(reporter, surface, kLast_BitmapInit); } @@ -603,8 +603,8 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(ReadPixels_Subset_Gpu, reporter, context) { // do they draw the same? const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - SkAutoTUnref surfA(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0)); - SkAutoTUnref surfB(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0)); + auto surfA(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto surfB(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); if (false) { // @@ -613,8 +613,8 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(ReadPixels_Subset_Gpu, reporter, context) { // SkFilterQuality quality = kLow_SkFilterQuality; - SkAutoTUnref dataA(draw_into_surface(surfA, bm_subset, quality)); - SkAutoTUnref dataB(draw_into_surface(surfB, tx_subset, quality)); + SkAutoTUnref dataA(draw_into_surface(surfA.get(), bm_subset, quality)); + SkAutoTUnref dataB(draw_into_surface(surfB.get(), tx_subset, quality)); REPORTER_ASSERT(reporter, dataA->equals(dataB)); if (false) { diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp index 8d91fbc8d2..17d971126c 100644 --- a/tests/RecordDrawTest.cpp +++ b/tests/RecordDrawTest.cpp @@ -279,7 +279,7 @@ DEF_TEST(RecordDraw_drawImage, r){ bool fDrawImageRectCalled; }; - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); surface->getCanvas()->clear(SK_ColorGREEN); sk_sp image(surface->makeImageSnapshot()); diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp index 59d5a8e6cd..a709a51381 100644 --- a/tests/RecorderTest.cpp +++ b/tests/RecorderTest.cpp @@ -74,7 +74,7 @@ DEF_TEST(Recorder_drawImage_takeReference, reporter) { sk_sp image; { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(100, 100)); + auto surface(SkSurface::MakeRasterN32Premul(100, 100)); surface->getCanvas()->clear(SK_ColorGREEN); image = surface->makeImageSnapshot(); } diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 784ae7e94d..0931876cf1 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -37,8 +37,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) { desc.fWidth = gWidth; desc.fHeight = gHeight; SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight); - SkAutoTUnref surface(SkSurface::NewRenderTarget(context, - SkBudgeted::kNo, info)); + auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); SkCanvas* canvas = surface->getCanvas(); const SkIRect size = SkIRect::MakeWH(gWidth, gHeight); diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp index 7ae5f6486f..3c0d1ffee3 100644 --- a/tests/SkResourceCacheTest.cpp +++ b/tests/SkResourceCacheTest.cpp @@ -264,7 +264,7 @@ DEF_TEST(BitmapCache_discarded_bitmap, reporter) { static void test_discarded_image(skiatest::Reporter* reporter, const SkMatrix& transform, sk_sp (*buildImage)()) { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); SkCanvas* canvas = surface->getCanvas(); // SkBitmapCache is global, so other threads could be evicting our bitmaps. Loop a few times @@ -313,7 +313,7 @@ DEF_TEST(BitmapCache_discarded_image, reporter) { for (size_t i = 0; i < SK_ARRAY_COUNT(xforms); ++i) { test_discarded_image(reporter, xforms[i], []() { - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(10, 10)); + auto surface(SkSurface::MakeRasterN32Premul(10, 10)); surface->getCanvas()->clear(SK_ColorCYAN); return surface->makeImageSnapshot(); }); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 89c7765c56..4aaabd8062 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -27,57 +27,57 @@ static void release_direct_surface_storage(void* pixels, void* context) { SkASSERT(pixels == context); sk_free(pixels); } -static SkSurface* create_surface(SkAlphaType at = kPremul_SkAlphaType, - SkImageInfo* requestedInfo = nullptr) { +static sk_sp create_surface(SkAlphaType at = kPremul_SkAlphaType, + SkImageInfo* requestedInfo = nullptr) { const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); if (requestedInfo) { *requestedInfo = info; } - return SkSurface::NewRaster(info); + return SkSurface::MakeRaster(info); } -static SkSurface* create_direct_surface(SkAlphaType at = kPremul_SkAlphaType, - SkImageInfo* requestedInfo = nullptr) { +static sk_sp create_direct_surface(SkAlphaType at = kPremul_SkAlphaType, + SkImageInfo* requestedInfo = nullptr) { const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); if (requestedInfo) { *requestedInfo = info; } const size_t rowBytes = info.minRowBytes(); void* storage = sk_malloc_throw(info.getSafeSize(rowBytes)); - return SkSurface::NewRasterDirectReleaseProc(info, storage, rowBytes, - release_direct_surface_storage, - storage); + return SkSurface::MakeRasterDirectReleaseProc(info, storage, rowBytes, + release_direct_surface_storage, + storage); } #if SK_SUPPORT_GPU -static SkSurface* create_gpu_surface(GrContext* context, SkAlphaType at = kPremul_SkAlphaType, - SkImageInfo* requestedInfo = nullptr) { +static sk_sp create_gpu_surface(GrContext* context, SkAlphaType at = kPremul_SkAlphaType, + SkImageInfo* requestedInfo = nullptr) { const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); if (requestedInfo) { *requestedInfo = info; } - return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); + return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); } -static SkSurface* create_gpu_scratch_surface(GrContext* context, - SkAlphaType at = kPremul_SkAlphaType, - SkImageInfo* requestedInfo = nullptr) { +static sk_sp create_gpu_scratch_surface(GrContext* context, + SkAlphaType at = kPremul_SkAlphaType, + SkImageInfo* requestedInfo = nullptr) { const SkImageInfo info = SkImageInfo::MakeN32(10, 10, at); if (requestedInfo) { *requestedInfo = info; } - return SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr); + return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr); } #endif DEF_TEST(SurfaceEmpty, reporter) { const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); - REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRaster(info)); - REPORTER_ASSERT(reporter, nullptr == SkSurface::NewRasterDirect(info, nullptr, 0)); + REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRaster(info)); + REPORTER_ASSERT(reporter, nullptr == SkSurface::MakeRasterDirect(info, nullptr, 0)); } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); REPORTER_ASSERT(reporter, nullptr == - SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr)); + SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr)); } #endif @@ -107,8 +107,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; wrappedDesc.fTextureHandle = texHandle; - SkAutoTUnref surface( - SkSurface::NewWrappedRenderTarget(context, wrappedDesc, nullptr)); + auto surface(SkSurface::MakeFromBackendTexture(context, wrappedDesc, nullptr)); REPORTER_ASSERT(reporter, surface); if (surface) { // Validate that we can draw to the canvas and that the original texture color is preserved @@ -152,7 +151,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { #endif static void test_canvas_peek(skiatest::Reporter* reporter, - SkSurface* surface, + sk_sp& surface, const SkImageInfo& requestInfo, bool expectPeekSuccess) { const SkColor color = SK_ColorRED; @@ -181,7 +180,7 @@ static void test_canvas_peek(skiatest::Reporter* reporter, DEF_TEST(SurfaceCanvasPeek, reporter) { for (auto& surface_func : { &create_surface, &create_direct_surface }) { SkImageInfo requestInfo; - SkAutoTUnref surface(surface_func(kPremul_SkAlphaType, &requestInfo)); + auto surface(surface_func(kPremul_SkAlphaType, &requestInfo)); test_canvas_peek(reporter, surface, requestInfo, true); } } @@ -189,7 +188,7 @@ DEF_TEST(SurfaceCanvasPeek, reporter) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { SkImageInfo requestInfo; - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, &requestInfo)); + auto surface(surface_func(context, kPremul_SkAlphaType, &requestInfo)); test_canvas_peek(reporter, surface, requestInfo, false); } } @@ -199,7 +198,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { // the bitmap's genID when we draw to it, else they won't know it has new values. When they are // exclusively using surface/image, and we can hide accessBitmap from device, we can remove this // test. -void test_access_pixels(skiatest::Reporter* reporter, SkSurface* surface) { +void test_access_pixels(skiatest::Reporter* reporter, const sk_sp& surface) { SkCanvas* canvas = surface->getCanvas(); canvas->clear(0); @@ -214,20 +213,20 @@ void test_access_pixels(skiatest::Reporter* reporter, SkSurface* surface) { } DEF_TEST(SurfaceAccessPixels, reporter) { for (auto& surface_func : { &create_surface, &create_direct_surface }) { - SkAutoTUnref surface(surface_func(kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(kPremul_SkAlphaType, nullptr)); test_access_pixels(reporter, surface); } } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); test_access_pixels(reporter, surface); } } #endif -static void test_snapshot_alphatype(skiatest::Reporter* reporter, SkSurface* surface, +static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp& surface, bool expectOpaque) { REPORTER_ASSERT(reporter, surface); if (surface) { @@ -242,7 +241,7 @@ DEF_TEST(SurfaceSnapshotAlphaType, reporter) { for (auto& surface_func : { &create_surface, &create_direct_surface }) { for (auto& isOpaque : { true, false }) { SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; - SkAutoTUnref surface(surface_func(alphaType, nullptr)); + auto surface(surface_func(alphaType, nullptr)); test_snapshot_alphatype(reporter, surface, isOpaque); } } @@ -252,7 +251,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, conte for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { for (auto& isOpaque : { true, false }) { SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; - SkAutoTUnref surface(surface_func(context, alphaType, nullptr)); + auto surface(surface_func(context, alphaType, nullptr)); test_snapshot_alphatype(reporter, surface, isOpaque); } } @@ -293,8 +292,8 @@ DEF_TEST(SurfaceBackendHandleAccessCopyOnWrite, reporter) { for (auto& handle_access_func : { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle }) { for (auto& accessMode : accessModes) { - SkAutoTUnref surface(create_surface()); - test_backend_handle_access_copy_on_write(reporter, surface, accessMode, + auto surface(create_surface()); + test_backend_handle_access_copy_on_write(reporter, surface.get(), accessMode, handle_access_func); } } @@ -310,9 +309,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re for (auto& handle_access_func : { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle }) { for (auto& accessMode : accessModes) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, - nullptr)); - test_backend_handle_access_copy_on_write(reporter, surface, accessMode, + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_backend_handle_access_copy_on_write(reporter, surface.get(), accessMode, handle_access_func); } } @@ -390,16 +388,18 @@ DEF_TEST(UniqueImageSnapshot, reporter) { return reinterpret_cast(pixels); }; - SkAutoTUnref surface(create_surface()); - test_unique_image_snap(reporter, surface, false, getImageBackingStore, getSufaceBackingStore); - surface.reset(create_direct_surface()); - test_unique_image_snap(reporter, surface, true, getImageBackingStore, getSufaceBackingStore); + auto surface(create_surface()); + test_unique_image_snap(reporter, surface.get(), false, getImageBackingStore, + getSufaceBackingStore); + surface = create_direct_surface(); + test_unique_image_snap(reporter, surface.get(), true, getImageBackingStore, + getSufaceBackingStore); } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); + auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); auto imageBackingStore = [reporter](SkImage* image) { GrTexture* texture = as_IB(image)->peekTexture(); @@ -420,7 +420,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { return static_cast(rt->getUniqueID()); }; - test_unique_image_snap(reporter, surface, false, imageBackingStore, surfaceBackingStore); + test_unique_image_snap(reporter, surface.get(), false, imageBackingStore, + surfaceBackingStore); // Test again with a "direct" render target; GrBackendObject textureObject = context->getGpu()->createTestingOnlyBackendTexture(nullptr, @@ -433,9 +434,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { desc.fTextureHandle = textureObject; GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc); { - SkAutoTUnref surface( - SkSurface::NewRenderTargetDirect(texture->asRenderTarget())); - test_unique_image_snap(reporter, surface, true, imageBackingStore, + auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget())); + test_unique_image_snap(reporter, surface.get(), true, imageBackingStore, surfaceBackingStore); } texture->unref(); @@ -504,9 +504,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_handle_gen_id }) { for (auto& handle_access_func : { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle}) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, - nullptr)); - test_func(reporter, surface, handle_access_func); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_func(reporter, surface.get(), handle_access_func); } } } @@ -589,14 +588,13 @@ static void test_copy_on_write(skiatest::Reporter* reporter, SkSurface* surface) testPaint)) } DEF_TEST(SurfaceCopyOnWrite, reporter) { - SkAutoTUnref surface(create_surface()); - test_copy_on_write(reporter, surface); + test_copy_on_write(reporter, create_surface().get()); } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, nullptr)); - test_copy_on_write(reporter, surface); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_copy_on_write(reporter, surface.get()); } } #endif @@ -612,14 +610,13 @@ static void test_writable_after_snapshot_release(skiatest::Reporter* reporter, canvas->clear(2); // Must not assert internally } DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { - SkAutoTUnref surface(create_surface()); - test_writable_after_snapshot_release(reporter, surface); + test_writable_after_snapshot_release(reporter, create_surface().get()); } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, nullptr)); - test_writable_after_snapshot_release(reporter, surface); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_writable_after_snapshot_release(reporter, surface.get()); } } #endif @@ -659,15 +656,15 @@ static void test_crbug263329(skiatest::Reporter* reporter, } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); - SkAutoTUnref surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); - test_crbug263329(reporter, surface1, surface2); + auto surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_crbug263329(reporter, surface1.get(), surface2.get()); } } #endif DEF_TEST(SurfaceGetTexture, reporter) { - SkAutoTUnref surface(create_surface()); + auto surface(create_surface()); sk_sp image(surface->makeImageSnapshot()); REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); @@ -676,7 +673,7 @@ DEF_TEST(SurfaceGetTexture, reporter) { #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - SkAutoTUnref surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); sk_sp image(surface->makeImageSnapshot()); GrTexture* texture = as_IB(image)->peekTexture(); REPORTER_ASSERT(reporter, texture); @@ -693,8 +690,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { #include "SkImage_Gpu.h" #include "SkSurface_Gpu.h" -static SkBudgeted is_budgeted(SkSurface* surf) { - return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted(); +static SkBudgeted is_budgeted(const sk_sp& surf) { + SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get(); + return gsurf->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted(); } static SkBudgeted is_budgeted(SkImage* image) { @@ -709,8 +707,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { - SkAutoTUnref - surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0)); + auto surface(SkSurface::MakeRenderTarget(context, sbudgeted, info)); SkASSERT(surface); REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); @@ -763,8 +760,7 @@ DEF_TEST(SurfaceNoCanvas, reporter) { { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode}; for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { for (auto& mode : modes) { - SkAutoTUnref surface(create_surface()); - test_func(reporter, surface, mode); + test_func(reporter, create_surface().get(), mode); } } } @@ -775,9 +771,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { for (auto& mode : modes) { - SkAutoTUnref surface( - surface_func(context, kPremul_SkAlphaType, nullptr)); - test_func(reporter, surface, mode); + auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + test_func(reporter, surface.get(), mode); } } } @@ -807,26 +802,25 @@ static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor DEF_TEST(surface_rowbytes, reporter) { const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surf0(SkSurface::NewRaster(info)); - check_rowbytes_remain_consistent(surf0, reporter); + auto surf0(SkSurface::MakeRaster(info)); + check_rowbytes_remain_consistent(surf0.get(), reporter); // specify a larger rowbytes - SkAutoTUnref surf1(SkSurface::NewRaster(info, 500, nullptr)); - check_rowbytes_remain_consistent(surf1, reporter); + auto surf1(SkSurface::MakeRaster(info, 500, nullptr)); + check_rowbytes_remain_consistent(surf1.get(), reporter); // Try some illegal rowByte values - SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be at least 400 + auto s = SkSurface::MakeRaster(info, 396, nullptr); // needs to be at least 400 REPORTER_ASSERT(reporter, nullptr == s); - s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large + s = SkSurface::MakeRaster(info, 1 << 30, nullptr); // allocation to large REPORTER_ASSERT(reporter, nullptr == s); } #if SK_SUPPORT_GPU -void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surfacePtr, +void test_surface_clear(skiatest::Reporter* reporter, sk_sp surface, std::function grSurfaceGetter, uint32_t expectedValue) { - SkAutoTUnref surface(surfacePtr); if (!surface) { ERRORF(reporter, "Could not create GPU SkSurface."); return; @@ -836,12 +830,11 @@ void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surfacePtr, SkAutoTDeleteArray pixels(new uint32_t[w * h]); memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h); - SkAutoTUnref grSurface(SkSafeRef(grSurfaceGetter(surface))); + SkAutoTUnref grSurface(SkSafeRef(grSurfaceGetter(surface.get()))); if (!grSurface) { ERRORF(reporter, "Could access render target of GPU SkSurface."); return; } - SkASSERT(surface->unique()); surface.reset(); grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get()); for (int y = 0; y < h; ++y) { @@ -875,7 +868,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { }; for (auto grSurfaceGetter : grSurfaceGetters) { for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surface}) { - SkSurface* surface = surface_func(context, kPremul_SkAlphaType, nullptr); + auto surface = surface_func(context, kPremul_SkAlphaType, nullptr); test_surface_clear(reporter, surface, grSurfaceGetter, 0x0); } // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface). @@ -895,7 +888,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { desc.fFlags = kRenderTarget_GrBackendTextureFlag; desc.fTextureHandle = textureObject; - SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nullptr); + auto surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr); test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); } diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp index b7456d6b39..6ec32637cb 100644 --- a/tests/TextBlobCacheTest.cpp +++ b/tests/TextBlobCacheTest.cpp @@ -66,8 +66,7 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte } SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType); - SkAutoTUnref surface(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, - 0, &props)); + auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props)); REPORTER_ASSERT(reporter, surface); if (!surface) { return; @@ -133,7 +132,7 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte // create surface where LCD is impossible info = SkImageInfo::MakeN32Premul(kWidth, kHeight); SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry); - SkAutoTUnref surfaceNoLCD(canvas->newSurface(info, &propsNoLCD)); + auto surfaceNoLCD(canvas->makeSurface(info, &propsNoLCD)); REPORTER_ASSERT(reporter, surface); if (!surface) { return; diff --git a/tests/TextureStorageAllocator.cpp b/tests/TextureStorageAllocator.cpp index 5c9962e2c6..1d226861e2 100644 --- a/tests/TextureStorageAllocator.cpp +++ b/tests/TextureStorageAllocator.cpp @@ -66,7 +66,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, context, glContext) grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateTextureStorage; grAllocator.fCtx = &allocator; - SkAutoTUnref surface(SkSurface_Gpu::NewRenderTarget( + auto surface(SkSurface_Gpu::MakeRenderTarget( context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0, NULL, grAllocator)); REPORTER_ASSERT(reporter, surface); @@ -100,7 +100,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, context, glCo grAllocator.fAllocateTextureStorage = &TestStorageAllocator::allocateTextureStorage; grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateTextureStorage; grAllocator.fCtx = &allocator; - SkAutoTUnref surface(SkSurface_Gpu::NewRenderTarget( + auto surface(SkSurface_Gpu::MakeRenderTarget( context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0, NULL, grAllocator)); REPORTER_ASSERT(reporter, !surface); diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 0141bf351f..6dda6ff89e 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -294,7 +294,7 @@ static void call_writepixels(SkCanvas* canvas) { DEF_TEST(WritePixelsSurfaceGenID, reporter) { const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); - SkAutoTUnref surface(SkSurface::NewRaster(info)); + auto surface(SkSurface::MakeRaster(info)); uint32_t genID1 = surface->generationID(); call_writepixels(surface->getCanvas()); uint32_t genID2 = surface->generationID(); @@ -400,8 +400,9 @@ DEF_TEST(WritePixels, reporter) { if (!tightRowBytes) { memset(pixels, DEV_PAD, size); } - SkAutoTUnref surface(SkSurface::NewRasterDirectReleaseProc(info, pixels, rowBytes, free_pixels, nullptr)); - test_write_pixels(reporter, surface); + auto surface(SkSurface::MakeRasterDirectReleaseProc(info, pixels, rowBytes, + free_pixels, nullptr)); + test_write_pixels(reporter, surface.get()); } } #if SK_SUPPORT_GPU @@ -415,8 +416,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, context) { desc.fOrigin = origin; SkAutoTUnref texture(context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); - SkAutoTUnref surface(SkSurface::NewRenderTargetDirect(texture->asRenderTarget())); - test_write_pixels(reporter, surface); + auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget())); + test_write_pixels(reporter, surface.get()); } } #endif diff --git a/tools/VisualBench/VisualBench.cpp b/tools/VisualBench/VisualBench.cpp index 69d47b6b04..cbd1abe97b 100644 --- a/tools/VisualBench/VisualBench.cpp +++ b/tools/VisualBench/VisualBench.cpp @@ -78,7 +78,7 @@ void VisualBench::setTitle() { SkSurface* VisualBench::createSurface() { if (!fSurface) { SkSurfaceProps props(INHERITED::getSurfaceProps()); - fSurface.reset(SkSurface::NewRenderTargetDirect(fRenderTarget, &props)); + fSurface.reset(SkSurface::MakeRenderTargetDirect(fRenderTarget, &props).release()); } // The caller will wrap the SkSurface in an SkAutoTUnref diff --git a/tools/VisualBench/WrappedBenchmark.h b/tools/VisualBench/WrappedBenchmark.h index 35d64ee182..bd88f13502 100644 --- a/tools/VisualBench/WrappedBenchmark.h +++ b/tools/VisualBench/WrappedBenchmark.h @@ -36,20 +36,20 @@ public: fBench->perCanvasPreDraw(fOffScreen->getCanvas()); } void onPreDraw(SkCanvas* canvas) override { - SkASSERT(fOffScreen.get()); + SkASSERT(fOffScreen); fBench->preDraw(fOffScreen->getCanvas()); } void onPostDraw(SkCanvas* canvas) override { - SkASSERT(fOffScreen.get()); + SkASSERT(fOffScreen); fBench->postDraw(fOffScreen->getCanvas()); } void onPerCanvasPostDraw(SkCanvas* canvas) override { - SkASSERT(fOffScreen.get()); + SkASSERT(fOffScreen); fBench->perCanvasPostDraw(fOffScreen->getCanvas()); } void onDraw(int loops, SkCanvas* canvas) override { - SkASSERT(fOffScreen.get()); + SkASSERT(fOffScreen); fBench->draw(loops, fOffScreen->getCanvas()); this->blitToScreen(canvas); } @@ -68,7 +68,7 @@ protected: virtual void onBlitToScreen(SkCanvas* canvas, int w, int h) = 0; SkSurfaceProps fSurfaceProps; - SkAutoTUnref fOffScreen; + sk_sp fOffScreen; SkAutoTUnref fBench; }; @@ -80,7 +80,7 @@ public: private: void setupOffScreen(SkCanvas* canvas) override { - fOffScreen.reset(SkSurface::NewRaster(canvas->imageInfo(), &this->surfaceProps())); + fOffScreen = SkSurface::MakeRaster(canvas->imageInfo(), &this->surfaceProps()); } void onBlitToScreen(SkCanvas* canvas, int w, int h) override { @@ -104,11 +104,11 @@ public: private: void setupOffScreen(SkCanvas* canvas) override { - fOffScreen.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), + fOffScreen = SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::kNo, canvas->imageInfo(), fNumSamples, - &this->surfaceProps())); + &this->surfaceProps()); } void onBlitToScreen(SkCanvas* canvas, int w, int h) override { diff --git a/tools/android/SkAndroidSDKCanvas.cpp b/tools/android/SkAndroidSDKCanvas.cpp index d7a76ca215..d31f93b671 100644 --- a/tools/android/SkAndroidSDKCanvas.cpp +++ b/tools/android/SkAndroidSDKCanvas.cpp @@ -12,6 +12,7 @@ #include "SkPaint.h" #include "SkPathEffect.h" #include "SkShader.h" +#include "SkSurface.h" #include "SkTLazy.h" namespace { @@ -287,9 +288,9 @@ bool SkAndroidSDKCanvas::getClipDeviceBounds(SkIRect* rect) const { bool SkAndroidSDKCanvas::isClipEmpty() const { return fProxyTarget->isClipEmpty(); } bool SkAndroidSDKCanvas::isClipRect() const { return fProxyTarget->isClipRect(); } -SkSurface* SkAndroidSDKCanvas::onNewSurface(const SkImageInfo& info, - const SkSurfaceProps& props) { - return fProxyTarget->newSurface(info, &props); +sk_sp SkAndroidSDKCanvas::onNewSurface(const SkImageInfo& info, + const SkSurfaceProps& props) { + return fProxyTarget->makeSurface(info, &props); } bool SkAndroidSDKCanvas::onPeekPixels(SkPixmap* pmap) { diff --git a/tools/android/SkAndroidSDKCanvas.h b/tools/android/SkAndroidSDKCanvas.h index 68a53816c6..812775f185 100644 --- a/tools/android/SkAndroidSDKCanvas.h +++ b/tools/android/SkAndroidSDKCanvas.h @@ -87,7 +87,7 @@ protected: bool getClipDeviceBounds(SkIRect*) const override; bool isClipEmpty() const override; bool isClipRect() const override; - SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; + sk_sp onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; bool onPeekPixels(SkPixmap*) override; bool onAccessTopLayerPixels(SkPixmap*) override; void willSave() override; diff --git a/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp index 06cb33fb49..c0422d81eb 100644 --- a/tools/kilobench/kilobench.cpp +++ b/tools/kilobench/kilobench.cpp @@ -182,9 +182,9 @@ struct GPUTarget { uint32_t flags = useDfText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - fSurface.reset(SkSurface::NewRenderTarget(context, - SkBudgeted::kNo, info, - numSamples, &props)); + fSurface.reset(SkSurface::MakeRenderTarget(context, + SkBudgeted::kNo, info, + numSamples, &props).release()); fGL = factory->getContextInfo(ctxType, ctxOptions).fGLContext; if (!fSurface.get()) { return false; diff --git a/tools/skhello.cpp b/tools/skhello.cpp index 61502a6fb8..d033641bf1 100644 --- a/tools/skhello.cpp +++ b/tools/skhello.cpp @@ -34,7 +34,7 @@ static void doDraw(SkCanvas* canvas, const SkPaint& paint, const char text[]) { static bool do_surface(int w, int h, const char path[], const char text[], const SkPaint& paint) { SkSurfaceProps props(0, kUnknown_SkPixelGeometry); - SkAutoTUnref surface(SkSurface::NewRasterN32Premul(w, h, &props)); + sk_sp surface(SkSurface::MakeRasterN32Premul(w, h, &props)); doDraw(surface->getCanvas(), paint, text); sk_sp image(surface->makeImageSnapshot()); diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index 110bd49550..47b467cd1f 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -140,7 +140,7 @@ SkSurface* Request::createCPUSurface() { SkIRect bounds = this->getBounds(); SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), kN32_SkColorType, kPremul_SkAlphaType); - return SkSurface::NewRaster(info); + return SkSurface::MakeRaster(info).release(); } SkSurface* Request::createGPUSurface() { @@ -150,8 +150,8 @@ SkSurface* Request::createGPUSurface() { kN32_SkColorType, kPremul_SkAlphaType); uint32_t flags = 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - SkSurface* surface = SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, - &props); + SkSurface* surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, + &props).release(); return surface; } -- cgit v1.2.3