Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
SkTextBlobPriv Class Reference

#include <SkTextBlobPriv.h>

Static Public Member Functions

static void Flatten (const SkTextBlob &, SkWriteBuffer &)
 
static sk_sp< SkTextBlobMakeFromBuffer (SkReadBuffer &)
 
static bool HasRSXForm (const SkTextBlob &blob)
 

Detailed Description

Definition at line 25 of file SkTextBlobPriv.h.

Member Function Documentation

◆ Flatten()

void SkTextBlobPriv::Flatten ( const SkTextBlob blob,
SkWriteBuffer buffer 
)
static

Serialize to a buffer.

Definition at line 663 of file SkTextBlob.cpp.

663 {
664 // seems like we could skip this, and just recompute bounds in unflatten, but
665 // some cc_unittests fail if we remove this...
666 buffer.writeRect(blob.bounds());
667
668 SkTextBlobRunIterator it(&blob);
669 while (!it.done()) {
670 SkASSERT(it.glyphCount() > 0);
671
672 buffer.write32(it.glyphCount());
673 PositioningAndExtended pe;
674 pe.intValue = 0;
675 pe.positioning = it.positioning();
676 SkASSERT((int32_t)it.positioning() == pe.intValue); // backwards compat.
677
678 uint32_t textSize = it.textSize();
679 pe.extended = textSize > 0;
680 buffer.write32(pe.intValue);
681 if (pe.extended) {
682 buffer.write32(textSize);
683 }
684 buffer.writePoint(it.offset());
685
686 SkFontPriv::Flatten(it.font(), buffer);
687
688 buffer.writeByteArray(it.glyphs(), it.glyphCount() * sizeof(uint16_t));
689 buffer.writeByteArray(it.pos(),
690 it.glyphCount() * sizeof(SkScalar) *
691 SkTextBlob::ScalarsPerGlyph(
692 SkTo<SkTextBlob::GlyphPositioning>(it.positioning())));
693 if (pe.extended) {
694 buffer.writeByteArray(it.clusters(), sizeof(uint32_t) * it.glyphCount());
695 buffer.writeByteArray(it.text(), it.textSize());
696 }
697
698 it.next();
699 }
700
701 // Marker for the last run (0 is not a valid glyph count).
702 buffer.write32(0);
703}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void Flatten(const SkFont &, SkWriteBuffer &buffer)
const SkRect & bounds() const
Definition: SkTextBlob.h:53
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ HasRSXForm()

static bool SkTextBlobPriv::HasRSXForm ( const SkTextBlob blob)
static

◆ MakeFromBuffer()

sk_sp< SkTextBlob > SkTextBlobPriv::MakeFromBuffer ( SkReadBuffer reader)
static

Recreate an SkTextBlob that was serialized into a buffer.

Parameters
SkReadBufferSerialized blob data.
Returns
A new SkTextBlob representing the serialized data, or NULL if the buffer is invalid.

Definition at line 705 of file SkTextBlob.cpp.

705 {
707 reader.readRect(&bounds);
708
709 SkTextBlobBuilder blobBuilder;
710 SkSafeMath safe;
711 for (;;) {
712 int glyphCount = reader.read32();
713 if (glyphCount == 0) {
714 // End-of-runs marker.
715 break;
716 }
717
718 PositioningAndExtended pe;
719 pe.intValue = reader.read32();
720 const auto pos = SkTo<SkTextBlob::GlyphPositioning>(pe.positioning);
721 if (glyphCount <= 0 || pos > SkTextBlob::kRSXform_Positioning) {
722 return nullptr;
723 }
724 int textSize = pe.extended ? reader.read32() : 0;
725 if (textSize < 0) {
726 return nullptr;
727 }
728
730 reader.readPoint(&offset);
731 SkFont font;
732 SkFontPriv::Unflatten(&font, reader);
733
734 // Compute the expected size of the buffer and ensure we have enough to deserialize
735 // a run before allocating it.
736 const size_t glyphSize = safe.mul(glyphCount, sizeof(uint16_t)),
737 posSize =
738 safe.mul(glyphCount, safe.mul(sizeof(SkScalar),
739 SkTextBlob::ScalarsPerGlyph(pos))),
740 clusterSize = pe.extended ? safe.mul(glyphCount, sizeof(uint32_t)) : 0;
741 const size_t totalSize =
742 safe.add(safe.add(glyphSize, posSize), safe.add(clusterSize, textSize));
743
744 if (!reader.isValid() || !safe || totalSize > reader.available()) {
745 return nullptr;
746 }
747
748 const SkTextBlobBuilder::RunBuffer* buf = nullptr;
749 switch (pos) {
751 buf = &blobBuilder.allocRunText(font, glyphCount, offset.x(), offset.y(),
752 textSize, &bounds);
753 break;
755 buf = &blobBuilder.allocRunTextPosH(font, glyphCount, offset.y(),
756 textSize, &bounds);
757 break;
759 buf = &blobBuilder.allocRunTextPos(font, glyphCount, textSize, &bounds);
760 break;
762 buf = &blobBuilder.allocRunTextRSXform(font, glyphCount, textSize, &bounds);
763 break;
764 }
765
766 if (!buf->glyphs ||
767 !buf->pos ||
768 (pe.extended && (!buf->clusters || !buf->utf8text))) {
769 return nullptr;
770 }
771
772 if (!reader.readByteArray(buf->glyphs, glyphSize) ||
773 !reader.readByteArray(buf->pos, posSize)) {
774 return nullptr;
775 }
776
777 if (pe.extended) {
778 if (!reader.readByteArray(buf->clusters, clusterSize) ||
779 !reader.readByteArray(buf->utf8text, textSize)) {
780 return nullptr;
781 }
782 }
783 }
784
785 return blobBuilder.make();
786}
SkPoint pos
@ kHorizontal_Positioning
Definition: SkTextBlob.cpp:194
@ kDefault_Positioning
Definition: SkTextBlob.cpp:193
@ kRSXform_Positioning
Definition: SkTextBlob.cpp:196
@ kFull_Positioning
Definition: SkTextBlob.cpp:195
static bool Unflatten(SkFont *, SkReadBuffer &buffer)
Definition: SkFont.h:35
void readRect(SkRect *rect)
void readPoint(SkPoint *point)
bool readByteArray(void *value, size_t size)
bool isValid() const
Definition: SkReadBuffer.h:208
int32_t read32()
size_t available() const
Definition: SkReadBuffer.h:82
size_t add(size_t x, size_t y)
Definition: SkSafeMath.h:33
size_t mul(size_t x, size_t y)
Definition: SkSafeMath.h:29
const RunBuffer & allocRunTextPosH(const SkFont &font, int count, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
Definition: SkTextBlob.cpp:578
const RunBuffer & allocRunText(const SkFont &font, int count, SkScalar x, SkScalar y, int textByteCount, const SkRect *bounds=nullptr)
Definition: SkTextBlob.cpp:565
const RunBuffer & allocRunTextRSXform(const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
Definition: SkTextBlob.cpp:604
sk_sp< SkTextBlob > make()
Definition: SkTextBlob.cpp:617
const RunBuffer & allocRunTextPos(const SkFont &font, int count, int textByteCount, const SkRect *bounds=nullptr)
Definition: SkTextBlob.cpp:592
Optional< SkRect > bounds
Definition: SkRecords.h:189
font
Font Metadata and Metrics.
SeparatedVector2 offset
SkScalar * pos
storage for glyph positions in run
Definition: SkTextBlob.h:330
char * utf8text
storage for text UTF-8 code units in run
Definition: SkTextBlob.h:331
SkGlyphID * glyphs
storage for glyph indexes in run
Definition: SkTextBlob.h:329
uint32_t * clusters
storage for glyph clusters (index of UTF-8 code unit)
Definition: SkTextBlob.h:332

The documentation for this class was generated from the following files: