Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* Description: | 8 /* Description: |
| 9 * This test defines a series of elementatry test steps that perform | 9 * This test defines a series of elementatry test steps that perform |
| 10 * a single or a small group of canvas API calls. Each test step is | 10 * a single or a small group of canvas API calls. Each test step is |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 static const char* const kProxyIndirectStateAssertMessageFormat = | 144 static const char* const kProxyIndirectStateAssertMessageFormat = |
| 145 "test step %s, SkProxyCanvas indirect canvas state consistency"; | 145 "test step %s, SkProxyCanvas indirect canvas state consistency"; |
| 146 static const char* const kNWayStateAssertMessageFormat = | 146 static const char* const kNWayStateAssertMessageFormat = |
| 147 "test step %s, SkNWayCanvas state consistency"; | 147 "test step %s, SkNWayCanvas state consistency"; |
| 148 static const char* const kNWayIndirect1StateAssertMessageFormat = | 148 static const char* const kNWayIndirect1StateAssertMessageFormat = |
| 149 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; | 149 "test step %s, SkNWayCanvas indirect canvas 1 state consistency"; |
| 150 static const char* const kNWayIndirect2StateAssertMessageFormat = | 150 static const char* const kNWayIndirect2StateAssertMessageFormat = |
| 151 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; | 151 "test step %s, SkNWayCanvas indirect canvas 2 state consistency"; |
| 152 static const char* const kPdfAssertMessageFormat = | 152 static const char* const kPdfAssertMessageFormat = |
| 153 "PDF sanity check failed %s"; | 153 "PDF sanity check failed %s"; |
| 154 | 154 |
|
robertphillips
2014/09/29 17:07:55
create_bitmap ?
Rémi Piotaix
2014/09/29 17:57:55
Done.
| |
| 155 static void createBitmap(SkBitmap* bm, SkColor color) { | 155 static void createBitmap(SkBitmap* bm, SkColor color) { |
| 156 bm->allocN32Pixels(kWidth, kHeight); | 156 bm->allocN32Pixels(kWidth, kHeight); |
| 157 bm->eraseColor(color); | 157 bm->eraseColor(color); |
| 158 } | 158 } |
| 159 | 159 |
|
robertphillips
2014/09/29 17:07:55
create_surface ?
Rémi Piotaix
2014/09/29 17:57:55
Done.
| |
| 160 static SkSurface* createSurface(SkColor color) { | 160 static SkSurface* createSurface(SkColor color) { |
| 161 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); | 161 SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight); |
| 162 surface->getCanvas()->clear(color); | 162 surface->getCanvas()->clear(color); |
| 163 return surface; | 163 return surface; |
| 164 } | 164 } |
| 165 | 165 |
| 166 class CanvasTestStep; | 166 class CanvasTestStep; |
| 167 static SkTDArray<CanvasTestStep*>& testStepArray() { | 167 static SkTDArray<CanvasTestStep*>& testStepArray() { |
| 168 static SkTDArray<CanvasTestStep*> theTests; | 168 static SkTDArray<CanvasTestStep*> theTests; |
| 169 return theTests; | 169 return theTests; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 { SkIntToScalar(2), SkIntToScalar(1) }, | 260 { SkIntToScalar(2), SkIntToScalar(1) }, |
| 261 { SkIntToScalar(3), SkIntToScalar(1) }, | 261 { SkIntToScalar(3), SkIntToScalar(1) }, |
| 262 { SkIntToScalar(4), SkIntToScalar(1) }, | 262 { SkIntToScalar(4), SkIntToScalar(1) }, |
| 263 { SkIntToScalar(5), SkIntToScalar(1) }, | 263 { SkIntToScalar(5), SkIntToScalar(1) }, |
| 264 { SkIntToScalar(6), SkIntToScalar(1) }, | 264 { SkIntToScalar(6), SkIntToScalar(1) }, |
| 265 { SkIntToScalar(7), SkIntToScalar(1) }, | 265 { SkIntToScalar(7), SkIntToScalar(1) }, |
| 266 { SkIntToScalar(8), SkIntToScalar(1) }, | 266 { SkIntToScalar(8), SkIntToScalar(1) }, |
| 267 { SkIntToScalar(9), SkIntToScalar(1) }, | 267 { SkIntToScalar(9), SkIntToScalar(1) }, |
| 268 { SkIntToScalar(10), SkIntToScalar(1) }, | 268 { SkIntToScalar(10), SkIntToScalar(1) }, |
| 269 }; | 269 }; |
| 270 | 270 SkSurface* kTestSurface; |
| 271 SkImage* kTestImage; | |
| 271 | 272 |
| 272 /////////////////////////////////////////////////////////////////////////////// | 273 /////////////////////////////////////////////////////////////////////////////// |
| 273 // Macros for defining test steps | 274 // Macros for defining test steps |
| 274 | 275 |
| 275 #define TEST_STEP(NAME, FUNCTION) \ | 276 #define TEST_STEP(NAME, FUNCTION) \ |
| 276 class NAME##_TestStep : public CanvasTestStep{ \ | 277 class NAME##_TestStep : public CanvasTestStep{ \ |
| 277 public: \ | 278 public: \ |
| 278 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ | 279 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| 279 FUNCTION (canvas, reporter, this); \ | 280 FUNCTION (canvas, reporter, this); \ |
| 280 } \ | 281 } \ |
| 281 virtual const char* name() const {return #NAME ;} \ | 282 virtual const char* name() const {return #NAME ;} \ |
| 282 }; \ | 283 }; \ |
| 283 static NAME##_TestStep NAME##_TestStepInstance; | 284 static NAME##_TestStep NAME##_TestStepInstance; |
| 284 | 285 |
| 285 #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ | 286 #define TEST_STEP_NO_PDF(NAME, FUNCTION) \ |
| 286 class NAME##_TestStep : public CanvasTestStep{ \ | 287 class NAME##_TestStep : public CanvasTestStep{ \ |
| 287 public: \ | 288 public: \ |
| 288 NAME##_TestStep() : CanvasTestStep(false) {} \ | 289 NAME##_TestStep() : CanvasTestStep(false) {} \ |
| 289 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ | 290 virtual void draw(SkCanvas* canvas, skiatest::Reporter* reporter) { \ |
| 290 FUNCTION (canvas, reporter, this); \ | 291 FUNCTION (canvas, reporter, this); \ |
| 291 } \ | 292 } \ |
| 292 virtual const char* name() const {return #NAME ;} \ | 293 virtual const char* name() const {return #NAME ;} \ |
| 293 }; \ | 294 }; \ |
| 294 static NAME##_TestStep NAME##_TestStepInstance; | 295 static NAME##_TestStep NAME##_TestStepInstance; |
| 295 | 296 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), | 357 SIMPLE_TEST_STEP(DrawPosText, drawPosText(kTestText.c_str(), |
| 357 kTestText.size(), kTestPoints2, kTestPaint)); | 358 kTestText.size(), kTestPoints2, kTestPaint)); |
| 358 SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), | 359 SIMPLE_TEST_STEP(DrawTextOnPath, drawTextOnPath(kTestText.c_str(), |
| 359 kTestText.size(), kTestPath, NULL, kTestPaint)); | 360 kTestText.size(), kTestPath, NULL, kTestPaint)); |
| 360 SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), | 361 SIMPLE_TEST_STEP(DrawTextOnPathMatrix, drawTextOnPath(kTestText.c_str(), |
| 361 kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); | 362 kTestText.size(), kTestPath, &kTestMatrix, kTestPaint)); |
| 362 SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); | 363 SIMPLE_TEST_STEP(DrawData, drawData(kTestText.c_str(), kTestText.size())); |
| 363 SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); | 364 SIMPLE_TEST_STEP(BeginGroup, beginCommentGroup(kTestText.c_str())); |
| 364 SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); | 365 SIMPLE_TEST_STEP(AddComment, addComment(kTestText.c_str(), kTestText.c_str())); |
| 365 SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); | 366 SIMPLE_TEST_STEP(EndGroup, endCommentGroup()); |
| 367 SIMPLE_TEST_STEP(DrawImage, drawImage(kTestImage, 0, 0)); | |
| 368 SIMPLE_TEST_STEP(DrawImageRect, drawImageRect(kTestImage, 0, SkRect::MakeWH(kWid th, kHeight))); | |
| 366 | 369 |
| 367 /////////////////////////////////////////////////////////////////////////////// | 370 /////////////////////////////////////////////////////////////////////////////// |
| 368 // Complex test steps | 371 // Complex test steps |
| 369 | 372 |
| 370 static void SaveMatrixClipStep(SkCanvas* canvas, | 373 static void SaveMatrixClipStep(SkCanvas* canvas, |
| 371 skiatest::Reporter* reporter, | 374 skiatest::Reporter* reporter, |
| 372 CanvasTestStep* testStep) { | 375 CanvasTestStep* testStep) { |
| 373 int saveCount = canvas->getSaveCount(); | 376 int saveCount = canvas->getSaveCount(); |
| 374 canvas->save(); | 377 canvas->save(); |
| 375 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); | 378 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, | 459 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
| 457 NULL, NULL, NULL, 0, paint); | 460 NULL, NULL, NULL, 0, paint); |
| 458 } | 461 } |
| 459 // NYI: issue 240. | 462 // NYI: issue 240. |
| 460 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); | 463 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
| 461 | 464 |
| 462 static void DrawPictureTestStep(SkCanvas* canvas, | 465 static void DrawPictureTestStep(SkCanvas* canvas, |
| 463 skiatest::Reporter*, | 466 skiatest::Reporter*, |
| 464 CanvasTestStep*) { | 467 CanvasTestStep*) { |
| 465 SkPictureRecorder recorder; | 468 SkPictureRecorder recorder; |
| 466 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight), | 469 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight), |
| 467 NULL, 0); | 470 NULL, 0); |
| 468 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); | 471 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
| 469 testCanvas->clipRect(kTestRect); | 472 testCanvas->clipRect(kTestRect); |
| 470 testCanvas->drawRect(kTestRect, kTestPaint); | 473 testCanvas->drawRect(kTestRect, kTestPaint); |
| 471 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); | 474 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); |
| 472 | 475 |
| 473 canvas->drawPicture(testPicture); | 476 canvas->drawPicture(testPicture); |
| 474 } | 477 } |
| 475 TEST_STEP(DrawPicture, DrawPictureTestStep); | 478 TEST_STEP(DrawPicture, DrawPictureTestStep); |
| 476 | 479 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 public: | 685 public: |
| 683 | 686 |
| 684 static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter, | 687 static void TestPictureFlattenedObjectReuse(skiatest::Reporter* reporter, |
| 685 CanvasTestStep* testStep, | 688 CanvasTestStep* testStep, |
| 686 uint32_t recordFlags) { | 689 uint32_t recordFlags) { |
| 687 // Verify that when a test step is executed twice, no extra resources | 690 // Verify that when a test step is executed twice, no extra resources |
| 688 // are flattened during the second execution | 691 // are flattened during the second execution |
| 689 testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat); | 692 testStep->setAssertMessageFormat(kPictureDrawAssertMessageFormat); |
| 690 SkPictureRecorder referenceRecorder; | 693 SkPictureRecorder referenceRecorder; |
| 691 SkCanvas* referenceCanvas = | 694 SkCanvas* referenceCanvas = |
| 692 referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth), | 695 referenceRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth), |
| 693 SkIntToScalar(kHeight), | 696 SkIntToScalar(kHeight), |
| 694 NULL, recordFlags); | 697 NULL, recordFlags); |
| 695 testStep->draw(referenceCanvas, reporter); | 698 testStep->draw(referenceCanvas, reporter); |
| 696 | 699 |
| 697 SkPictureRecorder testRecorder; | 700 SkPictureRecorder testRecorder; |
| 698 SkCanvas* testCanvas = | 701 SkCanvas* testCanvas = |
| 699 testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth), | 702 testRecorder.DEPRECATED_beginRecording(SkIntToScalar(kWidth), |
| 700 SkIntToScalar(kHeight), | 703 SkIntToScalar(kHeight), |
| 701 NULL, recordFlags); | 704 NULL, recordFlags); |
| 702 testStep->draw(testCanvas, reporter); | 705 testStep->draw(testCanvas, reporter); |
| 703 testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat); | 706 testStep->setAssertMessageFormat(kPictureSecondDrawAssertMessageFormat); |
| 704 testStep->draw(testCanvas, reporter); | 707 testStep->draw(testCanvas, reporter); |
| 705 | 708 |
| 706 SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(referen ceCanvas); | 709 SkPictureRecord* referenceRecord = static_cast<SkPictureRecord*>(referen ceCanvas); |
| 707 SkPictureRecord* testRecord = static_cast<SkPictureRecord*>(testCanvas); | 710 SkPictureRecord* testRecord = static_cast<SkPictureRecord*>(testCanvas); |
| 708 testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat); | 711 testStep->setAssertMessageFormat(kPictureResourceReuseMessageFormat); |
| 709 AssertFlattenedObjectsEqual(referenceRecord, testRecord, | 712 AssertFlattenedObjectsEqual(referenceRecord, testRecord, |
| 710 reporter, testStep); | 713 reporter, testStep); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 info = SkImageInfo::MakeN32Premul(0, 0); | 901 info = SkImageInfo::MakeN32Premul(0, 0); |
| 899 canvas = SkCanvas::NewRaster(info); | 902 canvas = SkCanvas::NewRaster(info); |
| 900 REPORTER_ASSERT(reporter, canvas); | 903 REPORTER_ASSERT(reporter, canvas); |
| 901 SkDELETE(canvas); | 904 SkDELETE(canvas); |
| 902 } | 905 } |
| 903 | 906 |
| 904 DEF_TEST(Canvas, reporter) { | 907 DEF_TEST(Canvas, reporter) { |
| 905 // Init global here because bitmap pixels cannot be alocated during | 908 // Init global here because bitmap pixels cannot be alocated during |
| 906 // static initialization | 909 // static initialization |
| 907 kTestBitmap = testBitmap(); | 910 kTestBitmap = testBitmap(); |
| 911 kTestSurface = createSurface(SK_ColorGREEN); | |
| 912 kTestImage = kTestSurface->newImageSnapshot(); | |
| 908 | 913 |
| 909 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 914 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
| 910 TestOverrideStateConsistency(reporter, testStepArray()[testStep]); | 915 TestOverrideStateConsistency(reporter, testStepArray()[testStep]); |
| 911 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, | 916 SkPictureTester::TestPictureFlattenedObjectReuse(reporter, |
| 912 testStepArray()[testStep], 0); | 917 testStepArray()[testStep], 0); |
| 913 if (testStepArray()[testStep]->enablePdfTesting()) { | 918 if (testStepArray()[testStep]->enablePdfTesting()) { |
| 914 TestPdfDevice(reporter, testStepArray()[testStep]); | 919 TestPdfDevice(reporter, testStepArray()[testStep]); |
| 915 } | 920 } |
| 916 } | 921 } |
| 917 | 922 |
| 918 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i s a global) | 923 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i s a global) |
| 919 kTestBitmap.reset(); | 924 kTestBitmap.reset(); |
| 925 kTestSurface->unref(); | |
| 926 kTestImage->unref(); | |
| 920 | 927 |
| 921 test_newraster(reporter); | 928 test_newraster(reporter); |
| 922 } | 929 } |
| OLD | NEW |