| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include <new> | 7 #include <new> |
| 8 #include "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
| 9 #include "SkPicturePlayback.h" | 9 #include "SkPicturePlayback.h" |
| 10 #include "SkPictureRecord.h" | 10 #include "SkPictureRecord.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (record.fTextWrites != 0) | 92 if (record.fTextWrites != 0) |
| 93 SkDebugf("text size %zd (text strings:%d) ", record.fTextBytes, record.f
TextWrites); | 93 SkDebugf("text size %zd (text strings:%d) ", record.fTextBytes, record.f
TextWrites); |
| 94 | 94 |
| 95 SkDebugf("\n"); | 95 SkDebugf("\n"); |
| 96 #endif | 96 #endif |
| 97 #ifdef SK_DEBUG_DUMP | 97 #ifdef SK_DEBUG_DUMP |
| 98 record.dumpMatrices(); | 98 record.dumpMatrices(); |
| 99 record.dumpPaints(); | 99 record.dumpPaints(); |
| 100 #endif | 100 #endif |
| 101 | 101 |
| 102 record.validate(record.writeStream().bytesWritten(), 0); | |
| 103 const SkWriter32& writer = record.writeStream(); | |
| 104 this->init(); | 102 this->init(); |
| 105 SkASSERT(!fOpData); | 103 |
| 106 if (writer.bytesWritten() == 0) { | 104 fOpData = record.opData(deepCopyOps); |
| 107 fOpData = SkData::NewEmpty(); | |
| 108 return; | |
| 109 } | |
| 110 if (deepCopyOps) { | |
| 111 // Don't try to do anything clever w.r.t. copy on write | |
| 112 fOpData = SkData::NewWithCopy(writer.contiguousArray(), writer.bytesWrit
ten()); | |
| 113 } else { | |
| 114 fOpData = writer.snapshotAsData(); | |
| 115 } | |
| 116 | 105 |
| 117 fBoundingHierarchy = record.fBoundingHierarchy; | 106 fBoundingHierarchy = record.fBoundingHierarchy; |
| 118 fStateTree = record.fStateTree; | 107 fStateTree = record.fStateTree; |
| 119 | 108 |
| 120 SkSafeRef(fBoundingHierarchy); | 109 SkSafeRef(fBoundingHierarchy); |
| 121 SkSafeRef(fStateTree); | 110 SkSafeRef(fStateTree); |
| 111 fContentInfo.set(record.fContentInfo); |
| 122 | 112 |
| 123 if (NULL != fBoundingHierarchy) { | 113 if (NULL != fBoundingHierarchy) { |
| 124 fBoundingHierarchy->flushDeferredInserts(); | 114 fBoundingHierarchy->flushDeferredInserts(); |
| 125 } | 115 } |
| 126 | 116 |
| 127 // copy over the refcnt dictionary to our reader | 117 // copy over the refcnt dictionary to our reader |
| 128 record.fFlattenableHeap.setupPlaybacks(); | 118 record.fFlattenableHeap.setupPlaybacks(); |
| 129 | 119 |
| 130 fBitmaps = record.fBitmapHeap->extractBitmaps(); | 120 fBitmaps = record.fBitmapHeap->extractBitmaps(); |
| 131 fPaints = record.fPaints.unflattenToArray(); | 121 fPaints = record.fPaints.unflattenToArray(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 159 if (paths != 0) | 149 if (paths != 0) |
| 160 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths); | 150 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths); |
| 161 if (pictures != 0) | 151 if (pictures != 0) |
| 162 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures); | 152 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures); |
| 163 if (regions != 0) | 153 if (regions != 0) |
| 164 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions); | 154 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions); |
| 165 SkDebugf("\n"); | 155 SkDebugf("\n"); |
| 166 #endif | 156 #endif |
| 167 } | 157 } |
| 168 | 158 |
| 169 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, const SkPicturePl
ayback& src, | 159 SkPicturePlayback::SkPicturePlayback(const SkPicture* picture, |
| 160 const SkPicturePlayback& src, |
| 170 SkPictCopyInfo* deepCopyInfo) | 161 SkPictCopyInfo* deepCopyInfo) |
| 171 : fPicture(picture) | 162 : fPicture(picture) |
| 172 , fInfo(src.fInfo) { | 163 , fInfo(src.fInfo) { |
| 173 this->init(); | 164 this->init(); |
| 174 | 165 |
| 175 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); | 166 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); |
| 176 | 167 |
| 177 fOpData = SkSafeRef(src.fOpData); | 168 fOpData = SkSafeRef(src.fOpData); |
| 178 | 169 |
| 179 fBoundingHierarchy = src.fBoundingHierarchy; | 170 fBoundingHierarchy = src.fBoundingHierarchy; |
| 180 fStateTree = src.fStateTree; | 171 fStateTree = src.fStateTree; |
| 172 fContentInfo.set(src.fContentInfo); |
| 181 | 173 |
| 182 SkSafeRef(fBoundingHierarchy); | 174 SkSafeRef(fBoundingHierarchy); |
| 183 SkSafeRef(fStateTree); | 175 SkSafeRef(fStateTree); |
| 184 | 176 |
| 185 if (deepCopyInfo) { | 177 if (deepCopyInfo) { |
| 186 SkASSERT(deepCopyInfo->initialized); | 178 SkASSERT(deepCopyInfo->initialized); |
| 187 | 179 |
| 188 int paintCount = SafeCount(src.fPaints); | 180 int paintCount = SafeCount(src.fPaints); |
| 189 | 181 |
| 190 if (src.fBitmaps) { | 182 if (src.fBitmaps) { |
| (...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 skipCull.fSize; | 1320 skipCull.fSize; |
| 1329 SkDebugf("--- Clip skips %d%% rect:%d rrect:%d path:%d rgn:%d cull:%d\n"
, | 1321 SkDebugf("--- Clip skips %d%% rect:%d rrect:%d path:%d rgn:%d cull:%d\n"
, |
| 1330 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, | 1322 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, |
| 1331 skipPath.fCount, skipRegion.fCount, skipCull.fCount); | 1323 skipPath.fCount, skipRegion.fCount, skipCull.fCount); |
| 1332 SkDebugf("--- Total ops: %d\n", opCount); | 1324 SkDebugf("--- Total ops: %d\n", opCount); |
| 1333 } | 1325 } |
| 1334 #endif | 1326 #endif |
| 1335 // this->dumpSize(); | 1327 // this->dumpSize(); |
| 1336 } | 1328 } |
| 1337 | 1329 |
| 1330 |
| 1331 #if SK_SUPPORT_GPU |
| 1332 bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const ch
ar **reason) const { |
| 1333 // TODO: the heuristic used here needs to be refined |
| 1334 static const int kNumPaintWithPathEffectUsesTol = 1; |
| 1335 static const int kNumAAConcavePaths = 5; |
| 1336 |
| 1337 SkASSERT(fContentInfo.numAAHairlineConcavePaths() <= fContentInfo.numAAConca
vePaths()); |
| 1338 |
| 1339 bool ret = fContentInfo.numPaintWithPathEffectUses() < kNumPaintWithPathEffe
ctUsesTol && |
| 1340 (fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairli
neConcavePaths()) |
| 1341 < kNumAAConcavePaths; |
| 1342 if (!ret && NULL != reason) { |
| 1343 if (fContentInfo.numPaintWithPathEffectUses() >= kNumPaintWithPathEffect
UsesTol) |
| 1344 *reason = "Too many path effects."; |
| 1345 else if ((fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlineC
oncavePaths()) |
| 1346 >= kNumAAConcavePaths) |
| 1347 *reason = "Too many anti-aliased concave paths."; |
| 1348 else |
| 1349 *reason = "Unknown reason for GPU unsuitability."; |
| 1350 } |
| 1351 return ret; |
| 1352 } |
| 1353 #endif |
| 1338 /////////////////////////////////////////////////////////////////////////////// | 1354 /////////////////////////////////////////////////////////////////////////////// |
| 1339 | 1355 |
| 1340 #ifdef SK_DEBUG_SIZE | 1356 #ifdef SK_DEBUG_SIZE |
| 1341 int SkPicturePlayback::size(size_t* sizePtr) { | 1357 int SkPicturePlayback::size(size_t* sizePtr) { |
| 1342 int objects = bitmaps(sizePtr); | 1358 int objects = bitmaps(sizePtr); |
| 1343 objects += paints(sizePtr); | 1359 objects += paints(sizePtr); |
| 1344 objects += paths(sizePtr); | 1360 objects += paths(sizePtr); |
| 1345 objects += pictures(sizePtr); | 1361 objects += pictures(sizePtr); |
| 1346 objects += regions(sizePtr); | 1362 objects += regions(sizePtr); |
| 1347 *sizePtr = fOpData.size(); | 1363 *sizePtr = fOpData.size(); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 for (index = 0; index < fPictureCount; index++) | 1855 for (index = 0; index < fPictureCount; index++) |
| 1840 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1856 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
| 1841 "picture%p, ", fPictureRefs[index]); | 1857 "picture%p, ", fPictureRefs[index]); |
| 1842 if (fPictureCount > 0) | 1858 if (fPictureCount > 0) |
| 1843 SkDebugf("%s0};\n", pBuffer); | 1859 SkDebugf("%s0};\n", pBuffer); |
| 1844 | 1860 |
| 1845 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1861 const_cast<SkPicturePlayback*>(this)->dumpStream(); |
| 1846 } | 1862 } |
| 1847 | 1863 |
| 1848 #endif | 1864 #endif |
| OLD | NEW |