Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 96fdfe0

Browse files
dogbenSkia Commit-Bot
authored andcommitted
Fix test TextBlob_serialize
Previously, this test was passing only because it used the default typeface. In deserialization code, if the typeface can't be deserialized, it is replaced with the default typeface. I changed the test to use a non-default typeface, which caused it to fail. I then changed the custom typeface serializer/deserializer functions so that the test passes. Change-Id: I14e33f7fd18342e76a1fa624ae97fd894e010b6a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226221 Commit-Queue: Ben Wagner <[email protected]> Auto-Submit: Ben Wagner aka dogben <[email protected]> Reviewed-by: Ben Wagner <[email protected]>
1 parent 7232e90 commit 96fdfe0

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tests/TextBlobTest.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ DEF_TEST(TextBlob_extended, reporter) {
352352
///////////////////////////////////////////////////////////////////////////////////////////////////
353353
#include "include/core/SkCanvas.h"
354354
#include "include/core/SkSurface.h"
355-
#include "include/private/SkTDArray.h"
355+
#include "include/private/SkTArray.h"
356356

357357
static void add_run(SkTextBlobBuilder* builder, const char text[], SkScalar x, SkScalar y,
358358
sk_sp<SkTypeface> tf) {
@@ -381,22 +381,25 @@ static sk_sp<SkImage> render(const SkTextBlob* blob) {
381381
}
382382

383383
static sk_sp<SkData> SerializeTypeface(SkTypeface* tf, void* ctx) {
384-
auto array = (SkTDArray<SkTypeface*>*)ctx;
385-
*array->append() = tf;
386-
return sk_sp<SkData>(nullptr);
384+
auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
385+
const size_t idx = array->size();
386+
array->emplace_back(sk_ref_sp(tf));
387+
// In this test, we are deserializing on the same machine, so we don't worry about endianness.
388+
return SkData::MakeWithCopy(&idx, sizeof(idx));
387389
}
388390

389391
static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, void* ctx) {
390-
auto array = (SkTDArray<SkTypeface*>*)ctx;
391-
for (int i = 0; i < array->count(); ++i) {
392-
auto result = (*array)[i];
393-
if (result) {
394-
(*array)[i] = nullptr;
395-
return sk_ref_sp(result);
396-
}
392+
auto array = (SkTArray<sk_sp<SkTypeface>>*)ctx;
393+
if (length != sizeof(size_t)) {
394+
SkASSERT(false);
395+
return nullptr;
396+
}
397+
size_t idx = *reinterpret_cast<const size_t*>(data);
398+
if (idx >= array->size()) {
399+
SkASSERT(false);
400+
return nullptr;
397401
}
398-
SkASSERT(false);
399-
return sk_sp<SkTypeface>(nullptr);
402+
return (*array)[idx];
400403
}
401404

402405
/*
@@ -407,15 +410,15 @@ static sk_sp<SkTypeface> DeserializeTypeface(const void* data, size_t length, vo
407410
*/
408411
DEF_TEST(TextBlob_serialize, reporter) {
409412
sk_sp<SkTextBlob> blob0 = []() {
410-
sk_sp<SkTypeface> tf = SkTypeface::MakeDefault();
413+
sk_sp<SkTypeface> tf = SkTypeface::MakeFromName(nullptr, SkFontStyle::BoldItalic());
411414

412415
SkTextBlobBuilder builder;
413416
add_run(&builder, "Hello", 10, 20, nullptr); // don't flatten a typeface
414417
add_run(&builder, "World", 10, 40, tf); // do flatten this typeface
415418
return builder.make();
416419
}();
417420

418-
SkTDArray<SkTypeface*> array;
421+
SkTArray<sk_sp<SkTypeface>> array;
419422
SkSerialProcs serializeProcs;
420423
serializeProcs.fTypefaceProc = &SerializeTypeface;
421424
serializeProcs.fTypefaceCtx = (void*) &array;

0 commit comments

Comments
 (0)