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
This commit is contained in:
robertphillips 2015-11-16 11:02:05 -08:00 committed by Commit bot
parent 3c2d32b8e2
commit 504ce5dc77
11 changed files with 32 additions and 29 deletions

View File

@ -157,7 +157,7 @@ protected:
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 @@ protected:
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;
@ -305,7 +305,7 @@ protected:
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 @@ protected:
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;
@ -546,7 +546,7 @@ protected:
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 @@ protected:
canvas->drawRect(bounds, boundsPaint);
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
SkASSERT(tt.target());
GrPipelineBuilder pipelineBuilder;

View File

@ -65,7 +65,7 @@ protected:
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;

View File

@ -91,7 +91,7 @@ protected:
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;

View File

@ -174,7 +174,7 @@ protected:
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 @@ protected:
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;

View File

@ -101,7 +101,7 @@ protected:
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;

View File

@ -80,7 +80,7 @@ protected:
}
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;

View File

@ -78,7 +78,7 @@ protected:
}
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
if (nullptr == tt.target()) {
SkDEBUGFAIL("Couldn't get Gr test target.");
return;

View File

@ -328,7 +328,7 @@ public:
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;

View File

@ -52,25 +52,28 @@ void GrTestTarget::init(GrContext* ctx, GrDrawTarget* target, GrRenderTarget* rt
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);

View File

@ -357,7 +357,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
set_random_stencil(&pipelineBuilder, &random);
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
tt.target()->drawBatch(pipelineBuilder, batch);
}
@ -391,7 +391,7 @@ bool GrDrawingManager::ProgramUnitTest(GrContext* context, int maxStages) {
builder.addColorFragmentProcessor(blockFP);
GrTestTarget tt;
context->getTestTarget(&tt);
context->getTestTarget(&tt, rt);
tt.target()->drawBatch(builder, batch);
drawingManager->flush();

View File

@ -263,8 +263,8 @@ DEF_GPUTEST(TessellatingPathRendererTests, reporter, factory) {
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();