Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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

◆ 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 239 of file GrGeometryProcessor.cpp.

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

346 {
347 if (!uniform.isValid() || (state && SkMatrixPriv::CheapEqual(*state, matrix))) {
348 // No update needed
349 return;
350 }
351 if (state) {
352 *state = matrix;
353 }
354 if (matrix.isScaleTranslate() && !shaderCaps.fReducedShaderMode) {
355 // ComputeMatrixKey and writeX() assume the uniform is a float4 (can't assert since nothing
356 // is exposed on a handle, but should be caught lower down).
357 float values[4] = {matrix.getScaleX(), matrix.getTranslateX(),
358 matrix.getScaleY(), matrix.getTranslateY()};
359 pdman.set4fv(uniform, 1, values);
360 } else {
361 pdman.setSkMatrix(uniform, matrix);
362 }
363}
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)
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 325 of file GrGeometryProcessor.cpp.

328 {
329 SkASSERT(colorUniform);
330 const char* stagedLocalVarName;
331 *colorUniform = uniformHandler->addUniform(nullptr,
334 "Color",
335 &stagedLocalVarName);
336 fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
338 fragBuilder->codeAppendf("%s = max(%s, half4(0));", outputName, outputName);
339 }
340}
@ kFragment_GrShaderFlag
UniformHandle addUniform(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, const char **outName=nullptr)
bool fMustObfuscateUniformColor

◆ WriteLocalCoord()

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

Definition at line 476 of file GrGeometryProcessor.cpp.

482 {
483 write_vertex_position(vertBuilder,
484 uniformHandler,
485 shaderCaps,
486 localVar,
487 localMatrix,
488 "localMatrix",
489 &gpArgs->fLocalCoordVar,
490 localMatrixUniform);
491}
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: