Optionally pass rendertarget to getTestTarget
This shouldn't really make any difference but allocating and holding on to a GrRenderTarget for each test target generates image differences for Mali GPUs. This CL allows an existing render target to be used for the test target.
TBR=bsalomon@google.com
Review URL: https://codereview.chromium.org/1447113002
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp
index 5313919..58d7fef 100644
--- a/gm/beziereffects.cpp
+++ b/gm/beziereffects.cpp
@@ -157,7 +157,7 @@
SkAutoTUnref<GrGeometryProcessor> gp;
{ // scope to contain GrTestTarget
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
continue;
}
@@ -217,7 +217,7 @@
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;
@@ -305,7 +305,7 @@
SkAutoTUnref<GrGeometryProcessor> gp;
{ // scope to contain GrTestTarget
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
continue;
}
@@ -362,7 +362,7 @@
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;
@@ -546,7 +546,7 @@
SkAutoTUnref<GrGeometryProcessor> gp;
{ // scope to contain GrTestTarget
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
continue;
}
@@ -600,7 +600,7 @@
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;
diff --git a/gm/bigrrectaaeffect.cpp b/gm/bigrrectaaeffect.cpp
index bc0b56a..472910b 100644
--- a/gm/bigrrectaaeffect.cpp
+++ b/gm/bigrrectaaeffect.cpp
@@ -65,7 +65,7 @@
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp
index 539119e..3b2605e 100644
--- a/gm/constcolorprocessor.cpp
+++ b/gm/constcolorprocessor.cpp
@@ -91,7 +91,7 @@
SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectSize);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp
index de0b692..d35997b 100644
--- a/gm/convexpolyeffect.cpp
+++ b/gm/convexpolyeffect.cpp
@@ -174,7 +174,7 @@
for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) {
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
@@ -225,7 +225,7 @@
for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) {
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/gm/rrects.cpp b/gm/rrects.cpp
index 279f4a6..e48b8c8 100644
--- a/gm/rrects.cpp
+++ b/gm/rrects.cpp
@@ -101,7 +101,7 @@
if (kEffect_Type == fType) {
#if SK_SUPPORT_GPU
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp
index cf772f5..a2dc4b0 100644
--- a/gm/texturedomaineffect.cpp
+++ b/gm/texturedomaineffect.cpp
@@ -80,7 +80,7 @@
}
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp
index 25dca35..5f7cc13 100644
--- a/gm/yuvtorgbeffect.cpp
+++ b/gm/yuvtorgbeffect.cpp
@@ -78,7 +78,7 @@
}
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 098fdd2..7621f8b 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -328,7 +328,7 @@
GrResourceCache* getResourceCache() { return fResourceCache; }
// Called by tests that draw directly to the context via GrDrawTarget
- void getTestTarget(GrTestTarget*);
+ void getTestTarget(GrTestTarget*, GrRenderTarget* rt);
/** Prints cache stats to the string if GR_CACHE_STATS == 1. */
void dumpCacheStats(SkString*) const;
diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp
index f6ece6c..f0f6370 100644
--- a/src/gpu/GrTest.cpp
+++ b/src/gpu/GrTest.cpp
@@ -52,25 +52,28 @@
fRenderTarget.reset(SkRef(rt));
}
-void GrContext::getTestTarget(GrTestTarget* tar) {
+void GrContext::getTestTarget(GrTestTarget* tar, GrRenderTarget* rt) {
this->flush();
// 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().
- GrSurfaceDesc desc;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fWidth = 32;
- desc.fHeight = 32;
- desc.fConfig = kRGBA_8888_GrPixelConfig;
- desc.fSampleCnt = 0;
+ if (!rt) {
+ GrSurfaceDesc desc;
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = 32;
+ desc.fHeight = 32;
+ desc.fConfig = kRGBA_8888_GrPixelConfig;
+ desc.fSampleCnt = 0;
- SkAutoTUnref<GrTexture> texture(this->textureProvider()->createTexture(desc, false, nullptr, 0));
- if (nullptr == texture) {
- return;
+ SkAutoTUnref<GrTexture> texture(this->textureProvider()->createTexture(desc, false,
+ nullptr, 0));
+ if (nullptr == texture) {
+ return;
+ }
+ SkASSERT(nullptr != texture->asRenderTarget());
+ rt = texture->asRenderTarget();
}
- SkASSERT(nullptr != texture->asRenderTarget());
- GrRenderTarget* rt = texture->asRenderTarget();
SkAutoTUnref<GrDrawTarget> dt(fDrawingManager->newDrawTarget(rt));
tar->init(this, dt, rt);
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index ce247df..47a88fc 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -357,7 +357,7 @@
set_random_stencil(&pipelineBuilder, &random);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
tt.target()->drawBatch(pipelineBuilder, batch);
}
@@ -391,7 +391,7 @@
builder.addColorFragmentProcessor(blockFP);
GrTestTarget tt;
- context->getTestTarget(&tt);
+ context->getTestTarget(&tt, rt);
tt.target()->drawBatch(builder, batch);
drawingManager->flush();
diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp
index ae648ac..219397b 100644
--- a/tests/TessellatingPathRendererTests.cpp
+++ b/tests/TessellatingPathRendererTests.cpp
@@ -263,8 +263,8 @@
desc.fOrigin = kTopLeft_GrSurfaceOrigin;
SkAutoTUnref<GrTexture> texture(context->textureProvider()->createApproxTexture(desc));
GrTestTarget tt;
- context->getTestTarget(&tt);
GrRenderTarget* rt = texture->asRenderTarget();
+ context->getTestTarget(&tt, rt);
GrDrawTarget* dt = tt.target();
GrResourceProvider* rp = tt.resourceProvider();