| 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 #include "Test.h" | 7 #include "Test.h" |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkDevice.h" |
| 11 #include "SkError.h" | 12 #include "SkError.h" |
| 12 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 13 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 14 #include "SkRandom.h" | 15 #include "SkRandom.h" |
| 15 #include "SkRRect.h" | 16 #include "SkRRect.h" |
| 16 #include "SkShader.h" | 17 #include "SkShader.h" |
| 17 #include "SkStream.h" | 18 #include "SkStream.h" |
| 18 | 19 |
| 19 #include "SkPictureUtils.h" | 20 #include "SkPictureUtils.h" |
| 20 | 21 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 canvas->clipPath(path2, SkRegion::kXOR_Op); | 544 canvas->clipPath(path2, SkRegion::kXOR_Op); |
| 544 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); | 545 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); |
| 545 REPORTER_ASSERT(reporter, true == nonEmpty); | 546 REPORTER_ASSERT(reporter, true == nonEmpty); |
| 546 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); | 547 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); |
| 547 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); | 548 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); |
| 548 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); | 549 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); |
| 549 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); | 550 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); |
| 550 } | 551 } |
| 551 } | 552 } |
| 552 | 553 |
| 554 /** |
| 555 * A canvas that records the number of clip commands. |
| 556 */ |
| 557 class ClipCountingCanvas : public SkCanvas { |
| 558 public: |
| 559 explicit ClipCountingCanvas(SkDevice* device) |
| 560 : SkCanvas(device) |
| 561 , fClipCount(0){ |
| 562 } |
| 563 |
| 564 virtual bool clipRect(const SkRect& r, SkRegion::Op op, bool doAA) |
| 565 SK_OVERRIDE { |
| 566 fClipCount += 1; |
| 567 return this->INHERITED::clipRect(r, op, doAA); |
| 568 } |
| 569 |
| 570 virtual bool clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) |
| 571 SK_OVERRIDE { |
| 572 fClipCount += 1; |
| 573 return this->INHERITED::clipRRect(rrect, op, doAA); |
| 574 } |
| 575 |
| 576 virtual bool clipPath(const SkPath& path, SkRegion::Op op, bool doAA) |
| 577 SK_OVERRIDE { |
| 578 fClipCount += 1; |
| 579 return this->INHERITED::clipPath(path, op, doAA); |
| 580 } |
| 581 |
| 582 unsigned getClipCount() const { return fClipCount; } |
| 583 |
| 584 private: |
| 585 unsigned fClipCount; |
| 586 |
| 587 typedef SkCanvas INHERITED; |
| 588 }; |
| 589 |
| 590 static void test_clip_expansion(skiatest::Reporter* reporter) { |
| 591 SkPicture picture; |
| 592 SkCanvas* canvas = picture.beginRecording(10, 10, 0); |
| 593 |
| 594 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); |
| 595 // The following expanding clip should not be skipped. |
| 596 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); |
| 597 // Draw something so the optimizer doesn't just fold the world. |
| 598 SkPaint p; |
| 599 p.setColor(SK_ColorBLUE); |
| 600 canvas->drawPaint(p); |
| 601 |
| 602 SkDevice testDevice(SkBitmap::kNo_Config, 10, 10); |
| 603 ClipCountingCanvas testCanvas(&testDevice); |
| 604 picture.draw(&testCanvas); |
| 605 |
| 606 // Both clips should be present on playback. |
| 607 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); |
| 608 } |
| 609 |
| 553 static void TestPicture(skiatest::Reporter* reporter) { | 610 static void TestPicture(skiatest::Reporter* reporter) { |
| 554 #ifdef SK_DEBUG | 611 #ifdef SK_DEBUG |
| 555 test_deleting_empty_playback(); | 612 test_deleting_empty_playback(); |
| 556 test_serializing_empty_picture(); | 613 test_serializing_empty_picture(); |
| 557 #else | 614 #else |
| 558 test_bad_bitmap(); | 615 test_bad_bitmap(); |
| 559 #endif | 616 #endif |
| 560 test_peephole(); | 617 test_peephole(); |
| 561 test_gatherpixelrefs(reporter); | 618 test_gatherpixelrefs(reporter); |
| 562 test_bitmap_with_encoded_data(reporter); | 619 test_bitmap_with_encoded_data(reporter); |
| 563 test_clone_empty(reporter); | 620 test_clone_empty(reporter); |
| 564 test_clip_bound_opt(reporter); | 621 test_clip_bound_opt(reporter); |
| 622 test_clip_expansion(reporter); |
| 565 } | 623 } |
| 566 | 624 |
| 567 #include "TestClassDef.h" | 625 #include "TestClassDef.h" |
| 568 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) | 626 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) |
| OLD | NEW |