81 unsigned char dataWritten[1024];
82 size_t bytesWrittenToMemory = testObj->writeToMemory(dataWritten);
84 size_t bytesReadFromMemory = testObj->readFromMemory(dataWritten, bytesWrittenToMemory);
208template<
typename T,
bool testInval
id>
212 size_t bytesWritten = writer.bytesWritten();
215 unsigned char dataWritten[1024];
216 writer.writeToMemory(dataWritten);
228 size_t offsetBefore = buffer2.
offset();
231 size_t offsetAfter = buffer2.
offset();
241 TestObjectSerializationNoAlign<T, false>(testObj,
reporter);
250 size_t bytesWritten = writer.bytesWritten();
254 unsigned char dataWritten[4096];
255 writer.writeToMemory(dataWritten);
266 const unsigned char* peekBefore =
static_cast<const unsigned char*
>(buffer2.
skip(0));
269 const unsigned char* peekAfter =
static_cast<const unsigned char*
>(buffer2.
skip(0));
288 size_t bytesWritten = writer.bytesWritten();
292 unsigned char dataWritten[2048];
293 writer.writeToMemory(dataWritten);
321 std::move(invalidBitmapSource),
322 std::move(validBitmapSource),
nullptr));
325 TestFlattenableSerialization<SkImageFilter_Base>(
332 bitmap.allocN32Pixels(24, 24);
334 canvas.
clear(0x00000000);
336 paint.setImageFilter(deserializedFilter);
344 for (
int i = 0; i < 256; ++i) {
345 table[i] = (i * 41) % 256;
357 picture.playback(&canvas);
373 for (
int x = 0;
x < b2.
width(); ++
x) {
385 uint32_t typeface_id = typeface->
uniqueID();
386 stream.write(&typeface_id,
sizeof(typeface_id));
387 stream.write(data->data(), data->size());
388 return stream.detachAsData();
393 if (
length <
sizeof(stream)) {
396 memcpy(&stream, data,
sizeof(stream));
399 if (!stream->read(&
id,
sizeof(
id))) {
415 SkFont font(std::move(typeface), 30);
428 picture->
serialize(&stream, serial_procs);
429 std::unique_ptr<SkStream> inputStream(stream.detachAsStream());
458 int count = typeface->getVariationDesignPosition(
nullptr, 0);
473 INFOF(
reporter,
"Could not run fontstream test because test.ttc not found.");
484 INFOF(
reporter,
"Could not run fontstream test because Distortable.ttf not created.");
494 std::unique_ptr<SkStreamAsset> typefaceStream = typeface.
openStream(&index);
495 if (!typefaceStream) {
498 size_t length = typefaceStream->getLength();
501 s.appendf(
"Index: %d\n", index);
502 s.appendf(
"Length: %zu\n",
length);
508 if (metrics.
fFlags == 0) {
512 m +=
" UnderlineThicknessIsValid\n";
515 m +=
" kUnderlinePositionIsValid\n";
518 m +=
" kStrikeoutThicknessIsValid\n";
521 m +=
" kStrikeoutPositionIsValid\n";
524 m +=
" kBoundsInvalid\n";
528 m.appendf(
"Top: %f\n", metrics.
fTop);
529 m.appendf(
"Ascent: %f\n", metrics.
fAscent);
530 m.appendf(
"Descent: %f\n", metrics.
fDescent);
531 m.appendf(
"Bottom: %f\n", metrics.
fBottom);
532 m.appendf(
"Leading: %f\n", metrics.
fLeading);
535 m.appendf(
"XMin: %f\n", metrics.
fXMin);
536 m.appendf(
"XMax: %f\n", metrics.
fXMax);
537 m.appendf(
"XHeight: %f\n", metrics.
fXHeight);
538 m.appendf(
"CapHeight: %f\n", metrics.
fCapHeight);
548 typeface->serialize(&typefaceWStream);
550 std::unique_ptr<SkStream> typefaceStream = typefaceWStream.
detachAsStream();
556 typeface->getFamilyName(&
name);
557 cloneTypeface->getFamilyName(&cloneName);
560 "Typeface: \"%s\" CloneTypeface: \"%s\"",
name.c_str(), cloneName.
c_str());
562 "Typeface: \"%s\" CloneTypeface: \"%s\"",
name.c_str(), cloneName.
c_str());
564 SkFont font(typeface, 12);
565 SkFont clone(cloneTypeface, 12);
567 font.getMetrics(&fontMetrics);
570 "Typeface: \"%s\"\n-Metrics---\n%s-Data---\n%s\n\n"
571 "CloneTypeface: \"%s\"\n-Metrics---\n%s-Data---\n%s",
593 canvas.
clear(0x00000000);
616 canvas->
scale(0.5f, 0.5f);
621 paint.setAntiAlias(
true);
638 p.playback(surf->getCanvas());
639 return surf->makeImageSnapshot();
652 TestObjectSerializationNoAlign<SkPoint3, false>(&point,
reporter);
675 TestObjectSerializationNoAlign<SkString, false>(&
string,
reporter);
676 TestObjectSerializationNoAlign<SkString, true>(&
string,
reporter);
686 SkVector corners[4] = { {1, 2}, {2, 3}, {3,4}, {4,5} };
709 { 1.f, 2.f, 4.f, 8.f }
740 writer.writeToMemory(buf.
get());
755 writer.writeToMemory(buf.
get());
769 writer.writeToMemory(buf.
get());
824 left.write(
d->data(),
d->size());
828 right.write(
d->data(),
d->size());
847 src->serialize(&wstream,
nullptr);
895 const char* str0 =
"rect-with-url";
900 const char* str1 =
"named-destination";
905 const char* str2 =
"link-to-destination";
927 int32_t storage[
kSize/4];
934 writer.write(src,
kSize - 4);
941 writer.reset(storage,
kSize-4);
944 writer.write(src,
kSize - 4);
957 const auto&
run = builder.allocRun(font, glyph_count, 1.2f, 2.3f);
959 std::fill(
run.glyphs,
run.glyphs + glyph_count, 0);
960 auto blob = builder.make();
963 size_t blob_size = 0u;
964 size_t storage_size = 0u;
966 blob_size =
SkAlign4(blob->serialize(procs)->size());
968 storage_size = blob_size - 4;
971 storage_size = blob_size;
979 size_t path_size =
SkAlign4(path_effect->serialize()->size());
983 size_t storage_size = path_size - 4;
987 storage_size = path_size;
996 writer.writeInt(321);
998 size_t size = writer.bytesWritten();
1000 writer.writeToMemory(storage.
get());
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
static void TestObjectSerializationNoAlign(T *testObj, skiatest::Reporter *reporter)
static void TestPictureTypefaceSerialization(const SkSerialProcs *serial_procs, const SkDeserialProcs *deserial_procs, skiatest::Reporter *reporter)
static sk_sp< SkPicture > copy_picture_via_serialization(SkPicture *src)
static void setup_bitmap_for_canvas(SkBitmap *bitmap)
static sk_sp< SkTypeface > makeDistortableWithNonDefaultAxes(skiatest::Reporter *reporter)
static void compare_bitmaps(skiatest::Reporter *reporter, const SkBitmap &b1, const SkBitmap &b2)
SkString DumpFontMetrics(const SkFontMetrics &metrics)
static void TestArraySerialization(T *data, skiatest::Reporter *reporter)
static sk_sp< SkImage > make_checkerboard_image()
static void serialize_and_compare_typeface(sk_sp< SkTypeface > typeface, const char *text, const SkSerialProcs *serial_procs, const SkDeserialProcs *deserial_procs, skiatest::Reporter *reporter)
static const int kBitmapSize
static void TestTypefaceSerialization(skiatest::Reporter *reporter, const sk_sp< SkTypeface > &typeface)
static void TestObjectSerialization(T *testObj, skiatest::Reporter *reporter)
static SkBitmap draw_picture(SkPicture &picture)
SkString DumpTypeface(const SkTypeface &typeface)
static const uint32_t kArraySize
static void TestBitmapSerialization(const SkBitmap &validBitmap, const SkBitmap &invalidBitmap, bool shouldSucceed, skiatest::Reporter *reporter)
static sk_sp< SkTypeface > deserialize_typeface_proc(const void *data, size_t length, void *ctx)
static sk_sp< SkImage > render(const SkPicture &p)
static void TestColorFilterSerialization(skiatest::Reporter *reporter)
static sk_sp< SkData > serialize_typeface_proc(SkTypeface *typeface, void *ctx)
static void draw_something(SkCanvas *canvas)
static T * TestFlattenableSerialization(T *testObj, bool shouldSucceed, skiatest::Reporter *reporter)
static constexpr T SkAlign4(T x)
SK_API void SkAnnotateRectWithURL(SkCanvas *, const SkRect &, SkData *)
SK_API void SkAnnotateNamedDestination(SkCanvas *, const SkPoint &, SkData *)
SK_API void SkAnnotateLinkToDestination(SkCanvas *, const SkRect &, SkData *)
@ kSrcOver
r = s + (1-sa)*d
static SkColorFilterBase * as_CFB(SkColorFilter *filter)
constexpr SkColor SK_ColorGRAY
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
static bool ok(int result)
static void sk_bzero(void *buffer, size_t size)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SkScalarRoundToInt(x)
#define SkScalarCeilToInt(x)
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
#define DEF_TEST(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
#define INFOF(REPORTER,...)
#define REPORT_FAILURE(reporter, cond, message)
static void TestAlignment(T *testObj, skiatest::Reporter *reporter)
static const char * Define_Named_Dest_Key()
static const char * Link_Named_Dest_Key()
static const char * URL_Key()
void writeByteArray(const void *data, size_t size) override
void writeUInt(uint32_t value) override
void writeInt(int32_t value) override
sk_sp< SkImage > asImage() const
SkColor getColor(int x, int y) const
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
void clear(SkColor color)
void scale(SkScalar sx, SkScalar sy)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void drawPicture(const SkPicture *picture)
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkColorFilter > Table(const uint8_t table[256])
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
static sk_sp< SkData > MakeWithCString(const char cstr[])
static sk_sp< SkData > MakeEmpty()
std::unique_ptr< SkStreamAsset > detachAsStream()
SkScalar getMetrics(SkFontMetrics *metrics) const
static sk_sp< SkImageFilter > Image(sk_sp< SkImage > image, const SkRect &srcRect, const SkRect &dstRect, const SkSamplingOptions &sampling)
static sk_sp< SkImageFilter > Blend(SkBlendMode mode, sk_sp< SkImageFilter > background, sk_sp< SkImageFilter > foreground=nullptr, const CropRect &cropRect={})
static const SkMatrix & I()
void setColor(SkColor color)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
static sk_sp< SkPicture > MakeFromData(const SkData *data, const SkDeserialProcs *procs=nullptr)
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
void setRectRadii(const SkRect &rect, const SkVector radii[4])
bool readColor4fArray(SkColor4f *colors, size_t size)
const void * skipByteArray(size_t *size)
void readMatrix(SkMatrix *matrix)
SkFlattenable * readFlattenable(SkFlattenable::Type)
bool readByteArray(void *value, size_t size)
bool readIntArray(int32_t *values, size_t size)
const void * skip(size_t size)
sk_sp< SkData > readByteArrayAsData()
bool readPointArray(SkPoint *points, size_t size)
void readString(SkString *string)
bool readColorArray(SkColor *colors, size_t size)
bool readScalarArray(SkScalar *values, size_t size)
void readPoint3(SkPoint3 *point)
void readRegion(SkRegion *region)
void readPath(SkPath *path)
const char * c_str() const
SkTypefaceID uniqueID() const
void serialize(SkWStream *, SerializeBehavior=SerializeBehavior::kIncludeDataIfLocal) const
static sk_sp< SkTypeface > MakeDeserialize(SkStream *, sk_sp< SkFontMgr > lastResortMgr)
std::unique_ptr< SkStreamAsset > openStream(int *ttcIndex) const
virtual void writeScalarArray(const SkScalar *value, uint32_t count)=0
virtual void writeRegion(const SkRegion ®ion)=0
virtual void writePointArray(const SkPoint *point, uint32_t count)=0
virtual void writeColor4fArray(const SkColor4f *color, uint32_t count)=0
virtual void writeFlattenable(const SkFlattenable *flattenable)=0
virtual void writeMatrix(const SkMatrix &matrix)=0
virtual void writeByteArray(const void *data, size_t size)=0
virtual void writePoint3(const SkPoint3 &point)=0
virtual void writePath(const SkPath &path)=0
virtual void writeColorArray(const SkColor *color, uint32_t count)=0
virtual void writeIntArray(const int32_t *value, uint32_t count)=0
virtual void writeString(std::string_view value)=0
TestAnnotationCanvas(skiatest::Reporter *reporter, const AnnotationRec rec[], int count)
void onDrawAnnotation(const SkRect &rect, const char key[], SkData *value) override
~TestAnnotationCanvas() override
void realloc(size_t count)
static constexpr int kSize
const EmbeddedViewParams * params
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static const uint8_t buffer[]
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static void InvalidateData(unsigned char *data)
static void InvalidateData(unsigned char *data)
static void Write(SkWriteBuffer &writer, SkColor4f *data, uint32_t arraySize)
static bool Read(SkReadBuffer &reader, SkColor4f *data, uint32_t arraySize)
static void Write(SkWriteBuffer &writer, SkColor *data, uint32_t arraySize)
static bool Read(SkReadBuffer &reader, SkColor *data, uint32_t arraySize)
static void Read(SkReadBuffer &reader, SkMatrix *matrix)
static void Write(SkWriteBuffer &writer, const SkMatrix *matrix)
static void Write(SkWriteBuffer &writer, const SkPath *path)
static void Read(SkReadBuffer &reader, SkPath *path)
static void Write(SkWriteBuffer &writer, const SkPoint3 *data)
static void Read(SkReadBuffer &reader, SkPoint3 *data)
static bool Read(SkReadBuffer &reader, SkPoint *data, uint32_t arraySize)
static void Write(SkWriteBuffer &writer, SkPoint *data, uint32_t arraySize)
static void Write(SkWriteBuffer &writer, const SkRegion *region)
static void Read(SkReadBuffer &reader, SkRegion *region)
static void Write(SkWriteBuffer &writer, SkScalar *data, uint32_t arraySize)
static bool Read(SkReadBuffer &reader, SkScalar *data, uint32_t arraySize)
static void Read(SkReadBuffer &reader, SkString *string)
static void Write(SkWriteBuffer &writer, const SkString *string)
static bool Read(SkReadBuffer &reader, int32_t *data, uint32_t arraySize)
static void Write(SkWriteBuffer &writer, int32_t *data, uint32_t arraySize)
static void Write(SkWriteBuffer &writer, unsigned char *data, uint32_t arraySize)
static bool Read(SkReadBuffer &reader, unsigned char *data, uint32_t arraySize)
static void Read(SkReadBuffer &reader, T **flattenable)
static void Write(SkWriteBuffer &writer, const T *flattenable)
SkDeserialTypefaceProc fTypefaceProc
SkFontArguments & setVariationDesignPosition(VariationPosition position)
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
SkScalar fLeading
distance to add between lines, typically positive or zero
SkScalar fAvgCharWidth
average character width, zero if unknown
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
SkScalar fStrikeoutThickness
strikeout thickness
SkScalar fMaxCharWidth
maximum character width, zero if unknown
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
uint32_t fFlags
FontMetricsFlags indicating which metrics are valid.
SkScalar fAscent
distance to reserve above baseline, typically negative
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
SkScalar fUnderlineThickness
underline thickness
@ kStrikeoutPositionIsValid_Flag
set if fStrikeoutPosition is valid
@ kStrikeoutThicknessIsValid_Flag
set if fStrikeoutThickness is valid
@ kUnderlinePositionIsValid_Flag
set if fUnderlinePosition is valid
@ kUnderlineThicknessIsValid_Flag
set if fUnderlineThickness is valid
@ kBoundsInvalid_Flag
set if fTop, fBottom, fXMin, fXMax invalid
SkScalar fDescent
distance to reserve below baseline, typically positive
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
constexpr int32_t height() const
constexpr int32_t width() const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
static SkImageInfo MakeN32Premul(int width, int height)
static SkRGBA4f FromColor(SkColor color)
constexpr float x() const
constexpr float y() const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)
SkSerialImageProc fImageProc
SkSerialTypefaceProc fTypefaceProc