Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Private Member Functions | List of all members
GrGeometryProcessor::ProgramImpl Class Referenceabstract

#include <GrGeometryProcessor.h>

Inheritance diagram for GrGeometryProcessor::ProgramImpl:
GrBitmapTextGeoProc::Impl GrConicEffect::Impl GrDistanceFieldA8TextGeoProc::Impl GrDistanceFieldLCDTextGeoProc::Impl GrDistanceFieldPathGeoProc::Impl GrQuadEffect::Impl GrRRectShadowGeoProc::Impl

Classes

struct  EmitArgs
 
struct  FPCoords
 
struct  GrGPArgs
 

Public Types

using UniformHandle = GrGLSLProgramDataManager::UniformHandle
 
using SamplerHandle = GrGLSLUniformHandler::SamplerHandle
 
using FPCoordsMap = std::unordered_map< const GrFragmentProcessor *, FPCoords >
 

Public Member Functions

virtual ~ProgramImpl ()=default
 
std::tuple< FPCoordsMap, GrShaderVaremitCode (EmitArgs &, const GrPipeline &pipeline)
 
void emitTransformCode (GrGLSLVertexBuilder *vb, GrGLSLUniformHandler *uniformHandler)
 
virtual void setData (const GrGLSLProgramDataManager &, const GrShaderCaps &, const GrGeometryProcessor &)=0
 

Static Public Member Functions

static uint32_t ComputeMatrixKey (const GrShaderCaps &caps, const SkMatrix &mat)
 
static uint32_t ComputeMatrixKeys (const GrShaderCaps &shaderCaps, const SkMatrix &viewMatrix, const SkMatrix &localMatrix)
 
static uint32_t AddMatrixKeys (const GrShaderCaps &shaderCaps, uint32_t flags, const SkMatrix &viewMatrix, const SkMatrix &localMatrix)
 

Static Public Attributes

static constexpr int kMatrixKeyBits = 2
 

Protected Member Functions

void setupUniformColor (GrGLSLFPFragmentBuilder *fragBuilder, GrGLSLUniformHandler *uniformHandler, const char *outputName, UniformHandle *colorUniform)
 

Static Protected Member Functions

static void SetTransform (const GrGLSLProgramDataManager &, const GrShaderCaps &, const UniformHandle &uniform, const SkMatrix &matrix, SkMatrix *state=nullptr)
 
static void WriteOutputPosition (GrGLSLVertexBuilder *, GrGPArgs *, const char *posName)
 
static void WriteOutputPosition (GrGLSLVertexBuilder *, GrGLSLUniformHandler *, const GrShaderCaps &, GrGPArgs *, const char *posName, const SkMatrix &viewMatrix, UniformHandle *viewMatrixUniform)
 
static void WriteLocalCoord (GrGLSLVertexBuilder *, GrGLSLUniformHandler *, const GrShaderCaps &, GrGPArgs *, GrShaderVar localVar, const SkMatrix &localMatrix, UniformHandle *localMatrixUniform)
 

Private Member Functions

virtual void onEmitCode (EmitArgs &, GrGPArgs *)=0
 

Detailed Description

Definition at line 261 of file GrGeometryProcessor.h.

Member Typedef Documentation

◆ FPCoordsMap

using GrGeometryProcessor::ProgramImpl::FPCoordsMap = std::unordered_map<const GrFragmentProcessor*, FPCoords>

Definition at line 271 of file GrGeometryProcessor.h.

◆ SamplerHandle

using GrGeometryProcessor::ProgramImpl::SamplerHandle = GrGLSLUniformHandler::SamplerHandle

Definition at line 264 of file GrGeometryProcessor.h.

◆ UniformHandle

using GrGeometryProcessor::ProgramImpl::UniformHandle = GrGLSLProgramDataManager::UniformHandle

Definition at line 263 of file GrGeometryProcessor.h.

Constructor & Destructor Documentation

◆ ~ProgramImpl()

virtual GrGeometryProcessor::ProgramImpl::~ProgramImpl ( )
virtualdefault

Member Function Documentation

◆ AddMatrixKeys()

static uint32_t GrGeometryProcessor::ProgramImpl::AddMatrixKeys ( const GrShaderCaps shaderCaps,
uint32_t  flags,
const SkMatrix viewMatrix,
const SkMatrix localMatrix 
)
inlinestatic

Definition at line 357 of file GrGeometryProcessor.h.

360 {
361 // Shifting to make room for the matrix keys shouldn't lose bits
362 SkASSERT(((flags << (2 * kMatrixKeyBits)) >> (2 * kMatrixKeyBits)) == flags);
363 return (flags << (2 * kMatrixKeyBits)) |
364 ComputeMatrixKeys(shaderCaps, viewMatrix, localMatrix);
365 }
#define SkASSERT(cond)
Definition: SkAssert.h:116
static uint32_t ComputeMatrixKeys(const GrShaderCaps &shaderCaps, const SkMatrix &viewMatrix, const SkMatrix &localMatrix)
FlutterSemanticsFlag flags

◆ ComputeMatrixKey()

static uint32_t GrGeometryProcessor::ProgramImpl::ComputeMatrixKey ( const GrShaderCaps caps,
const SkMatrix mat 
)
inlinestatic

Definition at line 335 of file GrGeometryProcessor.h.

335 {
336 if (!caps.fReducedShaderMode) {
337 if (mat.isIdentity()) {
338 return 0b00;
339 }
340 if (mat.isScaleTranslate()) {
341 return 0b01;
342 }
343 }
344 if (!mat.hasPerspective()) {
345 return 0b10;
346 }
347 return 0b11;
348 }
bool isScaleTranslate() const
Definition: SkMatrix.h:236
bool hasPerspective() const
Definition: SkMatrix.h:312
bool isIdentity() const
Definition: SkMatrix.h:223
bool fReducedShaderMode
Definition: GrShaderCaps.h:46

◆ ComputeMatrixKeys()

static uint32_t GrGeometryProcessor::ProgramImpl::ComputeMatrixKeys ( const GrShaderCaps shaderCaps,
const SkMatrix viewMatrix,
const SkMatrix localMatrix 
)
inlinestatic

Definition at line 350 of file GrGeometryProcessor.h.

352 {
353 return (ComputeMatrixKey(shaderCaps, viewMatrix) << kMatrixKeyBits) |
354 ComputeMatrixKey(shaderCaps, localMatrix);
355 }
static uint32_t ComputeMatrixKey(const GrShaderCaps &caps, const SkMatrix &mat)

◆ emitCode()

std::tuple< FPCoordsMap, GrShaderVar > GrGeometryProcessor::ProgramImpl::emitCode ( EmitArgs ,
const GrPipeline pipeline 
)

Emits the code from this geometry processor into the shaders. For any FP in the pipeline that has its input coords implemented by the GP as a varying, the varying will be accessible in the returned map and should be used when the FP code is emitted. The FS variable containing the GP's output local coords is also returned.

◆ emitTransformCode()

void ProgramImpl::emitTransformCode ( GrGLSLVertexBuilder vb,
GrGLSLUniformHandler uniformHandler 
)

Called after all effect emitCode() functions, to give the processor a chance to write out additional transformation code now that all uniforms have been emitted. It generates the final code for assigning transformed coordinates to the varyings recorded in the call to collectTransforms(). This must happen after FP code emission so that it has access to any uniforms the FPs registered for uniform sample matrix invocations.

Definition at line 237 of file GrGeometryProcessor.cpp.

237 {
238 // Because descendant varyings may be computed using the varyings of ancestor FPs we make
239 // sure to visit the varyings according to FP pre-order traversal by dumping them into a
240 // priority queue.
241 using FPAndInfo = std::tuple<const GrFragmentProcessor*, TransformInfo>;
242 auto compare = [](const FPAndInfo& a, const FPAndInfo& b) {
243 return std::get<1>(a).traversalOrder > std::get<1>(b).traversalOrder;
244 };
245 std::priority_queue<FPAndInfo, std::vector<FPAndInfo>, decltype(compare)> pq(compare);
246 std::for_each(fTransformVaryingsMap.begin(), fTransformVaryingsMap.end(), [&pq](auto entry) {
247 pq.push(entry);
248 });
249 for (; !pq.empty(); pq.pop()) {
250 const auto& [fp, info] = pq.top();
251 // If we recorded a transform info, its sample matrix must be uniform
252 SkASSERT(fp->sampleUsage().isUniformMatrix());
253 GrShaderVar uniform = uniformHandler->liftUniformToVertexShader(
255 // Start with this matrix and accumulate additional matrices as we walk up the FP tree
256 // to either the base coords or an ancestor FP that has an associated varying.
257 SkString transformExpression = uniform.getName();
258
259 // If we hit an ancestor with a varying on our walk up then save off the varying as the
260 // input to our accumulated transformExpression. Start off assuming we'll reach the root.
261 GrShaderVar inputCoords = info.inputCoords;
262
263 for (const auto* base = fp->parent(); base; base = base->parent()) {
264 if (auto iter = fTransformVaryingsMap.find(base); iter != fTransformVaryingsMap.end()) {
265 // Can stop here, as this varying already holds all transforms from higher FPs
266 // We'll apply the residual transformExpression we've accumulated up from our
267 // starting FP to this varying.
268 inputCoords = iter->second.varying.vsOutVar();
269 break;
270 } else if (base->sampleUsage().isUniformMatrix()) {
271 // Accumulate any matrices along the path to either the original local/device coords
272 // or a parent varying. Getting here means this FP was sampled with a uniform matrix
273 // but all uses of coords below here in the FP hierarchy are beneath additional
274 // matrix samples and thus this node wasn't assigned a varying.
275 GrShaderVar parentUniform = uniformHandler->liftUniformToVertexShader(
277 transformExpression.appendf(" * %s", parentUniform.getName().c_str());
278 } else if (base->sampleUsage().isFragCoord()) {
279 // Our chain of matrices starts here and is based on the device space position.
280 break;
281 } else {
282 // This intermediate FP is just a pass through and doesn't need to be built
283 // in to the expression, but we must visit its parents in case they add transforms.
284 SkASSERT(base->sampleUsage().isPassThrough() || !base->sampleUsage().isSampled());
285 }
286 }
287
288 SkString inputStr;
289 if (inputCoords.getType() == SkSLType::kFloat2) {
290 inputStr = SkStringPrintf("%s.xy1", inputCoords.getName().c_str());
291 } else {
292 SkASSERT(inputCoords.getType() == SkSLType::kFloat3);
293 inputStr = inputCoords.getName();
294 }
295
296 vb->codeAppend("{\n");
297 if (info.varying.type() == SkSLType::kFloat2) {
299 vb->codeAppendf("%s = float3x2(%s) * %s",
300 info.varying.vsOut(),
301 transformExpression.c_str(),
302 inputStr.c_str());
303 } else {
304 vb->codeAppendf("%s = (%s * %s).xy",
305 info.varying.vsOut(),
306 transformExpression.c_str(),
307 inputStr.c_str());
308 }
309 } else {
310 SkASSERT(info.varying.type() == SkSLType::kFloat3);
311 vb->codeAppendf("%s = %s * %s",
312 info.varying.vsOut(),
313 transformExpression.c_str(),
314 inputStr.c_str());
315 }
316 vb->codeAppend(";\n");
317 vb->codeAppend("}\n");
318 }
319 // We don't need this map anymore.
320 fTransformVaryingsMap.clear();
321}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
const GrShaderCaps * shaderCaps() const
void codeAppend(const char *str)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
GrGLSLProgramBuilder * getProgramBuilder()
GrShaderVar liftUniformToVertexShader(const GrProcessor &owner, SkString rawName)
SkSLType getType() const
Definition: GrShaderVar.h:97
const SkString & getName() const
Definition: GrShaderVar.h:91
static const char * MatrixUniformName()
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
static bool b
struct MyStruct a[10]
const uint32_t fp
const myers::Point & get< 1 >(const myers::Segment &s)
Definition: Myers.h:81
int compare(const void *untyped_lhs, const void *untyped_rhs)
Definition: skdiff.h:161
bool fNonsquareMatrixSupport
Definition: SkSLUtil.h:90

◆ onEmitCode()

virtual void GrGeometryProcessor::ProgramImpl::onEmitCode ( EmitArgs ,
GrGPArgs  
)
privatepure virtual

◆ setData()

virtual void GrGeometryProcessor::ProgramImpl::setData ( const GrGLSLProgramDataManager ,
const GrShaderCaps ,
const GrGeometryProcessor  
)
pure virtual

A ProgramImpl instance can be reused with any GrGeometryProcessor that produces the same key. This function reads data from a GrGeometryProcessor and updates any uniform variables required by the shaders created in emitCode(). The GrGeometryProcessor parameter is guaranteed to be of the same type and to have an identical processor key as the GrGeometryProcessor that created this ProgramImpl.

Implemented in GrRRectShadowGeoProc::Impl, GrConicEffect::Impl, GrQuadEffect::Impl, GrBitmapTextGeoProc::Impl, GrDistanceFieldA8TextGeoProc::Impl, GrDistanceFieldPathGeoProc::Impl, and GrDistanceFieldLCDTextGeoProc::Impl.

◆ SetTransform()

void ProgramImpl::SetTransform ( const GrGLSLProgramDataManager pdman,
const GrShaderCaps shaderCaps,
const UniformHandle uniform,
const SkMatrix matrix,
SkMatrix state = nullptr 
)
staticprotected

Definition at line 340 of file GrGeometryProcessor.cpp.

344 {
345 if (!uniform.isValid() || (state && SkMatrixPriv::CheapEqual(*state, matrix))) {
346 // No update needed
347 return;
348 }
349 if (state) {
350 *state = matrix;
351 }
352 if (matrix.isScaleTranslate() && !shaderCaps.fReducedShaderMode) {
353 // ComputeMatrixKey and writeX() assume the uniform is a float4 (can't assert since nothing
354 // is exposed on a handle, but should be caught lower down).
355 float values[4] = {matrix.getScaleX(), matrix.getTranslateX(),
356 matrix.getScaleY(), matrix.getTranslateY()};
357 pdman.set4fv(uniform, 1, values);
358 } else {
359 pdman.setSkMatrix(uniform, matrix);
360 }
361}
virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const =0
void setSkMatrix(UniformHandle, const SkMatrix &) const
static bool CheapEqual(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrixPriv.h:181
AtkStateType state
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ setupUniformColor()

void ProgramImpl::setupUniformColor ( GrGLSLFPFragmentBuilder fragBuilder,
GrGLSLUniformHandler uniformHandler,
const char *  outputName,
UniformHandle colorUniform 
)
protected

Definition at line 323 of file GrGeometryProcessor.cpp.

326 {
327 SkASSERT(colorUniform);
328 const char* stagedLocalVarName;
329 *colorUniform = uniformHandler->addUniform(nullptr,
332 "Color",
333 &stagedLocalVarName);
334 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
336 fragBuilder->codeAppendf("%s = max(%s, half4(0));", outputName, outputName);
337 }
338}
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
UniformHandle addUniform(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, const char **outName=nullptr)
bool fMustObfuscateUniformColor
Definition: GrShaderCaps.h:51

◆ WriteLocalCoord()

void ProgramImpl::WriteLocalCoord ( GrGLSLVertexBuilder vertBuilder,
GrGLSLUniformHandler uniformHandler,
const GrShaderCaps shaderCaps,
GrGPArgs gpArgs,
GrShaderVar  localVar,
const SkMatrix localMatrix,
UniformHandle localMatrixUniform 
)
staticprotected

Definition at line 474 of file GrGeometryProcessor.cpp.

480 {
481 write_vertex_position(vertBuilder,
482 uniformHandler,
483 shaderCaps,
484 localVar,
485 localMatrix,
486 "localMatrix",
487 &gpArgs->fLocalCoordVar,
488 localMatrixUniform);
489}
static void write_vertex_position(GrGLSLVertexBuilder *vertBuilder, GrGLSLUniformHandler *uniformHandler, const GrShaderCaps &shaderCaps, const GrShaderVar &inPos, const SkMatrix &matrix, const char *matrixName, GrShaderVar *outPos, ProgramImpl::UniformHandle *matrixUniform)

◆ WriteOutputPosition() [1/2]

static void GrGeometryProcessor::ProgramImpl::WriteOutputPosition ( GrGLSLVertexBuilder ,
GrGLSLUniformHandler ,
const GrShaderCaps ,
GrGPArgs ,
const char *  posName,
const SkMatrix viewMatrix,
UniformHandle viewMatrixUniform 
)
staticprotected

◆ WriteOutputPosition() [2/2]

static void GrGeometryProcessor::ProgramImpl::WriteOutputPosition ( GrGLSLVertexBuilder ,
GrGPArgs ,
const char *  posName 
)
staticprotected

Member Data Documentation

◆ kMatrixKeyBits

constexpr int GrGeometryProcessor::ProgramImpl::kMatrixKeyBits = 2
inlinestaticconstexpr

Definition at line 366 of file GrGeometryProcessor.h.


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