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 "SkPictureRecord.h" | 8 #include "SkPictureRecord.h" |
9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 static const uint32_t kSaveSize = 2 * kUInt32Size; | 26 static const uint32_t kSaveSize = 2 * kUInt32Size; |
27 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; | 27 static const uint32_t kSaveLayerNoBoundsSize = 4 * kUInt32Size; |
28 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); | 28 static const uint32_t kSaveLayerWithBoundsSize = 4 * kUInt32Size + sizeof(SkRect
); |
29 | 29 |
30 SkPictureRecord::SkPictureRecord(uint32_t flags, SkBaseDevice* device) : | 30 SkPictureRecord::SkPictureRecord(uint32_t flags, SkBaseDevice* device) : |
31 INHERITED(device), | 31 INHERITED(device), |
32 fBoundingHierarchy(NULL), | 32 fBoundingHierarchy(NULL), |
33 fStateTree(NULL), | 33 fStateTree(NULL), |
34 fFlattenableHeap(HEAP_BLOCK_SIZE), | 34 fFlattenableHeap(HEAP_BLOCK_SIZE), |
35 fMatrices(&fFlattenableHeap), | |
36 fPaints(&fFlattenableHeap), | 35 fPaints(&fFlattenableHeap), |
37 fRegions(&fFlattenableHeap), | |
38 fRecordFlags(flags) { | 36 fRecordFlags(flags) { |
39 #ifdef SK_DEBUG_SIZE | 37 #ifdef SK_DEBUG_SIZE |
40 fPointBytes = fRectBytes = fTextBytes = 0; | 38 fPointBytes = fRectBytes = fTextBytes = 0; |
41 fPointWrites = fRectWrites = fTextWrites = 0; | 39 fPointWrites = fRectWrites = fTextWrites = 0; |
42 #endif | 40 #endif |
43 | 41 |
44 fRestoreOffsetStack.setReserve(32); | 42 fRestoreOffsetStack.setReserve(32); |
45 | 43 |
46 fBitmapHeap = SkNEW(SkBitmapHeap); | 44 fBitmapHeap = SkNEW(SkBitmapHeap); |
47 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 45 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); | 652 uint32_t size = 1 * kUInt32Size + 2 * sizeof(SkScalar); |
655 size_t initialOffset = this->addDraw(SKEW, &size); | 653 size_t initialOffset = this->addDraw(SKEW, &size); |
656 addScalar(sx); | 654 addScalar(sx); |
657 addScalar(sy); | 655 addScalar(sy); |
658 this->validate(initialOffset, size); | 656 this->validate(initialOffset, size); |
659 return this->INHERITED::skew(sx, sy); | 657 return this->INHERITED::skew(sx, sy); |
660 } | 658 } |
661 | 659 |
662 bool SkPictureRecord::concat(const SkMatrix& matrix) { | 660 bool SkPictureRecord::concat(const SkMatrix& matrix) { |
663 this->validate(fWriter.bytesWritten(), 0); | 661 this->validate(fWriter.bytesWritten(), 0); |
664 // op + matrix index | 662 // op + matrix |
665 uint32_t size = 2 * kUInt32Size; | 663 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); |
666 size_t initialOffset = this->addDraw(CONCAT, &size); | 664 size_t initialOffset = this->addDraw(CONCAT, &size); |
667 addMatrix(matrix); | 665 addMatrix(matrix); |
668 this->validate(initialOffset, size); | 666 this->validate(initialOffset, size); |
669 return this->INHERITED::concat(matrix); | 667 return this->INHERITED::concat(matrix); |
670 } | 668 } |
671 | 669 |
672 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { | 670 void SkPictureRecord::setMatrix(const SkMatrix& matrix) { |
673 this->validate(fWriter.bytesWritten(), 0); | 671 this->validate(fWriter.bytesWritten(), 0); |
674 // op + matrix index | 672 // op + matrix |
675 uint32_t size = 2 * kUInt32Size; | 673 uint32_t size = kUInt32Size + matrix.writeToMemory(NULL); |
676 size_t initialOffset = this->addDraw(SET_MATRIX, &size); | 674 size_t initialOffset = this->addDraw(SET_MATRIX, &size); |
677 addMatrix(matrix); | 675 addMatrix(matrix); |
678 this->validate(initialOffset, size); | 676 this->validate(initialOffset, size); |
679 this->INHERITED::setMatrix(matrix); | 677 this->INHERITED::setMatrix(matrix); |
680 } | 678 } |
681 | 679 |
682 static bool regionOpExpands(SkRegion::Op op) { | 680 static bool regionOpExpands(SkRegion::Op op) { |
683 switch (op) { | 681 switch (op) { |
684 case SkRegion::kUnion_Op: | 682 case SkRegion::kUnion_Op: |
685 case SkRegion::kXOR_Op: | 683 case SkRegion::kXOR_Op: |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 | 816 |
819 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { | 817 if (fRecordFlags & SkPicture::kUsePathBoundsForClip_RecordingFlag) { |
820 return this->updateClipConservativelyUsingBounds(path.getBounds(), op, | 818 return this->updateClipConservativelyUsingBounds(path.getBounds(), op, |
821 path.isInverseFillType(
)); | 819 path.isInverseFillType(
)); |
822 } else { | 820 } else { |
823 return this->INHERITED::clipPath(path, op, doAA); | 821 return this->INHERITED::clipPath(path, op, doAA); |
824 } | 822 } |
825 } | 823 } |
826 | 824 |
827 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { | 825 bool SkPictureRecord::clipRegion(const SkRegion& region, SkRegion::Op op) { |
828 // op + region index + clip params | 826 // op + clip params + region |
829 uint32_t size = 3 * kUInt32Size; | 827 uint32_t size = 2 * kUInt32Size + region.writeToMemory(NULL); |
830 // recordRestoreOffsetPlaceholder doesn't always write an offset | 828 // recordRestoreOffsetPlaceholder doesn't always write an offset |
831 if (!fRestoreOffsetStack.isEmpty()) { | 829 if (!fRestoreOffsetStack.isEmpty()) { |
832 // + restore offset | 830 // + restore offset |
833 size += kUInt32Size; | 831 size += kUInt32Size; |
834 } | 832 } |
835 size_t initialOffset = this->addDraw(CLIP_REGION, &size); | 833 size_t initialOffset = this->addDraw(CLIP_REGION, &size); |
836 addRegion(region); | 834 addRegion(region); |
837 addInt(ClipParams_pack(op, false)); | 835 addInt(ClipParams_pack(op, false)); |
838 recordRestoreOffsetPlaceholder(op); | 836 recordRestoreOffsetPlaceholder(op); |
839 | 837 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 addPaintPtr(paint); | 944 addPaintPtr(paint); |
947 addBitmap(bitmap); | 945 addBitmap(bitmap); |
948 addRectPtr(src); // may be null | 946 addRectPtr(src); // may be null |
949 addRect(dst); | 947 addRect(dst); |
950 addInt(flags); | 948 addInt(flags); |
951 this->validate(initialOffset, size); | 949 this->validate(initialOffset, size); |
952 } | 950 } |
953 | 951 |
954 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, | 952 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, |
955 const SkPaint* paint) { | 953 const SkPaint* paint) { |
956 // id + paint index + bitmap index + matrix index | 954 // id + paint index + bitmap index + matrix |
957 uint32_t size = 4 * kUInt32Size; | 955 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); |
958 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); | 956 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); |
959 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b
ytesWritten()); | 957 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b
ytesWritten()); |
960 addPaintPtr(paint); | 958 addPaintPtr(paint); |
961 addBitmap(bitmap); | 959 addBitmap(bitmap); |
962 addMatrix(matrix); | 960 addMatrix(matrix); |
963 this->validate(initialOffset, size); | 961 this->validate(initialOffset, size); |
964 } | 962 } |
965 | 963 |
966 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, | 964 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, |
967 const SkRect& dst, const SkPaint* paint) { | 965 const SkRect& dst, const SkPaint* paint) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 #ifdef SK_DEBUG_SIZE | 1157 #ifdef SK_DEBUG_SIZE |
1160 fPointBytes += fWriter.bytesWritten() - start; | 1158 fPointBytes += fWriter.bytesWritten() - start; |
1161 fPointWrites += points; | 1159 fPointWrites += points; |
1162 #endif | 1160 #endif |
1163 this->validate(initialOffset, size); | 1161 this->validate(initialOffset, size); |
1164 } | 1162 } |
1165 | 1163 |
1166 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, | 1164 void SkPictureRecord::drawTextOnPath(const void* text, size_t byteLength, |
1167 const SkPath& path, const SkMatrix* matrix, | 1165 const SkPath& path, const SkMatrix* matrix, |
1168 const SkPaint& paint) { | 1166 const SkPaint& paint) { |
1169 // op + paint index + length + 'length' worth of data + path index + matrix
index | 1167 // op + paint index + length + 'length' worth of data + path index + matrix |
1170 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + 2 * kUInt32Size; | 1168 const SkMatrix& m = matrix ? *matrix : SkMatrix::I(); |
| 1169 uint32_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.wri
teToMemory(NULL); |
1171 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); | 1170 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
1172 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); | 1171 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); |
1173 addPaint(paint); | 1172 addPaint(paint); |
1174 addText(text, byteLength); | 1173 addText(text, byteLength); |
1175 addPath(path); | 1174 addPath(path); |
1176 addMatrixPtr(matrix); | 1175 addMatrix(m); |
1177 this->validate(initialOffset, size); | 1176 this->validate(initialOffset, size); |
1178 } | 1177 } |
1179 | 1178 |
1180 void SkPictureRecord::drawPicture(SkPicture& picture) { | 1179 void SkPictureRecord::drawPicture(SkPicture& picture) { |
1181 // op + picture index | 1180 // op + picture index |
1182 uint32_t size = 2 * kUInt32Size; | 1181 uint32_t size = 2 * kUInt32Size; |
1183 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); | 1182 size_t initialOffset = this->addDraw(DRAW_PICTURE, &size); |
1184 addPicture(picture); | 1183 addPicture(picture); |
1185 this->validate(initialOffset, size); | 1184 this->validate(initialOffset, size); |
1186 } | 1185 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | 1288 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
1290 const int index = fBitmapHeap->insert(bitmap); | 1289 const int index = fBitmapHeap->insert(bitmap); |
1291 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In | 1290 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In |
1292 // release builds, the invalid value will be recorded so that the reader wil
l know that there | 1291 // release builds, the invalid value will be recorded so that the reader wil
l know that there |
1293 // was a problem. | 1292 // was a problem. |
1294 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); | 1293 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); |
1295 addInt(index); | 1294 addInt(index); |
1296 } | 1295 } |
1297 | 1296 |
1298 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { | 1297 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
1299 addMatrixPtr(&matrix); | 1298 fWriter.writeMatrix(matrix); |
1300 } | |
1301 | |
1302 void SkPictureRecord::addMatrixPtr(const SkMatrix* matrix) { | |
1303 this->addInt(matrix ? fMatrices.find(*matrix) : 0); | |
1304 } | 1299 } |
1305 | 1300 |
1306 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { | 1301 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { |
1307 return fPaints.findAndReturnFlat(paint); | 1302 return fPaints.findAndReturnFlat(paint); |
1308 } | 1303 } |
1309 | 1304 |
1310 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { | 1305 const SkFlatData* SkPictureRecord::addPaintPtr(const SkPaint* paint) { |
1311 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; | 1306 const SkFlatData* data = paint ? getFlatPaintData(*paint) : NULL; |
1312 this->addFlatPaint(data); | 1307 this->addFlatPaint(data); |
1313 return data; | 1308 return data; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 if (fWriter.writeBool(rect != NULL)) { | 1375 if (fWriter.writeBool(rect != NULL)) { |
1381 *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; | 1376 *(SkIRect*)fWriter.reserve(sizeof(SkIRect)) = *rect; |
1382 } | 1377 } |
1383 } | 1378 } |
1384 | 1379 |
1385 void SkPictureRecord::addRRect(const SkRRect& rrect) { | 1380 void SkPictureRecord::addRRect(const SkRRect& rrect) { |
1386 fWriter.writeRRect(rrect); | 1381 fWriter.writeRRect(rrect); |
1387 } | 1382 } |
1388 | 1383 |
1389 void SkPictureRecord::addRegion(const SkRegion& region) { | 1384 void SkPictureRecord::addRegion(const SkRegion& region) { |
1390 addInt(fRegions.find(region)); | 1385 fWriter.writeRegion(region); |
1391 } | 1386 } |
1392 | 1387 |
1393 void SkPictureRecord::addText(const void* text, size_t byteLength) { | 1388 void SkPictureRecord::addText(const void* text, size_t byteLength) { |
1394 #ifdef SK_DEBUG_SIZE | 1389 #ifdef SK_DEBUG_SIZE |
1395 size_t start = fWriter.bytesWritten(); | 1390 size_t start = fWriter.bytesWritten(); |
1396 #endif | 1391 #endif |
1397 addInt(byteLength); | 1392 addInt(byteLength); |
1398 fWriter.writePad(text, byteLength); | 1393 fWriter.writePad(text, byteLength); |
1399 #ifdef SK_DEBUG_SIZE | 1394 #ifdef SK_DEBUG_SIZE |
1400 fTextBytes += fWriter.bytesWritten() - start; | 1395 fTextBytes += fWriter.bytesWritten() - start; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 void SkPictureRecord::validateRegions() const { | 1523 void SkPictureRecord::validateRegions() const { |
1529 int count = fRegions.count(); | 1524 int count = fRegions.count(); |
1530 SkASSERT((unsigned) count < 0x1000); | 1525 SkASSERT((unsigned) count < 0x1000); |
1531 for (int index = 0; index < count; index++) { | 1526 for (int index = 0; index < count; index++) { |
1532 const SkFlatData* region = fRegions[index]; | 1527 const SkFlatData* region = fRegions[index]; |
1533 SkASSERT(region); | 1528 SkASSERT(region); |
1534 // region->validate(); | 1529 // region->validate(); |
1535 } | 1530 } |
1536 } | 1531 } |
1537 #endif | 1532 #endif |
OLD | NEW |