Index: src/core/SkPictureRecord.cpp |
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp |
index b79b185b2d04a04d9d37a49e479e0591eb8abe7e..dec09db5575938070c4f5b448ec688e6c57ea129 100644 |
--- a/src/core/SkPictureRecord.cpp |
+++ b/src/core/SkPictureRecord.cpp |
@@ -12,6 +12,7 @@ |
#include "SkPictureStateTree.h" |
#include "SkPixelRef.h" |
#include "SkRRect.h" |
+#include "SkTextBlob.h" |
#include "SkTSearch.h" |
#define HEAP_BLOCK_SIZE 4096 |
@@ -114,6 +115,7 @@ static inline size_t getPaintOffset(DrawType op, size_t opSize) { |
0, // POP_CULL - no paint |
1, // DRAW_PATCH - right after op code |
1, // DRAW_PICTURE_MATRIX_PAINT - right after op code |
+ 1, // DRAW_TEXT_BLOB - right after op code |
}; |
SK_COMPILE_ASSERT(sizeof(gPaintOffsets) == LAST_DRAWTYPE_ENUM + 1, |
@@ -1202,6 +1204,54 @@ void SkPictureRecord::onDrawTextOnPath(const void* text, size_t byteLength, cons |
this->validate(initialOffset, size); |
} |
+ |
+void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, const SkPoint& offset, |
+ const SkPaint& paint) { |
+ // op + paint index + chunk count + offset |
+ size_t size = 3 * kUInt32Size + sizeof(SkPoint); |
+ unsigned chunk_count = 0; |
+ |
+ { |
+ // Yikes -- we need to scan the chunks upfront to compute the size :( |
+ // Hopefully this is going to be irrelevant soon thanks to SkRecord. |
+ SkTextBlob::Iter iter(blob); |
+ while (const SkTextChunk* chunk = iter.next()) { |
+ chunk_count++; |
+ |
+ // glyph count + chunk paint + flags + bounds bool |
+ size += 4 * kUInt32Size; |
+ if (!chunk->fBoundsDirty) { |
+ size += sizeof(chunk->fBounds); |
+ } |
+ // glyphs |
+ size += SkAlign4(chunk->fGlyphCount * sizeof(uint16_t)); |
+ // positions |
+ size += SkAlign4(chunk->fGlyphCount * sizeof(SkScalar) * chunk->fScalarsPerPos); |
+ } |
+ } |
+ |
+ size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size); |
+ SkASSERT(initialOffset+getPaintOffset(DRAW_TEXT_ON_PATH, size) == fWriter.bytesWritten()); |
+ this->addPaint(paint); |
+ this->addInt(chunk_count); |
+ this->addPoint(offset); |
+ |
+ SkTextBlob::Iter iter(blob); |
+ while (const SkTextChunk* chunk = iter.next()) { |
+ this->addInt(SkToInt(chunk->fGlyphCount)); |
+ this->addPaint(chunk->fFont); |
+ this->addInt(chunk->fScalarsPerPos); |
+ this->addRectPtr(chunk->fBoundsDirty ? NULL : &chunk->fBounds); |
+ fWriter.writePad(chunk->fGlyphs, chunk->fGlyphCount * sizeof(uint16_t)); |
+ if (chunk->fScalarsPerPos > 0) { |
+ SkASSERT(NULL != chunk->fPos); |
+ fWriter.writePad(chunk->fPos, chunk->fGlyphCount * sizeof(SkScalar) * chunk->fScalarsPerPos); |
+ } |
+ } |
+ |
+ this->validate(initialOffset, size); |
+} |
+ |
void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
const SkPaint* paint) { |
// op + picture index |