Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skgpu::graphite::UniformManager Class Reference

#include <UniformManager.h>

Public Member Functions

 UniformManager (Layout layout)
 
UniformDataBlock finishUniformDataBlock ()
 
size_t size () const
 
void resetWithNewLayout (Layout layout)
 
void reset ()
 
void write (float f)
 
void write (int32_t i)
 
void writeHalf (float f)
 
void write (const SkPMColor4f &c)
 
void write (const SkRect &r)
 
void write (const SkV4 &v)
 
void write (const SkIRect &r)
 
void writeHalf (const SkPMColor4f &c)
 
void writeHalf (const SkRect &r)
 
void writeHalf (const SkV4 &v)
 
void writeArray (SkSpan< const SkV4 > v)
 
void writeArray (SkSpan< const SkPMColor4f > c)
 
void writeHalfArray (SkSpan< const SkPMColor4f > c)
 
void write (const SkV3 &v)
 
void write (const SkPoint3 &p)
 
void writeHalf (const SkV3 &v)
 
void writeHalf (const SkPoint3 &p)
 
void write (const SkV2 &v)
 
void write (const SkSize &s)
 
void write (const SkPoint &p)
 
void write (const SkISize &s)
 
void writeHalf (const SkV2 &v)
 
void writeHalf (const SkSize &s)
 
void writeHalf (const SkPoint &p)
 
void write (const SkM44 &m)
 
void writeHalf (const SkM44 &m)
 
void write (const SkMatrix &m)
 
void writeHalf (const SkMatrix &m)
 
void writePaintColor (const SkPMColor4f &color)
 
void write (const Uniform &, const void *src)
 

Detailed Description

Definition at line 198 of file UniformManager.h.

Constructor & Destructor Documentation

◆ UniformManager()

skgpu::graphite::UniformManager::UniformManager ( Layout  layout)
inline

Definition at line 200 of file UniformManager.h.

200{ this->resetWithNewLayout(layout); }
void resetWithNewLayout(Layout layout)

Member Function Documentation

◆ finishUniformDataBlock()

UniformDataBlock skgpu::graphite::UniformManager::finishUniformDataBlock ( )

Definition at line 51 of file UniformManager.cpp.

51 {
52 size_t size = SkAlignTo(fStorage.size(), fReqAlignment);
53 size_t paddingSize = size - fStorage.size();
54 if (paddingSize > 0) {
55 char* padding = fStorage.append(paddingSize);
56 memset(padding, 0, paddingSize);
57 }
58 return UniformDataBlock(SkSpan(fStorage.begin(), size));
59}
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
int size() const
Definition: SkTDArray.h:138
T * begin()
Definition: SkTDArray.h:150
T * append()
Definition: SkTDArray.h:191

◆ reset()

void skgpu::graphite::UniformManager::reset ( )
inline

Definition at line 206 of file UniformManager.h.

206{ this->resetWithNewLayout(fLayout); }

◆ resetWithNewLayout()

void skgpu::graphite::UniformManager::resetWithNewLayout ( Layout  layout)

Definition at line 61 of file UniformManager.cpp.

61 {
62 fStorage.clear();
63 fLayout = layout;
64 fReqAlignment = 0;
65 fWrotePaintColor = false;
66
67#ifdef SK_DEBUG
68 fOffsetCalculator = UniformOffsetCalculator(layout, 0);
69 fExpectedUniforms = {};
70 fExpectedUniformIndex = 0;
71#endif
72}
void clear()
Definition: SkTDArray.h:175

◆ size()

size_t skgpu::graphite::UniformManager::size ( ) const
inline

Definition at line 203 of file UniformManager.h.

203{ return fStorage.size(); }

◆ write() [1/15]

void skgpu::graphite::UniformManager::write ( const SkIRect r)
inline

Definition at line 218 of file UniformManager.h.

218{ this->write<SkSLType::kInt4>(&r); }

◆ write() [2/15]

void skgpu::graphite::UniformManager::write ( const SkISize s)
inline

Definition at line 248 of file UniformManager.h.

248{ this->write<SkSLType::kInt2>(&s); }
struct MyStruct s

◆ write() [3/15]

void skgpu::graphite::UniformManager::write ( const SkM44 m)
inline

Definition at line 257 of file UniformManager.h.

257 {
258 // All Layouts treat a 4x4 column-major matrix as an array of vec4's, which is exactly how
259 // SkM44 already stores its data.
260 this->writeArray<SkSLType::kFloat4>(SkMatrixPriv::M44ColMajor(m), 4);
261 }
static const SkScalar * M44ColMajor(const SkM44 &m)
Definition: SkMatrixPriv.h:185

◆ write() [4/15]

void skgpu::graphite::UniformManager::write ( const SkMatrix m)
inline

Definition at line 267 of file UniformManager.h.

267 {
268 // SkMatrix is row-major, so rewrite to column major. All Layouts treat a 3x3 column
269 // major matrix as an array of vec3's.
270 float colMajor[9] = {m[0], m[3], m[6],
271 m[1], m[4], m[7],
272 m[2], m[5], m[8]};
273 this->writeArray<SkSLType::kFloat3>(colMajor, 3);
274 }

◆ write() [5/15]

void skgpu::graphite::UniformManager::write ( const SkPMColor4f c)
inline

Definition at line 214 of file UniformManager.h.

214{ this->write<SkSLType::kFloat4>(c.vec()); }
const float * vec() const
Definition: SkColor.h:308

◆ write() [6/15]

void skgpu::graphite::UniformManager::write ( const SkPoint p)
inline

Definition at line 246 of file UniformManager.h.

246{ this->write<SkSLType::kFloat2>(&p); }

◆ write() [7/15]

void skgpu::graphite::UniformManager::write ( const SkPoint3 p)
inline

Definition at line 236 of file UniformManager.h.

236{ this->write<SkSLType::kFloat3>(&p); }

◆ write() [8/15]

void skgpu::graphite::UniformManager::write ( const SkRect r)
inline

Definition at line 215 of file UniformManager.h.

215{ this->write<SkSLType::kFloat4>(r.asScalars()); }
const float * asScalars() const
Definition: SkRect.h:1340

◆ write() [9/15]

void skgpu::graphite::UniformManager::write ( const SkSize s)
inline

Definition at line 245 of file UniformManager.h.

245{ this->write<SkSLType::kFloat2>(&s); }

◆ write() [10/15]

void skgpu::graphite::UniformManager::write ( const SkV2 v)
inline

Definition at line 244 of file UniformManager.h.

244{ this->write<SkSLType::kFloat2>(v.ptr()); }
const float * ptr() const
Definition: SkM44.h:52

◆ write() [11/15]

void skgpu::graphite::UniformManager::write ( const SkV3 v)
inline

Definition at line 235 of file UniformManager.h.

235{ this->write<SkSLType::kFloat3>(v.ptr()); }
const float * ptr() const
Definition: SkM44.h:94

◆ write() [12/15]

void skgpu::graphite::UniformManager::write ( const SkV4 v)
inline

Definition at line 216 of file UniformManager.h.

216{ this->write<SkSLType::kFloat4>(v.ptr()); }
const float * ptr() const
Definition: SkM44.h:129

◆ write() [13/15]

void skgpu::graphite::UniformManager::write ( const Uniform u,
const void *  src 
)

Definition at line 92 of file UniformManager.cpp.

92 {
94 SkASSERT(!u.isPaintColor()); // Must go through writePaintColor()
95
96 auto [type, count] = adjust_for_matrix_type(u.type(), u.count());
97 SkASSERT(SkSLTypeMatrixSize(type) < 0); // Matrix types should have been flattened
98
99 const bool fullPrecision = LayoutRules::UseFullPrecision(fLayout) || !IsHalfVector(type);
100 if (count == Uniform::kNonArray) {
101 if (fullPrecision) {
102 switch(SkSLTypeVecLength(type)) {
103 case 1: this->write<1, /*Half=*/false>(data, type); break;
104 case 2: this->write<2, /*Half=*/false>(data, type); break;
105 case 3: this->write<3, /*Half=*/false>(data, type); break;
106 case 4: this->write<4, /*Half=*/false>(data, type); break;
107 }
108 } else {
109 switch(SkSLTypeVecLength(type)) {
110 case 1: this->write<1, /*Half=*/true>(data, type); break;
111 case 2: this->write<2, /*Half=*/true>(data, type); break;
112 case 3: this->write<3, /*Half=*/true>(data, type); break;
113 case 4: this->write<4, /*Half=*/true>(data, type); break;
114 }
115 }
116 } else {
117 if (fullPrecision) {
118 switch(SkSLTypeVecLength(type)) {
119 case 1: this->writeArray<1, /*Half=*/false>(data, count, type); break;
120 case 2: this->writeArray<2, /*Half=*/false>(data, count, type); break;
121 case 3: this->writeArray<3, /*Half=*/false>(data, count, type); break;
122 case 4: this->writeArray<4, /*Half=*/false>(data, count, type); break;
123 }
124 } else {
125 switch(SkSLTypeVecLength(type)) {
126 case 1: this->writeArray<1, /*Half=*/true>(data, count, type); break;
127 case 2: this->writeArray<2, /*Half=*/true>(data, count, type); break;
128 case 3: this->writeArray<3, /*Half=*/true>(data, count, type); break;
129 case 4: this->writeArray<4, /*Half=*/true>(data, count, type); break;
130 }
131 }
132 }
133}
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
int SkSLTypeMatrixSize(SkSLType type)
static constexpr bool SkSLTypeCanBeUniformValue(SkSLType type)
static constexpr int SkSLTypeVecLength(SkSLType type)
GLenum type
void writeArray(SkSpan< const SkV4 > v)
static constexpr int kNonArray
Definition: Uniform.h:25
static constexpr bool UseFullPrecision(Layout layout)
static std::pair< SkSLType, int > adjust_for_matrix_type(SkSLType type, int count)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ write() [14/15]

void skgpu::graphite::UniformManager::write ( float  f)
inline

Definition at line 209 of file UniformManager.h.

209{ this->write<SkSLType::kFloat>(&f); }

◆ write() [15/15]

void skgpu::graphite::UniformManager::write ( int32_t  i)
inline

Definition at line 210 of file UniformManager.h.

210{ this->write<SkSLType::kInt >(&i); }

◆ writeArray() [1/2]

void skgpu::graphite::UniformManager::writeArray ( SkSpan< const SkPMColor4f c)
inline

Definition at line 227 of file UniformManager.h.

227 {
228 this->writeArray<SkSLType::kFloat4>(c.data(), c.size());
229 }
constexpr T * data() const
Definition: SkSpan_impl.h:94
constexpr size_t size() const
Definition: SkSpan_impl.h:95

◆ writeArray() [2/2]

void skgpu::graphite::UniformManager::writeArray ( SkSpan< const SkV4 v)
inline

Definition at line 224 of file UniformManager.h.

224 {
225 this->writeArray<SkSLType::kFloat4>(v.data(), v.size());
226 }

◆ writeHalf() [1/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkM44 m)
inline

Definition at line 263 of file UniformManager.h.

263 {
264 this->writeArray<SkSLType::kHalf4>(SkMatrixPriv::M44ColMajor(m), 4);
265 }

◆ writeHalf() [2/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkMatrix m)
inline

Definition at line 275 of file UniformManager.h.

275 {
276 float colMajor[9] = {m[0], m[3], m[6],
277 m[1], m[4], m[7],
278 m[2], m[5], m[8]};
279 this->writeArray<SkSLType::kHalf3>(colMajor, 3);
280 }

◆ writeHalf() [3/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkPMColor4f c)
inline

Definition at line 220 of file UniformManager.h.

220{ this->write<SkSLType::kHalf4>(c.vec()); }

◆ writeHalf() [4/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkPoint p)
inline

Definition at line 252 of file UniformManager.h.

252{ this->write<SkSLType::kHalf2>(&p); }

◆ writeHalf() [5/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkPoint3 p)
inline

Definition at line 239 of file UniformManager.h.

239{ this->write<SkSLType::kHalf3>(&p); }

◆ writeHalf() [6/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkRect r)
inline

Definition at line 221 of file UniformManager.h.

221{ this->write<SkSLType::kHalf4>(r.asScalars()); }

◆ writeHalf() [7/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkSize s)
inline

Definition at line 251 of file UniformManager.h.

251{ this->write<SkSLType::kHalf2>(&s); }

◆ writeHalf() [8/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkV2 v)
inline

Definition at line 250 of file UniformManager.h.

250{ this->write<SkSLType::kHalf2>(v.ptr()); }

◆ writeHalf() [9/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkV3 v)
inline

Definition at line 238 of file UniformManager.h.

238{ this->write<SkSLType::kHalf3>(v.ptr()); }

◆ writeHalf() [10/11]

void skgpu::graphite::UniformManager::writeHalf ( const SkV4 v)
inline

Definition at line 222 of file UniformManager.h.

222{ this->write<SkSLType::kHalf4>(v.ptr()); }

◆ writeHalf() [11/11]

void skgpu::graphite::UniformManager::writeHalf ( float  f)
inline

Definition at line 211 of file UniformManager.h.

211{ this->write<SkSLType::kHalf >(&f); }

◆ writeHalfArray()

void skgpu::graphite::UniformManager::writeHalfArray ( SkSpan< const SkPMColor4f c)
inline

Definition at line 230 of file UniformManager.h.

230 {
231 this->writeArray<SkSLType::kHalf4>(c.data(), c.size());
232 }

◆ writePaintColor()

void skgpu::graphite::UniformManager::writePaintColor ( const SkPMColor4f color)
inline

Definition at line 287 of file UniformManager.h.

287 {
288 if (fWrotePaintColor) {
289 // Validate expected uniforms, but don't write a second copy since the paint color
290 // uniform can only ever be declared once in the final SkSL program.
291 SkASSERT(this->checkExpected(/*dst=*/nullptr, SkSLType::kFloat4, Uniform::kNonArray));
292 } else {
293 this->write<SkSLType::kFloat4>(&color);
294 fWrotePaintColor = true;
295 }
296 }
DlColor color

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