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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 Canvas2CanvasClipVisitor visitor(&c); | 209 Canvas2CanvasClipVisitor visitor(&c); |
210 canvas->replayClips(&visitor); | 210 canvas->replayClips(&visitor); |
211 | 211 |
212 REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); | 212 REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); |
213 } | 213 } |
214 | 214 |
215 static void test_clipstack(skiatest::Reporter* reporter) { | 215 static void test_clipstack(skiatest::Reporter* reporter) { |
216 // The clipstack is refcounted, and needs to be able to out-live the canvas
if a client has | 216 // The clipstack is refcounted, and needs to be able to out-live the canvas
if a client has |
217 // ref'd it. | 217 // ref'd it. |
218 const SkClipStack* cs = NULL; | 218 const SkClipStack* cs = nullptr; |
219 { | 219 { |
220 SkCanvas canvas(10, 10); | 220 SkCanvas canvas(10, 10); |
221 cs = SkRef(canvas.getClipStack()); | 221 cs = SkRef(canvas.getClipStack()); |
222 } | 222 } |
223 REPORTER_ASSERT(reporter, cs->unique()); | 223 REPORTER_ASSERT(reporter, cs->unique()); |
224 cs->unref(); | 224 cs->unref(); |
225 } | 225 } |
226 | 226 |
227 // Format strings that describe the test context. The %s token is where | 227 // Format strings that describe the test context. The %s token is where |
228 // the name of the test step is inserted. The context is required for | 228 // the name of the test step is inserted. The context is required for |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 testStep->assertMessage()); | 349 testStep->assertMessage()); |
350 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), | 350 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
351 testStep->assertMessage()); | 351 testStep->assertMessage()); |
352 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t
estStep->assertMessage()); | 352 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t
estStep->assertMessage()); |
353 } | 353 } |
354 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); | 354 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
355 | 355 |
356 static void SaveLayerStep(SkCanvas* canvas, const TestData& d, | 356 static void SaveLayerStep(SkCanvas* canvas, const TestData& d, |
357 skiatest::Reporter* reporter, CanvasTestStep* testStep
) { | 357 skiatest::Reporter* reporter, CanvasTestStep* testStep
) { |
358 int saveCount = canvas->getSaveCount(); | 358 int saveCount = canvas->getSaveCount(); |
359 canvas->saveLayer(NULL, NULL); | 359 canvas->saveLayer(nullptr, nullptr); |
360 canvas->restore(); | 360 canvas->restore(); |
361 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 361 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
362 testStep->assertMessage()); | 362 testStep->assertMessage()); |
363 } | 363 } |
364 TEST_STEP(SaveLayer, SaveLayerStep); | 364 TEST_STEP(SaveLayer, SaveLayerStep); |
365 | 365 |
366 static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& d, | 366 static void BoundedSaveLayerStep(SkCanvas* canvas, const TestData& d, |
367 skiatest::Reporter* reporter, CanvasTestStep* t
estStep) { | 367 skiatest::Reporter* reporter, CanvasTestStep* t
estStep) { |
368 int saveCount = canvas->getSaveCount(); | 368 int saveCount = canvas->getSaveCount(); |
369 canvas->saveLayer(&d.fRect, NULL); | 369 canvas->saveLayer(&d.fRect, nullptr); |
370 canvas->restore(); | 370 canvas->restore(); |
371 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 371 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
372 testStep->assertMessage()); | 372 testStep->assertMessage()); |
373 } | 373 } |
374 TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); | 374 TEST_STEP(BoundedSaveLayer, BoundedSaveLayerStep); |
375 | 375 |
376 static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& d, | 376 static void PaintSaveLayerStep(SkCanvas* canvas, const TestData& d, |
377 skiatest::Reporter* reporter, CanvasTestStep* tes
tStep) { | 377 skiatest::Reporter* reporter, CanvasTestStep* tes
tStep) { |
378 int saveCount = canvas->getSaveCount(); | 378 int saveCount = canvas->getSaveCount(); |
379 canvas->saveLayer(NULL, &d.fPaint); | 379 canvas->saveLayer(nullptr, &d.fPaint); |
380 canvas->restore(); | 380 canvas->restore(); |
381 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 381 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
382 testStep->assertMessage()); | 382 testStep->assertMessage()); |
383 } | 383 } |
384 TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); | 384 TEST_STEP(PaintSaveLayer, PaintSaveLayerStep); |
385 | 385 |
386 static void TwoClipOpsStep(SkCanvas* canvas, const TestData& d, | 386 static void TwoClipOpsStep(SkCanvas* canvas, const TestData& d, |
387 skiatest::Reporter*, CanvasTestStep*) { | 387 skiatest::Reporter*, CanvasTestStep*) { |
388 // This test exercises a functionality in SkPicture that leads to the | 388 // This test exercises a functionality in SkPicture that leads to the |
389 // recording of restore offset placeholders. This test will trigger an | 389 // recording of restore offset placeholders. This test will trigger an |
(...skipping 21 matching lines...) Expand all Loading... |
411 SkPoint pts[4]; | 411 SkPoint pts[4]; |
412 pts[0].set(0, 0); | 412 pts[0].set(0, 0); |
413 pts[1].set(SkIntToScalar(d.fWidth), 0); | 413 pts[1].set(SkIntToScalar(d.fWidth), 0); |
414 pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight)); | 414 pts[2].set(SkIntToScalar(d.fWidth), SkIntToScalar(d.fHeight)); |
415 pts[3].set(0, SkIntToScalar(d.fHeight)); | 415 pts[3].set(0, SkIntToScalar(d.fHeight)); |
416 SkPaint paint; | 416 SkPaint paint; |
417 SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap, | 417 SkShader* shader = SkShader::CreateBitmapShader(d.fBitmap, |
418 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); | 418 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
419 paint.setShader(shader)->unref(); | 419 paint.setShader(shader)->unref(); |
420 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, | 420 canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, 4, pts, pts, |
421 NULL, NULL, NULL, 0, paint); | 421 nullptr, nullptr, nullptr, 0, paint); |
422 } | 422 } |
423 // NYI: issue 240. | 423 // NYI: issue 240. |
424 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); | 424 TEST_STEP_NO_PDF(DrawVerticesShader, DrawVerticesShaderTestStep); |
425 | 425 |
426 static void DrawPictureTestStep(SkCanvas* canvas, const TestData& d, | 426 static void DrawPictureTestStep(SkCanvas* canvas, const TestData& d, |
427 skiatest::Reporter*, CanvasTestStep*) { | 427 skiatest::Reporter*, CanvasTestStep*) { |
428 SkPictureRecorder recorder; | 428 SkPictureRecorder recorder; |
429 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(d.fWidth), SkIn
tToScalar(d.fHeight), | 429 SkCanvas* testCanvas = recorder.beginRecording(SkIntToScalar(d.fWidth), SkIn
tToScalar(d.fHeight), |
430 NULL, 0); | 430 nullptr, 0); |
431 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); | 431 testCanvas->scale(SkIntToScalar(2), SkIntToScalar(1)); |
432 testCanvas->clipRect(d.fRect); | 432 testCanvas->clipRect(d.fRect); |
433 testCanvas->drawRect(d.fRect, d.fPaint); | 433 testCanvas->drawRect(d.fRect, d.fPaint); |
434 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); | 434 SkAutoTUnref<SkPicture> testPicture(recorder.endRecording()); |
435 | 435 |
436 canvas->drawPicture(testPicture); | 436 canvas->drawPicture(testPicture); |
437 } | 437 } |
438 TEST_STEP(DrawPicture, DrawPictureTestStep); | 438 TEST_STEP(DrawPicture, DrawPictureTestStep); |
439 | 439 |
440 static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& d, | 440 static void SaveRestoreTestStep(SkCanvas* canvas, const TestData& d, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 for (int y = 0; y < info.height(); ++y) { | 651 for (int y = 0; y < info.height(); ++y) { |
652 for (int x = 0; x < info.width(); ++x) { | 652 for (int x = 0; x < info.width(); ++x) { |
653 REPORTER_ASSERT(reporter, 0 == addr[x]); | 653 REPORTER_ASSERT(reporter, 0 == addr[x]); |
654 } | 654 } |
655 addr = (const SkPMColor*)((const char*)addr + rowBytes); | 655 addr = (const SkPMColor*)((const char*)addr + rowBytes); |
656 } | 656 } |
657 delete canvas; | 657 delete canvas; |
658 | 658 |
659 // now try a deliberately bad info | 659 // now try a deliberately bad info |
660 info = info.makeWH(-1, info.height()); | 660 info = info.makeWH(-1, info.height()); |
661 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 661 REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAdd
r, minRowBytes)); |
662 | 662 |
663 // too big | 663 // too big |
664 info = info.makeWH(1 << 30, 1 << 30); | 664 info = info.makeWH(1 << 30, 1 << 30); |
665 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 665 REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAdd
r, minRowBytes)); |
666 | 666 |
667 // not a valid pixel type | 667 // not a valid pixel type |
668 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); | 668 info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType()); |
669 REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr,
minRowBytes)); | 669 REPORTER_ASSERT(reporter, nullptr == SkCanvas::NewRasterDirect(info, baseAdd
r, minRowBytes)); |
670 | 670 |
671 // We should succeed with a zero-sized valid info | 671 // We should succeed with a zero-sized valid info |
672 info = SkImageInfo::MakeN32Premul(0, 0); | 672 info = SkImageInfo::MakeN32Premul(0, 0); |
673 canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); | 673 canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes); |
674 REPORTER_ASSERT(reporter, canvas); | 674 REPORTER_ASSERT(reporter, canvas); |
675 delete canvas; | 675 delete canvas; |
676 } | 676 } |
677 | 677 |
678 DEF_TEST(Canvas, reporter) { | 678 DEF_TEST(Canvas, reporter) { |
679 TestData d; | 679 TestData d; |
680 | 680 |
681 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { | 681 for (int testStep = 0; testStep < testStepArray().count(); testStep++) { |
682 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); | 682 TestOverrideStateConsistency(reporter, d, testStepArray()[testStep]); |
683 if (testStepArray()[testStep]->enablePdfTesting()) { | 683 if (testStepArray()[testStep]->enablePdfTesting()) { |
684 TestPdfDevice(reporter, d, testStepArray()[testStep]); | 684 TestPdfDevice(reporter, d, testStepArray()[testStep]); |
685 } | 685 } |
686 } | 686 } |
687 | 687 |
688 test_newraster(reporter); | 688 test_newraster(reporter); |
689 } | 689 } |
690 | 690 |
691 DEF_TEST(Canvas_SaveState, reporter) { | 691 DEF_TEST(Canvas_SaveState, reporter) { |
692 SkCanvas canvas(10, 10); | 692 SkCanvas canvas(10, 10); |
693 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); | 693 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
694 | 694 |
695 int n = canvas.save(); | 695 int n = canvas.save(); |
696 REPORTER_ASSERT(reporter, 1 == n); | 696 REPORTER_ASSERT(reporter, 1 == n); |
697 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); | 697 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
698 | 698 |
699 n = canvas.saveLayer(NULL, NULL); | 699 n = canvas.saveLayer(nullptr, nullptr); |
700 REPORTER_ASSERT(reporter, 2 == n); | 700 REPORTER_ASSERT(reporter, 2 == n); |
701 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); | 701 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); |
702 | 702 |
703 canvas.restore(); | 703 canvas.restore(); |
704 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); | 704 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
705 canvas.restore(); | 705 canvas.restore(); |
706 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); | 706 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
707 } | 707 } |
708 | 708 |
709 DEF_TEST(Canvas_ClipEmptyPath, reporter) { | 709 DEF_TEST(Canvas_ClipEmptyPath, reporter) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 749 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
750 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 750 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
751 REPORTER_ASSERT(reporter, clip1 == clip2); | 751 REPORTER_ASSERT(reporter, clip1 == clip2); |
752 | 752 |
753 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 753 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
754 filterCanvas.scale(0.75f, 0.5f); | 754 filterCanvas.scale(0.75f, 0.5f); |
755 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 755 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
756 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 756 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
757 REPORTER_ASSERT(reporter, clip1 == clip2); | 757 REPORTER_ASSERT(reporter, clip1 == clip2); |
758 } | 758 } |
OLD | NEW |