Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
SkDescriptor Class Reference

#include <SkDescriptor.h>

Inheritance diagram for SkDescriptor:
SkNoncopyable

Classes

struct  Entry
 

Public Member Functions

void operator delete (void *p)
 
void * operator new (size_t)
 
void * operator new (size_t, void *p)
 
void flatten (SkWriteBuffer &buffer) const
 
uint32_t getLength () const
 
void * addEntry (uint32_t tag, size_t length, const void *data=nullptr)
 
void computeChecksum ()
 
bool isValid () const
 
const void * findEntry (uint32_t tag, uint32_t *length) const
 
std::unique_ptr< SkDescriptorcopy () const
 
bool operator== (const SkDescriptor &other) const
 
bool operator!= (const SkDescriptor &other) const
 
uint32_t getChecksum () const
 
uint32_t getCount () const
 
SkString dumpRec () const
 

Static Public Member Functions

static size_t ComputeOverhead (int entryCount)
 
static std::unique_ptr< SkDescriptorAlloc (size_t length)
 

Friends

class SkDescriptorTestHelper
 
class SkAutoDescriptor
 

Detailed Description

Definition at line 24 of file SkDescriptor.h.

Member Function Documentation

◆ addEntry()

void * SkDescriptor::addEntry ( uint32_t  tag,
size_t  length,
const void *  data = nullptr 
)

Definition at line 35 of file SkDescriptor.cpp.

35 {
36 SkASSERT(tag);
38 SkASSERT(this->findEntry(tag, nullptr) == nullptr);
39
40 Entry* entry = (Entry*)((char*)this + fLength);
41 entry->fTag = tag;
42 entry->fLen = SkToU32(length);
43 if (data) {
44 memcpy(entry + 1, data, length);
45 }
46
47 fCount += 1;
48 fLength = SkToU32(fLength + sizeof(Entry) + length);
49 return (entry + 1); // return its data
50}
static constexpr T SkAlign4(T x)
Definition SkAlign.h:16
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr uint32_t SkToU32(S x)
Definition SkTo.h:26
const void * findEntry(uint32_t tag, uint32_t *length) const
size_t length

◆ Alloc()

std::unique_ptr< SkDescriptor > SkDescriptor::Alloc ( size_t  length)
static

Definition at line 20 of file SkDescriptor.cpp.

20 {
22 void* allocation = ::operator new(length);
23 return std::unique_ptr<SkDescriptor>(new (allocation) SkDescriptor{});
24}

◆ computeChecksum()

void SkDescriptor::computeChecksum ( )

Definition at line 52 of file SkDescriptor.cpp.

52 {
53 fChecksum = SkDescriptor::ComputeChecksum(this);
54}

◆ ComputeOverhead()

static size_t SkDescriptor::ComputeOverhead ( int  entryCount)
inlinestatic

Definition at line 26 of file SkDescriptor.h.

26 {
27 SkASSERT(entryCount >= 0);
28 return sizeof(SkDescriptor) + entryCount * sizeof(Entry);
29 }

◆ copy()

std::unique_ptr< SkDescriptor > SkDescriptor::copy ( ) const

Definition at line 72 of file SkDescriptor.cpp.

72 {
73 std::unique_ptr<SkDescriptor> desc = SkDescriptor::Alloc(fLength);
74 memcpy(desc.get(), this, fLength);
75 return desc;
76}
static std::unique_ptr< SkDescriptor > Alloc(size_t length)

◆ dumpRec()

SkString SkDescriptor::dumpRec ( ) const

Definition at line 93 of file SkDescriptor.cpp.

93 {
94 const SkScalerContextRec* rec = static_cast<const SkScalerContextRec*>(
95 this->findEntry(kRec_SkDescriptorTag, nullptr));
96
98 result.appendf(" Checksum: %x\n", fChecksum);
99 if (rec != nullptr) {
100 result.append(rec->dump());
101 }
102 return result;
103}
#define kRec_SkDescriptorTag
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
GAsyncResult * result
SkString dump() const

◆ findEntry()

const void * SkDescriptor::findEntry ( uint32_t  tag,
uint32_t *  length 
) const

Definition at line 56 of file SkDescriptor.cpp.

56 {
57 const Entry* entry = (const Entry*)(this + 1);
58 int count = fCount;
59
60 while (--count >= 0) {
61 if (entry->fTag == tag) {
62 if (length) {
63 *length = entry->fLen;
64 }
65 return entry + 1;
66 }
67 entry = (const Entry*)((const char*)(entry + 1) + entry->fLen);
68 }
69 return nullptr;
70}
int count

◆ flatten()

void SkDescriptor::flatten ( SkWriteBuffer buffer) const

Definition at line 31 of file SkDescriptor.cpp.

31 {
32 buffer.writePad32(static_cast<const void*>(this), this->fLength);
33}
static const uint8_t buffer[]

◆ getChecksum()

uint32_t SkDescriptor::getChecksum ( ) const
inline

Definition at line 63 of file SkDescriptor.h.

63{ return fChecksum; }

◆ getCount()

uint32_t SkDescriptor::getCount ( ) const
inline

Definition at line 70 of file SkDescriptor.h.

70{ return fCount; }

◆ getLength()

uint32_t SkDescriptor::getLength ( ) const
inline

Definition at line 41 of file SkDescriptor.h.

41{ return fLength; }

◆ isValid()

bool SkDescriptor::isValid ( ) const

Definition at line 111 of file SkDescriptor.cpp.

111 {
112 uint32_t count = fCount;
113 size_t lengthRemaining = this->fLength;
114 if (lengthRemaining < sizeof(SkDescriptor)) {
115 return false;
116 }
117 lengthRemaining -= sizeof(SkDescriptor);
118 size_t offset = sizeof(SkDescriptor);
119
120 while (lengthRemaining > 0 && count > 0) {
121 if (lengthRemaining < sizeof(Entry)) {
122 return false;
123 }
124 lengthRemaining -= sizeof(Entry);
125
126 const Entry* entry = (const Entry*)(reinterpret_cast<const char*>(this) + offset);
127
128 if (lengthRemaining < entry->fLen) {
129 return false;
130 }
131 lengthRemaining -= entry->fLen;
132
133 // rec tags are always a known size.
134 if (entry->fTag == kRec_SkDescriptorTag && entry->fLen != sizeof(SkScalerContextRec)) {
135 return false;
136 }
137
138 offset += sizeof(Entry) + entry->fLen;
139 count--;
140 }
141 return lengthRemaining == 0 && count == 0;
142}
Point offset

◆ operator delete()

void SkDescriptor::operator delete ( void *  p)

Definition at line 26 of file SkDescriptor.cpp.

26{ ::operator delete(p); }

◆ operator new() [1/2]

void * SkDescriptor::operator new ( size_t  )

Definition at line 27 of file SkDescriptor.cpp.

27 {
28 SK_ABORT("Descriptors are created with placement new.");
29}
#define SK_ABORT(message,...)
Definition SkAssert.h:70

◆ operator new() [2/2]

void * SkDescriptor::operator new ( size_t  ,
void *  p 
)
inline

Definition at line 37 of file SkDescriptor.h.

37{ return p; }

◆ operator!=()

bool SkDescriptor::operator!= ( const SkDescriptor other) const
inline

Definition at line 61 of file SkDescriptor.h.

61{ return !(*this == other); }

◆ operator==()

bool SkDescriptor::operator== ( const SkDescriptor other) const

Definition at line 78 of file SkDescriptor.cpp.

78 {
79 // the first value we should look at is the checksum, so this loop
80 // should terminate early if they descriptors are different.
81 // NOTE: if we wrote a sentinel value at the end of each, we could
82 // remove the aa < stop test in the loop...
83 const uint32_t* aa = (const uint32_t*)this;
84 const uint32_t* bb = (const uint32_t*)&other;
85 const uint32_t* stop = (const uint32_t*)((const char*)aa + fLength);
86 do {
87 if (*aa++ != *bb++)
88 return false;
89 } while (aa < stop);
90 return true;
91}

Friends And Related Symbol Documentation

◆ SkAutoDescriptor

friend class SkAutoDescriptor
friend

Definition at line 77 of file SkDescriptor.h.

◆ SkDescriptorTestHelper

friend class SkDescriptorTestHelper
friend

Definition at line 76 of file SkDescriptor.h.


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