Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: src/core/SkPicturePlayback.cpp

Issue 195793010: Add a means of extracting active operations from SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: more clean up Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/core/SkPicturePlayback.h ('K') | « src/core/SkPicturePlayback.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 fCachedActiveOps = NULL;
270 } 271 }
271 272
272 SkPicturePlayback::~SkPicturePlayback() { 273 SkPicturePlayback::~SkPicturePlayback() {
273 SkSafeUnref(fOpData); 274 SkSafeUnref(fOpData);
274 275
275 SkSafeUnref(fBitmaps); 276 SkSafeUnref(fBitmaps);
276 SkSafeUnref(fPaints); 277 SkSafeUnref(fPaints);
277 SkSafeUnref(fBoundingHierarchy); 278 SkSafeUnref(fBoundingHierarchy);
278 SkSafeUnref(fStateTree); 279 SkSafeUnref(fStateTree);
279 280
281 SkDELETE(fCachedActiveOps);
282
280 for (int i = 0; i < fPictureCount; i++) { 283 for (int i = 0; i < fPictureCount; i++) {
281 fPictureRefs[i]->unref(); 284 fPictureRefs[i]->unref();
282 } 285 }
283 SkDELETE_ARRAY(fPictureRefs); 286 SkDELETE_ARRAY(fPictureRefs);
284 287
285 SkDELETE(fFactoryPlayback); 288 SkDELETE(fFactoryPlayback);
286 } 289 }
287 290
288 void SkPicturePlayback::dumpSize() const { 291 void SkPicturePlayback::dumpSize() const {
289 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d] paths=%d\n ", 292 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
753 if (MASK_24 == *size) { 756 if (MASK_24 == *size) {
754 *size = reader->readInt(); 757 *size = reader->readInt();
755 } 758 }
756 } 759 }
757 return (DrawType) op; 760 return (DrawType) op;
758 } 761 }
759 762
760 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw *>&". 763 // The activeOps parameter is actually "const SkTDArray<SkPictureStateTree::Draw *>&".
761 // It represents the operations about to be drawn, as generated by some spatial 764 // 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. 765 // subdivision helper class. It should already be in 'fOffset' sorted order.
763 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>& activeOps) { 766 void SkPicturePlayback::preLoadBitmaps(const SkTDArray<void*>* activeOps) {
764 if (0 == activeOps.count() || NULL == fBitmapUseOffsets) { 767 if ((NULL != activeOps && 0 == activeOps->count()) || NULL == fBitmapUseOffs ets) {
768 return;
769 }
770
771 if (NULL == activeOps) {
772 // going to need everything
765 return; 773 return;
766 } 774 }
767 775
768 SkTDArray<int> active; 776 SkTDArray<int> active;
769 777
770 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]); 778 SkAutoTDeleteArray<bool> needToCheck(new bool[fBitmapUseOffsets->numIDs()]);
771 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) { 779 for (int i = 0; i < fBitmapUseOffsets->numIDs(); ++i) {
772 needToCheck.get()[i] = true; 780 needToCheck.get()[i] = true;
773 } 781 }
774 782
775 uint32_t max = ((SkPictureStateTree::Draw*)activeOps[activeOps.count()-1])-> fOffset; 783 uint32_t max = ((SkPictureStateTree::Draw*)(*activeOps)[(*activeOps).count() -1])->fOffset;
776 784
777 for (int i = 0; i < activeOps.count(); ++i) { 785 for (int i = 0; i < activeOps->count(); ++i) {
778 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) activeOps[i ]; 786 SkPictureStateTree::Draw* draw = (SkPictureStateTree::Draw*) (*activeOps )[i];
779 787
780 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) { 788 for (int j = 0; j < fBitmapUseOffsets->numIDs(); ++j) {
781 if (!needToCheck.get()[j]) { 789 if (!needToCheck.get()[j]) {
782 continue; 790 continue;
783 } 791 }
784 792
785 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) { 793 if (!fBitmapUseOffsets->overlap(j, draw->fOffset, max)) {
786 needToCheck.get()[j] = false; 794 needToCheck.get()[j] = false;
787 continue; 795 continue;
788 } 796 }
789 797
790 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) { 798 if (!fBitmapUseOffsets->includes(j, draw->fOffset)) {
791 continue; 799 continue;
792 } 800 }
793 801
794 *active.append() = j; 802 *active.append() = j;
795 needToCheck.get()[j] = false; 803 needToCheck.get()[j] = false;
796 } 804 }
797 } 805 }
798 806
799 for (int i = 0; i < active.count(); ++i) { 807 for (int i = 0; i < active.count(); ++i) {
800 SkDebugf("preload texture %d\n", active[i]); 808 SkDebugf("preload texture %d\n", active[i]);
801 } 809 }
802 } 810 }
803 811
812 uint32_t SkPicturePlayback::CachedOperationList::offset(int index) const {
813 SkASSERT(index < fOps.count());
814 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset;
815 }
816
817 const SkMatrix& SkPicturePlayback::CachedOperationList::matrix(int index) const {
818 SkASSERT(index < fOps.count());
819 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix;
820 }
821
822 const SkPicture::OperationList& SkPicturePlayback::getActiveOps(const SkIRect& q uery) {
823 if (NULL == fStateTree || NULL == fBoundingHierarchy) {
824 return SkPicture::OperationList::InvalidList();
825 }
826
827 if (NULL == fCachedActiveOps) {
828 fCachedActiveOps = SkNEW(CachedOperationList);
829 }
830
831 if (query == fCachedActiveOps->fCacheQueryRect) {
832 return *fCachedActiveOps;
833 }
834
835 fCachedActiveOps->fOps.rewind();
836
837 fBoundingHierarchy->search(query, &(fCachedActiveOps->fOps));
838
839 SkTQSort<SkPictureStateTree::Draw>(
840 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.begi n()),
841 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.end( )-1));
842
843 fCachedActiveOps->fCacheQueryRect = query;
844 return *fCachedActiveOps;
845 }
846
804 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) { 847 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) {
805 #ifdef ENABLE_TIME_DRAW 848 #ifdef ENABLE_TIME_DRAW
806 SkAutoTime at("SkPicture::draw", 50); 849 SkAutoTime at("SkPicture::draw", 50);
807 #endif 850 #endif
808 851
809 #ifdef SPEW_CLIP_SKIPPING 852 #ifdef SPEW_CLIP_SKIPPING
810 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; 853 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull;
811 int opCount = 0; 854 int opCount = 0;
812 #endif 855 #endif
813 856
814 #ifdef SK_BUILD_FOR_ANDROID 857 #ifdef SK_BUILD_FOR_ANDROID
815 SkAutoMutexAcquire autoMutex(fDrawMutex); 858 SkAutoMutexAcquire autoMutex(fDrawMutex);
816 #endif 859 #endif
817 860
818 // kDrawComplete will be the signal that we have reached the end of 861 // kDrawComplete will be the signal that we have reached the end of
819 // the command stream 862 // the command stream
820 static const uint32_t kDrawComplete = SK_MaxU32; 863 static const uint32_t kDrawComplete = SK_MaxU32;
821 864
822 SkReader32 reader(fOpData->bytes(), fOpData->size()); 865 SkReader32 reader(fOpData->bytes(), fOpData->size());
823 TextContainer text; 866 TextContainer text;
824 SkTDArray<void*> activeOps; 867 const SkTDArray<void*>* activeOps = NULL;
825 868
826 if (NULL != fStateTree && NULL != fBoundingHierarchy) { 869 if (NULL != fStateTree && NULL != fBoundingHierarchy) {
827 SkRect clipBounds; 870 SkRect clipBounds;
828 if (canvas.getClipBounds(&clipBounds)) { 871 if (canvas.getClipBounds(&clipBounds)) {
829 SkIRect query; 872 SkIRect query;
830 clipBounds.roundOut(&query); 873 clipBounds.roundOut(&query);
831 fBoundingHierarchy->search(query, &activeOps); 874
832 if (activeOps.count() == 0) { 875 const SkPicture::OperationList& activeOpsList = this->getActiveOps(q uery);
833 return; 876 if (activeOpsList.valid()) {
877 if (0 == activeOpsList.numOps()) {
878 return; // nothing to draw
879 }
880
881 // Since the opList is valid we know it is our derived class
882 activeOps = &((const CachedOperationList&)activeOpsList).fOps;
834 } 883 }
835 SkTQSort<SkPictureStateTree::Draw>(
836 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.begin()),
837 reinterpret_cast<SkPictureStateTree::Draw**>(activeOps.end()-1)) ;
838 } 884 }
839 } 885 }
840 886
841 SkPictureStateTree::Iterator it = (NULL == fStateTree) ? 887 SkPictureStateTree::Iterator it = (NULL == activeOps) ?
842 SkPictureStateTree::Iterator() : 888 SkPictureStateTree::Iterator() :
843 fStateTree->getIterator(activeOps, &canvas); 889 fStateTree->getIterator(*activeOps, &canvas);
844 890
845 if (it.isValid()) { 891 if (it.isValid()) {
846 uint32_t skipTo = it.draw(); 892 uint32_t skipTo = it.draw();
847 if (kDrawComplete == skipTo) { 893 if (kDrawComplete == skipTo) {
848 return; 894 return;
849 } 895 }
850 reader.setOffset(skipTo); 896 reader.setOffset(skipTo);
851 } 897 }
852 898
853 this->preLoadBitmaps(activeOps); 899 this->preLoadBitmaps(activeOps);
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 for (index = 0; index < fPictureCount; index++) 1811 for (index = 0; index < fPictureCount; index++)
1766 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ), 1812 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer ),
1767 "picture%p, ", fPictureRefs[index]); 1813 "picture%p, ", fPictureRefs[index]);
1768 if (fPictureCount > 0) 1814 if (fPictureCount > 0)
1769 SkDebugf("%s0};\n", pBuffer); 1815 SkDebugf("%s0};\n", pBuffer);
1770 1816
1771 const_cast<SkPicturePlayback*>(this)->dumpStream(); 1817 const_cast<SkPicturePlayback*>(this)->dumpStream();
1772 } 1818 }
1773 1819
1774 #endif 1820 #endif
OLDNEW
« src/core/SkPicturePlayback.h ('K') | « src/core/SkPicturePlayback.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698