diff options
author | bungeman <bungeman@google.com> | 2016-06-09 08:01:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-06-09 08:01:03 -0700 |
commit | 06ca8ec87cf6fab57cadd043a5ac18c4154a4129 (patch) | |
tree | 95e7eaaaf3f42ce550332277c431e3ec119446f4 /tests | |
parent | 897a8e38879643d81a64d2bb6bed4e22af982aa4 (diff) |
sk_sp for Ganesh.
Convert use of GrFragmentProcessor, GrGeometryProcessor, and
GrXPFactory to sk_sp. This clarifies ownership and should
reduce reference count churn by moving ownership.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2041113004
Review-Url: https://codereview.chromium.org/2041113004
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GLProgramsTest.cpp | 67 | ||||
-rw-r--r-- | tests/GpuColorFilterTest.cpp | 2 | ||||
-rw-r--r-- | tests/GrPorterDuffTest.cpp | 6 | ||||
-rw-r--r-- | tests/TessellatingPathRendererTests.cpp | 2 |
4 files changed, 37 insertions, 40 deletions
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 2470061257..7ce71c6637 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -66,8 +66,8 @@ private: class BigKeyProcessor : public GrFragmentProcessor { public: - static GrFragmentProcessor* Create() { - return new BigKeyProcessor; + static sk_sp<GrFragmentProcessor> Make() { + return sk_sp<GrFragmentProcessor>(new BigKeyProcessor); } const char* name() const override { return "Big Ole Key"; } @@ -94,16 +94,16 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); -const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { - return BigKeyProcessor::Create(); +sk_sp<GrFragmentProcessor> BigKeyProcessor::TestCreate(GrProcessorTestData*) { + return BigKeyProcessor::Make(); } ////////////////////////////////////////////////////////////////////////////// class BlockInputFragmentProcessor : public GrFragmentProcessor { public: - static GrFragmentProcessor* Create(const GrFragmentProcessor* fp) { - return new BlockInputFragmentProcessor(fp); + static sk_sp<GrFragmentProcessor> Make(sk_sp<GrFragmentProcessor> fp) { + return sk_sp<GrFragmentProcessor>(new BlockInputFragmentProcessor(fp)); } const char* name() const override { return "Block Input"; } @@ -121,9 +121,9 @@ private: typedef GrGLSLFragmentProcessor INHERITED; }; - BlockInputFragmentProcessor(const GrFragmentProcessor* child) { + BlockInputFragmentProcessor(sk_sp<GrFragmentProcessor> child) { this->initClassID<BlockInputFragmentProcessor>(); - this->registerChildProcessor(child); + this->registerChildProcessor(std::move(child)); } void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override {} @@ -185,13 +185,13 @@ static sk_sp<GrDrawContext> random_draw_context(GrContext* context, } static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) { - SkAutoTUnref<const GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Create(d)); + sk_sp<GrXPFactory> xpf(GrProcessorTestFactory<GrXPFactory>::Make(d)); SkASSERT(xpf); - pipelineBuilder->setXPFactory(xpf.get()); + pipelineBuilder->setXPFactory(std::move(xpf)); } -static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d, - int minLevels, int maxLevels) { +static sk_sp<GrFragmentProcessor> create_random_proc_tree(GrProcessorTestData* d, + int minLevels, int maxLevels) { SkASSERT(1 <= minLevels); SkASSERT(minLevels <= maxLevels); @@ -202,14 +202,13 @@ static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d if (1 == minLevels) { bool terminate = (1 == maxLevels) || (d->fRandom->nextF() < terminateProbability); if (terminate) { - const GrFragmentProcessor* fp; + sk_sp<GrFragmentProcessor> fp; while (true) { - fp = GrProcessorTestFactory<GrFragmentProcessor>::Create(d); + fp = GrProcessorTestFactory<GrFragmentProcessor>::Make(d); SkASSERT(fp); if (0 == fp->numChildProcessors()) { break; } - fp->unref(); } return fp; } @@ -220,18 +219,18 @@ static const GrFragmentProcessor* create_random_proc_tree(GrProcessorTestData* d if (minLevels > 1) { --minLevels; } - SkAutoTUnref<const GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLevels, - maxLevels - 1)); - SkAutoTUnref<const GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, - maxLevels - 1)); + sk_sp<GrFragmentProcessor> minLevelsChild(create_random_proc_tree(d, minLevels, maxLevels - 1)); + sk_sp<GrFragmentProcessor> otherChild(create_random_proc_tree(d, 1, maxLevels - 1)); SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); - const GrFragmentProcessor* fp; + sk_sp<GrFragmentProcessor> fp; if (d->fRandom->nextF() < 0.5f) { - fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(minLevelsChild, otherChild, mode); + fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(minLevelsChild), + std::move(otherChild), mode); SkASSERT(fp); } else { - fp = GrXfermodeFragmentProcessor::CreateFromTwoProcessors(otherChild, minLevelsChild, mode); + fp = GrXfermodeFragmentProcessor::MakeFromTwoProcessors(std::move(otherChild), + std::move(minLevelsChild), mode); SkASSERT(fp); } return fp; @@ -245,23 +244,21 @@ static void set_random_color_coverage_stages(GrPipelineBuilder* pipelineBuilder, // A full tree with 5 levels (31 nodes) may exceed the max allowed length of the gl // processor key; maxTreeLevels should be a number from 1 to 4 inclusive. const int maxTreeLevels = 4; - SkAutoTUnref<const GrFragmentProcessor> fp( - create_random_proc_tree(d, 2, maxTreeLevels)); - pipelineBuilder->addColorFragmentProcessor(fp); + sk_sp<GrFragmentProcessor> fp(create_random_proc_tree(d, 2, maxTreeLevels)); + pipelineBuilder->addColorFragmentProcessor(std::move(fp)); } else { int numProcs = d->fRandom->nextULessThan(maxStages + 1); int numColorProcs = d->fRandom->nextULessThan(numProcs + 1); for (int s = 0; s < numProcs;) { - SkAutoTUnref<const GrFragmentProcessor> fp( - GrProcessorTestFactory<GrFragmentProcessor>::Create(d)); + sk_sp<GrFragmentProcessor> fp(GrProcessorTestFactory<GrFragmentProcessor>::Make(d)); SkASSERT(fp); // finally add the stage to the correct pipeline in the drawstate if (s < numColorProcs) { - pipelineBuilder->addColorFragmentProcessor(fp); + pipelineBuilder->addColorFragmentProcessor(std::move(fp)); } else { - pipelineBuilder->addCoverageFragmentProcessor(fp); + pipelineBuilder->addCoverageFragmentProcessor(std::move(fp)); } ++s; } @@ -385,13 +382,13 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) { GrProcessorTestData ptd(&random, context, context->caps(), drawContext.get(), dummyTextures); GrPipelineBuilder builder; - builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); + builder.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); - SkAutoTUnref<const GrFragmentProcessor> fp( - GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd)); - SkAutoTUnref<const GrFragmentProcessor> blockFP( - BlockInputFragmentProcessor::Create(fp)); - builder.addColorFragmentProcessor(blockFP); + sk_sp<GrFragmentProcessor> fp( + GrProcessorTestFactory<GrFragmentProcessor>::MakeIdx(i, &ptd)); + sk_sp<GrFragmentProcessor> blockFP( + BlockInputFragmentProcessor::Make(std::move(fp))); + builder.addColorFragmentProcessor(std::move(blockFP)); drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch); drawingManager->flush(); diff --git a/tests/GpuColorFilterTest.cpp b/tests/GpuColorFilterTest.cpp index b18af18b1c..0fbce6c562 100644 --- a/tests/GpuColorFilterTest.cpp +++ b/tests/GpuColorFilterTest.cpp @@ -99,7 +99,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, ctxInfo) { for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) { const GetConstantComponentTestCase& test = filterTests[i]; auto cf(SkColorFilter::MakeModeFilter(test.filterColor, test.filterMode)); - SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(ctxInfo.grContext())); + sk_sp<GrFragmentProcessor> fp(cf->asFragmentProcessor(ctxInfo.grContext())); REPORTER_ASSERT(reporter, fp); GrInvariantOutput inout(test.inputColor, static_cast<GrColorComponentFlags>(test.inputComponents), diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index a5ac868023..71db9939b8 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -69,7 +69,7 @@ public: struct XPInfo { XPInfo(skiatest::Reporter* reporter, SkXfermode::Mode xfermode, const GrCaps& caps, const GrPipelineOptimizations& optimizations) { - SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode)); + sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(xfermode)); SkAutoTUnref<GrXferProcessor> xp( xpf->createXferProcessor(optimizations, false, nullptr, caps)); TEST_ASSERT(!xpf->willNeedDstTexture(caps, optimizations)); @@ -1121,7 +1121,7 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags()); SkASSERT(covPOI.isFourChannelOutput()); - SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode)); + sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(SkXfermode::kSrcOver_Mode)); TEST_ASSERT(!xpf->willNeedDstTexture(caps, opts)); SkAutoTUnref<GrXferProcessor> xp( @@ -1198,7 +1198,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { } for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) { SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m); - SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(xfermode)); + sk_sp<GrXPFactory> xpf(GrPorterDuffXPFactory::Make(xfermode)); GrXferProcessor::DstTexture* dstTexture = xpf->willNeedDstTexture(caps, optimizations) ? &fakeDstTexture : 0; SkAutoTUnref<GrXferProcessor> xp( diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp index 6d562ea24d..51ccef9329 100644 --- a/tests/TessellatingPathRendererTests.cpp +++ b/tests/TessellatingPathRendererTests.cpp @@ -236,7 +236,7 @@ static void test_path(GrDrawContext* drawContext, GrResourceProvider* rp, const GrTessellatingPathRenderer tess; GrPaint paint; - paint.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); + paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); GrNoClip noClip; GrStyle style(SkStrokeRec::kFill_InitStyle); |