Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
skgpu::Plot Class Reference

#include <AtlasTypes.h>

Inheritance diagram for skgpu::Plot:
SkRefCnt SkRefCntBase

Public Member Functions

 Plot (int pageIndex, int plotIndex, AtlasGenerationCounter *generationCounter, int offX, int offY, int width, int height, SkColorType colorType, size_t bpp)
 
uint32_t pageIndex () const
 
uint32_t plotIndex () const
 
uint64_t genID () const
 
PlotLocator plotLocator () const
 
 SkDEBUGCODE (size_t bpp() const { return fBytesPerPixel;}) bool addRect(int width
 
void * dataAt (const AtlasLocator &atlasLocator)
 
void copySubImage (const AtlasLocator &atlasLocator, const void *image)
 
SkIPoint prepForRender (const AtlasLocator &, SkAutoPixmapStorage *)
 
bool addSubImage (int width, int height, const void *image, AtlasLocator *atlasLocator)
 
skgpu::AtlasToken lastUploadToken () const
 
skgpu::AtlasToken lastUseToken () const
 
void setLastUploadToken (skgpu::AtlasToken token)
 
void setLastUseToken (skgpu::AtlasToken token)
 
int flushesSinceLastUsed ()
 
void resetFlushesSinceLastUsed ()
 
void incFlushesSinceLastUsed ()
 
bool needsUpload ()
 
std::pair< const void *, SkIRectprepareForUpload ()
 
void resetRects ()
 
void markFullIfUsed ()
 
sk_sp< Plotclone () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Public Attributes

int height
 
int AtlasLocatoratlasLocator
 
const uint32_t fPageIndex: 16
 
const uint32_t fPlotIndex: 16
 

Detailed Description

The backing texture for an atlas is broken into a spatial grid of Plots. The Plots keep track of subimage placement via their Rectanizer. A Plot may be subclassed if the atlas class needs to track additional information.

Definition at line 435 of file AtlasTypes.h.

Constructor & Destructor Documentation

◆ Plot()

skgpu::Plot::Plot ( int  pageIndex,
int  plotIndex,
AtlasGenerationCounter generationCounter,
int  offX,
int  offY,
int  width,
int  height,
SkColorType  colorType,
size_t  bpp 
)

Definition at line 18 of file AtlasTypes.cpp.

20 : fLastUpload(AtlasToken::InvalidToken())
21 , fLastUse(AtlasToken::InvalidToken())
22 , fFlushesSinceLastUse(0)
25 , fGenerationCounter(generationCounter)
26 , fGenID(fGenerationCounter->next())
27 , fPlotLocator(fPageIndex, fPlotIndex, fGenID)
28 , fData(nullptr)
29 , fWidth(width)
30 , fHeight(height)
31 , fX(offX)
32 , fY(offY)
33 , fRectanizer(width, height)
34 , fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight))
35 , fColorType(colorType)
36 , fBytesPerPixel(bpp)
37 , fIsFull(false)
38#ifdef SK_DEBUG
39 , fDirty(false)
40#endif
41{
42 // We expect the allocated dimensions to be a multiple of 4 bytes
43 SkASSERT(((width*fBytesPerPixel) & 0x3) == 0);
44 // The padding for faster uploads only works for 1, 2 and 4 byte texels
45 SkASSERT(fBytesPerPixel != 3 && fBytesPerPixel <= 4);
46 fDirtyRect.setEmpty();
47}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static AtlasToken InvalidToken()
Definition: AtlasTypes.h:153
const uint32_t fPageIndex
Definition: AtlasTypes.h:518
uint32_t pageIndex() const
Definition: AtlasTypes.h:442
const uint32_t fPlotIndex
Definition: AtlasTypes.h:519
uint32_t plotIndex() const
Definition: AtlasTypes.h:445
int32_t width
static constexpr SkIPoint16 Make(int x, int y)
Definition: SkIPoint16.h:29
void setEmpty()
Definition: SkRect.h:242

Member Function Documentation

◆ addSubImage()

bool skgpu::Plot::addSubImage ( int  width,
int  height,
const void *  image,
AtlasLocator atlasLocator 
)

Definition at line 123 of file AtlasTypes.cpp.

123 {
124 if (fIsFull || !this->addRect(width, height, atlasLocator)) {
125 return false;
126 }
127 this->copySubImage(*atlasLocator, image);
128
129 return true;
130}
int AtlasLocator * atlasLocator
Definition: AtlasTypes.h:462
void copySubImage(const AtlasLocator &atlasLocator, const void *image)
Definition: AtlasTypes.cpp:99
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ clone()

sk_sp< Plot > skgpu::Plot::clone ( ) const
inline

Create a clone of this plot. The cloned plot will take the place of the current plot in the atlas

Definition at line 497 of file AtlasTypes.h.

497 {
498 return sk_sp<Plot>(new Plot(
499 fPageIndex, fPlotIndex, fGenerationCounter, fX, fY, fWidth, fHeight, fColorType,
500 fBytesPerPixel));
501 }
Plot(int pageIndex, int plotIndex, AtlasGenerationCounter *generationCounter, int offX, int offY, int width, int height, SkColorType colorType, size_t bpp)
Definition: AtlasTypes.cpp:18

◆ copySubImage()

void skgpu::Plot::copySubImage ( const AtlasLocator atlasLocator,
const void *  image 
)

Definition at line 99 of file AtlasTypes.cpp.

99 {
100 const unsigned char* imagePtr = (const unsigned char*)image;
101 unsigned char* dataPtr = (unsigned char*)this->dataAt(al);
102 int width = al.width();
103 int height = al.height();
104 size_t rowBytes = width * fBytesPerPixel;
105
106 // copy into the data buffer, swizzling as we go if this is ARGB data
107 constexpr bool kBGRAIsNative = kN32_SkColorType == kBGRA_8888_SkColorType;
108 if (4 == fBytesPerPixel && kBGRAIsNative) {
109 for (int i = 0; i < height; ++i) {
110 SkOpts::RGBA_to_BGRA((uint32_t*)dataPtr, (const uint32_t*)imagePtr, width);
111 dataPtr += fBytesPerPixel * fWidth;
112 imagePtr += rowBytes;
113 }
114 } else {
115 for (int i = 0; i < height; ++i) {
116 memcpy(dataPtr, imagePtr, rowBytes);
117 dataPtr += fBytesPerPixel * fWidth;
118 imagePtr += rowBytes;
119 }
120 }
121}
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
void * dataAt(const AtlasLocator &atlasLocator)
Definition: AtlasTypes.cpp:71
Swizzle_8888_u32 RGBA_to_BGRA

◆ dataAt()

void * skgpu::Plot::dataAt ( const AtlasLocator atlasLocator)

Definition at line 71 of file AtlasTypes.cpp.

71 {
72 if (!fData) {
73 fData = reinterpret_cast<unsigned char*>(
74 sk_calloc_throw(fBytesPerPixel * fWidth * fHeight));
75 }
76 // point ourselves at the right starting spot
77 unsigned char* dataPtr = fData;
78 SkIPoint topLeft = atlasLocator.topLeft();
79 // Assert if we're not accessing the correct Plot
80 SkASSERT(topLeft.fX >= fOffset.fX && topLeft.fX < fOffset.fX + fWidth &&
81 topLeft.fY >= fOffset.fY && topLeft.fY < fOffset.fY + fHeight);
82 topLeft -= SkIPoint::Make(fOffset.fX, fOffset.fY);
83 dataPtr += fBytesPerPixel * fWidth * topLeft.fY;
84 dataPtr += fBytesPerPixel * topLeft.fX;
85
86 return dataPtr;
87}
static void * sk_calloc_throw(size_t size)
Definition: SkMalloc.h:71
SkIPoint topLeft() const
Definition: AtlasTypes.h:309
int16_t fY
y-axis value used by SkIPoint16
Definition: SkIPoint16.h:20
int16_t fX
x-axis value used by SkIPoint16
Definition: SkIPoint16.h:18
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30
static constexpr SkIPoint Make(int32_t x, int32_t y)
Definition: SkPoint_impl.h:38

◆ flushesSinceLastUsed()

int skgpu::Plot::flushesSinceLastUsed ( )
inline

Definition at line 483 of file AtlasTypes.h.

483{ return fFlushesSinceLastUse; }

◆ genID()

uint64_t skgpu::Plot::genID ( ) const
inline

genID() is incremented when the plot is evicted due to a atlas spill. It is used to know if a particular subimage is still present in the atlas.

Definition at line 450 of file AtlasTypes.h.

450{ return fGenID; }

◆ incFlushesSinceLastUsed()

void skgpu::Plot::incFlushesSinceLastUsed ( )
inline

Definition at line 485 of file AtlasTypes.h.

485{ fFlushesSinceLastUse++; }

◆ lastUploadToken()

skgpu::AtlasToken skgpu::Plot::lastUploadToken ( ) const
inline

To manage the lifetime of a plot, we use two tokens. We use the last upload token to know when we can 'piggy back' uploads, i.e. if the last upload hasn't been flushed to the gpu, we don't need to issue a new upload even if we update the cpu backing store. We use lastUse to determine when we can evict a plot from the cache, i.e. if the last use has already flushed through the gpu then we can reuse the plot.

Definition at line 478 of file AtlasTypes.h.

478{ return fLastUpload; }

◆ lastUseToken()

skgpu::AtlasToken skgpu::Plot::lastUseToken ( ) const
inline

Definition at line 479 of file AtlasTypes.h.

479{ return fLastUse; }

◆ markFullIfUsed()

void skgpu::Plot::markFullIfUsed ( )
inline

Definition at line 491 of file AtlasTypes.h.

491{ fIsFull = !fDirtyRect.isEmpty(); }
bool isEmpty() const
Definition: SkRect.h:202

◆ needsUpload()

bool skgpu::Plot::needsUpload ( )
inline

Definition at line 487 of file AtlasTypes.h.

487{ return !fDirtyRect.isEmpty(); }

◆ pageIndex()

uint32_t skgpu::Plot::pageIndex ( ) const
inline

Definition at line 442 of file AtlasTypes.h.

442{ return fPageIndex; }

◆ plotIndex()

uint32_t skgpu::Plot::plotIndex ( ) const
inline

plotIndex() is a unique id for the plot relative to the owning GrAtlas and page.

Definition at line 445 of file AtlasTypes.h.

445{ return fPlotIndex; }

◆ plotLocator()

PlotLocator skgpu::Plot::plotLocator ( ) const
inline

Definition at line 451 of file AtlasTypes.h.

451 {
452 SkASSERT(fPlotLocator.isValid());
453 return fPlotLocator;
454 }
bool isValid() const
Definition: AtlasTypes.h:262

◆ prepareForUpload()

std::pair< const void *, SkIRect > skgpu::Plot::prepareForUpload ( )

Definition at line 132 of file AtlasTypes.cpp.

132 {
133 // We should only be issuing uploads if we are dirty
134 SkASSERT(fDirty);
135 if (!fData) {
136 return {nullptr, {}};
137 }
138 size_t rowBytes = fBytesPerPixel * fWidth;
139 const unsigned char* dataPtr;
140 SkIRect offsetRect;
141 // Clamp to 4-byte aligned boundaries
142 unsigned int clearBits = 0x3 / fBytesPerPixel;
143 fDirtyRect.fLeft &= ~clearBits;
144 fDirtyRect.fRight += clearBits;
145 fDirtyRect.fRight &= ~clearBits;
146 SkASSERT(fDirtyRect.fRight <= fWidth);
147 // Set up dataPtr
148 dataPtr = fData;
149 dataPtr += rowBytes * fDirtyRect.fTop;
150 dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
151 offsetRect = fDirtyRect.makeOffset(fOffset.fX, fOffset.fY);
152
153 fDirtyRect.setEmpty();
154 fIsFull = false;
155 SkDEBUGCODE(fDirty = false);
156
157 return { dataPtr, offsetRect };
158}
SkDEBUGCODE(size_t bpp() const { return fBytesPerPixel;}) bool addRect(int width
Definition: SkRect.h:32
int32_t fTop
smaller y-axis bounds
Definition: SkRect.h:34
constexpr SkIRect makeOffset(int32_t dx, int32_t dy) const
Definition: SkRect.h:300
int32_t fLeft
smaller x-axis bounds
Definition: SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition: SkRect.h:35

◆ prepForRender()

SkIPoint skgpu::Plot::prepForRender ( const AtlasLocator al,
SkAutoPixmapStorage pixmap 
)

Definition at line 89 of file AtlasTypes.cpp.

89 {
90 if (!fData) {
91 fData = reinterpret_cast<unsigned char*>(
92 sk_calloc_throw(fBytesPerPixel * fWidth * fHeight));
93 }
94 pixmap->reset(SkImageInfo::Make(fWidth, fHeight, fColorType, kOpaque_SkAlphaType),
95 fData, fBytesPerPixel * fWidth);
96 return al.topLeft() - SkIPoint::Make(fOffset.fX, fOffset.fY);
97}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ resetFlushesSinceLastUsed()

void skgpu::Plot::resetFlushesSinceLastUsed ( )
inline

Definition at line 484 of file AtlasTypes.h.

484{ fFlushesSinceLastUse = 0; }

◆ resetRects()

void skgpu::Plot::resetRects ( )

Definition at line 160 of file AtlasTypes.cpp.

160 {
161 fRectanizer.reset();
162 fGenID = fGenerationCounter->next();
163 fPlotLocator = PlotLocator(fPageIndex, fPlotIndex, fGenID);
164 fLastUpload = AtlasToken::InvalidToken();
165 fLastUse = AtlasToken::InvalidToken();
166
167 // zero out the plot
168 if (fData) {
169 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight);
170 }
171
172 fDirtyRect.setEmpty();
173 fIsFull = false;
174 SkDEBUGCODE(fDirty = false;)
175}
sk_bzero(glyphs, sizeof(glyphs))
skgpu::PlotLocator PlotLocator

◆ setLastUploadToken()

void skgpu::Plot::setLastUploadToken ( skgpu::AtlasToken  token)
inline

Definition at line 480 of file AtlasTypes.h.

480{ fLastUpload = token; }

◆ setLastUseToken()

void skgpu::Plot::setLastUseToken ( skgpu::AtlasToken  token)
inline

Definition at line 481 of file AtlasTypes.h.

481{ fLastUse = token; }

◆ SkDEBUGCODE()

skgpu::Plot::SkDEBUGCODE ( size_t bpp() const { return fBytesPerPixel;}  )

To add data to the Plot, first call addRect to see if it's possible. If successful, use the atlasLocator to get a pointer to the location in the atlas via dataAt() and render to that location, or if you already have data use copySubImage().

Member Data Documentation

◆ atlasLocator

int AtlasLocator* skgpu::Plot::atlasLocator

Definition at line 462 of file AtlasTypes.h.

◆ fPageIndex

const uint32_t skgpu::Plot::fPageIndex

Definition at line 518 of file AtlasTypes.h.

◆ fPlotIndex

const uint32_t skgpu::Plot::fPlotIndex

Definition at line 519 of file AtlasTypes.h.

◆ height

int skgpu::Plot::height

Definition at line 462 of file AtlasTypes.h.


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