diff options
author | Cary Clark <caryclark@skia.org> | 2018-07-19 10:07:01 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-19 14:32:45 +0000 |
commit | 785586af7dc72c23d0ab30204ab2975a1451dc16 (patch) | |
tree | 73c0d824fd0e35baef10df90b9f55faba6ab08bb /tests | |
parent | e70604ea8b5216621e50f7063edf7d56ee95498d (diff) |
remove unused serialization in textblob
The SKTextBlob serialization code that is tested by Skia is
unused by Chrome. The serialization code that is
used by Chrome is untested by Skia.
Remove the unused code; test the used code.
The code path introduced nearly a year ago,
likely for slimming paint, attempts to make
text blobs smarter by allowing the reuse of typefaces.
Maybe there needs to be a Chrome bug / feature
request to use this?
If if turns out there is no interest to do so,
This CL aligns used interfaces with tests.
R=reed@google.com,fmalita@google.com,bungeman@google.com
Bug: skia:6818
Change-Id: I9b3ec0c326495322986ba26f20f901bcb208be73
Reviewed-on: https://skia-review.googlesource.com/141542
Reviewed-by: Cary Clark <caryclark@skia.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
Auto-Submit: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/TextBlobTest.cpp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 7780ef7a7f..5018d7a79b 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -7,6 +7,7 @@ #include "SkPaint.h" #include "SkPoint.h" +#include "SkSerialProcs.h" #include "SkTextBlobRunIterator.h" #include "SkTo.h" #include "SkTypeface.h" @@ -412,6 +413,25 @@ static sk_sp<SkImage> render(const SkTextBlob* blob) { return surf->makeImageSnapshot(); } +static sk_sp<SkData> SerializeTypeface(SkTypeface* tf, void* ctx) { + auto array = (SkTDArray<SkTypeface*>*)ctx; + *array->append() = tf; + return sk_sp<SkData>(nullptr); +} + +static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, void* ctx) { + auto array = (SkTDArray<SkTypeface*>*)ctx; + for (int i = 0; i < array->count(); ++i) { + auto result = (*array)[i]; + if (result) { + (*array)[i] = nullptr; + return sk_ref_sp(result); + } + } + SkASSERT(false); + return sk_sp<SkTypeface>(nullptr); +} + /* * Build a blob with more than one typeface. * Draw it into an offscreen, @@ -429,26 +449,15 @@ DEF_TEST(TextBlob_serialize, reporter) { }(); SkTDArray<SkTypeface*> array; - sk_sp<SkData> data = blob0->serialize([](SkTypeface* tf, void* ctx) { - auto array = (SkTDArray<SkTypeface*>*)ctx; - if (array->find(tf) < 0) { - *array->append() = tf; - } - }, &array); - // we only expect 1, since null would not have been serialized, but the default would - REPORTER_ASSERT(reporter, array.count() == 1); - - sk_sp<SkTextBlob> blob1 = SkTextBlob::Deserialize(data->data(), data->size(), - [](uint32_t uniqueID, void* ctx) { - auto array = (SkTDArray<SkTypeface*>*)ctx; - for (int i = 0; i < array->count(); ++i) { - if ((*array)[i]->uniqueID() == uniqueID) { - return sk_ref_sp((*array)[i]); - } - } - SkASSERT(false); - return sk_sp<SkTypeface>(nullptr); - }, &array); + SkSerialProcs serializeProcs; + serializeProcs.fTypefaceProc = &SerializeTypeface; + serializeProcs.fTypefaceCtx = (void*) &array; + sk_sp<SkData> data = blob0->serialize(serializeProcs); + REPORTER_ASSERT(reporter, array.count() == 2); + SkDeserialProcs deserializeProcs; + deserializeProcs.fTypefaceProc = &DeserializeTypeface; + deserializeProcs.fTypefaceCtx = (void*) &array; + sk_sp<SkTextBlob> blob1 = SkTextBlob::Deserialize(data->data(), data->size(), deserializeProcs); sk_sp<SkImage> img0 = render(blob0.get()); sk_sp<SkImage> img1 = render(blob1.get()); |