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 "SkBBoxHierarchy.h" | 9 #include "SkBBoxHierarchy.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
11 #include "SkPatchUtils.h" | 11 #include "SkPatchUtils.h" |
12 #include "SkPictureStateTree.h" | 12 #include "SkPictureStateTree.h" |
13 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "SkTextBlob.h" |
15 #include "SkTSearch.h" | 16 #include "SkTSearch.h" |
16 | 17 |
17 #define HEAP_BLOCK_SIZE 4096 | 18 #define HEAP_BLOCK_SIZE 4096 |
18 | 19 |
19 // If SK_RECORD_LITERAL_PICTURES is defined, record our inputs as literally as p
ossible. | 20 // If SK_RECORD_LITERAL_PICTURES is defined, record our inputs as literally as p
ossible. |
20 // Otherwise, we can be clever and record faster equivalents. kBeClever is norm
ally true. | 21 // Otherwise, we can be clever and record faster equivalents. kBeClever is norm
ally true. |
21 static const bool kBeClever = | 22 static const bool kBeClever = |
22 #ifdef SK_RECORD_LITERAL_PICTURES | 23 #ifdef SK_RECORD_LITERAL_PICTURES |
23 false; | 24 false; |
24 #else | 25 #else |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 0, // TRANSLATE - no paint | 108 0, // TRANSLATE - no paint |
108 0, // NOOP - no paint | 109 0, // NOOP - no paint |
109 0, // BEGIN_GROUP - no paint | 110 0, // BEGIN_GROUP - no paint |
110 0, // COMMENT - no paint | 111 0, // COMMENT - no paint |
111 0, // END_GROUP - no paint | 112 0, // END_GROUP - no paint |
112 1, // DRAWDRRECT - right after op code | 113 1, // DRAWDRRECT - right after op code |
113 0, // PUSH_CULL - no paint | 114 0, // PUSH_CULL - no paint |
114 0, // POP_CULL - no paint | 115 0, // POP_CULL - no paint |
115 1, // DRAW_PATCH - right after op code | 116 1, // DRAW_PATCH - right after op code |
116 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code | 117 1, // DRAW_PICTURE_MATRIX_PAINT - right after op code |
| 118 1, // DRAW_TEXT_BLOB - right after op code |
117 }; | 119 }; |
118 | 120 |
119 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, | 121 SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, |
120 need_to_be_in_sync); | 122 need_to_be_in_sync); |
121 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); | 123 SkASSERT((unsigned)op <= (unsigned)LAST_DRAWTYPE_ENUM); |
122 | 124 |
123 int overflow = 0; | 125 int overflow = 0; |
124 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { | 126 if (0 != (opSize & ~MASK_24) || opSize == MASK_24) { |
125 // This op's size overflows so an extra uint32_t will be written | 127 // This op's size overflows so an extra uint32_t will be written |
126 // after the op code | 128 // after the op code |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write
ToMemory(NULL); | 1197 size_t size = 3 * kUInt32Size + SkAlign4(byteLength) + kUInt32Size + m.write
ToMemory(NULL); |
1196 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); | 1198 size_t initialOffset = this->addDraw(DRAW_TEXT_ON_PATH, &size); |
1197 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); | 1199 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); |
1198 this->addPaint(paint); | 1200 this->addPaint(paint); |
1199 this->addText(text, byteLength); | 1201 this->addText(text, byteLength); |
1200 this->addPath(path); | 1202 this->addPath(path); |
1201 this->addMatrix(m); | 1203 this->addMatrix(m); |
1202 this->validate(initialOffset, size); | 1204 this->validate(initialOffset, size); |
1203 } | 1205 } |
1204 | 1206 |
| 1207 |
| 1208 void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, const SkPoint& offs
et, |
| 1209 const SkPaint& paint) { |
| 1210 // op + paint index + chunk count + offset |
| 1211 size_t size = 3 * kUInt32Size + sizeof(SkPoint); |
| 1212 unsigned chunk_count = 0; |
| 1213 |
| 1214 { |
| 1215 // Yikes -- we need to scan the chunks upfront to compute the size :( |
| 1216 // Hopefully this is going to be irrelevant soon thanks to SkRecord. |
| 1217 SkTextBlob::Iter iter(blob); |
| 1218 while (const SkTextChunk* chunk = iter.next()) { |
| 1219 chunk_count++; |
| 1220 |
| 1221 // glyph count + chunk paint + flags + bounds bool |
| 1222 size += 4 * kUInt32Size; |
| 1223 if (!chunk->fBoundsDirty) { |
| 1224 size += sizeof(chunk->fBounds); |
| 1225 } |
| 1226 // glyphs |
| 1227 size += SkAlign4(chunk->fGlyphCount * sizeof(uint16_t)); |
| 1228 // positions |
| 1229 size += SkAlign4(chunk->fGlyphCount * sizeof(SkScalar) * chunk->fSca
larsPerPos); |
| 1230 } |
| 1231 } |
| 1232 |
| 1233 size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); |
| 1234 SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.by
tesWritten()); |
| 1235 this->addPaint(paint); |
| 1236 this->addInt(chunk_count); |
| 1237 this->addPoint(offset); |
| 1238 |
| 1239 SkTextBlob::Iter iter(blob); |
| 1240 while (const SkTextChunk* chunk = iter.next()) { |
| 1241 this->addInt(SkToInt(chunk->fGlyphCount)); |
| 1242 this->addPaint(chunk->fFont); |
| 1243 this->addInt(chunk->fScalarsPerPos); |
| 1244 this->addRectPtr(chunk->fBoundsDirty ? NULL : &chunk->fBounds); |
| 1245 fWriter.writePad(chunk->fGlyphs, chunk->fGlyphCount * sizeof(uint16_t)); |
| 1246 if (chunk->fScalarsPerPos > 0) { |
| 1247 SkASSERT(NULL != chunk->fPos); |
| 1248 fWriter.writePad(chunk->fPos, chunk->fGlyphCount * sizeof(SkScalar)
* chunk->fScalarsPerPos); |
| 1249 } |
| 1250 } |
| 1251 |
| 1252 this->validate(initialOffset, size); |
| 1253 } |
| 1254 |
1205 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma
trix, | 1255 void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* ma
trix, |
1206 const SkPaint* paint) { | 1256 const SkPaint* paint) { |
1207 // op + picture index | 1257 // op + picture index |
1208 size_t size = 2 * kUInt32Size; | 1258 size_t size = 2 * kUInt32Size; |
1209 size_t initialOffset; | 1259 size_t initialOffset; |
1210 | 1260 |
1211 if (NULL == matrix && NULL == paint) { | 1261 if (NULL == matrix && NULL == paint) { |
1212 initialOffset = this->addDraw(DRAW_PICTURE, &size); | 1262 initialOffset = this->addDraw(DRAW_PICTURE, &size); |
1213 this->addPicture(picture); | 1263 this->addPicture(picture); |
1214 } else { | 1264 } else { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1513 } | 1563 } |
1514 | 1564 |
1515 void SkPictureRecord::addText(const void* text, size_t byteLength) { | 1565 void SkPictureRecord::addText(const void* text, size_t byteLength) { |
1516 fContentInfo.onDrawText(); | 1566 fContentInfo.onDrawText(); |
1517 addInt(SkToInt(byteLength)); | 1567 addInt(SkToInt(byteLength)); |
1518 fWriter.writePad(text, byteLength); | 1568 fWriter.writePad(text, byteLength); |
1519 } | 1569 } |
1520 | 1570 |
1521 /////////////////////////////////////////////////////////////////////////////// | 1571 /////////////////////////////////////////////////////////////////////////////// |
1522 | 1572 |
OLD | NEW |