diff options
author | 2017-12-07 21:30:19 +0000 | |
---|---|---|
committer | 2017-12-07 21:30:31 +0000 | |
commit | 1a104bce20adc47a343fa910899ca6c4f261be40 (patch) | |
tree | dd210345afbae56f87d564284dfe8ce93680ed7b /src | |
parent | 990014d082e82e34ae53de05fabc012af3a24778 (diff) |
Revert "use serialprocs for typefaces"
This reverts commit b681972e79993e37adb9de9666cc9064b528db8b.
Reason for revert: need to handle null typeface in new procs
Original change's description:
> use serialprocs for typefaces
>
> Bug: skia:
> Change-Id: Ibf59a0fdcf68e8555bd4241e9473e733f6a30993
> Reviewed-on: https://skia-review.googlesource.com/81840
> Reviewed-by: Florin Malita <fmalita@chromium.org>
> Reviewed-by: Mike Klein <mtklein@chromium.org>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=mtklein@chromium.org,mtklein@google.com,fmalita@chromium.org,reed@google.com
Change-Id: Id69500fbc291ecee753e7ee6b80abc2a7cd60d18
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/82341
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkReadBuffer.cpp | 22 | ||||
-rw-r--r-- | src/core/SkReadBuffer.h | 2 | ||||
-rw-r--r-- | src/core/SkTextBlob.cpp | 89 | ||||
-rw-r--r-- | src/core/SkWriteBuffer.cpp | 26 |
4 files changed, 43 insertions, 96 deletions
diff --git a/src/core/SkReadBuffer.cpp b/src/core/SkReadBuffer.cpp index 9fcee54c9f..78071ee227 100644 --- a/src/core/SkReadBuffer.cpp +++ b/src/core/SkReadBuffer.cpp @@ -374,26 +374,12 @@ sk_sp<SkTypeface> SkReadBuffer::readTypeface() { return sk_ref_sp(fInflator->getTypeface(this->read32())); } - // Read 32 bits (signed) - // 0 -- failure - // >0 -- index - // <0 -- custom (serial procs) : negative size in bytes - - int32_t index = this->readUInt(); - if (index == 0) { + uint32_t index = this->readUInt(); + if (0 == index || index > (unsigned)fTFCount) { return nullptr; - } else if (index > 0) { - if (index > fTFCount) { - return nullptr; - } + } else { + SkASSERT(fTFArray); return sk_ref_sp(fTFArray[index - 1]); - } else { // custom - size_t size = -index; - const void* data = this->skip(size); - if (!data) { - return nullptr; - } - return fProcs.fTypefaceProc(data, size, fProcs.fTypefaceCtx); } } diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index b1c67fe95b..78038aa7af 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -185,7 +185,7 @@ public: // be created (e.g. it was not originally encoded) then this returns an image that doesn't // draw. sk_sp<SkImage> readImage(); - sk_sp<SkTypeface> readTypeface(); + virtual sk_sp<SkTypeface> readTypeface(); void setTypefaceArray(SkTypeface* array[], int count) { fTFArray = array; diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index fb076b9cd2..193c82de66 100644 --- a/src/core/SkTextBlob.cpp +++ b/src/core/SkTextBlob.cpp @@ -868,9 +868,25 @@ sk_sp<SkTextBlob> SkTextBlob::MakeFromBuffer(SkReadBuffer& reader) { return blobBuilder.make(); } -sk_sp<SkData> SkTextBlob::serialize(const SkSerialProcs& procs) const { - SkBinaryWriteBuffer buffer; - buffer.setSerialProcs(procs); +class SkTypefaceCatalogerWriteBuffer : public SkBinaryWriteBuffer { +public: + SkTypefaceCatalogerWriteBuffer(SkTypefaceCatalogerProc proc, void* ctx) + : SkBinaryWriteBuffer(SkBinaryWriteBuffer::kCrossProcess_Flag) + , fCatalogerProc(proc) + , fCatalogerCtx(ctx) + {} + + void writeTypeface(SkTypeface* typeface) override { + fCatalogerProc(typeface, fCatalogerCtx); + this->write32(typeface ? typeface->uniqueID() : 0); + } + + SkTypefaceCatalogerProc fCatalogerProc; + void* fCatalogerCtx; +}; + +sk_sp<SkData> SkTextBlob::serialize(SkTypefaceCatalogerProc proc, void* ctx) const { + SkTypefaceCatalogerWriteBuffer buffer(proc, ctx); this->flatten(buffer); size_t total = buffer.bytesWritten(); @@ -879,61 +895,26 @@ sk_sp<SkData> SkTextBlob::serialize(const SkSerialProcs& procs) const { return data; } -sk_sp<SkTextBlob> SkTextBlob::Deserialize(const void* data, size_t length, - const SkDeserialProcs& procs) { - SkReadBuffer buffer(data, length); - buffer.setDeserialProcs(procs); - return SkTextBlob::MakeFromBuffer(buffer); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - -namespace { - struct CatalogState { - SkTypefaceCatalogerProc fProc; - void* fCtx; - }; +class SkTypefaceResolverReadBuffer : public SkReadBuffer { +public: + SkTypefaceResolverReadBuffer(const void* data, size_t size, SkTypefaceResolverProc proc, + void* ctx) + : SkReadBuffer(data, size) + , fResolverProc(proc) + , fResolverCtx(ctx) + {} - bool catalog_typeface_proc(SkTypeface* face, SkWStream* stream, void* ctx) { - CatalogState* state = static_cast<CatalogState*>(ctx); - state->fProc(face, state->fCtx); - stream->write32(face->uniqueID()); - return true; + sk_sp<SkTypeface> readTypeface() override { + auto id = this->readUInt(); + return this->isValid() ? fResolverProc(id, fResolverCtx) : nullptr; } -} - -sk_sp<SkData> SkTextBlob::serialize(SkTypefaceCatalogerProc proc, void* ctx) const { - CatalogState state = { proc, ctx }; - SkSerialProcs procs; - procs.fTypefaceProc = catalog_typeface_proc; - procs.fTypefaceCtx = &state; - return this->serialize(procs); -} - -namespace { - struct ResolverState { - SkTypefaceResolverProc fProc; - void* fCtx; - }; - sk_sp<SkTypeface> resolver_typeface_proc(const void* data, size_t length, void* ctx) { - SkASSERT(length == 4); - if (length != 4) { - return nullptr; - } - - ResolverState* state = static_cast<ResolverState*>(ctx); - uint32_t id; - memcpy(&id, data, length); - return state->fProc(id, state->fCtx); - } -} + SkTypefaceResolverProc fResolverProc; + void* fResolverCtx; +}; sk_sp<SkTextBlob> SkTextBlob::Deserialize(const void* data, size_t length, SkTypefaceResolverProc proc, void* ctx) { - ResolverState state = { proc, ctx }; - SkDeserialProcs procs; - procs.fTypefaceProc = resolver_typeface_proc; - procs.fTypefaceCtx = &state; - return Deserialize(data, length, procs); + SkTypefaceResolverReadBuffer buffer(data, length, proc, ctx); + return SkTextBlob::MakeFromBuffer(buffer); } diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp index 5da0aa4d93..49cccd6783 100644 --- a/src/core/SkWriteBuffer.cpp +++ b/src/core/SkWriteBuffer.cpp @@ -175,31 +175,11 @@ void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) { return; } - // Write 32 bits (signed) - // 0 -- failure - // >0 -- index - // <0 -- custom (serial procs) - - if (obj == nullptr) { + if (nullptr == obj || nullptr == fTFSet) { fWriter.write32(0); - } else if (fProcs.fTypefaceProc) { - SkDynamicMemoryWStream stream; - if (fProcs.fTypefaceProc(obj, &stream, fProcs.fTypefaceCtx)) { - auto data = stream.detachAsData(); - size_t size = data->size(); - if (!sk_64_isS32(size)) { - size = 0; - } - int32_t ssize = SkToS32(size); - fWriter.write32(-ssize); // negative to signal custom - if (size) { - this->writePad32(data->data(), size); - } - return; - } - // if the proc returned false, we fall through for std behavior + } else { + fWriter.write32(fTFSet->add(obj)); } - fWriter.write32(fTFSet ? fTFSet->add(obj) : 0); } void SkBinaryWriteBuffer::writePaint(const SkPaint& paint) { |