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

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

Powered by Google App Engine
This is Rietveld 408576698