Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: src/gpu/GrContext.cpp

Issue 1133613004: Add unit tests for stroke rects and drawVertices (Closed) Base URL: https://skia.googlesource.com/skia.git@randbatch8
Patch Set: tidy Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/GrTypes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrContext.cpp
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index c9342a5e6a75aa564c2ef4bfe53eac573bce8bd0..662677163112fe43c4510361080169467ae7bd2b 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -13,6 +13,7 @@
#include "GrBatch.h"
#include "GrBatchFontCache.h"
#include "GrBatchTarget.h"
+#include "GrBatchTest.h"
#include "GrBufferAllocPool.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrGpuResource.h"
@@ -1908,3 +1909,128 @@ void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
fDrawBuffer->removeGpuTraceMarker(marker);
}
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef GR_TEST_UTILS
+
+BATCH_TEST_DEFINE(StrokeRect) {
+ StrokeRectBatch::Geometry geometry;
+ geometry.fViewMatrix = GrTest::TestMatrix(random);
+ geometry.fColor = GrRandomColor(random);
+ geometry.fRect = GrTest::TestRect(random);
robertphillips 2015/05/08 18:32:17 A big one? 10?
+ geometry.fStrokeWidth = random->nextBool() ? 0.0f : 1.0f;
+
+ return StrokeRectBatch::Create(geometry);
+}
+
+static int seed_vertices(GrPrimitiveType type) {
robertphillips 2015/05/08 18:40:13 space between 'h' and '(' ?
+ switch(type) {
robertphillips 2015/05/08 18:32:17 add // fall throughs ?
+ case kTriangles_GrPrimitiveType:
+ case kTriangleStrip_GrPrimitiveType:
+ case kTriangleFan_GrPrimitiveType:
+ return 3;
+ case kPoints_GrPrimitiveType:
+ return 1;
+ case kLines_GrPrimitiveType:
+ case kLineStrip_GrPrimitiveType:
+ return 2;
+ }
+ SkFAIL("Incomplete switch\n");
+ return 0;
+}
+
+static int primitive_vertices(GrPrimitiveType type) {
+ switch(type) {
+ case kTriangles_GrPrimitiveType:
+ return 3;
+ case kLines_GrPrimitiveType:
+ return 2;
+ case kTriangleStrip_GrPrimitiveType:
+ case kTriangleFan_GrPrimitiveType:
+ case kPoints_GrPrimitiveType:
+ case kLineStrip_GrPrimitiveType:
+ return 1;
+ }
+ SkFAIL("Incomplete switch\n");
+ return 0;
+}
+
+static SkPoint random_point(SkRandom* random, SkScalar min, SkScalar max) {
+ SkPoint p;
+ p.fX = random->nextRangeScalar(min, max);
+ p.fY = random->nextRangeScalar(min, max);
+ return p;
+}
+
robertphillips 2015/05/08 18:40:13 Actually use min & max ?
+static void randomize_params(int count, int maxVertex, SkScalar min, SkScalar max,
+ SkRandom* random,
+ SkTArray<SkPoint>* positions,
+ SkTArray<SkPoint>* texCoords, bool hasTexCoords,
+ SkTArray<GrColor>* colors, bool hasColors,
+ SkTArray<uint16_t>* indices, bool hasIndices) {
+ for (int v = 0; v < count; v++) {
+ positions->push_back(random_point(random, -100.f, 100.f));
+ if (hasTexCoords) {
+ texCoords->push_back(random_point(random, -100.f, 100.f));
+ }
+ if (hasColors) {
+ colors->push_back(GrRandomColor(random));
+ }
+ if (hasIndices) {
+ indices->push_back(random->nextULessThan(maxVertex));
+ }
+ }
+}
+
+BATCH_TEST_DEFINE(Vertices) {
+ GrPrimitiveType type = GrPrimitiveType(random->nextULessThan(kLast_GrPrimitiveType + 1));
+ int primitiveCount = random->nextRangeU(1, 100);
+
+ // TODO make 'sensible' indexbuffers
+ SkTArray<SkPoint> positions;
+ SkTArray<SkPoint> texCoords;
+ SkTArray<GrColor> colors;
+ SkTArray<uint16_t> indices;
+
+ bool hasTexCoords = random->nextBool();
+ bool hasIndices = random->nextBool();
+ bool hasColors = random->nextBool();
+
+ int vertexCount = seed_vertices(type) + (primitiveCount - 1) * primitive_vertices(type);
+
+ int i = 1;
robertphillips 2015/05/08 18:40:13 Maybe kMinVertExtent, kMaxVertExtent instead of -1
+ randomize_params(seed_vertices(type), vertexCount, -100.f, 100.f,
+ random,
+ &positions,
+ &texCoords, hasTexCoords,
+ &colors, hasColors,
+ &indices, hasIndices);
+
robertphillips 2015/05/08 18:32:17 I, personally, would do "for (int i = 1; ..." but
+ for (; i < primitiveCount; i++) {
+ randomize_params(primitive_vertices(type), vertexCount, -100.f, 100.f,
+ random,
+ &positions,
+ &texCoords, hasTexCoords,
+ &colors, hasColors,
+ &indices, hasIndices);
+ }
+
+ SkMatrix viewMatrix = GrTest::TestMatrix(random);
+ SkRect bounds;
robertphillips 2015/05/08 18:40:13 Don't we want to assert that the bound is finite ?
+ SkDEBUGCODE(bool result = ) !bounds.setBoundsCheck(positions.begin(), vertexCount);
+ SkASSERT(result);
+
+ viewMatrix.mapRect(&bounds);
+
+ DrawVerticesBatch::Geometry geometry;
+ geometry.fColor = GrRandomColor(random);
+ return DrawVerticesBatch::Create(geometry, type, viewMatrix,
+ positions.begin(), vertexCount,
+ indices.begin(), hasIndices ? vertexCount : 0,
+ colors.begin(),
+ texCoords.begin(),
+ bounds);
+}
+
+#endif
« no previous file with comments | « include/gpu/GrTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698