Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Private Member Functions | 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 ()
 
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
 

Private Member Functions

 ~Plot () override
 

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#ifdef SK_DEBUG
38 , fDirty(false)
39#endif
40{
41 // We expect the allocated dimensions to be a multiple of 4 bytes
42 SkASSERT(((width*fBytesPerPixel) & 0x3) == 0);
43 // The padding for faster uploads only works for 1, 2 and 4 byte texels
44 SkASSERT(fBytesPerPixel != 3 && fBytesPerPixel <= 4);
45 fDirtyRect.setEmpty();
46}
#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:516
uint32_t pageIndex() const
Definition AtlasTypes.h:442
const uint32_t fPlotIndex
Definition AtlasTypes.h:517
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 122 of file AtlasTypes.cpp.

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

◆ 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 495 of file AtlasTypes.h.

495 {
496 return sk_sp<Plot>(new Plot(
497 fPageIndex, fPlotIndex, fGenerationCounter, fX, fY, fWidth, fHeight, fColorType,
498 fBytesPerPixel));
499 }

◆ copySubImage()

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

Definition at line 98 of file AtlasTypes.cpp.

98 {
99 const unsigned char* imagePtr = (const unsigned char*)image;
100 unsigned char* dataPtr = (unsigned char*)this->dataAt(al);
101 int width = al.width();
102 int height = al.height();
103 size_t rowBytes = width * fBytesPerPixel;
104
105 // copy into the data buffer, swizzling as we go if this is ARGB data
106 constexpr bool kBGRAIsNative = kN32_SkColorType == kBGRA_8888_SkColorType;
107 if (4 == fBytesPerPixel && kBGRAIsNative) {
108 for (int i = 0; i < height; ++i) {
109 SkOpts::RGBA_to_BGRA((uint32_t*)dataPtr, (const uint32_t*)imagePtr, width);
110 dataPtr += fBytesPerPixel * fWidth;
111 imagePtr += rowBytes;
112 }
113 } else {
114 for (int i = 0; i < height; ++i) {
115 memcpy(dataPtr, imagePtr, rowBytes);
116 dataPtr += fBytesPerPixel * fWidth;
117 imagePtr += rowBytes;
118 }
119 }
120}
@ 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)
Swizzle_8888_u32 RGBA_to_BGRA

◆ dataAt()

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

Definition at line 70 of file AtlasTypes.cpp.

70 {
71 if (!fData) {
72 fData = reinterpret_cast<unsigned char*>(
73 sk_calloc_throw(fBytesPerPixel * fWidth * fHeight));
74 }
75 // point ourselves at the right starting spot
76 unsigned char* dataPtr = fData;
77 SkIPoint topLeft = atlasLocator.topLeft();
78 // Assert if we're not accessing the correct Plot
79 SkASSERT(topLeft.fX >= fOffset.fX && topLeft.fX < fOffset.fX + fWidth &&
80 topLeft.fY >= fOffset.fY && topLeft.fY < fOffset.fY + fHeight);
81 topLeft -= SkIPoint::Make(fOffset.fX, fOffset.fY);
82 dataPtr += fBytesPerPixel * fWidth * topLeft.fY;
83 dataPtr += fBytesPerPixel * topLeft.fX;
84
85 return dataPtr;
86}
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
int32_t fY
y-axis value
static constexpr SkIPoint Make(int32_t x, int32_t y)

◆ 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; }

◆ needsUpload()

bool skgpu::Plot::needsUpload ( )
inline

Definition at line 487 of file AtlasTypes.h.

487{ return !fDirtyRect.isEmpty(); }
bool isEmpty() const
Definition SkRect.h:202

◆ 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 131 of file AtlasTypes.cpp.

131 {
132 // We should only be issuing uploads if we are dirty
133 SkASSERT(fDirty);
134 if (!fData) {
135 return {nullptr, {}};
136 }
137 size_t rowBytes = fBytesPerPixel * fWidth;
138 const unsigned char* dataPtr;
139 SkIRect offsetRect;
140 // Clamp to 4-byte aligned boundaries
141 unsigned int clearBits = 0x3 / fBytesPerPixel;
142 fDirtyRect.fLeft &= ~clearBits;
143 fDirtyRect.fRight += clearBits;
144 fDirtyRect.fRight &= ~clearBits;
145 SkASSERT(fDirtyRect.fRight <= fWidth);
146 // Set up dataPtr
147 dataPtr = fData;
148 dataPtr += rowBytes * fDirtyRect.fTop;
149 dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
150 offsetRect = fDirtyRect.makeOffset(fOffset.fX, fOffset.fY);
151
152 fDirtyRect.setEmpty();
153 SkDEBUGCODE(fDirty = false);
154
155 return { dataPtr, offsetRect };
156}
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
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 88 of file AtlasTypes.cpp.

88 {
89 if (!fData) {
90 fData = reinterpret_cast<unsigned char*>(
91 sk_calloc_throw(fBytesPerPixel * fWidth * fHeight));
92 }
93 pixmap->reset(SkImageInfo::Make(fWidth, fHeight, fColorType, kOpaque_SkAlphaType),
94 fData, fBytesPerPixel * fWidth);
95 return al.topLeft() - SkIPoint::Make(fOffset.fX, fOffset.fY);
96}
@ 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 158 of file AtlasTypes.cpp.

158 {
159 fRectanizer.reset();
160 fGenID = fGenerationCounter->next();
161 fPlotLocator = PlotLocator(fPageIndex, fPlotIndex, fGenID);
162 fLastUpload = AtlasToken::InvalidToken();
163 fLastUse = AtlasToken::InvalidToken();
164
165 // zero out the plot
166 if (fData) {
167 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight);
168 }
169
170 fDirtyRect.setEmpty();
171 SkDEBUGCODE(fDirty = false;)
172}
static void sk_bzero(void *buffer, size_t size)
Definition SkMalloc.h:105

◆ 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().

◆ ~Plot()

skgpu::Plot::~Plot ( )
overrideprivate

Definition at line 48 of file AtlasTypes.cpp.

48 {
49 sk_free(fData);
50}
SK_API void sk_free(void *)

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 516 of file AtlasTypes.h.

◆ fPlotIndex

const uint32_t skgpu::Plot::fPlotIndex

Definition at line 517 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: