| 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 | 7 |
| 8 #include "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
| 9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
| 10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); | 37 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); |
| 38 | 38 |
| 39 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) | 39 SkPictureRecord::SkPictureRecord(const SkISize& dimensions, uint32_t flags) |
| 40 : INHERITED(dimensions.width(), dimensions.height()) | 40 : INHERITED(dimensions.width(), dimensions.height()) |
| 41 , fBoundingHierarchy(NULL) | 41 , fBoundingHierarchy(NULL) |
| 42 , fStateTree(NULL) | 42 , fStateTree(NULL) |
| 43 , fFlattenableHeap(HEAP_BLOCK_SIZE) | 43 , fFlattenableHeap(HEAP_BLOCK_SIZE) |
| 44 , fPaints(&fFlattenableHeap) | 44 , fPaints(&fFlattenableHeap) |
| 45 , fRecordFlags(flags) | 45 , fRecordFlags(flags) |
| 46 , fOptsEnabled(kBeClever) { | 46 , fOptsEnabled(kBeClever) { |
| 47 #ifdef SK_DEBUG_SIZE | |
| 48 fPointBytes = fRectBytes = fTextBytes = 0; | |
| 49 fPointWrites = fRectWrites = fTextWrites = 0; | |
| 50 #endif | |
| 51 | 47 |
| 52 fBitmapHeap = SkNEW(SkBitmapHeap); | 48 fBitmapHeap = SkNEW(SkBitmapHeap); |
| 53 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 49 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
| 54 | 50 |
| 55 fFirstSavedLayerIndex = kNoSavedLayerIndex; | 51 fFirstSavedLayerIndex = kNoSavedLayerIndex; |
| 56 fInitialSaveCount = kNoInitialSave; | 52 fInitialSaveCount = kNoInitialSave; |
| 57 } | 53 } |
| 58 | 54 |
| 59 SkPictureRecord::~SkPictureRecord() { | 55 SkPictureRecord::~SkPictureRecord() { |
| 60 SkSafeUnref(fBitmapHeap); | 56 SkSafeUnref(fBitmapHeap); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 219 |
| 224 uint32_t op; | 220 uint32_t op; |
| 225 UNPACK_8_24(peek, op, *size); | 221 UNPACK_8_24(peek, op, *size); |
| 226 if (MASK_24 == *size) { | 222 if (MASK_24 == *size) { |
| 227 // size required its own slot right after the op code | 223 // size required its own slot right after the op code |
| 228 *size = writer->readTAt<uint32_t>(offset + kUInt32Size); | 224 *size = writer->readTAt<uint32_t>(offset + kUInt32Size); |
| 229 } | 225 } |
| 230 return (DrawType) op; | 226 return (DrawType) op; |
| 231 } | 227 } |
| 232 | 228 |
| 233 #ifdef TRACK_COLLAPSE_STATS | |
| 234 static int gCollapseCount, gCollapseCalls; | |
| 235 #endif | |
| 236 | |
| 237 // Is the supplied paint simply a color? | 229 // Is the supplied paint simply a color? |
| 238 static bool is_simple(const SkPaint& p) { | 230 static bool is_simple(const SkPaint& p) { |
| 239 intptr_t orAccum = (intptr_t)p.getPathEffect() | | 231 intptr_t orAccum = (intptr_t)p.getPathEffect() | |
| 240 (intptr_t)p.getShader() | | 232 (intptr_t)p.getShader() | |
| 241 (intptr_t)p.getXfermode() | | 233 (intptr_t)p.getXfermode() | |
| 242 (intptr_t)p.getMaskFilter() | | 234 (intptr_t)p.getMaskFilter() | |
| 243 (intptr_t)p.getColorFilter() | | 235 (intptr_t)p.getColorFilter() | |
| 244 (intptr_t)p.getRasterizer() | | 236 (intptr_t)p.getRasterizer() | |
| 245 (intptr_t)p.getLooper() | | 237 (intptr_t)p.getLooper() | |
| 246 (intptr_t)p.getImageFilter(); | 238 (intptr_t)p.getImageFilter(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 /* | 457 /* |
| 466 * Restore has just been called (but not recorded), so look back at the | 458 * Restore has just been called (but not recorded), so look back at the |
| 467 * matching save(), and see if we can eliminate the pair of them, due to no | 459 * matching save(), and see if we can eliminate the pair of them, due to no |
| 468 * intervening matrix/clip calls. | 460 * intervening matrix/clip calls. |
| 469 * | 461 * |
| 470 * If so, update the writer and return true, in which case we won't even record | 462 * If so, update the writer and return true, in which case we won't even record |
| 471 * the restore() call. If we still need the restore(), return false. | 463 * the restore() call. If we still need the restore(), return false. |
| 472 */ | 464 */ |
| 473 static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset, | 465 static bool collapse_save_clip_restore(SkWriter32* writer, int32_t offset, |
| 474 SkPaintDictionary* paintDict) { | 466 SkPaintDictionary* paintDict) { |
| 475 #ifdef TRACK_COLLAPSE_STATS | |
| 476 gCollapseCalls += 1; | |
| 477 #endif | |
| 478 | |
| 479 int32_t restoreOffset = (int32_t)writer->bytesWritten(); | 467 int32_t restoreOffset = (int32_t)writer->bytesWritten(); |
| 480 | 468 |
| 481 // back up to the save block | 469 // back up to the save block |
| 482 while (offset > 0) { | 470 while (offset > 0) { |
| 483 offset = writer->readTAt<uint32_t>(offset); | 471 offset = writer->readTAt<uint32_t>(offset); |
| 484 } | 472 } |
| 485 | 473 |
| 486 // now offset points to a save | 474 // now offset points to a save |
| 487 offset = -offset; | 475 offset = -offset; |
| 488 uint32_t opSize; | 476 uint32_t opSize; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 501 offset += opSize; | 489 offset += opSize; |
| 502 while (offset < restoreOffset) { | 490 while (offset < restoreOffset) { |
| 503 op = peek_op_and_size(writer, offset, &opSize); | 491 op = peek_op_and_size(writer, offset, &opSize); |
| 504 if (is_drawing_op(op) || (SAVE_LAYER == op)) { | 492 if (is_drawing_op(op) || (SAVE_LAYER == op)) { |
| 505 // drawing verb, abort | 493 // drawing verb, abort |
| 506 return false; | 494 return false; |
| 507 } | 495 } |
| 508 offset += opSize; | 496 offset += opSize; |
| 509 } | 497 } |
| 510 | 498 |
| 511 #ifdef TRACK_COLLAPSE_STATS | |
| 512 gCollapseCount += 1; | |
| 513 SkDebugf("Collapse [%d out of %d] %g%spn", gCollapseCount, gCollapseCalls, | |
| 514 (double)gCollapseCount / gCollapseCalls, "%"); | |
| 515 #endif | |
| 516 | |
| 517 writer->rewindToOffset(saveOffset); | 499 writer->rewindToOffset(saveOffset); |
| 518 return true; | 500 return true; |
| 519 } | 501 } |
| 520 | 502 |
| 521 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, | 503 typedef bool (*PictureRecordOptProc)(SkWriter32* writer, int32_t offset, |
| 522 SkPaintDictionary* paintDict); | 504 SkPaintDictionary* paintDict); |
| 523 enum PictureRecordOptType { | 505 enum PictureRecordOptType { |
| 524 kRewind_OptType, // Optimization rewinds the command stream | 506 kRewind_OptType, // Optimization rewinds the command stream |
| 525 kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair | 507 kCollapseSaveLayer_OptType, // Optimization eliminates a save/restore pair |
| 526 }; | 508 }; |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 } else { | 1109 } else { |
| 1128 op = DRAW_POS_TEXT; | 1110 op = DRAW_POS_TEXT; |
| 1129 } | 1111 } |
| 1130 size_t initialOffset = this->addDraw(op, &size); | 1112 size_t initialOffset = this->addDraw(op, &size); |
| 1131 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); | 1113 SkASSERT(initialOffset+getPaintOffset(op, size) == fWriter.bytesWritten()); |
| 1132 const SkFlatData* flatPaintData = this->addPaint(paint); | 1114 const SkFlatData* flatPaintData = this->addPaint(paint); |
| 1133 SkASSERT(flatPaintData); | 1115 SkASSERT(flatPaintData); |
| 1134 this->addText(text, byteLength); | 1116 this->addText(text, byteLength); |
| 1135 this->addInt(points); | 1117 this->addInt(points); |
| 1136 | 1118 |
| 1137 #ifdef SK_DEBUG_SIZE | |
| 1138 size_t start = fWriter.bytesWritten(); | |
| 1139 #endif | |
| 1140 if (canUseDrawH) { | 1119 if (canUseDrawH) { |
| 1141 if (fast) { | 1120 if (fast) { |
| 1142 this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[
0].fY); | 1121 this->addFontMetricsTopBottom(paint, *flatPaintData, pos[0].fY, pos[
0].fY); |
| 1143 } | 1122 } |
| 1144 this->addScalar(pos[0].fY); | 1123 this->addScalar(pos[0].fY); |
| 1145 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); | 1124 SkScalar* xptr = (SkScalar*)fWriter.reserve(points * sizeof(SkScalar)); |
| 1146 for (int index = 0; index < points; index++) | 1125 for (int index = 0; index < points; index++) |
| 1147 *xptr++ = pos[index].fX; | 1126 *xptr++ = pos[index].fX; |
| 1148 } else { | 1127 } else { |
| 1149 fWriter.writeMul4(pos, points * sizeof(SkPoint)); | 1128 fWriter.writeMul4(pos, points * sizeof(SkPoint)); |
| 1150 if (fastBounds) { | 1129 if (fastBounds) { |
| 1151 this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); | 1130 this->addFontMetricsTopBottom(paint, *flatPaintData, minY, maxY); |
| 1152 } | 1131 } |
| 1153 } | 1132 } |
| 1154 #ifdef SK_DEBUG_SIZE | |
| 1155 fPointBytes += fWriter.bytesWritten() - start; | |
| 1156 fPointWrites += points; | |
| 1157 #endif | |
| 1158 this->validate(initialOffset, size); | 1133 this->validate(initialOffset, size); |
| 1159 } | 1134 } |
| 1160 | 1135 |
| 1161 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const
SkScalar xpos[], | 1136 void SkPictureRecord::onDrawPosTextH(const void* text, size_t byteLength, const
SkScalar xpos[], |
| 1162 SkScalar constY, const SkPaint& paint) { | 1137 SkScalar constY, const SkPaint& paint) { |
| 1163 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); | 1138 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); |
| 1164 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData)
; | 1139 this->drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData)
; |
| 1165 } | 1140 } |
| 1166 | 1141 |
| 1167 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, | 1142 void SkPictureRecord::drawPosTextHImpl(const void* text, size_t byteLength, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1182 // + y + the actual points | 1157 // + y + the actual points |
| 1183 size += 1 * kUInt32Size + points * sizeof(SkScalar); | 1158 size += 1 * kUInt32Size + points * sizeof(SkScalar); |
| 1184 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA
W_POS_TEXT_H, | 1159 size_t initialOffset = this->addDraw(fast ? DRAW_POS_TEXT_H_TOP_BOTTOM : DRA
W_POS_TEXT_H, |
| 1185 &size); | 1160 &size); |
| 1186 SkASSERT(flatPaintData); | 1161 SkASSERT(flatPaintData); |
| 1187 this->addFlatPaint(flatPaintData); | 1162 this->addFlatPaint(flatPaintData); |
| 1188 | 1163 |
| 1189 this->addText(text, byteLength); | 1164 this->addText(text, byteLength); |
| 1190 this->addInt(points); | 1165 this->addInt(points); |
| 1191 | 1166 |
| 1192 #ifdef SK_DEBUG_SIZE | |
| 1193 size_t start = fWriter.bytesWritten(); | |
| 1194 #endif | |
| 1195 if (fast) { | 1167 if (fast) { |
| 1196 this->addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); | 1168 this->addFontMetricsTopBottom(paint, *flatPaintData, constY, constY); |
| 1197 } | 1169 } |
| 1198 this->addScalar(constY); | 1170 this->addScalar(constY); |
| 1199 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); | 1171 fWriter.writeMul4(xpos, points * sizeof(SkScalar)); |
| 1200 #ifdef SK_DEBUG_SIZE | |
| 1201 fPointBytes += fWriter.bytesWritten() - start; | |
| 1202 fPointWrites += points; | |
| 1203 #endif | |
| 1204 this->validate(initialOffset, size); | 1172 this->validate(initialOffset, size); |
| 1205 } | 1173 } |
| 1206 | 1174 |
| 1207 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons
t SkPath& path, | 1175 void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons
t SkPath& path, |
| 1208 const SkMatrix* matrix, const SkPaint& pa
int) { | 1176 const SkMatrix* matrix, const SkPaint& pa
int) { |
| 1209 // op + paint index + length + 'length' worth of data + path index + matrix | 1177 // op + paint index + length + 'length' worth of data + path index + matrix |
| 1210 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); | 1178 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
| 1211 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write
ToMemory(NULL); | 1179 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write
ToMemory(NULL); |
| 1212 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); | 1180 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
| 1213 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); | 1181 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 if (index < 0) { // not found | 1415 if (index < 0) { // not found |
| 1448 index = fPictureRefs.count(); | 1416 index = fPictureRefs.count(); |
| 1449 *fPictureRefs.append() = picture; | 1417 *fPictureRefs.append() = picture; |
| 1450 picture->ref(); | 1418 picture->ref(); |
| 1451 } | 1419 } |
| 1452 // follow the convention of recording a 1-based index | 1420 // follow the convention of recording a 1-based index |
| 1453 this->addInt(index + 1); | 1421 this->addInt(index + 1); |
| 1454 } | 1422 } |
| 1455 | 1423 |
| 1456 void SkPictureRecord::addPoint(const SkPoint& point) { | 1424 void SkPictureRecord::addPoint(const SkPoint& point) { |
| 1457 #ifdef SK_DEBUG_SIZE | |
| 1458 size_t start = fWriter.bytesWritten(); | |
| 1459 #endif | |
| 1460 fWriter.writePoint(point); | 1425 fWriter.writePoint(point); |
| 1461 #ifdef SK_DEBUG_SIZE | |
| 1462 fPointBytes += fWriter.bytesWritten() - start; | |
| 1463 fPointWrites++; | |
| 1464 #endif | |
| 1465 } | 1426 } |
| 1466 | 1427 |
| 1467 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { | 1428 void SkPictureRecord::addPoints(const SkPoint pts[], int count) { |
| 1468 fWriter.writeMul4(pts, count * sizeof(SkPoint)); | 1429 fWriter.writeMul4(pts, count * sizeof(SkPoint)); |
| 1469 #ifdef SK_DEBUG_SIZE | |
| 1470 fPointBytes += count * sizeof(SkPoint); | |
| 1471 fPointWrites++; | |
| 1472 #endif | |
| 1473 } | 1430 } |
| 1474 | 1431 |
| 1475 void SkPictureRecord::addNoOp() { | 1432 void SkPictureRecord::addNoOp() { |
| 1476 size_t size = kUInt32Size; // op | 1433 size_t size = kUInt32Size; // op |
| 1477 this->addDraw(NOOP, &size); | 1434 this->addDraw(NOOP, &size); |
| 1478 } | 1435 } |
| 1479 | 1436 |
| 1480 void SkPictureRecord::addRect(const SkRect& rect) { | 1437 void SkPictureRecord::addRect(const SkRect& rect) { |
| 1481 #ifdef SK_DEBUG_SIZE | |
| 1482 size_t start = fWriter.bytesWritten(); | |
| 1483 #endif | |
| 1484 fWriter.writeRect(rect); | 1438 fWriter.writeRect(rect); |
| 1485 #ifdef SK_DEBUG_SIZE | |
| 1486 fRectBytes += fWriter.bytesWritten() - start; | |
| 1487 fRectWrites++; | |
| 1488 #endif | |
| 1489 } | 1439 } |
| 1490 | 1440 |
| 1491 void SkPictureRecord::addRectPtr(const SkRect* rect) { | 1441 void SkPictureRecord::addRectPtr(const SkRect* rect) { |
| 1492 if (fWriter.writeBool(rect != NULL)) { | 1442 if (fWriter.writeBool(rect != NULL)) { |
| 1493 fWriter.writeRect(*rect); | 1443 fWriter.writeRect(*rect); |
| 1494 } | 1444 } |
| 1495 } | 1445 } |
| 1496 | 1446 |
| 1497 void SkPictureRecord::addIRect(const SkIRect& rect) { | 1447 void SkPictureRecord::addIRect(const SkIRect& rect) { |
| 1498 fWriter.write(&rect, sizeof(rect)); | 1448 fWriter.write(&rect, sizeof(rect)); |
| 1499 } | 1449 } |
| 1500 | 1450 |
| 1501 void SkPictureRecord::addIRectPtr(const SkIRect* rect) { | 1451 void SkPictureRecord::addIRectPtr(const SkIRect* rect) { |
| 1502 if (fWriter.writeBool(rect != NULL)) { | 1452 if (fWriter.writeBool(rect != NULL)) { |
| 1503 *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; | 1453 *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |
| 1504 } | 1454 } |
| 1505 } | 1455 } |
| 1506 | 1456 |
| 1507 void SkPictureRecord::addRRect(const SkRRect& rrect) { | 1457 void SkPictureRecord::addRRect(const SkRRect& rrect) { |
| 1508 fWriter.writeRRect(rrect); | 1458 fWriter.writeRRect(rrect); |
| 1509 } | 1459 } |
| 1510 | 1460 |
| 1511 void SkPictureRecord::addRegion(const SkRegion& region) { | 1461 void SkPictureRecord::addRegion(const SkRegion& region) { |
| 1512 fWriter.writeRegion(region); | 1462 fWriter.writeRegion(region); |
| 1513 } | 1463 } |
| 1514 | 1464 |
| 1515 void SkPictureRecord::addText(const void* text, size_t byteLength) { | 1465 void SkPictureRecord::addText(const void* text, size_t byteLength) { |
| 1516 fContentInfo.onDrawText(); | 1466 fContentInfo.onDrawText(); |
| 1517 #ifdef SK_DEBUG_SIZE | |
| 1518 size_t start = fWriter.bytesWritten(); | |
| 1519 #endif | |
| 1520 addInt(SkToInt(byteLength)); | 1467 addInt(SkToInt(byteLength)); |
| 1521 fWriter.writePad(text, byteLength); | 1468 fWriter.writePad(text, byteLength); |
| 1522 #ifdef SK_DEBUG_SIZE | |
| 1523 fTextBytes += fWriter.bytesWritten() - start; | |
| 1524 fTextWrites++; | |
| 1525 #endif | |
| 1526 } | 1469 } |
| 1527 | 1470 |
| 1528 /////////////////////////////////////////////////////////////////////////////// | 1471 /////////////////////////////////////////////////////////////////////////////// |
| 1529 | 1472 |
| 1530 #ifdef SK_DEBUG_SIZE | |
| 1531 size_t SkPictureRecord::size() const { | |
| 1532 size_t result = 0; | |
| 1533 size_t sizeData; | |
| 1534 bitmaps(&sizeData); | |
| 1535 result += sizeData; | |
| 1536 matrices(&sizeData); | |
| 1537 result += sizeData; | |
| 1538 paints(&sizeData); | |
| 1539 result += sizeData; | |
| 1540 paths(&sizeData); | |
| 1541 result += sizeData; | |
| 1542 pictures(&sizeData); | |
| 1543 result += sizeData; | |
| 1544 regions(&sizeData); | |
| 1545 result += sizeData; | |
| 1546 result += streamlen(); | |
| 1547 return result; | |
| 1548 } | |
| 1549 | |
| 1550 int SkPictureRecord::bitmaps(size_t* size) const { | |
| 1551 size_t result = 0; | |
| 1552 int count = fBitmaps.count(); | |
| 1553 for (int index = 0; index < count; index++) | |
| 1554 result += sizeof(fBitmaps[index]) + fBitmaps[index]->size(); | |
| 1555 *size = result; | |
| 1556 return count; | |
| 1557 } | |
| 1558 | |
| 1559 int SkPictureRecord::matrices(size_t* size) const { | |
| 1560 int count = fMatrices.count(); | |
| 1561 *size = sizeof(fMatrices[0]) * count; | |
| 1562 return count; | |
| 1563 } | |
| 1564 | |
| 1565 int SkPictureRecord::paints(size_t* size) const { | |
| 1566 size_t result = 0; | |
| 1567 int count = fPaints.count(); | |
| 1568 for (int index = 0; index < count; index++) | |
| 1569 result += sizeof(fPaints[index]) + fPaints[index]->size(); | |
| 1570 *size = result; | |
| 1571 return count; | |
| 1572 } | |
| 1573 | |
| 1574 int SkPictureRecord::paths(size_t* size) const { | |
| 1575 size_t result = 0; | |
| 1576 int count = fPaths.count(); | |
| 1577 for (int index = 0; index < count; index++) | |
| 1578 result += sizeof(fPaths[index]) + fPaths[index]->size(); | |
| 1579 *size = result; | |
| 1580 return count; | |
| 1581 } | |
| 1582 | |
| 1583 int SkPictureRecord::regions(size_t* size) const { | |
| 1584 size_t result = 0; | |
| 1585 int count = fRegions.count(); | |
| 1586 for (int index = 0; index < count; index++) | |
| 1587 result += sizeof(fRegions[index]) + fRegions[index]->size(); | |
| 1588 *size = result; | |
| 1589 return count; | |
| 1590 } | |
| 1591 | |
| 1592 size_t SkPictureRecord::streamlen() const { | |
| 1593 return fWriter.size(); | |
| 1594 } | |
| 1595 #endif | |
| 1596 | |
| 1597 #ifdef SK_DEBUG_VALIDATE | |
| 1598 void SkPictureRecord::validate(uint32_t initialOffset, uint32_t size) const { | |
| 1599 SkASSERT(fWriter.size() == initialOffset + size); | |
| 1600 | |
| 1601 validateBitmaps(); | |
| 1602 validateMatrices(); | |
| 1603 validatePaints(); | |
| 1604 validatePaths(); | |
| 1605 validateRegions(); | |
| 1606 } | |
| 1607 | |
| 1608 void SkPictureRecord::validateBitmaps() const { | |
| 1609 int count = fBitmapHeap->count(); | |
| 1610 SkASSERT((unsigned) count < 0x1000); | |
| 1611 for (int index = 0; index < count; index++) { | |
| 1612 const SkBitmap* bitPtr = fBitmapHeap->getBitmap(index); | |
| 1613 SkASSERT(bitPtr); | |
| 1614 bitPtr->validate(); | |
| 1615 } | |
| 1616 } | |
| 1617 | |
| 1618 void SkPictureRecord::validateMatrices() const { | |
| 1619 int count = fMatrices.count(); | |
| 1620 SkASSERT((unsigned) count < 0x1000); | |
| 1621 for (int index = 0; index < count; index++) { | |
| 1622 const SkFlatData* matrix = fMatrices[index]; | |
| 1623 SkASSERT(matrix); | |
| 1624 // matrix->validate(); | |
| 1625 } | |
| 1626 } | |
| 1627 | |
| 1628 void SkPictureRecord::validatePaints() const { | |
| 1629 int count = fPaints.count(); | |
| 1630 SkASSERT((unsigned) count < 0x1000); | |
| 1631 for (int index = 0; index < count; index++) { | |
| 1632 const SkFlatData* paint = fPaints[index]; | |
| 1633 SkASSERT(paint); | |
| 1634 // paint->validate(); | |
| 1635 } | |
| 1636 } | |
| 1637 | |
| 1638 void SkPictureRecord::validatePaths() const { | |
| 1639 if (NULL == fPathHeap) { | |
| 1640 return; | |
| 1641 } | |
| 1642 | |
| 1643 int count = fPathHeap->count(); | |
| 1644 SkASSERT((unsigned) count < 0x1000); | |
| 1645 for (int index = 0; index < count; index++) { | |
| 1646 const SkPath& path = (*fPathHeap)[index]; | |
| 1647 path.validate(); | |
| 1648 } | |
| 1649 } | |
| 1650 | |
| 1651 void SkPictureRecord::validateRegions() const { | |
| 1652 int count = fRegions.count(); | |
| 1653 SkASSERT((unsigned) count < 0x1000); | |
| 1654 for (int index = 0; index < count; index++) { | |
| 1655 const SkFlatData* region = fRegions[index]; | |
| 1656 SkASSERT(region); | |
| 1657 // region->validate(); | |
| 1658 } | |
| 1659 } | |
| 1660 #endif | |
| OLD | NEW |