Chromium Code Reviews| Index: tests/CanvasTest.cpp |
| diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp |
| index 5ec0b8f646cc4d6adaa09d75e111064ebd69640d..c594106073ae91e3d61cb44c9cff7f117070e841 100644 |
| --- a/tests/CanvasTest.cpp |
| +++ b/tests/CanvasTest.cpp |
| @@ -65,6 +65,114 @@ |
| #include "SkTDArray.h" |
| #include "Test.h" |
| +static const int kWidth = 2, kHeight = 2; |
| + |
| +static void createBitmap(SkBitmap* bm, SkColor color) { |
| + bm->allocN32Pixels(kWidth, kHeight); |
| + bm->eraseColor(color); |
| +} |
| + |
| +static SkSurface* createSurface(SkColor color) { |
| + SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); |
| + surface->getCanvas()->clear(color); |
| + return surface; |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// Constants used by test steps |
| +const SkPoint hkTestPoints[] = { |
| + {SkIntToScalar(0), SkIntToScalar(0)}, |
| + {SkIntToScalar(2), SkIntToScalar(1)}, |
| + {SkIntToScalar(0), SkIntToScalar(2)} |
| +}; |
| +const SkPoint hkTestPoints2[] = { |
| + { SkIntToScalar(0), SkIntToScalar(1) }, |
| + { SkIntToScalar(1), SkIntToScalar(1) }, |
| + { SkIntToScalar(2), SkIntToScalar(1) }, |
| + { SkIntToScalar(3), SkIntToScalar(1) }, |
| + { SkIntToScalar(4), SkIntToScalar(1) }, |
| + { SkIntToScalar(5), SkIntToScalar(1) }, |
| + { SkIntToScalar(6), SkIntToScalar(1) }, |
| + { SkIntToScalar(7), SkIntToScalar(1) }, |
| + { SkIntToScalar(8), SkIntToScalar(1) }, |
| + { SkIntToScalar(9), SkIntToScalar(1) }, |
| + { SkIntToScalar(10), SkIntToScalar(1) } |
| +}; |
| + |
| +struct TestData { |
| +public: |
| + TestData() |
| + : fTestRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| + SkIntToScalar(2), SkIntToScalar(1))) |
| + , fTestMatrix(testMatrix()) |
| + , fTestPath(test_path()) |
| + , fNearlyZeroLengthPath(test_nearly_zero_length_path()) |
| + , fTestIRect(SkIRect::MakeXYWH(0, 0, 2, 1)) |
| + , fTestRegion(testRegion()) |
| + , fTestColor(0x01020304) |
| + , fTestPoints(hkTestPoints) |
| + , fTestPointCount(3) |
| + , fWidth(2) |
| + , fHeight(2) |
| + , fTestText("Hello World") |
| + , fTestPoints2(hkTestPoints2) |
| + , fTestBitmap(testBitmap()) |
| + { } |
| + |
| + const SkRect fTestRect; |
| + const SkMatrix fTestMatrix;; |
| + const SkPath fTestPath; |
| + const SkPath fNearlyZeroLengthPath; |
| + const SkIRect fTestIRect; |
| + const SkRegion fTestRegion; |
| + const SkColor fTestColor; |
| + const SkPaint fTestPaint; |
| + const SkPoint* fTestPoints; |
| + const size_t fTestPointCount; |
| + const int fWidth; |
| + const int fHeight; |
| + const SkString fTestText; |
| + const SkPoint* fTestPoints2; |
| + const SkBitmap fTestBitmap; |
| +private: |
| + static SkMatrix testMatrix() { |
| + SkMatrix matrix; |
| + matrix.reset(); |
| + matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| + |
| + return matrix; |
| + } |
| + static SkPath test_path() { |
| + SkPath path; |
| + path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| + SkIntToScalar(2), SkIntToScalar(1))); |
| + return path; |
| + } |
| + static SkPath test_nearly_zero_length_path() { |
|
reed1
2014/10/02 19:53:06
nit: Static methods are Capitalized
Rémi Piotaix
2014/10/02 20:02:26
Done.
|
| + SkPath path; |
| + SkPoint pt1 = { 0, 0 }; |
| + SkPoint pt2 = { 0, SK_ScalarNearlyZero }; |
| + SkPoint pt3 = { SkIntToScalar(1), 0 }; |
| + SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; |
| + path.moveTo(pt1); |
| + path.lineTo(pt2); |
| + path.lineTo(pt3); |
| + path.lineTo(pt4); |
| + return path; |
| + } |
| + static SkRegion testRegion() { |
|
reed1
2014/10/02 19:53:06
same static function nit
Rémi Piotaix
2014/10/02 20:02:26
Done.
|
| + SkRegion region; |
| + SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| + region.setRect(rect); |
| + return region; |
| + } |
| + static SkBitmap testBitmap() { |
| + SkBitmap bitmap; |
| + createBitmap(&bitmap, 0x05060708); |
| + return bitmap; |
| + } |
| +}; |
| + |
| static bool equal_clips(const SkCanvas& a, const SkCanvas& b) { |
| if (a.isClipEmpty()) { |
| return b.isClipEmpty(); |
| @@ -110,9 +218,6 @@ static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { |
| REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); |
| } |
| -static const int kWidth = 2; |
| -static const int kHeight = 2; |
| - |
| // Format strings that describe the test context. The %s token is where |
| // the name of the test step is inserted. The context is required for |
| // disambiguating the error in the case of failures that are reported in |
| @@ -146,17 +251,6 @@ static const char* const kNWayIndirect2StateAssertMessageFormat = |
| static const char* const kPdfAssertMessageFormat = |
| "PDF sanity check failed %s"; |
| -static void createBitmap(SkBitmap* bm, SkColor color) { |
| - bm->allocN32Pixels(kWidth, kHeight); |
| - bm->eraseColor(color); |
| -} |
| - |
| -static SkSurface* createSurface(SkColor color) { |
| - SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); |
| - surface->getCanvas()->clear(color); |
| - return surface; |
| -} |
| - |
| class CanvasTestStep; |
| static SkTDArray<CanvasTestStep*>& testStepArray() { |
| static SkTDArray<CanvasTestStep*> theTests; |
| @@ -172,7 +266,7 @@ public: |
| } |
| virtual ~CanvasTestStep() { } |
| - virtual void draw(SkCanvas*, skiatest::Reporter*) = 0; |
| + virtual void draw(SkCanvas*, const TestData&, skiatest::Reporter*) = 0; |
| virtual const char* name() const = 0; |
| const char* assertMessage() { |
| @@ -193,110 +287,41 @@ private: |
| }; |
| /////////////////////////////////////////////////////////////////////////////// |
| -// Constants used by test steps |
| - |
| -const SkRect kTestRect = |
| - SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| - SkIntToScalar(2), SkIntToScalar(1)); |
| -static SkMatrix testMatrix() { |
| - SkMatrix matrix; |
| - matrix.reset(); |
| - matrix.setScale(SkIntToScalar(2), SkIntToScalar(3)); |
| - return matrix; |
| -} |
| -const SkMatrix kTestMatrix = testMatrix(); |
| -static SkPath test_path() { |
| - SkPath path; |
| - path.addRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(0), |
| - SkIntToScalar(2), SkIntToScalar(1))); |
| - return path; |
| -} |
| -const SkPath kTestPath = test_path(); |
| -static SkPath test_nearly_zero_length_path() { |
| - SkPath path; |
| - SkPoint pt1 = { 0, 0 }; |
| - SkPoint pt2 = { 0, SK_ScalarNearlyZero }; |
| - SkPoint pt3 = { SkIntToScalar(1), 0 }; |
| - SkPoint pt4 = { SkIntToScalar(1), SK_ScalarNearlyZero/2 }; |
| - path.moveTo(pt1); |
| - path.lineTo(pt2); |
| - path.lineTo(pt3); |
| - path.lineTo(pt4); |
| - return path; |
| -} |
| -const SkPath kNearlyZeroLengthPath = test_nearly_zero_length_path(); |
| -static SkRegion testRegion() { |
| - SkRegion region; |
| - SkIRect rect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| - region.setRect(rect); |
| - return region; |
| -} |
| -const SkIRect kTestIRect = SkIRect::MakeXYWH(0, 0, 2, 1); |
| -const SkRegion kTestRegion = testRegion(); |
| -const SkColor kTestColor = 0x01020304; |
| -const SkPaint kTestPaint; |
| -const SkPoint kTestPoints[3] = { |
| - {SkIntToScalar(0), SkIntToScalar(0)}, |
| - {SkIntToScalar(2), SkIntToScalar(1)}, |
| - {SkIntToScalar(0), SkIntToScalar(2)} |
| -}; |
| -const size_t kTestPointCount = 3; |
| -static SkBitmap testBitmap() { |
| - SkBitmap bitmap; |
| - createBitmap(&bitmap, 0x05060708); |
| - return bitmap; |
| -} |
| -SkBitmap kTestBitmap; // cannot be created during static init |
| -SkString kTestText("Hello World"); |
| -SkPoint kTestPoints2[] = { |
| - { SkIntToScalar(0), SkIntToScalar(1) }, |
| - { SkIntToScalar(1), SkIntToScalar(1) }, |
| - { SkIntToScalar(2), SkIntToScalar(1) }, |
| - { SkIntToScalar(3), SkIntToScalar(1) }, |
| - { SkIntToScalar(4), SkIntToScalar(1) }, |
| - { SkIntToScalar(5), SkIntToScalar(1) }, |
| - { SkIntToScalar(6), SkIntToScalar(1) }, |
| - { SkIntToScalar(7), SkIntToScalar(1) }, |
| - { SkIntToScalar(8), SkIntToScalar(1) }, |
| - { SkIntToScalar(9), SkIntToScalar(1) }, |
| - { SkIntToScalar(10), SkIntToScalar(1) }, |
| -}; |
| - |
| - |
| -/////////////////////////////////////////////////////////////////////////////// |
| // Macros for defining test steps |
| #define TEST_STEP(NAME, FUNCTION) \ |
| class NAME##_TestStep : public CanvasTestStep{ \ |
| public: \ |
| - virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| - FUNCTION (canvas, reporter, this); \ |
| + virtual void draw(SkCanvas* canvas, const TestData& testData, \ |
| + skiatest::Reporter* reporter) { \ |
| + FUNCTION (canvas, testData, reporter, this); \ |
| } \ |
| virtual const char* name() const {return #NAME ;} \ |
| }; \ |
| static NAME##_TestStep NAME##_TestStepInstance; |
| -#define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
| +#define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
| class NAME##_TestStep : public CanvasTestStep{ \ |
| public: \ |
| NAME##_TestStep() : CanvasTestStep(false) {} \ |
| - virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| - FUNCTION (canvas, reporter, this); \ |
| + virtual void draw(SkCanvas* canvas, const TestData& testData, \ |
| + skiatest::Reporter* reporter) { \ |
| + FUNCTION (canvas, testData, reporter, this); \ |
| } \ |
| virtual const char* name() const {return #NAME ;} \ |
| }; \ |
| static NAME##_TestStep NAME##_TestStepInstance; |
| -#define SIMPLE_TEST_STEP(NAME, CALL) \ |
| -static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter*, \ |
| - CanvasTestStep*) { \ |
| - canvas-> CALL ; \ |
| -} \ |
| +#define SIMPLE_TEST_STEP(NAME, CALL) \ |
| +static void NAME##TestStep(SkCanvas* canvas, const TestData& testData, \ |
| + skiatest::Reporter*, CanvasTestStep*) { \ |
| + canvas-> CALL ; \ |
| +} \ |
| TEST_STEP(NAME, NAME##TestStep ) |
| #define SIMPLE_TEST_STEP_WITH_ASSERT(NAME, CALL) \ |
| -static void NAME##TestStep(SkCanvas* canvas, skiatest::Reporter* reporter, \ |
| - CanvasTestStep* testStep) { \ |
| +static void NAME##TestStep(SkCanvas* canvas, const TestData& testData, \ |
| + skiatest::Reporter*, CanvasTestStep* testStep) { \ |
| REPORTER_ASSERT_MESSAGE(reporter, canvas-> CALL , \ |
| testStep->assertMessage()); \ |
| } \ |
| @@ -311,63 +336,62 @@ SIMPLE_TEST_STEP(Translate, translate(SkIntToScalar(1), SkIntToScalar(2))); |
| SIMPLE_TEST_STEP(Scale, scale(SkIntToScalar(1), SkIntToScalar(2))); |
| SIMPLE_TEST_STEP(Rotate, rotate(SkIntToScalar(1))); |
| SIMPLE_TEST_STEP(Skew, skew(SkIntToScalar(1), SkIntToScalar(2))); |
| -SIMPLE_TEST_STEP(Concat, concat(kTestMatrix)); |
| -SIMPLE_TEST_STEP(SetMatrix, setMatrix(kTestMatrix)); |
| -SIMPLE_TEST_STEP(ClipRect, clipRect(kTestRect)); |
| -SIMPLE_TEST_STEP(ClipPath, clipPath(kTestPath)); |
| +SIMPLE_TEST_STEP(Concat, concat(testData.fTestMatrix)); |
| +SIMPLE_TEST_STEP(SetMatrix, setMatrix(testData.fTestMatrix)); |
| +SIMPLE_TEST_STEP(ClipRect, clipRect(testData.fTestRect)); |
| +SIMPLE_TEST_STEP(ClipPath, clipPath(testData.fTestPath)); |
| SIMPLE_TEST_STEP(ClipRegion, |
| - clipRegion(kTestRegion, SkRegion::kReplace_Op)); |
| -SIMPLE_TEST_STEP(Clear, clear(kTestColor)); |
| -SIMPLE_TEST_STEP(DrawPaint, drawPaint(kTestPaint)); |
| + clipRegion(testData.fTestRegion, SkRegion::kReplace_Op)); |
| +SIMPLE_TEST_STEP(Clear, clear(testData.fTestColor)); |
| +SIMPLE_TEST_STEP(DrawPaint, drawPaint(testData.fTestPaint)); |
| SIMPLE_TEST_STEP(DrawPointsPoints, drawPoints(SkCanvas::kPoints_PointMode, |
| - kTestPointCount, kTestPoints, kTestPaint)); |
| + testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
| SIMPLE_TEST_STEP(DrawPointsLiness, drawPoints(SkCanvas::kLines_PointMode, |
| - kTestPointCount, kTestPoints, kTestPaint)); |
| + testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
| SIMPLE_TEST_STEP(DrawPointsPolygon, drawPoints(SkCanvas::kPolygon_PointMode, |
| - kTestPointCount, kTestPoints, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawRect, drawRect(kTestRect, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawPath, drawPath(kTestPath, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(kTestBitmap, 0, 0)); |
| -SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(kTestBitmap, 0, 0, &kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(kTestBitmap, NULL, kTestRect, |
| + testData.fTestPointCount, testData.fTestPoints, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawRect, drawRect(testData.fTestRect, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawPath, drawPath(testData.fTestPath, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawBitmap, drawBitmap(testData.fTestBitmap, 0, 0)); |
| +SIMPLE_TEST_STEP(DrawBitmapPaint, drawBitmap(testData.fTestBitmap, 0, 0, &testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawBitmapRect, drawBitmapRect(testData.fTestBitmap, NULL, testData.fTestRect, |
| NULL)); |
| -SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(kTestBitmap, |
| - &kTestIRect, kTestRect, NULL)); |
| -SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(kTestBitmap, NULL, |
| - kTestRect, &kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(kTestBitmap, kTestMatrix, |
| +SIMPLE_TEST_STEP(DrawBitmapRectSrcRect, drawBitmapRect(testData.fTestBitmap, |
| + &testData.fTestIRect, testData.fTestRect, NULL)); |
| +SIMPLE_TEST_STEP(DrawBitmapRectPaint, drawBitmapRect(testData.fTestBitmap, NULL, |
| + testData.fTestRect, &testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawBitmapMatrix, drawBitmapMatrix(testData.fTestBitmap, testData.fTestMatrix, |
| NULL)); |
| -SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(kTestBitmap, |
| - kTestMatrix, &kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(kTestBitmap, kTestIRect, |
| - kTestRect, NULL)); |
| -SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(kTestBitmap, kTestIRect, |
| - kTestRect, &kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawSprite, drawSprite(kTestBitmap, 0, 0, NULL)); |
| -SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(kTestBitmap, 0, 0, &kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawText, drawText(kTestText.c_str(), kTestText.size(), |
| - 0, 1, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), |
| - kTestText.size(), kTestPoints2, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), |
| - kTestText.size(), kTestPath, NULL, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), |
| - kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); |
| -SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); |
| -SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); |
| -SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); |
| +SIMPLE_TEST_STEP(DrawBitmapMatrixPaint, drawBitmapMatrix(testData.fTestBitmap, |
| + testData.fTestMatrix, &testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawBitmapNine, drawBitmapNine(testData.fTestBitmap, testData.fTestIRect, |
| + testData.fTestRect, NULL)); |
| +SIMPLE_TEST_STEP(DrawBitmapNinePaint, drawBitmapNine(testData.fTestBitmap, testData.fTestIRect, |
| + testData.fTestRect, &testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawSprite, drawSprite(testData.fTestBitmap, 0, 0, NULL)); |
| +SIMPLE_TEST_STEP(DrawSpritePaint, drawSprite(testData.fTestBitmap, 0, 0, &testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawText, drawText(testData.fTestText.c_str(), testData.fTestText.size(), |
| + 0, 1, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawPosText, drawPosText(testData.fTestText.c_str(), |
| + testData.fTestText.size(), testData.fTestPoints2, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(testData.fTestText.c_str(), |
| + testData.fTestText.size(), testData.fTestPath, NULL, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(testData.fTestText.c_str(), |
| + testData.fTestText.size(), testData.fTestPath, &testData.fTestMatrix, testData.fTestPaint)); |
| +SIMPLE_TEST_STEP(DrawData, drawData(testData.fTestText.c_str(), testData.fTestText.size())); |
| +SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(testData.fTestText.c_str())); |
| +SIMPLE_TEST_STEP(AddComment, addComment(testData.fTestText.c_str(), testData.fTestText.c_str())); |
| SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); |
| /////////////////////////////////////////////////////////////////////////////// |
| // Complex test steps |
| -static void SaveMatrixClipStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void SaveMatrixClipStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| int saveCount = canvas->getSaveCount(); |
| canvas->save(); |
| canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
| - canvas->clipRegion(kTestRegion); |
| + canvas->clipRegion(testData.fTestRegion); |
| canvas->restore(); |
| REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
| testStep->assertMessage()); |
| @@ -377,9 +401,8 @@ static void SaveMatrixClipStep(SkCanvas* canvas, |
| } |
| TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
| -static void SaveLayerStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void SaveLayerStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| int saveCount = canvas->getSaveCount(); |
| canvas->saveLayer(NULL, NULL); |
| canvas->restore(); |
| @@ -388,63 +411,58 @@ static void SaveLayerStep(SkCanvas* canvas, |
| } |
| TEST_STEP(SaveLayer, SaveLayerStep); |
| -static void BoundedSaveLayerStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| int saveCount = canvas->getSaveCount(); |
| - canvas->saveLayer(&kTestRect, NULL); |
| + canvas->saveLayer(&testData.fTestRect, NULL); |
| canvas->restore(); |
| REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
| testStep->assertMessage()); |
| } |
| TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); |
| -static void PaintSaveLayerStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| int saveCount = canvas->getSaveCount(); |
| - canvas->saveLayer(NULL, &kTestPaint); |
| + canvas->saveLayer(NULL, &testData.fTestPaint); |
| canvas->restore(); |
| REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
| testStep->assertMessage()); |
| } |
| TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); |
| -static void TwoClipOpsStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void TwoClipOpsStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| // This test exercises a functionality in SkPicture that leads to the |
| // recording of restore offset placeholders. This test will trigger an |
| // assertion at playback time if the placeholders are not properly |
| // filled when the recording ends. |
| - canvas->clipRect(kTestRect); |
| - canvas->clipRegion(kTestRegion); |
| + canvas->clipRect(testData.fTestRect); |
| + canvas->clipRegion(testData.fTestRegion); |
| } |
| TEST_STEP(TwoClipOps, TwoClipOpsStep); |
| // exercise fix for http://code.google.com/p/skia/issues/detail?id=560 |
| // ('SkPathStroker::lineTo() fails for line with length SK_ScalarNearlyZero') |
| -static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void DrawNearlyZeroLengthPathTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| SkPaint paint; |
| paint.setStrokeWidth(SkIntToScalar(1)); |
| paint.setStyle(SkPaint::kStroke_Style); |
| - canvas->drawPath(kNearlyZeroLengthPath, paint); |
| + canvas->drawPath(testData.fNearlyZeroLengthPath, paint); |
| } |
| TEST_STEP(DrawNearlyZeroLengthPath, DrawNearlyZeroLengthPathTestStep); |
| -static void DrawVerticesShaderTestStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void DrawVerticesShaderTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| SkPoint pts[4]; |
| pts[0].set(0, 0); |
| - pts[1].set(SkIntToScalar(kWidth), 0); |
| - pts[2].set(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| - pts[3].set(0, SkIntToScalar(kHeight)); |
| + pts[1].set(SkIntToScalar(testData.fWidth), 0); |
| + pts[2].set(SkIntToScalar(testData.fWidth), SkIntToScalar(testData.fHeight)); |
| + pts[3].set(0, SkIntToScalar(testData.fHeight)); |
| SkPaint paint; |
| - SkShader* shader = SkShader::CreateBitmapShader(kTestBitmap, |
| + SkShader* shader = SkShader::CreateBitmapShader(testData.fTestBitmap, |
| SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| paint.setShader(shader)->unref(); |
| canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
| @@ -453,24 +471,22 @@ static void DrawVerticesShaderTestStep(SkCanvas* canvas, |
| // NYI: issue 240. |
| TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
| -static void DrawPictureTestStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void DrawPictureTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| SkPictureRecorder recorder; |
| - SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntToScalar(kHeight), |
| + SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(testData.fWidth), SkIntToScalar(testData.fHeight), |
| NULL, 0); |
| testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
| - testCanvas->clipRect(kTestRect); |
| - testCanvas->drawRect(kTestRect, kTestPaint); |
| + testCanvas->clipRect(testData.fTestRect); |
| + testCanvas->drawRect(testData.fTestRect, testData.fTestPaint); |
| SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); |
| canvas->drawPicture(testPicture); |
| } |
| TEST_STEP(DrawPicture, DrawPictureTestStep); |
| -static void SaveRestoreTestStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| int baseSaveCount = canvas->getSaveCount(); |
| int n = canvas->save(); |
| REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount == n, testStep->assertMessage()); |
| @@ -491,9 +507,8 @@ static void SaveRestoreTestStep(SkCanvas* canvas, |
| } |
| TEST_STEP(SaveRestore, SaveRestoreTestStep); |
| -static void DrawLayerTestStep(SkCanvas* canvas, |
| - skiatest::Reporter* reporter, |
| - CanvasTestStep* testStep) { |
| +static void DrawLayerTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter* reporter, CanvasTestStep* testStep) { |
| REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), |
| testStep->assertMessage()); |
| canvas->save(); |
| @@ -525,9 +540,8 @@ static void DrawLayerTestStep(SkCanvas* canvas, |
| } |
| TEST_STEP(DrawLayer, DrawLayerTestStep); |
| -static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| // This test step challenges the TestDeferredCanvasStateConsistency |
| // test cases because the opaque paint can trigger an optimization |
| // that discards previously recorded commands. The challenge is to maintain |
| @@ -547,9 +561,8 @@ static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, |
| TEST_STEP(NestedSaveRestoreWithSolidPaint, \ |
| NestedSaveRestoreWithSolidPaintTestStep); |
| -static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, |
| - skiatest::Reporter*, |
| - CanvasTestStep*) { |
| +static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData& testData, |
| + skiatest::Reporter*, CanvasTestStep*) { |
| // This test step challenges the TestDeferredCanvasStateConsistency |
| // test case because the canvas flush on a deferred canvas will |
| // reset the recording session. The challenge is to maintain correct |
| @@ -560,17 +573,15 @@ static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, |
| canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| canvas->save(); |
| canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| - canvas->drawRect(kTestRect,kTestPaint); |
| + canvas->drawRect(testData.fTestRect,testData.fTestPaint); |
| canvas->flush(); |
| canvas->restore(); |
| canvas->restore(); |
| } |
| -TEST_STEP(NestedSaveRestoreWithFlush, \ |
| - NestedSaveRestoreWithFlushTestStep); |
| +TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
| -static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, |
| - const SkCanvas* canvas1, |
| - const SkCanvas* canvas2, |
| +static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData& testData, |
| + const SkCanvas* canvas1, const SkCanvas* canvas2, |
| CanvasTestStep* testStep) { |
| REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| canvas2->getDeviceSize(), testStep->assertMessage()); |
| @@ -675,12 +686,13 @@ private: |
| }; |
| static void TestPdfDevice(skiatest::Reporter* reporter, |
| + const TestData& testData, |
| CanvasTestStep* testStep) { |
| - SkISize pageSize = SkISize::Make(kWidth, kHeight); |
| + SkISize pageSize = SkISize::Make(testData.fWidth, testData.fHeight); |
| SkPDFDevice device(pageSize, pageSize, SkMatrix::I()); |
| SkCanvas canvas(&device); |
| testStep->setAssertMessageFormat(kPdfAssertMessageFormat); |
| - testStep->draw(&canvas, reporter); |
| + testStep->draw(&canvas, testData, reporter); |
| SkPDFDocument doc; |
| doc.appendPage(&device); |
| SkDynamicMemoryWStream stream; |
| @@ -693,6 +705,7 @@ class SkDeferredCanvasTester { |
| public: |
| static void TestDeferredCanvasStateConsistency( |
| skiatest::Reporter* reporter, |
| + const TestData& testData, |
| CanvasTestStep* testStep, |
| const SkCanvas& referenceCanvas, bool silent) { |
| @@ -700,10 +713,9 @@ public: |
| SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(surface.get())); |
| testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat); |
| - testStep->draw(deferredCanvas, reporter); |
| + testStep->draw(deferredCanvas, testData, reporter); |
| testStep->setAssertMessageFormat(kDeferredPreFlushAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, deferredCanvas, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, deferredCanvas, &referenceCanvas, testStep); |
| if (silent) { |
| deferredCanvas->silentFlush(); |
| @@ -714,9 +726,8 @@ public: |
| testStep->setAssertMessageFormat( |
| silent ? kDeferredPostSilentFlushPlaybackAssertMessageFormat : |
| kDeferredPostFlushPlaybackAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, |
| - deferredCanvas->immediateCanvas(), |
| - &referenceCanvas, testStep); |
| + AssertCanvasStatesEqual(reporter, testData, deferredCanvas->immediateCanvas(), |
| + &referenceCanvas, testStep); |
| // Verified that deferred canvas state is not affected by flushing |
| // pending draw operations |
| @@ -734,6 +745,7 @@ public: |
| // unused |
| static void TestProxyCanvasStateConsistency( |
| skiatest::Reporter* reporter, |
| + const TestData& testData, |
| CanvasTestStep* testStep, |
| const SkCanvas& referenceCanvas) { |
| @@ -742,20 +754,19 @@ static void TestProxyCanvasStateConsistency( |
| SkCanvas indirectCanvas(indirectStore); |
| SkProxyCanvas proxyCanvas(&indirectCanvas); |
| testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat); |
| - testStep->draw(&proxyCanvas, reporter); |
| + testStep->draw(&proxyCanvas, testData, reporter); |
| // Verify that the SkProxyCanvas reports consitent state |
| testStep->setAssertMessageFormat(kProxyStateAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, &proxyCanvas, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, &proxyCanvas, &referenceCanvas, testStep); |
| // Verify that the indirect canvas reports consitent state |
| testStep->setAssertMessageFormat(kProxyIndirectStateAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, &indirectCanvas, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, &indirectCanvas, &referenceCanvas, testStep); |
| } |
| // unused |
| static void TestNWayCanvasStateConsistency( |
| skiatest::Reporter* reporter, |
| + const TestData& testData, |
| CanvasTestStep* testStep, |
| const SkCanvas& referenceCanvas) { |
| @@ -773,18 +784,15 @@ static void TestNWayCanvasStateConsistency( |
| nWayCanvas.addCanvas(&indirectCanvas2); |
| testStep->setAssertMessageFormat(kNWayDrawAssertMessageFormat); |
| - testStep->draw(&nWayCanvas, reporter); |
| + testStep->draw(&nWayCanvas, testData, reporter); |
| // Verify that the SkProxyCanvas reports consitent state |
| testStep->setAssertMessageFormat(kNWayStateAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, &nWayCanvas, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, &nWayCanvas, &referenceCanvas, testStep); |
| // Verify that the indirect canvases report consitent state |
| testStep->setAssertMessageFormat(kNWayIndirect1StateAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, &indirectCanvas1, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, &indirectCanvas1, &referenceCanvas, testStep); |
| testStep->setAssertMessageFormat(kNWayIndirect2StateAssertMessageFormat); |
| - AssertCanvasStatesEqual(reporter, &indirectCanvas2, &referenceCanvas, |
| - testStep); |
| + AssertCanvasStatesEqual(reporter, testData, &indirectCanvas2, &referenceCanvas, testStep); |
| } |
| /* |
| @@ -793,17 +801,17 @@ static void TestNWayCanvasStateConsistency( |
| * that the all canvas derivatives report the same state as an SkCanvas |
| * after having executed the test step. |
| */ |
| -static void TestOverrideStateConsistency(skiatest::Reporter* reporter, |
| +static void TestOverrideStateConsistency(skiatest::Reporter* reporter, const TestData& testData, |
| CanvasTestStep* testStep) { |
| SkBitmap referenceStore; |
| createBitmap(&referenceStore, 0xFFFFFFFF); |
| SkCanvas referenceCanvas(referenceStore); |
| testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat); |
| - testStep->draw(&referenceCanvas, reporter); |
| + testStep->draw(&referenceCanvas, testData, reporter); |
| - SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas, false); |
| + SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testData, testStep, referenceCanvas, false); |
| - SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testStep, referenceCanvas, true); |
| + SkDeferredCanvasTester::TestDeferredCanvasStateConsistency(reporter, testData, testStep, referenceCanvas, true); |
| // The following test code is disabled because SkProxyCanvas is |
| // missing a lot of virtual overrides on get* methods, which are used |
| @@ -811,7 +819,7 @@ static void TestOverrideStateConsistency(skiatest::Reporter* reporter, |
| // Issue: http://code.google.com/p/skia/issues/detail?id=500 |
| if (false) { // avoid bit rot, suppress warning |
| - TestProxyCanvasStateConsistency(reporter, testStep, referenceCanvas); |
| + TestProxyCanvasStateConsistency(reporter, testData, testStep, referenceCanvas); |
| } |
| // The following test code is disabled because SkNWayCanvas does not |
| @@ -819,7 +827,7 @@ static void TestOverrideStateConsistency(skiatest::Reporter* reporter, |
| // Issue: http://code.google.com/p/skia/issues/detail?id=501 |
| if (false) { // avoid bit rot, suppress warning |
| - TestNWayCanvasStateConsistency(reporter, testStep, referenceCanvas); |
| + TestNWayCanvasStateConsistency(reporter, testData, testStep, referenceCanvas); |
| } |
| if (false) { // avoid bit rot, suppress warning |
| @@ -867,17 +875,18 @@ static void test_newraster(skiatest::Reporter* reporter) { |
| DEF_TEST(Canvas, reporter) { |
| // Init global here because bitmap pixels cannot be alocated during |
| // static initialization |
| - kTestBitmap = testBitmap(); |
| +// kTestBitmap = testBitmap(); |
|
reed1
2014/10/02 19:53:06
can we remove this // line?
Rémi Piotaix
2014/10/02 20:02:26
Done.
|
| + TestData testData; |
| for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
| - TestOverrideStateConsistency(reporter, testStepArray()[testStep]); |
| + TestOverrideStateConsistency(reporter, testData, testStepArray()[testStep]); |
| if (testStepArray()[testStep]->enablePdfTesting()) { |
| - TestPdfDevice(reporter, testStepArray()[testStep]); |
| + TestPdfDevice(reporter, testData, testStepArray()[testStep]); |
| } |
| } |
| // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap is a global) |
| - kTestBitmap.reset(); |
| +// kTestBitmap.reset(); |
|
reed1
2014/10/02 19:53:06
can we remove this reset()?
Rémi Piotaix
2014/10/02 20:02:26
Done.
|
| test_newraster(reporter); |
| } |