OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include <new> | 8 #include <new> |
9 #include "SkBBoxHierarchy.h" | 9 #include "SkBBoxHierarchy.h" |
10 #include "SkOffsetTable.h" | 10 #include "SkOffsetTable.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 SkDebugf("\n"); | 63 SkDebugf("\n"); |
64 #endif | 64 #endif |
65 #ifdef SK_DEBUG_DUMP | 65 #ifdef SK_DEBUG_DUMP |
66 record.dumpMatrices(); | 66 record.dumpMatrices(); |
67 record.dumpPaints(); | 67 record.dumpPaints(); |
68 #endif | 68 #endif |
69 | 69 |
70 record.validate(record.writeStream().bytesWritten(), 0); | 70 record.validate(record.writeStream().bytesWritten(), 0); |
71 const SkWriter32& writer = record.writeStream(); | 71 const SkWriter32& writer = record.writeStream(); |
72 this->init(); | 72 init(); |
73 SkASSERT(!fOpData); | 73 SkASSERT(!fOpData); |
74 if (writer.bytesWritten() == 0) { | 74 if (writer.bytesWritten() == 0) { |
75 fOpData = SkData::NewEmpty(); | 75 fOpData = SkData::NewEmpty(); |
76 return; | 76 return; |
77 } | 77 } |
78 fOpData = writer.snapshotAsData(); | 78 fOpData = writer.snapshotAsData(); |
79 | 79 |
80 fBoundingHierarchy = record.fBoundingHierarchy; | 80 fBoundingHierarchy = record.fBoundingHierarchy; |
81 fStateTree = record.fStateTree; | 81 fStateTree = record.fStateTree; |
82 | 82 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 void SkPicturePlayback::init() { | 255 void SkPicturePlayback::init() { |
256 fBitmaps = NULL; | 256 fBitmaps = NULL; |
257 fPaints = NULL; | 257 fPaints = NULL; |
258 fPictureRefs = NULL; | 258 fPictureRefs = NULL; |
259 fPictureCount = 0; | 259 fPictureCount = 0; |
260 fOpData = NULL; | 260 fOpData = NULL; |
261 fFactoryPlayback = NULL; | 261 fFactoryPlayback = NULL; |
262 fBoundingHierarchy = NULL; | 262 fBoundingHierarchy = NULL; |
263 fStateTree = NULL; | 263 fStateTree = NULL; |
264 fCachedActiveOps = NULL; | |
265 } | 264 } |
266 | 265 |
267 SkPicturePlayback::~SkPicturePlayback() { | 266 SkPicturePlayback::~SkPicturePlayback() { |
268 SkSafeUnref(fOpData); | 267 SkSafeUnref(fOpData); |
269 | 268 |
270 SkSafeUnref(fBitmaps); | 269 SkSafeUnref(fBitmaps); |
271 SkSafeUnref(fPaints); | 270 SkSafeUnref(fPaints); |
272 SkSafeUnref(fBoundingHierarchy); | 271 SkSafeUnref(fBoundingHierarchy); |
273 SkSafeUnref(fStateTree); | 272 SkSafeUnref(fStateTree); |
274 | 273 |
275 SkDELETE(fCachedActiveOps); | |
276 | |
277 for (int i = 0; i < fPictureCount; i++) { | 274 for (int i = 0; i < fPictureCount; i++) { |
278 fPictureRefs[i]->unref(); | 275 fPictureRefs[i]->unref(); |
279 } | 276 } |
280 SkDELETE_ARRAY(fPictureRefs); | 277 SkDELETE_ARRAY(fPictureRefs); |
281 | 278 |
282 SkDELETE(fFactoryPlayback); | 279 SkDELETE(fFactoryPlayback); |
283 } | 280 } |
284 | 281 |
285 void SkPicturePlayback::dumpSize() const { | 282 void SkPicturePlayback::dumpSize() const { |
286 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n
", | 283 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n
", |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 if (MASK_24 == *size) { | 747 if (MASK_24 == *size) { |
751 *size = reader->readInt(); | 748 *size = reader->readInt(); |
752 } | 749 } |
753 } | 750 } |
754 return (DrawType) op; | 751 return (DrawType) op; |
755 } | 752 } |
756 | 753 |
757 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw
*>&". | 754 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw
*>&". |
758 // It represents the operations about to be drawn, as generated by some spatial | 755 // It represents the operations about to be drawn, as generated by some spatial |
759 // subdivision helper class. It should already be in 'fOffset' sorted order. | 756 // subdivision helper class. It should already be in 'fOffset' sorted order. |
760 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>* activeOps) { | 757 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>& activeOps) { |
761 if ((NULL != activeOps && 0 == activeOps->count()) || NULL == fBitmapUseOffs
ets) { | 758 if (0 == activeOps.count() || NULL == fBitmapUseOffsets) { |
762 return; | |
763 } | |
764 | |
765 if (NULL == activeOps) { | |
766 // going to need everything | |
767 return; | 759 return; |
768 } | 760 } |
769 | 761 |
770 SkTDArray<int> active; | 762 SkTDArray<int> active; |
771 | 763 |
772 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]); | 764 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]); |
773 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) { | 765 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) { |
774 needToCheck.get()[i] = true; | 766 needToCheck.get()[i] = true; |
775 } | 767 } |
776 | 768 |
777 uint32_t max = ((SkPictureStateTree::Draw*)(*activeOps)[(*activeOps).count()
-1])->fOffset; | 769 uint32_t max = ((SkPictureStateTree::Draw*)activeOps[activeOps.count()-1])->
fOffset; |
778 | 770 |
779 for (int i = 0; i < activeOps->count(); ++i) { | 771 for (int i = 0; i < activeOps.count(); ++i) { |
780 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) (*activeOps
)[i]; | 772 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) activeOps[i
]; |
781 | 773 |
782 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) { | 774 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) { |
783 if (!needToCheck.get()[j]) { | 775 if (!needToCheck.get()[j]) { |
784 continue; | 776 continue; |
785 } | 777 } |
786 | 778 |
787 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) { | 779 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) { |
788 needToCheck.get()[j] = false; | 780 needToCheck.get()[j] = false; |
789 continue; | 781 continue; |
790 } | 782 } |
791 | 783 |
792 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) { | 784 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) { |
793 continue; | 785 continue; |
794 } | 786 } |
795 | 787 |
796 *active.append() = j; | 788 *active.append() = j; |
797 needToCheck.get()[j] = false; | 789 needToCheck.get()[j] = false; |
798 } | 790 } |
799 } | 791 } |
800 | 792 |
801 for (int i = 0; i < active.count(); ++i) { | 793 for (int i = 0; i < active.count(); ++i) { |
802 SkDebugf("preload texture %d\n", active[i]); | 794 SkDebugf("preload texture %d\n", active[i]); |
803 } | 795 } |
804 } | 796 } |
805 | 797 |
806 uint32_t SkPicturePlayback::CachedOperationList::offset(int index) const { | |
807 SkASSERT(index < fOps.count()); | |
808 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset; | |
809 } | |
810 | |
811 const SkMatrix& SkPicturePlayback::CachedOperationList::matrix(int index) const
{ | |
812 SkASSERT(index < fOps.count()); | |
813 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix; | |
814 } | |
815 | |
816 const SkPicture::OperationList& SkPicturePlayback::getActiveOps(const SkIRect& q
uery) { | |
817 if (NULL == fStateTree || NULL == fBoundingHierarchy) { | |
818 return SkPicture::OperationList::InvalidList(); | |
819 } | |
820 | |
821 if (NULL == fCachedActiveOps) { | |
822 fCachedActiveOps = SkNEW(CachedOperationList); | |
823 } | |
824 | |
825 if (query == fCachedActiveOps->fCacheQueryRect) { | |
826 return *fCachedActiveOps; | |
827 } | |
828 | |
829 fCachedActiveOps->fOps.rewind(); | |
830 | |
831 fBoundingHierarchy->search(query, &(fCachedActiveOps->fOps)); | |
832 | |
833 SkTQSort<SkPictureStateTree::Draw>( | |
834 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.begi
n()), | |
835 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.end(
)-1)); | |
836 | |
837 fCachedActiveOps->fCacheQueryRect = query; | |
838 return *fCachedActiveOps; | |
839 } | |
840 | |
841 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback)
{ | 798 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback)
{ |
842 #ifdef ENABLE_TIME_DRAW | 799 #ifdef ENABLE_TIME_DRAW |
843 SkAutoTime at("SkPicture::draw", 50); | 800 SkAutoTime at("SkPicture::draw", 50); |
844 #endif | 801 #endif |
845 | 802 |
846 #ifdef SPEW_CLIP_SKIPPING | 803 #ifdef SPEW_CLIP_SKIPPING |
847 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; | 804 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; |
848 int opCount = 0; | 805 int opCount = 0; |
849 #endif | 806 #endif |
850 | 807 |
851 #ifdef SK_BUILD_FOR_ANDROID | 808 #ifdef SK_BUILD_FOR_ANDROID |
852 SkAutoMutexAcquire autoMutex(fDrawMutex); | 809 SkAutoMutexAcquire autoMutex(fDrawMutex); |
853 #endif | 810 #endif |
854 | 811 |
855 // kDrawComplete will be the signal that we have reached the end of | 812 // kDrawComplete will be the signal that we have reached the end of |
856 // the command stream | 813 // the command stream |
857 static const uint32_t kDrawComplete = SK_MaxU32; | 814 static const uint32_t kDrawComplete = SK_MaxU32; |
858 | 815 |
859 SkReader32 reader(fOpData->bytes(), fOpData->size()); | 816 SkReader32 reader(fOpData->bytes(), fOpData->size()); |
860 TextContainer text; | 817 TextContainer text; |
861 const SkTDArray<void*>* activeOps = NULL; | 818 SkTDArray<void*> activeOps; |
862 | 819 |
863 if (NULL != fStateTree && NULL != fBoundingHierarchy) { | 820 if (NULL != fStateTree && NULL != fBoundingHierarchy) { |
864 SkRect clipBounds; | 821 SkRect clipBounds; |
865 if (canvas.getClipBounds(&clipBounds)) { | 822 if (canvas.getClipBounds(&clipBounds)) { |
866 SkIRect query; | 823 SkIRect query; |
867 clipBounds.roundOut(&query); | 824 clipBounds.roundOut(&query); |
868 | 825 fBoundingHierarchy->search(query, &activeOps); |
869 const SkPicture::OperationList& activeOpsList = this->getActiveOps(q
uery); | 826 if (activeOps.count() == 0) { |
870 if (activeOpsList.valid()) { | 827 return; |
871 if (0 == activeOpsList.numOps()) { | |
872 return; // nothing to draw | |
873 } | |
874 | |
875 // Since the opList is valid we know it is our derived class | |
876 activeOps = &((const CachedOperationList&)activeOpsList).fOps; | |
877 } | 828 } |
| 829 SkTQSort<SkPictureStateTree::Draw>( |
| 830 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.begin()), |
| 831 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.end()-1))
; |
878 } | 832 } |
879 } | 833 } |
880 | 834 |
881 SkPictureStateTree::Iterator it = (NULL == activeOps) ? | 835 SkPictureStateTree::Iterator it = (NULL == fStateTree) ? |
882 SkPictureStateTree::Iterator() : | 836 SkPictureStateTree::Iterator() : |
883 fStateTree->getIterator(*activeOps, &canvas); | 837 fStateTree->getIterator(activeOps, &canvas); |
884 | 838 |
885 if (it.isValid()) { | 839 if (it.isValid()) { |
886 uint32_t skipTo = it.draw(); | 840 uint32_t skipTo = it.draw(); |
887 if (kDrawComplete == skipTo) { | 841 if (kDrawComplete == skipTo) { |
888 return; | 842 return; |
889 } | 843 } |
890 reader.setOffset(skipTo); | 844 reader.setOffset(skipTo); |
891 } | 845 } |
892 | 846 |
893 this->preLoadBitmaps(activeOps); | 847 this->preLoadBitmaps(activeOps); |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 for (index = 0; index < fPictureCount; index++) | 1759 for (index = 0; index < fPictureCount; index++) |
1806 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1760 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1807 "picture%p, ", fPictureRefs[index]); | 1761 "picture%p, ", fPictureRefs[index]); |
1808 if (fPictureCount > 0) | 1762 if (fPictureCount > 0) |
1809 SkDebugf("%s0};\n", pBuffer); | 1763 SkDebugf("%s0};\n", pBuffer); |
1810 | 1764 |
1811 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1765 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
1812 } | 1766 } |
1813 | 1767 |
1814 #endif | 1768 #endif |
OLD | NEW |