This change is in preparation for updating how processor keys and meta keys are generated for frag procs.
BUG=skia:4182 Review URL: https://codereview.chromium.org/1298233002
This commit is contained in:
parent
5b4a7abd48
commit
93ab254b7e
@ -25,7 +25,9 @@ class GrFragmentProcessor : public GrProcessor {
|
|||||||
public:
|
public:
|
||||||
GrFragmentProcessor()
|
GrFragmentProcessor()
|
||||||
: INHERITED()
|
: INHERITED()
|
||||||
, fUsesLocalCoords(false) {}
|
, fUsesLocalCoords(false)
|
||||||
|
, fNumTexturesExclChildren(0)
|
||||||
|
, fNumTransformsExclChildren(0) {}
|
||||||
|
|
||||||
GrGLFragmentProcessor* createGLInstance() const;
|
GrGLFragmentProcessor* createGLInstance() const;
|
||||||
|
|
||||||
@ -40,6 +42,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int numTexturesExclChildren() const { return fNumTexturesExclChildren; }
|
||||||
|
|
||||||
|
int numTransformsExclChildren() const { return fNumTransformsExclChildren; }
|
||||||
|
|
||||||
int numTransforms() const { return fCoordTransforms.count(); }
|
int numTransforms() const { return fCoordTransforms.count(); }
|
||||||
|
|
||||||
/** Returns the coordinate transformation at index. index must be valid according to
|
/** Returns the coordinate transformation at index. index must be valid according to
|
||||||
@ -84,6 +90,8 @@ public:
|
|||||||
void computeInvariantOutput(GrInvariantOutput* inout) const;
|
void computeInvariantOutput(GrInvariantOutput* inout) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void addTextureAccess(const GrTextureAccess* textureAccess) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment Processor subclasses call this from their constructor to register coordinate
|
* Fragment Processor subclasses call this from their constructor to register coordinate
|
||||||
* transformations. Coord transforms provide a mechanism for a processor to receive coordinates
|
* transformations. Coord transforms provide a mechanism for a processor to receive coordinates
|
||||||
@ -105,7 +113,8 @@ protected:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* FragmentProcessor subclasses call this from their constructor to register any child
|
* FragmentProcessor subclasses call this from their constructor to register any child
|
||||||
* FragmentProcessors they have.
|
* FragmentProcessors they have. This must be called AFTER all texture accesses and coord
|
||||||
|
* transforms have been added.
|
||||||
* This is for processors whose shader code will be composed of nested processors whose output
|
* This is for processors whose shader code will be composed of nested processors whose output
|
||||||
* colors will be combined somehow to produce its output color. Registering these child
|
* colors will be combined somehow to produce its output color. Registering these child
|
||||||
* processors will allow the ProgramBuilder to automatically handle their transformed coords and
|
* processors will allow the ProgramBuilder to automatically handle their transformed coords and
|
||||||
@ -168,6 +177,9 @@ private:
|
|||||||
*/
|
*/
|
||||||
SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
|
SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
|
||||||
|
|
||||||
|
int fNumTexturesExclChildren;
|
||||||
|
int fNumTransformsExclChildren;
|
||||||
|
|
||||||
SkTArray<GrFragmentStage, false> fChildProcessors;
|
SkTArray<GrFragmentStage, false> fChildProcessors;
|
||||||
|
|
||||||
typedef GrProcessor INHERITED;
|
typedef GrProcessor INHERITED;
|
||||||
|
@ -101,7 +101,7 @@ protected:
|
|||||||
* GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
|
* GrTextureAccess is typically a member field of the GrProcessor subclass. This must only be
|
||||||
* called from the constructor because GrProcessors are immutable.
|
* called from the constructor because GrProcessors are immutable.
|
||||||
*/
|
*/
|
||||||
void addTextureAccess(const GrTextureAccess* textureAccess);
|
virtual void addTextureAccess(const GrTextureAccess* textureAccess);
|
||||||
|
|
||||||
bool hasSameTextureAccesses(const GrProcessor&) const;
|
bool hasSameTextureAccesses(const GrProcessor&) const;
|
||||||
|
|
||||||
|
@ -166,10 +166,24 @@ GrGLFragmentProcessor* GrFragmentProcessor::createGLInstance() const {
|
|||||||
return glFragProc;
|
return glFragProc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GrFragmentProcessor::addTextureAccess(const GrTextureAccess* textureAccess) {
|
||||||
|
// Can't add texture accesses after registering any children since their texture accesses have
|
||||||
|
// already been bubbled up into our fTextureAccesses array
|
||||||
|
SkASSERT(fChildProcessors.empty());
|
||||||
|
|
||||||
|
INHERITED::addTextureAccess(textureAccess);
|
||||||
|
fNumTexturesExclChildren++;
|
||||||
|
}
|
||||||
|
|
||||||
void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) {
|
void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) {
|
||||||
|
// Can't add transforms after registering any children since their transforms have already been
|
||||||
|
// bubbled up into our fCoordTransforms array
|
||||||
|
SkASSERT(fChildProcessors.empty());
|
||||||
|
|
||||||
fCoordTransforms.push_back(transform);
|
fCoordTransforms.push_back(transform);
|
||||||
fUsesLocalCoords = fUsesLocalCoords || transform->sourceCoords() == kLocal_GrCoordSet;
|
fUsesLocalCoords = fUsesLocalCoords || transform->sourceCoords() == kLocal_GrCoordSet;
|
||||||
SkDEBUGCODE(transform->setInProcessor();)
|
SkDEBUGCODE(transform->setInProcessor();)
|
||||||
|
fNumTransformsExclChildren++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GrFragmentProcessor::registerChildProcessor(const GrFragmentProcessor* child) {
|
int GrFragmentProcessor::registerChildProcessor(const GrFragmentProcessor* child) {
|
||||||
|
@ -32,8 +32,8 @@ void GrGLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* We now want to find the subset of coords and samplers that belong to the child and its
|
* We now want to find the subset of coords and samplers that belong to the child and its
|
||||||
* descendants and put that into childCoords and childSamplers. To do so, we must do a
|
* descendants and put that into childCoords and childSamplers. To do so, we'll do a forwards
|
||||||
* backwards linear search on coords and samplers.
|
* linear search.
|
||||||
*
|
*
|
||||||
* Explanation:
|
* Explanation:
|
||||||
* Each GrFragmentProcessor has a copy of all the transforms and textures of itself and
|
* Each GrFragmentProcessor has a copy of all the transforms and textures of itself and
|
||||||
@ -53,23 +53,20 @@ void GrGLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
|
|||||||
* (C) (E) (F)
|
* (C) (E) (F)
|
||||||
* [c1] [e1,e2,e3] [f1,f2]
|
* [c1] [e1,e2,e3] [f1,f2]
|
||||||
*
|
*
|
||||||
* So if we're inside proc A's emitCode, and A is about to call emitCode on proc B, we want the
|
* So if we're inside proc A's emitCode, and A is about to call emitCode on proc D, we want the
|
||||||
* EmitArgs that's passed onto B to only contain its and its descendants' coords. The
|
* EmitArgs that's passed onto D to only contain its and its descendants' coords. The
|
||||||
* EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2], and we want
|
* EmitArgs given to A would contain the transforms [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2], and we want
|
||||||
* to extract the subset [b1,b2,c1] to pass on to B. We can do this with a backwards linear
|
* to extract the subset [d1,e1,e2,e3,f1,f2] to pass on to D. We can do this with a linear
|
||||||
* search since we know that D's subtree has 6 transforms and B's subtree has 3 transforms (by
|
* search since we know that A has 1 transform (using A.numTransformsExclChildren()), and B's
|
||||||
* calling D.numTextures() and B.numTextures()), so we know the start of B's transforms is 9
|
* subtree has 3 transforms (using B.numTransforms()), so we know the start of D's transforms is
|
||||||
* from the end of A's transforms. We cannot do this with a forwards linear search since we
|
* 4 after the start of A's transforms.
|
||||||
* don't know how many transforms belong to A (A.numTextures() will return 10, not 1), so
|
|
||||||
* we wouldn't know how many transforms to initially skip in A's array if using a forward linear
|
|
||||||
* search.
|
|
||||||
* Textures work the same way as transforms.
|
* Textures work the same way as transforms.
|
||||||
*/
|
*/
|
||||||
int firstCoordAt = args.fFp.numTransforms();
|
int firstCoordAt = args.fFp.numTransformsExclChildren();
|
||||||
int firstSamplerAt = args.fFp.numTextures();
|
int firstSamplerAt = args.fFp.numTexturesExclChildren();
|
||||||
for (int i = args.fFp.numChildProcessors() - 1; i >= childIndex; --i) {
|
for (int i = 0; i < childIndex; ++i) {
|
||||||
firstCoordAt -= args.fFp.childProcessor(i).numTransforms();
|
firstCoordAt += args.fFp.childProcessor(i).numTransforms();
|
||||||
firstSamplerAt -= args.fFp.childProcessor(i).numTextures();
|
firstSamplerAt += args.fFp.childProcessor(i).numTextures();
|
||||||
}
|
}
|
||||||
TransformedCoordsArray childCoords;
|
TransformedCoordsArray childCoords;
|
||||||
TextureSamplerArray childSamplers;
|
TextureSamplerArray childSamplers;
|
||||||
|
Loading…
Reference in New Issue
Block a user