Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
skgpu::graphite::PathAtlas::DrawAtlasMgr Class Referenceabstract

#include <PathAtlas.h>

Inheritance diagram for skgpu::graphite::PathAtlas::DrawAtlasMgr:
skgpu::AtlasGenerationCounter skgpu::PlotEvictionCallback

Public Member Functions

const TextureProxyfindOrCreateEntry (Recorder *recorder, const Shape &shape, const Transform &transform, const SkStrokeRec &strokeRec, skvx::half2 maskSize, skvx::half2 *outPos)
 
const TextureProxyaddToAtlas (Recorder *recorder, const Shape &shape, const Transform &transform, const SkStrokeRec &strokeRec, skvx::half2 maskSize, skvx::half2 *outPos, AtlasLocator *locator)
 
bool recordUploads (DrawContext *, Recorder *)
 
void evict (PlotLocator) override
 
void postFlush (Recorder *)
 
- Public Member Functions inherited from skgpu::AtlasGenerationCounter
uint64_t next ()
 
- Public Member Functions inherited from skgpu::PlotEvictionCallback
virtual ~PlotEvictionCallback ()=default
 

Protected Member Functions

 DrawAtlasMgr (size_t width, size_t height, size_t plotWidth, size_t plotHeight, std::string_view label, const Caps *)
 
virtual bool onAddToAtlas (const Shape &, const Transform &transform, const SkStrokeRec &, SkIRect shapeBounds, const AtlasLocator &)=0
 

Protected Attributes

std::unique_ptr< DrawAtlasfDrawAtlas
 

Additional Inherited Members

- Static Public Attributes inherited from skgpu::AtlasGenerationCounter
static constexpr uint64_t kInvalidGeneration = 0
 

Detailed Description

Definition at line 113 of file PathAtlas.h.

Constructor & Destructor Documentation

◆ DrawAtlasMgr()

skgpu::graphite::PathAtlas::DrawAtlasMgr::DrawAtlasMgr ( size_t  width,
size_t  height,
size_t  plotWidth,
size_t  plotHeight,
std::string_view  label,
const Caps caps 
)
protected

Definition at line 76 of file PathAtlas.cpp.

79 {
81
85 plotWidth, plotHeight,
86 this,
87 caps->allowMultipleAtlasTextures() ?
89 DrawAtlas::AllowMultitexturing::kNo,
90 this,
91 label);
93 fKeyLists.resize(fDrawAtlas->numPlots() * fDrawAtlas->maxPages());
94 for (int i = 0; i < fKeyLists.size(); ++i) {
95 fKeyLists[i].reset();
96 }
97}
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType
Definition SkColorType.h:19
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition SkColorType.h:21
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
static std::unique_ptr< DrawAtlas > Make(SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, PlotEvictionCallback *evictor, std::string_view label)
Definition DrawAtlas.cpp:52
std::unique_ptr< DrawAtlas > fDrawAtlas
Definition PathAtlas.h:144
uint32_t height() const
Definition PathAtlas.h:95
uint32_t width() const
Definition PathAtlas.h:94
skgpu::graphite::DrawAtlas DrawAtlas

Member Function Documentation

◆ addToAtlas()

const TextureProxy * skgpu::graphite::PathAtlas::DrawAtlasMgr::addToAtlas ( Recorder recorder,
const Shape shape,
const Transform transform,
const SkStrokeRec strokeRec,
skvx::half2  maskSize,
skvx::half2 outPos,
AtlasLocator locator 
)

Definition at line 140 of file PathAtlas.cpp.

146 {
147 // Render mask.
148 SkIRect iShapeBounds = SkIRect::MakeXYWH(0, 0, maskSize.x(), maskSize.y());
149 // Outset to take padding into account
150 SkIRect iAtlasBounds = iShapeBounds.makeOutset(kEntryPadding, kEntryPadding);
151
152 // Request space in DrawAtlas.
153 DrawAtlas::ErrorCode errorCode = fDrawAtlas->addRect(recorder,
154 iAtlasBounds.width(),
155 iAtlasBounds.height(),
156 locator);
157 if (errorCode != DrawAtlas::ErrorCode::kSucceeded) {
158 return nullptr;
159 }
160 SkIPoint topLeft = locator->topLeft();
161 *outPos = skvx::half2(topLeft.x()+kEntryPadding, topLeft.y()+kEntryPadding);
162
163 // If the mask is empty, just return.
164 // TODO: this may not be needed if we can handle clipped out bounds with inverse fills
165 // another way. See PathAtlas::addShape().
166 if (!all(maskSize)) {
167 fDrawAtlas->setLastUseToken(*locator,
168 recorder->priv().tokenTracker()->nextFlushToken());
169 return fDrawAtlas->getProxies()[locator->pageIndex()].get();
170 }
171
172 if (!this->onAddToAtlas(shape, transform, strokeRec, iShapeBounds, *locator)) {
173 return nullptr;
174 }
175
176 fDrawAtlas->setLastUseToken(*locator,
177 recorder->priv().tokenTracker()->nextFlushToken());
178
179 return fDrawAtlas->getProxies()[locator->pageIndex()].get();
180}
SkIPoint topLeft() const
Definition AtlasTypes.h:309
uint32_t pageIndex() const
Definition AtlasTypes.h:303
AtlasToken nextFlushToken() const
Definition AtlasTypes.h:207
virtual bool onAddToAtlas(const Shape &, const Transform &transform, const SkStrokeRec &, SkIRect shapeBounds, const AtlasLocator &)=0
static constexpr int kEntryPadding
Definition PathAtlas.h:101
TokenTracker * tokenTracker()
Vec< 2, uint16_t > half2
Definition SkVx.h:1175
SIT bool all(const Vec< 1, T > &x)
Definition SkVx.h:582
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
constexpr int32_t y() const
constexpr int32_t x() const
SkIRect makeOutset(int32_t dx, int32_t dy) const
Definition SkRect.h:350
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104

◆ evict()

void skgpu::graphite::PathAtlas::DrawAtlasMgr::evict ( PlotLocator  plotLocator)
overridevirtual

Implements skgpu::PlotEvictionCallback.

Definition at line 186 of file PathAtlas.cpp.

186 {
187 // Remove all entries for this Plot from the ShapeCache
188 uint32_t index = shape_key_list_index(plotLocator, fDrawAtlas.get());
189 ShapeKeyList::Iter iter;
190 iter.init(fKeyLists[index], ShapeKeyList::Iter::kHead_IterStart);
191 ShapeKeyEntry* currEntry;
192 while ((currEntry = iter.get())) {
193 iter.next();
194 fShapeCache.remove(currEntry->fKey);
195 fKeyLists[index].remove(currEntry);
196 delete currEntry;
197 }
198}
void remove(const K &key)
Definition SkTHash.h:494

◆ findOrCreateEntry()

const TextureProxy * skgpu::graphite::PathAtlas::DrawAtlasMgr::findOrCreateEntry ( Recorder recorder,
const Shape shape,
const Transform transform,
const SkStrokeRec strokeRec,
skvx::half2  maskSize,
skvx::half2 outPos 
)

Definition at line 105 of file PathAtlas.cpp.

110 {
111 // Shapes must have a key to use this method
112 skgpu::UniqueKey maskKey = GeneratePathMaskKey(shape, transform, strokeRec, maskSize);
113 AtlasLocator* cachedLocator = fShapeCache.find(maskKey);
114 if (cachedLocator) {
115 SkIPoint topLeft = cachedLocator->topLeft();
116 *outPos = skvx::half2(topLeft.x() + kEntryPadding, topLeft.y() + kEntryPadding);
117 fDrawAtlas->setLastUseToken(*cachedLocator,
118 recorder->priv().tokenTracker()->nextFlushToken());
119 return fDrawAtlas->getProxies()[cachedLocator->pageIndex()].get();
120 }
121
122 AtlasLocator locator;
123 const TextureProxy* proxy = this->addToAtlas(recorder, shape, transform, strokeRec,
124 maskSize, outPos, &locator);
125 if (!proxy) {
126 return nullptr;
127 }
128
129 // Add locator to ShapeCache.
130 fShapeCache.set(maskKey, locator);
131 // Add key to Plot's ShapeKeyList.
132 uint32_t index = shape_key_list_index(locator.plotLocator(), fDrawAtlas.get());
133 ShapeKeyEntry* keyEntry = new ShapeKeyEntry();
134 keyEntry->fKey = maskKey;
135 fKeyLists[index].addToTail(keyEntry);
136
137 return proxy;
138}
PlotLocator plotLocator() const
Definition AtlasTypes.h:301
const TextureProxy * addToAtlas(Recorder *recorder, const Shape &shape, const Transform &transform, const SkStrokeRec &strokeRec, skvx::half2 maskSize, skvx::half2 *outPos, AtlasLocator *locator)
V * find(const K &key) const
Definition SkTHash.h:479
V * set(K key, V val)
Definition SkTHash.h:472
skgpu::UniqueKey GeneratePathMaskKey(const Shape &shape, const Transform &transform, const SkStrokeRec &strokeRec, skvx::half2 maskSize)

◆ onAddToAtlas()

virtual bool skgpu::graphite::PathAtlas::DrawAtlasMgr::onAddToAtlas ( const Shape ,
const Transform transform,
const SkStrokeRec ,
SkIRect  shapeBounds,
const AtlasLocator  
)
protectedpure virtual

◆ postFlush()

void skgpu::graphite::PathAtlas::DrawAtlasMgr::postFlush ( Recorder recorder)

Definition at line 200 of file PathAtlas.cpp.

200 {
201 fDrawAtlas->compact(recorder->priv().tokenTracker()->nextFlushToken());
202}

◆ recordUploads()

bool skgpu::graphite::PathAtlas::DrawAtlasMgr::recordUploads ( DrawContext dc,
Recorder recorder 
)

Definition at line 182 of file PathAtlas.cpp.

182 {
183 return fDrawAtlas->recordUploads(dc, recorder);
184}

Member Data Documentation

◆ fDrawAtlas

std::unique_ptr<DrawAtlas> skgpu::graphite::PathAtlas::DrawAtlasMgr::fDrawAtlas
protected

Definition at line 144 of file PathAtlas.h.


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