Chromium Code Reviews| 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 init(); | 72 this->init(); |
| 73 if (writer.bytesWritten() == 0) { | 73 if (writer.bytesWritten() == 0) { |
| 74 fOpData = SkData::NewEmpty(); | 74 fOpData = SkData::NewEmpty(); |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 fBoundingHierarchy = record.fBoundingHierarchy; | 78 fBoundingHierarchy = record.fBoundingHierarchy; |
| 79 fStateTree = record.fStateTree; | 79 fStateTree = record.fStateTree; |
| 80 | 80 |
| 81 SkSafeRef(fBoundingHierarchy); | 81 SkSafeRef(fBoundingHierarchy); |
| 82 SkSafeRef(fStateTree); | 82 SkSafeRef(fStateTree); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 | 260 |
| 261 void SkPicturePlayback::init() { | 261 void SkPicturePlayback::init() { |
| 262 fBitmaps = NULL; | 262 fBitmaps = NULL; |
| 263 fPaints = NULL; | 263 fPaints = NULL; |
| 264 fPictureRefs = NULL; | 264 fPictureRefs = NULL; |
| 265 fPictureCount = 0; | 265 fPictureCount = 0; |
| 266 fOpData = NULL; | 266 fOpData = NULL; |
| 267 fFactoryPlayback = NULL; | 267 fFactoryPlayback = NULL; |
| 268 fBoundingHierarchy = NULL; | 268 fBoundingHierarchy = NULL; |
| 269 fStateTree = NULL; | 269 fStateTree = NULL; |
| 270 fCacheQueryRect.setEmpty(); | |
| 271 fCachedActiveOps = NULL; | |
| 270 } | 272 } |
| 271 | 273 |
| 272 SkPicturePlayback::~SkPicturePlayback() { | 274 SkPicturePlayback::~SkPicturePlayback() { |
| 273 SkSafeUnref(fOpData); | 275 SkSafeUnref(fOpData); |
| 274 | 276 |
| 275 SkSafeUnref(fBitmaps); | 277 SkSafeUnref(fBitmaps); |
| 276 SkSafeUnref(fPaints); | 278 SkSafeUnref(fPaints); |
| 277 SkSafeUnref(fBoundingHierarchy); | 279 SkSafeUnref(fBoundingHierarchy); |
| 278 SkSafeUnref(fStateTree); | 280 SkSafeUnref(fStateTree); |
| 279 | 281 |
| 282 SkDELETE(fCachedActiveOps); | |
| 283 | |
| 280 for (int i = 0; i < fPictureCount; i++) { | 284 for (int i = 0; i < fPictureCount; i++) { |
| 281 fPictureRefs[i]->unref(); | 285 fPictureRefs[i]->unref(); |
| 282 } | 286 } |
| 283 SkDELETE_ARRAY(fPictureRefs); | 287 SkDELETE_ARRAY(fPictureRefs); |
| 284 | 288 |
| 285 SkDELETE(fFactoryPlayback); | 289 SkDELETE(fFactoryPlayback); |
| 286 } | 290 } |
| 287 | 291 |
| 288 void SkPicturePlayback::dumpSize() const { | 292 void SkPicturePlayback::dumpSize() const { |
| 289 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n ", | 293 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... | |
| 753 if (MASK_24 == *size) { | 757 if (MASK_24 == *size) { |
| 754 *size = reader->readInt(); | 758 *size = reader->readInt(); |
| 755 } | 759 } |
| 756 } | 760 } |
| 757 return (DrawType) op; | 761 return (DrawType) op; |
| 758 } | 762 } |
| 759 | 763 |
| 760 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw *>&". | 764 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw *>&". |
| 761 // It represents the operations about to be drawn, as generated by some spatial | 765 // It represents the operations about to be drawn, as generated by some spatial |
| 762 // subdivision helper class. It should already be in 'fOffset' sorted order. | 766 // subdivision helper class. It should already be in 'fOffset' sorted order. |
| 763 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>& activeOps) { | 767 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>* activeOps) { |
| 764 if (0 == activeOps.count() || NULL == fBitmapUseOffsets) { | 768 if ((NULL != activeOps && 0 == activeOps->count()) || NULL == fBitmapUseOffs ets) { |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 if (NULL == activeOps) { | |
| 773 // going to need everything | |
| 765 return; | 774 return; |
| 766 } | 775 } |
| 767 | 776 |
| 768 SkTDArray<int> active; | 777 SkTDArray<int> active; |
| 769 | 778 |
| 770 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]); | 779 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]); |
| 771 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) { | 780 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) { |
| 772 needToCheck.get()[i] = true; | 781 needToCheck.get()[i] = true; |
| 773 } | 782 } |
| 774 | 783 |
| 775 uint32_t max = ((SkPictureStateTree::Draw*)activeOps[activeOps.count()-1])-> fOffset; | 784 uint32_t max = ((SkPictureStateTree::Draw*)(*activeOps)[(*activeOps).count() -1])->fOffset; |
| 776 | 785 |
| 777 for (int i = 0; i < activeOps.count(); ++i) { | 786 for (int i = 0; i < activeOps->count(); ++i) { |
| 778 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) activeOps[i ]; | 787 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) (*activeOps )[i]; |
| 779 | 788 |
| 780 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) { | 789 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) { |
| 781 if (!needToCheck.get()[j]) { | 790 if (!needToCheck.get()[j]) { |
| 782 continue; | 791 continue; |
| 783 } | 792 } |
| 784 | 793 |
| 785 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) { | 794 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) { |
| 786 needToCheck.get()[j] = false; | 795 needToCheck.get()[j] = false; |
| 787 continue; | 796 continue; |
| 788 } | 797 } |
| 789 | 798 |
| 790 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) { | 799 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) { |
| 791 continue; | 800 continue; |
| 792 } | 801 } |
| 793 | 802 |
| 794 *active.append() = j; | 803 *active.append() = j; |
| 795 needToCheck.get()[j] = false; | 804 needToCheck.get()[j] = false; |
| 796 } | 805 } |
| 797 } | 806 } |
| 798 | 807 |
| 799 for (int i = 0; i < active.count(); ++i) { | 808 for (int i = 0; i < active.count(); ++i) { |
| 800 SkDebugf("preload texture %d\n", active[i]); | 809 SkDebugf("preload texture %d\n", active[i]); |
| 801 } | 810 } |
| 802 } | 811 } |
| 803 | 812 |
| 813 const SkTDArray<void*>* SkPicturePlayback::getActiveOps(const SkIRect& query) { | |
| 814 if (NULL == fStateTree || NULL == fBoundingHierarchy) { | |
| 815 return NULL; | |
| 816 } | |
| 817 | |
| 818 if (query == fCacheQueryRect) { | |
| 819 return fCachedActiveOps; | |
| 820 } | |
| 821 | |
| 822 if (NULL == fCachedActiveOps) { | |
| 823 fCachedActiveOps = SkNEW(SkTDArray<void*>); | |
| 824 } | |
| 825 | |
| 826 fCachedActiveOps->rewind(); | |
| 827 | |
| 828 fBoundingHierarchy->search(query, fCachedActiveOps); | |
| 829 | |
| 830 SkTQSort<SkPictureStateTree::Draw>( | |
|
bsalomon
2014/03/13 17:59:34
Is this sorting by offset?
robertphillips
2014/03/14 17:59:34
Yep - that is pre-existing behavior.
| |
| 831 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->begin()), | |
| 832 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->end()-1)) ; | |
| 833 | |
| 834 fCacheQueryRect = query; | |
| 835 return fCachedActiveOps; | |
| 836 } | |
| 837 | |
| 804 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) { | 838 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) { |
| 805 #ifdef ENABLE_TIME_DRAW | 839 #ifdef ENABLE_TIME_DRAW |
| 806 SkAutoTime at("SkPicture::draw", 50); | 840 SkAutoTime at("SkPicture::draw", 50); |
| 807 #endif | 841 #endif |
| 808 | 842 |
| 809 #ifdef SPEW_CLIP_SKIPPING | 843 #ifdef SPEW_CLIP_SKIPPING |
| 810 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; | 844 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; |
| 811 int opCount = 0; | 845 int opCount = 0; |
| 812 #endif | 846 #endif |
| 813 | 847 |
| 814 #ifdef SK_BUILD_FOR_ANDROID | 848 #ifdef SK_BUILD_FOR_ANDROID |
| 815 SkAutoMutexAcquire autoMutex(fDrawMutex); | 849 SkAutoMutexAcquire autoMutex(fDrawMutex); |
| 816 #endif | 850 #endif |
| 817 | 851 |
| 818 // kDrawComplete will be the signal that we have reached the end of | 852 // kDrawComplete will be the signal that we have reached the end of |
| 819 // the command stream | 853 // the command stream |
| 820 static const uint32_t kDrawComplete = SK_MaxU32; | 854 static const uint32_t kDrawComplete = SK_MaxU32; |
| 821 | 855 |
| 822 SkReader32 reader(fOpData->bytes(), fOpData->size()); | 856 SkReader32 reader(fOpData->bytes(), fOpData->size()); |
| 823 TextContainer text; | 857 TextContainer text; |
| 824 SkTDArray<void*> activeOps; | 858 const SkTDArray<void*>* activeOps = NULL; |
| 825 | 859 |
| 826 if (NULL != fStateTree && NULL != fBoundingHierarchy) { | 860 if (NULL != fStateTree && NULL != fBoundingHierarchy) { |
| 827 SkRect clipBounds; | 861 SkRect clipBounds; |
| 828 if (canvas.getClipBounds(&clipBounds)) { | 862 if (canvas.getClipBounds(&clipBounds)) { |
| 829 SkIRect query; | 863 SkIRect query; |
| 830 clipBounds.roundOut(&query); | 864 clipBounds.roundOut(&query); |
| 831 fBoundingHierarchy->search(query, &activeOps); | 865 |
| 832 if (activeOps.count() == 0) { | 866 activeOps = this->getActiveOps(query); |
| 833 return; | 867 if (NULL != activeOps && 0 == activeOps->count()) { |
| 868 return; // nothing to draw | |
| 834 } | 869 } |
| 835 SkTQSort<SkPictureStateTree::Draw>( | |
| 836 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.begin()), | |
| 837 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.end()-1)) ; | |
| 838 } | 870 } |
| 839 } | 871 } |
| 840 | 872 |
| 841 SkPictureStateTree::Iterator it = (NULL == fStateTree) ? | 873 SkPictureStateTree::Iterator it = (NULL == activeOps) ? |
| 842 SkPictureStateTree::Iterator() : | 874 SkPictureStateTree::Iterator() : |
| 843 fStateTree->getIterator(activeOps, &canvas); | 875 fStateTree->getIterator(*activeOps, &canvas); |
| 844 | 876 |
| 845 if (it.isValid()) { | 877 if (it.isValid()) { |
| 846 uint32_t skipTo = it.draw(); | 878 uint32_t skipTo = it.draw(); |
| 847 if (kDrawComplete == skipTo) { | 879 if (kDrawComplete == skipTo) { |
| 848 return; | 880 return; |
| 849 } | 881 } |
| 850 reader.setOffset(skipTo); | 882 reader.setOffset(skipTo); |
| 851 } | 883 } |
| 852 | 884 |
| 853 this->preLoadBitmaps(activeOps); | 885 this->preLoadBitmaps(activeOps); |
| (...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1765 for (index = 0; index < fPictureCount; index++) | 1797 for (index = 0; index < fPictureCount; index++) |
| 1766 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), | 1798 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), |
| 1767 "picture%p, ", fPictureRefs[index]); | 1799 "picture%p, ", fPictureRefs[index]); |
| 1768 if (fPictureCount > 0) | 1800 if (fPictureCount > 0) |
| 1769 SkDebugf("%s0};\n", pBuffer); | 1801 SkDebugf("%s0};\n", pBuffer); |
| 1770 | 1802 |
| 1771 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1803 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
| 1772 } | 1804 } |
| 1773 | 1805 |
| 1774 #endif | 1806 #endif |
| OLD | NEW |