Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
SkBlockAllocator::Block Class Referencefinal

#include <SkBlockAllocator.h>

Public Member Functions

 ~Block ()
 
void operator delete (void *p)
 
template<size_t Align = 1, size_t Padding = 0>
int avail () const
 
template<size_t Align = 1, size_t Padding = 0>
int firstAlignedOffset () const
 
void * ptr (int offset)
 
const void * ptr (int offset) const
 
int metadata () const
 
void setMetadata (int value)
 
bool release (int start, int end)
 
bool resize (int start, int end, int deltaBytes)
 

Friends

class SkBlockAllocator
 

Detailed Description

Definition at line 71 of file SkBlockAllocator.h.

Constructor & Destructor Documentation

◆ ~Block()

SkBlockAllocator::Block::~Block ( )

Definition at line 48 of file SkBlockAllocator.cpp.

48 {
49 this->unpoisonRange(kDataStart, fSize);
50
51 SkASSERT(fSentinel == kAssignedMarker);
52 SkDEBUGCODE(fSentinel = kFreedMarker;) // FWIW
53}
#define SkASSERT(cond)
Definition: SkAssert.h:116

Member Function Documentation

◆ avail()

template<size_t Align = 1, size_t Padding = 0>
int SkBlockAllocator::Block::avail ( ) const
inline

Definition at line 78 of file SkBlockAllocator.h.

78{ return std::max(0, fSize - this->cursor<Align, Padding>()); }
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ firstAlignedOffset()

template<size_t Align = 1, size_t Padding = 0>
int SkBlockAllocator::Block::firstAlignedOffset ( ) const
inline

Definition at line 85 of file SkBlockAllocator.h.

85{ return this->alignedOffset<Align, Padding>(kDataStart); }

◆ metadata()

int SkBlockAllocator::Block::metadata ( ) const
inline

Definition at line 96 of file SkBlockAllocator.h.

96{ return fMetadata; }

◆ operator delete()

void SkBlockAllocator::Block::operator delete ( void *  p)
inline

Definition at line 74 of file SkBlockAllocator.h.

74{ ::operator delete(p); }

◆ ptr() [1/2]

void * SkBlockAllocator::Block::ptr ( int  offset)
inline

Definition at line 88 of file SkBlockAllocator.h.

88 {
89 SkASSERT(offset >= kDataStart && offset < fSize);
90 return reinterpret_cast<char*>(this) + offset;
91 }
SeparatedVector2 offset

◆ ptr() [2/2]

const void * SkBlockAllocator::Block::ptr ( int  offset) const
inline

Definition at line 92 of file SkBlockAllocator.h.

92{ return const_cast<Block*>(this)->ptr(offset); }
void * ptr(int offset)

◆ release()

bool SkBlockAllocator::Block::release ( int  start,
int  end 
)
inline

Release the byte range between offset 'start' (inclusive) and 'end' (exclusive). This will return true if those bytes were successfully reclaimed, i.e. a subsequent allocation request could occupy the space. Regardless of return value, the provided byte range that [start, end) represents should not be used until it's re-allocated with allocate<...>().

Definition at line 677 of file SkBlockAllocator.h.

677 {
678 SkASSERT(fSentinel == kAssignedMarker);
679 SkASSERT(start >= kDataStart && end <= fSize && start < end);
680
681 this->poisonRange(start, end);
682
683 if (fCursor == end) {
684 fCursor = start;
685 return true;
686 } else {
687 return false;
688 }
689}
glong glong end

◆ resize()

bool SkBlockAllocator::Block::resize ( int  start,
int  end,
int  deltaBytes 
)
inline

Resize a previously reserved byte range of offset 'start' (inclusive) to 'end' (exclusive). 'deltaBytes' is the SIGNED change to length of the reservation.

When negative this means the reservation is shrunk and the new length is (end - start - |deltaBytes|). If this new length would be 0, the byte range can no longer be used (as if it were released instead). Asserts that it would not shrink the reservation below 0.

If 'deltaBytes' is positive, the allocator attempts to increase the length of the reservation. If 'deltaBytes' is less than or equal to avail() and it was the last allocation in the block, it can be resized. If there is not enough available bytes to accommodate the increase in size, or another allocation is blocking the increase in size, then false will be returned and the reserved byte range is unmodified.

Definition at line 646 of file SkBlockAllocator.h.

646 {
647 SkASSERT(fSentinel == kAssignedMarker);
648 SkASSERT(start >= kDataStart && end <= fSize && start < end);
649
650 if (deltaBytes > kMaxAllocationSize || deltaBytes < -kMaxAllocationSize) {
651 // Cannot possibly satisfy the resize and could overflow subsequent math
652 return false;
653 }
654 if (fCursor == end) {
655 int nextCursor = end + deltaBytes;
656 SkASSERT(nextCursor >= start);
657 // We still check nextCursor >= start for release builds that wouldn't assert.
658 if (nextCursor <= fSize && nextCursor >= start) {
659 if (nextCursor < fCursor) {
660 // The allocation got smaller; poison the space that can no longer be used.
661 this->poisonRange(nextCursor + 1, end);
662 } else {
663 // The allocation got larger; unpoison the space that can now be used.
664 this->unpoisonRange(end, nextCursor);
665 }
666
667 fCursor = nextCursor;
668 return true;
669 }
670 }
671 return false;
672}
static constexpr int kMaxAllocationSize

◆ setMetadata()

void SkBlockAllocator::Block::setMetadata ( int  value)
inline

Definition at line 97 of file SkBlockAllocator.h.

97{ fMetadata = value; }
uint8_t value

Friends And Related Function Documentation

◆ SkBlockAllocator

friend class SkBlockAllocator
friend

Definition at line 124 of file SkBlockAllocator.h.


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