Flutter Engine
The Flutter Engine
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
 
virtual void evict (PlotLocator)=0
 

Protected Member Functions

 DrawAtlasMgr (size_t width, size_t height, size_t plotWidth, size_t plotHeight, DrawAtlas::UseStorageTextures useStorageTextures, 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 122 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,
DrawAtlas::UseStorageTextures  useStorageTextures,
std::string_view  label,
const Caps caps 
)
protected

Definition at line 76 of file PathAtlas.cpp.

80 {
82
86 plotWidth, plotHeight,
87 /*generationCounter=*/this,
88 caps->allowMultipleAtlasTextures() ?
91 useStorageTextures,
92 /*evictor=*/this,
93 label);
95 fKeyLists.resize(fDrawAtlas->numPlots() * fDrawAtlas->maxPages());
96 for (int i = 0; i < fKeyLists.size(); ++i) {
97 fKeyLists[i].reset();
98 }
99}
#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)
Definition: SkImageInfo.cpp:16
static std::unique_ptr< DrawAtlas > Make(SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, UseStorageTextures useStorageTextures, PlotEvictionCallback *evictor, std::string_view label)
Definition: DrawAtlas.cpp:52
std::unique_ptr< DrawAtlas > fDrawAtlas
Definition: PathAtlas.h:154
uint32_t height() const
Definition: PathAtlas.h:109
uint32_t width() const
Definition: PathAtlas.h:108

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 142 of file PathAtlas.cpp.

148 {
149 // Render mask.
150 SkIRect iShapeBounds = SkIRect::MakeXYWH(0, 0, maskSize.x(), maskSize.y());
151 // Outset to take padding into account
152 SkIRect iAtlasBounds = iShapeBounds.makeOutset(kEntryPadding, kEntryPadding);
153
154 // Request space in DrawAtlas.
155 DrawAtlas::ErrorCode errorCode = fDrawAtlas->addRect(recorder,
156 iAtlasBounds.width(),
157 iAtlasBounds.height(),
158 locator);
159 if (errorCode != DrawAtlas::ErrorCode::kSucceeded) {
160 return nullptr;
161 }
162 SkIPoint topLeft = locator->topLeft();
163 *outPos = skvx::half2(topLeft.x()+kEntryPadding, topLeft.y()+kEntryPadding);
164
165 // If the mask is empty, just return.
166 // TODO: this may not be needed if we can handle clipped out bounds with inverse fills
167 // another way. See PathAtlas::addShape().
168 if (!all(maskSize)) {
169 fDrawAtlas->setLastUseToken(*locator,
170 recorder->priv().tokenTracker()->nextFlushToken());
171 return fDrawAtlas->getProxies()[locator->pageIndex()].get();
172 }
173
174 if (!this->onAddToAtlas(shape, transform, strokeRec, iShapeBounds, *locator)) {
175 return nullptr;
176 }
177
178 fDrawAtlas->setLastUseToken(*locator,
179 recorder->priv().tokenTracker()->nextFlushToken());
180
181 return fDrawAtlas->getProxies()[locator->pageIndex()].get();
182}
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:55
TokenTracker * tokenTracker()
Definition: RecorderPriv.h:62
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
Definition: SkPoint_impl.h:52
constexpr int32_t x() const
Definition: SkPoint_impl.h:46
Definition: SkRect.h:32
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 188 of file PathAtlas.cpp.

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

◆ 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 107 of file PathAtlas.cpp.

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

202 {
203 fDrawAtlas->compact(recorder->priv().tokenTracker()->nextFlushToken());
204}

◆ recordUploads()

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

Definition at line 184 of file PathAtlas.cpp.

184 {
185 return fDrawAtlas->recordUploads(dc, recorder);
186}

Member Data Documentation

◆ fDrawAtlas

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

Definition at line 154 of file PathAtlas.h.


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