From 88a32efa75cbc0fc6f84bc7a0522a94166a2ab13 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Thu, 7 Jun 2018 11:05:56 -0400 Subject: 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 Commit-Queue: Robert Phillips --- tests/GrMeshTest.cpp | 63 +++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) (limited to 'tests/GrMeshTest.cpp') 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&, - const SkBitmap& gold, std::function testFn); +static void run_test(GrContext* context, const char* testName, skiatest::Reporter*, + const sk_sp&, const SkBitmap& gold, + std::function testFn); DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrMeshTest, reporter, ctxInfo) { - GrContext* const context = ctxInfo.grContext(); + GrContext* context = ctxInfo.grContext(); sk_sp 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 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 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 Make(GrContext* context, + std::function testFn) { + return std::unique_ptr(new GrMeshTestOp(testFn)); + } + +private: GrMeshTestOp(std::function 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& rtc, const SkBitmap& gold, std::function 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 resultPx(h * rowBytes); rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes); - rtc->priv().testingOnly_addDrawOp(skstd::make_unique(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) { -- cgit v1.2.3