Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
skgpu::graphite::ComputePathAtlas Class Referenceabstract

#include <ComputePathAtlas.h>

Inheritance diagram for skgpu::graphite::ComputePathAtlas:
skgpu::graphite::PathAtlas

Public Member Functions

virtual bool recordDispatches (Recorder *, ComputeTask::DispatchGroupList *) const =0
 
void reset ()
 
- Public Member Functions inherited from skgpu::graphite::PathAtlas
 PathAtlas (Recorder *recorder, uint32_t requestedWidth, uint32_t requestedHeight)
 
virtual ~PathAtlas ()
 
std::pair< const Renderer *, std::optional< MaskAndOrigin > > addShape (const Rect &transformedShapeBounds, const Shape &shape, const Transform &localToDevice, const SkStrokeRec &style)
 
virtual bool isSuitableForAtlasing (const Rect &transformedShapeBounds, const Rect &clipBounds) const
 
uint32_t width () const
 
uint32_t height () const
 

Static Public Member Functions

static std::unique_ptr< ComputePathAtlasCreateDefault (Recorder *)
 

Protected Member Functions

 ComputePathAtlas (Recorder *)
 
const TextureProxytexture () const
 
const TextureProxyaddRect (skvx::half2 maskSize, SkIPoint16 *outPos)
 
bool isSuitableForAtlasing (const Rect &transformedShapeBounds, const Rect &clipBounds) const override
 
virtual void onReset ()=0
 
- Protected Member Functions inherited from skgpu::graphite::PathAtlas
virtual const TextureProxyonAddShape (const Shape &, const Transform &transform, const SkStrokeRec &, skvx::half2 maskSize, skvx::half2 *outPos)=0
 

Additional Inherited Members

- Public Types inherited from skgpu::graphite::PathAtlas
using MaskAndOrigin = std::pair< CoverageMaskShape, SkIPoint >
 
- Static Public Attributes inherited from skgpu::graphite::PathAtlas
static constexpr int kEntryPadding = 1
 
- Protected Attributes inherited from skgpu::graphite::PathAtlas
RecorderfRecorder
 
uint32_t fWidth = 0
 
uint32_t fHeight = 0
 

Detailed Description

Base class for PathAtlas implementations that rasterize coverage masks on the GPU using compute shaders.

When a new shape gets added, it gets tracked as input to a series of GPU compute passes. This data is recorded by recordDispatches() into a DispatchGroup which can be added to a ComputeTask.

After a successful call to recordDispatches(), the client is free to call reset() and start adding new shapes for a future atlas render.

Definition at line 42 of file ComputePathAtlas.h.

Constructor & Destructor Documentation

◆ ComputePathAtlas()

skgpu::graphite::ComputePathAtlas::ComputePathAtlas ( Recorder recorder)
explicitprotected

Definition at line 44 of file ComputePathAtlas.cpp.

45 : PathAtlas(recorder, kComputeAtlasDim, kComputeAtlasDim)
46 , fRectanizer(this->width(), this->height()) {}
uint32_t height() const
Definition: PathAtlas.h:109
PathAtlas(Recorder *recorder, uint32_t requestedWidth, uint32_t requestedHeight)
Definition: PathAtlas.cpp:26
uint32_t width() const
Definition: PathAtlas.h:108

Member Function Documentation

◆ addRect()

const TextureProxy * skgpu::graphite::ComputePathAtlas::addRect ( skvx::half2  maskSize,
SkIPoint16 outPos 
)
protected

Definition at line 89 of file ComputePathAtlas.cpp.

90 {
91 if (!this->initializeTextureIfNeeded()) {
92 SKGPU_LOG_E("Failed to instantiate an atlas texture");
93 return nullptr;
94 }
95
96 // An empty mask always fits, so just return the texture.
97 // TODO: This may not be needed if we can handle clipped out bounds with inverse fills
98 // another way. See PathAtlas::addShape().
99 if (!all(maskSize)) {
100 *outPos = {0, 0};
101 return fTexture.get();
102 }
103
104 if (!fRectanizer.addPaddedRect(maskSize.x(), maskSize.y(), kEntryPadding, outPos)) {
105 return nullptr;
106 }
107
108 return fTexture.get();
109}
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
bool addPaddedRect(int width, int height, int16_t padding, SkIPoint16 *loc)
Definition: Rectanizer.h:34
static constexpr int kEntryPadding
Definition: PathAtlas.h:55
SIT bool all(const Vec< 1, T > &x)
Definition: SkVx.h:582

◆ CreateDefault()

std::unique_ptr< ComputePathAtlas > skgpu::graphite::ComputePathAtlas::CreateDefault ( Recorder recorder)
static

Definition at line 417 of file ComputePathAtlas.cpp.

417 {
418#ifdef SK_ENABLE_VELLO_SHADERS
419 return std::make_unique<VelloComputePathAtlas>(recorder);
420#else
421 return nullptr;
422#endif
423}

◆ isSuitableForAtlasing()

bool skgpu::graphite::ComputePathAtlas::isSuitableForAtlasing ( const Rect transformedShapeBounds,
const Rect clipBounds 
) const
overrideprotectedvirtual

Returns true if a path coverage mask with the given device-space bounds is sufficiently small to benefit from atlasing without causing too many atlas renders.

transformedShapeBounds represents the device-space bounds of the coverage mask shape unrestricted by clip and viewport bounds.

clipBounds represents the conservative bounding box of the union of the clip stack that should apply to the shape.

Reimplemented from skgpu::graphite::PathAtlas.

Definition at line 61 of file ComputePathAtlas.cpp.

62 {
63 Rect shapeBounds = transformedShapeBounds.makeRoundOut();
64 Rect maskBounds = shapeBounds.makeIntersect(clipBounds);
65 skvx::float2 maskSize = maskBounds.size();
66 float width = maskSize.x(), height = maskSize.y();
67
68 if (width > this->width() || height > this->height()) {
69 return false;
70 }
71
72 // For now we're allowing paths that are smaller than 1/32nd of the full 4096x4096 atlas size
73 // to prevent the atlas texture from filling up too often. There are several approaches we
74 // should explore to alleviate the cost of atlasing large paths.
75 if (width * height > kBboxAreaThreshold) {
76 return false;
77 }
78
79 // Reject pathological shapes that vello can't handle efficiently yet.
80 skvx::float2 unclippedSize = shapeBounds.size();
81 if (std::fabs(unclippedSize.x()) > kCoordinateThreshold ||
82 std::fabs(unclippedSize.y()) > kCoordinateThreshold) {
83 return false;
84 }
85
86 return true;
87}
TRect< Scalar > Rect
Definition: rect.h:769
Definition: SkVx.h:83

◆ onReset()

virtual void skgpu::graphite::ComputePathAtlas::onReset ( )
protectedpure virtual

◆ recordDispatches()

virtual bool skgpu::graphite::ComputePathAtlas::recordDispatches ( Recorder ,
ComputeTask::DispatchGroupList  
) const
pure virtual

◆ reset()

void skgpu::graphite::ComputePathAtlas::reset ( )

Definition at line 111 of file ComputePathAtlas.cpp.

111 {
112 fRectanizer.reset();
113
114 this->onReset();
115}

◆ texture()

const TextureProxy * skgpu::graphite::ComputePathAtlas::texture ( ) const
inlineprotected

Definition at line 58 of file ComputePathAtlas.h.

58{ return fTexture.get(); }

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