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" |
11 #include "SkRRect.h" | 11 #include "SkRRect.h" |
12 #include "SkBBoxHierarchy.h" | 12 #include "SkBBoxHierarchy.h" |
13 #include "SkDevice.h" | 13 #include "SkDevice.h" |
| 14 #include "SkOffsetTable.h" |
14 #include "SkPictureStateTree.h" | 15 #include "SkPictureStateTree.h" |
15 #include "SkSurface.h" | 16 #include "SkSurface.h" |
16 | 17 |
17 #define HEAP_BLOCK_SIZE 4096 | 18 #define HEAP_BLOCK_SIZE 4096 |
18 | 19 |
19 enum { | 20 enum { |
20 // just need a value that save or getSaveCount would never return | 21 // just need a value that save or getSaveCount would never return |
21 kNoInitialSave = -1, | 22 kNoInitialSave = -1, |
22 }; | 23 }; |
23 | 24 |
(...skipping 13 matching lines...) Expand all Loading... |
37 , fRecordFlags(flags) | 38 , fRecordFlags(flags) |
38 , fOptsEnabled(true) { | 39 , fOptsEnabled(true) { |
39 #ifdef SK_DEBUG_SIZE | 40 #ifdef SK_DEBUG_SIZE |
40 fPointBytes = fRectBytes = fTextBytes = 0; | 41 fPointBytes = fRectBytes = fTextBytes = 0; |
41 fPointWrites = fRectWrites = fTextWrites = 0; | 42 fPointWrites = fRectWrites = fTextWrites = 0; |
42 #endif | 43 #endif |
43 | 44 |
44 fBitmapHeap = SkNEW(SkBitmapHeap); | 45 fBitmapHeap = SkNEW(SkBitmapHeap); |
45 fFlattenableHeap.setBitmapStorage(fBitmapHeap); | 46 fFlattenableHeap.setBitmapStorage(fBitmapHeap); |
46 fPathHeap = NULL; // lazy allocate | 47 fPathHeap = NULL; // lazy allocate |
| 48 |
47 #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE | 49 #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
48 fFirstSavedLayerIndex = kNoSavedLayerIndex; | 50 fFirstSavedLayerIndex = kNoSavedLayerIndex; |
49 #endif | 51 #endif |
50 | 52 |
51 fInitialSaveCount = kNoInitialSave; | 53 fInitialSaveCount = kNoInitialSave; |
52 | 54 |
53 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 55 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
54 fMCMgr.init(this); | 56 fMCMgr.init(this); |
55 #endif | 57 #endif |
56 } | 58 } |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1120 |
1119 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1121 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1120 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1122 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1121 #endif | 1123 #endif |
1122 | 1124 |
1123 // op + paint index + bitmap index + left + top | 1125 // op + paint index + bitmap index + left + top |
1124 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); | 1126 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); |
1125 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); | 1127 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); |
1126 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri
tten()); | 1128 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri
tten()); |
1127 this->addPaintPtr(paint); | 1129 this->addPaintPtr(paint); |
1128 this->addBitmap(bitmap); | 1130 int bitmapID = this->addBitmap(bitmap); |
1129 this->addScalar(left); | 1131 this->addScalar(left); |
1130 this->addScalar(top); | 1132 this->addScalar(top); |
1131 this->validate(initialOffset, size); | 1133 this->validate(initialOffset, size); |
| 1134 this->trackBitmapUse(bitmapID, initialOffset); |
1132 } | 1135 } |
1133 | 1136 |
1134 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, | 1137 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect*
src, |
1135 const SkRect& dst, const SkPaint* pai
nt, | 1138 const SkRect& dst, const SkPaint* pai
nt, |
1136 DrawBitmapRectFlags flags) { | 1139 DrawBitmapRectFlags flags) { |
1137 if (bitmap.drawsNothing()) { | 1140 if (bitmap.drawsNothing()) { |
1138 return; | 1141 return; |
1139 } | 1142 } |
1140 | 1143 |
1141 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1144 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1142 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1145 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1143 #endif | 1146 #endif |
1144 // id + paint index + bitmap index + bool for 'src' + flags | 1147 // id + paint index + bitmap index + bool for 'src' + flags |
1145 uint32_t size = 5 * kUInt32Size; | 1148 uint32_t size = 5 * kUInt32Size; |
1146 if (NULL != src) { | 1149 if (NULL != src) { |
1147 size += sizeof(*src); // + rect | 1150 size += sizeof(*src); // + rect |
1148 } | 1151 } |
1149 size += sizeof(dst); // + rect | 1152 size += sizeof(dst); // + rect |
1150 | 1153 |
1151 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); | 1154 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); |
1152 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) | 1155 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) |
1153 == fWriter.bytesWritten()); | 1156 == fWriter.bytesWritten()); |
1154 this->addPaintPtr(paint); | 1157 this->addPaintPtr(paint); |
1155 this->addBitmap(bitmap); | 1158 int bitmapID = this->addBitmap(bitmap); |
1156 this->addRectPtr(src); // may be null | 1159 this->addRectPtr(src); // may be null |
1157 this->addRect(dst); | 1160 this->addRect(dst); |
1158 this->addInt(flags); | 1161 this->addInt(flags); |
1159 this->validate(initialOffset, size); | 1162 this->validate(initialOffset, size); |
| 1163 this->trackBitmapUse(bitmapID, initialOffset); |
1160 } | 1164 } |
1161 | 1165 |
1162 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, | 1166 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m
atrix, |
1163 const SkPaint* paint) { | 1167 const SkPaint* paint) { |
1164 if (bitmap.drawsNothing()) { | 1168 if (bitmap.drawsNothing()) { |
1165 return; | 1169 return; |
1166 } | 1170 } |
1167 | 1171 |
1168 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1172 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1169 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1173 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1170 #endif | 1174 #endif |
1171 | 1175 |
1172 // id + paint index + bitmap index + matrix | 1176 // id + paint index + bitmap index + matrix |
1173 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); | 1177 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); |
1174 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); | 1178 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); |
1175 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b
ytesWritten()); | 1179 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b
ytesWritten()); |
1176 this->addPaintPtr(paint); | 1180 this->addPaintPtr(paint); |
1177 this->addBitmap(bitmap); | 1181 int bitmapID = this->addBitmap(bitmap); |
1178 this->addMatrix(matrix); | 1182 this->addMatrix(matrix); |
1179 this->validate(initialOffset, size); | 1183 this->validate(initialOffset, size); |
| 1184 this->trackBitmapUse(bitmapID, initialOffset); |
1180 } | 1185 } |
1181 | 1186 |
1182 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, | 1187 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent
er, |
1183 const SkRect& dst, const SkPaint* paint) { | 1188 const SkRect& dst, const SkPaint* paint) { |
1184 if (bitmap.drawsNothing()) { | 1189 if (bitmap.drawsNothing()) { |
1185 return; | 1190 return; |
1186 } | 1191 } |
1187 | 1192 |
1188 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1193 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1189 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1194 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1190 #endif | 1195 #endif |
1191 | 1196 |
1192 // op + paint index + bitmap id + center + dst rect | 1197 // op + paint index + bitmap id + center + dst rect |
1193 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); | 1198 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); |
1194 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); | 1199 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); |
1195 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt
esWritten()); | 1200 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt
esWritten()); |
1196 this->addPaintPtr(paint); | 1201 this->addPaintPtr(paint); |
1197 this->addBitmap(bitmap); | 1202 int bitmapID = this->addBitmap(bitmap); |
1198 this->addIRect(center); | 1203 this->addIRect(center); |
1199 this->addRect(dst); | 1204 this->addRect(dst); |
1200 this->validate(initialOffset, size); | 1205 this->validate(initialOffset, size); |
| 1206 this->trackBitmapUse(bitmapID, initialOffset); |
1201 } | 1207 } |
1202 | 1208 |
1203 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, | 1209 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
1204 const SkPaint* paint = NULL) { | 1210 const SkPaint* paint = NULL) { |
1205 if (bitmap.drawsNothing()) { | 1211 if (bitmap.drawsNothing()) { |
1206 return; | 1212 return; |
1207 } | 1213 } |
1208 | 1214 |
1209 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 1215 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
1210 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); | 1216 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); |
1211 #endif | 1217 #endif |
1212 | 1218 |
1213 // op + paint index + bitmap index + left + top | 1219 // op + paint index + bitmap index + left + top |
1214 uint32_t size = 5 * kUInt32Size; | 1220 uint32_t size = 5 * kUInt32Size; |
1215 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); | 1221 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); |
1216 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri
tten()); | 1222 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri
tten()); |
1217 this->addPaintPtr(paint); | 1223 this->addPaintPtr(paint); |
1218 this->addBitmap(bitmap); | 1224 int bitmapID = this->addBitmap(bitmap); |
1219 this->addInt(left); | 1225 this->addInt(left); |
1220 this->addInt(top); | 1226 this->addInt(top); |
1221 this->validate(initialOffset, size); | 1227 this->validate(initialOffset, size); |
| 1228 this->trackBitmapUse(bitmapID, initialOffset); |
1222 } | 1229 } |
1223 | 1230 |
1224 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar
topbot[2]) { | 1231 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar
topbot[2]) { |
1225 SkPaint::FontMetrics metrics; | 1232 SkPaint::FontMetrics metrics; |
1226 paint.getFontMetrics(&metrics); | 1233 paint.getFontMetrics(&metrics); |
1227 SkRect bounds; | 1234 SkRect bounds; |
1228 // construct a rect so we can see any adjustments from the paint. | 1235 // construct a rect so we can see any adjustments from the paint. |
1229 // we use 0,1 for left,right, just so the rect isn't empty | 1236 // we use 0,1 for left,right, just so the rect isn't empty |
1230 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); | 1237 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); |
1231 (void)paint.computeFastBounds(bounds, &bounds); | 1238 (void)paint.computeFastBounds(bounds, &bounds); |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 | 1612 |
1606 this->validate(initialOffset, size); | 1613 this->validate(initialOffset, size); |
1607 } | 1614 } |
1608 | 1615 |
1609 /////////////////////////////////////////////////////////////////////////////// | 1616 /////////////////////////////////////////////////////////////////////////////// |
1610 | 1617 |
1611 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { | 1618 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { |
1612 return SkSurface::NewPicture(info.fWidth, info.fHeight); | 1619 return SkSurface::NewPicture(info.fWidth, info.fHeight); |
1613 } | 1620 } |
1614 | 1621 |
1615 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { | 1622 void SkPictureRecord::trackBitmapUse(int bitmapID, size_t offset) { |
| 1623 #ifndef SK_ALLOW_BITMAP_TRACKING |
| 1624 return; |
| 1625 #endif |
| 1626 |
| 1627 if (!(fRecordFlags & SkPicture::kOptimizeForClippedPlayback_RecordingFlag))
{ |
| 1628 return; |
| 1629 } |
| 1630 |
| 1631 if (SkBitmapHeap::INVALID_SLOT == bitmapID) { |
| 1632 return; |
| 1633 } |
| 1634 |
| 1635 if (NULL == fBitmapUseOffsets) { |
| 1636 fBitmapUseOffsets.reset(SkNEW(SkOffsetTable)); |
| 1637 } |
| 1638 |
| 1639 fBitmapUseOffsets->add(bitmapID, offset); |
| 1640 } |
| 1641 |
| 1642 int SkPictureRecord::addBitmap(const SkBitmap& bitmap) { |
1616 const int index = fBitmapHeap->insert(bitmap); | 1643 const int index = fBitmapHeap->insert(bitmap); |
1617 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In | 1644 // In debug builds, a bad return value from insert() will crash, allowing fo
r debugging. In |
1618 // release builds, the invalid value will be recorded so that the reader wil
l know that there | 1645 // release builds, the invalid value will be recorded so that the reader wil
l know that there |
1619 // was a problem. | 1646 // was a problem. |
1620 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); | 1647 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); |
1621 this->addInt(index); | 1648 this->addInt(index); |
| 1649 return index; |
1622 } | 1650 } |
1623 | 1651 |
1624 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { | 1652 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { |
1625 fWriter.writeMatrix(matrix); | 1653 fWriter.writeMatrix(matrix); |
1626 } | 1654 } |
1627 | 1655 |
1628 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { | 1656 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { |
1629 return fPaints.findAndReturnFlat(paint); | 1657 return fPaints.findAndReturnFlat(paint); |
1630 } | 1658 } |
1631 | 1659 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 void SkPictureRecord::validateRegions() const { | 1882 void SkPictureRecord::validateRegions() const { |
1855 int count = fRegions.count(); | 1883 int count = fRegions.count(); |
1856 SkASSERT((unsigned) count < 0x1000); | 1884 SkASSERT((unsigned) count < 0x1000); |
1857 for (int index = 0; index < count; index++) { | 1885 for (int index = 0; index < count; index++) { |
1858 const SkFlatData* region = fRegions[index]; | 1886 const SkFlatData* region = fRegions[index]; |
1859 SkASSERT(region); | 1887 SkASSERT(region); |
1860 // region->validate(); | 1888 // region->validate(); |
1861 } | 1889 } |
1862 } | 1890 } |
1863 #endif | 1891 #endif |
OLD | NEW |