aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GrMeshTest.cpp
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-06-07 11:05:56 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-08 11:55:11 +0000
commit88a32efa75cbc0fc6f84bc7a0522a94166a2ab13 (patch)
tree48ccbee45d39a1a62b1d54616b78fea564456eb1 /tests/GrMeshTest.cpp
parent7a45dd1daca8de90f984591cf938dd089a7795a3 (diff)
Add a factory to any GrOp-derived class that lacked one
All GrOp-derived classes are going to have allocate their memory in a GrMemoryPool. Change-Id: Ifa410b05eecd9b68c39dcc15dd4298d617204c13 Reviewed-on: https://skia-review.googlesource.com/132828 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/GrMeshTest.cpp')
-rw-r--r--tests/GrMeshTest.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 1cdfe380d8..fb3579cabe 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -75,11 +75,12 @@ struct Box {
* from the set (r,g,b) = (0,255)^3, so the GPU renderings ought to produce exact matches.
*/
-static void run_test(const char* testName, skiatest::Reporter*, const sk_sp<GrRenderTargetContext>&,
- const SkBitmap& gold, std::function<void(DrawMeshHelper*)> testFn);
+static void run_test(GrContext* context, const char* testName, skiatest::Reporter*,
+ const sk_sp<GrRenderTargetContext>&, const SkBitmap& gold,
+ std::function<void(DrawMeshHelper*)> testFn);
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
- GrContext* const context = ctxInfo.grContext();
+ GrContext* context = ctxInfo.grContext();
sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeDeferredRenderTargetContext(
SkBackingFit::kExact, kImageWidth, kImageHeight,
@@ -136,26 +137,27 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
return; \
}
- run_test("setNonIndexedNonInstanced", reporter, rtc, gold, [&](DrawMeshHelper* helper) {
- SkTArray<Box> expandedVertexData;
- for (int i = 0; i < kBoxCount; ++i) {
- for (int j = 0; j < 6; ++j) {
- expandedVertexData.push_back(vertexData[i][kIndexPattern[j]]);
- }
- }
-
- // Draw boxes one line at a time to exercise base vertex.
- auto vbuff = helper->makeVertexBuffer(expandedVertexData);
- VALIDATE(vbuff);
- for (int y = 0; y < kBoxCountY; ++y) {
- GrMesh mesh(GrPrimitiveType::kTriangles);
- mesh.setNonIndexedNonInstanced(kBoxCountX * 6);
- mesh.setVertexData(vbuff.get(), y * kBoxCountX * 6);
- helper->drawMesh(mesh);
- }
- });
-
- run_test("setIndexed", reporter, rtc, gold, [&](DrawMeshHelper* helper) {
+ run_test(context, "setNonIndexedNonInstanced", reporter, rtc, gold,
+ [&](DrawMeshHelper* helper) {
+ SkTArray<Box> expandedVertexData;
+ for (int i = 0; i < kBoxCount; ++i) {
+ for (int j = 0; j < 6; ++j) {
+ expandedVertexData.push_back(vertexData[i][kIndexPattern[j]]);
+ }
+ }
+
+ // Draw boxes one line at a time to exercise base vertex.
+ auto vbuff = helper->makeVertexBuffer(expandedVertexData);
+ VALIDATE(vbuff);
+ for (int y = 0; y < kBoxCountY; ++y) {
+ GrMesh mesh(GrPrimitiveType::kTriangles);
+ mesh.setNonIndexedNonInstanced(kBoxCountX * 6);
+ mesh.setVertexData(vbuff.get(), y * kBoxCountX * 6);
+ helper->drawMesh(mesh);
+ }
+ });
+
+ run_test(context, "setIndexed", reporter, rtc, gold, [&](DrawMeshHelper* helper) {
auto ibuff = helper->getIndexBuffer();
VALIDATE(ibuff);
auto vbuff = helper->makeVertexBuffer(vertexData);
@@ -179,7 +181,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
}
});
- run_test("setIndexedPatterned", reporter, rtc, gold, [&](DrawMeshHelper* helper) {
+ run_test(context, "setIndexedPatterned", reporter, rtc, gold, [&](DrawMeshHelper* helper) {
auto ibuff = helper->getIndexBuffer();
VALIDATE(ibuff);
auto vbuff = helper->makeVertexBuffer(vertexData);
@@ -200,7 +202,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) {
break;
}
- run_test(indexed ? "setIndexedInstanced" : "setInstanced",
+ run_test(context, indexed ? "setIndexedInstanced" : "setInstanced",
reporter, rtc, gold, [&](DrawMeshHelper* helper) {
auto idxbuff = indexed ? helper->getIndexBuffer() : nullptr;
auto instbuff = helper->makeVertexBuffer(boxes);
@@ -252,6 +254,12 @@ class GrMeshTestOp : public GrDrawOp {
public:
DEFINE_OP_CLASS_ID
+ static std::unique_ptr<GrDrawOp> Make(GrContext* context,
+ std::function<void(DrawMeshHelper*)> testFn) {
+ return std::unique_ptr<GrDrawOp>(new GrMeshTestOp(testFn));
+ }
+
+private:
GrMeshTestOp(std::function<void(DrawMeshHelper*)> testFn)
: INHERITED(ClassID())
, fTestFn(testFn) {
@@ -259,7 +267,6 @@ public:
HasAABloat::kNo, IsZeroArea::kNo);
}
-private:
const char* name() const override { return "GrMeshTestOp"; }
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
@@ -374,7 +381,7 @@ void DrawMeshHelper::drawMesh(const GrMesh& mesh) {
SkRect::MakeIWH(kImageWidth, kImageHeight));
}
-static void run_test(const char* testName, skiatest::Reporter* reporter,
+static void run_test(GrContext* context, const char* testName, skiatest::Reporter* reporter,
const sk_sp<GrRenderTargetContext>& rtc, const SkBitmap& gold,
std::function<void(DrawMeshHelper*)> testFn) {
const int w = gold.width(), h = gold.height(), rowBytes = gold.rowBytes();
@@ -390,7 +397,7 @@ static void run_test(const char* testName, skiatest::Reporter* reporter,
SkAutoSTMalloc<kImageHeight * kImageWidth, uint32_t> resultPx(h * rowBytes);
rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
- rtc->priv().testingOnly_addDrawOp(skstd::make_unique<GrMeshTestOp>(testFn));
+ rtc->priv().testingOnly_addDrawOp(GrMeshTestOp::Make(context, testFn));
rtc->readPixels(gold.info(), resultPx, rowBytes, 0, 0, 0);
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {