SkTextBlob plumbing
Add SkTextBlob serialization + drawTextBlob() overrides.
R=mtklein@google.com, reed@google.com, robertphillips@google.com
BUG=269080
Author: fmalita@chromium.org
Review URL: https://codereview.chromium.org/499413002
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index dd80400..67bd9a5 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
@@ -59,6 +60,7 @@
SkSafeUnref(fStateTree);
fFlattenableHeap.setBitmapStorage(NULL);
fPictureRefs.unrefAll();
+ fTextBlobRefs.unrefAll();
}
///////////////////////////////////////////////////////////////////////////////
@@ -114,6 +116,7 @@
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,
@@ -462,7 +465,8 @@
return (op > CONCAT && op < ROTATE)
|| DRAW_DRRECT == op
|| DRAW_PATCH == op
- || DRAW_PICTURE_MATRIX_PAINT == op;
+ || DRAW_PICTURE_MATRIX_PAINT == op
+ || DRAW_TEXT_BLOB == op;
}
/*
@@ -1207,6 +1211,22 @@
this->validate(initialOffset, size);
}
+void SkPictureRecord::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+
+ // op + paint index + blob index + x/y
+ size_t size = 3 * kUInt32Size + 2 * sizeof(SkScalar);
+ size_t initialOffset = this->addDraw(DRAW_TEXT_BLOB, &size);
+ SkASSERT(initialOffset + getPaintOffset(DRAW_TEXT_BLOB, size) == fWriter.bytesWritten());
+
+ this->addPaint(paint);
+ this->addTextBlob(blob);
+ this->addScalar(x);
+ this->addScalar(y);
+
+ this->validate(initialOffset, size);
+}
+
void SkPictureRecord::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
const SkPaint* paint) {
// op + picture index
@@ -1523,5 +1543,16 @@
fWriter.writePad(text, byteLength);
}
+void SkPictureRecord::addTextBlob(const SkTextBlob *blob) {
+ int index = fTextBlobRefs.find(blob);
+ if (index < 0) { // not found
+ index = fTextBlobRefs.count();
+ *fTextBlobRefs.append() = blob;
+ blob->ref();
+ }
+ // follow the convention of recording a 1-based index
+ this->addInt(index + 1);
+}
+
///////////////////////////////////////////////////////////////////////////////