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

Unified Diff: src/pipe/SkGPipeWrite.cpp

Issue 563783003: Ensure blob typeface information survives SkGPipe serialization. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cross-process fix + gm typeface coverage Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« src/pipe/SkGPipeRead.cpp ('K') | « src/pipe/SkGPipeRead.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pipe/SkGPipeWrite.cpp
diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp
index f361e5ed67ecf092b4fd3a10f41f793e4f5cac69..48a79c9b204c597cc97f5ce96ecb7abe45f4ee7e 100644
--- a/src/pipe/SkGPipeWrite.cpp
+++ b/src/pipe/SkGPipeWrite.cpp
@@ -22,6 +22,7 @@
#include "SkPatchUtils.h"
#include "SkPathEffect.h"
#include "SkPictureFlat.h"
+#include "SkPtrRecorder.h"
#include "SkRasterizer.h"
#include "SkRRect.h"
#include "SkShader.h"
@@ -944,17 +945,53 @@ void SkGPipeCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar
this->writePaint(paint);
// FIXME: this is inefficient but avoids duplicating the blob serialization logic.
+ SkRefCntSet typefaceSet;
SkWriteBuffer blobBuffer;
+ blobBuffer.setTypefaceRecorder(&typefaceSet);
blob->flatten(blobBuffer);
- size_t size = sizeof(uint32_t) + 2 * sizeof(SkScalar) + blobBuffer.bytesWritten();
+ // Unlike most draw ops (which only use one paint/typeface), text blobs may reference
+ // an arbitrary number of typefaces. Since the one-paint-per-op model is not applicable,
+ // we need to serialize these explicitly.
+ int typefaceCount = typefaceSet.count();
+ size_t typefaceSize = isCrossProcess(fFlags) ? sizeof(uint32_t) : sizeof(void*);
+ SkAutoSTMalloc<16, SkTypeface*> storage(typefaceCount);
+ SkTypeface** array = storage.get();
+ typefaceSet.copyToArray((SkRefCnt**)array);
+
+ // We need to convert to IDs before we start writing the blob as the lookup may write out
+ // kDef_Typeface_DrawOp blocks for new typefaces.
+ if (isCrossProcess(fFlags)) {
+ uint32_t* typefaceIDs = reinterpret_cast<uint32_t*>(array);
+ for (int i = 0; i < typefaceCount; ++i) {
+ // This overlaps/overrides 'array', but should be safe given
+ // that sizeof(uint32_t) <= sizeof(SkTypeface*)
+ typefaceIDs[i] = this->getTypefaceID(array[i]);
mtklein 2014/09/12 23:09:29 I can't help but think that if onDrawTextBlob() lo
reed1 2014/09/15 14:13:39 Hmm, seems like most of this function is common w/
f(malita) 2014/09/15 21:51:19 Added a couple of helpers to munge the typeface bu
+ }
+ }
+
+ // blob byte count + typeface count + x + y + blob data + an index (cross-process)
+ // or pointer (in-process) for each typeface
+ size_t size = 2 * sizeof(uint32_t)
+ + 2 * sizeof(SkScalar)
+ + blobBuffer.bytesWritten()
+ + typefaceCount * typefaceSize;
+
if (this->needOpBytes(size)) {
this->writeOp(kDrawTextBlob_DrawOp);
+ size_t initialOffset = fWriter.bytesWritten();
+
fWriter.writeScalar(x);
fWriter.writeScalar(y);
+
+ fWriter.write32(typefaceCount);
+ fWriter.write(array, typefaceCount * typefaceSize);
+
fWriter.write32(SkToU32(blobBuffer.bytesWritten()));
uint32_t* pad = fWriter.reservePad(blobBuffer.bytesWritten());
blobBuffer.writeToMemory(pad);
+
+ SkASSERT(initialOffset + size == fWriter.bytesWritten());
}
}
« src/pipe/SkGPipeRead.cpp ('K') | « src/pipe/SkGPipeRead.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698