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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 canvas->clipPath(path, SkRegion::kIntersect_Op); | 543 canvas->clipPath(path, SkRegion::kIntersect_Op); |
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 |
robertphillips
2013/08/27 15:08:56
// Comment
// This canvas ...
| |
554 class ClipCountingCanvas : public SkCanvas { | |
555 public: | |
556 explicit ClipCountingCanvas(SkDevice* device) | |
557 : SkCanvas(device) | |
558 , fClipCount(0){ | |
559 } | |
560 | |
robertphillips
2013/08/27 15:08:56
clipPath
fmalita's clipX
clipRRect
| |
561 virtual bool clipRect(const SkRect& r, SkRegion::Op op, bool doAA) | |
562 SK_OVERRIDE { | |
563 fClipCount += 1; | |
564 return SkCanvas::clipRect(r, op, doAA); | |
565 } | |
566 | |
567 unsigned getClipCount() const { return fClipCount; } | |
568 | |
569 private: | |
570 unsigned fClipCount; | |
robertphillips
2013/08/27 15:08:56
inherited
| |
571 }; | |
572 | |
573 static void test_clip_expansion(skiatest::Reporter* reporter) { | |
574 SkPicture picture; | |
575 SkCanvas* canvas = picture.beginRecording(10, 10, 0); | |
576 | |
577 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); | |
578 // The following expanding clip should not be skipped. | |
579 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); | |
580 // Draw something so the optimizer doesn't just fold the world. | |
581 SkPaint p; | |
582 p.setColor(SK_ColorBLUE); | |
583 canvas->drawPaint(p); | |
584 | |
585 SkDevice testDevice(SkBitmap::kNo_Config, 10, 10); | |
586 ClipCountingCanvas testCanvas(&testDevice); | |
587 picture.draw(&testCanvas); | |
588 | |
589 // Both clips should be present on playback. | |
590 REPORTER_ASSERT(reporter, testCanvas.getClipCount() == 2); | |
591 } | |
592 | |
553 static void TestPicture(skiatest::Reporter* reporter) { | 593 static void TestPicture(skiatest::Reporter* reporter) { |
554 #ifdef SK_DEBUG | 594 #ifdef SK_DEBUG |
555 test_deleting_empty_playback(); | 595 test_deleting_empty_playback(); |
556 test_serializing_empty_picture(); | 596 test_serializing_empty_picture(); |
557 #else | 597 #else |
558 test_bad_bitmap(); | 598 test_bad_bitmap(); |
559 #endif | 599 #endif |
560 test_peephole(); | 600 test_peephole(); |
561 test_gatherpixelrefs(reporter); | 601 test_gatherpixelrefs(reporter); |
562 test_bitmap_with_encoded_data(reporter); | 602 test_bitmap_with_encoded_data(reporter); |
563 test_clone_empty(reporter); | 603 test_clone_empty(reporter); |
564 test_clip_bound_opt(reporter); | 604 test_clip_bound_opt(reporter); |
605 test_clip_expansion(reporter); | |
565 } | 606 } |
566 | 607 |
567 #include "TestClassDef.h" | 608 #include "TestClassDef.h" |
568 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) | 609 DEFINE_TESTCLASS("Pictures", PictureTestClass, TestPicture) |
OLD | NEW |