revert 8265-8264 (broke build)

git-svn-id: http://skia.googlecode.com/svn/trunk@8268 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-03-20 17:47:16 +00:00
parent 113994051b
commit 67e7cde5c5
53 changed files with 865 additions and 1001 deletions

View File

@ -14,9 +14,6 @@
#include "SkTypes.h"
#include <new>
template <typename T> class SkTLazy;
template <typename T> void* operator new(size_t, SkTLazy<T>* lazy);
/**
* Efficient way to defer allocating/initializing a class until it is needed
* (if ever).
@ -47,7 +44,7 @@ public:
/**
* Return a pointer to a default-initialized instance of the class. If a
* previous instance had been initialized (either from init() or set()) it
* previous instance had been initialzied (either from init() or set()) it
* will first be destroyed, so that a freshly initialized instance is
* always returned.
*/
@ -87,27 +84,10 @@ public:
T* get() const { SkASSERT(this->isValid()); return fPtr; }
private:
friend void* operator new<T>(size_t, SkTLazy* lazy);
T* fPtr; // NULL or fStorage
char fStorage[sizeof(T)];
};
// Use the below macro (SkNEW_IN_TLAZY) rather than calling this directly
template <typename T> void* operator new(size_t, SkTLazy<T>* lazy) {
SkASSERT(!lazy->isValid());
lazy->fPtr = reinterpret_cast<T*>(lazy->fStorage);
return lazy->fPtr;
}
// Skia doesn't use C++ exceptions but it may be compiled with them enabled. Having an op delete
// to match the op new silences warnings about missing op delete when a constructor throws an
// exception.
template <typename T> void operator delete(void*, SkTLazy<T>) { SK_CRASH(); }
// Use this to construct a T inside an SkTLazy using a non-default constructor.
#define SkNEW_IN_TLAZY(tlazy_ptr, type_name, args) (new (tlazy_ptr) type_name args)
/**
* A helper built on top of SkTLazy to do copy-on-first-write. The object is initialized
* with a const pointer but provides a non-const pointer accessor. The first time the

View File

@ -24,16 +24,16 @@
*/
class GrEffectRef;
class GrEffectStage;
class GrGLEffect;
class GrGLCaps;
class GrDrawEffect;
class GrBackendEffectFactory : public GrNoncopyable {
public:
typedef uint32_t EffectKey;
enum {
kNoEffectKey = 0,
kEffectKeyBits = 16,
kEffectKeyBits = 12,
/**
* Some aspects of the generated code may be determined by the particular textures that are
* associated with the effect. These manipulations are performed by GrGLShaderBuilder beyond
@ -44,8 +44,8 @@ public:
kAttribKeyBits = 6
};
virtual EffectKey glEffectKey(const GrDrawEffect&, const GrGLCaps&) const = 0;
virtual GrGLEffect* createGLInstance(const GrDrawEffect&) const = 0;
virtual EffectKey glEffectKey(const GrEffectStage&, const GrGLCaps&) const = 0;
virtual GrGLEffect* createGLInstance(const GrEffectRef&) const = 0;
bool operator ==(const GrBackendEffectFactory& b) const {
return fEffectClassID == b.fEffectClassID;

View File

@ -390,23 +390,25 @@ public:
const SkMatrix* matrix = NULL);
/**
* Maps a rect of local coordinates onto the a rect of destination
* coordinates. Each rect can optionally be transformed. The localRect
* Maps a rect of paint coordinates onto the a rect of destination
* coordinates. Each rect can optionally be transformed. The srcRect
* is stretched over the dstRect. The dstRect is transformed by the
* context's matrix. Additional optional matrices for both rects can be
* provided by parameters.
* context's matrix and the srcRect is transformed by the paint's matrix.
* Additional optional matrices can be provided by parameters.
*
* @param paint describes how to color pixels.
* @param dstRect the destination rect to draw.
* @param localRect rect of local coordinates to be mapped onto dstRect
* @param dstMatrix Optional matrix to transform dstRect. Applied before context's matrix.
* @param localMatrix Optional matrix to transform localRect.
* @param paint describes how to color pixels.
* @param dstRect the destination rect to draw.
* @param srcRect rect of paint coordinates to be mapped onto dstRect
* @param dstMatrix Optional matrix to transform dstRect. Applied before
* context's matrix.
* @param srcMatrix Optional matrix to transform srcRect Applied before
* paint's matrix.
*/
void drawRectToRect(const GrPaint& paint,
const GrRect& dstRect,
const GrRect& localRect,
const GrRect& srcRect,
const SkMatrix* dstMatrix = NULL,
const SkMatrix* localMatrix = NULL);
const SkMatrix* srcMatrix = NULL);
/**
* Draws a path.
@ -697,7 +699,7 @@ public:
this->restore();
if (NULL != paint) {
if (!paint->localCoordChangeInverse(context->getMatrix())) {
if (!paint->sourceCoordChangeByInverse(context->getMatrix())) {
return false;
}
}
@ -735,7 +737,7 @@ public:
*/
void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) {
if (NULL != paint) {
paint->localCoordChange(preConcat);
paint->sourceCoordChange(preConcat);
}
fContext->concatMatrix(preConcat);
}

View File

@ -1,51 +0,0 @@
#ifndef GrDrawEffect_DEFINED
#define GrDrawEffect_DEFINED
#include "GrEffectStage.h"
/**
* This class is used to communicate the particular GrEffect used in a draw to the backend-specific
* effect subclass (e.g. GrGLEffect). It is used to by the backend-specific class to generate a
* cache key for the effect, generate code on a program cache miss, and to upload uniform values to
* the program.
* In addition to the effect, it also communicates any changes between the relationship between
* the view matrix and local coordinate system since the effect was installed in its GrDrawState.
* The typical use case is that sometime after an effect was installed a decision was made to draw
* in device coordinates (i.e. use an identity view-matrix). In such a case the GrDrawEffect's
* coord-change-matrix would be the inverse of the view matrix that was set when the effect was
* installed. GrGLEffectMatrix is a handy class that implements a local coordinate matrix that
* automatically accounts for the coord-change matrix.
*/
class GrDrawEffect {
public:
GrDrawEffect(const GrEffectStage& stage, bool explicitLocalCoords)
: fEffectStage(&stage)
, fExplicitLocalCoords(explicitLocalCoords) {
GrAssert(NULL != fEffectStage);
GrAssert(NULL != fEffectStage->getEffect());
}
const GrEffectRef* effect() const { return fEffectStage->getEffect(); }
template <typename T>
const T& castEffect() const { return *static_cast<const T*>(this->effect()->get()); }
const SkMatrix& getCoordChangeMatrix() const {
if (fExplicitLocalCoords) {
return SkMatrix::I();
} else {
return fEffectStage->getCoordChangeMatrix();
}
}
bool programHasExplicitLocalCoords() const { return fExplicitLocalCoords; }
const int* getVertexAttribIndices() const { return fEffectStage->getVertexAttribIndices(); }
int getVertexAttribIndexCount() const { return fEffectStage->getVertexAttribIndexCount(); }
private:
const GrEffectStage* fEffectStage;
bool fExplicitLocalCoords;
};
#endif

View File

@ -70,20 +70,6 @@ class GrEffect : private GrRefCnt {
public:
SK_DECLARE_INST_COUNT(GrEffect)
/**
* The types of vertex coordinates available to an effect in the vertex shader. Effects can
* require their own vertex attribute but these coordinates are made available by the framework
* in all programs. kCustom_CoordsType is provided to signify that an alternative set of coords
* is used (usually an explicit vertex attribute) but its meaning is determined by the effect
* subclass.
*/
enum CoordsType {
kLocal_CoordsType,
kPosition_CoordsType,
kCustom_CoordsType,
};
virtual ~GrEffect();
/**

View File

@ -58,10 +58,9 @@ public:
/**
* This is called when the coordinate system in which the geometry is specified will change.
*
* @param matrix The transformation from the old coord system in which geometry is specified
* to the new one from which it will actually be drawn.
* @param matrix The transformation from the old coord system to the new one.
*/
void localCoordChange(const SkMatrix& matrix) { fCoordChangeMatrix.preConcat(matrix); }
void preConcatCoordChange(const SkMatrix& matrix) { fCoordChangeMatrix.preConcat(matrix); }
class SavedCoordChange {
private:
@ -73,7 +72,7 @@ public:
/**
* This gets the current coordinate system change. It is the accumulation of
* localCoordChange calls since the effect was installed. It is used when then caller
* preConcatCoordChange calls since the effect was installed. It is used when then caller
* wants to temporarily change the source geometry coord system, draw something, and then
* restore the previous coord system (e.g. temporarily draw in device coords).
*/

View File

@ -169,6 +169,54 @@ public:
bool hasStage() const { return this->hasColorStage() || this->hasCoverageStage(); }
/**
* Called when the source coord system is changing. preConcatInverse is the inverse of the
* transformation from the old coord system to the new coord system. Returns false if the matrix
* cannot be inverted.
*/
bool sourceCoordChangeByInverse(const SkMatrix& preConcatInverse) {
SkMatrix inv;
bool computed = false;
for (int i = 0; i < kMaxColorStages; ++i) {
if (this->isColorStageEnabled(i)) {
if (!computed && !preConcatInverse.invert(&inv)) {
return false;
} else {
computed = true;
}
fColorStages[i].preConcatCoordChange(inv);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (this->isCoverageStageEnabled(i)) {
if (!computed && !preConcatInverse.invert(&inv)) {
return false;
} else {
computed = true;
}
fCoverageStages[i].preConcatCoordChange(inv);
}
}
return true;
}
/**
* Called when the source coord system is changing. preConcat gives the transformation from the
* old coord system to the new coord system.
*/
void sourceCoordChange(const SkMatrix& preConcat) {
for (int i = 0; i < kMaxColorStages; ++i) {
if (this->isColorStageEnabled(i)) {
fColorStages[i].preConcatCoordChange(preConcat);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (this->isCoverageStageEnabled(i)) {
fCoverageStages[i].preConcatCoordChange(preConcat);
}
}
}
GrPaint& operator=(const GrPaint& paint) {
fSrcBlendCoeff = paint.fSrcBlendCoeff;
fDstBlendCoeff = paint.fDstBlendCoeff;
@ -216,51 +264,6 @@ public:
};
private:
/**
* Called when the source coord system from which geometry is rendered changes. It ensures that
* the local coordinates seen by effects remains unchanged. oldToNew gives the transformation
* from the previous coord system to the new coord system.
*/
void localCoordChange(const SkMatrix& oldToNew) {
for (int i = 0; i < kMaxColorStages; ++i) {
if (this->isColorStageEnabled(i)) {
fColorStages[i].localCoordChange(oldToNew);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (this->isCoverageStageEnabled(i)) {
fCoverageStages[i].localCoordChange(oldToNew);
}
}
}
bool localCoordChangeInverse(const SkMatrix& newToOld) {
SkMatrix oldToNew;
bool computed = false;
for (int i = 0; i < kMaxColorStages; ++i) {
if (this->isColorStageEnabled(i)) {
if (!computed && !newToOld.invert(&oldToNew)) {
return false;
} else {
computed = true;
}
fColorStages[i].localCoordChange(oldToNew);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (this->isCoverageStageEnabled(i)) {
if (!computed && !newToOld.invert(&oldToNew)) {
return false;
} else {
computed = true;
}
fCoverageStages[i].localCoordChange(oldToNew);
}
}
return true;
}
friend class GrContext; // To access above two functions
GrEffectStage fColorStages[kMaxColorStages];
GrEffectStage fCoverageStages[kMaxCoverageStages];

View File

@ -9,7 +9,7 @@
#define GrTBackendEffectFactory_DEFINED
#include "GrBackendEffectFactory.h"
#include "GrDrawEffect.h"
#include "GrEffectStage.h"
/**
* Implements GrBackendEffectFactory for a GrEffect subclass as a singleton.
@ -30,12 +30,12 @@ public:
id identifies the GrEffect subclass. The remainder is based
on the aspects of the GrEffect object's configuration that affect
GLSL code generation. */
virtual EffectKey glEffectKey(const GrDrawEffect& drawEffect,
virtual EffectKey glEffectKey(const GrEffectStage& stage,
const GrGLCaps& caps) const SK_OVERRIDE {
GrAssert(kIllegalEffectClassID != fEffectClassID);
EffectKey effectKey = GLEffect::GenKey(drawEffect, caps);
EffectKey textureKey = GLEffect::GenTextureKey(drawEffect, caps);
EffectKey attribKey = GLEffect::GenAttribKey(drawEffect);
EffectKey effectKey = GLEffect::GenKey(stage, caps);
EffectKey textureKey = GLEffect::GenTextureKey(stage.getEffect(), caps);
EffectKey attribKey = GLEffect::GenAttribKey(stage);
#if GR_DEBUG
static const EffectKey kIllegalIDMask = (uint16_t) (~((1U << kEffectKeyBits) - 1));
GrAssert(!(kIllegalIDMask & effectKey));
@ -53,8 +53,8 @@ public:
/** Returns a new instance of the appropriate *GL* implementation class
for the given GrEffect; caller is responsible for deleting
the object. */
virtual GLEffect* createGLInstance(const GrDrawEffect& drawEffect) const SK_OVERRIDE {
return SkNEW_ARGS(GLEffect, (*this, drawEffect));
virtual GLEffect* createGLInstance(const GrEffectRef& effect) const SK_OVERRIDE {
return SkNEW_ARGS(GLEffect, (*this, effect));
}
/** This class is a singleton. This function returns the single instance.

View File

@ -185,17 +185,18 @@ private:
class GrGLBicubicEffect : public GrGLEffect {
public:
GrGLBicubicEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect&);
const GrEffectRef& effect);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLUniformManager::UniformHandle UniformHandle;
@ -209,21 +210,21 @@ private:
};
GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fCoefficientsUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
}
void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kMat44f_GrSLType, "Coefficients");
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@ -268,18 +269,17 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
}
GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrBicubicEffect& bicubic = drawEffect.castEffect<GrBicubicEffect>();
EffectKey matrixKey = GrGLEffectMatrix::GenKey(bicubic.getMatrix(),
drawEffect,
bicubic.coordsType(),
bicubic.texture(0));
GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
const GrBicubicEffect& m = GetEffectFromStage<GrBicubicEffect>(s);
EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
s.getCoordChangeMatrix(),
m.texture(0));
return matrixKey;
}
void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>();
const GrEffectStage& stage) {
const GrBicubicEffect& effect = GetEffectFromStage<GrBicubicEffect>(stage);
GrTexture& texture = *effect.texture(0);
float imageIncrement[2];
imageIncrement[0] = 1.0f / texture.width();
@ -288,7 +288,7 @@ void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
fEffectMatrix.setData(uman,
effect.getMatrix(),
drawEffect,
stage.getCoordChangeMatrix(),
effect.texture(0));
}

View File

@ -94,23 +94,23 @@ bool SkBlendImageFilter::onFilterImage(Proxy* proxy,
#if SK_SUPPORT_GPU
class GrGLBlendEffect : public GrGLEffect {
public:
GrGLBlendEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
GrGLBlendEffect(const GrBackendEffectFactory& factory,
const GrEffectRef& effect);
virtual ~GrGLBlendEffect();
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
private:
static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
SkBlendImageFilter::Mode fMode;
GrGLEffectMatrix fForegroundEffectMatrix;
GrGLEffectMatrix fBackgroundEffectMatrix;
@ -131,13 +131,13 @@ public:
virtual ~GrBlendEffect();
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
const GrBackendEffectFactory& getFactory() const;
SkBlendImageFilter::Mode mode() const { return fMode; }
typedef GrGLBlendEffect GLEffect;
static const char* Name() { return "Blend"; }
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
@ -224,28 +224,27 @@ void GrBlendEffect::getConstantColorComponents(GrColor* color, uint32_t* validFl
///////////////////////////////////////////////////////////////////////////////
GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fMode(drawEffect.castEffect<GrBlendEffect>().mode())
, fForegroundEffectMatrix(kCoordsType)
, fBackgroundEffectMatrix(kCoordsType) {
GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, const GrEffectRef& effect)
: INHERITED(factory),
fMode(CastEffect<GrBlendEffect>(effect).mode()) {
}
GrGLBlendEffect::~GrGLBlendEffect() {
}
void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const GrGLShaderVar& localCoords = builder->localCoordsAttribute();
const char* fgCoords;
const char* bgCoords;
GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(builder, key, &fgCoords, NULL, "FG");
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(
builder, key, vertexCoords, &fgCoords, NULL, "FG");
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(
builder, key, vertexCoords, &bgCoords, NULL, "BG");
const char* bgColor = "bgColor";
const char* fgColor = "fgColor";
@ -284,35 +283,33 @@ void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
}
}
void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage);
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
fForegroundEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(fgTex),
drawEffect,
stage.getCoordChangeMatrix(),
fgTex);
fBackgroundEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(bgTex),
drawEffect,
stage.getCoordChangeMatrix(),
bgTex);
}
GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage);
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(fgTex),
drawEffect,
kCoordsType,
stage.getCoordChangeMatrix(),
fgTex);
EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(bgTex),
drawEffect,
kCoordsType,
stage.getCoordChangeMatrix(),
bgTex);
bgKey <<= GrGLEffectMatrix::kKeyBits;
EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits);

View File

@ -386,17 +386,18 @@ public:
class GLEffect : public GrGLEffect {
public:
// this class always generates the same code.
static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
static EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; }
GLEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect&)
const GrEffectRef& effect)
: INHERITED(factory)
, fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle)
, fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) {}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE {
@ -423,8 +424,8 @@ public:
}
virtual void setData(const GrGLUniformManager& uniManager,
const GrDrawEffect& drawEffect) SK_OVERRIDE {
const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffect>();
const GrEffectStage& stage) SK_OVERRIDE {
const ColorMatrixEffect& cme = GetEffectFromStage<ColorMatrixEffect>(stage);
const float* m = cme.fMatrix.fMat;
// The GL matrix is transposed from SkColorMatrix.
GrGLfloat mt[] = {

View File

@ -201,23 +201,22 @@ bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
class GrGLDisplacementMapEffect : public GrGLEffect {
public:
GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect);
const GrEffectRef& effect);
virtual ~GrGLDisplacementMapEffect();
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
private:
static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
GrGLEffectMatrix fDisplacementEffectMatrix;
@ -246,7 +245,7 @@ public:
virtual ~GrDisplacementMapEffect();
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
const GrBackendEffectFactory& getFactory() const;
SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const
{ return fXChannelSelector; }
SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const
@ -256,10 +255,9 @@ public:
typedef GrGLDisplacementMapEffect GLEffect;
static const char* Name() { return "DisplacementMap"; }
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
@ -384,33 +382,32 @@ GrEffectRef* GrDisplacementMapEffect::TestCreate(SkMWCRandom* random,
///////////////////////////////////////////////////////////////////////////////
GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fDisplacementEffectMatrix(kCoordsType)
, fColorEffectMatrix(kCoordsType)
, fXChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().xChannelSelector())
, fYChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().yChannelSelector()) {
, fXChannelSelector(CastEffect<GrDisplacementMapEffect>(effect).xChannelSelector())
, fYChannelSelector(CastEffect<GrDisplacementMapEffect>(effect).yChannelSelector()) {
}
GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
}
void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
EffectKey key,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "Scale");
const char* scaleUni = builder->getUniformCStr(fScaleUni);
const char* dCoordsIn;
GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
builder, key, &dCoordsIn, NULL, "DISPL");
builder, key, vertexCoords, &dCoordsIn, NULL, "DISPL");
const char* cCoordsIn;
GrSLType cCoordsType = fColorEffectMatrix.emitCode(
builder, key, &cCoordsIn, NULL, "COLOR");
builder, key, vertexCoords, &cCoordsIn, NULL, "COLOR");
const char* dColor = "dColor";
const char* cCoords = "cCoords";
@ -481,19 +478,17 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend(";\n");
}
void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrDisplacementMapEffect& displacementMap =
drawEffect.castEffect<GrDisplacementMapEffect>();
void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrDisplacementMapEffect& displacementMap = GetEffectFromStage<GrDisplacementMapEffect>(stage);
GrTexture* displTex = displacementMap.texture(0);
GrTexture* colorTex = displacementMap.texture(1);
fDisplacementEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(displTex),
drawEffect,
stage.getCoordChangeMatrix(),
displTex);
fColorEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(colorTex),
drawEffect,
stage.getCoordChangeMatrix(),
colorTex);
SkScalar scaleX = SkScalarDiv(displacementMap.scale(), SkIntToScalar(colorTex->width()));
@ -503,22 +498,20 @@ void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman,
SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
}
GrGLEffect::EffectKey GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& drawEffect,
GrGLEffect::EffectKey GrGLDisplacementMapEffect::GenKey(const GrEffectStage& stage,
const GrGLCaps&) {
const GrDisplacementMapEffect& displacementMap =
drawEffect.castEffect<GrDisplacementMapEffect>();
GetEffectFromStage<GrDisplacementMapEffect>(stage);
GrTexture* displTex = displacementMap.texture(0);
GrTexture* colorTex = displacementMap.texture(1);
EffectKey displKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(displTex),
drawEffect,
kCoordsType,
stage.getCoordChangeMatrix(),
displTex);
EffectKey colorKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(colorTex),
drawEffect,
kCoordsType,
stage.getCoordChangeMatrix(),
colorTex);
colorKey <<= GrGLEffectMatrix::kKeyBits;

View File

@ -980,22 +980,23 @@ SkLight* create_random_light(SkMWCRandom* random) {
class GrGLLightingEffect : public GrGLEffect {
public:
GrGLLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& effect);
const GrEffectRef& effect);
virtual ~GrGLLightingEffect();
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
/**
* Subclasses of GrGLLightingEffect must call INHERITED::setData();
*/
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
protected:
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) = 0;
@ -1014,9 +1015,9 @@ private:
class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public:
GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect);
const GrEffectRef& effect);
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLLightingEffect INHERITED;
@ -1029,9 +1030,9 @@ private:
class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public:
GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& effect);
const GrEffectRef& effect);
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLLightingEffect INHERITED;
@ -1092,12 +1093,11 @@ GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkMWCRandom* random,
///////////////////////////////////////////////////////////////////////////////
GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fImageIncrementUni(kInvalidUniformHandle)
, fSurfaceScaleUni(kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrLightingEffect>().coordsType()) {
const GrLightingEffect& m = drawEffect.castEffect<GrLightingEffect>();
, fSurfaceScaleUni(kInvalidUniformHandle) {
const GrLightingEffect& m = CastEffect<GrLightingEffect>(effect);
fLight = m.light()->createGLLight();
}
@ -1106,14 +1106,14 @@ GrGLLightingEffect::~GrGLLightingEffect() {
}
void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
const GrGLShaderVar& localCoords = builder->localCoordsAttribute();
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType,
@ -1207,30 +1207,28 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend(modulate.c_str());
}
GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect,
GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrEffectStage& s,
const GrGLCaps& caps) {
const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>();
EffectKey key = lighting.light()->type();
const GrLightingEffect& effect = GetEffectFromStage<GrLightingEffect>(s);
EffectKey key = effect.light()->type();
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(lighting.getMatrix(),
drawEffect,
lighting.coordsType(),
lighting.texture(0));
EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
s.getCoordChangeMatrix(),
effect.texture(0));
return key | matrixKey;
}
void GrGLLightingEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>();
GrTexture* texture = lighting.texture(0);
void GrGLLightingEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrLightingEffect& effect = GetEffectFromStage<GrLightingEffect>(stage);
GrTexture* texture = effect.texture(0);
float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
uman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
fLight->setData(uman, lighting.light());
uman.set1f(fSurfaceScaleUni, effect.surfaceScale());
fLight->setData(uman, effect.light());
fEffectMatrix.setData(uman,
lighting.getMatrix(),
drawEffect,
lighting.texture(0));
effect.getMatrix(),
stage.getCoordChangeMatrix(),
effect.texture(0));
}
///////////////////////////////////////////////////////////////////////////////
@ -1238,8 +1236,8 @@ void GrGLLightingEffect::setData(const GrGLUniformManager& uman,
///////////////////////////////////////////////////////////////////////////////
GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED(factory, drawEffect)
const GrEffectRef& effect)
: INHERITED(factory, effect)
, fKDUni(kInvalidUniformHandle) {
}
@ -1268,10 +1266,10 @@ void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStri
}
void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
INHERITED::setData(uman, drawEffect);
const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLightingEffect>();
uman.set1f(fKDUni, diffuse.kd());
const GrEffectStage& stage) {
INHERITED::setData(uman, stage);
const GrDiffuseLightingEffect& effect = GetEffectFromStage<GrDiffuseLightingEffect>(stage);
uman.set1f(fKDUni, effect.kd());
}
///////////////////////////////////////////////////////////////////////////////
@ -1309,8 +1307,8 @@ GrEffectRef* GrSpecularLightingEffect::TestCreate(SkMWCRandom* random,
///////////////////////////////////////////////////////////////////////////////
GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: GrGLLightingEffect(factory, drawEffect)
const GrEffectRef& effect)
: GrGLLightingEffect(factory, effect)
, fKSUni(kInvalidUniformHandle)
, fShininessUni(kInvalidUniformHandle) {
}
@ -1344,11 +1342,11 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr
}
void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
INHERITED::setData(uman, drawEffect);
const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLightingEffect>();
uman.set1f(fKSUni, spec.ks());
uman.set1f(fShininessUni, spec.shininess());
const GrEffectStage& stage) {
INHERITED::setData(uman, stage);
const GrSpecularLightingEffect& effect = GetEffectFromStage<GrSpecularLightingEffect>(stage);
uman.set1f(fKSUni, effect.ks());
uman.set1f(fShininessUni, effect.shininess());
}
///////////////////////////////////////////////////////////////////////////////
@ -1362,7 +1360,8 @@ void GrGLLight::emitLightColor(GrGLShaderBuilder* builder,
builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni()));
}
void GrGLLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
void GrGLLight::setData(const GrGLUniformManager& uman,
const SkLight* light) const {
setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToScalar(255)));
}
@ -1384,7 +1383,8 @@ void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char
///////////////////////////////////////////////////////////////////////////////
void GrGLPointLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
void GrGLPointLight::setData(const GrGLUniformManager& uman,
const SkLight* light) const {
INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kPoint_LightType);
const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
@ -1400,7 +1400,8 @@ void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char*
///////////////////////////////////////////////////////////////////////////////
void GrGLSpotLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
void GrGLSpotLight::setData(const GrGLUniformManager& uman,
const SkLight* light) const {
INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kSpot_LightType);
const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);

View File

@ -92,20 +92,22 @@ typedef GrGLUniformManager::UniformHandle UniformHandle;
class GrGLMagnifierEffect : public GrGLEffect {
public:
GrGLMagnifierEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef& effect);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
UniformHandle fOffsetVar;
UniformHandle fZoomVar;
UniformHandle fInsetVar;
@ -115,23 +117,22 @@ private:
typedef GrGLEffect INHERITED;
};
GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED(factory)
, fOffsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fZoomVar(GrGLUniformManager::kInvalidUniformHandle)
, fInsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMagnifierEffect>().coordsType()) {
, fInsetVar(GrGLUniformManager::kInvalidUniformHandle) {
}
void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fOffsetVar = builder->addUniform(
GrGLShaderBuilder::kFragment_ShaderType |
GrGLShaderBuilder::kVertex_ShaderType,
@ -178,20 +179,18 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
}
void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
const GrEffectStage& stage) {
const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage);
uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset());
uman.set2f(fZoomVar, zoom.x_zoom(), zoom.y_zoom());
uman.set2f(fInsetVar, zoom.x_inset(), zoom.y_inset());
fEffectMatrix.setData(uman, zoom.getMatrix(), drawEffect, zoom.texture(0));
fEffectMatrix.setData(uman, zoom.getMatrix(), stage.getCoordChangeMatrix(), zoom.texture(0));
}
GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage);
return GrGLEffectMatrix::GenKey(zoom.getMatrix(),
drawEffect,
zoom.coordsType(),
stage.getCoordChangeMatrix(),
zoom.texture(0));
}

View File

@ -284,6 +284,8 @@ public:
typedef GrGLMatrixConvolutionEffect GLEffect;
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
private:
@ -314,17 +316,18 @@ private:
class GrGLMatrixConvolutionEffect : public GrGLEffect {
public:
GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& effect);
const GrEffectRef& effect);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLUniformManager::UniformHandle UniformHandle;
@ -345,15 +348,14 @@ private:
};
GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fKernelUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fTargetUni(GrGLUniformManager::kInvalidUniformHandle)
, fGainUni(GrGLUniformManager::kInvalidUniformHandle)
, fBiasUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMatrixConvolutionEffect>().coordsType()) {
const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
, fBiasUni(GrGLUniformManager::kInvalidUniformHandle) {
const GrMatrixConvolutionEffect& m = CastEffect<GrMatrixConvolutionEffect>(effect);
fKernelSize = m.kernelSize();
fTileMode = m.tileMode();
fConvolveAlpha = m.convolveAlpha();
@ -381,13 +383,14 @@ static void appendTextureLookup(GrGLShaderBuilder* builder,
}
void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
@ -447,40 +450,38 @@ int encodeXY(int x, int y) {
};
GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
const GrMatrixConvolutionEffect& m = GetEffectFromStage<GrMatrixConvolutionEffect>(s);
EffectKey key = encodeXY(m.kernelSize().width(), m.kernelSize().height());
key |= m.tileMode() << 7;
key |= m.convolveAlpha() ? 1 << 9 : 0;
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
drawEffect,
m.coordsType(),
s.getCoordChangeMatrix(),
m.texture(0));
return key | matrixKey;
}
void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvolutionEffect>();
GrTexture& texture = *conv.texture(0);
const GrEffectStage& stage) {
const GrMatrixConvolutionEffect& effect = GetEffectFromStage<GrMatrixConvolutionEffect>(stage);
GrTexture& texture = *effect.texture(0);
// the code we generated was for a specific kernel size
GrAssert(conv.kernelSize() == fKernelSize);
GrAssert(conv.tileMode() == fTileMode);
GrAssert(effect.kernelSize() == fKernelSize);
GrAssert(effect.tileMode() == fTileMode);
float imageIncrement[2];
float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
imageIncrement[0] = 1.0f / texture.width();
imageIncrement[1] = ySign / texture.height();
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
uman.set2fv(fTargetUni, 0, 1, conv.target());
uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), conv.kernel());
uman.set1f(fGainUni, conv.gain());
uman.set1f(fBiasUni, conv.bias());
uman.set2fv(fTargetUni, 0, 1, effect.target());
uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), effect.kernel());
uman.set1f(fGainUni, effect.gain());
uman.set1f(fBiasUni, effect.bias());
fEffectMatrix.setData(uman,
conv.getMatrix(),
drawEffect,
conv.texture(0));
effect.getMatrix(),
stage.getCoordChangeMatrix(),
effect.texture(0));
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,

View File

@ -278,18 +278,19 @@ private:
class GrGLMorphologyEffect : public GrGLEffect {
public:
GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&);
GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); }
@ -303,23 +304,23 @@ private:
};
GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrMorphologyEffect>().coordsType()) {
const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
const GrMorphologyEffect& m = CastEffect<GrMorphologyEffect>(effect);
fRadius = m.radius();
fType = m.type();
}
void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
@ -352,22 +353,19 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend(modulate.c_str());
}
GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
const GrMorphologyEffect& m = GetEffectFromStage<GrMorphologyEffect>(s);
EffectKey key = static_cast<EffectKey>(m.radius());
key |= (m.type() << 8);
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
drawEffect,
m.coordsType(),
s.getCoordChangeMatrix(),
m.texture(0));
return key | matrixKey;
}
void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const Gr1DKernelEffect& kern = drawEffect.castEffect<Gr1DKernelEffect>();
void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const Gr1DKernelEffect& kern = GetEffectFromStage<Gr1DKernelEffect>(stage);
GrTexture& texture = *kern.texture(0);
// the code we generated was for a specific kernel radius
GrAssert(kern.radius() == fRadius);
@ -383,7 +381,7 @@ void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman,
GrCrash("Unknown filter direction.");
}
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
fEffectMatrix.setData(uman, kern.getMatrix(), drawEffect, kern.texture(0));
fEffectMatrix.setData(uman, kern.getMatrix(), stage.getCoordChangeMatrix(), kern.texture(0));
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -256,31 +256,33 @@ private:
class GLColorTableEffect : public GrGLEffect {
public:
GLColorTableEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
GLColorTableEffect(const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {}
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE {}
static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
typedef GrGLEffect INHERITED;
};
GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED(factory) {
}
void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
@ -321,7 +323,7 @@ void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
GrGLEffect::EffectKey GLColorTableEffect::GenKey(const GrDrawEffect&, const GrGLCaps&) {
GrGLEffect::EffectKey GLColorTableEffect::GenKey(const GrEffectStage&, const GrGLCaps&) {
return 0;
}

View File

@ -734,14 +734,12 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
#if SK_SUPPORT_GPU
#include "effects/GrTextureStripAtlas.h"
#include "GrTBackendEffectFactory.h"
#include "SkGr.h"
GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
: INHERITED(factory)
, fCachedYCoord(SK_ScalarMax)
, fFSYUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(kCoordsType) {
, fFSYUni(GrGLUniformManager::kInvalidUniformHandle) {
}
GrGLGradientEffect::~GrGLGradientEffect() { }
@ -751,11 +749,10 @@ void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) {
kFloat_GrSLType, "GradientYCoordFS");
}
void GrGLGradientEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
void GrGLGradientEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrGradientEffect& e = GetEffectFromStage<GrGradientEffect>(stage);
const GrTexture* texture = e.texture(0);
fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, texture);
fEffectMatrix.setData(uman, e.getMatrix(), stage.getCoordChangeMatrix(), texture);
SkScalar yCoord = e.getYCoord();
if (yCoord != fCachedYCoord) {
@ -764,19 +761,21 @@ void GrGLGradientEffect::setData(const GrGLUniformManager& uman,
}
}
GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrDrawEffect& drawEffect) {
const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrEffectStage& s) {
const GrGradientEffect& e = GetEffectFromStage<GrGradientEffect>(s);
const GrTexture* texture = e.texture(0);
return GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, texture);
return GrGLEffectMatrix::GenKey(e.getMatrix(), s.getCoordChangeMatrix(), texture);
}
void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName,
GrSLType* vsVaryingType) {
fEffectMatrix.emitCodeMakeFSCoords2D(builder,
key & kMatrixKeyMask,
vertexCoords,
fsCoordName,
vsVaryingName,
vsVaryingType);

View File

@ -274,7 +274,7 @@ public:
GrGLGradientEffect(const GrBackendEffectFactory& factory);
virtual ~GrGLGradientEffect();
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
protected:
/**
@ -290,7 +290,7 @@ protected:
* Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt
* bits.
*/
static EffectKey GenMatrixKey(const GrDrawEffect&);
static EffectKey GenMatrixKey(const GrEffectStage& s);
/**
* Inserts code to implement the GrGradientEffect's matrix. This should be called before a
@ -302,6 +302,7 @@ protected:
*/
void setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL);
@ -320,8 +321,6 @@ protected:
const GrGLShaderBuilder::TextureSampler&);
private:
static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
SkScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
GrGLEffectMatrix fEffectMatrix;

View File

@ -453,20 +453,21 @@ void SkLinearGradient::shadeSpan16(int x, int y,
class GrGLLinearGradient : public GrGLGradientEffect {
public:
GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrDrawEffect&)
GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) { }
virtual ~GrGLLinearGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
return GenMatrixKey(drawEffect);
static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
return GenMatrixKey(stage);
}
private:
@ -532,14 +533,15 @@ GrEffectRef* GrLinearGradient::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage& stage,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
this->setupMatrix(builder, key, &coords);
this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t;
t.append(coords);
t.append(".x");

View File

@ -474,18 +474,19 @@ class GrGLRadialGradient : public GrGLGradientEffect {
public:
GrGLRadialGradient(const GrBackendEffectFactory& factory,
const GrDrawEffect&) : INHERITED (factory) { }
const GrEffectRef&) : INHERITED (factory) { }
virtual ~GrGLRadialGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
return GenMatrixKey(drawEffect);
static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
return GenMatrixKey(stage);
}
private:
@ -553,14 +554,15 @@ GrEffectRef* GrRadialGradient::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
this->setupMatrix(builder, key, &coords);
this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t("length(");
t.append(coords);
t.append(")");

View File

@ -391,18 +391,19 @@ class GrGLSweepGradient : public GrGLGradientEffect {
public:
GrGLSweepGradient(const GrBackendEffectFactory& factory,
const GrDrawEffect&) : INHERITED (factory) { }
const GrEffectRef&) : INHERITED (factory) { }
virtual ~GrGLSweepGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
return GenMatrixKey(drawEffect);
static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
return GenMatrixKey(stage);
}
private:
@ -463,14 +464,15 @@ GrEffectRef* GrSweepGradient::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
this->setupMatrix(builder, key, &coords);
this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t;
t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords, coords);
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);

View File

@ -343,18 +343,20 @@ static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
class GrGLConical2Gradient : public GrGLGradientEffect {
public:
GrGLConical2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffect&);
GrGLConical2Gradient(const GrBackendEffectFactory& factory,
const GrEffectRef&);
virtual ~GrGLConical2Gradient() { }
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps);
static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps);
protected:
@ -474,7 +476,7 @@ GrEffectRef* GrConical2Gradient::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////
GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& baseData)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
@ -484,20 +486,21 @@ GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory
, fCachedRadius(-SK_ScalarMax)
, fCachedDiffRadius(-SK_ScalarMax) {
const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>();
const GrConical2Gradient& data = CastEffect<GrConical2Gradient>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* fsCoords;
const char* vsCoordsVarying;
GrSLType coordsVaryingType;
this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
@ -655,10 +658,9 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
}
}
void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
INHERITED::setData(uman, drawEffect);
const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>();
void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
INHERITED::setData(uman, stage);
const GrConical2Gradient& data = GetEffectFromStage<GrConical2Gradient>(stage);
GrAssert(data.isDegenerate() == fIsDegenerate);
SkScalar centerX1 = data.center();
SkScalar radius0 = data.radius();
@ -692,14 +694,13 @@ void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
}
}
GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
enum {
kIsDegenerate = 1 << kMatrixKeyBitCnt,
};
EffectKey key = GenMatrixKey(drawEffect);
if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) {
EffectKey key = GenMatrixKey(s);
if (GetEffectFromStage<GrConical2Gradient>(s).isDegenerate()) {
key |= kIsDegenerate;
}
return key;

View File

@ -384,18 +384,19 @@ class GrGLRadial2Gradient : public GrGLGradientEffect {
public:
GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffect&);
GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrEffectRef&);
virtual ~GrGLRadial2Gradient() { }
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps);
static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps);
protected:
@ -515,7 +516,7 @@ GrEffectRef* GrRadial2Gradient::TestCreate(SkMWCRandom* random,
/////////////////////////////////////////////////////////////////////
GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& baseData)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
@ -525,13 +526,14 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
, fCachedRadius(-SK_ScalarMax)
, fCachedPosRoot(0) {
const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>();
const GrRadial2Gradient& data = CastEffect<GrRadial2Gradient>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
@ -540,7 +542,7 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
const char* fsCoords;
const char* vsCoordsVarying;
GrSLType coordsVaryingType;
this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
@ -637,10 +639,9 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
}
}
void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
INHERITED::setData(uman, drawEffect);
const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>();
void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
INHERITED::setData(uman, stage);
const GrRadial2Gradient& data = GetEffectFromStage<GrRadial2Gradient>(stage);
GrAssert(data.isDegenerate() == fIsDegenerate);
SkScalar centerX1 = data.center();
SkScalar radius0 = data.radius();
@ -672,14 +673,13 @@ void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman,
}
}
GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
enum {
kIsDegenerate = 1 << kMatrixKeyBitCnt,
};
EffectKey key = GenMatrixKey(drawEffect);
if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) {
EffectKey key = GenMatrixKey(s);
if (GetEffectFromStage<GrRadial2Gradient>(s).isDegenerate()) {
key |= kIsDegenerate;
}
return key;

View File

@ -40,9 +40,6 @@ void setup_drawstate_aaclip(GrGpu* gpu,
static const int kMaskStage = GrPaint::kTotalStages+1;
SkMatrix mat;
// We want to use device coords to compute the texture coordinates. We set our matrix to be
// equal to the view matrix followed by an offset to the devBound, and then a scaling matrix to
// normalized coords. We apply this matrix to the vertex positions rather than local coords.
mat.setIDiv(result->width(), result->height());
mat.preTranslate(SkIntToScalar(-devBound.fLeft),
SkIntToScalar(-devBound.fTop));
@ -54,9 +51,7 @@ void setup_drawstate_aaclip(GrGpu* gpu,
GrTextureDomainEffect::Create(result,
mat,
GrTextureDomainEffect::MakeTexelDomain(result, domainTexels),
GrTextureDomainEffect::kDecal_WrapMode,
false,
GrEffect::kPosition_CoordsType))->unref();
GrTextureDomainEffect::kDecal_WrapMode))->unref();
}
bool path_needs_SW_renderer(GrContext* context,
@ -359,8 +354,7 @@ void GrClipMaskManager::mergeMask(GrTexture* dstMask,
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
GrTextureDomainEffect::kDecal_WrapMode,
false))->unref();
GrTextureDomainEffect::kDecal_WrapMode))->unref();
fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL);
drawState->disableStage(0);

View File

@ -360,12 +360,12 @@ GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc,
{kVec2f_GrVertexAttribType, 0},
{kVec2f_GrVertexAttribType, sizeof(GrPoint)}
};
static const GrAttribBindings kAttribBindings = GrDrawState::kLocalCoords_AttribBindingsBit;
static const GrAttribBindings kAttribBindings =
GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
drawState->setAttribBindings(kAttribBindings);
drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
if (arg.succeeded()) {
@ -852,15 +852,21 @@ void GrContext::drawRect(const GrPaint& paint,
void GrContext::drawRectToRect(const GrPaint& paint,
const GrRect& dstRect,
const GrRect& localRect,
const GrRect& srcRect,
const SkMatrix* dstMatrix,
const SkMatrix* localMatrix) {
const SkMatrix* srcMatrix) {
SK_TRACE_EVENT0("GrContext::drawRectToRect");
// srcRect refers to paint's first color stage
if (!paint.isColorStageEnabled(0)) {
drawRect(paint, dstRect, -1, dstMatrix);
return;
}
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
GrDrawState::AutoStageDisable atr(fDrawState);
#if GR_STATIC_RECT_VB
GrDrawState::AutoStageDisable atr(fDrawState);
GrDrawState* drawState = target->drawState();
SkMatrix m;
@ -872,21 +878,19 @@ void GrContext::drawRectToRect(const GrPaint& paint,
m.postConcat(*dstMatrix);
}
// This code path plays a little fast and loose with the notion of local coords and coord
// change matrices in order to account for localRect and localMatrix. The unit square VB only
// has one set of coords. Rather than using AutoViewMatrixRestore we instead directly set concat
// with m and then call GrDrawState::localCoordChange() with a matrix that accounts for
// localRect and localMatrix. This code path is preventing some encapsulation in GrDrawState.
SkMatrix savedViewMatrix = drawState->getViewMatrix();
drawState->preConcatViewMatrix(m);
// The first color stage's coords come from srcRect rather than applying a matrix to dstRect.
// We explicitly compute a matrix for that stage below, no need to adjust here.
static const uint32_t kExplicitCoordMask = 1 << GrPaint::kFirstColorStage;
GrDrawState::AutoViewMatrixRestore avmr(drawState, m, kExplicitCoordMask);
m.setAll(localRect.width(), 0, localRect.fLeft,
0, localRect.height(), localRect.fTop,
0, 0, SkMatrix::I()[8]);
if (NULL != localMatrix) {
m.postConcat(*localMatrix);
m.setAll(srcRect.width(), 0, srcRect.fLeft,
0, srcRect.height(), srcRect.fTop,
0, 0, SkMatrix::I()[8]);
if (NULL != srcMatrix) {
m.postConcat(*srcMatrix);
}
drawState->localCoordChange(m);
drawState->preConcatStageMatrices(kExplicitCoordMask, m);
const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
if (NULL == sqVB) {
@ -896,9 +900,10 @@ void GrContext::drawRectToRect(const GrPaint& paint,
drawState->setDefaultVertexAttribs();
target->setVertexSourceToBuffer(sqVB);
target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
drawState->setViewMatrix(savedViewMatrix);
#else
target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
GrDrawState::AutoStageDisable atr(fDrawState);
target->drawRect(dstRect, dstMatrix, &srcRect, srcMatrix, 0);
#endif
}
@ -932,8 +937,8 @@ void GrContext::drawVertices(const GrPaint& paint,
// set up optional texture coordinate attributes
if (NULL != texCoords) {
bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
attribs.push_back(currAttrib);
texOffset = currentOffset;

View File

@ -46,6 +46,28 @@ void GrDrawState::setFromPaint(const GrPaint& paint) {
////////////////////////////////////////////////////////////////////////////////
namespace {
/**
* This function generates a mask that we like to have known at compile
* time. When the number of stages is bumped or the way bits are defined in
* GrDrawState.h changes this function should be rerun to generate the new mask.
* (We attempted to force the compiler to generate the mask using recursive
* templates but always wound up with static initializers under gcc, even if
* they were just a series of immediate->memory moves.)
*
*/
void gen_tex_coord_mask(GrAttribBindings* texCoordMask) {
*texCoordMask = 0;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
*texCoordMask |= GrDrawState::ExplicitTexCoordAttribBindingsBit(s);
}
}
const GrAttribBindings kTexCoord_AttribBindingsMask = (1 << GrDrawState::kNumStages)-1;
} //unnamed namespace
const size_t GrDrawState::kVertexAttribSizes[kGrVertexAttribTypeCount] = {
sizeof(float), // kFloat_GrVertexAttribType
2*sizeof(float), // kVec2_GrVertexAttribType
@ -84,7 +106,7 @@ const GrAttribBindings GrDrawState::kAttribIndexMasks[kAttribIndexCount] = {
kColor_AttribBindingsBit,
kCoverage_AttribBindingsBit,
kEdge_AttribBindingsBit,
kLocalCoords_AttribBindingsBit,
kTexCoord_AttribBindingsMask
};
////////////////////////////////////////////////////////////////////////////////
@ -188,8 +210,20 @@ bool GrDrawState::validateVertexAttribs() const {
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBindings) {
return SkToBool(kTexCoord_AttribBindingsMask & attribBindings);
}
////////////////////////////////////////////////////////////////////////////////
void GrDrawState::VertexAttributesUnitTest() {
// Ensure that our tex coord mask is correct
GrAttribBindings texCoordMask;
gen_tex_coord_mask(&texCoordMask);
GrAssert(texCoordMask == kTexCoord_AttribBindingsMask);
// not necessarily exhaustive
static bool run;
if (!run) {
@ -225,11 +259,27 @@ void GrDrawState::VertexAttributesUnitTest() {
attribs.push_back(currAttrib);
GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) + sizeof(float) + 4*sizeof(float) ==
vertex_size(attribs.begin(), attribs.count()));
GrAttribBindings tcMask = 0;
GrAssert(!AttributesBindExplicitTexCoords(0));
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
tcMask |= ExplicitTexCoordAttribBindingsBit(s);
GrAssert(AttributesBindExplicitTexCoords(tcMask));
GrAssert(StageBindsExplicitTexCoords(tcMask, s));
for (int s2 = s + 1; s2 < GrDrawState::kNumStages; ++s2) {
GrAssert(!StageBindsExplicitTexCoords(tcMask, s2));
}
}
GrAssert(kTexCoord_AttribBindingsMask == tcMask);
}
}
////////////////////////////////////////////////////////////////////////////////
bool GrDrawState::StageBindsExplicitTexCoords(GrAttribBindings bindings, int stageIdx) {
return SkToBool(bindings & ExplicitTexCoordAttribBindingsBit(stageIdx));
}
bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const {
uint32_t validComponentFlags;
@ -450,7 +500,8 @@ void GrDrawState::AutoViewMatrixRestore::restore() {
}
void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
const SkMatrix& preconcatMatrix) {
const SkMatrix& preconcatMatrix,
uint32_t explicitCoordStageMask) {
this->restore();
fDrawState = drawState;
@ -462,10 +513,10 @@ void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
fViewMatrix = drawState->getViewMatrix();
drawState->preConcatViewMatrix(preconcatMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (drawState->isStageEnabled(s)) {
if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]);
drawState->fStages[s].localCoordChange(preconcatMatrix);
drawState->fStages[s].preConcatCoordChange(preconcatMatrix);
}
}
}
@ -484,7 +535,8 @@ void GrDrawState::AutoDeviceCoordDraw::restore() {
fDrawState = NULL;
}
bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) {
bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState,
uint32_t explicitCoordStageMask) {
GrAssert(NULL != drawState);
this->restore();
@ -500,7 +552,7 @@ bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) {
bool inverted = false;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (drawState->isStageEnabled(s)) {
if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
if (!inverted && !fViewMatrix.invert(&invVM)) {
// sad trombone sound
fDrawState = NULL;
@ -511,7 +563,7 @@ bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) {
fRestoreMask |= (1 << s);
GrEffectStage* stage = drawState->fStages + s;
stage->saveCoordChange(&fSavedCoordChanges[s]);
stage->localCoordChange(invVM);
stage->preConcatCoordChange(invVM);
}
}
drawState->viewMatrix()->reset();

View File

@ -257,26 +257,38 @@ public:
/**
* The vertex data used by the current program is represented as a bitfield
* of flags. Programs always use positions and may also use texture
* coordinates, per-vertex colors, per-vertex coverage and edge data. The
* local coords accessible by effects may either come from positions or
* be specified explicitly.
* coordinates, per-vertex colors, per-vertex coverage and edge data. Each
* stage can use the explicit texture coordinates as its input texture
* coordinates or it may use the positions as texture coordinates.
*/
/**
* Generates a bit indicating that a texture stage uses texture coordinates
*
* @param stageIdx the stage that will use texture coordinates.
*
* @return the bit to add to a GrAttribBindings bitfield.
*/
static int ExplicitTexCoordAttribBindingsBit(int stageIdx) {
GrAssert(stageIdx < kNumStages);
return (1 << stageIdx);
}
static bool StageBindsExplicitTexCoords(GrAttribBindings bindings, int stageIdx);
/**
* Additional Bits that can be specified in GrAttribBindings.
*/
enum AttribBindingsBits {
/** explicit local coords are provided (instead of using pre-view-matrix positions) */
kLocalCoords_AttribBindingsBit = 0x1,
/* program uses colors (GrColor) */
kColor_AttribBindingsBit = 0x2,
kColor_AttribBindingsBit = 1 << (kNumStages + 0),
/* program uses coverage (GrColor)
*/
kCoverage_AttribBindingsBit = 0x4,
kCoverage_AttribBindingsBit = 1 << (kNumStages + 1),
/* program uses edge data. Distance to the edge is used to
* compute a coverage. See GrDrawState::setVertexEdgeType().
*/
kEdge_AttribBindingsBit = 0x8,
kEdge_AttribBindingsBit = 1 << (kNumStages + 2),
// for below assert
kDummyAttribBindingsBit,
kHighAttribBindingsBit = kDummyAttribBindingsBit - 1
@ -300,6 +312,17 @@ public:
////////////////////////////////////////////////////////////////////////////
// Helpers for picking apart attribute bindings
/**
* Helper function to determine if program uses explicit texture
* coordinates.
*
* @param bindings attribute bindings to query
*
* @return true if program uses texture coordinates,
* false otherwise.
*/
static bool AttributesBindExplicitTexCoords(GrAttribBindings bindings);
/**
* Determines whether src alpha is guaranteed to be one for all src pixels
*/
@ -333,9 +356,9 @@ public:
kColor_AttribIndex,
kCoverage_AttribIndex,
kEdge_AttribIndex,
kLocalCoords_AttribIndex,
kTexCoord_AttribIndex,
kLast_AttribIndex = kLocalCoords_AttribIndex
kLast_AttribIndex = kTexCoord_AttribIndex
};
static const int kAttribIndexCount = kLast_AttribIndex + 1;
@ -387,7 +410,7 @@ public:
/**
* Add a color filter that can be represented by a color and a mode. Applied
* after color-computing effect stages.
* after color-computing texture stages.
*/
void setColorFilter(GrColor c, SkXfermode::Mode mode) {
fCommon.fColorFilterColor = c;
@ -474,7 +497,7 @@ public:
}
/**
* Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
* Creates a GrSimpleTextureEffect.
*/
void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& matrix) {
GrAssert(!this->getStage(stageIdx).getEffect());
@ -533,18 +556,44 @@ public:
}
/**
* Called when the source coord system is changing. This ensures that effects will see the
* correct local coordinates. oldToNew gives the transformation from the old coord system in
* which the geometry was specified to the new coordinate system from which it will be rendered.
* Called when the source coord system is changing. preConcat gives the transformation from the
* old coord system to the new coord system.
*/
void localCoordChange(const SkMatrix& oldToNew) {
void preConcatStageMatrices(const SkMatrix& preConcat) {
this->preConcatStageMatrices(~0U, preConcat);
}
/**
* Version of above that applies the update matrix selectively to stages via a mask.
*/
void preConcatStageMatrices(uint32_t stageMask, const SkMatrix& preConcat) {
for (int i = 0; i < kNumStages; ++i) {
if (this->isStageEnabled(i)) {
fStages[i].localCoordChange(oldToNew);
if (((1 << i) & stageMask) && this->isStageEnabled(i)) {
fStages[i].preConcatCoordChange(preConcat);
}
}
}
/**
* Called when the source coord system is changing. preConcatInverse is the inverse of the
* transformation from the old coord system to the new coord system. Returns false if the matrix
* cannot be inverted.
*/
bool preConcatStageMatricesWithInverse(const SkMatrix& preConcatInverse) {
SkMatrix inv;
bool computed = false;
for (int i = 0; i < kNumStages; ++i) {
if (this->isStageEnabled(i)) {
if (!computed && !preConcatInverse.invert(&inv)) {
return false;
} else {
computed = true;
}
fStages[i].preConcatCoordChange(preConcatInverse);
}
}
return true;
}
/// @}
///////////////////////////////////////////////////////////////////////////
@ -783,9 +832,11 @@ public:
public:
AutoViewMatrixRestore() : fDrawState(NULL) {}
AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) {
AutoViewMatrixRestore(GrDrawState* ds,
const SkMatrix& preconcatMatrix,
uint32_t explicitCoordStageMask = 0) {
fDrawState = NULL;
this->set(ds, preconcatMatrix);
this->set(ds, preconcatMatrix, explicitCoordStageMask);
}
~AutoViewMatrixRestore() { this->restore(); }
@ -795,7 +846,9 @@ public:
*/
void restore();
void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix);
void set(GrDrawState* drawState,
const SkMatrix& preconcatMatrix,
uint32_t explicitCoordStageMask = 0);
bool isSet() const { return NULL != fDrawState; }
@ -822,14 +875,15 @@ public:
* positions, then we don't want to modify its matrix. The explicitCoordStageMask is used
* to specify such stages.
*/
AutoDeviceCoordDraw(GrDrawState* drawState) {
AutoDeviceCoordDraw(GrDrawState* drawState,
uint32_t explicitCoordStageMask = 0) {
fDrawState = NULL;
this->set(drawState);
this->set(drawState, explicitCoordStageMask);
}
~AutoDeviceCoordDraw() { this->restore(); }
bool set(GrDrawState* drawState);
bool set(GrDrawState* drawState, uint32_t explicitCoordStageMask = 0);
/**
* Returns true if this object was successfully initialized on to a GrDrawState. It may
@ -1143,7 +1197,8 @@ public:
return false;
}
for (int i = 0; i < kAttribIndexCount; ++i) {
if ((i == kPosition_AttribIndex || s.fCommon.fAttribBindings & (1 << i)) &&
if ((i == kPosition_AttribIndex ||
s.fCommon.fAttribBindings & kAttribIndexMasks[i]) &&
fAttribIndices[i] != s.fAttribIndices[i]) {
return false;
}

View File

@ -529,9 +529,11 @@ void GrDrawTarget::drawIndexedInstances(GrPrimitiveType type,
void GrDrawTarget::drawRect(const GrRect& rect,
const SkMatrix* matrix,
const GrRect* localRect,
const SkMatrix* localMatrix) {
const GrRect* srcRect,
const SkMatrix* srcMatrix,
int stage) {
GrAttribBindings bindings = 0;
uint32_t explicitCoordMask = 0;
// position + (optional) texture coord
static const GrVertexAttrib kAttribs[] = {
{kVec2f_GrVertexAttribType, 0},
@ -539,15 +541,16 @@ void GrDrawTarget::drawRect(const GrRect& rect,
};
int attribCount = 1;
if (NULL != localRect) {
bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
if (NULL != srcRect) {
bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
attribCount = 2;
this->drawState()->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
this->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
explicitCoordMask = (1 << stage);
}
GrDrawState::AutoViewMatrixRestore avmr;
if (NULL != matrix) {
avmr.set(this->drawState(), *matrix);
avmr.set(this->drawState(), *matrix, explicitCoordMask);
}
this->drawState()->setVertexAttribs(kAttribs, attribCount);
@ -561,15 +564,15 @@ void GrDrawTarget::drawRect(const GrRect& rect,
size_t vsize = this->drawState()->getVertexSize();
geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
if (NULL != localRect) {
if (NULL != srcRect) {
GrAssert(attribCount == 2);
GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
kAttribs[1].fOffset);
coords->setRectFan(localRect->fLeft, localRect->fTop,
localRect->fRight, localRect->fBottom,
vsize);
if (NULL != localMatrix) {
localMatrix->mapPointsWithStride(coords, vsize, 4);
coords->setRectFan(srcRect->fLeft, srcRect->fTop,
srcRect->fRight, srcRect->fBottom,
vsize);
if (NULL != srcMatrix) {
srcMatrix->mapPointsWithStride(coords, vsize, 4);
}
}

View File

@ -388,8 +388,8 @@ public:
/**
* Helper function for drawing rects. This does not use the current index
* and vertex sources. After returning, the vertex and index sources may
* have changed. They should be reestablished before the next draw call.
* This cannot be called between reserving and releasing
* have changed. They should be reestablished before the next drawIndexed
* or drawNonIndexed. This cannot be called between reserving and releasing
* geometry.
*
* A subclass may override this to perform more optimal rect rendering. Its
@ -397,29 +397,34 @@ public:
* (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
* triangle fan using drawNonIndexed from reserved vertex space.
*
* @param rect the rect to draw
* @param matrix optional matrix applied to rect (before viewMatrix)
* @param localRect optional rect that specifies local coords to map onto
* rect. If NULL then rect serves as the local coords.
* @param localMatrix optional matrix applied to localRect. If
* @param rect the rect to draw
* @param matrix optional matrix applied to rect (before viewMatrix)
* @param srcRects specifies rect for explicit texture coordinates.
* if srcRect is non-NULL then that rect will be used
* as the coordinates for the given stage.
* @param srcMatrix optional matrix applied to srcRect. If
* srcRect is non-NULL and srcMatrix is non-NULL
* then srcRect will be transformed by srcMatrix.
* srcMatrix can be NULL when no srcMatrix is desired.
* @param stage the stage to be given explicit texture coordinates.
* Ignored if srcRect is NULL.
*/
virtual void drawRect(const GrRect& rect,
const SkMatrix* matrix,
const GrRect* localRect,
const SkMatrix* localMatrix);
const GrRect* srcRect,
const SkMatrix* srcMatrix,
int stage);
/**
* Helper for drawRect when the caller doesn't need separate local rects or matrices.
* Helper for drawRect when the caller doesn't need separate src rects or
* matrices.
*/
void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) {
drawRect(rect, matrix, NULL, NULL);
drawRect(rect, matrix, NULL, NULL, 0);
}
void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) {
SkRect rect = SkRect::MakeFromIRect(irect);
this->drawRect(rect, matrix, NULL, NULL);
this->drawRect(rect, matrix, NULL, NULL, 0);
}
/**

View File

@ -74,8 +74,9 @@ void get_vertex_bounds(const void* vertices,
void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
const SkMatrix* matrix,
const GrRect* localRect,
const SkMatrix* localMatrix) {
const GrRect* srcRect,
const SkMatrix* srcMatrix,
int stage) {
GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
GrDrawState::AutoColorRestore acr;
@ -85,7 +86,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
GrColor color = drawState->getColor();
GrVertexAttribArray<3> attribs;
size_t currentOffset = 0;
int colorOffset = -1, localOffset = -1;
int colorOffset = -1, texOffset = -1;
// set position attrib
drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count());
@ -114,13 +115,15 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
acr.set(drawState, 0xFFFFFFFF);
}
if (NULL != localRect) {
bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
uint32_t explicitCoordMask = 0;
if (NULL != srcRect) {
bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
attribs.push_back(currAttrib);
localOffset = currentOffset;
texOffset = currentOffset;
currentOffset += sizeof(GrPoint);
explicitCoordMask = (1 << stage);
}
drawState->setVertexAttribs(attribs.begin(), attribs.count());
@ -142,7 +145,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
// When the caller has provided an explicit source rect for a stage then we don't want to
// modify that stage's matrix. Otherwise if the effect is generating its source rect from
// the vertex positions then we have to account for the view matrix change.
GrDrawState::AutoDeviceCoordDraw adcd(drawState);
GrDrawState::AutoDeviceCoordDraw adcd(drawState, explicitCoordMask);
if (!adcd.succeeded()) {
return;
}
@ -158,13 +161,15 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
// unnecessary clipping in our onDraw().
get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
if (localOffset >= 0) {
GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
coords->setRectFan(localRect->fLeft, localRect->fTop,
localRect->fRight, localRect->fBottom,
if (texOffset >= 0) {
GrAssert(explicitCoordMask != 0);
GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
texOffset);
coords->setRectFan(srcRect->fLeft, srcRect->fTop,
srcRect->fRight, srcRect->fBottom,
vsize);
if (NULL != localMatrix) {
localMatrix->mapPointsWithStride(coords, vsize, 4);
if (NULL != srcMatrix) {
srcMatrix->mapPointsWithStride(coords, vsize, 4);
}
}

View File

@ -78,8 +78,9 @@ public:
GrRenderTarget* renderTarget = NULL) SK_OVERRIDE;
virtual void drawRect(const GrRect& rect,
const SkMatrix* matrix,
const GrRect* localRect,
const SkMatrix* localMatrix) SK_OVERRIDE;
const GrRect* srcRect,
const SkMatrix* srcMatrix,
int stage) SK_OVERRIDE;
protected:
virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE;

View File

@ -197,29 +197,18 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
// && edge rendering (kEdgeEffectStage in GrContext)
kPathMaskStage = GrPaint::kTotalStages,
};
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
drawState->createTextureEffect(kPathMaskStage, texture, SkMatrix::I());
SkScalar w = SkIntToScalar(rect.width());
SkScalar h = SkIntToScalar(rect.height());
GrRect maskRect = GrRect::MakeWH(w / texture->width(),
h / texture->height());
GrRect dstRect = GrRect::MakeLTRB(
SK_Scalar1 * rect.fLeft,
SK_Scalar1 * rect.fTop,
SK_Scalar1 * rect.fRight,
SK_Scalar1 * rect.fBottom);
// We want to use device coords to compute the texture coordinates. We set our matrix to be
// equal to the view matrix followed by a translation so that the top-left of the device bounds
// maps to 0,0, and then a scaling matrix to normalized coords. We apply this matrix to the
// vertex positions rather than local coords.
SkMatrix maskMatrix;
maskMatrix.setIDiv(texture->width(), texture->height());
maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
maskMatrix.preConcat(drawState->getViewMatrix());
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
drawState->setEffect(kPathMaskStage,
GrSimpleTextureEffect::Create(texture,
maskMatrix,
false,
GrEffect::kPosition_CoordsType))->unref();
target->drawSimpleRect(dstRect);
target->drawRect(dstRect, NULL, &maskRect, NULL, kPathMaskStage);
drawState->disableStage(kPathMaskStage);
}

View File

@ -18,10 +18,12 @@
#include "SkPath.h"
#include "SkStrokeRec.h"
// glyph rendering shares this stage with edge rendering (kEdgeEffectStage in GrContext) && SW path
// rendering (kPathMaskStage in GrSWMaskHelper)
static const int kGlyphMaskStage = GrPaint::kTotalStages;
static const int kGlyphCoordsAttributeIndex = 1;
enum {
// glyph rendering shares this stage with edge rendering
// (kEdgeEffectStage in GrContext) && SW path rendering
// (kPathMaskStage in GrSWMaskHelper)
kGlyphMaskStage = GrPaint::kTotalStages,
};
void GrTextContext::flushGlyphs() {
if (NULL == fDrawTarget) {
@ -33,11 +35,7 @@ void GrTextContext::flushGlyphs() {
GrAssert(GrIsALIGN4(fCurrVertex));
GrAssert(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, false);
// This effect could be stored with one of the cache objects (atlas?)
drawState->setEffect(kGlyphMaskStage,
GrSimpleTextureEffect::CreateWithCustomCoords(fCurrTexture, params),
kGlyphCoordsAttributeIndex)->unref();
drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, SkMatrix::I(), params);
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
@ -197,7 +195,7 @@ HAS_ATLAS:
{kVec2f_GrVertexAttribType, 0},
{kVec2f_GrVertexAttribType, sizeof(GrPoint)}
};
static const GrAttribBindings kAttribBindings = 0;
static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTexCoordAttribBindingsBit(kGlyphMaskStage);
// If we need to reserve vertices allow the draw target to suggest
// a number of verts to reserve and whether to perform a flush.
@ -216,6 +214,7 @@ HAS_ATLAS:
fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
}
fDrawTarget->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
fDrawTarget->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
fDrawTarget->drawState()->setAttribBindings(kAttribBindings);
fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again.

View File

@ -17,27 +17,29 @@
class GrGLCircleEdgeEffect : public GrGLEffect {
public:
GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage& stage,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleEdgeEffect>();
const GrCircleEdgeEffect& effect = GetEffectFromStage<GrCircleEdgeEffect>(stage);
const char *vsName, *fsName;
builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName);
const SkString* attrName =
builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
builder->getEffectAttributeName(stage.getVertexAttribIndices()[0]);
builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str());
builder->fsCodeAppendf("\tfloat d = distance(%s.xy, %s.xy);\n",
builder->fragmentPosition(), fsName);
builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0);\n", fsName);
if (circleEffect.isStroked()) {
if (effect.isStroked()) {
builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0, 1.0);\n", fsName);
builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
}
@ -46,13 +48,13 @@ public:
builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
}
static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleEdgeEffect>();
static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrCircleEdgeEffect& effect = GetEffectFromStage<GrCircleEdgeEffect>(stage);
return circleEffect.isStroked() ? 0x1 : 0x0;
return effect.isStroked() ? 0x1 : 0x0;
}
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {
virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
}
private:

View File

@ -16,22 +16,21 @@
class GrGLConfigConversionEffect : public GrGLEffect {
public:
GrGLConfigConversionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
: INHERITED (factory)
, fEffectMatrix(drawEffect.castEffect<GrConfigConversionEffect>().coordsType()) {
const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigConversionEffect>();
const GrEffectRef& s) : INHERITED (factory) {
const GrConfigConversionEffect& effect = CastEffect<GrConfigConversionEffect>(s);
fSwapRedAndBlue = effect.swapsRedAndBlue();
fPMConversion = effect.pmConversion();
}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
const char* coords;
GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
GrSLType coordsType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coords);
builder->fsCodeAppendf("\t\t%s = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
@ -72,19 +71,23 @@ public:
builder->fsCodeAppend(modulate.c_str());
}
void setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>();
fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrConfigConversionEffect& effect =
GetEffectFromStage<GrConfigConversionEffect>(stage);
fEffectMatrix.setData(uman,
effect.getMatrix(),
stage.getCoordChangeMatrix(),
effect.texture(0));
}
static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>();
EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.pmConversion() << 1);
static inline EffectKey GenKey(const GrEffectStage& s, const GrGLCaps&) {
const GrConfigConversionEffect& effect = GetEffectFromStage<GrConfigConversionEffect>(s);
EffectKey key = static_cast<EffectKey>(effect.swapsRedAndBlue()) |
(effect.pmConversion() << 1);
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
drawEffect,
conv.coordsType(),
conv.texture(0));
EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
s.getCoordChangeMatrix(),
effect.texture(0));
GrAssert(!(matrixKey & key));
return matrixKey | key;
}

View File

@ -18,18 +18,19 @@ static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
class GrGLConvolutionEffect : public GrGLEffect {
public:
GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, const GrEffectStage&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); }
@ -43,23 +44,23 @@ private:
};
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef& effect)
: INHERITED(factory)
, fKernelUni(kInvalidUniformHandle)
, fImageIncrementUni(kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrConvolutionEffect>().coordsType()) {
const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>();
, fImageIncrementUni(kInvalidUniformHandle) {
const GrConvolutionEffect& c = CastEffect<GrConvolutionEffect>(effect);
fRadius = c.radius();
}
void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
@ -89,9 +90,8 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend(modulate.c_str());
}
void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>();
void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrConvolutionEffect& conv = GetEffectFromStage<GrConvolutionEffect>(stage);
GrTexture& texture = *conv.texture(0);
// the code we generated was for a specific kernel radius
GrAssert(conv.radius() == fRadius);
@ -108,17 +108,15 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
}
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
fEffectMatrix.setData(uman, conv.getMatrix(), stage.getCoordChangeMatrix(), conv.texture(0));
}
GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>();
GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
const GrConvolutionEffect& conv = GetEffectFromStage<GrConvolutionEffect>(s);
EffectKey key = conv.radius();
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
drawEffect,
conv.coordsType(),
s.getCoordChangeMatrix(),
conv.texture(0));
return key | matrixKey;
}

View File

@ -15,28 +15,29 @@
class GrGLEllipseEdgeEffect : public GrGLEffect {
public:
GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage& stage,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
const GrEllipseEdgeEffect& effect = GetEffectFromStage<GrEllipseEdgeEffect>(stage);
const char *vsCenterName, *fsCenterName;
const char *vsEdgeName, *fsEdgeName;
builder->addVarying(kVec2f_GrSLType, "EllipseCenter", &vsCenterName, &fsCenterName);
const SkString* attr0Name =
builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
builder->getEffectAttributeName(stage.getVertexAttribIndices()[0]);
builder->vsCodeAppendf("\t%s = %s;\n", vsCenterName, attr0Name->c_str());
builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsEdgeName, &fsEdgeName);
const SkString* attr1Name =
builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]);
builder->getEffectAttributeName(stage.getVertexAttribIndices()[1]);
builder->vsCodeAppendf("\t%s = %s;\n", vsEdgeName, attr1Name->c_str());
// translate to origin
@ -49,7 +50,7 @@ public:
// compare outer lengths against xOuterRadius
builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.x-dOuter, 0.0, 1.0);\n", fsEdgeName);
if (ellipseEffect.isStroked()) {
if (effect.isStroked()) {
builder->fsCodeAppendf("\tinnerOffset.y *= %s.w;\n", fsEdgeName);
builder->fsCodeAppend("\tfloat dInner = length(innerOffset);\n");
@ -63,13 +64,13 @@ public:
builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
}
static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrEllipseEdgeEffect& effect = GetEffectFromStage<GrEllipseEdgeEffect>(stage);
return ellipseEffect.isStroked() ? 0x1 : 0x0;
return effect.isStroked() ? 0x1 : 0x0;
}
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {
virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
}
private:

View File

@ -15,69 +15,41 @@
class GrGLSimpleTextureEffect : public GrGLEffect {
public:
GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect)
: INHERITED (factory) {
GrEffect::CoordsType coordsType =
drawEffect.castEffect<GrSimpleTextureEffect>().coordsType();
if (GrEffect::kCustom_CoordsType != coordsType) {
SkNEW_IN_TLAZY(&fEffectMatrix, GrGLEffectMatrix, (coordsType));
}
}
GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage&,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
const char* fsCoordName;
GrSLType fsCoordSLType;
if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
GrAssert(ste.getMatrix().isIdentity());
GrAssert(1 == ste.numVertexAttribs());
fsCoordSLType = kVec2f_GrSLType;
const char* vsVaryingName;
builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsCoordName);
const char* attrName =
builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0])->c_str();
builder->vsCodeAppendf("\t%s = %s;", vsVaryingName, attrName);
} else {
fsCoordSLType = fEffectMatrix.get()->emitCode(builder, key, &fsCoordName);
}
const char* coordName;
GrSLType coordType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coordName);
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
fsCoordName,
fsCoordSLType);
coordName,
coordType);
builder->fsCodeAppend(";\n");
}
static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
return 1 << GrGLEffectMatrix::kKeyBits;
} else {
return GrGLEffectMatrix::GenKey(ste.getMatrix(),
drawEffect,
ste.coordsType(),
ste.texture(0));
}
static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage);
return GrGLEffectMatrix::GenKey(ste.getMatrix(),
stage.getCoordChangeMatrix(),
ste.texture(0));
}
virtual void setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) SK_OVERRIDE {
const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
GrAssert(ste.getMatrix().isIdentity());
} else {
fEffectMatrix.get()->setData(uman, ste.getMatrix(), drawEffect, ste.texture(0));
}
virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage);
fEffectMatrix.setData(uman, ste.getMatrix(), stage.getCoordChangeMatrix(), ste.texture(0));
}
private:
SkTLazy<GrGLEffectMatrix> fEffectMatrix;
GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
@ -100,28 +72,6 @@ GrEffectRef* GrSimpleTextureEffect::TestCreate(SkMWCRandom* random,
GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
static const SkShader::TileMode kTileModes[] = {
SkShader::kClamp_TileMode,
SkShader::kRepeat_TileMode,
SkShader::kMirror_TileMode,
};
SkShader::TileMode tileModes[] = {
kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
};
GrTextureParams params(tileModes, random->nextBool());
static const CoordsType kCoordsTypes[] = {
kLocal_CoordsType,
kPosition_CoordsType,
kCustom_CoordsType
};
CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kCoordsTypes))];
if (kCustom_CoordsType == coordsType) {
return GrSimpleTextureEffect::CreateWithCustomCoords(textures[texIdx], params);
} else {
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
}
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
}

View File

@ -14,50 +14,25 @@ class GrGLSimpleTextureEffect;
/**
* The output color of this effect is a modulation of the input color and a sample from a texture.
* It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use
* local coords, positions, or a custom vertex attribute as input texture coords. The input coords
* can have a matrix applied in the VS in both the local and position cases but not with a custom
* attribute coords at this time. It will add a varying to input interpolate texture coords to the
* FS.
* The coord to sample the texture is determine by a matrix. It allows explicit specification of
* the filtering and wrap modes (GrTextureParams).
*/
class GrSimpleTextureEffect : public GrSingleTextureEffect {
public:
/* unfiltered, clamp mode */
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
CoordsType coordsType = kLocal_CoordsType) {
GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, false, coordsType)));
static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix)));
return CreateEffectRef(effect);
}
/* clamp mode */
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
bool bilerp,
CoordsType coordsType = kLocal_CoordsType) {
GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
AutoEffectUnref effect(
SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp, coordsType)));
static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp)));
return CreateEffectRef(effect);
}
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
const GrTextureParams& p,
CoordsType coordsType = kLocal_CoordsType) {
GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordsType)));
return CreateEffectRef(effect);
}
/** Variant that requires the client to install a custom kVec2 vertex attribute that will be
the source of the coords. No matrix is allowed in this mode. */
static GrEffectRef* CreateWithCustomCoords(GrTexture* tex, const GrTextureParams& p) {
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex,
SkMatrix::I(),
p,
kCustom_CoordsType)));
static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) {
AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p)));
return CreateEffectRef(effect);
}
@ -72,28 +47,16 @@ public:
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
private:
GrSimpleTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
bool bilerp,
CoordsType coordsType)
: GrSingleTextureEffect(texture, matrix, bilerp, coordsType) {
GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
}
GrSimpleTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params,
CoordsType coordsType)
: GrSingleTextureEffect(texture, matrix, params, coordsType) {
if (kCustom_CoordsType == coordsType) {
GrAssert(matrix.isIdentity());
this->addVertexAttrib(kVec2f_GrSLType);
}
}
GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix)
: GrSingleTextureEffect(texture, matrix) {}
GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, bool bilerp)
: GrSingleTextureEffect(texture, matrix, bilerp) {}
GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, const GrTextureParams& params)
: GrSingleTextureEffect(texture, matrix, params) {}
virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other);
return this->hasSameTextureParamsMatrixAndCoordsType(ste);
return this->hasSameTextureParamsAndMatrix(ste);
}
GR_DECLARE_EFFECT_TEST;

View File

@ -7,32 +7,23 @@
#include "effects/GrSingleTextureEffect.h"
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
CoordsType coordsType)
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m)
: fTextureAccess(texture)
, fMatrix(m)
, fCoordsType(coordsType) {
, fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
bool bilerp,
CoordsType coordsType)
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m, bool bilerp)
: fTextureAccess(texture, bilerp)
, fMatrix(m)
, fCoordsType(coordsType) {
, fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
const GrTextureParams& params,
CoordsType coordsType)
const GrTextureParams& params)
: fTextureAccess(texture, params)
, fMatrix(m)
, fCoordsType(coordsType) {
, fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}

View File

@ -14,8 +14,7 @@
class GrTexture;
/**
* A base class for effects that draw a single texture with a texture matrix. This effect has no
* backend implementations. One must be provided by the subclass.
* A base class for effects that draw a single texture with a texture matrix.
*/
class GrSingleTextureEffect : public GrEffect {
public:
@ -23,29 +22,20 @@ public:
const SkMatrix& getMatrix() const { return fMatrix; }
/** Indicates whether the matrix operates on local coords or positions */
CoordsType coordsType() const { return fCoordsType; }
protected:
/** unfiltered, clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_CoordsType);
/** clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp, CoordsType = kLocal_CoordsType);
GrSingleTextureEffect(GrTexture*,
const SkMatrix&,
const GrTextureParams&,
CoordsType = kLocal_CoordsType);
GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
/**
* Helper for subclass onIsEqual() functions.
*/
bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& other) const {
bool hasSameTextureParamsAndMatrix(const GrSingleTextureEffect& other) const {
const GrTextureAccess& otherAccess = other.fTextureAccess;
// We don't have to check the accesses' swizzles because they are inferred from the texture.
return fTextureAccess.getTexture() == otherAccess.getTexture() &&
fTextureAccess.getParams() == otherAccess.getParams() &&
this->getMatrix().cheapEqualTo(other.getMatrix()) &&
fCoordsType == other.fCoordsType;
this->getMatrix().cheapEqualTo(other.getMatrix());
}
/**
@ -65,7 +55,6 @@ protected:
private:
GrTextureAccess fTextureAccess;
SkMatrix fMatrix;
CoordsType fCoordsType;
typedef GrEffect INHERITED;
};

View File

@ -14,18 +14,19 @@
class GrGLTextureDomainEffect : public GrGLEffect {
public:
GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
const GrDrawEffect&,
const GrEffectStage&,
EffectKey,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
GrGLUniformManager::UniformHandle fNameUni;
@ -36,27 +37,27 @@ private:
};
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
const GrEffectRef&)
: INHERITED(factory)
, fNameUni(GrGLUniformManager::kInvalidUniformHandle)
, fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) {
, fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
fPrevDomain[0] = SK_FloatNaN;
}
void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage& stage,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
const char* coords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
const char* domain;
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType, "TexDom", &domain);
if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) {
if (GrTextureDomainEffect::kClamp_WrapMode == effect.wrapMode()) {
builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
coords, domain, domain);
@ -68,7 +69,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
"clampCoord");
builder->fsCodeAppend(";\n");
} else {
GrAssert(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode());
GrAssert(GrTextureDomainEffect::kDecal_WrapMode == effect.wrapMode());
if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) {
// On the NexusS and GalaxyNexus, the other path (with the 'any'
@ -105,10 +106,9 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
}
}
void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
const GrRect& domain = texDom.domain();
void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
const GrRect& domain = effect.domain();
float values[4] = {
SkScalarToFloat(domain.left()),
@ -117,7 +117,7 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
SkScalarToFloat(domain.bottom())
};
// vertical flip if necessary
if (kBottomLeft_GrSurfaceOrigin == texDom.texture(0)->origin()) {
if (kBottomLeft_GrSurfaceOrigin == effect.texture(0)->origin()) {
values[1] = 1.0f - values[1];
values[3] = 1.0f - values[3];
// The top and bottom were just flipped, so correct the ordering
@ -128,20 +128,18 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
uman.set4fv(fNameUni, 0, 1, values);
}
fEffectMatrix.setData(uman,
texDom.getMatrix(),
drawEffect,
texDom.texture(0));
effect.getMatrix(),
stage.getCoordChangeMatrix(),
effect.texture(0));
}
GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
EffectKey key = texDom.wrapMode();
GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
EffectKey key = effect.wrapMode();
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(texDom.getMatrix(),
drawEffect,
texDom.coordsType(),
texDom.texture(0));
EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
stage.getCoordChangeMatrix(),
effect.texture(0));
return key | matrixKey;
}
@ -152,8 +150,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
const SkMatrix& matrix,
const GrRect& domain,
WrapMode wrapMode,
bool bilerp,
CoordsType coordsType) {
bool bilerp) {
static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) {
return GrSimpleTextureEffect::Create(texture, matrix, bilerp);
@ -175,8 +172,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
matrix,
clippedDomain,
wrapMode,
bilerp,
coordsType)));
bilerp)));
return CreateEffectRef(effect);
}
@ -186,9 +182,8 @@ GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrRect& domain,
WrapMode wrapMode,
bool bilerp,
CoordsType coordsType)
: GrSingleTextureEffect(texture, matrix, bilerp, coordsType)
bool bilerp)
: GrSingleTextureEffect(texture, matrix, bilerp)
, fWrapMode(wrapMode)
, fTextureDomain(domain) {
}
@ -203,8 +198,7 @@ const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const {
bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const {
const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase);
return this->hasSameTextureParamsMatrixAndCoordsType(s) &&
this->fTextureDomain == s.fTextureDomain;
return this->hasSameTextureParamsAndMatrix(s) && this->fTextureDomain == s.fTextureDomain;
}
void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
@ -231,12 +225,5 @@ GrEffectRef* GrTextureDomainEffect::TestCreate(SkMWCRandom* random,
domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1);
WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode;
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
bool bilerp = random->nextBool();
CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_CoordsType;
return GrTextureDomainEffect::Create(textures[texIdx],
matrix,
domain,
wrapMode,
bilerp,
coords);
return GrTextureDomainEffect::Create(textures[texIdx], matrix, domain, wrapMode);
}

View File

@ -38,8 +38,7 @@ public:
const SkMatrix&,
const SkRect& domain,
WrapMode,
bool bilerp,
CoordsType = kLocal_CoordsType);
bool bilerp = false);
virtual ~GrTextureDomainEffect();
@ -76,8 +75,7 @@ private:
const SkMatrix&,
const GrRect& domain,
WrapMode,
bool bilerp,
CoordsType type);
bool bilerp);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;

View File

@ -7,7 +7,6 @@
#include "GrGLSL.h"
#include "GrGLEffect.h"
#include "GrDrawEffect.h"
GrGLEffect::GrGLEffect(const GrBackendEffectFactory& factory)
: fFactory(factory) {
@ -18,15 +17,14 @@ GrGLEffect::~GrGLEffect() {
///////////////////////////////////////////////////////////////////////////////
void GrGLEffect::setData(const GrGLUniformManager&, const GrDrawEffect&) {
void GrGLEffect::setData(const GrGLUniformManager&, const GrEffectStage&) {
}
GrGLEffect::EffectKey GrGLEffect::GenTextureKey(const GrDrawEffect& drawEffect,
GrGLEffect::EffectKey GrGLEffect::GenTextureKey(const GrEffectRef* effect,
const GrGLCaps& caps) {
EffectKey key = 0;
int numTextures = (*drawEffect.effect())->numTextures();
for (int index = 0; index < numTextures; ++index) {
const GrTextureAccess& access = (*drawEffect.effect())->textureAccess(index);
for (int index = 0; index < (*effect)->numTextures(); ++index) {
const GrTextureAccess& access = (*effect)->textureAccess(index);
EffectKey value = GrGLShaderBuilder::KeyForTextureAccess(access, caps) << index;
GrAssert(0 == (value & key)); // keys for each access ought not to overlap
key |= value;
@ -34,12 +32,12 @@ GrGLEffect::EffectKey GrGLEffect::GenTextureKey(const GrDrawEffect& drawEffect,
return key;
}
GrGLEffect::EffectKey GrGLEffect::GenAttribKey(const GrDrawEffect& drawEffect) {
GrGLEffect::EffectKey GrGLEffect::GenAttribKey(const GrEffectStage& stage) {
EffectKey key = 0;
int numAttributes = drawEffect.getVertexAttribIndexCount();
int numAttributes = stage.getVertexAttribIndexCount();
GrAssert(numAttributes <= 2);
const int* attributeIndices = drawEffect.getVertexAttribIndices();
const int* attributeIndices = stage.getVertexAttribIndices();
for (int index = 0; index < numAttributes; ++index) {
EffectKey value = attributeIndices[index] << 3*index;
GrAssert(0 == (value & key)); // keys for each attribute ought not to overlap

View File

@ -12,6 +12,7 @@
#include "GrGLShaderBuilder.h"
#include "GrGLShaderVar.h"
#include "GrGLSL.h"
#include "GrEffectStage.h"
class GrGLTexture;
@ -20,20 +21,13 @@ class GrGLTexture;
include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the
GLSL code that implements a GrEffect and for uploading uniforms at draw time. They also
must have a function:
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&)
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&)
that is used to implement a program cache. When two GrEffects produce the same key this means
that their GrGLEffects would emit the same GLSL code.
The GrGLEffect subclass must also have a constructor of the form:
EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDrawEffect&)
The effect held by the GrDrawEffect is guaranteed to be of the type that generated the
GrGLEffect subclass instance.
These objects are created by the factory object returned by the GrEffect::getFactory().
*/
class GrDrawEffect;
class GrGLEffect {
public:
@ -56,10 +50,14 @@ public:
stages.
@param builder Interface used to emit code in the shaders.
@param drawEffect A wrapper on the effect that generated this program stage.
@param stage The effect stage that generated this program stage.
@param key The key that was computed by GenKey() from the generating GrEffect.
Only the bits indicated by GrBackendEffectFactory::kEffectKeyBits are
guaranteed to match the value produced by GenKey();
@param vertexCoords A vec2 in the VS that holds the position in local coords. This is either
the pre-view-matrix vertex position or if explicit per-vertex texture
coords are used with a stage then it is those coordinates. See
GrVertexLayout.
@param outputColor A predefined vec4 in the FS in which the stage should place its output
color (or coverage).
@param inputColor A vec4 that holds the input color to the stage in the FS. This may be
@ -72,8 +70,9 @@ public:
reads in the generated code.
*/
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectStage& stage,
EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) = 0;
@ -82,15 +81,34 @@ public:
key; this function reads data from a stage and uploads any uniform variables required
by the shaders created in emitCode(). The GrEffect installed in the GrEffectStage is
guaranteed to be of the same type that created this GrGLEffect and to have an identical
EffectKey as the one that created this GrGLEffect. Effects that use local coords have
to consider whether the GrEffectStage's coord change matrix should be used. When explicit
local coordinates are used it can be ignored. */
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&);
EffectKey as the one that created this GrGLEffect. */
virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
const char* name() const { return fFactory.name(); }
static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
static EffectKey GenAttribKey(const GrDrawEffect& stage);
static EffectKey GenTextureKey(const GrEffectRef*, const GrGLCaps&);
static EffectKey GenAttribKey(const GrEffectStage& stage);
/**
* GrGLEffect subclasses get passed a GrEffectStage in their emitCode and setData functions.
* The GrGLEffect usually needs to cast the stage's effect to the GrEffect subclass that
* generated the GrGLEffect. This helper does just that.
*/
template <typename T>
static const T& GetEffectFromStage(const GrEffectStage& effectStage) {
GrAssert(NULL != effectStage.getEffect());
return CastEffect<T>(*effectStage.getEffect());
}
/**
* Extracts the GrEffect from a GrEffectRef and down-casts to a GrEffect subclass. Usually used
* in a GrGLEffect subclass's constructor (which takes const GrEffectRef&).
*/
template <typename T>
static const T& CastEffect(const GrEffectRef& effectRef) {
GrAssert(NULL != effectRef.get());
return *static_cast<const T*>(effectRef.get());
}
protected:
const GrBackendEffectFactory& fFactory;

View File

@ -6,67 +6,58 @@
*/
#include "GrGLEffectMatrix.h"
#include "GrDrawEffect.h"
#include "GrTexture.h"
GrGLEffect::EffectKey GrGLEffectMatrix::GenKey(const SkMatrix& effectMatrix,
const GrDrawEffect& drawEffect,
CoordsType coordsType,
const SkMatrix& coordChangeMatrix,
const GrTexture* texture) {
EffectKey key = 0;
SkMatrix::TypeMask type0 = effectMatrix.getType();
SkMatrix::TypeMask type1;
if (GrEffect::kLocal_CoordsType == coordsType) {
type1 = drawEffect.getCoordChangeMatrix().getType();
} else {
if (drawEffect.programHasExplicitLocalCoords()) {
// We only make the key indicate that device coords are referenced when the local coords
// are not actually determined by positions.
key |= kPositionCoords_Flag;
}
type1 = SkMatrix::kIdentity_Mask;
}
SkMatrix::TypeMask type1 = coordChangeMatrix.getType();
static const int kNonTransMask = SkMatrix::kAffine_Mask |
SkMatrix::kScale_Mask |
SkMatrix::kPerspective_Mask;
int combinedTypes = type0 | type1;
bool reverseY = (NULL != texture) && kBottomLeft_GrSurfaceOrigin == texture->origin();
if (SkMatrix::kPerspective_Mask & combinedTypes) {
key |= kGeneral_MatrixType;
} else if (((SkMatrix::kAffine_Mask | SkMatrix::kScale_Mask) & combinedTypes) || reverseY) {
key |= kNoPersp_MatrixType;
} else if (SkMatrix::kTranslate_Mask & combinedTypes) {
key |= kTrans_MatrixType;
return kGeneral_Key;
} else if ((kNonTransMask & combinedTypes) || reverseY) {
return kNoPersp_Key;
} else if (kTrans_Key & combinedTypes) {
return kTrans_Key;
} else {
key |= kIdentity_MatrixType;
GrAssert(effectMatrix.isIdentity() && coordChangeMatrix.isIdentity());
return kIdentity_Key;
}
return key;
}
GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
const char* vertexCoords,
const char** fsCoordName,
const char** vsCoordName,
const char* suffix) {
GrSLType varyingType;
const char* uniName;
key &= kKeyMask;
switch (key & kMatrixTypeKeyMask) {
case kIdentity_MatrixType:
switch (key) {
case kIdentity_Key:
fUniType = kVoid_GrSLType;
varyingType = kVec2f_GrSLType;
break;
case kTrans_MatrixType:
case kTrans_Key:
fUniType = kVec2f_GrSLType;
uniName = "StageTranslate";
varyingType = kVec2f_GrSLType;
break;
case kNoPersp_MatrixType:
case kNoPersp_Key:
fUniType = kMat33f_GrSLType;
uniName = "StageMatrix";
varyingType = kVec2f_GrSLType;
break;
case kGeneral_MatrixType:
case kGeneral_Key:
fUniType = kMat33f_GrSLType;
uniName = "StageMatrix";
varyingType = kVec3f_GrSLType;
@ -98,38 +89,24 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
const char* fsVaryingName;
builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName);
const GrGLShaderVar* coords;
switch (fCoordsType) {
case GrEffect::kLocal_CoordsType:
GrAssert(!(kPositionCoords_Flag & key));
coords = &builder->localCoordsAttribute();
break;
case GrEffect::kPosition_CoordsType:
GrAssert((kPositionCoords_Flag & key) || !builder->hasExplicitLocalCoords());
coords = &builder->positionAttribute();
break;
default:
GrCrash("Unexpected coords type.");
}
// varying = matrix * coords (logically)
// varying = matrix * vertex-coords (logically)
switch (fUniType) {
case kVoid_GrSLType:
GrAssert(kVec2f_GrSLType == varyingType);
builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->c_str());
builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, vertexCoords);
break;
case kVec2f_GrSLType:
GrAssert(kVec2f_GrSLType == varyingType);
builder->vsCodeAppendf("\t%s = %s + %s;\n",
vsVaryingName, uniName, coords->c_str());
builder->vsCodeAppendf("\t%s = %s + %s;\n", vsVaryingName, uniName, vertexCoords);
break;
case kMat33f_GrSLType: {
GrAssert(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
if (kVec2f_GrSLType == varyingType) {
builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n",
vsVaryingName, uniName, coords->c_str());
vsVaryingName, uniName, vertexCoords);
} else {
builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n",
vsVaryingName, uniName, coords->c_str());
vsVaryingName, uniName, vertexCoords);
}
break;
}
@ -151,6 +128,7 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
*/
void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
EffectKey key,
const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName,
GrSLType* vsVaryingType,
@ -159,6 +137,7 @@ void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
GrSLType varyingType = this->emitCode(builder,
key,
vertexCoords,
&fsVaryingName,
vsVaryingName,
suffix);
@ -185,14 +164,11 @@ void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
}
void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
const SkMatrix& matrix,
const GrDrawEffect& drawEffect,
const GrTexture* texture) {
const SkMatrix& matrix,
const SkMatrix& coordChangeMatrix,
const GrTexture* texture) {
GrAssert((GrGLUniformManager::kInvalidUniformHandle == fUni) ==
(kVoid_GrSLType == fUniType));
const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsType ?
drawEffect.getCoordChangeMatrix() :
SkMatrix::I();
(kVoid_GrSLType == fUniType));
switch (fUniType) {
case kVoid_GrSLType:
GrAssert(matrix.isIdentity());
@ -202,8 +178,8 @@ void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
case kVec2f_GrSLType: {
GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChangeMatrix.getType()));
GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->origin());
SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMatrix::kMTransX];
SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMatrix::kMTransY];
SkScalar tx = matrix[SkMatrix::kMTransX] + coordChangeMatrix[SkMatrix::kMTransX];
SkScalar ty = matrix[SkMatrix::kMTransY] + coordChangeMatrix[SkMatrix::kMTransY];
if (fPrevMatrix.get(SkMatrix::kMTransX) != tx ||
fPrevMatrix.get(SkMatrix::kMTransY) != ty) {
uniformManager.set2f(fUni, tx, ty);

View File

@ -14,68 +14,34 @@
class GrTexture;
/**
* This is a helper to implement a matrix in a GrGLEffect that operates on incoming coords in the
* vertex shader and writes them to an attribute to be used in the fragment shader. When the input
* coords in the vertex shader are local coordinates this class accounts for the coord change matrix
* communicated via GrDrawEffect. The input coords may also be positions and in this case the coord
* change matrix is ignored. The GrGLEffectMatrix will emit different code based on the type of
* matrix and thus must contribute to the effect's key.
*
* This class cannot be used to apply a matrix to coordinates that come in the form of custom vertex
* attributes.
* This is a helper to implement a texture matrix in a GrGLEffect.
*/
class GrGLEffectMatrix {
private:
// We specialize the generated code for each of these matrix types.
enum MatrixTypes {
kIdentity_MatrixType = 0,
kTrans_MatrixType = 1,
kNoPersp_MatrixType = 2,
kGeneral_MatrixType = 3,
};
// The key for is made up of a matrix type and a bit that indicates the source of the input
// coords.
enum {
kMatrixTypeKeyBits = 2,
kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
kPositionCoords_Flag = (1 << kMatrixTypeKeyBits),
kKeyBitsPrivate = kMatrixTypeKeyBits + 1,
};
public:
typedef GrEffect::CoordsType CoordsType;
typedef GrGLEffect::EffectKey EffectKey;
/**
* The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may place these bits at an
* arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCode*() code is called
* the relevant bits must be in the lower kKeyBits of the key parameter.
*/
enum {
kKeyBits = kKeyBitsPrivate,
kKeyBits = 2,
kKeyMask = (1 << kKeyBits) - 1,
};
GrGLEffectMatrix(CoordsType coordsType)
: fUni(GrGLUniformManager::kInvalidUniformHandle)
, fCoordsType(coordsType) {
GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
GrEffect::kPosition_CoordsType == coordsType);
GrGLEffectMatrix() : fUni(GrGLUniformManager::kInvalidUniformHandle) {
fPrevMatrix = SkMatrix::InvalidMatrix();
}
/**
* Generates the key for the portion of the code emitted by this class's emitCode() function.
* Pass a texture to make GrGLEffectMatrix automatically adjust for the texture's origin. Pass
* NULL when not using the EffectMatrix for a texture lookup, or if the GrGLEffect subclass
* wants to handle origin adjustments in some other manner. The coords type param must match the
* param that would be used to initialize GrGLEffectMatrix for the generating GrEffect.
* NULL when not using the EffectMatrix for a texture lookups, or if the GrGLEffect subclass
* wants to handle origin adjustments in some other manner. coordChangeMatrix is the matrix
* from GrEffectStage.
*/
static EffectKey GenKey(const SkMatrix& effectMatrix,
const GrDrawEffect&,
CoordsType,
const SkMatrix& coordChangeMatrix,
const GrTexture*);
/**
@ -89,6 +55,7 @@ public:
*/
GrSLType emitCode(GrGLShaderBuilder*,
EffectKey,
const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsCoordName = NULL,
const char* suffix = NULL);
@ -99,23 +66,31 @@ public:
*/
void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
EffectKey,
const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL,
const char* suffix = NULL);
/**
* Call from a GrGLEffect's subclass to update the texture matrix. The effectMatrix and texture
* params should match those used with GenKey.
* Call from a GrGLEffect's subclass to update the texture matrix. The matrix,
* coordChangeMatrix, and texture params should match those used with GenKey.
*/
void setData(const GrGLUniformManager& uniformManager,
const SkMatrix& effectMatrix,
const GrDrawEffect& drawEffect,
const SkMatrix& coordChangeMatrix,
const GrTexture*);
private:
enum {
kIdentity_Key = 0,
kTrans_Key = 1,
kNoPersp_Key = 2,
kGeneral_Key = 3,
};
GrGLUniformManager::UniformHandle fUni;
GrSLType fUniType;
SkMatrix fPrevMatrix;
CoordsType fCoordsType;
};
#endif

View File

@ -9,7 +9,6 @@
#include "GrAllocator.h"
#include "GrEffect.h"
#include "GrDrawEffect.h"
#include "GrGLEffect.h"
#include "GrGpuGL.h"
#include "GrGLShaderVar.h"
@ -27,6 +26,7 @@ SK_DEFINE_INST_COUNT(GrGLProgram)
SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false,
"Print the source code for all shaders generated.");
#define TEX_ATTR_NAME "aTexCoord"
#define COL_ATTR_NAME "aColor"
#define COV_ATTR_NAME "aCoverage"
#define EDGE_ATTR_NAME "aEdge"
@ -134,10 +134,7 @@ void GrGLProgram::BuildDesc(const GrDrawState& drawState,
lastEnabledStage = s;
const GrEffectRef& effect = *drawState.getStage(s).getEffect();
const GrBackendEffectFactory& factory = effect->getFactory();
bool explicitLocalCoords = (drawState.getAttribBindings() &
GrDrawState::kLocalCoords_AttribBindingsBit);
GrDrawEffect drawEffect(drawState.getStage(s), explicitLocalCoords);
desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
desc->fEffectKeys[s] = factory.glEffectKey(drawState.getStage(s), gpu->glCaps());
} else {
desc->fEffectKeys[s] = 0;
}
@ -210,8 +207,8 @@ void GrGLProgram::BuildDesc(const GrDrawState& drawState,
if (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
desc->fEdgeAttributeIndex = drawState.getAttribIndex(GrDrawState::kEdge_AttribIndex);
}
if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
desc->fLocalCoordsAttributeIndex = drawState.getAttribIndex(GrDrawState::kLocalCoords_AttribIndex);
if (GrDrawState::AttributesBindExplicitTexCoords(desc->fAttribBindings)) {
desc->fTexCoordAttributeIndex = drawState.getAttribIndex(GrDrawState::kTexCoord_AttribIndex);
}
#if GR_DEBUG
@ -230,10 +227,10 @@ void GrGLProgram::BuildDesc(const GrDrawState& drawState,
if (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
GrAssert(desc->fEdgeAttributeIndex < GrDrawState::kVertexAttribCnt);
GrAssert(kAttribLayouts[vertexAttribs[desc->fEdgeAttributeIndex].fType].fCount == 4);
}
if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
GrAssert(desc->fLocalCoordsAttributeIndex < GrDrawState::kVertexAttribCnt);
GrAssert(kAttribLayouts[vertexAttribs[desc->fLocalCoordsAttributeIndex].fType].fCount == 2);
}
if (GrDrawState::AttributesBindExplicitTexCoords(desc->fAttribBindings)) {
GrAssert(desc->fTexCoordAttributeIndex < GrDrawState::kVertexAttribCnt);
GrAssert(kAttribLayouts[vertexAttribs[desc->fTexCoordAttributeIndex].fType].fCount == 2);
}
#endif
}
@ -682,10 +679,8 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) {
bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
GrAssert(0 == fProgramID);
GrGLShaderBuilder builder(fContext.info(), fUniformManager);
const GrAttribBindings& attribBindings = fDesc.fAttribBindings;
bool hasExplicitLocalCoords =
SkToBool(attribBindings & GrDrawState::kLocalCoords_AttribBindingsBit);
GrGLShaderBuilder builder(fContext.info(), fUniformManager, hasExplicitLocalCoords);
#if GR_GL_EXPERIMENTAL_GS
builder.fUsesGS = fDesc.fExperimentalGS;
@ -765,6 +760,11 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
builder.vsCodeAppend("\tgl_PointSize = 1.0;\n");
}
// add texture coordinates that are used to the list of vertex attr decls
if (GrDrawState::AttributesBindExplicitTexCoords(attribBindings)) {
builder.addAttribute(kVec2f_GrSLType, TEX_ATTR_NAME);
}
///////////////////////////////////////////////////////////////////////////
// compute the final color
@ -779,11 +779,21 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
outColor.appendS32(s);
builder.fsCodeAppendf("\tvec4 %s;\n", outColor.c_str());
const char* inCoords;
// figure out what our input coords are
if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is enabled.
inCoords = TEX_ATTR_NAME;
}
builder.setCurrentStage(s);
fEffects[s] = builder.createAndEmitGLEffect(*stages[s],
fDesc.fEffectKeys[s],
inColor.size() ? inColor.c_str() : NULL,
outColor.c_str(),
inCoords,
&fUniformHandles.fSamplerUnis[s]);
builder.setNonStage();
inColor = outColor;
@ -861,6 +871,16 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
outCoverage.appendS32(s);
builder.fsCodeAppendf("\tvec4 %s;\n", outCoverage.c_str());
const char* inCoords;
// figure out what our input coords are
if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
inCoords = builder.positionAttribute().c_str();
} else {
// must have input tex coordinates if stage is
// enabled.
inCoords = TEX_ATTR_NAME;
}
// stages don't know how to deal with a scalar input. (Maybe they should. We
// could pass a GrGLShaderVar)
if (inCoverageIsScalar) {
@ -874,6 +894,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
fDesc.fEffectKeys[s],
inCoverage.size() ? inCoverage.c_str() : NULL,
outCoverage.c_str(),
inCoords,
&fUniformHandles.fSamplerUnis[s]);
builder.setNonStage();
inCoverage = outCoverage;
@ -987,10 +1008,8 @@ bool GrGLProgram::bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& buil
if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
GL_CALL(BindAttribLocation(fProgramID, fDesc.fEdgeAttributeIndex, EDGE_ATTR_NAME));
}
if (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
GL_CALL(BindAttribLocation(fProgramID,
fDesc.fLocalCoordsAttributeIndex,
builder.localCoordsAttribute().c_str()));
if (GrDrawState::AttributesBindExplicitTexCoords(fDesc.fAttribBindings)) {
GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TEX_ATTR_NAME));
}
const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttributes().end();
@ -1069,11 +1088,7 @@ void GrGLProgram::setData(GrGpuGL* gpu,
if (NULL != fEffects[s]) {
const GrEffectStage& stage = drawState.getStage(s);
GrAssert(NULL != stage.getEffect());
bool explicitLocalCoords =
(fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit);
GrDrawEffect drawEffect(stage, explicitLocalCoords);
fEffects[s]->setData(fUniformManager, drawEffect);
fEffects[s]->setData(fUniformManager, stage);
int numSamplers = fUniformHandles.fSamplerUnis[s].count();
for (int u = 0; u < numSamplers; ++u) {
UniformHandle handle = fUniformHandles.fSamplerUnis[s][u];

View File

@ -192,7 +192,7 @@ public:
int8_t fColorAttributeIndex;
int8_t fCoverageAttributeIndex;
int8_t fEdgeAttributeIndex;
int8_t fLocalCoordsAttributeIndex;
int8_t fTexCoordAttributeIndex;
friend class GrGLProgram;
};

View File

@ -8,7 +8,6 @@
#include "gl/GrGLShaderBuilder.h"
#include "gl/GrGLProgram.h"
#include "gl/GrGLUniformHandle.h"
#include "GrDrawEffect.h"
#include "GrTexture.h"
// number of each input/output type in a single allocation block
@ -83,8 +82,7 @@ void append_swizzle(SkString* outAppend,
//const int GrGLShaderBuilder::fCoordDims = 2;
GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
GrGLUniformManager& uniformManager,
bool explicitLocalCoords)
GrGLUniformManager& uniformManager)
: fUniforms(kVarsPerBlock)
, fVSAttrs(kVarsPerBlock)
, fVSOutputs(kVarsPerBlock)
@ -101,14 +99,6 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
fPositionVar = &fVSAttrs.push_back();
fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition");
if (explicitLocalCoords) {
fLocalCoordsVar = &fVSAttrs.push_back();
fLocalCoordsVar->set(kVec2f_GrSLType,
GrGLShaderVar::kAttribute_TypeModifier,
"aLocalCoords");
} else {
fLocalCoordsVar = fPositionVar;
}
}
void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_list args) {
@ -504,6 +494,7 @@ GrGLEffect* GrGLShaderBuilder::createAndEmitGLEffect(
GrGLEffect::EffectKey key,
const char* fsInColor,
const char* fsOutColor,
const char* vsInCoord,
SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles) {
GrAssert(NULL != stage.getEffect());
@ -515,7 +506,6 @@ GrGLEffect* GrGLShaderBuilder::createAndEmitGLEffect(
textureSamplers[i].init(this, &effect->textureAccess(i), i);
samplerHandles->push_back(textureSamplers[i].fSamplerUniform);
}
GrDrawEffect drawEffect(stage, this->hasExplicitLocalCoords());
int numAttributes = stage.getVertexAttribIndexCount();
const int* attributeIndices = stage.getVertexAttribIndices();
@ -529,15 +519,15 @@ GrGLEffect* GrGLShaderBuilder::createAndEmitGLEffect(
}
}
GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
GrGLEffect* glEffect = effect->getFactory().createGLInstance(effect);
// Enclose custom code in a block to avoid namespace conflicts
this->fVSCode.appendf("\t{ // %s\n", glEffect->name());
this->fFSCode.appendf("\t{ // %s \n", glEffect->name());
glEffect->emitCode(this,
drawEffect,
stage,
key,
vsInCoord,
fsOutColor,
fsInColor,
textureSamplers);

View File

@ -80,7 +80,7 @@ public:
kFragment_ShaderType = 0x4,
};
GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, bool explicitLocalCoords);
GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&);
/**
* Called by GrGLEffects to add code to one of the shaders.
@ -205,16 +205,6 @@ public:
*/
const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
/** Returns a vertex attribute that represents the local coords in the VS. This may be the same
as positionAttribute() or it may not be. It depends upon whether the rendering code
specified explicit local coords or not in the GrDrawState. */
const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
/**
* Are explicit local coordinates provided as input to the vertex shader.
*/
bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
/**
* Interfaces used by GrGLProgram.
* TODO: Hide these from the GrEffects using friend or splitting this into two related classes.
@ -233,6 +223,7 @@ public:
GrBackendEffectFactory::EffectKey key,
const char* fsInColor, // NULL means no incoming color
const char* fsOutColor,
const char* vsInCoord,
SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles);
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
@ -299,8 +290,6 @@ private:
SkSTArray<10, AttributePair, true> fEffectAttributes;
GrGLShaderVar* fPositionVar;
GrGLShaderVar* fLocalCoordsVar;
};
#endif

View File

@ -15,7 +15,6 @@
#include "gl/GrGpuGL.h"
#include "GrBackendEffectFactory.h"
#include "GrContextFactory.h"
#include "GrDrawEffect.h"
#include "effects/GrConfigConversionEffect.h"
#include "SkRandom.h"
@ -58,18 +57,16 @@ void GrGLProgram::Desc::setRandom(SkMWCRandom* random,
fDualSrcOutput = kNone_DualSrcOutput;
}
// use separate tex coords?
if (random->nextBool()) {
fAttribBindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
}
bool useOnce = false;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (NULL != stages[s].getEffect()) {
const GrBackendEffectFactory& factory = (*stages[s].getEffect())->getFactory();
bool explicitLocalCoords = (fAttribBindings &
GrDrawState::kLocalCoords_AttribBindingsBit);
GrDrawEffect drawEffect(stages[s], explicitLocalCoords);
fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
fEffectKeys[s] = factory.glEffectKey(stages[s], gpu->glCaps());
// use separate tex coords?
if (!useOnce && random->nextBool()) {
fAttribBindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(s);
useOnce = true;
}
}
}
@ -88,8 +85,8 @@ void GrGLProgram::Desc::setRandom(SkMWCRandom* random,
fEdgeAttributeIndex = attributeIndex;
++attributeIndex;
}
if (fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
fLocalCoordsAttributeIndex = attributeIndex;
if (GrDrawState::AttributesBindExplicitTexCoords(fAttribBindings)) {
fTexCoordAttributeIndex = attributeIndex;
++attributeIndex;
}
}