Initial CL to create GrBatchTest infrastructure

BUG=skia:

Review URL: https://codereview.chromium.org/1109153004
This commit is contained in:
joshualitt 2015-04-29 10:01:22 -07:00 committed by Commit bot
parent 61f501f8c6
commit 3f655f34a2
8 changed files with 185 additions and 25 deletions

View File

@ -73,6 +73,8 @@
'<(skia_src_path)/gpu/GrBatchFontCache.h',
'<(skia_src_path)/gpu/GrBatchTarget.cpp',
'<(skia_src_path)/gpu/GrBatchTarget.h',
'<(skia_src_path)/gpu/GrBatchTest.cpp',
'<(skia_src_path)/gpu/GrBatchTest.h',
'<(skia_src_path)/gpu/GrBlend.cpp',
'<(skia_src_path)/gpu/GrBlend.h',
'<(skia_src_path)/gpu/GrBufferAllocPool.cpp',

View File

@ -371,4 +371,10 @@
# define SK_GAMMA_EXPONENT (2.2f)
#endif
//////////////////////////////////////////////////////////////////////
#ifndef GR_TEST_UTILS
# define GR_TEST_UTILS 1
#endif
#endif // SkPostConfig_DEFINED

View File

@ -8,16 +8,22 @@
#ifndef GrTestUtils_DEFINED
#define GrTestUtils_DEFINED
#include "SkTypes.h"
#ifdef GR_TEST_UTILS
#include "GrColor.h"
#include "SkRandom.h"
class SkMatrix;
struct SkRect;
namespace GrTest {
/**
* A helper for use in Test functions.
*/
const SkMatrix& TestMatrix(SkRandom*);
const SkRect& TestRect(SkRandom*);
}
@ -46,13 +52,14 @@ static inline GrColor GrRandomColor(SkRandom* random) {
random->nextULessThan(256),
0xFF);
break;
case kRandom_ColorMode:
uint8_t alpha = random->nextULessThan(256);
color = GrColorPackRGBA(random->nextRangeU(0, alpha),
random->nextRangeU(0, alpha),
random->nextRangeU(0, alpha),
alpha);
case kRandom_ColorMode: {
uint8_t alpha = random->nextULessThan(256);
color = GrColorPackRGBA(random->nextRangeU(0, alpha),
random->nextRangeU(0, alpha),
random->nextRangeU(0, alpha),
alpha);
break;
}
}
GrColorIsPMAssert(color);
return color;
@ -82,3 +89,4 @@ static inline uint8_t GrRandomCoverage(SkRandom* random) {
}
#endif
#endif

View File

@ -8,12 +8,15 @@
#include "GrAARectRenderer.h"
#include "GrBatch.h"
#include "GrBatchTarget.h"
#include "GrBatchTest.h"
#include "GrBufferAllocPool.h"
#include "GrContext.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrGeometryProcessor.h"
#include "GrGpu.h"
#include "GrInvariantOutput.h"
#include "GrVertexBuffer.h"
#include "GrTestUtils.h"
#include "SkColorPriv.h"
#include "gl/GrGLProcessor.h"
#include "gl/GrGLGeometryProcessor.h"
@ -423,25 +426,28 @@ static int aa_stroke_rect_index_count(bool miterStroke) {
SK_ARRAY_COUNT(gBevelStrokeAARectIdx);
}
GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(bool miterStroke) {
static GrIndexBuffer* setup_aa_stroke_rect_indexbuffer(GrIndexBuffer** aaMiterStrokeRectIndexBuffer,
GrIndexBuffer** aaBevelStrokeRectIndexBuffer,
GrGpu* gpu,
bool miterStroke) {
if (miterStroke) {
if (NULL == fAAMiterStrokeRectIndexBuffer) {
fAAMiterStrokeRectIndexBuffer =
fGpu->createInstancedIndexBuffer(gMiterStrokeAARectIdx,
kIndicesPerMiterStrokeRect,
kNumMiterStrokeRectsInIndexBuffer,
kVertsPerMiterStrokeRect);
if (!*aaMiterStrokeRectIndexBuffer) {
*aaMiterStrokeRectIndexBuffer =
gpu->createInstancedIndexBuffer(gMiterStrokeAARectIdx,
kIndicesPerMiterStrokeRect,
kNumMiterStrokeRectsInIndexBuffer,
kVertsPerMiterStrokeRect);
}
return fAAMiterStrokeRectIndexBuffer;
return *aaMiterStrokeRectIndexBuffer;
} else {
if (NULL == fAABevelStrokeRectIndexBuffer) {
fAABevelStrokeRectIndexBuffer =
fGpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx,
kIndicesPerBevelStrokeRect,
kNumBevelStrokeRectsInIndexBuffer,
kVertsPerBevelStrokeRect);
if (!*aaBevelStrokeRectIndexBuffer) {
*aaBevelStrokeRectIndexBuffer =
gpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx,
kIndicesPerBevelStrokeRect,
kNumBevelStrokeRectsInIndexBuffer,
kVertsPerBevelStrokeRect);
}
return fAABevelStrokeRectIndexBuffer;
return *aaBevelStrokeRectIndexBuffer;
}
}
@ -852,7 +858,6 @@ private:
SkSTArray<1, Geometry, true> fGeoData;
};
void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target,
GrPipelineBuilder* pipelineBuilder,
GrColor color,
@ -861,7 +866,10 @@ void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target,
const SkRect& devOutsideAssist,
const SkRect& devInside,
bool miterStroke) {
GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke);
GrIndexBuffer* indexBuffer = setup_aa_stroke_rect_indexbuffer(&fAAMiterStrokeRectIndexBuffer,
&fAABevelStrokeRectIndexBuffer,
fGpu,
miterStroke);
if (!indexBuffer) {
SkDebugf("Failed to create index buffer!\n");
return;
@ -899,3 +907,58 @@ void GrAARectRenderer::fillAANestedRects(GrDrawTarget* target,
this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutsideAssist, devInside, true);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef GR_TEST_UTILS
BATCH_TEST_DEFINE(AAFillRectBatch) {
AAFillRectBatch::Geometry geo;
geo.fColor = GrRandomColor(random);
geo.fViewMatrix = GrTest::TestMatrix(random);
geo.fRect = GrTest::TestRect(random);
geo.fDevRect = GrTest::TestRect(random);
static GrIndexBuffer* aaFillRectIndexBuffer = NULL;
if (!aaFillRectIndexBuffer) {
aaFillRectIndexBuffer =
context->getGpu()->createInstancedIndexBuffer(gFillAARectIdx,
kIndicesPerAAFillRect,
kNumAAFillRectsInIndexBuffer,
kVertsPerAAFillRect);
}
return AAFillRectBatch::Create(geo, aaFillRectIndexBuffer);
}
BATCH_TEST_DEFINE(AAStrokeRectBatch) {
static GrIndexBuffer* aaMiterStrokeRectIndexBuffer = NULL;
static GrIndexBuffer* aaBevelStrokeRectIndexBuffer = NULL;
bool miterStroke = random->nextBool();
GrIndexBuffer* indexBuffer = setup_aa_stroke_rect_indexbuffer(&aaMiterStrokeRectIndexBuffer,
&aaBevelStrokeRectIndexBuffer,
context->getGpu(),
miterStroke);
// Create mock stroke rect
SkRect outside = GrTest::TestRect(random);
SkScalar minDim = SkMinScalar(outside.width(), outside.height());
SkScalar strokeWidth = minDim * 0.1f;
SkRect outsideAssist = outside;
outsideAssist.outset(strokeWidth, strokeWidth);
SkRect inside = outside;
inside.inset(strokeWidth, strokeWidth);
AAStrokeRectBatch::Geometry geo;
geo.fColor = GrRandomColor(random);
geo.fDevOutside = outside;
geo.fDevOutsideAssist = outsideAssist;
geo.fDevInside = inside;
geo.fMiterStroke = miterStroke;
return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffer);
}
#endif

View File

@ -68,8 +68,6 @@ public:
const SkRect rects[2]);
private:
GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
void geometryFillAARect(GrDrawTarget*,
GrPipelineBuilder*,
GrColor,

27
src/gpu/GrBatchTest.cpp Normal file
View File

@ -0,0 +1,27 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrBatchTest.h"
#include "SkRandom.h"
#include "SkTypes.h"
#ifdef GR_TEST_UTILS
BATCH_TEST_EXTERN(AAFillRectBatch);
BATCH_TEST_EXTERN(AAStrokeRectBatch);
static BatchTestFunc gTestBatches[] = {
BATCH_TEST_ENTRY(AAFillRectBatch),
BATCH_TEST_ENTRY(AAStrokeRectBatch),
};
GrBatch* GrRandomBatch(SkRandom* random, GrContext* context) {
uint32_t index = random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gTestBatches)));
BatchTestFunc func = gTestBatches[index];
return (*func)(random, context);
}
#endif

37
src/gpu/GrBatchTest.h Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrBatchTest_DEFINED
#define GrBatchTest_DEFINED
#include "GrTestUtils.h"
#ifdef GR_TEST_UTILS
class GrBatch;
class GrContext;
class SkRandom;
/*
* This file defines some macros for testing batches, and also declares functions / objects which
* are generally useful for GrBatch testing
*/
// Batches should define test functions using BATCH_TEST_DEFINE. The other macros defined below
// are used exclusively by the test harness.
typedef GrBatch* (*BatchTestFunc)(SkRandom* random, GrContext* context);
#define BATCH_TEST_DEFINE(Batch) \
GrBatch* Batch##__Test(SkRandom* random, GrContext* context)
#define BATCH_TEST_EXTERN(Batch) \
extern GrBatch* Batch##__Test(SkRandom*, GrContext* context);
#define BATCH_TEST_ENTRY(Batch) \
Batch##__Test
GrBatch* GrRandomBatch(SkRandom*, GrContext*);
#endif
#endif

View File

@ -8,6 +8,8 @@
#include "GrTestUtils.h"
#include "SkMatrix.h"
#ifdef GR_TEST_UTILS
namespace GrTest {
const SkMatrix& TestMatrix(SkRandom* random) {
static SkMatrix gMatrices[5];
@ -26,4 +28,21 @@ const SkMatrix& TestMatrix(SkRandom* random) {
}
return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))];
}
const SkRect& TestRect(SkRandom* random) {
static SkRect gRects[1];
static bool gOnce;
if (!gOnce) {
gRects[0] = SkRect::MakeWH(1.f, 1.f);
gRects[1] = SkRect::MakeWH(1.0f, 256.0f);
gRects[2] = SkRect::MakeWH(256.0f, 1.0f);
gRects[4] = SkRect::MakeLargest();
gRects[5] = SkRect::MakeLTRB(-65535.0f, -65535.0f, 65535.0f, 65535.0f);
gRects[6] = SkRect::MakeLTRB(10.0f, 10.0f, -10.0f, -10.0f);
gOnce = true;
}
return gRects[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gRects)))];
}
};
#endif