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 #include "SkBBoxHierarchy.h" |
8 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
9 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
10 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
11 #include "SkDashPathEffect.h" | 12 #include "SkDashPathEffect.h" |
12 #include "SkData.h" | 13 #include "SkData.h" |
13 #include "SkDecodingImageGenerator.h" | 14 #include "SkDecodingImageGenerator.h" |
14 #include "SkError.h" | 15 #include "SkError.h" |
15 #include "SkImageEncoder.h" | 16 #include "SkImageEncoder.h" |
16 #include "SkImageGenerator.h" | 17 #include "SkImageGenerator.h" |
17 #include "SkPaint.h" | 18 #include "SkPaint.h" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 // Everything in the analytic list should appear in the gathered | 656 // Everything in the analytic list should appear in the gathered |
656 // list. | 657 // list. |
657 for (int i = 0; i < fromAnalytic.count(); ++i) { | 658 for (int i = 0; i < fromAnalytic.count(); ++i) { |
658 REPORTER_ASSERT(reporter, -1 != gatheredRefs.find(fromAnalytic[i
])); | 659 REPORTER_ASSERT(reporter, -1 != gatheredRefs.find(fromAnalytic[i
])); |
659 } | 660 } |
660 } | 661 } |
661 } | 662 } |
662 } | 663 } |
663 | 664 |
664 #ifdef SK_DEBUG | 665 #ifdef SK_DEBUG |
665 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire | 666 // Ensure that deleting an empty SkPicture does not assert. Asserts only fire |
666 // in debug mode, so only run in debug mode. | 667 // in debug mode, so only run in debug mode. |
667 static void test_deleting_empty_picture() { | 668 static void test_deleting_empty_picture() { |
668 SkPictureRecorder recorder; | 669 SkPictureRecorder recorder; |
669 // Creates an SkPictureRecord | 670 // Creates an SkPictureRecord |
670 recorder.beginRecording(0, 0); | 671 recorder.beginRecording(0, 0); |
671 // Turns that into an SkPicture | 672 // Turns that into an SkPicture |
672 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 673 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
673 // Ceates a new SkPictureRecord | 674 // Ceates a new SkPictureRecord |
674 recorder.beginRecording(0, 0); | 675 recorder.beginRecording(0, 0); |
675 } | 676 } |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); | 1652 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); |
1652 SkCanvas replayCanvas(replayBM); | 1653 SkCanvas replayCanvas(replayBM); |
1653 picture->draw(&replayCanvas); | 1654 picture->draw(&replayCanvas); |
1654 replayCanvas.flush(); | 1655 replayCanvas.flush(); |
1655 | 1656 |
1656 // With the bug present, at (55, 55) we would get a fully opaque red | 1657 // With the bug present, at (55, 55) we would get a fully opaque red |
1657 // intead of a dark red. | 1658 // intead of a dark red. |
1658 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); | 1659 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); |
1659 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); | 1660 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); |
1660 } | 1661 } |
| 1662 |
| 1663 struct CountingBBH : public SkBBoxHierarchy { |
| 1664 mutable int searchCalls; |
| 1665 |
| 1666 CountingBBH() : searchCalls(0) {} |
| 1667 |
| 1668 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const { |
| 1669 this->searchCalls++; |
| 1670 } |
| 1671 |
| 1672 // All other methods unimplemented. |
| 1673 virtual void insert(void* data, const SkIRect& bounds, bool defer) {} |
| 1674 virtual void flushDeferredInserts() {} |
| 1675 virtual void clear() {} |
| 1676 virtual int getCount() const { return 0; } |
| 1677 virtual int getDepth() const { return 0; } |
| 1678 virtual void rewindInserts() {} |
| 1679 }; |
| 1680 |
| 1681 class SpoonFedBBHFactory : public SkBBHFactory { |
| 1682 public: |
| 1683 explicit SpoonFedBBHFactory(SkBBoxHierarchy* bbh) : fBBH(bbh) {} |
| 1684 virtual SkBBoxHierarchy* operator()(int width, int height) const { |
| 1685 return SkRef(fBBH); |
| 1686 } |
| 1687 private: |
| 1688 SkBBoxHierarchy* fBBH; |
| 1689 }; |
| 1690 |
| 1691 // When the canvas clip covers the full picture, we don't need to call the BBH. |
| 1692 DEF_TEST(Picture_SkipBBH, r) { |
| 1693 CountingBBH bbh; |
| 1694 SpoonFedBBHFactory factory(&bbh); |
| 1695 |
| 1696 SkPictureRecorder recorder; |
| 1697 recorder.beginRecording(320, 240, &factory); |
| 1698 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); |
| 1699 |
| 1700 SkCanvas big(640, 480), small(300, 200); |
| 1701 |
| 1702 picture->draw(&big); |
| 1703 REPORTER_ASSERT(r, bbh.searchCalls == 0); |
| 1704 |
| 1705 picture->draw(&small); |
| 1706 REPORTER_ASSERT(r, bbh.searchCalls == 1); |
| 1707 } |
OLD | NEW |