Retract GrRenderTarget from GLProgramsTest
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=1997773002
Review-Url: https://codereview.chromium.org/1997773002
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 52f8c7e..0e7211d 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -258,6 +258,8 @@
*/
void drawBatch(const GrClip&, const GrPaint&, GrDrawBatch*);
+ bool hasMixedSamples() const { return fRenderTarget->hasMixedSamples(); }
+
const GrSurfaceDesc& desc() const { return fRenderTarget->desc(); }
int width() const { return fRenderTarget->width(); }
int height() const { return fRenderTarget->height(); }
diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h
index 8442d7e..bc90204 100644
--- a/include/gpu/GrProcessorUnitTest.h
+++ b/include/gpu/GrProcessorUnitTest.h
@@ -15,7 +15,7 @@
class SkMatrix;
class GrCaps;
class GrContext;
-class GrRenderTarget;
+class GrDrawContext;
struct GrProcessorTestData;
namespace GrProcessorUnitTest {
@@ -43,19 +43,19 @@
GrProcessorTestData(SkRandom* random,
GrContext* context,
const GrCaps* caps,
- const GrRenderTarget* rt,
+ const GrDrawContext* drawContext,
GrTexture* textures[2])
: fRandom(random)
, fContext(context)
, fCaps(caps)
- , fRenderTarget(rt) {
+ , fDrawContext(drawContext) {
fTextures[0] = textures[0];
fTextures[1] = textures[1];
}
SkRandom* fRandom;
GrContext* fContext;
const GrCaps* fCaps;
- const GrRenderTarget* fRenderTarget;
+ const GrDrawContext* fDrawContext;
GrTexture* fTextures[2];
};
diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp
index c1c9425..c0ba62f 100644
--- a/src/gpu/effects/GrCoverageSetOpXP.cpp
+++ b/src/gpu/effects/GrCoverageSetOpXP.cpp
@@ -8,6 +8,7 @@
#include "effects/GrCoverageSetOpXP.h"
#include "GrCaps.h"
#include "GrColor.h"
+#include "GrDrawContext.h"
#include "GrPipeline.h"
#include "GrProcessor.h"
#include "GrProcOptInfo.h"
@@ -338,6 +339,6 @@
const GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) {
SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLastOp + 1));
- bool invertCoverage = !d->fRenderTarget->hasMixedSamples() && d->fRandom->nextBool();
+ bool invertCoverage = !d->fDrawContext->hasMixedSamples() && d->fRandom->nextBool();
return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage);
}
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index a59cffa..7fabf32 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -147,34 +147,41 @@
static const int kRenderTargetHeight = 1;
static const int kRenderTargetWidth = 1;
-static GrRenderTarget* random_render_target(GrTextureProvider* textureProvider, SkRandom* random,
- const GrCaps* caps) {
- // setup render target
- GrTextureParams params;
- GrSurfaceDesc texDesc;
- texDesc.fWidth = kRenderTargetWidth;
- texDesc.fHeight = kRenderTargetHeight;
- texDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- texDesc.fConfig = kRGBA_8888_GrPixelConfig;
- texDesc.fOrigin = random->nextBool() == true ? kTopLeft_GrSurfaceOrigin :
- kBottomLeft_GrSurfaceOrigin;
- texDesc.fSampleCnt = random->nextBool() == true ? SkTMin(4, caps->maxSampleCount()) : 0;
+static sk_sp<GrDrawContext> random_draw_context(GrContext* context,
+ SkRandom* random,
+ const GrCaps* caps) {
+ GrSurfaceOrigin origin = random->nextBool() ? kTopLeft_GrSurfaceOrigin
+ : kBottomLeft_GrSurfaceOrigin;
+ int sampleCnt = random->nextBool() ? SkTMin(4, caps->maxSampleCount()) : 0;
GrUniqueKey key;
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&key, kDomain, 2);
- builder[0] = texDesc.fOrigin;
- builder[1] = texDesc.fSampleCnt;
+ builder[0] = origin;
+ builder[1] = sampleCnt;
builder.finish();
- GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key);
- if (!texture) {
- texture = textureProvider->createTexture(texDesc, SkBudgeted::kYes);
- if (texture) {
- textureProvider->assignUniqueKeyToTexture(key, texture);
- }
+ sk_sp<GrTexture> texture(context->textureProvider()->findAndRefTextureByUniqueKey(key));
+ if (texture) {
+ sk_sp<GrRenderTarget> rt(sk_ref_sp(texture->asRenderTarget()));
+ return context->drawContext(std::move(rt));
}
- return texture ? texture->asRenderTarget() : nullptr;
+
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExact,
+ kRenderTargetWidth,
+ kRenderTargetHeight,
+ kRGBA_8888_GrPixelConfig,
+ sampleCnt,
+ origin));
+ if (!drawContext) {
+ return nullptr;
+ }
+
+ // TODO: need a real way to do this via the drawContext
+ texture = drawContext->asTexture();
+ context->textureProvider()->assignUniqueKeyToTexture(key, texture.get());
+
+ return drawContext;
}
static void set_random_xpf(GrPipelineBuilder* pipelineBuilder, GrProcessorTestData* d) {
@@ -261,15 +268,16 @@
}
}
-static void set_random_state(GrPipelineBuilder* pipelineBuilder, SkRandom* random) {
+static void set_random_state(GrPipelineBuilder* pipelineBuilder,
+ GrDrawContext* drawContext,
+ SkRandom* random) {
int state = 0;
for (int i = 1; i <= GrPipelineBuilder::kLast_Flag; i <<= 1) {
state |= random->nextBool() * i;
}
// If we don't have an MSAA rendertarget then we have to disable useHWAA
- if ((state | GrPipelineBuilder::kHWAntialias_Flag) &&
- !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled()) {
+ if ((state | GrPipelineBuilder::kHWAntialias_Flag) && !drawContext->isUnifiedMultisampled()) {
state &= ~GrPipelineBuilder::kHWAntialias_Flag;
}
pipelineBuilder->enableState(state);
@@ -335,54 +343,51 @@
static const int NUM_TESTS = 1024;
for (int t = 0; t < NUM_TESTS; t++) {
// setup random render target(can fail)
- sk_sp<GrRenderTarget> rt(random_render_target(
- context->textureProvider(), &random, context->caps()));
- if (!rt.get()) {
- SkDebugf("Could not allocate render target");
- return false;
- }
-
- GrPipelineBuilder pipelineBuilder;
- pipelineBuilder.setRenderTarget(rt.get());
-
- SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
- SkASSERT(batch);
-
- GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures);
- set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
- set_random_xpf(&pipelineBuilder, &ptd);
- set_random_state(&pipelineBuilder, &random);
- set_random_stencil(&pipelineBuilder, &random);
-
- sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
+ sk_sp<GrDrawContext> drawContext(random_draw_context(context, &random, context->caps()));
if (!drawContext) {
SkDebugf("Could not allocate drawContext");
return false;
}
+ GrPipelineBuilder pipelineBuilder;
+ pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
+
+ SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
+ SkASSERT(batch);
+
+ GrProcessorTestData ptd(&random, context, context->caps(),
+ drawContext.get(), dummyTextures);
+ set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
+ set_random_xpf(&pipelineBuilder, &ptd);
+ set_random_state(&pipelineBuilder, drawContext.get(), &random);
+ set_random_stencil(&pipelineBuilder, &random);
+
drawContext->drawContextPriv().testingOnly_drawBatch(pipelineBuilder, batch);
}
// Flush everything, test passes if flush is successful(ie, no asserts are hit, no crashes)
drawingManager->flush();
// Validate that GrFPs work correctly without an input.
- GrSurfaceDesc rtDesc;
- rtDesc.fWidth = kRenderTargetWidth;
- rtDesc.fHeight = kRenderTargetHeight;
- rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
- sk_sp<GrRenderTarget> rt(
- context->textureProvider()->createTexture(rtDesc, SkBudgeted::kNo)->asRenderTarget());
+ sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kExact,
+ kRenderTargetWidth,
+ kRenderTargetHeight,
+ kRGBA_8888_GrPixelConfig));
+ if (!drawContext) {
+ SkDebugf("Could not allocate a drawContext");
+ return false;
+ }
+
int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
for (int i = 0; i < fpFactoryCnt; ++i) {
// Since FP factories internally randomize, call each 10 times.
for (int j = 0; j < 10; ++j) {
SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
SkASSERT(batch);
- GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures);
+ GrProcessorTestData ptd(&random, context, context->caps(),
+ drawContext.get(), dummyTextures);
GrPipelineBuilder builder;
builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
- builder.setRenderTarget(rt.get());
+ builder.setRenderTarget(drawContext->accessRenderTarget());
SkAutoTUnref<const GrFragmentProcessor> fp(
GrProcessorTestFactory<GrFragmentProcessor>::CreateIdx(i, &ptd));
@@ -390,12 +395,6 @@
BlockInputFragmentProcessor::Create(fp));
builder.addColorFragmentProcessor(blockFP);
- sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
- if (!drawContext) {
- SkDebugf("Could not allocate a drawcontext");
- return false;
- }
-
drawContext->drawContextPriv().testingOnly_drawBatch(builder, batch);
drawingManager->flush();
}