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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #include "SkPictureRecord.h" | 57 #include "SkPictureRecord.h" |
58 #include "SkProxyCanvas.h" | 58 #include "SkProxyCanvas.h" |
59 #include "SkRect.h" | 59 #include "SkRect.h" |
60 #include "SkRegion.h" | 60 #include "SkRegion.h" |
61 #include "SkShader.h" | 61 #include "SkShader.h" |
62 #include "SkStream.h" | 62 #include "SkStream.h" |
63 #include "SkSurface.h" | 63 #include "SkSurface.h" |
64 #include "SkTDArray.h" | 64 #include "SkTDArray.h" |
65 #include "Test.h" | 65 #include "Test.h" |
66 | 66 |
| 67 static bool equal_clips(const SkCanvas& a, const SkCanvas& b) { |
| 68 if (a.isClipEmpty()) { |
| 69 return b.isClipEmpty(); |
| 70 } |
| 71 if (!a.isClipRect()) { |
| 72 // this is liberally true, since we don't expose a way to know this exac
tly (for non-rects) |
| 73 return !b.isClipRect(); |
| 74 } |
| 75 SkIRect ar, br; |
| 76 a.getClipDeviceBounds(&ar); |
| 77 b.getClipDeviceBounds(&br); |
| 78 return ar == br; |
| 79 } |
| 80 |
67 class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor { | 81 class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor { |
68 public: | 82 public: |
69 Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {} | 83 Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {} |
70 | 84 |
71 virtual void clipRect(const SkRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE
{ | 85 virtual void clipRect(const SkRect& r, SkRegion::Op op, bool aa) SK_OVERRIDE
{ |
72 fTarget->clipRect(r, op, aa); | 86 fTarget->clipRect(r, op, aa); |
73 } | 87 } |
74 virtual void clipRRect(const SkRRect& r, SkRegion::Op op, bool aa) SK_OVERRI
DE { | 88 virtual void clipRRect(const SkRRect& r, SkRegion::Op op, bool aa) SK_OVERRI
DE { |
75 fTarget->clipRRect(r, op, aa); | 89 fTarget->clipRRect(r, op, aa); |
76 } | 90 } |
77 virtual void clipPath(const SkPath& p, SkRegion::Op op, bool aa) SK_OVERRIDE
{ | 91 virtual void clipPath(const SkPath& p, SkRegion::Op op, bool aa) SK_OVERRIDE
{ |
78 fTarget->clipPath(p, op, aa); | 92 fTarget->clipPath(p, op, aa); |
79 } | 93 } |
80 | 94 |
81 private: | 95 private: |
82 SkCanvas* fTarget; | 96 SkCanvas* fTarget; |
83 }; | 97 }; |
84 | 98 |
85 static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { | 99 static void test_clipVisitor(skiatest::Reporter* reporter, SkCanvas* canvas) { |
86 SkISize size = canvas->getDeviceSize(); | 100 SkISize size = canvas->getDeviceSize(); |
87 | 101 |
88 SkBitmap bm; | 102 SkBitmap bm; |
89 bm.setConfig(SkImageInfo::MakeN32Premul(size.width(), size.height())); | 103 bm.setConfig(SkImageInfo::MakeN32Premul(size.width(), size.height())); |
90 SkCanvas c(bm); | 104 SkCanvas c(bm); |
91 | 105 |
92 Canvas2CanvasClipVisitor visitor(&c); | 106 Canvas2CanvasClipVisitor visitor(&c); |
93 canvas->replayClips(&visitor); | 107 canvas->replayClips(&visitor); |
94 | 108 |
95 REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip()); | 109 REPORTER_ASSERT(reporter, equal_clips(c, *canvas)); |
96 } | 110 } |
97 | 111 |
98 static const int kWidth = 2; | 112 static const int kWidth = 2; |
99 static const int kHeight = 2; | 113 static const int kHeight = 2; |
100 | 114 |
101 // Format strings that describe the test context. The %s token is where | 115 // Format strings that describe the test context. The %s token is where |
102 // the name of the test step is inserted. The context is required for | 116 // the name of the test step is inserted. The context is required for |
103 // disambiguating the error in the case of failures that are reported in | 117 // disambiguating the error in the case of failures that are reported in |
104 // functions that are called multiple times in different contexts (test | 118 // functions that are called multiple times in different contexts (test |
105 // cases and test steps). | 119 // cases and test steps). |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 CanvasTestStep* testStep) { | 376 CanvasTestStep* testStep) { |
363 int saveCount = canvas->getSaveCount(); | 377 int saveCount = canvas->getSaveCount(); |
364 canvas->save(SkCanvas::kMatrix_SaveFlag); | 378 canvas->save(SkCanvas::kMatrix_SaveFlag); |
365 canvas->clipRegion(kTestRegion); | 379 canvas->clipRegion(kTestRegion); |
366 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); | 380 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
367 canvas->restore(); | 381 canvas->restore(); |
368 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 382 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
369 testStep->assertMessage()); | 383 testStep->assertMessage()); |
370 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), | 384 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
371 testStep->assertMessage()); | 385 testStep->assertMessage()); |
372 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion, | 386 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion, t
estStep->assertMessage()); |
373 testStep->assertMessage()); | |
374 } | 387 } |
375 TEST_STEP(SaveMatrix, SaveMatrixStep); | 388 TEST_STEP(SaveMatrix, SaveMatrixStep); |
376 | 389 |
377 static void SaveClipStep(SkCanvas* canvas, | 390 static void SaveClipStep(SkCanvas* canvas, |
378 skiatest::Reporter* reporter, | 391 skiatest::Reporter* reporter, |
379 CanvasTestStep* testStep) { | 392 CanvasTestStep* testStep) { |
380 int saveCount = canvas->getSaveCount(); | 393 int saveCount = canvas->getSaveCount(); |
381 canvas->save(SkCanvas::kClip_SaveFlag); | 394 canvas->save(SkCanvas::kClip_SaveFlag); |
382 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); | 395 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
383 canvas->clipRegion(kTestRegion); | 396 canvas->clipRegion(kTestRegion); |
384 canvas->restore(); | 397 canvas->restore(); |
385 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 398 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
386 testStep->assertMessage()); | 399 testStep->assertMessage()); |
387 REPORTER_ASSERT_MESSAGE(reporter, !canvas->getTotalMatrix().isIdentity(), | 400 REPORTER_ASSERT_MESSAGE(reporter, !canvas->getTotalMatrix().isIdentity(), |
388 testStep->assertMessage()); | 401 testStep->assertMessage()); |
389 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, | 402 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t
estStep->assertMessage()); |
390 testStep->assertMessage()); | |
391 } | 403 } |
392 TEST_STEP(SaveClip, SaveClipStep); | 404 TEST_STEP(SaveClip, SaveClipStep); |
393 | 405 |
394 static void SaveMatrixClipStep(SkCanvas* canvas, | 406 static void SaveMatrixClipStep(SkCanvas* canvas, |
395 skiatest::Reporter* reporter, | 407 skiatest::Reporter* reporter, |
396 CanvasTestStep* testStep) { | 408 CanvasTestStep* testStep) { |
397 int saveCount = canvas->getSaveCount(); | 409 int saveCount = canvas->getSaveCount(); |
398 canvas->save(SkCanvas::kMatrixClip_SaveFlag); | 410 canvas->save(SkCanvas::kMatrixClip_SaveFlag); |
399 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); | 411 canvas->translate(SkIntToScalar(1), SkIntToScalar(2)); |
400 canvas->clipRegion(kTestRegion); | 412 canvas->clipRegion(kTestRegion); |
401 canvas->restore(); | 413 canvas->restore(); |
402 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 414 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
403 testStep->assertMessage()); | 415 testStep->assertMessage()); |
404 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), | 416 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(), |
405 testStep->assertMessage()); | 417 testStep->assertMessage()); |
406 REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, | 418 // REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, t
estStep->assertMessage()); |
407 testStep->assertMessage()); | |
408 } | 419 } |
409 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); | 420 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep); |
410 | 421 |
411 static void SaveLayerStep(SkCanvas* canvas, | 422 static void SaveLayerStep(SkCanvas* canvas, |
412 skiatest::Reporter* reporter, | 423 skiatest::Reporter* reporter, |
413 CanvasTestStep* testStep) { | 424 CanvasTestStep* testStep) { |
414 int saveCount = canvas->getSaveCount(); | 425 int saveCount = canvas->getSaveCount(); |
415 canvas->saveLayer(NULL, NULL); | 426 canvas->saveLayer(NULL, NULL); |
416 canvas->restore(); | 427 canvas->restore(); |
417 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, | 428 REPORTER_ASSERT_MESSAGE(reporter, canvas->getSaveCount() == saveCount, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 REPORTER_ASSERT_MESSAGE(reporter, | 632 REPORTER_ASSERT_MESSAGE(reporter, |
622 canvas1->getClipDeviceBounds(&deviceBounds1) == | 633 canvas1->getClipDeviceBounds(&deviceBounds1) == |
623 canvas2->getClipDeviceBounds(&deviceBounds2), | 634 canvas2->getClipDeviceBounds(&deviceBounds2), |
624 testStep->assertMessage()); | 635 testStep->assertMessage()); |
625 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, | 636 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, |
626 testStep->assertMessage()); | 637 testStep->assertMessage()); |
627 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getBounder() == | 638 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getBounder() == |
628 canvas2->getBounder(), testStep->assertMessage()); | 639 canvas2->getBounder(), testStep->assertMessage()); |
629 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == | 640 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == |
630 canvas2->getTotalMatrix(), testStep->assertMessage()); | 641 canvas2->getTotalMatrix(), testStep->assertMessage()); |
631 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getClipType() == | 642 REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep-
>assertMessage()); |
632 canvas2->getClipType(), testStep->assertMessage()); | |
633 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalClip() == | |
634 canvas2->getTotalClip(), testStep->assertMessage()); | |
635 | 643 |
636 // The following test code is commented out because the test fails when | 644 // The following test code is commented out because the test fails when |
637 // the canvas is an SkPictureRecord or SkDeferredCanvas | 645 // the canvas is an SkPictureRecord or SkDeferredCanvas |
638 // Issue: http://code.google.com/p/skia/issues/detail?id=498 | 646 // Issue: http://code.google.com/p/skia/issues/detail?id=498 |
639 // Also, creating a LayerIter on an SkProxyCanvas crashes | 647 // Also, creating a LayerIter on an SkProxyCanvas crashes |
640 // Issue: http://code.google.com/p/skia/issues/detail?id=499 | 648 // Issue: http://code.google.com/p/skia/issues/detail?id=499 |
641 /* | 649 /* |
642 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); | 650 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
643 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); | 651 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
644 while (!layerIter1.done() && !layerIter2.done()) { | 652 while (!layerIter1.done() && !layerIter2.done()) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (testStepArray()[testStep]->enablePdfTesting()) { | 954 if (testStepArray()[testStep]->enablePdfTesting()) { |
947 TestPdfDevice(reporter, testStepArray()[testStep]); | 955 TestPdfDevice(reporter, testStepArray()[testStep]); |
948 } | 956 } |
949 } | 957 } |
950 | 958 |
951 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) | 959 // Explicitly call reset(), so we don't leak the pixels (since kTestBitmap i
s a global) |
952 kTestBitmap.reset(); | 960 kTestBitmap.reset(); |
953 | 961 |
954 test_newraster(reporter); | 962 test_newraster(reporter); |
955 } | 963 } |
OLD | NEW |