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

Side by Side Diff: src/core/SkPictureRecord.cpp

Issue 187833003: First version of bitmap use tracking in SkPictureRecord (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: 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
« src/core/SkPictureRecord.h ('K') | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
37 , fRecordFlags(flags) 37 , fRecordFlags(flags)
38 , fOptsEnabled(true) { 38 , fOptsEnabled(true) {
39 #ifdef SK_DEBUG_SIZE 39 #ifdef SK_DEBUG_SIZE
40 fPointBytes = fRectBytes = fTextBytes = 0; 40 fPointBytes = fRectBytes = fTextBytes = 0;
41 fPointWrites = fRectWrites = fTextWrites = 0; 41 fPointWrites = fRectWrites = fTextWrites = 0;
42 #endif 42 #endif
43 43
44 fBitmapHeap = SkNEW(SkBitmapHeap); 44 fBitmapHeap = SkNEW(SkBitmapHeap);
45 fFlattenableHeap.setBitmapStorage(fBitmapHeap); 45 fFlattenableHeap.setBitmapStorage(fBitmapHeap);
46 fPathHeap = NULL; // lazy allocate 46 fPathHeap = NULL; // lazy allocate
47 fBitmapUseOffsets = 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 }
57 59
58 SkPictureRecord::~SkPictureRecord() { 60 SkPictureRecord::~SkPictureRecord() {
59 SkSafeUnref(fBitmapHeap); 61 SkSafeUnref(fBitmapHeap);
60 SkSafeUnref(fPathHeap); 62 SkSafeUnref(fPathHeap);
63 SkSafeUnref(fBitmapUseOffsets);
61 SkSafeUnref(fBoundingHierarchy); 64 SkSafeUnref(fBoundingHierarchy);
62 SkSafeUnref(fStateTree); 65 SkSafeUnref(fStateTree);
63 fFlattenableHeap.setBitmapStorage(NULL); 66 fFlattenableHeap.setBitmapStorage(NULL);
64 fPictureRefs.unrefAll(); 67 fPictureRefs.unrefAll();
65 } 68 }
66 69
67 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
68 71
69 // Return the offset of the paint inside a given op's byte stream. A zero 72 // Return the offset of the paint inside a given op's byte stream. A zero
70 // return value means there is no paint (and you really shouldn't be calling 73 // return value means there is no paint (and you really shouldn't be calling
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1121
1119 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1122 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1120 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1123 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1121 #endif 1124 #endif
1122 1125
1123 // op + paint index + bitmap index + left + top 1126 // op + paint index + bitmap index + left + top
1124 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar); 1127 uint32_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
1125 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size); 1128 size_t initialOffset = this->addDraw(DRAW_BITMAP, &size);
1126 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten()); 1129 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP, size) == fWriter.bytesWri tten());
1127 this->addPaintPtr(paint); 1130 this->addPaintPtr(paint);
1128 this->addBitmap(bitmap); 1131 int bitmapID = this->addBitmap(bitmap);
1129 this->addScalar(left); 1132 this->addScalar(left);
1130 this->addScalar(top); 1133 this->addScalar(top);
1131 this->validate(initialOffset, size); 1134 this->validate(initialOffset, size);
1135 this->trackBitmapUse(bitmapID, initialOffset);
1132 } 1136 }
1133 1137
1134 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 1138 void SkPictureRecord::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
1135 const SkRect& dst, const SkPaint* pai nt, 1139 const SkRect& dst, const SkPaint* pai nt,
1136 DrawBitmapRectFlags flags) { 1140 DrawBitmapRectFlags flags) {
1137 if (bitmap.drawsNothing()) { 1141 if (bitmap.drawsNothing()) {
1138 return; 1142 return;
1139 } 1143 }
1140 1144
1141 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1145 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1142 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1146 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1143 #endif 1147 #endif
1144 // id + paint index + bitmap index + bool for 'src' + flags 1148 // id + paint index + bitmap index + bool for 'src' + flags
1145 uint32_t size = 5 * kUInt32Size; 1149 uint32_t size = 5 * kUInt32Size;
1146 if (NULL != src) { 1150 if (NULL != src) {
1147 size += sizeof(*src); // + rect 1151 size += sizeof(*src); // + rect
1148 } 1152 }
1149 size += sizeof(dst); // + rect 1153 size += sizeof(dst); // + rect
1150 1154
1151 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size); 1155 size_t initialOffset = this->addDraw(DRAW_BITMAP_RECT_TO_RECT, &size);
1152 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size) 1156 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_RECT_TO_RECT, size)
1153 == fWriter.bytesWritten()); 1157 == fWriter.bytesWritten());
1154 this->addPaintPtr(paint); 1158 this->addPaintPtr(paint);
1155 this->addBitmap(bitmap); 1159 int bitmapID = this->addBitmap(bitmap);
1156 this->addRectPtr(src); // may be null 1160 this->addRectPtr(src); // may be null
1157 this->addRect(dst); 1161 this->addRect(dst);
1158 this->addInt(flags); 1162 this->addInt(flags);
1159 this->validate(initialOffset, size); 1163 this->validate(initialOffset, size);
1164 this->trackBitmapUse(bitmapID, initialOffset);
1160 } 1165 }
1161 1166
1162 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix, 1167 void SkPictureRecord::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m atrix,
1163 const SkPaint* paint) { 1168 const SkPaint* paint) {
1164 if (bitmap.drawsNothing()) { 1169 if (bitmap.drawsNothing()) {
1165 return; 1170 return;
1166 } 1171 }
1167 1172
1168 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1173 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1169 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1174 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1170 #endif 1175 #endif
1171 1176
1172 // id + paint index + bitmap index + matrix 1177 // id + paint index + bitmap index + matrix
1173 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL); 1178 uint32_t size = 3 * kUInt32Size + matrix.writeToMemory(NULL);
1174 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size); 1179 size_t initialOffset = this->addDraw(DRAW_BITMAP_MATRIX, &size);
1175 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten()); 1180 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_MATRIX, size) == fWriter.b ytesWritten());
1176 this->addPaintPtr(paint); 1181 this->addPaintPtr(paint);
1177 this->addBitmap(bitmap); 1182 int bitmapID = this->addBitmap(bitmap);
1178 this->addMatrix(matrix); 1183 this->addMatrix(matrix);
1179 this->validate(initialOffset, size); 1184 this->validate(initialOffset, size);
1185 this->trackBitmapUse(bitmapID, initialOffset);
1180 } 1186 }
1181 1187
1182 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er, 1188 void SkPictureRecord::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& cent er,
1183 const SkRect& dst, const SkPaint* paint) { 1189 const SkRect& dst, const SkPaint* paint) {
1184 if (bitmap.drawsNothing()) { 1190 if (bitmap.drawsNothing()) {
1185 return; 1191 return;
1186 } 1192 }
1187 1193
1188 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1194 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1189 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1195 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1190 #endif 1196 #endif
1191 1197
1192 // op + paint index + bitmap id + center + dst rect 1198 // op + paint index + bitmap id + center + dst rect
1193 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst); 1199 uint32_t size = 3 * kUInt32Size + sizeof(center) + sizeof(dst);
1194 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size); 1200 size_t initialOffset = this->addDraw(DRAW_BITMAP_NINE, &size);
1195 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten()); 1201 SkASSERT(initialOffset+getPaintOffset(DRAW_BITMAP_NINE, size) == fWriter.byt esWritten());
1196 this->addPaintPtr(paint); 1202 this->addPaintPtr(paint);
1197 this->addBitmap(bitmap); 1203 int bitmapID = this->addBitmap(bitmap);
1198 this->addIRect(center); 1204 this->addIRect(center);
1199 this->addRect(dst); 1205 this->addRect(dst);
1200 this->validate(initialOffset, size); 1206 this->validate(initialOffset, size);
1207 this->trackBitmapUse(bitmapID, initialOffset);
1201 } 1208 }
1202 1209
1203 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top, 1210 void SkPictureRecord::drawSprite(const SkBitmap& bitmap, int left, int top,
1204 const SkPaint* paint = NULL) { 1211 const SkPaint* paint = NULL) {
1205 if (bitmap.drawsNothing()) { 1212 if (bitmap.drawsNothing()) {
1206 return; 1213 return;
1207 } 1214 }
1208 1215
1209 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE 1216 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE
1210 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType); 1217 fMCMgr.call(SkMatrixClipStateMgr::kOther_CallType);
1211 #endif 1218 #endif
1212 1219
1213 // op + paint index + bitmap index + left + top 1220 // op + paint index + bitmap index + left + top
1214 uint32_t size = 5 * kUInt32Size; 1221 uint32_t size = 5 * kUInt32Size;
1215 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size); 1222 size_t initialOffset = this->addDraw(DRAW_SPRITE, &size);
1216 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten()); 1223 SkASSERT(initialOffset+getPaintOffset(DRAW_SPRITE, size) == fWriter.bytesWri tten());
1217 this->addPaintPtr(paint); 1224 this->addPaintPtr(paint);
1218 this->addBitmap(bitmap); 1225 int bitmapID = this->addBitmap(bitmap);
1219 this->addInt(left); 1226 this->addInt(left);
1220 this->addInt(top); 1227 this->addInt(top);
1221 this->validate(initialOffset, size); 1228 this->validate(initialOffset, size);
1229 this->trackBitmapUse(bitmapID, initialOffset);
1222 } 1230 }
1223 1231
1224 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) { 1232 void SkPictureRecord::ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]) {
1225 SkPaint::FontMetrics metrics; 1233 SkPaint::FontMetrics metrics;
1226 paint.getFontMetrics(&metrics); 1234 paint.getFontMetrics(&metrics);
1227 SkRect bounds; 1235 SkRect bounds;
1228 // construct a rect so we can see any adjustments from the paint. 1236 // 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 1237 // we use 0,1 for left,right, just so the rect isn't empty
1230 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom); 1238 bounds.set(0, metrics.fTop, SK_Scalar1, metrics.fBottom);
1231 (void)paint.computeFastBounds(bounds, &bounds); 1239 (void)paint.computeFastBounds(bounds, &bounds);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 1613
1606 this->validate(initialOffset, size); 1614 this->validate(initialOffset, size);
1607 } 1615 }
1608 1616
1609 /////////////////////////////////////////////////////////////////////////////// 1617 ///////////////////////////////////////////////////////////////////////////////
1610 1618
1611 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) { 1619 SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) {
1612 return SkSurface::NewPicture(info.fWidth, info.fHeight); 1620 return SkSurface::NewPicture(info.fWidth, info.fHeight);
1613 } 1621 }
1614 1622
1615 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) { 1623 void SkPictureRecord::trackBitmapUse(int bitmapID, size_t offset) {
1624 #ifndef SK_ALLOW_BITMAP_TRACKING
1625 return;
1626 #endif
1627
1628 if (!(fRecordFlags & SkPicture::kOptimizeForClippedPlayback_RecordingFlag)) {
1629 return;
1630 }
1631
1632 if (SkBitmapHeap::INVALID_SLOT == bitmapID) {
mtklein 2014/03/06 16:20:38 Is this something we can also SkASSERT doesn't hap
robertphillips 2014/03/06 20:18:26 addBitmap can return this value so we need this ch
1633 return;
1634 }
1635
1636 if (NULL == fBitmapUseOffsets) {
1637 fBitmapUseOffsets = SkNEW(SkOffsetTable);
1638 }
1639
1640 fBitmapUseOffsets->add(bitmapID, offset);
1641 }
1642
1643 int SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
1616 const int index = fBitmapHeap->insert(bitmap); 1644 const int index = fBitmapHeap->insert(bitmap);
1617 // In debug builds, a bad return value from insert() will crash, allowing fo r debugging. In 1645 // 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 1646 // release builds, the invalid value will be recorded so that the reader wil l know that there
1619 // was a problem. 1647 // was a problem.
1620 SkASSERT(index != SkBitmapHeap::INVALID_SLOT); 1648 SkASSERT(index != SkBitmapHeap::INVALID_SLOT);
1621 this->addInt(index); 1649 this->addInt(index);
1650 return index;
1622 } 1651 }
1623 1652
1624 void SkPictureRecord::addMatrix(const SkMatrix& matrix) { 1653 void SkPictureRecord::addMatrix(const SkMatrix& matrix) {
1625 fWriter.writeMatrix(matrix); 1654 fWriter.writeMatrix(matrix);
1626 } 1655 }
1627 1656
1628 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) { 1657 const SkFlatData* SkPictureRecord::getFlatPaintData(const SkPaint& paint) {
1629 return fPaints.findAndReturnFlat(paint); 1658 return fPaints.findAndReturnFlat(paint);
1630 } 1659 }
1631 1660
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 void SkPictureRecord::validateRegions() const { 1883 void SkPictureRecord::validateRegions() const {
1855 int count = fRegions.count(); 1884 int count = fRegions.count();
1856 SkASSERT((unsigned) count < 0x1000); 1885 SkASSERT((unsigned) count < 0x1000);
1857 for (int index = 0; index < count; index++) { 1886 for (int index = 0; index < count; index++) {
1858 const SkFlatData* region = fRegions[index]; 1887 const SkFlatData* region = fRegions[index];
1859 SkASSERT(region); 1888 SkASSERT(region);
1860 // region->validate(); 1889 // region->validate();
1861 } 1890 }
1862 } 1891 }
1863 #endif 1892 #endif
OLDNEW
« src/core/SkPictureRecord.h ('K') | « src/core/SkPictureRecord.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698