From 87f15c8ff11ad2bfb0c6711d7837020a50fe7fb8 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Fri, 20 May 2016 11:14:33 -0700 Subject: [PATCH] Retract GrRenderTarget from GrTestTarget Split out of: https://codereview.chromium.org/1988923002/ (Declassify GrClipMaskManager and Remove GrRenderTarget and GrDrawTarget from GrPipelineBuilder) GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2004433002 Review-Url: https://codereview.chromium.org/2004433002 --- bench/GLBench.cpp | 2 ++ gm/imagefromyuvtextures.cpp | 1 + gm/rectangletexture.cpp | 2 ++ include/gpu/GrContext.h | 5 ++- include/gpu/GrDrawContext.h | 1 + tests/TessellatingPathRendererTests.cpp | 58 ++++++++++++++++----------------- tools/gpu/GrTest.cpp | 28 +++------------- tools/gpu/GrTest.h | 10 +++--- 8 files changed, 46 insertions(+), 61 deletions(-) diff --git a/bench/GLBench.cpp b/bench/GLBench.cpp index 524bfe1..8cf41c2 100644 --- a/bench/GLBench.cpp +++ b/bench/GLBench.cpp @@ -8,7 +8,9 @@ #include "GLBench.h" #if SK_SUPPORT_GPU +#include "GrGpu.h" #include "GrTest.h" +#include "gl/GrGLContext.h" #include const GrGLContext* GLBench::getGLContext(SkCanvas* canvas) { diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index 5fa55da..3d25a0b 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -12,6 +12,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrGpu.h" #include "GrTest.h" #include "SkBitmap.h" #include "SkGradientShader.h" diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp index 0990487..3208c0d 100644 --- a/gm/rectangletexture.cpp +++ b/gm/rectangletexture.cpp @@ -12,7 +12,9 @@ #if SK_SUPPORT_GPU #include "GrContext.h" +#include "GrGpu.h" #include "GrTest.h" +#include "gl/GrGLContext.h" #include "SkBitmap.h" #include "SkGradientShader.h" #include "SkImage.h" diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 86c9fa9..4e2546b 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -27,7 +27,6 @@ struct GrContextOptions; class GrContextThreadSafeProxy; class GrDrawingManager; class GrDrawContext; -class GrDrawTarget; class GrFragmentProcessor; class GrGpu; class GrIndexBuffer; @@ -354,8 +353,8 @@ public: const GrResourceProvider* resourceProvider() const { return fResourceProvider; } GrResourceCache* getResourceCache() { return fResourceCache; } - // Called by tests that draw directly to the context via GrDrawTarget - void getTestTarget(GrTestTarget*, GrRenderTarget* rt); + // Called by tests that draw directly to the context via GrDrawContext + void getTestTarget(GrTestTarget*, sk_sp); /** Reset GPU stats */ void resetGpuStats() const ; diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index 0e7211d..3778b72 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -296,6 +296,7 @@ private: friend class GrStencilAndCoverTextContext; // for access to drawBatch friend class GrDrawingManager; // for ctor friend class GrDrawContextPriv; + friend class GrTestTarget; // for access to getDrawTarget bool drawFilledDRRect(const GrClip& clip, const GrPaint& paint, diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp index a3eb489..22779c2 100644 --- a/tests/TessellatingPathRendererTests.cpp +++ b/tests/TessellatingPathRendererTests.cpp @@ -232,13 +232,13 @@ static SkPath create_path_15() { return path; } -static void test_path(GrDrawTarget* dt, GrRenderTarget* rt, GrResourceProvider* rp, - const SkPath& path) { +static void test_path(GrDrawTarget* dt, GrDrawContext* drawContext, + GrResourceProvider* rp, const SkPath& path) { GrTessellatingPathRenderer tess; GrPipelineBuilder pipelineBuilder; pipelineBuilder.setXPFactory( GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref(); - pipelineBuilder.setRenderTarget(rt); + pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget()); GrNoClip noClip; GrStyle style(SkStrokeRec::kFill_InitStyle); GrPathRenderer::DrawPathArgs args; @@ -255,35 +255,35 @@ static void test_path(GrDrawTarget* dt, GrRenderTarget* rt, GrResourceProvider* } DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) { - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = 800; - desc.fHeight = 800; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fOrigin = kTopLeft_GrSurfaceOrigin; - SkAutoTUnref texture( - ctxInfo.grContext()->textureProvider()->createApproxTexture(desc)); + sk_sp drawContext(ctxInfo.grContext()->newDrawContext(SkBackingFit::kApprox, + 800, 800, + kSkia8888_GrPixelConfig, + 0, + kTopLeft_GrSurfaceOrigin)); + if (!drawContext) { + return; + } + GrTestTarget tt; - GrRenderTarget* rt = texture->asRenderTarget(); - ctxInfo.grContext()->getTestTarget(&tt, rt); + ctxInfo.grContext()->getTestTarget(&tt, drawContext); GrDrawTarget* dt = tt.target(); GrResourceProvider* rp = tt.resourceProvider(); - test_path(dt, rt, rp, create_path_0()); - test_path(dt, rt, rp, create_path_1()); - test_path(dt, rt, rp, create_path_2()); - test_path(dt, rt, rp, create_path_3()); - test_path(dt, rt, rp, create_path_4()); - test_path(dt, rt, rp, create_path_5()); - test_path(dt, rt, rp, create_path_6()); - test_path(dt, rt, rp, create_path_7()); - test_path(dt, rt, rp, create_path_8()); - test_path(dt, rt, rp, create_path_9()); - test_path(dt, rt, rp, create_path_10()); - test_path(dt, rt, rp, create_path_11()); - test_path(dt, rt, rp, create_path_12()); - test_path(dt, rt, rp, create_path_13()); - test_path(dt, rt, rp, create_path_14()); - test_path(dt, rt, rp, create_path_15()); + test_path(dt, drawContext.get(), rp, create_path_0()); + test_path(dt, drawContext.get(), rp, create_path_1()); + test_path(dt, drawContext.get(), rp, create_path_2()); + test_path(dt, drawContext.get(), rp, create_path_3()); + test_path(dt, drawContext.get(), rp, create_path_4()); + test_path(dt, drawContext.get(), rp, create_path_5()); + test_path(dt, drawContext.get(), rp, create_path_6()); + test_path(dt, drawContext.get(), rp, create_path_7()); + test_path(dt, drawContext.get(), rp, create_path_8()); + test_path(dt, drawContext.get(), rp, create_path_9()); + test_path(dt, drawContext.get(), rp, create_path_10()); + test_path(dt, drawContext.get(), rp, create_path_11()); + test_path(dt, drawContext.get(), rp, create_path_12()); + test_path(dt, drawContext.get(), rp, create_path_13()); + test_path(dt, drawContext.get(), rp, create_path_14()); + test_path(dt, drawContext.get(), rp, create_path_15()); } #endif diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index fc2a9e1..be539ca 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -52,39 +52,21 @@ void SetupAlwaysEvictAtlas(GrContext* context) { } }; -void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, GrRenderTarget* rt) { +void GrTestTarget::init(GrContext* ctx, sk_sp drawContext) { SkASSERT(!fContext); fContext.reset(SkRef(ctx)); - fDrawTarget.reset(SkRef(target)); - fRenderTarget.reset(SkRef(rt)); + fDrawContext = drawContext; } -void GrContext::getTestTarget(GrTestTarget* tar, GrRenderTarget* rt) { +void GrContext::getTestTarget(GrTestTarget* tar, sk_sp drawContext) { this->flush(); + SkASSERT(drawContext); // We could create a proxy GrDrawTarget that passes through to fGpu until ~GrTextTarget() and // then disconnects. This would help prevent test writers from mixing using the returned // GrDrawTarget and regular drawing. We could also assert or fail in GrContext drawing methods // until ~GrTestTarget(). - if (!rt) { - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = 32; - desc.fHeight = 32; - desc.fConfig = kRGBA_8888_GrPixelConfig; - desc.fSampleCnt = 0; - - SkAutoTUnref texture(this->textureProvider()->createTexture( - desc, SkBudgeted::kNo, nullptr, 0)); - if (nullptr == texture) { - return; - } - SkASSERT(nullptr != texture->asRenderTarget()); - rt = texture->asRenderTarget(); - } - - SkAutoTUnref dt(fDrawingManager->newDrawTarget(rt)); - tar->init(this, dt, rt); + tar->init(this, std::move(drawContext)); } void GrContext::setTextBlobCacheLimit_ForTesting(size_t bytes) { diff --git a/tools/gpu/GrTest.h b/tools/gpu/GrTest.h index 53aaac3..217efe6 100644 --- a/tools/gpu/GrTest.h +++ b/tools/gpu/GrTest.h @@ -9,8 +9,7 @@ #define GrTest_DEFINED #include "GrContext.h" -#include "GrDrawTarget.h" -#include "gl/GrGLContext.h" +#include "GrDrawContext.h" namespace GrTest { /** @@ -28,15 +27,14 @@ class GrTestTarget { public: GrTestTarget() {}; - void init(GrContext*, GrDrawTarget*, GrRenderTarget*); + void init(GrContext*, sk_sp); - GrDrawTarget* target() { return fDrawTarget.get(); } + GrDrawTarget* target() { return fDrawContext->getDrawTarget(); } GrResourceProvider* resourceProvider() { return fContext->resourceProvider(); } private: SkAutoTUnref fContext; - SkAutoTUnref fDrawTarget; - SkAutoTUnref fRenderTarget; + sk_sp fDrawContext; }; #endif -- 2.7.4