From 145dbcd165d9d27298eb8888bc240e2d06a95464 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Thu, 3 Nov 2016 14:40:50 -0400 Subject: [PATCH] Remove SkAutoTDelete. Replace with std::unique_ptr. Change-Id: I5806cfbb30515fcb20e5e66ce13fb5f3b8728176 Reviewed-on: https://skia-review.googlesource.com/4381 Commit-Queue: Ben Wagner Reviewed-by: Mike Klein --- bench/AndroidCodecBench.cpp | 4 +- bench/BitmapRegionDecoderBench.h | 2 +- bench/CodecBench.cpp | 6 +- bench/ColorCodecBench.cpp | 4 +- bench/GrMemoryPoolBench.cpp | 2 +- bench/PDFBench.cpp | 2 +- bench/PicturePlaybackBench.cpp | 4 +- bench/RectanizerBench.cpp | 2 +- bench/nanobench.cpp | 22 +++---- debugger/QT/SkDebuggerGUI.cpp | 2 +- dm/DM.cpp | 14 ++-- dm/DMSrcSink.cpp | 68 ++++++++++---------- dm/DMSrcSink.h | 4 +- dm/DMSrcSinkAndroid.cpp | 4 +- dm/DMSrcSinkAndroid.h | 2 +- fuzz/fuzz.cpp | 2 +- gm/encode-platform.cpp | 2 +- gm/fontscalerdistortable.cpp | 2 +- gm/gamut.cpp | 32 +++++----- gm/image.cpp | 4 +- gm/image_pict.cpp | 12 ++-- gm/pictureimagegenerator.cpp | 2 +- gm/reveal.cpp | 4 +- include/private/SkTemplates.h | 22 ------- samplecode/DecodeFile.h | 2 +- samplecode/SampleApp.h | 2 +- samplecode/SamplePdfFileViewer.cpp | 2 +- samplecode/SamplePictFile.cpp | 2 +- src/android/SkBitmapRegionCodec.h | 2 +- src/android/SkBitmapRegionDecoder.cpp | 6 +- src/animator/SkDisplayApply.cpp | 2 +- src/animator/SkSnapshot.cpp | 2 +- src/codec/SkAndroidCodec.cpp | 2 +- src/codec/SkBmpCodec.cpp | 4 +- src/codec/SkBmpMaskCodec.cpp | 2 +- src/codec/SkBmpMaskCodec.h | 8 +-- src/codec/SkBmpRLECodec.cpp | 2 +- src/codec/SkBmpRLECodec.h | 2 +- src/codec/SkBmpStandardCodec.h | 4 +- src/codec/SkCodec.cpp | 2 +- src/codec/SkCodecImageGenerator.h | 2 +- src/codec/SkIcoCodec.cpp | 20 +++--- src/codec/SkIcoCodec.h | 8 +-- src/codec/SkJpegCodec.cpp | 8 +-- src/codec/SkJpegCodec.h | 4 +- src/codec/SkPngCodec.cpp | 6 +- src/codec/SkPngCodec.h | 4 +- src/codec/SkRawCodec.cpp | 34 +++++----- src/codec/SkRawCodec.h | 2 +- src/codec/SkWbmpCodec.cpp | 4 +- src/codec/SkWbmpCodec.h | 4 +- src/codec/SkWebpCodec.cpp | 2 +- src/core/SkBigPicture.h | 2 +- src/core/SkColorTable.cpp | 4 +- src/core/SkPaint.cpp | 4 +- src/core/SkPicture.cpp | 12 ++-- src/core/SkPictureData.cpp | 4 +- src/core/SkPicturePlayback.cpp | 6 +- src/core/SkRecordedDrawable.cpp | 4 +- src/core/SkStream.cpp | 8 +-- src/fonts/SkFontMgr_indirect.cpp | 4 +- src/gpu/GrDrawingManager.h | 2 +- src/gpu/GrGpu.h | 6 +- src/gpu/GrPathRenderingRenderTargetContext.h | 2 +- src/gpu/GrRenderTargetOpList.cpp | 4 +- src/gpu/GrRenderTargetOpList.h | 4 +- src/gpu/SkGr.cpp | 2 +- src/gpu/gl/GrGLProgram.h | 4 +- src/gpu/instanced/InstanceProcessor.cpp | 2 +- src/gpu/text/GrAtlasTextBlob.h | 2 +- src/gpu/text/GrStencilAndCoverTextContext.cpp | 2 +- src/gpu/vk/GrVkExtensions.h | 8 +-- src/gpu/vk/GrVkGpu.h | 4 +- src/gpu/vk/GrVkMemory.cpp | 4 +- src/gpu/vk/GrVkMemory.h | 2 +- src/gpu/vk/GrVkPipelineState.cpp | 7 +- src/gpu/vk/GrVkPipelineState.h | 8 +-- src/image/SkImage_Gpu.cpp | 2 +- src/images/SkImageEncoder.cpp | 6 +- src/ports/SkFontHost_win.cpp | 4 +- src/ports/SkFontMgr_FontConfigInterface.cpp | 6 +- src/ports/SkFontMgr_android_parser.cpp | 24 +++---- src/ports/SkFontMgr_win_dw.cpp | 2 +- src/ports/SkTypeface_win_dw.cpp | 4 +- src/svg/SkSVGDevice.cpp | 22 +++---- src/svg/SkSVGDevice.h | 6 +- src/utils/SkCanvasStateUtils.cpp | 2 +- src/utils/SkFrontBufferedStream.cpp | 14 ++-- src/utils/win/SkDWriteFontFileStream.cpp | 2 +- src/utils/win/SkDWriteFontFileStream.h | 2 +- src/views/SkEvent.cpp | 5 +- src/xps/SkDocument_XPS.cpp | 2 +- src/xps/SkXPSDevice.cpp | 2 +- tests/BadIcoTest.cpp | 4 +- tests/CodecPartialTest.cpp | 12 ++-- tests/CodecPriv.h | 2 +- tests/CodecTest.cpp | 74 +++++++++++----------- tests/ColorSpaceTest.cpp | 4 +- tests/DataRefTest.cpp | 2 +- tests/DiscardableMemoryPoolTest.cpp | 4 +- tests/EGLImageTest.cpp | 16 ++--- tests/ExifTest.cpp | 4 +- tests/FontHostStreamTest.cpp | 2 +- tests/FontHostTest.cpp | 6 +- tests/FrontBufferedStreamTest.cpp | 60 +++++++++--------- tests/GifTest.cpp | 4 +- tests/GpuSampleLocationsTest.cpp | 2 +- tests/GrMemoryPoolTest.cpp | 4 +- tests/ImageTest.cpp | 4 +- tests/Matrix44Test.cpp | 2 +- tests/PDFDeflateWStreamTest.cpp | 5 +- tests/PathOpsSkpClipTest.cpp | 2 +- tests/PictureTest.cpp | 4 +- tests/SerializationTest.cpp | 6 +- tests/SkResourceCacheTest.cpp | 16 ++--- tests/StreamTest.cpp | 24 +++---- tests/YUVTest.cpp | 4 +- tools/Resources.cpp | 6 +- tools/debugger/SkDrawCommand.cpp | 10 +-- tools/flags/SkCommonFlagsConfig.h | 2 +- tools/get_images_from_skps.cpp | 2 +- tools/gpu/GrContextFactory.cpp | 2 +- tools/gpu/GrContextFactory.h | 2 +- tools/gpu/TestContext.h | 8 +-- tools/gpu/gl/GLTestContext.cpp | 28 ++++---- tools/gpu/gl/GLTestContext.h | 4 +- tools/gpu/gl/angle/GLTestContext_angle.cpp | 15 ++--- tools/gpu/gl/angle/GLTestContext_angle.h | 2 +- .../gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp | 14 ++-- tools/gpu/vk/VkTestContext.cpp | 4 +- tools/skdiff/skdiff_utils.cpp | 2 +- tools/skiaserve/Request.cpp | 4 +- tools/viewer/ImageSlide.cpp | 2 +- tools/viewer/Viewer.cpp | 2 +- tools/visualize_color_gamut.cpp | 2 +- 135 files changed, 472 insertions(+), 490 deletions(-) diff --git a/bench/AndroidCodecBench.cpp b/bench/AndroidCodecBench.cpp index 97e1176..e0680bd 100644 --- a/bench/AndroidCodecBench.cpp +++ b/bench/AndroidCodecBench.cpp @@ -29,7 +29,7 @@ bool AndroidCodecBench::isSuitableFor(Backend backend) { } void AndroidCodecBench::onDelayedSetup() { - SkAutoTDelete codec(SkAndroidCodec::NewFromData(fData)); + std::unique_ptr codec(SkAndroidCodec::NewFromData(fData)); SkISize scaledSize = codec->getSampledDimensions(fSampleSize); fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height()) @@ -42,7 +42,7 @@ void AndroidCodecBench::onDelayedSetup() { } void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) { - SkAutoTDelete codec; + std::unique_ptr codec; SkAndroidCodec::AndroidOptions options; options.fSampleSize = fSampleSize; for (int i = 0; i < n; i++) { diff --git a/bench/BitmapRegionDecoderBench.h b/bench/BitmapRegionDecoderBench.h index 2fb56ad..3099055 100644 --- a/bench/BitmapRegionDecoderBench.h +++ b/bench/BitmapRegionDecoderBench.h @@ -35,7 +35,7 @@ protected: private: SkString fName; - SkAutoTDelete fBRD; + std::unique_ptr fBRD; sk_sp fData; const SkColorType fColorType; const uint32_t fSampleSize; diff --git a/bench/CodecBench.cpp b/bench/CodecBench.cpp index 9bd404d..a1788ee 100644 --- a/bench/CodecBench.cpp +++ b/bench/CodecBench.cpp @@ -26,7 +26,7 @@ CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType alpha_type_to_str(alphaType)); #ifdef SK_DEBUG // Ensure that we can create an SkCodec from this data. - SkAutoTDelete codec(SkCodec::NewFromData(fData)); + std::unique_ptr codec(SkCodec::NewFromData(fData)); SkASSERT(codec); #endif } @@ -40,7 +40,7 @@ bool CodecBench::isSuitableFor(Backend backend) { } void CodecBench::onDelayedSetup() { - SkAutoTDelete codec(SkCodec::NewFromData(fData)); + std::unique_ptr codec(SkCodec::NewFromData(fData)); fInfo = codec->getInfo().makeColorType(fColorType) .makeAlphaType(fAlphaType) @@ -50,7 +50,7 @@ void CodecBench::onDelayedSetup() { } void CodecBench::onDraw(int n, SkCanvas* canvas) { - SkAutoTDelete codec; + std::unique_ptr codec; SkPMColor colorTable[256]; int colorCount; SkCodec::Options options; diff --git a/bench/ColorCodecBench.cpp b/bench/ColorCodecBench.cpp index 8df7e65..50727c7 100644 --- a/bench/ColorCodecBench.cpp +++ b/bench/ColorCodecBench.cpp @@ -34,7 +34,7 @@ bool ColorCodecBench::isSuitableFor(Backend backend) { } void ColorCodecBench::decodeAndXform() { - SkAutoTDelete codec(SkCodec::NewFromData(fEncoded)); + std::unique_ptr codec(SkCodec::NewFromData(fEncoded)); SkASSERT(codec); #ifdef SK_DEBUG @@ -61,7 +61,7 @@ void ColorCodecBench::xformOnly() { } void ColorCodecBench::onDelayedSetup() { - SkAutoTDelete codec(SkCodec::NewFromData(fEncoded)); + std::unique_ptr codec(SkCodec::NewFromData(fEncoded)); fSrcInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType); fDstInfo = fSrcInfo; diff --git a/bench/GrMemoryPoolBench.cpp b/bench/GrMemoryPoolBench.cpp index 9b60c3c..55ba3e6 100644 --- a/bench/GrMemoryPoolBench.cpp +++ b/bench/GrMemoryPoolBench.cpp @@ -110,7 +110,7 @@ protected: enum { kMaxObjects = 4 * (1 << 10), }; - SkAutoTDelete objects[kMaxObjects]; + std::unique_ptr objects[kMaxObjects]; for (int i = 0; i < loops; i++) { uint32_t idx = r.nextRangeU(0, kMaxObjects-1); diff --git a/bench/PDFBench.cpp b/bench/PDFBench.cpp index 1010f74..573353f 100644 --- a/bench/PDFBench.cpp +++ b/bench/PDFBench.cpp @@ -144,7 +144,7 @@ protected: } private: - SkAutoTDelete fAsset; + std::unique_ptr fAsset; }; // Test speed of SkPDFUtils::FloatToDecimal for typical floats that diff --git a/bench/PicturePlaybackBench.cpp b/bench/PicturePlaybackBench.cpp index 2b2b6ad..54ecd3c 100644 --- a/bench/PicturePlaybackBench.cpp +++ b/bench/PicturePlaybackBench.cpp @@ -163,14 +163,14 @@ public: SkIPoint onGetSize() override { return SkIPoint::Make(1024,1024); } void onDelayedSetup() override { - SkAutoTDelete factory; + std::unique_ptr factory; switch (fBBH) { case kNone: break; case kRTree: factory.reset(new SkRTreeFactory); break; } SkPictureRecorder recorder; - SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory); + SkCanvas* canvas = recorder.beginRecording(1024, 1024, factory.get()); SkRandom rand; for (int i = 0; i < 10000; i++) { SkScalar x = rand.nextRangeScalar(0, 1024), diff --git a/bench/RectanizerBench.cpp b/bench/RectanizerBench.cpp index 5bc6f11..b282313 100644 --- a/bench/RectanizerBench.cpp +++ b/bench/RectanizerBench.cpp @@ -115,7 +115,7 @@ private: SkString fName; RectanizerType fRectanizerType; RectType fRectType; - SkAutoTDelete fRectanizer; + std::unique_ptr fRectanizer; typedef Benchmark INHERITED; }; diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 37e3f06..0651302 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -63,7 +63,7 @@ #include "gl/GrGLUtil.h" using sk_gpu_test::GrContextFactory; using sk_gpu_test::TestContext; - SkAutoTDelete gGrFactory; + std::unique_ptr gGrFactory; #endif struct GrContextOptions; @@ -481,7 +481,7 @@ void create_configs(SkTArray* configs) { SkCommandLineConfigArray array; ParseConfigs(FLAGS_config, &array); for (int i = 0; i < array.count(); ++i) { - create_config(array[i], configs); + create_config(array[i].get(), configs); } } @@ -531,7 +531,7 @@ static Target* is_enabled(Benchmark* bench, const Config& config) { static bool valid_brd_bench(sk_sp encoded, SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int* width, int* height) { - SkAutoTDelete brd( + std::unique_ptr brd( SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy)); if (nullptr == brd.get()) { // This is indicates that subset decoding is not supported for a particular image format. @@ -683,7 +683,7 @@ public: } Benchmark* next() { - SkAutoTDelete bench; + std::unique_ptr bench; do { bench.reset(this->rawNext()); if (!bench) { @@ -704,7 +704,7 @@ public: } while (fGMs) { - SkAutoTDelete gm(fGMs->factory()(nullptr)); + std::unique_ptr gm(fGMs->factory()(nullptr)); fGMs = fGMs->next(); if (gm->runAsBench()) { fSourceType = "gm"; @@ -816,7 +816,7 @@ public: continue; } sk_sp encoded(SkData::MakeFromFileName(path.c_str())); - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (!codec) { // Nothing to time. SkDebugf("Cannot find codec for %s\n", path.c_str()); @@ -900,7 +900,7 @@ public: continue; } sk_sp encoded(SkData::MakeFromFileName(path.c_str())); - SkAutoTDelete codec(SkAndroidCodec::NewFromData(encoded)); + std::unique_ptr codec(SkAndroidCodec::NewFromData(encoded)); if (!codec) { // Nothing to time. SkDebugf("Cannot find codec for %s\n", path.c_str()); @@ -1137,7 +1137,7 @@ int nanobench_main() { } } - SkAutoTDelete log(new ResultsWriter); + std::unique_ptr log(new ResultsWriter); if (!FLAGS_outResultsFile.isEmpty()) { #if defined(SK_RELEASE) log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); @@ -1204,7 +1204,7 @@ int nanobench_main() { int runs = 0; BenchmarkStream benchStream; while (Benchmark* b = benchStream.next()) { - SkAutoTDelete bench(b); + std::unique_ptr bench(b); if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { continue; } @@ -1249,12 +1249,12 @@ int nanobench_main() { samples.reset(); auto stop = now_ms() + FLAGS_ms; do { - samples.push_back(time(loops, bench, target) / loops); + samples.push_back(time(loops, bench.get(), target) / loops); } while (now_ms() < stop); } else { samples.reset(FLAGS_samples); for (int s = 0; s < FLAGS_samples; s++) { - samples[s] = time(loops, bench, target) / loops; + samples[s] = time(loops, bench.get(), target) / loops; } } diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp index 348b366..7e6f2a0 100644 --- a/debugger/QT/SkDebuggerGUI.cpp +++ b/debugger/QT/SkDebuggerGUI.cpp @@ -672,7 +672,7 @@ void SkDebuggerGUI::populateDirectoryWidget() { void SkDebuggerGUI::loadPicture(const SkString& fileName) { fFileName = fileName; fLoading = true; - SkAutoTDelete stream(new SkFILEStream(fileName.c_str())); + std::unique_ptr stream(new SkFILEStream(fileName.c_str())); auto picture = SkPicture::MakeFromStream(stream); diff --git a/dm/DM.cpp b/dm/DM.cpp index 150b994..5f4203c 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -334,12 +334,12 @@ static void gather_uninteresting_hashes() { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -struct TaggedSrc : public SkAutoTDelete { +struct TaggedSrc : public std::unique_ptr { SkString tag; SkString options; }; -struct TaggedSink : public SkAutoTDelete { +struct TaggedSink : public std::unique_ptr { SkString tag; }; @@ -354,7 +354,7 @@ static bool in_shard() { } static void push_src(const char* tag, ImplicitString options, Src* s) { - SkAutoTDelete src(s); + std::unique_ptr src(s); if (in_shard() && FLAGS_src.contains(tag) && !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { @@ -510,7 +510,7 @@ static void push_codec_srcs(Path path) { info("Couldn't read %s.", path.c_str()); return; } - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec.get()) { info("Couldn't create codec for %s.", path.c_str()); return; @@ -803,7 +803,7 @@ static bool gather_srcs() { } static void push_sink(const SkCommandLineConfig& config, Sink* s) { - SkAutoTDelete sink(s); + std::unique_ptr sink(s); // Try a simple Src as a canary. If it fails, skip this sink. struct : public Src { @@ -1079,7 +1079,7 @@ struct Task { // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. SkStreamAsset* data = stream.detachAsStream(); gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ - SkAutoTDelete ownedData(data); + std::unique_ptr ownedData(data); // Why doesn't the copy constructor do this when we have pre-locked pixels? bitmap.lockPixels(); @@ -1331,7 +1331,7 @@ int dm_main() { gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); info("%d srcs * %d sinks + %d tests == %d tasks", gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); - SkAutoTDelete statusThread(start_status_thread()); + std::unique_ptr statusThread(start_status_thread()); // Kick off as much parallel work as we can, making note of any serial work we'll need to do. SkTaskGroup parallel; diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index d519860..ae7c6a1 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -61,24 +61,24 @@ namespace DM { GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} Error GMSrc::draw(SkCanvas* canvas) const { - SkAutoTDelete gm(fFactory(nullptr)); + std::unique_ptr gm(fFactory(nullptr)); canvas->concat(gm->getInitialTransform()); gm->draw(canvas); return ""; } SkISize GMSrc::size() const { - SkAutoTDelete gm(fFactory(nullptr)); + std::unique_ptr gm(fFactory(nullptr)); return gm->getISize(); } Name GMSrc::name() const { - SkAutoTDelete gm(fFactory(nullptr)); + std::unique_ptr gm(fFactory(nullptr)); return gm->getName(); } void GMSrc::modifyGrContextOptions(GrContextOptions* options) const { - SkAutoTDelete gm(fFactory(nullptr)); + std::unique_ptr gm(fFactory(nullptr)); gm->modifyGrContextOptions(options); } @@ -125,7 +125,7 @@ Error BRDSrc::draw(SkCanvas* canvas) const { break; } - SkAutoTDelete brd(create_brd(fPath)); + std::unique_ptr brd(create_brd(fPath)); if (nullptr == brd.get()) { return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fPath.c_str())); } @@ -227,7 +227,7 @@ Error BRDSrc::draw(SkCanvas* canvas) const { } SkISize BRDSrc::size() const { - SkAutoTDelete brd(create_brd(fPath)); + std::unique_ptr brd(create_brd(fPath)); if (brd) { return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize), SkTMax(1, brd->height() / (int) fSampleSize)); @@ -381,7 +381,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const { return SkStringPrintf("Couldn't read %s.", fPath.c_str()); } - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec.get()) { return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); } @@ -718,7 +718,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const { SkISize CodecSrc::size() const { sk_sp encoded(SkData::MakeFromFileName(fPath.c_str())); - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec) { return SkISize::Make(0, 0); } @@ -771,7 +771,7 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const { if (!encoded) { return SkStringPrintf("Couldn't read %s.", fPath.c_str()); } - SkAutoTDelete codec(SkAndroidCodec::NewFromData(encoded)); + std::unique_ptr codec(SkAndroidCodec::NewFromData(encoded)); if (nullptr == codec.get()) { return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str()); } @@ -824,7 +824,7 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const { SkISize AndroidCodecSrc::size() const { sk_sp encoded(SkData::MakeFromFileName(fPath.c_str())); - SkAutoTDelete codec(SkAndroidCodec::NewFromData(encoded)); + std::unique_ptr codec(SkAndroidCodec::NewFromData(encoded)); if (nullptr == codec) { return SkISize::Make(0, 0); } @@ -876,7 +876,7 @@ Error ImageGenSrc::draw(SkCanvas* canvas) const { } #endif - SkAutoTDelete gen(nullptr); + std::unique_ptr gen(nullptr); switch (fMode) { case kCodec_Mode: gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded.get())); @@ -931,7 +931,7 @@ Error ImageGenSrc::draw(SkCanvas* canvas) const { SkISize ImageGenSrc::size() const { sk_sp encoded(SkData::MakeFromFileName(fPath.c_str())); - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec) { return SkISize::Make(0, 0); } @@ -972,7 +972,7 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const { return SkStringPrintf("Couldn't read %s.", fPath.c_str()); } - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec.get()) { return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); } @@ -1039,7 +1039,7 @@ Error ColorCodecSrc::draw(SkCanvas* canvas) const { SkISize ColorCodecSrc::size() const { sk_sp encoded(SkData::MakeFromFileName(fPath.c_str())); - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (nullptr == codec) { return SkISize::Make(0, 0); } @@ -1194,8 +1194,8 @@ Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const { - SkAutoTDelete canvas(SkCreateNullCanvas()); - return src.draw(canvas); + std::unique_ptr canvas(SkCreateNullCanvas()); + return src.draw(canvas.get()); } /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -1372,7 +1372,7 @@ SVGSink::SVGSink() {} Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { #if defined(SK_XML) - SkAutoTDelete xmlWriter(new SkXMLStreamWriter(dst)); + std::unique_ptr xmlWriter(new SkXMLStreamWriter(dst)); SkAutoTUnref canvas(SkSVGCanvas::Create( SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())), xmlWriter)); @@ -1470,7 +1470,7 @@ ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) { Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { SkMatrix matrix = fMatrix; SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height()); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) { canvas->concat(matrix); return src.draw(canvas); }); @@ -1528,9 +1528,9 @@ Error ViaSerialization::draw( // Serialize it and then deserialize it. sk_sp deserialized(SkPicture::MakeFromData(pic->serialize().get())); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) { canvas->drawPicture(deserialized); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1553,7 +1553,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri } sk_sp pic(recorder.finishRecordingAsPicture()); - return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) { + return draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(), [&](SkCanvas* canvas) { const int xTiles = (size.width() + fW - 1) / fW, yTiles = (size.height() + fH - 1) / fH; SkMultiPictureDraw mpd(xTiles*yTiles); @@ -1591,7 +1591,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { SkPictureRecorder recorder; sk_sp pic; Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()), @@ -1601,7 +1601,7 @@ Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt } pic = recorder.finishRecordingAsPicture(); canvas->drawPicture(pic); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1609,7 +1609,7 @@ Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt Error ViaDefer::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { SkDeferredCanvas deferred(canvas); return src.draw(&deferred); }); @@ -1619,7 +1619,7 @@ Error ViaDefer::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { SkDynamicMemoryWStream tmpStream; Error err = src.draw(SkPipeSerializer().beginWrite(SkRect::Make(size), &tmpStream)); if (!err.isEmpty()) { @@ -1627,7 +1627,7 @@ Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin } sk_sp data = tmpStream.detachAsData(); SkPipeDeserializer().playback(data->data(), data->size(), canvas); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1638,7 +1638,7 @@ Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin Error ViaSecondPicture::draw( const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { SkPictureRecorder recorder; sk_sp pic; for (int i = 0; i < 2; i++) { @@ -1650,7 +1650,7 @@ Error ViaSecondPicture::draw( pic = recorder.finishRecordingAsPicture(); } canvas->drawPicture(pic); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1658,7 +1658,7 @@ Error ViaSecondPicture::draw( // Draw the Src twice. This can help exercise caching. Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { - return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error { for (int i = 0; i < 2; i++) { SkAutoCanvasRestore acr(canvas, true/*save now*/); canvas->clear(SK_ColorTRANSPARENT); @@ -1667,7 +1667,7 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri return err; } } - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1711,7 +1711,7 @@ struct DrawsAsSingletonPictures { Error ViaSingletonPictures::draw( const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { // Use low-level (Skia-private) recording APIs so we can read the SkRecord. SkRecord skr; SkRecorder recorder(&skr, size.width(), size.height()); @@ -1739,7 +1739,7 @@ Error ViaSingletonPictures::draw( sk_sp macroPic(macroRec.finishRecordingAsPicture()); canvas->drawPicture(macroPic); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } @@ -1748,7 +1748,7 @@ Error ViaSingletonPictures::draw( Error ViaLite::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { auto size = src.size(); SkRect bounds = {0,0, (SkScalar)size.width(), (SkScalar)size.height()}; - return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { + return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error { sk_sp dl = SkLiteDL::New(bounds); SkLiteRecorder rec; @@ -1759,7 +1759,7 @@ Error ViaLite::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin return err; } dl->draw(canvas); - return check_against_reference(bitmap, src, fSink); + return check_against_reference(bitmap, src, fSink.get()); }); } diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 237f5d1..bb60115 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -399,7 +399,7 @@ public: return flags; } protected: - SkAutoTDelete fSink; + std::unique_ptr fSink; }; class ViaMatrix : public Via { @@ -448,7 +448,7 @@ public: Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; private: const int fW, fH; - SkAutoTDelete fFactory; + std::unique_ptr fFactory; }; class ViaSecondPicture : public Via { diff --git a/dm/DMSrcSinkAndroid.cpp b/dm/DMSrcSinkAndroid.cpp index 3958e48..77ec1c9 100644 --- a/dm/DMSrcSinkAndroid.cpp +++ b/dm/DMSrcSinkAndroid.cpp @@ -47,9 +47,9 @@ Error ViaAndroidSDK::draw(const Src& src, Error draw(SkCanvas* canvas) const override { // Pass through HWUI's upper layers to get operational transforms - SkAutoTDelete ac (android::Canvas::create_canvas(canvas)); + std::unique_ptr ac(android::Canvas::create_canvas(canvas)); SkAutoTUnref scProxy - (new android::uirenderer::SkiaCanvasProxy(ac)); + (new android::uirenderer::SkiaCanvasProxy(ac.get())); // Pass through another proxy to get paint transforms SkAndroidSDKCanvas fc; diff --git a/dm/DMSrcSinkAndroid.h b/dm/DMSrcSinkAndroid.h index 2d7ad65..6717df6 100644 --- a/dm/DMSrcSinkAndroid.h +++ b/dm/DMSrcSinkAndroid.h @@ -46,7 +46,7 @@ public: } private: - SkAutoTDelete fSink; + std::unique_ptr fSink; }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp index e6b95fd..7aac5da 100644 --- a/fuzz/fuzz.cpp +++ b/fuzz/fuzz.cpp @@ -133,7 +133,7 @@ int fuzz_img(sk_sp bytes, uint8_t scale, uint8_t mode) { // This is mostly copied from DMSrcSink's CodecSrc::draw method. SkDebugf("Decoding\n"); - SkAutoTDelete codec(SkCodec::NewFromData(bytes)); + std::unique_ptr codec(SkCodec::NewFromData(bytes)); if (nullptr == codec.get()) { SkDebugf("[terminated] Couldn't create codec.\n"); return 3; diff --git a/gm/encode-platform.cpp b/gm/encode-platform.cpp index 90f6aa9..09b64cc 100644 --- a/gm/encode-platform.cpp +++ b/gm/encode-platform.cpp @@ -96,7 +96,7 @@ protected: make_unpremul_256(&unpremulBm); for (SkImageEncoder::Type type : kTypes) { - SkAutoTDelete encoder(make_encoder(type)); + std::unique_ptr encoder(make_encoder(type)); sk_sp opaqueData(encoder->encodeData(opaqueBm, 100)); sk_sp premulData(encoder->encodeData(premulBm, 100)); sk_sp unpremulData(encoder->encodeData(unpremulBm, 100)); diff --git a/gm/fontscalerdistortable.cpp b/gm/fontscalerdistortable.cpp index be6a7eb..712400c 100644 --- a/gm/fontscalerdistortable.cpp +++ b/gm/fontscalerdistortable.cpp @@ -35,7 +35,7 @@ protected: paint.setLCDRenderText(true); SkAutoTUnref fontMgr(SkFontMgr::RefDefault()); - SkAutoTDelete distortable(GetResourceAsStream("/fonts/Distortable.ttf")); + std::unique_ptr distortable(GetResourceAsStream("/fonts/Distortable.ttf")); if (!distortable) { return; } diff --git a/gm/gamut.cpp b/gm/gamut.cpp index 9f45d6e..21312ce 100644 --- a/gm/gamut.cpp +++ b/gm/gamut.cpp @@ -113,7 +113,7 @@ protected: SkColor fColors[4]; }; -static void draw_gamut_grid(SkCanvas* canvas, SkTArray>& renderers) { +static void draw_gamut_grid(SkCanvas* canvas, SkTArray>& renderers) { // We want our colors in our wide gamut to be obviously visibly distorted from sRGB, so we use // Wide Gamut RGB (with sRGB gamma, for HW acceleration) as the working space for this test: const float gWideGamutRGB_toXYZD50[]{ @@ -199,35 +199,35 @@ static void draw_gamut_grid(SkCanvas* canvas, SkTArray> renderers; + SkTArray> renderers; // sRGB primaries, rendered as paint color - renderers.push_back(new PaintColorCellRenderer(SK_ColorRED)); - renderers.push_back(new PaintColorCellRenderer(SK_ColorGREEN)); + renderers.emplace_back(new PaintColorCellRenderer(SK_ColorRED)); + renderers.emplace_back(new PaintColorCellRenderer(SK_ColorGREEN)); // sRGB primaries, rendered as bitmaps - renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kNone_SkFilterQuality)); - renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kLow_SkFilterQuality)); + renderers.emplace_back(new BitmapCellRenderer(SK_ColorRED, kNone_SkFilterQuality)); + renderers.emplace_back(new BitmapCellRenderer(SK_ColorGREEN, kLow_SkFilterQuality)); // Larger bitmap to trigger mipmaps - renderers.push_back(new BitmapCellRenderer(SK_ColorRED, kMedium_SkFilterQuality, 2.0f)); + renderers.emplace_back(new BitmapCellRenderer(SK_ColorRED, kMedium_SkFilterQuality, 2.0f)); // Smaller bitmap to trigger bicubic - renderers.push_back(new BitmapCellRenderer(SK_ColorGREEN, kHigh_SkFilterQuality, 0.5f)); + renderers.emplace_back(new BitmapCellRenderer(SK_ColorGREEN, kHigh_SkFilterQuality, 0.5f)); // Various gradients involving sRGB primaries and white/black // First with just two stops (implemented with uniforms on GPU) - renderers.push_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, false)); - renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, false)); - renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, false)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, false)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, false)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, false)); // ... and then with four stops (implemented with textures on GPU) - renderers.push_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, true)); - renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, true)); - renderers.push_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, true)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorRED, SK_ColorGREEN, true)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorBLACK, true)); + renderers.emplace_back(new GradientCellRenderer(SK_ColorGREEN, SK_ColorWHITE, true)); // Vertex colors - renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorRED)); - renderers.push_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorGREEN)); + renderers.emplace_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorRED)); + renderers.emplace_back(new VerticesCellRenderer(SK_ColorRED, SK_ColorGREEN)); draw_gamut_grid(canvas, renderers); } diff --git a/gm/image.cpp b/gm/image.cpp index f1bb5a4..d15919e 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -412,9 +412,9 @@ protected: gen_raster, gen_picture, gen_png, gen_jpg, }; for (auto& proc : procs) { - SkAutoTDelete gen(proc(info)); + std::unique_ptr gen(proc(info)); if (gen) { - show_scaled_generator(canvas, gen); + show_scaled_generator(canvas, gen.get()); } canvas->translate(0, 120); } diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index f88a20b..2e2c284 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -260,8 +260,8 @@ class ImageCacheratorGM : public skiagm::GM { SkString fName; SkImageGenerator* (*fFactory)(GrContext*, SkPicture*); sk_sp fPicture; - SkAutoTDelete fCache; - SkAutoTDelete fCacheSubset; + std::unique_ptr fCache; + std::unique_ptr fCacheSubset; public: ImageCacheratorGM(const char suffix[], SkImageGenerator* (*factory)(GrContext*, SkPicture*)) @@ -346,11 +346,11 @@ protected: // Draw the tex first, so it doesn't hit a lucky cache from the raster version. This // way we also can force the generateTexture call. - draw_as_tex(canvas, fCache, 310, 0); - draw_as_tex(canvas, fCacheSubset, 310+101, 0); + draw_as_tex(canvas, fCache.get(), 310, 0); + draw_as_tex(canvas, fCacheSubset.get(), 310+101, 0); - draw_as_bitmap(canvas, fCache, 150, 0); - draw_as_bitmap(canvas, fCacheSubset, 150+101, 0); + draw_as_bitmap(canvas, fCache.get(), 150, 0); + draw_as_bitmap(canvas, fCacheSubset.get(), 150+101, 0); } void onDraw(SkCanvas* canvas) override { diff --git a/gm/pictureimagegenerator.cpp b/gm/pictureimagegenerator.cpp index 95efbb2..c340d1f 100644 --- a/gm/pictureimagegenerator.cpp +++ b/gm/pictureimagegenerator.cpp @@ -152,7 +152,7 @@ protected: if (configs[i].scaleY < 0) { m.postTranslate(0, SkIntToScalar(configs[i].size.height())); } - SkAutoTDelete gen( + std::unique_ptr gen( SkImageGenerator::NewFromPicture(configs[i].size, fPicture.get(), &m, p.getAlpha() != 255 ? &p : nullptr)); SkBitmap bm; diff --git a/gm/reveal.cpp b/gm/reveal.cpp index b88e7fe..3c7de7d 100644 --- a/gm/reveal.cpp +++ b/gm/reveal.cpp @@ -380,8 +380,8 @@ protected: clipCenter.fX + curSize, clipCenter.fY + curSize); - SkAutoTDelete clipObj((*clipMakes[x])(clipRect)); - SkAutoTDelete drawObj((*drawMakes[y])(cell)); + std::unique_ptr clipObj((*clipMakes[x])(clipRect)); + std::unique_ptr drawObj((*drawMakes[y])(cell)); // The goal is to replace this clipped draw (which clips the // shadow) with a draw using the geometric clip diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h index 4c72897..5c6403d 100644 --- a/include/private/SkTemplates.h +++ b/include/private/SkTemplates.h @@ -81,28 +81,6 @@ public: operator T*() const { return this->get(); } }; -/** \class SkAutoTDelete - An SkAutoTDelete is like a T*, except that the destructor of SkAutoTDelete - automatically deletes the pointer it holds (if any). That is, SkAutoTDelete - owns the T object that it points to. Like a T*, an SkAutoTDelete may hold - either NULL or a pointer to a T object. Also like T*, SkAutoTDelete is - thread-compatible, and once you dereference it, you get the threadsafety - guarantees of T. - - The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete) == sizeof(T*) -*/ -template class SkAutoTDelete : public std::unique_ptr { -public: - SkAutoTDelete(T* obj = NULL) : std::unique_ptr(obj) {} - - operator T*() const { return this->get(); } - -#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) - // Need to update graphics/BitmapRegionDecoder.cpp. - T* detach() { return this->release(); } -#endif -}; - /** Allocate an array of T elements, and free the array in the destructor */ template class SkAutoTArray : SkNoncopyable { diff --git a/samplecode/DecodeFile.h b/samplecode/DecodeFile.h index b954af6..95f3e39 100644 --- a/samplecode/DecodeFile.h +++ b/samplecode/DecodeFile.h @@ -15,7 +15,7 @@ static inline bool decode_file(const char* filename, SkBitmap* bitmap, bool requireUnpremul = false) { SkASSERT(kIndex_8_SkColorType != colorType); sk_sp data(SkData::MakeFromFileName(filename)); - SkAutoTDelete codec(SkCodec::NewFromData(data)); + std::unique_ptr codec(SkCodec::NewFromData(data)); if (!codec) { return false; } diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h index 3011f5f..c52541d 100644 --- a/samplecode/SampleApp.h +++ b/samplecode/SampleApp.h @@ -175,7 +175,7 @@ private: SkPipeDeserializer fPipeDeserializer; SkPictureRecorder fRecorder; - SkAutoTDelete fFlagsFilterCanvas; + std::unique_ptr fFlagsFilterCanvas; SkPath fClipPath; SkTouchGesture fGesture; diff --git a/samplecode/SamplePdfFileViewer.cpp b/samplecode/SamplePdfFileViewer.cpp index a36b29f..110aa58 100644 --- a/samplecode/SamplePdfFileViewer.cpp +++ b/samplecode/SamplePdfFileViewer.cpp @@ -36,7 +36,7 @@ private: SkPicture* fPicture; // TODO(edisonn): multiple pages, one page / picture, make it an array static SkPicture* LoadPdf(const char path[]) { - SkAutoTDelete renderer(SkPdfRenderer::CreateFromFile(path)); + std::unique_ptr renderer(SkPdfRenderer::CreateFromFile(path)); if (nullptr == renderer.get()) { return nullptr; } diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp index 8548328..a826edd 100644 --- a/samplecode/SamplePictFile.cpp +++ b/samplecode/SamplePictFile.cpp @@ -199,7 +199,7 @@ private: return nullptr; } - SkAutoTDelete factory; + std::unique_ptr factory; switch (bbox) { case kNo_BBoxType: // no bbox playback necessary diff --git a/src/android/SkBitmapRegionCodec.h b/src/android/SkBitmapRegionCodec.h index 7977417..5c59d52 100644 --- a/src/android/SkBitmapRegionCodec.h +++ b/src/android/SkBitmapRegionCodec.h @@ -30,7 +30,7 @@ public: private: - SkAutoTDelete fCodec; + std::unique_ptr fCodec; typedef SkBitmapRegionDecoder INHERITED; diff --git a/src/android/SkBitmapRegionDecoder.cpp b/src/android/SkBitmapRegionDecoder.cpp index 6dd48c5..15a530e 100644 --- a/src/android/SkBitmapRegionDecoder.cpp +++ b/src/android/SkBitmapRegionDecoder.cpp @@ -19,11 +19,11 @@ SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create( SkStreamRewindable* stream, Strategy strategy) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); switch (strategy) { case kAndroidCodec_Strategy: { - SkAutoTDelete codec = - SkAndroidCodec::NewFromStream(streamDeleter.release()); + std::unique_ptr codec( + SkAndroidCodec::NewFromStream(streamDeleter.release())); if (nullptr == codec) { SkCodecPrintf("Error: Failed to create codec.\n"); return NULL; diff --git a/src/animator/SkDisplayApply.cpp b/src/animator/SkDisplayApply.cpp index 0d5f09d..776d08f 100644 --- a/src/animator/SkDisplayApply.cpp +++ b/src/animator/SkDisplayApply.cpp @@ -463,7 +463,7 @@ void SkApply::endSave(int index) { int count = (int) (size / sizeof(SkScalar)); int activeIndex = fActive->fDrawIndex + index; SkOperand* last = new SkOperand[count]; - SkAutoTDelete autoLast(last); + std::unique_ptr autoLast(last); if (type != SkType_MemberProperty) { info->getValue(target, last, count); SkOperand* saveOperand = fActive->fSaveRestore[activeIndex]; diff --git a/src/animator/SkSnapshot.cpp b/src/animator/SkSnapshot.cpp index 4d35432..fbaedff 100644 --- a/src/animator/SkSnapshot.cpp +++ b/src/animator/SkSnapshot.cpp @@ -42,7 +42,7 @@ bool SkSnapshot::draw(SkAnimateMaker& maker) { if (!encoder) { return false; } - SkAutoTDelete ad(encoder); + std::unique_ptr ad(encoder); SkString name(filename); if (sequence) { diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 0a4172f..01605b2 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -23,7 +23,7 @@ SkAndroidCodec::SkAndroidCodec(SkCodec* codec) {} SkAndroidCodec* SkAndroidCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkReader) { - SkAutoTDelete codec(SkCodec::NewFromStream(stream, chunkReader)); + std::unique_ptr codec(SkCodec::NewFromStream(stream, chunkReader)); if (nullptr == codec) { return nullptr; } diff --git a/src/codec/SkBmpCodec.cpp b/src/codec/SkBmpCodec.cpp index b0ef8ad..b3a8010 100644 --- a/src/codec/SkBmpCodec.cpp +++ b/src/codec/SkBmpCodec.cpp @@ -503,7 +503,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { if (codecOut) { // Check that input bit masks are valid and create the masks object - SkAutoTDelete masks(SkMasks::CreateMasks(inputMasks, bitsPerPixel)); + std::unique_ptr masks(SkMasks::CreateMasks(inputMasks, bitsPerPixel)); if (nullptr == masks) { SkCodecPrintf("Error: invalid input masks.\n"); return false; @@ -569,7 +569,7 @@ bool SkBmpCodec::ReadHeader(SkStream* stream, bool inIco, SkCodec** codecOut) { * Reads enough of the stream to determine the image format */ SkCodec* SkBmpCodec::NewFromStream(SkStream* stream, bool inIco) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); SkCodec* codec = nullptr; if (ReadHeader(stream, inIco, &codec)) { // codec has taken ownership of stream, so we do not need to diff --git a/src/codec/SkBmpMaskCodec.cpp b/src/codec/SkBmpMaskCodec.cpp index 5b28252..a5705ee 100644 --- a/src/codec/SkBmpMaskCodec.cpp +++ b/src/codec/SkBmpMaskCodec.cpp @@ -60,7 +60,7 @@ SkCodec::Result SkBmpMaskCodec::onGetPixels(const SkImageInfo& dstInfo, SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo, const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) { // Initialize the mask swizzler - fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInfo(), fMasks, + fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInfo(), fMasks.get(), this->bitsPerPixel(), options)); SkASSERT(fMaskSwizzler); diff --git a/src/codec/SkBmpMaskCodec.h b/src/codec/SkBmpMaskCodec.h index 4cfd4d2..a1927f8 100644 --- a/src/codec/SkBmpMaskCodec.h +++ b/src/codec/SkBmpMaskCodec.h @@ -46,15 +46,15 @@ private: SkSampler* getSampler(bool createIfNecessary) override { SkASSERT(fMaskSwizzler); - return fMaskSwizzler; + return fMaskSwizzler.get(); } int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options& opts) override; - SkAutoTDelete fMasks; // owned - SkAutoTDelete fMaskSwizzler; - std::unique_ptr fSrcBuffer; + std::unique_ptr fMasks; + std::unique_ptr fMaskSwizzler; + std::unique_ptr fSrcBuffer; typedef SkBmpCodec INHERITED; }; diff --git a/src/codec/SkBmpRLECodec.cpp b/src/codec/SkBmpRLECodec.cpp index 33ba851..6e7bac9 100644 --- a/src/codec/SkBmpRLECodec.cpp +++ b/src/codec/SkBmpRLECodec.cpp @@ -548,7 +548,7 @@ SkSampler* SkBmpRLECodec::getSampler(bool /*createIfNecessary*/) { fSampler.reset(new SkBmpRLESampler(this)); } - return fSampler; + return fSampler.get(); } int SkBmpRLECodec::setSampleX(int sampleX){ diff --git a/src/codec/SkBmpRLECodec.h b/src/codec/SkBmpRLECodec.h index 1291e9f..ff1a274 100644 --- a/src/codec/SkBmpRLECodec.h +++ b/src/codec/SkBmpRLECodec.h @@ -104,7 +104,7 @@ private: const size_t fOrigRLEBytes; uint32_t fCurrRLEByte; int fSampleX; - SkAutoTDelete fSampler; + std::unique_ptr fSampler; // Scanline decodes allow the client to ask for a single scanline at a time. // This can be tricky when the RLE encoding instructs the decoder to jump down diff --git a/src/codec/SkBmpStandardCodec.h b/src/codec/SkBmpStandardCodec.h index edb88ac..20665db 100644 --- a/src/codec/SkBmpStandardCodec.h +++ b/src/codec/SkBmpStandardCodec.h @@ -61,7 +61,7 @@ protected: SkSampler* getSampler(bool createIfNecessary) override { SkASSERT(fSwizzler); - return fSwizzler; + return fSwizzler.get(); } private: @@ -89,7 +89,7 @@ private: const uint32_t fNumColors; const uint32_t fBytesPerColor; const uint32_t fOffset; - SkAutoTDelete fSwizzler; + std::unique_ptr fSwizzler; std::unique_ptr fSrcBuffer; const bool fIsOpaque; const bool fInIco; diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 31323f0..2673d2e 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -53,7 +53,7 @@ SkCodec* SkCodec::NewFromStream(SkStream* stream, return nullptr; } - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); // 14 is enough to read all of the supported types. const size_t bytesToRead = 14; diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h index 22a39aa..3abc908 100644 --- a/src/codec/SkCodecImageGenerator.h +++ b/src/codec/SkCodecImageGenerator.h @@ -36,7 +36,7 @@ private: */ SkCodecImageGenerator(SkCodec* codec, sk_sp); - SkAutoTDelete fCodec; + std::unique_ptr fCodec; sk_sp fData; typedef SkImageGenerator INHERITED; diff --git a/src/codec/SkIcoCodec.cpp b/src/codec/SkIcoCodec.cpp index e4fce4c..b5e399d 100644 --- a/src/codec/SkIcoCodec.cpp +++ b/src/codec/SkIcoCodec.cpp @@ -33,7 +33,7 @@ bool SkIcoCodec::IsIco(const void* buffer, size_t bytesRead) { */ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { // Ensure that we do not leak the input stream - SkAutoTDelete inputStream(stream); + std::unique_ptr inputStream(stream); // Header size constants static const uint32_t kIcoDirectoryBytes = 6; @@ -107,8 +107,8 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { // Now will construct a candidate codec for each of the embedded images uint32_t bytesRead = kIcoDirectoryBytes + numImages * kIcoDirEntryBytes; - SkAutoTDelete, true>> codecs( - new (SkTArray, true>)(numImages)); + std::unique_ptr, true>> codecs( + new (SkTArray, true>)(numImages)); for (uint32_t i = 0; i < numImages; i++) { uint32_t offset = directoryEntries.get()[i].offset; uint32_t size = directoryEntries.get()[i].size; @@ -133,7 +133,7 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { SkCodecPrintf("Warning: could not create embedded stream.\n"); break; } - SkAutoTDelete embeddedStream(new SkMemoryStream(data)); + std::unique_ptr embeddedStream(new SkMemoryStream(data)); bytesRead += size; // Check if the embedded codec is bmp or png and create the codec @@ -183,7 +183,7 @@ SkCodec* SkIcoCodec::NewFromStream(SkStream* stream) { * Called only by NewFromStream */ SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info, - SkTArray, true>* codecs, + SkTArray, true>* codecs, sk_sp colorSpace) : INHERITED(width, height, info, nullptr, std::move(colorSpace)) , fEmbeddedCodecs(codecs) @@ -255,10 +255,8 @@ SkCodec::Result SkIcoCodec::onGetPixels(const SkImageInfo& dstInfo, break; } - SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); - result = embeddedCodec->getPixels(dstInfo, dst, dstRowBytes, &opts, colorTable, - colorCount); - + SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index).get(); + result = embeddedCodec->getPixels(dstInfo, dst, dstRowBytes, &opts, colorTable, colorCount); switch (result) { case kSuccess: case kIncompleteInput: @@ -288,7 +286,7 @@ SkCodec::Result SkIcoCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, break; } - SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); + SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index).get(); result = embeddedCodec->startScanlineDecode(dstInfo, &options, colorTable, colorCount); if (kSuccess == result) { fCurrScanlineCodec = embeddedCodec; @@ -323,7 +321,7 @@ SkCodec::Result SkIcoCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo, break; } - SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); + SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index).get(); switch (embeddedCodec->startIncrementalDecode(dstInfo, pixels, rowBytes, &options, colorTable, colorCount)) { case kSuccess: diff --git a/src/codec/SkIcoCodec.h b/src/codec/SkIcoCodec.h index b9ed823..0c4e504 100644 --- a/src/codec/SkIcoCodec.h +++ b/src/codec/SkIcoCodec.h @@ -77,16 +77,16 @@ private: * @param embeddedCodecs codecs for the embedded images, takes ownership */ SkIcoCodec(int width, int height, const SkEncodedInfo& info, - SkTArray, true>* embeddedCodecs, sk_sp colorSpace); + SkTArray, true>* embeddedCodecs, sk_sp colorSpace); - SkAutoTDelete, true>> fEmbeddedCodecs; // owned + std::unique_ptr, true>> fEmbeddedCodecs; // Only used by the scanline decoder. onStartScanlineDecode() will set // fCurrScanlineCodec to one of the fEmbeddedCodecs, if it can find a // codec of the appropriate size. We will use fCurrScanlineCodec for // subsequent calls to onGetScanlines() or onSkipScanlines(). // fCurrScanlineCodec is owned by this class, but should not be an - // SkAutoTDelete. It will be deleted by the destructor of fEmbeddedCodecs. + // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs. SkCodec* fCurrScanlineCodec; // Only used by incremental decoder. onStartIncrementalDecode() will set @@ -94,7 +94,7 @@ private: // codec of the appropriate size. We will use fCurrIncrementalCodec for // subsequent calls to incrementalDecode(). // fCurrIncrementalCodec is owned by this class, but should not be an - // SkAutoTDelete. It will be deleted by the destructor of fEmbeddedCodecs. + // std::unique_ptr. It will be deleted by the destructor of fEmbeddedCodecs. SkCodec* fCurrIncrementalCodec; typedef SkCodec INHERITED; diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 1c8ace5..e762483 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -192,7 +192,7 @@ bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, JpegDecoderMgr** decoderMgrOut) { // Create a JpegDecoderMgr to own all of the decompress information - SkAutoTDelete decoderMgr(new JpegDecoderMgr(stream)); + std::unique_ptr decoderMgr(new JpegDecoderMgr(stream)); // libjpeg errors will be caught and reported here if (setjmp(decoderMgr->getJmpBuf())) { @@ -251,7 +251,7 @@ bool SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, } SkCodec* SkJpegCodec::NewFromStream(SkStream* stream) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); SkCodec* codec = nullptr; if (ReadHeader(stream, &codec, nullptr)) { // Codec has taken ownership of the stream, we do not need to delete it @@ -635,12 +635,12 @@ void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { if (!createIfNecessary || fSwizzler) { SkASSERT(!fSwizzler || (fSwizzleSrcRow && fStorage.get() == fSwizzleSrcRow)); - return fSwizzler; + return fSwizzler.get(); } this->initializeSwizzler(this->dstInfo(), this->options()); this->allocateStorage(this->dstInfo()); - return fSwizzler; + return fSwizzler.get(); } SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index a889a4a..9e08c86 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -116,7 +116,7 @@ private: int onGetScanlines(void* dst, int count, size_t rowBytes) override; bool onSkipScanlines(int count) override; - SkAutoTDelete fDecoderMgr; + std::unique_ptr fDecoderMgr; // We will save the state of the decompress struct after reading the header. // This allows us to safely call onGetScaledDimensions() at any time. @@ -132,7 +132,7 @@ private: // to further subset the output from libjpeg-turbo. SkIRect fSwizzlerSubset; - SkAutoTDelete fSwizzler; + std::unique_ptr fSwizzler; typedef SkCodec INHERITED; }; diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index ae11048..da6e062 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -1144,11 +1144,11 @@ void SkPngCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& o SkSampler* SkPngCodec::getSampler(bool createIfNecessary) { if (fSwizzler || !createIfNecessary) { - return fSwizzler; + return fSwizzler.get(); } this->initializeSwizzler(this->dstInfo(), this->options()); - return fSwizzler; + return fSwizzler.get(); } bool SkPngCodec::onRewind() { @@ -1249,7 +1249,7 @@ uint64_t SkPngCodec::onGetFillValue(const SkImageInfo& dstInfo) const { } SkCodec* SkPngCodec::NewFromStream(SkStream* stream, SkPngChunkReader* chunkReader) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); SkCodec* outCodec = nullptr; if (read_header(streamDeleter.get(), chunkReader, &outCodec, nullptr, nullptr)) { diff --git a/src/codec/SkPngCodec.h b/src/codec/SkPngCodec.h index c10f174..2c427ca 100644 --- a/src/codec/SkPngCodec.h +++ b/src/codec/SkPngCodec.h @@ -61,7 +61,7 @@ protected: voidp png_ptr() { return fPng_ptr; } voidp info_ptr() { return fInfo_ptr; } - SkSwizzler* swizzler() { return fSwizzler; } + SkSwizzler* swizzler() { return fSwizzler.get(); } // Initialize variables used by applyXformRow. void initializeXformParams(); @@ -97,7 +97,7 @@ protected: // These are stored here so they can be used both by normal decoding and scanline decoding. SkAutoTUnref fColorTable; // May be unpremul. - SkAutoTDelete fSwizzler; + std::unique_ptr fSwizzler; SkAutoTMalloc fStorage; uint32_t* fColorXformSrcRow; const int fBitDepth; diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index 5ae44d1..26519e6 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -322,7 +322,7 @@ private: return fStreamBuffer.write(tempBuffer.get(), bytesRead); } - SkAutoTDelete fStream; + std::unique_ptr fStream; bool fWholeStreamRead; // Use a size-limited stream to avoid holding too huge buffer. @@ -396,7 +396,7 @@ public: } } private: - SkAutoTDelete fStream; + std::unique_ptr fStream; }; class SkPiexStream : public ::piex::StreamInterface { @@ -446,7 +446,7 @@ public: * Note: this will take the ownership of the stream. */ static SkDngImage* NewFromStream(SkRawStream* stream) { - SkAutoTDelete dngImage(new SkDngImage(stream)); + std::unique_ptr dngImage(new SkDngImage(stream)); if (!dngImage->isTiffHeaderValid()) { return nullptr; } @@ -479,10 +479,10 @@ public: const int preferredSize = SkTMax(width, height); try { // render() takes ownership of fHost, fInfo, fNegative and fDngStream when available. - SkAutoTDelete host(fHost.release()); - SkAutoTDelete info(fInfo.release()); - SkAutoTDelete negative(fNegative.release()); - SkAutoTDelete dngStream(fDngStream.release()); + std::unique_ptr host(fHost.release()); + std::unique_ptr info(fInfo.release()); + std::unique_ptr negative(fNegative.release()); + std::unique_ptr dngStream(fDngStream.release()); host->SetPreferredSize(preferredSize); host->ValidateSizes(); @@ -588,7 +588,7 @@ private: // Due to the limit of DNG SDK, we need to reset host and info. fHost.reset(new SkDngHost(&fAllocator)); fInfo.reset(new dng_info); - fDngStream.reset(new SkDngStream(fStream)); + fDngStream.reset(new SkDngStream(fStream.get())); fHost->ValidateSizes(); fInfo->Parse(*fHost, *fDngStream); @@ -622,11 +622,11 @@ private: {} SkDngMemoryAllocator fAllocator; - SkAutoTDelete fStream; - SkAutoTDelete fHost; - SkAutoTDelete fInfo; - SkAutoTDelete fNegative; - SkAutoTDelete fDngStream; + std::unique_ptr fStream; + std::unique_ptr fHost; + std::unique_ptr fInfo; + std::unique_ptr fNegative; + std::unique_ptr fDngStream; int fWidth; int fHeight; @@ -641,7 +641,7 @@ private: * fallback to create SkRawCodec for DNG images. */ SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { - SkAutoTDelete rawStream; + std::unique_ptr rawStream; if (is_asset_stream(*stream)) { rawStream.reset(new SkRawAssetStream(stream)); } else { @@ -671,7 +671,7 @@ SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { } // Takes the ownership of the rawStream. - SkAutoTDelete dngImage(SkDngImage::NewFromStream(rawStream.release())); + std::unique_ptr dngImage(SkDngImage::NewFromStream(rawStream.release())); if (!dngImage) { return nullptr; } @@ -688,13 +688,13 @@ SkCodec::Result SkRawCodec::onGetPixels(const SkImageInfo& requestedInfo, void* return kInvalidConversion; } - SkAutoTDelete swizzler(SkSwizzler::CreateSwizzler( + std::unique_ptr swizzler(SkSwizzler::CreateSwizzler( this->getEncodedInfo(), nullptr, requestedInfo, options)); SkASSERT(swizzler); const int width = requestedInfo.width(); const int height = requestedInfo.height(); - SkAutoTDelete image(fDngImage->render(width, height)); + std::unique_ptr image(fDngImage->render(width, height)); if (!image) { return kInvalidInput; } diff --git a/src/codec/SkRawCodec.h b/src/codec/SkRawCodec.h index 3ca7b9c..75654c7 100644 --- a/src/codec/SkRawCodec.h +++ b/src/codec/SkRawCodec.h @@ -53,7 +53,7 @@ private: */ SkRawCodec(SkDngImage* dngImage); - SkAutoTDelete fDngImage; + std::unique_ptr fDngImage; typedef SkCodec INHERITED; }; diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp index 45296d8..4102bf2 100644 --- a/src/codec/SkWbmpCodec.cpp +++ b/src/codec/SkWbmpCodec.cpp @@ -136,7 +136,7 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, setup_color_table(info.colorType(), ctable, ctableCount); // Initialize the swizzler - SkAutoTDelete swizzler(this->initializeSwizzler(info, ctable, options)); + std::unique_ptr swizzler(this->initializeSwizzler(info, ctable, options)); SkASSERT(swizzler); // Perform the decode @@ -160,7 +160,7 @@ bool SkWbmpCodec::IsWbmp(const void* buffer, size_t bytesRead) { } SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); SkISize size; if (!read_header(stream, &size)) { return nullptr; diff --git a/src/codec/SkWbmpCodec.h b/src/codec/SkWbmpCodec.h index 9f29237..3c8df02 100644 --- a/src/codec/SkWbmpCodec.h +++ b/src/codec/SkWbmpCodec.h @@ -36,7 +36,7 @@ private: const Options& opts); SkSampler* getSampler(bool createIfNecessary) override { SkASSERT(fSwizzler || !createIfNecessary); - return fSwizzler; + return fSwizzler.get(); } /* @@ -49,7 +49,7 @@ private: const size_t fSrcRowBytes; // Used for scanline decodes: - SkAutoTDelete fSwizzler; + std::unique_ptr fSwizzler; SkAutoTUnref fColorTable; SkAutoTMalloc fSrcBuffer; diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index ca42093..09913c7 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -36,7 +36,7 @@ bool SkWebpCodec::IsWebp(const void* buf, size_t bytesRead) { // bytes again. // Returns an SkWebpCodec on success; SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) { - SkAutoTDelete streamDeleter(stream); + std::unique_ptr streamDeleter(stream); // Webp demux needs a contiguous data buffer. sk_sp data = nullptr; diff --git a/src/core/SkBigPicture.h b/src/core/SkBigPicture.h index c5dfda9..3dde147 100644 --- a/src/core/SkBigPicture.h +++ b/src/core/SkBigPicture.h @@ -77,7 +77,7 @@ private: mutable SkOnce fAnalysisOnce; mutable Analysis fAnalysis; SkAutoTUnref fRecord; - SkAutoTDelete fDrawablePicts; + std::unique_ptr fDrawablePicts; SkAutoTUnref fBBH; }; diff --git a/src/core/SkColorTable.cpp b/src/core/SkColorTable.cpp index 296b31c..9710346 100644 --- a/src/core/SkColorTable.cpp +++ b/src/core/SkColorTable.cpp @@ -101,8 +101,8 @@ SkColorTable* SkColorTable::Create(SkReadBuffer& buffer) { } const size_t allocSize = count * sizeof(SkPMColor); - SkAutoTDelete colors((SkPMColor*)sk_malloc_throw(allocSize)); - if (!buffer.readColorArray(colors, count)) { + std::unique_ptr colors((SkPMColor*)sk_malloc_throw(allocSize)); + if (!buffer.readColorArray(colors.get(), count)) { return nullptr; } diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 04f1251..a72309a 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -2047,10 +2047,10 @@ void SkPaint::toString(SkString* str) const { if (typeface) { SkDynamicMemoryWStream ostream; typeface->serialize(&ostream); - SkAutoTDelete istream(ostream.detachAsStream()); + std::unique_ptr istream(ostream.detachAsStream()); SkFontDescriptor descriptor; - if (!SkFontDescriptor::Deserialize(istream, &descriptor)) { + if (!SkFontDescriptor::Deserialize(istream.get(), &descriptor)) { str->append("
FontDescriptor deserialization failed
"); } else { str->append("
Font Family Name:
"); diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index ae3b704..039efc8 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -171,9 +171,9 @@ sk_sp SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { return nullptr; } - SkAutoTDelete data( + std::unique_ptr data( SkPictureData::CreateFromStream(stream, info, factory, typefaces)); - return Forwardport(info, data, nullptr); + return Forwardport(info, data.get(), nullptr); } sk_sp SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { @@ -181,8 +181,8 @@ sk_sp SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { return nullptr; } - SkAutoTDelete data(SkPictureData::CreateFromBuffer(buffer, info)); - return Forwardport(info, data, &buffer); + std::unique_ptr data(SkPictureData::CreateFromBuffer(buffer, info)); + return Forwardport(info, data.get(), &buffer); } SkPictureData* SkPicture::backport() const { @@ -208,7 +208,7 @@ void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer, SkRefCntSet* typefaceSet) const { SkPictInfo info = this->createHeader(); - SkAutoTDelete data(this->backport()); + std::unique_ptr data(this->backport()); stream->write(&info, sizeof(info)); if (data) { @@ -221,7 +221,7 @@ void SkPicture::serialize(SkWStream* stream, void SkPicture::flatten(SkWriteBuffer& buffer) const { SkPictInfo info = this->createHeader(); - SkAutoTDelete data(this->backport()); + std::unique_ptr data(this->backport()); buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); buffer.writeUInt(info.getVersion()); diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index cc529e3..5f9cb71 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -577,7 +577,7 @@ SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, const SkPictInfo& info, SkImageDeserializer* factory, SkTypefacePlayback* topLevelTFPlayback) { - SkAutoTDelete data(new SkPictureData(info)); + std::unique_ptr data(new SkPictureData(info)); if (!topLevelTFPlayback) { topLevelTFPlayback = &data->fTFPlayback; } @@ -590,7 +590,7 @@ SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer, const SkPictInfo& info) { - SkAutoTDelete data(new SkPictureData(info)); + std::unique_ptr data(new SkPictureData(info)); buffer.setVersion(info.getVersion()); if (!data->parseBuffer(buffer)) { diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 51e1c98..0b3dd0e 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -86,7 +86,7 @@ void SkPicturePlayback::draw(SkCanvas* canvas, AutoResetOpID aroi(this); SkASSERT(0 == fCurOffset); - SkAutoTDelete reader; + std::unique_ptr reader; if (buffer) { reader.reset(buffer->clone(fPictureData->opData()->bytes(), fPictureData->opData()->size())); @@ -107,12 +107,12 @@ void SkPicturePlayback::draw(SkCanvas* canvas, fCurOffset = reader->offset(); uint32_t size; - DrawType op = ReadOpAndSize(reader, &size); + DrawType op = ReadOpAndSize(reader.get(), &size); if (!reader->validate(op > UNUSED && op <= LAST_DRAWTYPE_ENUM)) { return; } - this->handleOp(reader, op, size, canvas, initialMatrix); + this->handleOp(reader.get(), op, size, canvas, initialMatrix); } // need to propagate invalid state to the parent reader diff --git a/src/core/SkRecordedDrawable.cpp b/src/core/SkRecordedDrawable.cpp index 62a9339..3e31166 100644 --- a/src/core/SkRecordedDrawable.cpp +++ b/src/core/SkRecordedDrawable.cpp @@ -81,13 +81,13 @@ sk_sp SkRecordedDrawable::CreateProc(SkReadBuffer& buffer) { info.setVersion(buffer.getVersion()); info.fCullRect = bounds; info.fFlags = 0; // ??? - SkAutoTDelete pictureData(SkPictureData::CreateFromBuffer(buffer, info)); + std::unique_ptr pictureData(SkPictureData::CreateFromBuffer(buffer, info)); if (!pictureData) { return nullptr; } // Create a drawable. - SkPicturePlayback playback(pictureData); + SkPicturePlayback playback(pictureData.get()); SkPictureRecorder recorder; playback.draw(recorder.beginRecording(bounds), nullptr, &buffer); return recorder.finishRecordingAsDrawable(); diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp index fc2ba12..41d1a86 100644 --- a/src/core/SkStream.cpp +++ b/src/core/SkStream.cpp @@ -233,7 +233,7 @@ SkStreamAsset* SkFILEStream::duplicate() const { } if (!fName.isEmpty()) { - SkAutoTDelete that(new SkFILEStream(fName.c_str())); + std::unique_ptr that(new SkFILEStream(fName.c_str())); if (sk_fidentical(that->fFILE, this->fFILE)) { return that.release(); } @@ -259,7 +259,7 @@ bool SkFILEStream::move(long offset) { } SkStreamAsset* SkFILEStream::fork() const { - SkAutoTDelete that(this->duplicate()); + std::unique_ptr that(this->duplicate()); that->seek(this->getPosition()); return that.release(); } @@ -381,7 +381,7 @@ bool SkMemoryStream::move(long offset) { } SkMemoryStream* SkMemoryStream::fork() const { - SkAutoTDelete that(this->duplicate()); + std::unique_ptr that(this->duplicate()); that->seek(fOffset); return that.release(); } @@ -767,7 +767,7 @@ public: } SkBlockMemoryStream* fork() const override { - SkAutoTDelete that(this->duplicate()); + std::unique_ptr that(this->duplicate()); that->fCurrent = this->fCurrent; that->fOffset = this->fOffset; that->fCurrentOffset = this->fCurrentOffset; diff --git a/src/fonts/SkFontMgr_indirect.cpp b/src/fonts/SkFontMgr_indirect.cpp index 070c0aa..41447ac 100644 --- a/src/fonts/SkFontMgr_indirect.cpp +++ b/src/fonts/SkFontMgr_indirect.cpp @@ -123,14 +123,14 @@ SkTypeface* SkFontMgr_Indirect::createTypefaceFromFontId(const SkFontIdentity& i // No exact match, but did find a data match. if (dataTypeface.get() != nullptr) { - SkAutoTDelete stream(dataTypeface->openStream(nullptr)); + std::unique_ptr stream(dataTypeface->openStream(nullptr)); if (stream.get() != nullptr) { return fImpl->createFromStream(stream.release(), dataTypefaceIndex); } } // No data match, request data and add entry. - SkAutoTDelete stream(fProxy->getData(id.fDataId)); + std::unique_ptr stream(fProxy->getData(id.fDataId)); if (stream.get() == nullptr) { return nullptr; } diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index 3945fe5..fa275d2 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -103,7 +103,7 @@ private: bool fAbandoned; SkTDArray fOpLists; - SkAutoTDelete fAtlasTextContext; + std::unique_ptr fAtlasTextContext; GrPathRendererChain* fPathRendererChain; GrSoftwarePathRenderer* fSoftwarePathRenderer; diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 475950a..9a74560 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -513,10 +513,10 @@ protected: // Handles cases where a surface will be updated without a call to flushRenderTarget void didWriteToSurface(GrSurface* surface, const SkIRect* bounds, uint32_t mipLevels = 1) const; - Stats fStats; - SkAutoTDelete fPathRendering; + Stats fStats; + std::unique_ptr fPathRendering; // Subclass must initialize this in its constructor. - SkAutoTUnref fCaps; + SkAutoTUnref fCaps; typedef SkTArray SamplePattern; diff --git a/src/gpu/GrPathRenderingRenderTargetContext.h b/src/gpu/GrPathRenderingRenderTargetContext.h index a4353e1..1ad3a0b 100644 --- a/src/gpu/GrPathRenderingRenderTargetContext.h +++ b/src/gpu/GrPathRenderingRenderTargetContext.h @@ -34,7 +34,7 @@ protected: : INHERITED(ctx, mgr, std::move(rtp), std::move(colorSpace), surfaceProps, at, so) {} private: - SkAutoTDelete fStencilAndCoverTextContext; + std::unique_ptr fStencilAndCoverTextContext; friend class GrDrawingManager; // for ctor diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp index 37c469a..b4e6870 100644 --- a/src/gpu/GrRenderTargetOpList.cpp +++ b/src/gpu/GrRenderTargetOpList.cpp @@ -185,7 +185,7 @@ bool GrRenderTargetOpList::drawBatches(GrBatchFlushState* flushState) { // Draw all the generated geometry. SkRandom random; GrRenderTarget* currentRT = nullptr; - SkAutoTDelete commandBuffer; + std::unique_ptr commandBuffer; for (int i = 0; i < fRecordedBatches.count(); ++i) { if (!fRecordedBatches[i].fBatch) { continue; @@ -205,7 +205,7 @@ bool GrRenderTargetOpList::drawBatches(GrBatchFlushState* flushState) { kBasicLoadStoreInfo, // Color kBasicLoadStoreInfo)); // Stencil } - flushState->setCommandBuffer(commandBuffer); + flushState->setCommandBuffer(commandBuffer.get()); } if (fDrawBatchBounds) { const SkRect& bounds = fRecordedBatches[i].fClippedBounds; diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h index e4b2bf6..62f86d1 100644 --- a/src/gpu/GrRenderTargetOpList.h +++ b/src/gpu/GrRenderTargetOpList.h @@ -125,7 +125,7 @@ public: gr_instanced::InstancedRendering* instancedRendering() const { SkASSERT(fInstancedRendering); - return fInstancedRendering; + return fInstancedRendering.get(); } SkDEBUGCODE(void dump() const override;) @@ -167,7 +167,7 @@ private: int fMaxBatchLookback; int fMaxBatchLookahead; - SkAutoTDelete fInstancedRendering; + std::unique_ptr fInstancedRendering; int32_t fLastClipStackGenID; SkIRect fLastClipStackRect; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index d0a35b5..679ba8c 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -378,7 +378,7 @@ GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& b sk_throw(); } - SkAutoTDelete mipmaps(SkMipMap::Build(pixmap, gammaTreatment, nullptr)); + std::unique_ptr mipmaps(SkMipMap::Build(pixmap, gammaTreatment, nullptr)); if (!mipmaps) { return nullptr; } diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 34037a2..157f404 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -136,8 +136,8 @@ protected: GrGLuint fProgramID; // the installed effects - SkAutoTDelete fGeometryProcessor; - SkAutoTDelete fXferProcessor; + std::unique_ptr fGeometryProcessor; + std::unique_ptr fXferProcessor; GrGLSLFragProcs fFragmentProcessors; GrProgramDesc fDesc; diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp index 475b020..bcf4864 100644 --- a/src/gpu/instanced/InstanceProcessor.cpp +++ b/src/gpu/instanced/InstanceProcessor.cpp @@ -242,7 +242,7 @@ void GLSLInstanceProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { inputs.attr(Attrib::kInstanceInfo)); } - SkAutoTDelete backend(Backend::Create(pipeline, ip.batchInfo(), inputs)); + std::unique_ptr backend(Backend::Create(pipeline, ip.batchInfo(), inputs)); backend->init(varyingHandler, v); int usedShapeDefinitions = 0; diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index 5aaf210..c8e2008 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -490,7 +490,7 @@ private: // though the distance field text and the coloremoji may share the same run, they // will have different descriptors. If fOverrideDescriptor is non-nullptr, then it // will be used in place of the run's descriptor to regen texture coords - SkAutoTDelete fOverrideDescriptor; // df properties + std::unique_ptr fOverrideDescriptor; // df properties bool fInitialized; bool fDrawAsPaths; }; diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp index 1d46fc6..b3a7eef 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp @@ -351,7 +351,7 @@ private: void flush(); - SkAutoTDelete fBuilder; + std::unique_ptr fBuilder; SkPaint fFont; int fBuffIdx; int fCount; diff --git a/src/gpu/vk/GrVkExtensions.h b/src/gpu/vk/GrVkExtensions.h index 6c395fd..2decd15 100644 --- a/src/gpu/vk/GrVkExtensions.h +++ b/src/gpu/vk/GrVkExtensions.h @@ -37,10 +37,10 @@ public: void print(const char* sep = "\n") const; private: - SkAutoTDelete > fInstanceExtensionStrings; - SkAutoTDelete > fDeviceExtensionStrings; - SkAutoTDelete > fInstanceLayerStrings; - SkAutoTDelete > fDeviceLayerStrings; + std::unique_ptr> fInstanceExtensionStrings; + std::unique_ptr> fDeviceExtensionStrings; + std::unique_ptr> fInstanceLayerStrings; + std::unique_ptr> fDeviceLayerStrings; }; #endif diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 6f03803..50f7471 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -168,7 +168,7 @@ public: }; static const int kHeapCount = kLastHeap + 1; - GrVkHeap* getHeap(Heap heap) const { return fHeaps[heap]; } + GrVkHeap* getHeap(Heap heap) const { return fHeaps[heap].get(); } private: GrVkGpu(GrContext* context, const GrContextOptions& options, @@ -269,7 +269,7 @@ private: GrVkPrimaryCommandBuffer* fCurrentCmdBuffer; VkPhysicalDeviceMemoryProperties fPhysDevMemProps; - SkAutoTDelete fHeaps[kHeapCount]; + std::unique_ptr fHeaps[kHeapCount]; GrVkCopyManager fCopyManager; diff --git a/src/gpu/vk/GrVkMemory.cpp b/src/gpu/vk/GrVkMemory.cpp index 2853c89..2764102 100644 --- a/src/gpu/vk/GrVkMemory.cpp +++ b/src/gpu/vk/GrVkMemory.cpp @@ -561,7 +561,7 @@ bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment, } // need to allocate a new subheap - SkAutoTDelete& subHeap = fSubHeaps.push_back(); + std::unique_ptr& subHeap = fSubHeaps.push_back(); subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, heapIndex, fSubHeapSize, alignment)); // try to recover from failed allocation by only allocating what we need if (subHeap->size() == 0) { @@ -609,7 +609,7 @@ bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment, } // need to allocate a new subheap - SkAutoTDelete& subHeap = fSubHeaps.push_back(); + std::unique_ptr& subHeap = fSubHeaps.push_back(); subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, heapIndex, alignedSize, alignment)); fAllocSize += alignedSize; if (subHeap->alloc(size, alloc)) { diff --git a/src/gpu/vk/GrVkMemory.h b/src/gpu/vk/GrVkMemory.h index a1d4392..77267ab 100644 --- a/src/gpu/vk/GrVkMemory.h +++ b/src/gpu/vk/GrVkMemory.h @@ -162,6 +162,6 @@ private: VkDeviceSize fAllocSize; VkDeviceSize fUsedSize; AllocFunc fAllocFunc; - SkTArray> fSubHeaps; + SkTArray> fSubHeaps; }; #endif diff --git a/src/gpu/vk/GrVkPipelineState.cpp b/src/gpu/vk/GrVkPipelineState.cpp index abb95f6..ba4f95f 100644 --- a/src/gpu/vk/GrVkPipelineState.cpp +++ b/src/gpu/vk/GrVkPipelineState.cpp @@ -226,8 +226,11 @@ void GrVkPipelineState::setData(GrVkGpu* gpu, } if (fVertexUniformBuffer.get() || fFragmentUniformBuffer.get()) { - if (fDataManager.uploadUniformBuffers(gpu, fVertexUniformBuffer, fFragmentUniformBuffer) || - !fUniformDescriptorSet) { + if (fDataManager.uploadUniformBuffers(gpu, + fVertexUniformBuffer.get(), + fFragmentUniformBuffer.get()) + || !fUniformDescriptorSet) + { if (fUniformDescriptorSet) { fUniformDescriptorSet->recycle(gpu); } diff --git a/src/gpu/vk/GrVkPipelineState.h b/src/gpu/vk/GrVkPipelineState.h index ba8a21f..63277c0 100644 --- a/src/gpu/vk/GrVkPipelineState.h +++ b/src/gpu/vk/GrVkPipelineState.h @@ -208,8 +208,8 @@ private: int fStartDS; int fDSCount; - SkAutoTDelete fVertexUniformBuffer; - SkAutoTDelete fFragmentUniformBuffer; + std::unique_ptr fVertexUniformBuffer; + std::unique_ptr fFragmentUniformBuffer; // GrVkResources used for sampling textures SkTDArray fSamplers; @@ -221,8 +221,8 @@ private: BuiltinUniformHandles fBuiltinUniformHandles; // Processors in the GrVkPipelineState - SkAutoTDelete fGeometryProcessor; - SkAutoTDelete fXferProcessor; + std::unique_ptr fGeometryProcessor; + std::unique_ptr fXferProcessor; GrGLSLFragProcs fFragmentProcessors; Desc fDesc; diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index d80b187..e993002 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -616,7 +616,7 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox static_assert(std::is_standard_layout::value, "offsetof, which we use below, requires the type have a standard layout"); - SkAutoTDelete mipmaps(SkMipMap::Build(pixmap, gammaTreatment, nullptr)); + std::unique_ptr mipmaps(SkMipMap::Build(pixmap, gammaTreatment, nullptr)); // SkMipMap holds only the mipmap levels it generates. // A programmer can use the data they provided to SkMipMap::Build as level 0. // So the SkMipMap provides levels 1-x but it stores them in its own diff --git a/src/images/SkImageEncoder.cpp b/src/images/SkImageEncoder.cpp index 023885f..787ff8e 100644 --- a/src/images/SkImageEncoder.cpp +++ b/src/images/SkImageEncoder.cpp @@ -38,18 +38,18 @@ SkData* SkImageEncoder::encodeData(const SkBitmap& bm, int quality) { bool SkImageEncoder::EncodeFile(const char file[], const SkBitmap& bm, Type t, int quality) { - SkAutoTDelete enc(SkImageEncoder::Create(t)); + std::unique_ptr enc(SkImageEncoder::Create(t)); return enc.get() && enc.get()->encodeFile(file, bm, quality); } bool SkImageEncoder::EncodeStream(SkWStream* stream, const SkBitmap& bm, Type t, int quality) { - SkAutoTDelete enc(SkImageEncoder::Create(t)); + std::unique_ptr enc(SkImageEncoder::Create(t)); return enc.get() && enc.get()->encodeStream(stream, bm, quality); } SkData* SkImageEncoder::EncodeData(const SkBitmap& bm, Type t, int quality) { - SkAutoTDelete enc(SkImageEncoder::Create(t)); + std::unique_ptr enc(SkImageEncoder::Create(t)); return enc.get() ? enc.get()->encodeData(bm, quality) : nullptr; } diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index 19eff6f..83fbd1d 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -2454,8 +2454,8 @@ protected: } SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override { - SkAutoTDelete stream(bareStream); - return create_from_stream(stream); + std::unique_ptr stream(bareStream); + return create_from_stream(stream.get()); } SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override { diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp index d4c7569..404ae98 100644 --- a/src/ports/SkFontMgr_FontConfigInterface.cpp +++ b/src/ports/SkFontMgr_FontConfigInterface.cpp @@ -113,7 +113,7 @@ private: const char* getCategory() const override { return "request_cache"; } SkDiscardableMemory* diagnostic_only_getDiscardable() const override { return nullptr; } - SkAutoTDelete fRequest; + std::unique_ptr fRequest; SkAutoTUnref fFace; }; @@ -267,8 +267,8 @@ protected: // Check if this request is already in the request cache. using Request = SkFontRequestCache::Request; - SkAutoTDelete request(Request::Create(requestedFamilyName, requestedStyle)); - SkTypeface* face = fCache.findAndRef(request); + std::unique_ptr request(Request::Create(requestedFamilyName, requestedStyle)); + SkTypeface* face = fCache.findAndRef(request.get()); if (face) { return face; } diff --git a/src/ports/SkFontMgr_android_parser.cpp b/src/ports/SkFontMgr_android_parser.cpp index 306c6ff..e5fdcd0 100644 --- a/src/ports/SkFontMgr_android_parser.cpp +++ b/src/ports/SkFontMgr_android_parser.cpp @@ -100,18 +100,18 @@ struct FamilyData { , fHandler(&topLevelHandler, 1) { } - XML_Parser fParser; // The expat parser doing the work, owned by caller - SkTDArray& fFamilies; // The array to append families, owned by caller - SkAutoTDelete fCurrentFamily; // The family being created, owned by this - FontFileInfo* fCurrentFontInfo; // The fontInfo being created, owned by fCurrentFamily - int fVersion; // The version of the file parsed. - const SkString& fBasePath; // The current base path. - const bool fIsFallback; // Indicates the file being parsed is a fallback file - const char* fFilename; // The name of the file currently being parsed. - - int fDepth; // The current element depth of the parse. - int fSkip; // The depth to stop skipping, 0 if not skipping. - SkTDArray fHandler; // The stack of current tag handlers. + XML_Parser fParser; // The expat parser doing the work, owned by caller + SkTDArray& fFamilies; // The array to append families, owned by caller + std::unique_ptr fCurrentFamily; // The family being created, owned by this + FontFileInfo* fCurrentFontInfo; // The info being created, owned by fCurrentFamily + int fVersion; // The version of the file parsed. + const SkString& fBasePath; // The current base path. + const bool fIsFallback; // The file being parsed is a fallback file + const char* fFilename; // The name of the file currently being parsed. + + int fDepth; // The current element depth of the parse. + int fSkip; // The depth to stop skipping, 0 if not skipping. + SkTDArray fHandler; // The stack of current tag handlers. }; static bool memeq(const char* s1, const char* s2, size_t n1, size_t n2) { diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp index 33ae767..cd0b665 100644 --- a/src/ports/SkFontMgr_win_dw.cpp +++ b/src/ports/SkFontMgr_win_dw.cpp @@ -51,7 +51,7 @@ public: return S_OK; } - SkAutoTDelete fStream; + std::unique_ptr fStream; private: StreamFontFileLoader(SkStreamAsset* stream) : fStream(stream), fRefCount(1) { } diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp index dc87218..e955665 100644 --- a/src/ports/SkTypeface_win_dw.cpp +++ b/src/ports/SkTypeface_win_dw.cpp @@ -193,8 +193,8 @@ int DWriteFontTypeface::onGetTableTags(SkFontTableTag tags[]) const { } int ttcIndex; - SkAutoTDelete stream(this->openStream(&ttcIndex)); - return stream.get() ? SkFontStream::GetTableTags(stream, ttcIndex, tags) : 0; + std::unique_ptr stream(this->openStream(&ttcIndex)); + return stream.get() ? SkFontStream::GetTableTags(stream.get(), ttcIndex, tags) : 0; } size_t DWriteFontTypeface::onGetTableData(SkFontTableTag tag, size_t offset, diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp index b07e0aa..4496c0a 100644 --- a/src/svg/SkSVGDevice.cpp +++ b/src/svg/SkSVGDevice.cpp @@ -342,7 +342,7 @@ private: SkXMLWriter* fWriter; ResourceBucket* fResourceBucket; - SkAutoTDelete fClipGroup; + std::unique_ptr fClipGroup; }; void SkSVGDevice::AutoElement::addPaint(const SkPaint& paint, const Resources& resources) { @@ -592,7 +592,7 @@ SkSVGDevice::~SkSVGDevice() { } void SkSVGDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { - AutoElement rect("rect", fWriter, fResourceBucket, draw, paint); + AutoElement rect("rect", fWriter, fResourceBucket.get(), draw, paint); rect.addRectAttributes(SkRect::MakeWH(SkIntToScalar(this->width()), SkIntToScalar(this->height()))); } @@ -612,7 +612,7 @@ void SkSVGDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_ path.rewind(); path.moveTo(pts[i]); path.lineTo(pts[i+1]); - AutoElement elem("path", fWriter, fResourceBucket, draw, paint); + AutoElement elem("path", fWriter, fResourceBucket.get(), draw, paint); elem.addPathAttributes(path); } break; @@ -620,7 +620,7 @@ void SkSVGDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_ if (count > 1) { path.addPoly(pts, SkToInt(count), false); path.moveTo(pts[0]); - AutoElement elem("path", fWriter, fResourceBucket, draw, paint); + AutoElement elem("path", fWriter, fResourceBucket.get(), draw, paint); elem.addPathAttributes(path); } break; @@ -628,12 +628,12 @@ void SkSVGDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_ } void SkSVGDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { - AutoElement rect("rect", fWriter, fResourceBucket, draw, paint); + AutoElement rect("rect", fWriter, fResourceBucket.get(), draw, paint); rect.addRectAttributes(r); } void SkSVGDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { - AutoElement ellipse("ellipse", fWriter, fResourceBucket, draw, paint); + AutoElement ellipse("ellipse", fWriter, fResourceBucket.get(), draw, paint); ellipse.addAttribute("cx", oval.centerX()); ellipse.addAttribute("cy", oval.centerY()); ellipse.addAttribute("rx", oval.width() / 2); @@ -644,13 +644,13 @@ void SkSVGDevice::drawRRect(const SkDraw& draw, const SkRRect& rr, const SkPaint SkPath path; path.addRRect(rr); - AutoElement elem("path", fWriter, fResourceBucket, draw, paint); + AutoElement elem("path", fWriter, fResourceBucket.get(), draw, paint); elem.addPathAttributes(path); } void SkSVGDevice::drawPath(const SkDraw& draw, const SkPath& path, const SkPaint& paint, const SkMatrix* prePathMatrix, bool pathIsMutable) { - AutoElement elem("path", fWriter, fResourceBucket, draw, paint); + AutoElement elem("path", fWriter, fResourceBucket.get(), draw, paint); elem.addPathAttributes(path); // TODO: inverse fill types? @@ -687,7 +687,7 @@ void SkSVGDevice::drawBitmapCommon(const SkDraw& draw, const SkBitmap& bm, } { - AutoElement imageUse("use", fWriter, fResourceBucket, draw, paint); + AutoElement imageUse("use", fWriter, fResourceBucket.get(), draw, paint); imageUse.addAttribute("xlink:href", SkStringPrintf("#%s", imageID.c_str())); } } @@ -737,7 +737,7 @@ void SkSVGDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bm, const S void SkSVGDevice::drawText(const SkDraw& draw, const void* text, size_t len, SkScalar x, SkScalar y, const SkPaint& paint) { - AutoElement elem("text", fWriter, fResourceBucket, draw, paint); + AutoElement elem("text", fWriter, fResourceBucket.get(), draw, paint); elem.addTextAttributes(paint); SVGTextBuilder builder(text, len, paint, SkPoint::Make(x, y), 0); @@ -751,7 +751,7 @@ void SkSVGDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, const SkPaint& paint) { SkASSERT(scalarsPerPos == 1 || scalarsPerPos == 2); - AutoElement elem("text", fWriter, fResourceBucket, draw, paint); + AutoElement elem("text", fWriter, fResourceBucket.get(), draw, paint); elem.addTextAttributes(paint); SVGTextBuilder builder(text, len, paint, offset, scalarsPerPos, pos); diff --git a/src/svg/SkSVGDevice.h b/src/svg/SkSVGDevice.h index d0b9a24..ccd18c4 100644 --- a/src/svg/SkSVGDevice.h +++ b/src/svg/SkSVGDevice.h @@ -63,9 +63,9 @@ private: class AutoElement; class ResourceBucket; - SkXMLWriter* fWriter; - SkAutoTDelete fRootElement; - SkAutoTDelete fResourceBucket; + SkXMLWriter* fWriter; + std::unique_ptr fRootElement; + std::unique_ptr fResourceBucket; typedef SkBaseDevice INHERITED; }; diff --git a/src/utils/SkCanvasStateUtils.cpp b/src/utils/SkCanvasStateUtils.cpp index 60484a4..3426126 100644 --- a/src/utils/SkCanvasStateUtils.cpp +++ b/src/utils/SkCanvasStateUtils.cpp @@ -204,7 +204,7 @@ SkCanvasState* SkCanvasStateUtils::CaptureCanvasState(SkCanvas* canvas) { return nullptr; } - SkAutoTDelete canvasState(new SkCanvasState_v1(canvas)); + std::unique_ptr canvasState(new SkCanvasState_v1(canvas)); // decompose the total matrix and clip setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(), diff --git a/src/utils/SkFrontBufferedStream.cpp b/src/utils/SkFrontBufferedStream.cpp index 2dfb8ab..42b86f0 100644 --- a/src/utils/SkFrontBufferedStream.cpp +++ b/src/utils/SkFrontBufferedStream.cpp @@ -29,19 +29,19 @@ public: SkStreamRewindable* duplicate() const override { return nullptr; } private: - SkAutoTDelete fStream; - const bool fHasLength; - const size_t fLength; + std::unique_ptr fStream; + const bool fHasLength; + const size_t fLength; // Current offset into the stream. Always >= 0. - size_t fOffset; + size_t fOffset; // Amount that has been buffered by calls to read. Will always be less than // fBufferSize. - size_t fBufferedSoFar; + size_t fBufferedSoFar; // Total size of the buffer. - const size_t fBufferSize; + const size_t fBufferSize; // FIXME: SkAutoTMalloc throws on failure. Instead, Create should return a // nullptr stream. - SkAutoTMalloc fBuffer; + SkAutoTMalloc fBuffer; // Read up to size bytes from already buffered data, and copy to // dst, if non-nullptr. Updates fOffset. Assumes that fOffset is less diff --git a/src/utils/win/SkDWriteFontFileStream.cpp b/src/utils/win/SkDWriteFontFileStream.cpp index 6c73441..2bb7d0f 100644 --- a/src/utils/win/SkDWriteFontFileStream.cpp +++ b/src/utils/win/SkDWriteFontFileStream.cpp @@ -105,7 +105,7 @@ bool SkDWriteFontFileStream::move(long offset) { } SkDWriteFontFileStream* SkDWriteFontFileStream::fork() const { - SkAutoTDelete that(this->duplicate()); + std::unique_ptr that(this->duplicate()); that->seek(fPos); return that.release(); } diff --git a/src/utils/win/SkDWriteFontFileStream.h b/src/utils/win/SkDWriteFontFileStream.h index e78b621..25322c5 100644 --- a/src/utils/win/SkDWriteFontFileStream.h +++ b/src/utils/win/SkDWriteFontFileStream.h @@ -73,7 +73,7 @@ private: virtual ~SkDWriteFontFileStreamWrapper() { } ULONG fRefCount; - SkAutoTDelete fStream; + std::unique_ptr fStream; SkMutex fStreamMutex; }; #endif diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp index 7b658c8..57e165f 100644 --- a/src/views/SkEvent.cpp +++ b/src/views/SkEvent.cpp @@ -415,9 +415,8 @@ SkMSec SkEvent::EnqueueTime(SkEvent* evt, SkMSec time) { #include "SkEventSink.h" bool SkEvent::ProcessEvent() { - SkEvent* evt = SkEvent::Dequeue(); - SkAutoTDelete autoDelete(evt); - bool again = false; + std::unique_ptr evt(SkEvent::Dequeue()); + bool again = false; EVENT_LOGN("ProcessEvent", (int32_t)evt); diff --git a/src/xps/SkDocument_XPS.cpp b/src/xps/SkDocument_XPS.cpp index 4a977ae..cb4938b 100644 --- a/src/xps/SkDocument_XPS.cpp +++ b/src/xps/SkDocument_XPS.cpp @@ -72,7 +72,7 @@ sk_sp SkDocument::MakeXPS(SkWStream* stream, SkScalar dpi) { static void delete_wstream(SkWStream* stream, bool aborted) { delete stream; } sk_sp SkDocument::MakeXPS(const char path[], SkScalar dpi) { - SkAutoTDelete stream(new SkFILEWStream(path)); + std::unique_ptr stream(new SkFILEWStream(path)); if (!stream->isValid()) { return nullptr; } diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index 7eb1587..07dcd45 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -428,7 +428,7 @@ static HRESULT subset_typeface(SkXPSDevice::TypefaceUse* current) { fontPackageBuffer.realloc(bytesWritten); } - SkAutoTDelete newStream(new SkMemoryStream()); + std::unique_ptr newStream(new SkMemoryStream()); newStream->setMemoryOwned(fontPackageBuffer.release(), bytesWritten + extra); SkTScopedComPtr newIStream; diff --git a/tests/BadIcoTest.cpp b/tests/BadIcoTest.cpp index 4affa85..a0664f1 100644 --- a/tests/BadIcoTest.cpp +++ b/tests/BadIcoTest.cpp @@ -28,8 +28,8 @@ DEF_TEST(BadImage, reporter) { for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) { SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]); - SkAutoTDelete stream(GetResourceAsStream(resourcePath.c_str())); - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr stream(GetResourceAsStream(resourcePath.c_str())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); // These images are corrupt. It's not important whether we succeed/fail in codec // creation or decoding. We just want to make sure that we don't crash. diff --git a/tests/CodecPartialTest.cpp b/tests/CodecPartialTest.cpp index 22d4e7b..ba1a51f 100644 --- a/tests/CodecPartialTest.cpp +++ b/tests/CodecPartialTest.cpp @@ -28,12 +28,12 @@ static SkImageInfo standardize_info(SkCodec* codec) { } static bool create_truth(sk_sp data, SkBitmap* dst) { - SkAutoTDelete codec(SkCodec::NewFromData(std::move(data))); + std::unique_ptr codec(SkCodec::NewFromData(std::move(data))); if (!codec) { return false; } - const SkImageInfo info = standardize_info(codec); + const SkImageInfo info = standardize_info(codec.get()); dst->allocPixels(info); return SkCodec::kSuccess == codec->getPixels(info, dst->getPixels(), dst->rowBytes()); } @@ -108,7 +108,7 @@ static void test_partial(skiatest::Reporter* r, const char* name) { // Note that we cheat and hold on to a pointer to stream, though it is owned by // partialCodec. - SkAutoTDelete partialCodec(SkCodec::NewFromStream(stream)); + std::unique_ptr partialCodec(SkCodec::NewFromStream(stream)); if (!partialCodec) { // Technically, this could be a small file where half the file is not // enough. @@ -116,7 +116,7 @@ static void test_partial(skiatest::Reporter* r, const char* name) { return; } - const SkImageInfo info = standardize_info(partialCodec); + const SkImageInfo info = standardize_info(partialCodec.get()); SkASSERT(info == truth.info()); SkBitmap incremental; incremental.allocPixels(info); @@ -284,14 +284,14 @@ static void test_interleaved(skiatest::Reporter* r, const char* name) { return; } const size_t halfSize = file->size() / 2; - SkAutoTDelete partialCodec(SkCodec::NewFromStream( + std::unique_ptr partialCodec(SkCodec::NewFromStream( new HaltingStream(std::move(file), halfSize))); if (!partialCodec) { ERRORF(r, "Failed to create codec for %s", name); return; } - const SkImageInfo info = standardize_info(partialCodec); + const SkImageInfo info = standardize_info(partialCodec.get()); SkBitmap incremental; incremental.allocPixels(info); diff --git a/tests/CodecPriv.h b/tests/CodecPriv.h index a5afb09..e9ea242 100644 --- a/tests/CodecPriv.h +++ b/tests/CodecPriv.h @@ -10,7 +10,7 @@ #include "SkData.h" inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) { - SkAutoTDelete codec(SkCodec::NewFromData(SkData::MakeWithoutCopy(mem, size))); + std::unique_ptr codec(SkCodec::NewFromData(SkData::MakeWithoutCopy(mem, size))); if (!codec) { return false; } diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp index c171a7e..c8b573a 100644 --- a/tests/CodecTest.cpp +++ b/tests/CodecTest.cpp @@ -260,16 +260,16 @@ static void check(skiatest::Reporter* r, bool supportsIncomplete, bool supportsNewScanlineDecoding = false) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete codec(nullptr); + std::unique_ptr codec(nullptr); bool isIncomplete = supportsIncomplete; if (isIncomplete) { size_t size = stream->getLength(); - sk_sp data((SkData::MakeFromStream(stream, 2 * size / 3))); + sk_sp data((SkData::MakeFromStream(stream.get(), 2 * size / 3))); codec.reset(SkCodec::NewFromData(data)); } else { codec.reset(SkCodec::NewFromStream(stream.release())); @@ -289,12 +289,12 @@ static void check(skiatest::Reporter* r, // Scanline decoding follows. if (supportsNewScanlineDecoding && !isIncomplete) { - test_incremental_decode(r, codec, info, codecDigest); + test_incremental_decode(r, codec.get(), info, codecDigest); // This is only supported by codecs that use incremental decoding to // support subset decodes - png and jpeg (once SkJpegCodec is // converted). if (SkStrEndsWith(path, "png") || SkStrEndsWith(path, "PNG")) { - test_in_stripes(r, codec, info, codecDigest); + test_in_stripes(r, codec.get(), info, codecDigest); } } @@ -397,15 +397,15 @@ static void check(skiatest::Reporter* r, // SkAndroidCodec tests if (supportsScanlineDecoding || supportsSubsetDecoding || supportsNewScanlineDecoding) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete androidCodec(nullptr); + std::unique_ptr androidCodec(nullptr); if (isIncomplete) { size_t size = stream->getLength(); - sk_sp data((SkData::MakeFromStream(stream, 2 * size / 3))); + sk_sp data((SkData::MakeFromStream(stream.get(), 2 * size / 3))); androidCodec.reset(SkAndroidCodec::NewFromData(data)); } else { androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release())); @@ -423,9 +423,9 @@ static void check(skiatest::Reporter* r, if (!isIncomplete) { // Test SkCodecImageGenerator - SkAutoTDelete stream(GetResourceAsStream(path)); - sk_sp fullData(SkData::MakeFromStream(stream, stream->getLength())); - SkAutoTDelete gen( + std::unique_ptr stream(GetResourceAsStream(path)); + sk_sp fullData(SkData::MakeFromStream(stream.get(), stream->getLength())); + std::unique_ptr gen( SkCodecImageGenerator::NewFromEncodedCodec(fullData.get())); SkBitmap bm; bm.allocPixels(info); @@ -560,11 +560,11 @@ DEF_TEST(Codec_null, r) { static void test_dimensions(skiatest::Reporter* r, const char path[]) { // Create the codec from the resource file - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete codec(SkAndroidCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkAndroidCodec::NewFromStream(stream.release())); if (!codec) { ERRORF(r, "Unable to create codec '%s'", path); return; @@ -624,11 +624,11 @@ DEF_TEST(Codec_Dimensions, r) { } static void test_invalid(skiatest::Reporter* r, const char path[]) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, nullptr == codec); } @@ -649,11 +649,11 @@ DEF_TEST(Codec_Empty, r) { } static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete decoder(SkCodec::NewFromStream(stream.release())); + std::unique_ptr decoder(SkCodec::NewFromStream(stream.release())); if (!decoder) { SkDebugf("Missing codec for %s\n", path); return; @@ -818,7 +818,7 @@ DEF_TEST(Codec_pngChunkReader, r) { ChunkReader chunkReader(r); // Now read the file with SkCodec. - SkAutoTDelete codec(SkCodec::NewFromData(wStream.detachAsData(), &chunkReader)); + std::unique_ptr codec(SkCodec::NewFromData(wStream.detachAsData(), &chunkReader)); REPORTER_ASSERT(r, codec); if (!codec) { return; @@ -922,7 +922,7 @@ DEF_TEST(Codec_raw_notseekable, r) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(new NotAssetMemStream(std::move(data)))); + std::unique_ptr codec(SkCodec::NewFromStream(new NotAssetMemStream(std::move(data)))); REPORTER_ASSERT(r, codec); test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); @@ -941,7 +941,7 @@ DEF_TEST(Codec_webp_peek, r) { } // The limit is less than webp needs to peek or read. - SkAutoTDelete codec(SkCodec::NewFromStream( + std::unique_ptr codec(SkCodec::NewFromStream( new LimitedPeekingMemStream(data, 25))); REPORTER_ASSERT(r, codec); @@ -960,18 +960,18 @@ DEF_TEST(Codec_webp_peek, r) { // Test that SkCodec now supports an image with these bits set. DEF_TEST(Codec_wbmp, r) { const char* path = "mandrill.wbmp"; - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } // Modify the stream to contain a second byte with some bits set. - auto data = SkCopyStreamToData(stream); + auto data = SkCopyStreamToData(stream.get()); uint8_t* writeableData = static_cast(data->writable_data()); writeableData[1] = static_cast(~0x9F); // SkCodec should support this. - SkAutoTDelete codec(SkCodec::NewFromData(data)); + std::unique_ptr codec(SkCodec::NewFromData(data)); REPORTER_ASSERT(r, codec); if (!codec) { return; @@ -988,8 +988,8 @@ DEF_TEST(Codec_wbmp_max_size, r) { const unsigned char maxSizeWbmp[] = { 0x00, 0x00, // Header 0x83, 0xFF, 0x7F, // W: 65535 0x83, 0xFF, 0x7F }; // H: 65535 - SkAutoTDelete stream(new SkMemoryStream(maxSizeWbmp, sizeof(maxSizeWbmp), false)); - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr stream(new SkMemoryStream(maxSizeWbmp, sizeof(maxSizeWbmp), false)); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, codec); if (!codec) return; @@ -1010,11 +1010,11 @@ DEF_TEST(Codec_wbmp_max_size, r) { DEF_TEST(Codec_jpeg_rewind, r) { const char* path = "mandrill_512_q075.jpg"; - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete codec(SkAndroidCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkAndroidCodec::NewFromStream(stream.release())); if (!codec) { ERRORF(r, "Unable to create codec '%s'.", path); return; @@ -1037,7 +1037,7 @@ DEF_TEST(Codec_jpeg_rewind, r) { } static void check_color_xform(skiatest::Reporter* r, const char* path) { - SkAutoTDelete codec(SkAndroidCodec::NewFromStream(GetResourceAsStream(path))); + std::unique_ptr codec(SkAndroidCodec::NewFromStream(GetResourceAsStream(path))); SkAndroidCodec::AndroidOptions opts; opts.fSampleSize = 3; @@ -1104,7 +1104,7 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk sk_sp data = sk_sp(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_Type, 100)); - SkAutoTDelete codec(SkCodec::NewFromData(data)); + std::unique_ptr codec(SkCodec::NewFromData(data)); REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType())); REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alphaType())); @@ -1123,8 +1123,8 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk DEF_TEST(Codec_PngRoundTrip, r) { const char* path = "mandrill_512_q075.jpg"; - SkAutoTDelete stream(GetResourceAsStream(path)); - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr stream(GetResourceAsStream(path)); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); SkColorType colorTypesOpaque[] = { kRGB_565_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType @@ -1173,8 +1173,8 @@ DEF_TEST(Codec_PngRoundTrip, r) { static void test_conversion_possible(skiatest::Reporter* r, const char* path, bool supportsScanlineDecoder, bool supportsIncrementalDecoder) { - SkAutoTDelete stream(GetResourceAsStream(path)); - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr stream(GetResourceAsStream(path)); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType); SkBitmap bm; @@ -1314,9 +1314,9 @@ public: } private: - SkAutoTDelete fStream; - const size_t fLimit; - size_t fPosition; + std::unique_ptr fStream; + const size_t fLimit; + size_t fPosition; LimitedRewindingStream(SkStream* stream, size_t limit) : fStream(stream) @@ -1346,7 +1346,7 @@ DEF_TEST(Codec_fallBack, r) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(stream)); + std::unique_ptr codec(SkCodec::NewFromStream(stream)); if (!codec) { ERRORF(r, "Failed to create codec for %s,", file); continue; diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp index ca08563..e1ff160 100644 --- a/tests/ColorSpaceTest.cpp +++ b/tests/ColorSpaceTest.cpp @@ -46,13 +46,13 @@ static void test_space(skiatest::Reporter* r, SkColorSpace* space, static void test_path(skiatest::Reporter* r, const char* path, const float red[], const float green[], const float blue[], const SkGammaNamed expectedGamma) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); REPORTER_ASSERT(r, nullptr != stream); if (!stream) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, nullptr != codec); if (!codec) { return; diff --git a/tests/DataRefTest.cpp b/tests/DataRefTest.cpp index 391124e..72bad6f 100644 --- a/tests/DataRefTest.cpp +++ b/tests/DataRefTest.cpp @@ -365,7 +365,7 @@ DEF_TEST(RWBuffer_noAppend, r) { REPORTER_ASSERT(r, !iter.next()); } - SkAutoTDelete stream(buffer.newStreamSnapshot()); + std::unique_ptr stream(buffer.newStreamSnapshot()); REPORTER_ASSERT(r, stream); if (stream) { REPORTER_ASSERT(r, stream->hasLength()); diff --git a/tests/DiscardableMemoryPoolTest.cpp b/tests/DiscardableMemoryPoolTest.cpp index cabd14b..d1ba38a 100644 --- a/tests/DiscardableMemoryPoolTest.cpp +++ b/tests/DiscardableMemoryPoolTest.cpp @@ -14,7 +14,7 @@ DEF_TEST(DiscardableMemoryPool, reporter) { pool->setRAMBudget(3); REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); - SkAutoTDelete dm1(pool->create(100)); + std::unique_ptr dm1(pool->create(100)); REPORTER_ASSERT(reporter, dm1->data() != nullptr); REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed()); dm1->unlock(); @@ -22,7 +22,7 @@ DEF_TEST(DiscardableMemoryPool, reporter) { REPORTER_ASSERT(reporter, !dm1->lock()); - SkAutoTDelete dm2(pool->create(200)); + std::unique_ptr dm2(pool->create(200)); REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); pool->setRAMBudget(400); dm2->unlock(); diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index de305c7..3d2ee05 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -96,7 +96,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { return; } - SkAutoTDelete glCtx1 = glCtx0->createNew(); + std::unique_ptr glCtx1 = glCtx0->makeNew(); if (!glCtx1) { return; } @@ -107,13 +107,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { externalTexture.fID = 0; if (!context1) { - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } if (!glCtx1->gl()->hasExtension("EGL_KHR_image") || !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } @@ -127,12 +127,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { gpu1->createTestingOnlyBackendTexture(nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig)); if (!backendTexture1 || !backendTexture1->fID) { ERRORF(reporter, "Error creating texture for EGL Image"); - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } if (GR_GL_TEXTURE_2D != backendTexture1->fTarget) { ERRORF(reporter, "Expected backend texture to be 2D"); - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } @@ -140,7 +140,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { image = glCtx1->texture2DToEGLImage(backendTexture1->fID); if (GR_EGL_NO_IMAGE == image) { ERRORF(reporter, "Error creating EGL Image from texture"); - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } @@ -177,7 +177,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { context0->textureProvider()->wrapBackendTexture(externalDesc)); if (!externalTextureObj) { ERRORF(reporter, "Error wrapping external texture in GrTexture."); - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); return; } @@ -205,7 +205,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { test_copy_surface(reporter, context0, externalTextureObj.get(), pixels.get()); - cleanup(glCtx0, externalTexture.fID, glCtx1, context1, backendTexture1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); } #endif diff --git a/tests/ExifTest.cpp b/tests/ExifTest.cpp index 4aac487..4fed2b0 100644 --- a/tests/ExifTest.cpp +++ b/tests/ExifTest.cpp @@ -10,13 +10,13 @@ #include "Test.h" DEF_TEST(ExifOrientation, r) { - SkAutoTDelete stream(GetResourceAsStream("exif-orientation-2-ur.jpg")); + std::unique_ptr stream(GetResourceAsStream("exif-orientation-2-ur.jpg")); REPORTER_ASSERT(r, nullptr != stream); if (!stream) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, nullptr != codec); SkCodec::Origin origin = codec->getOrigin(); REPORTER_ASSERT(r, SkCodec::kTopRight_Origin == origin); diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp index 66908bc..efb1453 100644 --- a/tests/FontHostStreamTest.cpp +++ b/tests/FontHostStreamTest.cpp @@ -90,7 +90,7 @@ DEF_TEST(FontHostStream, reporter) { sk_sp typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(paint.getTypeface()) : SkTypeface::MakeDefault()); int ttcIndex; - SkAutoTDelete fontData(typeface->openStream(&ttcIndex)); + std::unique_ptr fontData(typeface->openStream(&ttcIndex)); sk_sp streamTypeface(SkTypeface::MakeFromStream(fontData.release())); SkFontDescriptor desc; diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp index 811b4b3..55c5244 100644 --- a/tests/FontHostTest.cpp +++ b/tests/FontHostTest.cpp @@ -138,18 +138,18 @@ static void test_fontstream(skiatest::Reporter* reporter, SkStream* stream, int } static void test_fontstream(skiatest::Reporter* reporter) { - SkAutoTDelete stream(GetResourceAsStream("/fonts/test.ttc")); + std::unique_ptr stream(GetResourceAsStream("/fonts/test.ttc")); if (!stream) { SkDebugf("Skipping FontHostTest::test_fontstream\n"); return; } - int count = SkFontStream::CountTTCEntries(stream); + int count = SkFontStream::CountTTCEntries(stream.get()); #ifdef DUMP_TTC_TABLES SkDebugf("CountTTCEntries %d\n", count); #endif for (int i = 0; i < count; ++i) { - test_fontstream(reporter, stream, i); + test_fontstream(reporter, stream.get(), i); } } diff --git a/tests/FrontBufferedStreamTest.cpp b/tests/FrontBufferedStreamTest.cpp index 445f0bf..a386274 100644 --- a/tests/FrontBufferedStreamTest.cpp +++ b/tests/FrontBufferedStreamTest.cpp @@ -56,70 +56,70 @@ static void test_incremental_buffering(skiatest::Reporter* reporter, size_t buff // deleted yet (and we only call const methods in it). SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); - test_hasLength(reporter, *bufferedStream.get(), *memStream); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); + test_hasLength(reporter, *bufferedStream, *memStream); // First, test reading less than the max buffer size. - test_read(reporter, bufferedStream, gAbcs, bufferSize / 2); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize / 2); // Now test rewinding back to the beginning and reading less than what was // already buffered. - test_rewind(reporter, bufferedStream, true); - test_read(reporter, bufferedStream, gAbcs, bufferSize / 4); + test_rewind(reporter, bufferedStream.get(), true); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize / 4); // Now test reading part of what was buffered, and buffering new data. - test_read(reporter, bufferedStream, gAbcs + bufferSize / 4, bufferSize / 2); + test_read(reporter, bufferedStream.get(), gAbcs + bufferSize / 4, bufferSize / 2); // Now test reading what was buffered, buffering new data, and // reading directly from the stream. - test_rewind(reporter, bufferedStream, true); - test_read(reporter, bufferedStream, gAbcs, bufferSize << 1); + test_rewind(reporter, bufferedStream.get(), true); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize << 1); // We have reached the end of the buffer, so rewinding will fail. // This test assumes that the stream is larger than the buffer; otherwise the // result of rewind should be true. - test_rewind(reporter, bufferedStream, false); + test_rewind(reporter, bufferedStream.get(), false); } static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) { SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); - test_hasLength(reporter, *bufferedStream.get(), *memStream); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); + test_hasLength(reporter, *bufferedStream, *memStream); // Read exactly the amount that fits in the buffer. - test_read(reporter, bufferedStream, gAbcs, bufferSize); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize); // Rewinding should succeed. - test_rewind(reporter, bufferedStream, true); + test_rewind(reporter, bufferedStream.get(), true); // Once again reading buffered info should succeed - test_read(reporter, bufferedStream, gAbcs, bufferSize); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize); // Read past the size of the buffer. At this point, we cannot return. - test_read(reporter, bufferedStream, gAbcs + memStream->getPosition(), 1); - test_rewind(reporter, bufferedStream, false); + test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), 1); + test_rewind(reporter, bufferedStream.get(), false); } static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) { SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false); - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); - test_hasLength(reporter, *bufferedStream.get(), *memStream); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); + test_hasLength(reporter, *bufferedStream, *memStream); // Skip half the buffer. bufferedStream->skip(bufferSize / 2); // Rewind, then read part of the buffer, which should have been read. - test_rewind(reporter, bufferedStream, true); - test_read(reporter, bufferedStream, gAbcs, bufferSize / 4); + test_rewind(reporter, bufferedStream.get(), true); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize / 4); // Now skip beyond the buffered piece, but still within the total buffer. bufferedStream->skip(bufferSize / 2); // Test that reading will still work. - test_read(reporter, bufferedStream, gAbcs + memStream->getPosition(), bufferSize / 4); + test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), bufferSize / 4); - test_rewind(reporter, bufferedStream, true); - test_read(reporter, bufferedStream, gAbcs, bufferSize); + test_rewind(reporter, bufferedStream.get(), true); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize); } // A custom class whose isAtEnd behaves the way Android's stream does - since it is an adaptor to a @@ -156,7 +156,7 @@ static void test_read_beyond_buffer(skiatest::Reporter* reporter, size_t bufferS new AndroidLikeMemoryStream((void*)gAbcs, bufferSize, false); // Create a buffer that matches the length of the stream. - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); test_hasLength(reporter, *bufferedStream.get(), *memStream); // Attempt to read one more than the bufferSize @@ -164,7 +164,7 @@ static void test_read_beyond_buffer(skiatest::Reporter* reporter, size_t bufferS test_rewind(reporter, bufferedStream.get(), true); // Ensure that the initial read did not invalidate the buffer. - test_read(reporter, bufferedStream, gAbcs, bufferSize); + test_read(reporter, bufferedStream.get(), gAbcs, bufferSize); } // Dummy stream that optionally has a length and/or position. Tests that FrontBufferedStream's @@ -203,7 +203,7 @@ static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) for (int hasPos = 0; hasPos <= 1; hasPos++) { LengthOptionalStream* stream = new LengthOptionalStream(SkToBool(hasLen), SkToBool(hasPos)); - SkAutoTDelete buffered(SkFrontBufferedStream::Create(stream, bufferSize)); + std::unique_ptr buffered(SkFrontBufferedStream::Create(stream, bufferSize)); test_hasLength(reporter, *buffered.get(), *stream); } } @@ -217,7 +217,7 @@ static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) // the stream it wraps. const size_t arbitraryOffset = 17; memStream->skip(arbitraryOffset); - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize)); // Since SkMemoryStream has a length, bufferedStream must also. REPORTER_ASSERT(reporter, bufferedStream->hasLength()); @@ -231,7 +231,7 @@ static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) // Importantly, the end should not have been reached until currentPosition == bufferedLength. while (currentPosition < bufferedLength) { REPORTER_ASSERT(reporter, !bufferedStream->isAtEnd()); - test_read(reporter, bufferedStream, gAbcs + arbitraryOffset + currentPosition, + test_read(reporter, bufferedStream.get(), gAbcs + arbitraryOffset + currentPosition, amountToRead); currentPosition = SkTMin(currentPosition + amountToRead, bufferedLength); REPORTER_ASSERT(reporter, memStream->getPosition() - arbitraryOffset == currentPosition); @@ -281,9 +281,9 @@ private: DEF_TEST(ShortFrontBufferedStream, reporter) { FailingStream* failingStream = new FailingStream; - SkAutoTDelete stream(SkFrontBufferedStream::Create(failingStream, 64)); + std::unique_ptr stream(SkFrontBufferedStream::Create(failingStream, 64)); // This will fail to create a codec. However, what we really want to test is that we // won't read past the end of the stream. - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); } diff --git a/tests/GifTest.cpp b/tests/GifTest.cpp index 51cd85d..4e8fa2b 100644 --- a/tests/GifTest.cpp +++ b/tests/GifTest.cpp @@ -191,14 +191,14 @@ DEF_TEST(Gif, reporter) { // Regression test for decoding a gif image with sampleSize of 4, which was // previously crashing. DEF_TEST(Gif_Sampled, r) { - SkAutoTDelete stream( + std::unique_ptr stream( new SkFILEStream(GetResourcePath("test640x479.gif").c_str())); REPORTER_ASSERT(r, stream->isValid()); if (!stream->isValid()) { return; } - SkAutoTDelete codec(SkAndroidCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkAndroidCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, codec); if (!codec) { return; diff --git a/tests/GpuSampleLocationsTest.cpp b/tests/GpuSampleLocationsTest.cpp index 2a57ccb..275951b 100644 --- a/tests/GpuSampleLocationsTest.cpp +++ b/tests/GpuSampleLocationsTest.cpp @@ -199,7 +199,7 @@ public: } private: - SkAutoTDelete fTestContext; + std::unique_ptr fTestContext; SamplePattern fSamplePattern; }; diff --git a/tests/GrMemoryPoolTest.cpp b/tests/GrMemoryPoolTest.cpp index 4a0a4c6..863574a 100644 --- a/tests/GrMemoryPoolTest.cpp +++ b/tests/GrMemoryPoolTest.cpp @@ -55,11 +55,11 @@ public: } private: - static SkAutoTDelete gPool; + static std::unique_ptr gPool; char fChar; }; -SkAutoTDelete A::gPool; +std::unique_ptr A::gPool; class B : public A { public: diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 5857625..f348ac4 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -295,8 +295,8 @@ DEF_TEST(Image_Serialize_Encoding_Failure, reporter) { picture->serialize(&wstream, serializers[i]); REPORTER_ASSERT(reporter, serializers[i]->didEncode()); - SkAutoTDelete rstream(wstream.detachAsStream()); - sk_sp deserialized(SkPicture::MakeFromStream(rstream)); + std::unique_ptr rstream(wstream.detachAsStream()); + sk_sp deserialized(SkPicture::MakeFromStream(rstream.get())); REPORTER_ASSERT(reporter, deserialized); REPORTER_ASSERT(reporter, deserialized->approximateOpCount() > 0); } diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp index 75086b6..382cd21 100644 --- a/tests/Matrix44Test.cpp +++ b/tests/Matrix44Test.cpp @@ -78,7 +78,7 @@ static bool bits_isonly(int value, int mask) { static void test_constructor(skiatest::Reporter* reporter) { // Allocate a matrix on the heap SkMatrix44* placeholderMatrix = new SkMatrix44(SkMatrix44::kUninitialized_Constructor); - SkAutoTDelete deleteMe(placeholderMatrix); + std::unique_ptr deleteMe(placeholderMatrix); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { diff --git a/tests/PDFDeflateWStreamTest.cpp b/tests/PDFDeflateWStreamTest.cpp index eedcaaf..11d2370 100644 --- a/tests/PDFDeflateWStreamTest.cpp +++ b/tests/PDFDeflateWStreamTest.cpp @@ -125,9 +125,8 @@ DEF_TEST(SkPDF_DeflateWStream, r) { } REPORTER_ASSERT(r, deflateWStream.bytesWritten() == size); } - SkAutoTDelete compressed( - dynamicMemoryWStream.detachAsStream()); - SkAutoTDelete decompressed(stream_inflate(r, compressed)); + std::unique_ptr compressed(dynamicMemoryWStream.detachAsStream()); + std::unique_ptr decompressed(stream_inflate(r, compressed.get())); if (!decompressed) { ERRORF(r, "Decompression failed."); diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp index e16be4c..3cbe7ef 100644 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -1074,7 +1074,7 @@ int tool_main(int argc, char** argv) { Iter iter; Test* test; while ((test = iter.next()) != nullptr) { - SkAutoTDelete owned(test); + std::unique_ptr owned(test); if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) { test->run(); } diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 8c7312e..8fdf92a 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -1087,8 +1087,8 @@ DEF_TEST(Picture_preserveCullRect, r) { SkDynamicMemoryWStream wstream; picture->serialize(&wstream); - SkAutoTDelete rstream(wstream.detachAsStream()); - sk_sp deserializedPicture(SkPicture::MakeFromStream(rstream)); + std::unique_ptr rstream(wstream.detachAsStream()); + sk_sp deserializedPicture(SkPicture::MakeFromStream(rstream.get())); REPORTER_ASSERT(r, deserializedPicture != nullptr); REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 82db03e..0e5e8ec 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -357,7 +357,7 @@ static void serialize_and_compare_typeface(sk_sp typeface, const cha // Serlialize picture and create its clone from stream. SkDynamicMemoryWStream stream; picture->serialize(&stream); - SkAutoTDelete inputStream(stream.detachAsStream()); + std::unique_ptr inputStream(stream.detachAsStream()); sk_sp loadedPicture(SkPicture::MakeFromStream(inputStream.get())); // Draw both original and clone picture and compare bitmaps -- they should be identical. @@ -648,8 +648,8 @@ DEF_TEST(Serialization, reporter) { static sk_sp copy_picture_via_serialization(SkPicture* src) { SkDynamicMemoryWStream wstream; src->serialize(&wstream); - SkAutoTDelete rstream(wstream.detachAsStream()); - return SkPicture::MakeFromStream(rstream); + std::unique_ptr rstream(wstream.detachAsStream()); + return SkPicture::MakeFromStream(rstream.get()); } struct AnnotationRec { diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp index f363fb7..615c7b4 100644 --- a/tests/SkResourceCacheTest.cpp +++ b/tests/SkResourceCacheTest.cpp @@ -38,7 +38,7 @@ DEF_TEST(BitmapCache_add_rect, reporter) { SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory(); SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); - SkAutoTDelete cache; + std::unique_ptr cache; if (factory) { cache.reset(new SkResourceCache(factory)); } else { @@ -55,18 +55,18 @@ DEF_TEST(BitmapCache_add_rect, reporter) { SkPixelRef* cachedPR = cachedBitmap.pixelRef(); // Wrong subset size - REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache)); - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache.get())); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache.get())); // Wrong offset value - REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache.get())); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache.get())); // Should not be in the cache - REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); + REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache.get())); - REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache.get())); // Should be in the cache, we just added it - REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache)); + REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache.get())); } #include "SkMipMap.h" diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp index 74e6055..ca750d1 100644 --- a/tests/StreamTest.cpp +++ b/tests/StreamTest.cpp @@ -61,7 +61,7 @@ static void test_filestreams(skiatest::Reporter* reporter, const char* tmpDir) { REPORTER_ASSERT(reporter, stream.isValid()); test_loop_stream(reporter, &stream, s, 26, 100); - SkAutoTDelete stream2(stream.duplicate()); + std::unique_ptr stream2(stream.duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } @@ -71,7 +71,7 @@ static void test_filestreams(skiatest::Reporter* reporter, const char* tmpDir) { REPORTER_ASSERT(reporter, stream.isValid()); test_loop_stream(reporter, &stream, s, 26, 100); - SkAutoTDelete stream2(stream.duplicate()); + std::unique_ptr stream2(stream.duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } } @@ -94,15 +94,15 @@ static void TestWStream(skiatest::Reporter* reporter) { } { - SkAutoTDelete stream(ds.detachAsStream()); + std::unique_ptr stream(ds.detachAsStream()); REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength()); REPORTER_ASSERT(reporter, ds.getOffset() == 0); test_loop_stream(reporter, stream.get(), s, 26, 100); - SkAutoTDelete stream2(stream->duplicate()); + std::unique_ptr stream2(stream->duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); - SkAutoTDelete stream3(stream->fork()); + std::unique_ptr stream3(stream->fork()); REPORTER_ASSERT(reporter, stream3->isAtEnd()); char tmp; size_t bytes = stream->read(&tmp, 1); @@ -124,11 +124,11 @@ static void TestWStream(skiatest::Reporter* reporter) { { // Test that this works after a snapshot. - SkAutoTDelete stream(ds.detachAsStream()); + std::unique_ptr stream(ds.detachAsStream()); REPORTER_ASSERT(reporter, ds.getOffset() == 0); test_loop_stream(reporter, stream.get(), s, 26, 100); - SkAutoTDelete stream2(stream->duplicate()); + std::unique_ptr stream2(stream->duplicate()); test_loop_stream(reporter, stream2.get(), s, 26, 100); } delete[] dst; @@ -234,12 +234,12 @@ static void test_peeking_front_buffered_stream(skiatest::Reporter* r, size_t bufferSize) { SkStream* dupe = original.duplicate(); REPORTER_ASSERT(r, dupe != nullptr); - SkAutoTDelete bufferedStream(SkFrontBufferedStream::Create(dupe, bufferSize)); + std::unique_ptr bufferedStream(SkFrontBufferedStream::Create(dupe, bufferSize)); REPORTER_ASSERT(r, bufferedStream != nullptr); size_t peeked = 0; for (size_t i = 1; !bufferedStream->isAtEnd(); i++) { - const size_t unpeekableBytes = compare_peek_to_read(r, bufferedStream, i); + const size_t unpeekableBytes = compare_peek_to_read(r, bufferedStream.get(), i); if (unpeekableBytes > 0) { // This could not have returned a number greater than i. REPORTER_ASSERT(r, unpeekableBytes <= i); @@ -359,7 +359,7 @@ DEF_TEST(StreamPeek_BlockMemoryStream, rep) { } dynamicMemoryWStream.write(buffer, size); } - SkAutoTDelete asset(dynamicMemoryWStream.detachAsStream()); + std::unique_ptr asset(dynamicMemoryWStream.detachAsStream()); sk_sp expected(SkData::MakeUninitialized(asset->getLength())); uint8_t* expectedPtr = static_cast(expected->writable_data()); valueSource.setSeed(kSeed); // reseed. @@ -369,7 +369,7 @@ DEF_TEST(StreamPeek_BlockMemoryStream, rep) { for (size_t i = 0; i < asset->getLength(); ++i) { expectedPtr[i] = valueSource.nextU() & 0xFF; } - stream_peek_test(rep, asset, expected.get()); + stream_peek_test(rep, asset.get(), expected.get()); } namespace { @@ -429,6 +429,6 @@ DEF_TEST(StreamCopy, reporter) { DEF_TEST(StreamEmptyStreamMemoryBase, r) { SkDynamicMemoryWStream tmp; - SkAutoTDelete asset(tmp.detachAsStream()); + std::unique_ptr asset(tmp.detachAsStream()); REPORTER_ASSERT(r, nullptr == asset->getMemoryBase()); } diff --git a/tests/YUVTest.cpp b/tests/YUVTest.cpp index d3b9167..913997b 100644 --- a/tests/YUVTest.cpp +++ b/tests/YUVTest.cpp @@ -15,11 +15,11 @@ static void codec_yuv(skiatest::Reporter* reporter, const char path[], SkISize expectedSizes[3]) { - SkAutoTDelete stream(GetResourceAsStream(path)); + std::unique_ptr stream(GetResourceAsStream(path)); if (!stream) { return; } - SkAutoTDelete codec(SkCodec::NewFromStream(stream.release())); + std::unique_ptr codec(SkCodec::NewFromStream(stream.release())); REPORTER_ASSERT(reporter, codec); if (!codec) { return; diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 9c12a67..dcca202 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -28,7 +28,7 @@ void SetResourcePath(const char* resource) { bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { SkString resourcePath = GetResourcePath(resource); sk_sp resourceData(SkData::MakeFromFileName(resourcePath.c_str())); - SkAutoTDelete gen(SkImageGenerator::NewFromEncoded(resourceData.get())); + std::unique_ptr gen(SkImageGenerator::NewFromEncoded(resourceData.get())); return gen && gen->tryGenerateBitmap(dst); } @@ -40,7 +40,7 @@ sk_sp GetResourceAsImage(const char* resource) { SkStreamAsset* GetResourceAsStream(const char* resource) { SkString resourcePath = GetResourcePath(resource); - SkAutoTDelete stream(new SkFILEStream(resourcePath.c_str())); + std::unique_ptr stream(new SkFILEStream(resourcePath.c_str())); if (!stream->isValid()) { SkDebugf("Resource %s not found.\n", resource); return nullptr; @@ -49,7 +49,7 @@ SkStreamAsset* GetResourceAsStream(const char* resource) { } sk_sp MakeResourceAsTypeface(const char* resource) { - SkAutoTDelete stream(GetResourceAsStream(resource)); + std::unique_ptr stream(GetResourceAsStream(resource)); if (!stream) { return nullptr; } diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 4c34b87..3ee5cdb 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -847,9 +847,9 @@ static SkBitmap* load_bitmap(const Json::Value& jsonBitmap, UrlDataManager& urlD sk_sp encoded(SkData::MakeWithoutCopy(data, size)); sk_sp image(SkImage::MakeFromEncoded(std::move(encoded), nullptr)); - SkAutoTDelete bitmap(new SkBitmap()); + std::unique_ptr bitmap(new SkBitmap()); if (nullptr != image) { - if (!image->asLegacyBitmap(bitmap, SkImage::kRW_LegacyBitmapMode)) { + if (!image->asLegacyBitmap(bitmap.get(), SkImage::kRW_LegacyBitmapMode)) { SkDebugf("image decode failed\n"); return nullptr; } @@ -2791,18 +2791,18 @@ SkDrawTextBlobCommand::SkDrawTextBlobCommand(sk_sp blob, SkScalar x, , fYPos(y) , fPaint(paint) { - SkAutoTDelete runsStr(new SkString); + std::unique_ptr runsStr(new SkString); fInfo.push(SkObjectParser::ScalarToString(x, "XPOS: ")); fInfo.push(SkObjectParser::ScalarToString(y, "YPOS: ")); fInfo.push(SkObjectParser::RectToString(fBlob->bounds(), "Bounds: ")); - fInfo.push(runsStr); + fInfo.push(runsStr.get()); fInfo.push(SkObjectParser::PaintToString(paint)); unsigned runs = 0; SkPaint runPaint(paint); SkTextBlobRunIterator iter(fBlob.get()); while (!iter.done()) { - SkAutoTDelete tmpStr(new SkString); + std::unique_ptr tmpStr(new SkString); tmpStr->printf("==== Run [%d] ====", runs++); fInfo.push(tmpStr.release()); diff --git a/tools/flags/SkCommonFlagsConfig.h b/tools/flags/SkCommonFlagsConfig.h index 9abf4cb..2b80397 100644 --- a/tools/flags/SkCommonFlagsConfig.h +++ b/tools/flags/SkCommonFlagsConfig.h @@ -75,7 +75,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig { }; #endif -typedef SkTArray, true> SkCommandLineConfigArray; +typedef SkTArray, true> SkCommandLineConfigArray; void ParseConfigs(const SkCommandLineFlags::StringArray& configList, SkCommandLineConfigArray* outResult); diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp index e38a245..b8a8930 100644 --- a/tools/get_images_from_skps.cpp +++ b/tools/get_images_from_skps.cpp @@ -54,7 +54,7 @@ struct Sniffer : public SkPixelSerializer { gSeen.add(digest); sk_sp data(SkData::MakeWithoutCopy(ptr, len)); - SkAutoTDelete codec(SkCodec::NewFromData(data)); + std::unique_ptr codec(SkCodec::NewFromData(data)); if (!codec) { // FIXME: This code is currently unreachable because we create an empty generator when // we fail to create a codec. diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp index 4f18994..79489f4 100644 --- a/tools/gpu/GrContextFactory.cpp +++ b/tools/gpu/GrContextFactory.cpp @@ -101,7 +101,7 @@ ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions op return ContextInfo(context.fBackend, context.fTestContext, context.fGrContext); } } - SkAutoTDelete testCtx; + std::unique_ptr testCtx; sk_sp grCtx; GrBackendContext backendContext = 0; sk_sp glInterface; diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h index d6baffc..54b6611 100644 --- a/tools/gpu/GrContextFactory.h +++ b/tools/gpu/GrContextFactory.h @@ -162,7 +162,7 @@ private: bool fAbandoned; }; SkTArray fContexts; - SkAutoTDelete fSentinelGLContext; + std::unique_ptr fSentinelGLContext; const GrContextOptions fGlobalOptions; }; } // namespace sk_gpu_test diff --git a/tools/gpu/TestContext.h b/tools/gpu/TestContext.h index 8722a33..ecb61e3 100644 --- a/tools/gpu/TestContext.h +++ b/tools/gpu/TestContext.h @@ -28,10 +28,10 @@ public: virtual bool isValid() const = 0; bool fenceSyncSupport() const { return fFenceSync != nullptr; } - FenceSync* fenceSync() { SkASSERT(fFenceSync); return fFenceSync; } + FenceSync* fenceSync() { SkASSERT(fFenceSync); return fFenceSync.get(); } bool gpuTimingSupport() const { return fGpuTimer != nullptr; } - GpuTimer* gpuTimer() const { SkASSERT(fGpuTimer); return fGpuTimer; } + GpuTimer* gpuTimer() const { SkASSERT(fGpuTimer); return fGpuTimer.get(); } bool getMaxGpuFrameLag(int *maxFrameLag) const { if (!fFenceSync) { @@ -81,8 +81,8 @@ public: virtual void finish() = 0; protected: - SkAutoTDelete fFenceSync; - SkAutoTDelete fGpuTimer; + std::unique_ptr fFenceSync; + std::unique_ptr fGpuTimer; TestContext(); diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp index 20a9908..e6d0e40 100644 --- a/tools/gpu/gl/GLTestContext.cpp +++ b/tools/gpu/gl/GLTestContext.cpp @@ -14,7 +14,7 @@ namespace { class GLFenceSync : public sk_gpu_test::FenceSync { public: - static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*); + static std::unique_ptr MakeIfSupported(const sk_gpu_test::GLTestContext*); sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override; bool waitFence(sk_gpu_test::PlatformFence fence) const override; @@ -43,8 +43,8 @@ private: typedef FenceSync INHERITED; }; -GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) { - SkAutoTDelete ret; +std::unique_ptr GLFenceSync::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) { + std::unique_ptr ret; if (kGL_GrGLStandard == ctx->gl()->fStandard) { if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) { return nullptr; @@ -56,7 +56,10 @@ GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ct } ret.reset(new GLFenceSync(ctx, "APPLE")); } - return ret->validate() ? ret.release() : nullptr; + if (!ret->validate()) { + ret = nullptr; + } + return ret; } GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) { @@ -82,7 +85,7 @@ void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const { class GLGpuTimer : public sk_gpu_test::GpuTimer { public: - static GLGpuTimer* CreateIfSupported(const sk_gpu_test::GLTestContext*); + static std::unique_ptr MakeIfSupported(const sk_gpu_test::GLTestContext*); QueryStatus checkQueryStatus(sk_gpu_test::PlatformTimerQuery) override; std::chrono::nanoseconds getTimeElapsed(sk_gpu_test::PlatformTimerQuery) override; @@ -121,8 +124,8 @@ private: typedef sk_gpu_test::GpuTimer INHERITED; }; -GLGpuTimer* GLGpuTimer::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) { - SkAutoTDelete ret; +std::unique_ptr GLGpuTimer::MakeIfSupported(const sk_gpu_test::GLTestContext* ctx) { + std::unique_ptr ret; const GrGLInterface* gl = ctx->gl(); if (gl->fExtensions.has("GL_EXT_disjoint_timer_query")) { ret.reset(new GLGpuTimer(true, ctx, "EXT")); @@ -132,7 +135,10 @@ GLGpuTimer* GLGpuTimer::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) } else if (gl->fExtensions.has("GL_EXT_timer_query")) { ret.reset(new GLGpuTimer(false, ctx, "EXT")); } - return ret && ret->validate() ? ret.release() : nullptr; + if (ret && !ret->validate()) { + ret = nullptr; + } + return ret; } GLGpuTimer::GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext* ctx, const char* ext) @@ -219,11 +225,11 @@ GLTestContext::~GLTestContext() { SkASSERT(nullptr == fGL.get()); } -void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) { +void GLTestContext::init(const GrGLInterface* gl, std::unique_ptr fenceSync) { SkASSERT(!fGL.get()); fGL.reset(gl); - fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); - fGpuTimer = GLGpuTimer::CreateIfSupported(this); + fFenceSync = fenceSync ? std::move(fenceSync) : GLFenceSync::MakeIfSupported(this); + fGpuTimer = GLGpuTimer::MakeIfSupported(this); } void GLTestContext::teardown() { diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h index 0cd9762..a2b0455 100644 --- a/tools/gpu/gl/GLTestContext.h +++ b/tools/gpu/gl/GLTestContext.h @@ -57,7 +57,7 @@ public: * Creates a new GL context of the same type and makes the returned context current * (if not null). */ - virtual GLTestContext *createNew() const { return nullptr; } + virtual std::unique_ptr makeNew() const { return nullptr; } template void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...), @@ -81,7 +81,7 @@ protected: /* * Methods that sublcasses must call from their constructors and destructors. */ - void init(const GrGLInterface *, FenceSync* = nullptr); + void init(const GrGLInterface *, std::unique_ptr = nullptr); void teardown() override; diff --git a/tools/gpu/gl/angle/GLTestContext_angle.cpp b/tools/gpu/gl/angle/GLTestContext_angle.cpp index 449e14c..aa55bf3 100644 --- a/tools/gpu/gl/angle/GLTestContext_angle.cpp +++ b/tools/gpu/gl/angle/GLTestContext_angle.cpp @@ -82,7 +82,7 @@ public: GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; void destroyEGLImage(GrEGLImage) const override; GrGLuint eglImageToExternalTexture(GrEGLImage) const override; - sk_gpu_test::GLTestContext* createNew() const override; + std::unique_ptr makeNew() const override; private: void destroyGLContext(); @@ -216,8 +216,9 @@ GrGLuint ANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const { return texID; } -sk_gpu_test::GLTestContext* ANGLEGLContext::createNew() const { - sk_gpu_test::GLTestContext* ctx = sk_gpu_test::CreateANGLETestContext(fType, fVersion); +std::unique_ptr ANGLEGLContext::makeNew() const { + std::unique_ptr ctx = + sk_gpu_test::MakeANGLETestContext(fType, fVersion); if (ctx) { ctx->makeCurrent(); } @@ -286,12 +287,10 @@ const GrGLInterface* CreateANGLEGLInterface() { return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); } -GLTestContext* CreateANGLETestContext(ANGLEBackend type, - ANGLEContextVersion version) { - ANGLEGLContext* ctx = new ANGLEGLContext(type, version); +std::unique_ptr MakeANGLETestContext(ANGLEBackend type, ANGLEContextVersion version){ + std::unique_ptr ctx(new ANGLEGLContext(type, version)); if (!ctx->isValid()) { - delete ctx; - return NULL; + return nullptr; } return ctx; } diff --git a/tools/gpu/gl/angle/GLTestContext_angle.h b/tools/gpu/gl/angle/GLTestContext_angle.h index 0da747f..9314710 100644 --- a/tools/gpu/gl/angle/GLTestContext_angle.h +++ b/tools/gpu/gl/angle/GLTestContext_angle.h @@ -30,7 +30,7 @@ enum class ANGLEContextVersion { }; /** Creates a GLTestContext backed by ANGLE. */ -GLTestContext* CreateANGLETestContext(ANGLEBackend, ANGLEContextVersion); +std::unique_ptr MakeANGLETestContext(ANGLEBackend, ANGLEContextVersion); } // namespace sk_gpu_test #endif diff --git a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp index 06bd70f..b2517f0 100644 --- a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp +++ b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp @@ -22,7 +22,7 @@ namespace { // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_sync. class EGLFenceSync : public sk_gpu_test::FenceSync { public: - static EGLFenceSync* CreateIfSupported(EGLDisplay); + static std::unique_ptr MakeIfSupported(EGLDisplay); sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override; bool waitFence(sk_gpu_test::PlatformFence fence) const override; @@ -44,7 +44,7 @@ public: GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; void destroyEGLImage(GrEGLImage) const override; GrGLuint eglImageToExternalTexture(GrEGLImage) const override; - sk_gpu_test::GLTestContext* createNew() const override; + std::unique_ptr makeNew() const override; private: void destroyGLContext(); @@ -180,7 +180,7 @@ EGLGLTestContext::EGLGLTestContext(GrGLStandard forcedGpuAPI) continue; } - this->init(gl.release(), EGLFenceSync::CreateIfSupported(fDisplay)); + this->init(gl.release(), EGLFenceSync::MakeIfSupported(fDisplay)); break; } } @@ -255,8 +255,8 @@ GrGLuint EGLGLTestContext::eglImageToExternalTexture(GrEGLImage image) const { return texID; } -sk_gpu_test::GLTestContext* EGLGLTestContext::createNew() const { - sk_gpu_test::GLTestContext* ctx = new EGLGLTestContext(this->gl()->fStandard); +std::unique_ptr EGLGLTestContext::makeNew() const { + std::unique_ptr ctx(new EGLGLTestContext(this->gl()->fStandard)); if (ctx) { ctx->makeCurrent(); } @@ -294,11 +294,11 @@ static bool supports_egl_extension(EGLDisplay display, const char* extension) { return false; } -EGLFenceSync* EGLFenceSync::CreateIfSupported(EGLDisplay display) { +std::unique_ptr EGLFenceSync::MakeIfSupported(EGLDisplay display) { if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { return nullptr; } - return new EGLFenceSync(display); + return std::unique_ptr(new EGLFenceSync(display)); } sk_gpu_test::PlatformFence EGLFenceSync::insertFence() const { diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp index 92bef7c..502dea8 100644 --- a/tools/gpu/vk/VkTestContext.cpp +++ b/tools/gpu/vk/VkTestContext.cpp @@ -134,8 +134,8 @@ protected: private: VkTestContextImpl(sk_sp backendContext) : VkTestContext(std::move(backendContext)) { - fFenceSync = new VkFenceSync(sk_ref_sp(fVk->fInterface.get()), fVk->fDevice, fVk->fQueue, - fVk->fGraphicsQueueIndex); + fFenceSync.reset(new VkFenceSync(fVk->fInterface, fVk->fDevice, fVk->fQueue, + fVk->fGraphicsQueueIndex)); } void onPlatformMakeCurrent() const override {} diff --git a/tools/skdiff/skdiff_utils.cpp b/tools/skdiff/skdiff_utils.cpp index 609d75d..f788ec8 100644 --- a/tools/skdiff/skdiff_utils.cpp +++ b/tools/skdiff/skdiff_utils.cpp @@ -34,7 +34,7 @@ sk_sp read_file(const char* file_path) { } bool get_bitmap(sk_sp fileBits, DiffResource& resource, bool sizeOnly) { - SkAutoTDelete codec(SkCodec::NewFromData(fileBits)); + std::unique_ptr codec(SkCodec::NewFromData(fileBits)); if (!codec) { SkDebugf("ERROR: could not create codec for <%s>\n", resource.fFullPath.c_str()); resource.fStatus = DiffResource::kCouldNotDecode_Status; diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index 9da9f0f..134fdf0 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -55,7 +55,7 @@ SkBitmap* Request::getBitmapFromCanvas(SkCanvas* canvas) { sk_sp Request::writeCanvasToPng(SkCanvas* canvas) { // capture pixels - SkAutoTDelete bmp(this->getBitmapFromCanvas(canvas)); + std::unique_ptr bmp(this->getBitmapFromCanvas(canvas)); SkASSERT(bmp); // Convert to format suitable for PNG output @@ -302,7 +302,7 @@ sk_sp Request::getJsonInfo(int n) { SkColor Request::getPixel(int x, int y) { SkCanvas* canvas = this->getCanvas(); canvas->flush(); - SkAutoTDelete bitmap(this->getBitmapFromCanvas(canvas)); + std::unique_ptr bitmap(this->getBitmapFromCanvas(canvas)); SkASSERT(bitmap); // Convert to format suitable for inspection diff --git a/tools/viewer/ImageSlide.cpp b/tools/viewer/ImageSlide.cpp index e70f618..0ffd4ea 100644 --- a/tools/viewer/ImageSlide.cpp +++ b/tools/viewer/ImageSlide.cpp @@ -37,7 +37,7 @@ void ImageSlide::draw(SkCanvas* canvas) { void ImageSlide::load(SkScalar, SkScalar) { sk_sp encoded = SkData::MakeFromFileName(fPath.c_str()); - SkAutoTDelete codec(SkCodec::NewFromData(encoded)); + std::unique_ptr codec(SkCodec::NewFromData(encoded)); if (!codec) { return; } diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp index 739882d..d92b801 100644 --- a/tools/viewer/Viewer.cpp +++ b/tools/viewer/Viewer.cpp @@ -252,7 +252,7 @@ void Viewer::initSlides() { const skiagm::GMRegistry* gms(skiagm::GMRegistry::Head()); while (gms) { - SkAutoTDelete gm(gms->factory()(nullptr)); + std::unique_ptr gm(gms->factory()(nullptr)); if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) { sk_sp slide(new GMSlide(gm.release())); diff --git a/tools/visualize_color_gamut.cpp b/tools/visualize_color_gamut.cpp index 9e9ed96..ee4c2a5 100644 --- a/tools/visualize_color_gamut.cpp +++ b/tools/visualize_color_gamut.cpp @@ -124,7 +124,7 @@ int main(int argc, char** argv) { SkDebugf("Cannot find input image.\n"); return -1; } - SkAutoTDelete codec(SkCodec::NewFromData(data)); + std::unique_ptr codec(SkCodec::NewFromData(data)); if (!codec) { SkDebugf("Invalid input image.\n"); return -1; -- 2.7.4