Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
GrDynamicAtlas Class Reference

#include <GrDynamicAtlas.h>

Classes

class  Node
 

Public Types

enum class  InternalMultisample : bool { kNo = false , kYes = true }
 
enum class  RectanizerAlgorithm { kSkyline , kPow2 }
 
using LazyAtlasDesc = GrSurfaceProxy::LazySurfaceDesc
 
using LazyInstantiateAtlasCallback = GrSurfaceProxy::LazyInstantiateCallback
 

Public Member Functions

 GrDynamicAtlas (GrColorType colorType, InternalMultisample, SkISize initialSize, int maxAtlasSize, const GrCaps &, RectanizerAlgorithm=RectanizerAlgorithm::kSkyline)
 
virtual ~GrDynamicAtlas ()
 
void reset (SkISize initialSize, const GrCaps &desc)
 
GrColorType colorType () const
 
int maxAtlasSize () const
 
GrTextureProxytextureProxy () const
 
GrSurfaceProxyView readView (const GrCaps &) const
 
GrSurfaceProxyView writeView (const GrCaps &) const
 
bool isInstantiated () const
 
bool addRect (int width, int height, SkIPoint16 *location)
 
const SkISizedrawBounds ()
 
bool instantiate (GrOnFlushResourceProvider *, sk_sp< GrTexture > backingTexture=nullptr)
 

Static Public Member Functions

static sk_sp< GrTextureProxyMakeLazyAtlasProxy (LazyInstantiateAtlasCallback &&, GrColorType colorType, InternalMultisample, const GrCaps &, GrSurfaceProxy::UseAllocator)
 

Static Public Attributes

static constexpr GrSurfaceOrigin kTextureOrigin = kTopLeft_GrSurfaceOrigin
 
static constexpr int kPadding = 1
 

Detailed Description

This class implements a dynamic size skgpu::Rectanizer that grows until it reaches the implementation-dependent max texture size. When finalized, it also creates and stores a GrTextureProxy for the underlying atlas.

Definition at line 25 of file GrDynamicAtlas.h.

Member Typedef Documentation

◆ LazyAtlasDesc

Definition at line 32 of file GrDynamicAtlas.h.

◆ LazyInstantiateAtlasCallback

Definition at line 33 of file GrDynamicAtlas.h.

Member Enumeration Documentation

◆ InternalMultisample

enum class GrDynamicAtlas::InternalMultisample : bool
strong
Enumerator
kNo 
kYes 

Definition at line 35 of file GrDynamicAtlas.h.

◆ RectanizerAlgorithm

Enumerator
kSkyline 
kPow2 

Definition at line 46 of file GrDynamicAtlas.h.

Constructor & Destructor Documentation

◆ GrDynamicAtlas()

GrDynamicAtlas::GrDynamicAtlas ( GrColorType  colorType,
InternalMultisample  internalMultisample,
SkISize  initialSize,
int  maxAtlasSize,
const GrCaps caps,
RectanizerAlgorithm  algorithm = RectanizerAlgorithm::kSkyline 
)

Definition at line 77 of file GrDynamicAtlas.cpp.

80 : fColorType(colorType)
81 , fInternalMultisample(internalMultisample)
82 , fMaxAtlasSize(maxAtlasSize)
83 , fRectanizerAlgorithm(algorithm) {
84 SkASSERT(fMaxAtlasSize <= caps.maxTextureSize());
85 this->reset(initialSize, caps);
86}
m reset()
#define SkASSERT(cond)
Definition SkAssert.h:116
int maxTextureSize() const
Definition GrCaps.h:229
GrColorType colorType() const
int maxAtlasSize() const

◆ ~GrDynamicAtlas()

GrDynamicAtlas::~GrDynamicAtlas ( )
virtual

Definition at line 88 of file GrDynamicAtlas.cpp.

88 {
89}

Member Function Documentation

◆ addRect()

bool GrDynamicAtlas::addRect ( int  width,
int  height,
SkIPoint16 location 
)

Definition at line 136 of file GrDynamicAtlas.cpp.

136 {
137 // This can't be called anymore once instantiate() has been called.
138 SkASSERT(!this->isInstantiated());
139
140 if (!this->internalPlaceRect(width, height, location)) {
141 return false;
142 }
143
144 fDrawBounds.fWidth = std::max(fDrawBounds.width(), location->x() + width);
145 fDrawBounds.fHeight = std::max(fDrawBounds.height(), location->y() + height);
146 return true;
147}
bool isInstantiated() const
int32_t height
int32_t width
int16_t y() const
Definition SkIPoint16.h:43
int16_t x() const
Definition SkIPoint16.h:37
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37

◆ colorType()

GrColorType GrDynamicAtlas::colorType ( ) const
inline

Definition at line 58 of file GrDynamicAtlas.h.

58{ return fColorType; }

◆ drawBounds()

const SkISize & GrDynamicAtlas::drawBounds ( )
inline

Definition at line 68 of file GrDynamicAtlas.h.

68{ return fDrawBounds; }

◆ instantiate()

bool GrDynamicAtlas::instantiate ( GrOnFlushResourceProvider onFlushRP,
sk_sp< GrTexture backingTexture = nullptr 
)

Definition at line 193 of file GrDynamicAtlas.cpp.

194 {
195 SkASSERT(!this->isInstantiated()); // This method should only be called once.
196 // Caller should have cropped any paths to the destination render target instead of asking for
197 // an atlas larger than maxRenderTargetSize.
198 SkASSERT(std::max(fHeight, fWidth) <= fMaxAtlasSize);
199 SkASSERT(fMaxAtlasSize <= onFlushRP->caps()->maxRenderTargetSize());
200
201 if (fTextureProxy->isFullyLazy()) {
202 // Finalize the content size of our proxy. The GPU can potentially make optimizations if it
203 // knows we only intend to write out a smaller sub-rectangle of the backing texture.
204 fTextureProxy->priv().setLazyDimensions(fDrawBounds);
205 }
206 SkASSERT(fTextureProxy->dimensions() == fDrawBounds);
207
208 if (backingTexture) {
209#ifdef SK_DEBUG
210 auto backingRT = backingTexture->asRenderTarget();
211 SkASSERT(backingRT);
212 SkASSERT(backingRT->backendFormat() == fTextureProxy->backendFormat());
213 SkASSERT(backingRT->numSamples() == fTextureProxy->asRenderTargetProxy()->numSamples());
214 SkASSERT(backingRT->dimensions() == fTextureProxy->backingStoreDimensions());
215#endif
216 // This works bc 'fTextureProxy' is a lazy proxy and, in its LazyInstantiateAtlasCallback,
217 // it will just wrap 'fBackingTexture' if it is non-null.
218 fBackingTexture = std::move(backingTexture);
219 }
220 return onFlushRP->instantiateProxy(fTextureProxy.get());
221}
bool instantiateProxy(GrSurfaceProxy *)
void setLazyDimensions(SkISize dimensions)
SkISize backingStoreDimensions() const
virtual GrRenderTargetProxy * asRenderTargetProxy()
const GrBackendFormat & backendFormat() const
GrSurfaceProxyPriv priv()
bool isFullyLazy() const
SkISize dimensions() const
virtual GrRenderTarget * asRenderTarget()
Definition GrSurface.h:65
T * get() const
Definition SkRefCnt.h:303

◆ isInstantiated()

bool GrDynamicAtlas::isInstantiated ( ) const
inline

Definition at line 63 of file GrDynamicAtlas.h.

63{ return fTextureProxy->isInstantiated(); }
bool isInstantiated() const

◆ MakeLazyAtlasProxy()

sk_sp< GrTextureProxy > GrDynamicAtlas::MakeLazyAtlasProxy ( LazyInstantiateAtlasCallback &&  callback,
GrColorType  colorType,
InternalMultisample  internalMultisample,
const GrCaps caps,
GrSurfaceProxy::UseAllocator  useAllocator 
)
static

Definition at line 57 of file GrDynamicAtlas.cpp.

62 {
63 GrBackendFormat format = caps.getDefaultBackendFormat(colorType, GrRenderable::kYes);
64
65 int sampleCount = 1;
66 if (InternalMultisample::kYes == internalMultisample) {
67 sampleCount = caps.internalMultisampleCount(format);
68 }
69
71 GrProxyProvider::MakeFullyLazyProxy(std::move(callback), format, GrRenderable::kYes,
72 sampleCount, GrProtected::kNo, caps, useAllocator);
73
74 return proxy;
75}
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
int internalMultisampleCount(const GrBackendFormat &format) const
Definition GrCaps.h:271
static sk_sp< GrTextureProxy > MakeFullyLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint32_t uint32_t * format

◆ maxAtlasSize()

int GrDynamicAtlas::maxAtlasSize ( ) const
inline

Definition at line 59 of file GrDynamicAtlas.h.

59{ return fMaxAtlasSize; }

◆ readView()

GrSurfaceProxyView GrDynamicAtlas::readView ( const GrCaps caps) const

Definition at line 126 of file GrDynamicAtlas.cpp.

126 {
127 return {fTextureProxy, kTextureOrigin,
128 caps.getReadSwizzle(fTextureProxy->backendFormat(), fColorType)};
129}
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
static constexpr GrSurfaceOrigin kTextureOrigin

◆ reset()

void GrDynamicAtlas::reset ( SkISize  initialSize,
const GrCaps desc 
)

Definition at line 91 of file GrDynamicAtlas.cpp.

91 {
92 fNodeAllocator.reset();
93 fWidth = std::min(SkNextPow2(initialSize.width()), fMaxAtlasSize);
94 fHeight = std::min(SkNextPow2(initialSize.height()), fMaxAtlasSize);
95 fTopNode = nullptr;
96 fDrawBounds.setEmpty();
97 fTextureProxy = MakeLazyAtlasProxy(
98 [this](GrResourceProvider* resourceProvider, const LazyAtlasDesc& desc) {
99 if (!fBackingTexture) {
100 fBackingTexture =
101 resourceProvider->createTexture(fTextureProxy->backingStoreDimensions(),
102 desc.fFormat,
103 desc.fTextureType,
104 desc.fRenderable,
105 desc.fSampleCnt,
106 desc.fMipmapped,
107 desc.fBudgeted,
108 desc.fProtected,
109 desc.fLabel);
110 }
111 return GrSurfaceProxy::LazyCallbackResult(fBackingTexture);
112 },
113 fColorType, fInternalMultisample, caps, GrSurfaceProxy::UseAllocator::kNo);
114 fBackingTexture = nullptr;
115}
static int SkNextPow2(int value)
Definition SkMathPriv.h:272
static sk_sp< GrTextureProxy > MakeLazyAtlasProxy(LazyInstantiateAtlasCallback &&, GrColorType colorType, InternalMultisample, const GrCaps &, GrSurfaceProxy::UseAllocator)
GrSurfaceProxy::LazySurfaceDesc LazyAtlasDesc
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
void setEmpty()
Definition SkSize.h:34

◆ textureProxy()

GrTextureProxy * GrDynamicAtlas::textureProxy ( ) const
inline

Definition at line 60 of file GrDynamicAtlas.h.

60{ return fTextureProxy.get(); }

◆ writeView()

GrSurfaceProxyView GrDynamicAtlas::writeView ( const GrCaps caps) const

Definition at line 131 of file GrDynamicAtlas.cpp.

131 {
132 return {fTextureProxy, kTextureOrigin,
133 caps.getWriteSwizzle(fTextureProxy->backendFormat(), fColorType)};
134}
virtual skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const =0

Member Data Documentation

◆ kPadding

constexpr int GrDynamicAtlas::kPadding = 1
inlinestaticconstexpr

Definition at line 29 of file GrDynamicAtlas.h.

◆ kTextureOrigin

constexpr GrSurfaceOrigin GrDynamicAtlas::kTextureOrigin = kTopLeft_GrSurfaceOrigin
inlinestaticconstexpr

Definition at line 28 of file GrDynamicAtlas.h.


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