GrMatrix tm;
tm = vm;
tm.postIDiv(2*S, 2*S);
- paint.colorSampler(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
- (texture)), tm)->unref();
+ paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
+ (texture)), tm)->unref();
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
'<(skia_include_path)/gpu/GrContext.h',
'<(skia_include_path)/gpu/GrContextFactory.h',
'<(skia_include_path)/gpu/GrEffect.h',
+ '<(skia_include_path)/gpu/GrEffectStage.h',
'<(skia_include_path)/gpu/GrEffectUnitTest.h',
'<(skia_include_path)/gpu/GrFontScaler.h',
'<(skia_include_path)/gpu/GrGlyph.h',
'<(skia_include_path)/gpu/GrRefCnt.h',
'<(skia_include_path)/gpu/GrRenderTarget.h',
'<(skia_include_path)/gpu/GrResource.h',
- '<(skia_include_path)/gpu/GrSamplerState.h',
'<(skia_include_path)/gpu/GrScalar.h',
'<(skia_include_path)/gpu/GrSurface.h',
'<(skia_include_path)/gpu/GrTextContext.h',
class SkPath;
class GrContext;
class GrEffect;
-class GrSamplerState;
+class GrEffectStage;
/** \class SkShader
*
virtual GradientType asAGradient(GradientInfo* info) const;
/**
- * If the shader subclass has a GrEffect implementation, this installs
- * an effect on the sampler. A GrContext pointer is required since custom
- * stages may need to create textures. The sampler parameter is necessary to set a
- * texture matrix. It will eventually be removed and this function will operate as a
- * GrEffect factory.
+ * If the shader subclass has a GrEffect implementation, this installs an effect on the stage.
+ * A GrContext pointer is required since effects may need to create textures. The stage
+ * parameter is necessary to set a texture matrix. It will eventually be removed and this
+ * function will operate as a GrEffect factory.
*/
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const;
//////////////////////////////////////////////////////////////////////////
// Factory methods for stock shaders
--- /dev/null
+
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+
+#ifndef GrSamplerState_DEFINED
+#define GrSamplerState_DEFINED
+
+#include "GrEffect.h"
+#include "GrMatrix.h"
+#include "GrTypes.h"
+
+#include "SkShader.h"
+
+class GrEffectStage {
+public:
+
+ GrEffectStage()
+ : fEffect (NULL) {
+ GR_DEBUGCODE(fSavedCoordChangeCnt = 0;)
+ }
+
+ ~GrEffectStage() {
+ GrSafeUnref(fEffect);
+ GrAssert(0 == fSavedCoordChangeCnt);
+ }
+
+ bool operator ==(const GrEffectStage& other) const {
+ // first handle cases where one or the other has no effect
+ if (NULL == fEffect) {
+ return NULL == other.fEffect;
+ } else if (NULL == other.fEffect) {
+ return false;
+ }
+
+ if (fEffect->getFactory() != other.fEffect->getFactory()) {
+ return false;
+ }
+
+ if (!fEffect->isEqual(*other.fEffect)) {
+ return false;
+ }
+
+ return fMatrix == other.fMatrix && fCoordChangeMatrix == other.fCoordChangeMatrix;
+ }
+
+ bool operator !=(const GrEffectStage& s) const { return !(*this == s); }
+
+ GrEffectStage& operator =(const GrEffectStage& other) {
+ GrSafeAssign(fEffect, other.fEffect);
+ if (NULL != fEffect) {
+ fMatrix = other.fMatrix;
+ fCoordChangeMatrix = other.fCoordChangeMatrix;
+ }
+ return *this;
+ }
+
+ /**
+ * This is called when the coordinate system in which the geometry is specified will change.
+ *
+ * @param matrix The transformation from the old coord system to the new one.
+ */
+ void preConcatCoordChange(const GrMatrix& matrix) { fCoordChangeMatrix.preConcat(matrix); }
+
+ class SavedCoordChange {
+ private:
+ GrMatrix fCoordChangeMatrix;
+ GR_DEBUGCODE(mutable SkAutoTUnref<GrEffect> fEffect;)
+
+ friend class GrEffectStage;
+ };
+
+ /**
+ * This gets the current coordinate system change. It is the accumulation of
+ * 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).s
+ */
+ void saveCoordChange(SavedCoordChange* savedCoordChange) const {
+ savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
+ GrAssert(NULL == savedCoordChange->fEffect.get());
+ GR_DEBUGCODE(GrSafeRef(fEffect);)
+ GR_DEBUGCODE(savedCoordChange->fEffect.reset(fEffect);)
+ GR_DEBUGCODE(++fSavedCoordChangeCnt);
+ }
+
+ /**
+ * This balances the saveCoordChange call.
+ */
+ void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
+ fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
+ GrAssert(savedCoordChange.fEffect.get() == fEffect);
+ GR_DEBUGCODE(--fSavedCoordChangeCnt);
+ GR_DEBUGCODE(savedCoordChange.fEffect.reset(NULL);)
+ }
+
+ /**
+ * Gets the texture matrix. This is will be removed soon and be managed by GrEffect.
+ */
+ const GrMatrix& getMatrix() const { return fMatrix; }
+
+ /**
+ * Gets the matrix to apply at draw time. This is the original texture matrix combined with
+ * any coord system changes.
+ */
+ void getTotalMatrix(GrMatrix* matrix) const {
+ *matrix = fMatrix;
+ matrix->preConcat(fCoordChangeMatrix);
+ }
+
+ void reset() {
+ GrSafeSetNull(fEffect);
+ }
+
+ GrEffect* setEffect(GrEffect* effect) {
+ GrAssert(0 == fSavedCoordChangeCnt);
+ GrSafeAssign(fEffect, effect);
+ fMatrix.reset();
+ fCoordChangeMatrix.reset();
+ return effect;
+ }
+
+ GrEffect* setEffect(GrEffect* effect, const GrMatrix& matrix) {
+ GrAssert(0 == fSavedCoordChangeCnt);
+ GrSafeAssign(fEffect, effect);
+ fMatrix = matrix;
+ fCoordChangeMatrix.reset();
+ return effect;
+ }
+
+ const GrEffect* getEffect() const { return fEffect; }
+
+private:
+ GrMatrix fCoordChangeMatrix;
+ GrMatrix fMatrix; // TODO: remove this, store in GrEffect
+ GrEffect* fEffect;
+
+ GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
+};
+
+#endif
+
#define GrPaint_DEFINED
#include "GrColor.h"
-#include "GrSamplerState.h"
+#include "GrEffectStage.h"
#include "SkXfermode.h"
/**
* Specifies a stage of the color pipeline. Usually the texture matrices of color stages apply
* to the primitive's positions. Some GrContext calls take explicit coords as an array or a
- * rect. In this case these are the pre-matrix coords to colorSampler(0).
+ * rect. In this case these are the pre-matrix coords to colorStage(0).
*/
- GrSamplerState* colorSampler(int i) {
+ GrEffectStage* colorStage(int i) {
GrAssert((unsigned)i < kMaxColorStages);
- return fColorSamplers + i;
+ return fColorStages + i;
}
- const GrSamplerState& getColorSampler(int i) const {
+ const GrEffectStage& getColorStage(int i) const {
GrAssert((unsigned)i < kMaxColorStages);
- return fColorSamplers[i];
+ return fColorStages[i];
}
bool isColorStageEnabled(int i) const {
GrAssert((unsigned)i < kMaxColorStages);
- return (NULL != fColorSamplers[i].getEffect());
+ return (NULL != fColorStages[i].getEffect());
}
/**
* Specifies a stage of the coverage pipeline. Coverage stages' texture matrices are always
* applied to the primitive's position, never to explicit texture coords.
*/
- GrSamplerState* coverageSampler(int i) {
+ GrEffectStage* coverageStage(int i) {
GrAssert((unsigned)i < kMaxCoverageStages);
- return fCoverageSamplers + i;
+ return fCoverageStages + i;
}
- const GrSamplerState& getCoverageSampler(int i) const {
+ const GrEffectStage& getCoverageStage(int i) const {
GrAssert((unsigned)i < kMaxCoverageStages);
- return fCoverageSamplers[i];
+ return fCoverageStages[i];
}
bool isCoverageStageEnabled(int i) const {
GrAssert((unsigned)i < kMaxCoverageStages);
- return (NULL != fCoverageSamplers[i].getEffect());
+ return (NULL != fCoverageStages[i].getEffect());
}
bool hasCoverageStage() const {
} else {
computed = true;
}
- fColorSamplers[i].preConcatCoordChange(inv);
+ fColorStages[i].preConcatCoordChange(inv);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
} else {
computed = true;
}
- fCoverageSamplers[i].preConcatCoordChange(inv);
+ fCoverageStages[i].preConcatCoordChange(inv);
}
}
return true;
void sourceCoordChange(const GrMatrix& preConcat) {
for (int i = 0; i < kMaxColorStages; ++i) {
if (this->isColorStageEnabled(i)) {
- fColorSamplers[i].preConcatCoordChange(preConcat);
+ fColorStages[i].preConcatCoordChange(preConcat);
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (this->isCoverageStageEnabled(i)) {
- fCoverageSamplers[i].preConcatCoordChange(preConcat);
+ fCoverageStages[i].preConcatCoordChange(preConcat);
}
}
}
for (int i = 0; i < kMaxColorStages; ++i) {
if (paint.isColorStageEnabled(i)) {
- fColorSamplers[i] = paint.fColorSamplers[i];
+ fColorStages[i] = paint.fColorStages[i];
}
}
for (int i = 0; i < kMaxCoverageStages; ++i) {
if (paint.isCoverageStageEnabled(i)) {
- fCoverageSamplers[i] = paint.fCoverageSamplers[i];
+ fCoverageStages[i] = paint.fCoverageStages[i];
}
}
return *this;
this->resetOptions();
this->resetColor();
this->resetCoverage();
- this->resetTextures();
+ this->resetStages();
this->resetColorFilter();
- this->resetMasks();
}
// internal use
private:
- GrSamplerState fColorSamplers[kMaxColorStages];
- GrSamplerState fCoverageSamplers[kMaxCoverageStages];
+ GrEffectStage fColorStages[kMaxColorStages];
+ GrEffectStage fCoverageStages[kMaxCoverageStages];
GrBlendCoeff fSrcBlendCoeff;
GrBlendCoeff fDstBlendCoeff;
fCoverage = 0xff;
}
- void resetTextures() {
+ void resetStages() {
for (int i = 0; i < kMaxColorStages; ++i) {
- fColorSamplers[i].reset();
+ fColorStages[i].reset();
}
- }
-
- void resetMasks() {
for (int i = 0; i < kMaxCoverageStages; ++i) {
- fCoverageSamplers[i].reset();
+ fCoverageStages[i].reset();
}
}
};
+++ /dev/null
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrSamplerState_DEFINED
-#define GrSamplerState_DEFINED
-
-#include "GrEffect.h"
-#include "GrMatrix.h"
-#include "GrTypes.h"
-
-#include "SkShader.h"
-
-class GrSamplerState {
-public:
-
- GrSamplerState()
- : fEffect (NULL) {
- GR_DEBUGCODE(fSavedCoordChangeCnt = 0;)
- }
-
- ~GrSamplerState() {
- GrSafeUnref(fEffect);
- GrAssert(0 == fSavedCoordChangeCnt);
- }
-
- bool operator ==(const GrSamplerState& other) const {
- // first handle cases where one or the other has no effect
- if (NULL == fEffect) {
- return NULL == other.fEffect;
- } else if (NULL == other.fEffect) {
- return false;
- }
-
- if (fEffect->getFactory() != other.fEffect->getFactory()) {
- return false;
- }
-
- if (!fEffect->isEqual(*other.fEffect)) {
- return false;
- }
-
- return fMatrix == other.fMatrix && fCoordChangeMatrix == other.fCoordChangeMatrix;
- }
-
- bool operator !=(const GrSamplerState& s) const { return !(*this == s); }
-
- GrSamplerState& operator =(const GrSamplerState& other) {
- GrSafeAssign(fEffect, other.fEffect);
- if (NULL != fEffect) {
- fMatrix = other.fMatrix;
- fCoordChangeMatrix = other.fCoordChangeMatrix;
- }
- return *this;
- }
-
- /**
- * This is called when the coordinate system in which the geometry is specified will change.
- *
- * @param matrix The transformation from the old coord system to the new one.
- */
- void preConcatCoordChange(const GrMatrix& matrix) { fCoordChangeMatrix.preConcat(matrix); }
-
- class SavedCoordChange {
- private:
- GrMatrix fCoordChangeMatrix;
- GR_DEBUGCODE(mutable SkAutoTUnref<GrEffect> fEffect;)
-
- friend class GrSamplerState;
- };
-
- /**
- * This gets the current coordinate system change. It is the accumulation of
- * 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).s
- */
- void saveCoordChange(SavedCoordChange* savedCoordChange) const {
- savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
- GrAssert(NULL == savedCoordChange->fEffect.get());
- GR_DEBUGCODE(GrSafeRef(fEffect);)
- GR_DEBUGCODE(savedCoordChange->fEffect.reset(fEffect);)
- GR_DEBUGCODE(++fSavedCoordChangeCnt);
- }
-
- /**
- * This balances the saveCoordChange call.
- */
- void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
- fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
- GrAssert(savedCoordChange.fEffect.get() == fEffect);
- GR_DEBUGCODE(--fSavedCoordChangeCnt);
- GR_DEBUGCODE(savedCoordChange.fEffect.reset(NULL);)
- }
-
- /**
- * Gets the texture matrix. This is will be removed soon and be managed by GrEffect.
- */
- const GrMatrix& getMatrix() const { return fMatrix; }
-
- /**
- * Gets the matrix to apply at draw time. This is the original texture matrix combined with
- * any coord system changes.
- */
- void getTotalMatrix(GrMatrix* matrix) const {
- *matrix = fMatrix;
- matrix->preConcat(fCoordChangeMatrix);
- }
-
- void reset() {
- GrSafeSetNull(fEffect);
- }
-
- GrEffect* setEffect(GrEffect* effect) {
- GrAssert(0 == fSavedCoordChangeCnt);
- GrSafeAssign(fEffect, effect);
- fMatrix.reset();
- fCoordChangeMatrix.reset();
- return effect;
- }
-
- GrEffect* setEffect(GrEffect* effect, const GrMatrix& matrix) {
- GrAssert(0 == fSavedCoordChangeCnt);
- GrSafeAssign(fEffect, effect);
- fMatrix = matrix;
- fCoordChangeMatrix.reset();
- return effect;
- }
-
- const GrEffect* getEffect() const { return fEffect; }
-
-private:
- GrMatrix fCoordChangeMatrix;
- GrMatrix fMatrix; // TODO: remove this, store in GrEffect
- GrEffect* fEffect;
-
- GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
-};
-
-#endif
-
return kNone_GradientType;
}
-bool SkShader::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkShader::asNewEffect(GrContext*, GrEffectStage*) const {
return false;
}
backgroundTexMatrix.setIDiv(background->width(), background->height());
foregroundTexMatrix.setIDiv(foreground->width(), foreground->height());
GrPaint paint;
- paint.colorSampler(0)->setEffect(
+ paint.colorStage(0)->setEffect(
SkNEW_ARGS(GrSingleTextureEffect, (background.get())), backgroundTexMatrix)->unref();
- paint.colorSampler(1)->setEffect(
+ paint.colorStage(1)->setEffect(
SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())), foregroundTexMatrix)->unref();
context->drawRect(paint, rect);
return dst;
SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(width), SkIntToScalar(height)),
inset));
- GrSamplerState sampler;
GrEffect* effect;
filter->asNewEffect(&effect, textures[0]);
GrAssert(NULL != effect);
GrMatrix sampleM;
sampleM.setIDiv(texture->width(), texture->height());
GrPaint paint;
- paint.colorSampler(0)->setEffect(SkNEW_ARGS(GrMorphologyEffect, (texture, direction, radius, morphType)), sampleM)->unref();
+ paint.colorStage(0)->setEffect(SkNEW_ARGS(GrMorphologyEffect, (texture, direction, radius, morphType)), sampleM)->unref();
context->drawRect(paint, rect);
}
#include "gl/GrGLEffect.h"
-class GrSamplerState;
+class GrEffectStage;
class GrBackendEffectFactory;
/*
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points,
colors, stops, colorCount,
tm));
- GrSamplerState sampler;
- shader->asNewEffect(context, &sampler);
- GrAssert(NULL != sampler.getEffect());
+ GrEffectStage stage;
+ shader->asNewEffect(context, &stage);
+ GrAssert(NULL != stage.getEffect());
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
- sampler.getEffect()->ref();
- return const_cast<GrEffect*>(sampler.getEffect());
+ stage.getEffect()->ref();
+ return const_cast<GrEffect*>(stage.getEffect());
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-bool SkLinearGradient::asNewEffect(GrContext* context, GrSamplerState* sampler) const {
- SkASSERT(NULL != context && NULL != sampler);
+bool SkLinearGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
+ SkASSERT(NULL != context && NULL != stage);
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode)));
return false;
}
matrix.postConcat(fPtsToUnit);
- sampler->setEffect(effect, matrix);
+ stage->setEffect(effect, matrix);
} else {
- sampler->setEffect(effect, fPtsToUnit);
+ stage->setEffect(effect, fPtsToUnit);
}
return true;
#else
-bool SkLinearGradient::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkLinearGradient::asNewEffect(GrContext*, GrEffectStage*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius,
colors, stops, colorCount,
tm));
- GrSamplerState sampler;
- shader->asNewEffect(context, &sampler);
- GrAssert(NULL != sampler.getEffect());
+ GrEffectStage stage;
+ shader->asNewEffect(context, &stage);
+ GrAssert(NULL != stage.getEffect());
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
- sampler.getEffect()->ref();
- return const_cast<GrEffect*>(sampler.getEffect());
+ stage.getEffect()->ref();
+ return const_cast<GrEffect*>(stage.getEffect());
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-bool SkRadialGradient::asNewEffect(GrContext* context, GrSamplerState* sampler) const {
- SkASSERT(NULL != context && NULL != sampler);
+bool SkRadialGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
+ SkASSERT(NULL != context && NULL != stage);
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)));
SkMatrix matrix;
return false;
}
matrix.postConcat(fPtsToUnit);
- sampler->setEffect(effect, matrix);
+ stage->setEffect(effect, matrix);
} else {
- sampler->setEffect(effect, fPtsToUnit);
+ stage->setEffect(effect, fPtsToUnit);
}
return true;
#else
-bool SkRadialGradient::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkRadialGradient::asNewEffect(GrContext*, GrEffectStage*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
SkMatrix* matrix,
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored);
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
colors, stops, colorCount));
- GrSamplerState sampler;
- shader->asNewEffect(context, &sampler);
- GrAssert(NULL != sampler.getEffect());
+ GrEffectStage stage;
+ shader->asNewEffect(context, &stage);
+ GrAssert(NULL != stage.getEffect());
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
- sampler.getEffect()->ref();
- return const_cast<GrEffect*>(sampler.getEffect());
+ stage.getEffect()->ref();
+ return const_cast<GrEffect*>(stage.getEffect());
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-bool SkSweepGradient::asNewEffect(GrContext* context, GrSamplerState* sampler) const {
+bool SkSweepGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSweepGradient, (context, *this)));
SkMatrix matrix;
return false;
}
matrix.postConcat(fPtsToUnit);
- sampler->setEffect(effect, matrix);
+ stage->setEffect(effect, matrix);
} else {
- sampler->setEffect(effect, fPtsToUnit);
+ stage->setEffect(effect, fPtsToUnit);
}
return true;
#else
-bool SkSweepGradient::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkSweepGradient::asNewEffect(GrContext*, GrEffectStage*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
center2, radius2,
colors, stops, colorCount,
tm));
- GrSamplerState sampler;
- shader->asNewEffect(context, &sampler);
- GrAssert(NULL != sampler.getEffect());
+ GrEffectStage stage;
+ shader->asNewEffect(context, &stage);
+ GrAssert(NULL != stage.getEffect());
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
- sampler.getEffect()->ref();
- return const_cast<GrEffect*>(sampler.getEffect());
+ stage.getEffect()->ref();
+ return const_cast<GrEffect*>(stage.getEffect());
}
/////////////////////////////////////////////////////////////////////
bool SkTwoPointConicalGradient::asNewEffect(GrContext* context,
- GrSamplerState* sampler) const {
- SkASSERT(NULL != context && NULL != sampler);
+ GrEffectStage* stage) const {
+ SkASSERT(NULL != context && NULL != stage);
SkMatrix matrix;
SkPoint diff = fCenter2 - fCenter1;
matrix.preConcat(localM);
}
- sampler->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode)), matrix)->unref();
return true;
}
#else
-bool SkTwoPointConicalGradient::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkTwoPointConicalGradient::asNewEffect(GrContext*, GrEffectStage*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
SkMatrix* matrix,
TileMode* xy) const;
virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
SkScalar getStartRadius() const { return fRadius1; }
center2, radius2,
colors, stops, colorCount,
tm));
- GrSamplerState sampler;
- shader->asNewEffect(context, &sampler);
- GrAssert(NULL != sampler.getEffect());
+ GrEffectStage stage;
+ shader->asNewEffect(context, &stage);
+ GrAssert(NULL != stage.getEffect());
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
- sampler.getEffect()->ref();
- return const_cast<GrEffect*>(sampler.getEffect());
+ stage.getEffect()->ref();
+ return const_cast<GrEffect*>(stage.getEffect());
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
bool SkTwoPointRadialGradient::asNewEffect(GrContext* context,
- GrSamplerState* sampler) const {
- SkASSERT(NULL != context && NULL != sampler);
+ GrEffectStage* stage) const {
+ SkASSERT(NULL != context && NULL != stage);
SkScalar diffLen = fDiff.length();
SkMatrix matrix;
if (0 != diffLen) {
matrix.preConcat(localM);
}
- sampler->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode)), matrix)->unref();
return true;
}
#else
-bool SkTwoPointRadialGradient::asNewEffect(GrContext*, GrSamplerState*) const {
+bool SkTwoPointRadialGradient::asNewEffect(GrContext*, GrEffectStage*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
SkMatrix* matrix,
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext* context, GrSamplerState* sampler) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
int count) SK_OVERRIDE;
////////////////////////////////////////////////////////////////////////////////
namespace {
// set up the draw state to enable the aa clipping mask. Besides setting up the
-// sampler matrix this also alters the vertex layout
+// stage matrix this also alters the vertex layout
void setup_drawstate_aaclip(GrGpu* gpu,
GrTexture* result,
const GrIRect &devBound) {
SkIntToScalar(-devBound.fTop));
mat.preConcat(drawState->getViewMatrix());
- drawState->sampler(kMaskStage)->reset();
+ drawState->stage(kMaskStage)->reset();
drawState->createTextureEffect(kMaskStage, result, mat);
}
SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
(texture, direction, radius,
sigma)));
- drawState->sampler(0)->setEffect(conv, sampleM);
+ drawState->stage(0)->setEffect(conv, sampleM);
target->drawSimpleRect(rect, NULL);
}
texture->releaseRenderTarget();
} else {
// TODO: Our CPU stretch doesn't filter. But we create separate
- // stretched textures when the sampler state is either filtered or
+ // stretched textures when the texture params is either filtered or
// not. Either implement filtered stretch blit on CPU or just create
// one when FBO case fails.
rtDesc.fWidth = GrNextPow2(desc.fWidth);
rtDesc.fHeight = GrNextPow2(desc.fHeight);
int bpp = GrBytesPerPixel(desc.fConfig);
- SkAutoSMalloc<128*128*4> stretchedPixels(bpp *
- rtDesc.fWidth *
- rtDesc.fHeight);
+ SkAutoSMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight);
stretchImage(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight,
- srcData, desc.fWidth, desc.fHeight, bpp);
+ srcData, desc.fWidth, desc.fHeight, bpp);
size_t stretchedRowBytes = rtDesc.fWidth * bpp;
- GrTexture* texture = fGpu->createTexture(rtDesc,
- stretchedPixels.get(),
- stretchedRowBytes);
+ GrTexture* texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRowBytes);
GrAssert(NULL != texture);
}
}
}
- // If the caller gives us the same desc/sampler twice we don't want
- // to return the same texture the second time (unless it was previously
- // released). So make it exclusive to hide it from future searches.
+ // If the caller gives us the same desc twice we don't want to return the
+ // same texture the second time (unless it was previously released). So
+ // make it exclusive to hide it from future searches.
if (NULL != resource) {
fTextureCache->makeExclusive(resource->getCacheEntry());
}
m.postConcat(*srcMatrix);
}
- drawState->sampler(GrPaint::kFirstColorStage)->preConcatCoordChange(m);
+ drawState->stage(GrPaint::kFirstColorStage)->preConcatCoordChange(m);
const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
if (NULL == sqVB) {
matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
}
matrix.postIDiv(src->width(), src->height());
- drawState->sampler(0)->setEffect(effect, matrix);
+ drawState->stage(0)->setEffect(effect, matrix);
GrRect rect = GrRect::MakeWH(GrIntToScalar(width), GrIntToScalar(height));
fGpu->drawSimpleRect(rect, NULL);
// we want to read back from the scratch's origin
drawState->setRenderTarget(target);
matrix.setIDiv(texture->width(), texture->height());
- drawState->sampler(0)->setEffect(effect, matrix);
+ drawState->stage(0)->setEffect(effect, matrix);
fGpu->drawSimpleRect(GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), NULL);
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
- paint.colorSampler(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
- (srcTexture, true)), matrix)->unref();
+ paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
+ (srcTexture, true)), matrix)->unref();
this->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
// FIXME: This should be mitchell, not bilinear.
matrix.setIDiv(srcTexture->width(), srcTexture->height());
this->setRenderTarget(dstTexture->asRenderTarget());
- paint.colorSampler(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,(srcTexture, true)),
- matrix)->unref();
+ paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,(srcTexture, true)),
+ matrix)->unref();
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
this->drawRectToRect(paint, dstRect, srcRect);
for (int i = 0; i < GrPaint::kMaxColorStages; ++i) {
int s = i + GrPaint::kFirstColorStage;
if (paint.isColorStageEnabled(i)) {
- *this->sampler(s) = paint.getColorSampler(i);
+ *this->stage(s) = paint.getColorStage(i);
}
}
for (int i = 0; i < GrPaint::kMaxCoverageStages; ++i) {
int s = i + GrPaint::kFirstCoverageStage;
if (paint.isCoverageStageEnabled(i)) {
- *this->sampler(s) = paint.getCoverageSampler(i);
+ *this->stage(s) = paint.getCoverageStage(i);
}
}
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- fDrawState->sampler(s)->restoreCoordChange(fSavedCoordChanges[s]);
+ fDrawState->stage(s)->restoreCoordChange(fSavedCoordChanges[s]);
}
}
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
- fDrawState->sampler(s)->saveCoordChange(&fSavedCoordChanges[s]);
- drawState->sampler(s)->preConcatCoordChange(preconcatMatrix);
+ fDrawState->stage(s)->saveCoordChange(&fSavedCoordChanges[s]);
+ drawState->stage(s)->preConcatCoordChange(preconcatMatrix);
}
}
}
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- fDrawState->sampler(s)->restoreCoordChange(fSavedCoordChanges[s]);
+ fDrawState->stage(s)->restoreCoordChange(fSavedCoordChanges[s]);
}
}
}
inverted = true;
}
fRestoreMask |= (1 << s);
- GrSamplerState* sampler = drawState->sampler(s);
- sampler->saveCoordChange(&fSavedCoordChanges[s]);
- sampler->preConcatCoordChange(invVM);
+ GrEffectStage* stage = drawState->stage(s);
+ stage->saveCoordChange(&fSavedCoordChanges[s]);
+ stage->preConcatCoordChange(invVM);
}
}
drawState->viewMatrix()->reset();
#include "GrColor.h"
#include "GrMatrix.h"
#include "GrRefCnt.h"
-#include "GrSamplerState.h"
+#include "GrEffectStage.h"
#include "GrStencil.h"
#include "GrTexture.h"
#include "GrRenderTarget.h"
/**
* Resets to the default state.
- * Sampler states *will* be modified: textures or GrEffect objects will be released.
+ * GrEffects will be removed from all stages.
*/
void reset() {
/**
* Creates a GrSingleTextureEffect.
*/
- void createTextureEffect(int stage, GrTexture* texture) {
- GrAssert(!this->getSampler(stage).getEffect());
- this->sampler(stage)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
+ void createTextureEffect(int stageIdx, GrTexture* texture) {
+ GrAssert(!this->getStage(stageIdx).getEffect());
+ this->stage(stageIdx)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
}
- void createTextureEffect(int stage, GrTexture* texture, const GrMatrix& matrix) {
- GrAssert(!this->getSampler(stage).getEffect());
+ void createTextureEffect(int stageIdx, GrTexture* texture, const GrMatrix& matrix) {
+ GrAssert(!this->getStage(stageIdx).getEffect());
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture));
- this->sampler(stage)->setEffect(effect, matrix)->unref();
+ this->stage(stageIdx)->setEffect(effect, matrix)->unref();
}
- void createTextureEffect(int stage, GrTexture* texture,
+ void createTextureEffect(int stageIdx,
+ GrTexture* texture,
const GrMatrix& matrix,
const GrTextureParams& params) {
- GrAssert(!this->getSampler(stage).getEffect());
+ GrAssert(!this->getStage(stageIdx).getEffect());
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, params));
- this->sampler(stage)->setEffect(effect, matrix)->unref();
+ this->stage(stageIdx)->setEffect(effect, matrix)->unref();
}
bool stagesDisabled() {
for (int i = 0; i < kNumStages; ++i) {
- if (NULL != fSamplerStates[i].getEffect()) {
+ if (NULL != fStages[i].getEffect()) {
return false;
}
}
return true;
}
- void disableStage(int index) {
- fSamplerStates[index].setEffect(NULL);
+ void disableStage(int stageIdx) {
+ fStages[stageIdx].setEffect(NULL);
}
/**
/// @}
///////////////////////////////////////////////////////////////////////////
- /// @name Samplers
+ /// @name Stages
////
/**
- * Returns the current sampler for a stage.
+ * Returns the current stage by index.
*/
- const GrSamplerState& getSampler(int stage) const {
- GrAssert((unsigned)stage < kNumStages);
- return fSamplerStates[stage];
+ const GrEffectStage& getStage(int stageIdx) const {
+ GrAssert((unsigned)stageIdx < kNumStages);
+ return fStages[stageIdx];
}
/**
- * Writable pointer to a stage's sampler.
+ * Writable pointer to a stage.
*/
- GrSamplerState* sampler(int stage) {
- GrAssert((unsigned)stage < kNumStages);
- return fSamplerStates + stage;
+ GrEffectStage* stage(int stageIdx) {
+ GrAssert((unsigned)stageIdx < kNumStages);
+ return fStages + stageIdx;
}
/**
* Called when the source coord system is changing. preConcat gives the transformation from the
* old coord system to the new coord system.
*/
- void preConcatSamplerMatrices(const GrMatrix& preConcat) {
+ void preConcatStageMatrices(const GrMatrix& preConcat) {
for (int i = 0; i < kNumStages; ++i) {
if (this->isStageEnabled(i)) {
- fSamplerStates[i].preConcatCoordChange(preConcat);
+ fStages[i].preConcatCoordChange(preConcat);
}
}
}
* transformation from the old coord system to the new coord system. Returns false if the matrix
* cannot be inverted.
*/
- bool preConcatSamplerMatricesWithInverse(const GrMatrix& preConcatInverse) {
+ bool preConcatStageMatricesWithInverse(const GrMatrix& preConcatInverse) {
GrMatrix inv;
bool computed = false;
for (int i = 0; i < kNumStages; ++i) {
} else {
computed = true;
}
- fSamplerStates[i].preConcatCoordChange(preConcatInverse);
+ fStages[i].preConcatCoordChange(preConcatInverse);
}
}
return true;
private:
GrDrawState* fDrawState;
GrMatrix fViewMatrix;
- GrSamplerState::SavedCoordChange fSavedCoordChanges[GrDrawState::kNumStages];
+ GrEffectStage::SavedCoordChange fSavedCoordChanges[GrDrawState::kNumStages];
uint32_t fRestoreMask;
};
private:
GrDrawState* fDrawState;
GrMatrix fViewMatrix;
- GrSamplerState::SavedCoordChange fSavedCoordChanges[GrDrawState::kNumStages];
+ GrEffectStage::SavedCoordChange fSavedCoordChanges[GrDrawState::kNumStages];
uint32_t fRestoreMask;
};
bool isStageEnabled(int s) const {
GrAssert((unsigned)s < kNumStages);
- return (NULL != fSamplerStates[s].getEffect());
+ return (NULL != fStages[s].getEffect());
}
// Most stages are usually not used, so conditionals here
if (enabled != s.isStageEnabled(i)) {
return false;
}
- if (enabled && this->fSamplerStates[i] != s.fSamplerStates[i]) {
+ if (enabled && this->fStages[i] != s.fStages[i]) {
return false;
}
}
for (int i = 0; i < kNumStages; i++) {
if (s.isStageEnabled(i)) {
- this->fSamplerStates[i] = s.fSamplerStates[i];
+ this->fStages[i] = s.fStages[i];
}
}
// This field must be last; it will not be copied or compared
// if the corresponding fTexture[] is NULL.
- GrSamplerState fSamplerStates[kNumStages];
+ GrEffectStage fStages[kNumStages];
typedef GrRefCnt INHERITED;
};
* Coverage
*/
-int GrDrawTarget::VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout) {
+int GrDrawTarget::VertexStageCoordOffset(int stageIdx, GrVertexLayout vertexLayout) {
GrAssert(check_layout(vertexLayout));
- if (!StageUsesTexCoords(vertexLayout, stage)) {
+ if (!StageUsesTexCoords(vertexLayout, stageIdx)) {
return 0;
}
- int tcIdx = VertexTexCoordsForStage(stage, vertexLayout);
+ int tcIdx = VertexTexCoordsForStage(stageIdx, vertexLayout);
if (tcIdx >= 0) {
int vecSize = (vertexLayout & kTextFormat_VertexLayoutBit) ?
return !!(gTexCoordMasks[coordIndex] & vertexLayout);
}
-int GrDrawTarget::VertexTexCoordsForStage(int stage,
+int GrDrawTarget::VertexTexCoordsForStage(int stageIdx,
GrVertexLayout vertexLayout) {
- GrAssert(stage < GrDrawState::kNumStages);
+ GrAssert(stageIdx < GrDrawState::kNumStages);
GrAssert(check_layout(vertexLayout));
- int bit = vertexLayout & gStageTexCoordMasks[stage];
+ int bit = vertexLayout & gStageTexCoordMasks[stageIdx];
if (bit) {
// figure out which set of texture coordates is used
// bits are ordered T0S0, T0S1, T0S2, ..., T1S0, T1S1, ...
}
-bool GrDrawTarget::StageUsesTexCoords(GrVertexLayout layout, int stage) {
- return SkToBool(layout & gStageTexCoordMasks[stage]);
+bool GrDrawTarget::StageUsesTexCoords(GrVertexLayout layout, int stageIdx) {
+ return SkToBool(layout & gStageTexCoordMasks[stageIdx]);
}
bool GrDrawTarget::reserveVertexAndIndexSpace(GrVertexLayout vertexLayout,
GrAssert(NULL != drawState.getRenderTarget());
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (drawState.isStageEnabled(s)) {
- const GrEffect* effect = drawState.getSampler(s).getEffect();
+ const GrEffect* effect = drawState.getStage(s).getEffect();
int numTextures = effect->numTextures();
for (int t = 0; t < numTextures; ++t) {
GrTexture* texture = effect->texture(t);
// Check if a color stage could create a partial alpha
for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
if (this->isStageEnabled(s)) {
- const GrEffect* effect = drawState.getSampler(s).getEffect();
+ const GrEffect* effect = drawState.getStage(s).getEffect();
// FIXME: The param indicates whether the texture is opaque or not. However, the effect
// already controls its textures. It really needs to know whether the incoming color
// (from a uni, per-vertex colors, or previous stage) is opaque or not.
/**
* Generates a bit indicating that a texture stage uses texture coordinates
*
- * @param stage the stage that will use texture coordinates.
+ * @param stageIdx the stage that will use texture coordinates.
* @param texCoordIdx the index of the texture coordinates to use
*
* @return the bit to add to a GrVertexLayout bitfield.
*/
- static int StageTexCoordVertexLayoutBit(int stage, int texCoordIdx) {
- GrAssert(stage < GrDrawState::kNumStages);
+ static int StageTexCoordVertexLayoutBit(int stageIdx, int texCoordIdx) {
+ GrAssert(stageIdx < GrDrawState::kNumStages);
GrAssert(texCoordIdx < GrDrawState::kMaxTexCoords);
- return 1 << (stage + (texCoordIdx * GrDrawState::kNumStages));
+ return 1 << (stageIdx + (texCoordIdx * GrDrawState::kNumStages));
}
- static bool StageUsesTexCoords(GrVertexLayout layout, int stage);
+ static bool StageUsesTexCoords(GrVertexLayout layout, int stageIdx);
private:
// non-stage bits start at this index.
* as texture coordinates, in which case the result of the function is
* indistinguishable from the case when the stage is disabled.
*
- * @param stage the stage to query
+ * @param stageIdx the stage to query
* @param vertexLayout layout to query
*
* @return the texture coordinate index or -1 if the stage doesn't use
* separate (non-position) texture coordinates.
*/
- static int VertexTexCoordsForStage(int stage, GrVertexLayout vertexLayout);
+ static int VertexTexCoordsForStage(int stageIdx, GrVertexLayout vertexLayout);
/**
* Helper function to compute the offset of texture coordinates in a vertex
* layout has no texture coordinates. Will be 0 if positions are
* used as texture coordinates for the stage.
*/
- static int VertexStageCoordOffset(int stage, GrVertexLayout vertexLayout);
+ static int VertexStageCoordOffset(int stageIdx, GrVertexLayout vertexLayout);
/**
* Helper function to compute the offset of the color in a vertex
}
}
- bool isStageEnabled(int stage) const {
- return this->getDrawState().isStageEnabled(stage);
+ bool isStageEnabled(int stageIdx) const {
+ return this->getDrawState().isStageEnabled(stageIdx);
}
// A sublcass can optionally overload this function to be notified before
GrMatrix combinedMatrix = drawState->getViewMatrix();
// We go to device space so that matrix changes allow us to concat
// rect draws. When the caller has provided explicit source rects
- // then we don't want to modify the sampler matrices. Otherwise
- // we have to account for the view matrix change in the sampler
+ // then we don't want to modify the stages' matrices. Otherwise
+ // we have to account for the view matrix change in the stage
// matrices.
uint32_t explicitCoordMask = 0;
if (srcRects) {
kPathMaskStage = GrPaint::kTotalStages,
};
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
- drawState->sampler(kPathMaskStage)->reset();
+ drawState->stage(kPathMaskStage)->reset();
drawState->createTextureEffect(kPathMaskStage, texture);
GrScalar w = GrIntToScalar(rect.width());
GrScalar h = GrIntToScalar(rect.height());
GrDrawState* drawState = fDrawTarget->drawState();
if (fCurrVertex > 0) {
// setup our sampler state for our text texture/atlas
- drawState->sampler(kGlyphMaskStage)->reset();
+ drawState->stage(kGlyphMaskStage)->reset();
GrAssert(GrIsALIGN4(fCurrVertex));
GrAssert(fCurrTexture);
bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
GrTexture* texture = fRenderTarget->asTexture();
if (NULL != texture) {
- paint->colorSampler(kBitmapTextureIdx)->setEffect(
+ paint->colorStage(kBitmapTextureIdx)->setEffect(
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
return true;
}
} else {
SkAutoTUnref<GrEffect> effect(colorFilter->asNewEffect(dev->context()));
if (NULL != effect.get()) {
- grPaint->colorSampler(kColorFilterTextureIdx)->setEffect(effect);
+ grPaint->colorStage(kColorFilterTextureIdx)->setEffect(effect);
} else {
// TODO: rewrite this using asNewEffect()
SkColor color;
}
// This function is similar to skPaint2GrPaintNoShader but also converts
-// skPaint's shader to a GrTexture/GrSamplerState if possible. The texture to
+// skPaint's shader to a GrTexture/GrEffectStage if possible. The texture to
// be used is set on grPaint and returned in param act. constantColor has the
// same meaning as in skPaint2GrPaintNoShader.
inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
return false;
}
- GrSamplerState* sampler = grPaint->colorSampler(kShaderTextureIdx);
- if (shader->asNewEffect(dev->context(), sampler)) {
+ GrEffectStage* stage = grPaint->colorStage(kShaderTextureIdx);
+ if (shader->asNewEffect(dev->context(), stage)) {
return true;
}
GrScalar sy = SkFloatToScalar(1.f / bitmap.height());
matrix.postScale(sx, sy);
}
- sampler->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)), matrix)->unref();
return true;
}
matrix.setIDiv(pathTexture->width(), pathTexture->height());
// Blend pathTexture over blurTexture.
context->setRenderTarget(blurTexture->asRenderTarget());
- paint.colorSampler(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (pathTexture)), matrix)->unref();
+ paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (pathTexture)), matrix)->unref();
if (SkMaskFilter::kInner_BlurType == blurType) {
// inner: dst = dst * src
paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
matrix.setTranslate(-finalRect.fLeft, -finalRect.fTop);
matrix.postIDiv(blurTexture->width(), blurTexture->height());
- grp->coverageSampler(MASK_IDX)->reset();
- grp->coverageSampler(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)), matrix)->unref();
+ grp->coverageStage(MASK_IDX)->reset();
+ grp->coverageStage(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (blurTexture)), matrix)->unref();
context->drawRect(*grp, finalRect);
return true;
}
m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1);
m.postIDiv(texture->width(), texture->height());
- grp->coverageSampler(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture)), m)->unref();
+ grp->coverageStage(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture)), m)->unref();
GrRect d;
d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
GrIntToScalar(dstM.fBounds.fTop),
return;
}
- GrSamplerState* sampler = grPaint->colorSampler(kBitmapTextureIdx);
+ GrEffectStage* stage = grPaint->colorStage(kBitmapTextureIdx);
GrTexture* texture;
SkAutoCachedTexture act(this, bitmap, ¶ms, &texture);
} else {
effect.reset(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)));
}
- grPaint->colorSampler(kBitmapTextureIdx)->setEffect(effect);
+ grPaint->colorStage(kBitmapTextureIdx)->setEffect(effect);
fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m);
}
GrMatrix sampleM;
sampleM.setIDiv(srcTexture->width(), srcTexture->height());
GrPaint paint;
- paint.colorSampler(0)->setEffect(effect, sampleM);
+ paint.colorStage(0)->setEffect(effect, sampleM);
context->drawRect(paint, rect);
}
return;
}
- GrSamplerState* sampler = grPaint.colorSampler(kBitmapTextureIdx);
+ GrEffectStage* stage = grPaint.colorStage(kBitmapTextureIdx);
GrTexture* texture;
- sampler->reset();
+ stage->reset();
// draw sprite uses the default texture params
SkAutoCachedTexture act(this, bitmap, NULL, &texture);
- grPaint.colorSampler(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
(GrSingleTextureEffect, (texture)))->unref();
SkImageFilter* filter = paint.getImageFilter();
GrTexture* filteredTexture = filter_texture(this, fContext, texture, filter,
GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
if (filteredTexture) {
- grPaint.colorSampler(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
(GrSingleTextureEffect, (filteredTexture)))->unref();
texture = filteredTexture;
filteredTexture->unref();
GrPaint grPaint;
SkAutoCachedTexture colorLutTexture;
- grPaint.colorSampler(kBitmapTextureIdx)->reset();
+ grPaint.colorStage(kBitmapTextureIdx)->reset();
if (!dev->bindDeviceAsTexture(&grPaint) ||
!skPaint2GrPaintNoShader(this, paint, true, false, &colorLutTexture, &grPaint)) {
return;
}
- GrTexture* devTex = grPaint.getColorSampler(kBitmapTextureIdx).getEffect()->texture(0);
+ GrTexture* devTex = grPaint.getColorStage(kBitmapTextureIdx).getEffect()->texture(0);
SkASSERT(NULL != devTex);
SkImageFilter* filter = paint.getImageFilter();
SkIntToScalar(devTex->height()));
GrTexture* filteredTexture = filter_texture(this, fContext, devTex, filter, rect);
if (filteredTexture) {
- grPaint.colorSampler(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
(GrSingleTextureEffect, (filteredTexture)))->unref();
devTex = filteredTexture;
filteredTexture->unref();
(tempTex, false, *pmToUPMRule)));
context->setRenderTarget(readTex->asRenderTarget());
- paint.colorSampler(0)->setEffect(pmToUPMEffect1);
+ paint.colorStage(0)->setEffect(pmToUPMEffect1);
context->drawRectToRect(paint, kDstRect, kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead);
context->setRenderTarget(tempTex->asRenderTarget());
- paint.colorSampler(0)->setEffect(upmToPMEffect);
+ paint.colorStage(0)->setEffect(upmToPMEffect);
context->drawRectToRect(paint, kDstRect, kSrcRect);
context->setRenderTarget(readTex->asRenderTarget());
- paint.colorSampler(0)->setEffect(pmToUPMEffect2);
+ paint.colorStage(0)->setEffect(pmToUPMEffect2);
context->drawRectToRect(paint, kDstRect, kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
int count = fUniforms.fStages[s].fSamplerUniforms.count();
// FIXME: We're still always reserving one texture per stage. After GrTextureParams are
- // expressed by the effect rather than the GrSamplerState we can move texture binding
+ // expressed by the effect rather than the GrEffectStage we can move texture binding
// into GrGLProgram and it should be easier to fix this.
GrAssert(count <= 1);
for (int t = 0; t < count; ++t) {
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (NULL != fEffects[s]) {
- const GrSamplerState& sampler = drawState.getSampler(s);
- GrAssert(NULL != sampler.getEffect());
- fEffects[s]->setData(fUniformManager, *sampler.getEffect());
+ const GrEffectStage& stage = drawState.getStage(s);
+ GrAssert(NULL != stage.getEffect());
+ fEffects[s]->setData(fUniformManager, *stage.getEffect());
}
}
}
, fUsesGS(false)
, fContext(ctx)
, fUniformManager(uniformManager)
- , fCurrentStage(kNonStageIdx)
+ , fCurrentStageIdx(kNonStageIdx)
, fSetupFragPosition(false)
, fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle)
, fTexCoordVaryingType(kVoid_GrSLType) {
break;
case kVec3f_GrSLType: {
fDefaultTexCoordsName = "inCoord";
- GrAssert(kNonStageIdx != fCurrentStage);
- fDefaultTexCoordsName.appendS32(fCurrentStage);
+ GrAssert(kNonStageIdx != fCurrentStageIdx);
+ fDefaultTexCoordsName.appendS32(fCurrentStageIdx);
fTexCoordVaryingType = kVec3f_GrSLType;
fFSCode.appendf("\t%s %s = %s.xy / %s.z;\n",
GrGLShaderVar::TypeString(kVec2f_GrSLType),
uni.fVariable.setType(type);
uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier);
SkString* uniName = uni.fVariable.accessName();
- if (kNonStageIdx == fCurrentStage) {
+ if (kNonStageIdx == fCurrentStageIdx) {
uniName->printf("u%s", name);
} else {
- uniName->printf("u%s%d", name, fCurrentStage);
+ uniName->printf("u%s%d", name, fCurrentStageIdx);
}
uni.fVariable.setArrayCount(count);
uni.fVisibility = visibility;
fVSOutputs.push_back();
fVSOutputs.back().setType(type);
fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
- if (kNonStageIdx == fCurrentStage) {
+ if (kNonStageIdx == fCurrentStageIdx) {
fVSOutputs.back().accessName()->printf("v%s", name);
} else {
- fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStage);
+ fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStageIdx);
}
if (vsOutName) {
*vsOutName = fVSOutputs.back().getName().c_str();
fGSOutputs.push_back();
fGSOutputs.back().setType(type);
fGSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier);
- if (kNonStageIdx == fCurrentStage) {
+ if (kNonStageIdx == fCurrentStageIdx) {
fGSOutputs.back().accessName()->printf("g%s", name);
} else {
- fGSOutputs.back().accessName()->printf("g%s%d", name, fCurrentStage);
+ fGSOutputs.back().accessName()->printf("g%s%d", name, fCurrentStageIdx);
}
fsName = fGSOutputs.back().accessName();
} else {
// temporarily change the stage index because we're inserting a uniform whose name
// shouldn't be mangled to be stage-specific.
- int oldStageIdx = fCurrentStage;
- fCurrentStage = kNonStageIdx;
+ int oldStageIdx = fCurrentStageIdx;
+ fCurrentStageIdx = kNonStageIdx;
fRTHeightUniform = this->addUniform(kFragment_ShaderType,
kFloat_GrSLType,
"RTHeight",
&rtHeightName);
- fCurrentStage = oldStageIdx;
+ fCurrentStageIdx = oldStageIdx;
this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_FragCoord.y, gl_FragCoord.zw);\n",
kCoordName, rtHeightName);
SkString* outName) {
GrAssert(kFragment_ShaderType == shader);
fFSFunctions.append(GrGLShaderVar::TypeString(returnType));
- if (kNonStageIdx != fCurrentStage) {
- outName->printf(" %s_%d", name, fCurrentStage);
+ if (kNonStageIdx != fCurrentStageIdx) {
+ outName->printf(" %s_%d", name, fCurrentStageIdx);
} else {
*outName = name;
}
* Sets the current stage (used to make variable names unique).
* TODO: Hide from the GrEffects
*/
- void setCurrentStage(int stage) { fCurrentStage = stage; }
- void setNonStage() { fCurrentStage = kNonStageIdx; }
+ void setCurrentStage(int stageIdx) { fCurrentStageIdx = stageIdx; }
+ void setNonStage() { fCurrentStageIdx = kNonStageIdx; }
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
const GrGLContextInfo& fContext;
GrGLUniformManager& fUniformManager;
- int fCurrentStage;
+ int fCurrentStageIdx;
SkString fFSFunctions;
SkString fFSHeader;
}
-void GrGpuGL::flushBoundTextureAndParams(int stage) {
+void GrGpuGL::flushBoundTextureAndParams(int stageIdx) {
GrDrawState* drawState = this->drawState();
// FIXME: Assuming at most one texture per effect
- const GrEffect* effect = drawState->sampler(stage)->getEffect();
+ const GrEffect* effect = drawState->stage(stageIdx)->getEffect();
if (effect->numTextures() > 0) {
GrGLTexture* nextTexture = static_cast<GrGLTexture*>(effect->texture(0));
if (NULL != nextTexture) {
const GrTextureParams& texParams = effect->textureAccess(0).getParams();
- this->flushBoundTextureAndParams(stage, texParams, nextTexture);
+ this->flushBoundTextureAndParams(stageIdx, texParams, nextTexture);
}
}
}
-void GrGpuGL::flushBoundTextureAndParams(int stage,
+void GrGpuGL::flushBoundTextureAndParams(int stageIdx,
const GrTextureParams& params,
GrGLTexture* nextTexture) {
this->onResolveRenderTarget(texRT);
}
- if (fHWBoundTextures[stage] != nextTexture) {
- this->setTextureUnit(stage);
+ if (fHWBoundTextures[stageIdx] != nextTexture) {
+ this->setTextureUnit(stageIdx);
GL_CALL(BindTexture(GR_GL_TEXTURE_2D, nextTexture->textureID()));
//GrPrintf("---- bindtexture %d\n", nextTexture->textureID());
- fHWBoundTextures[stage] = nextTexture;
+ fHWBoundTextures[stageIdx] = nextTexture;
}
ResetTimestamp timestamp;
GrGLShaderBuilder::GetTexParamSwizzle(nextTexture->config(), this->glCaps()),
sizeof(newTexParams.fSwizzleRGBA));
if (setAll || newTexParams.fFilter != oldTexParams.fFilter) {
- this->setTextureUnit(stage);
+ this->setTextureUnit(stageIdx);
GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
GR_GL_TEXTURE_MAG_FILTER,
newTexParams.fFilter));
newTexParams.fFilter));
}
if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) {
- this->setTextureUnit(stage);
+ this->setTextureUnit(stageIdx);
GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
GR_GL_TEXTURE_WRAP_S,
newTexParams.fWrapS));
}
if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) {
- this->setTextureUnit(stage);
+ this->setTextureUnit(stageIdx);
GL_CALL(TexParameteri(GR_GL_TEXTURE_2D,
GR_GL_TEXTURE_WRAP_T,
newTexParams.fWrapT));
(setAll || memcmp(newTexParams.fSwizzleRGBA,
oldTexParams.fSwizzleRGBA,
sizeof(newTexParams.fSwizzleRGBA)))) {
- this->setTextureUnit(stage);
+ this->setTextureUnit(stageIdx);
set_tex_swizzle(newTexParams.fSwizzleRGBA,
this->glInterface());
}
// This helper determines if what optimizations can be applied to the matrix after any coord
// adjustments are applied. The return is a bitfield of GrGLProgram::StageDesc::OptFlags.
- static int TextureMatrixOptFlags(const GrGLTexture* texture, const GrSamplerState& sampler);
+ static int TextureMatrixOptFlags(const GrGLTexture* texture, const GrEffectStage& sampler);
static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
GrGLTexture* nextTexture);
// sets the texture matrix for the currently bound program
- void flushTextureMatrix(int stage);
+ void flushTextureMatrix(int stageIdx);
// sets the color specified by GrDrawState::setColor()
void flushColor(GrColor color);
}
int GrGpuGL::TextureMatrixOptFlags(const GrGLTexture* texture,
- const GrSamplerState& sampler) {
+ const GrEffectStage& stage) {
GrAssert(NULL != texture);
GrMatrix matrix;
- sampler.getTotalMatrix(&matrix);
+ stage.getTotalMatrix(&matrix);
bool canBeIndentity = GrGLTexture::kTopDown_Orientation == texture->orientation();
const GrDrawState& drawState = this->getDrawState();
// FIXME: Still assuming only a single texture per effect
- const GrEffect* effect = drawState.getSampler(s).getEffect();
+ const GrEffect* effect = drawState.getStage(s).getEffect();
if (0 == effect->numTextures()) {
return;
}
const GrMatrix& hwMatrix = fCurrentProgram->fTextureMatrices[s];
GrMatrix samplerMatrix;
- drawState.getSampler(s).getTotalMatrix(&samplerMatrix);
+ drawState.getStage(s).getTotalMatrix(&samplerMatrix);
if (kInvalidUniformHandle != matrixUni &&
(orientationChange || !hwMatrix.cheapEqualTo(samplerMatrix))) {
namespace {
-void setup_effect(GrGLProgram::Desc::StageDesc* stage,
- const GrSamplerState& sampler,
+void setup_effect(GrGLProgram::Desc::StageDesc* stageDesc,
+ const GrEffectStage& stage,
const GrGLCaps& caps,
const GrEffect** effects,
GrGLProgram* program, int index) {
- const GrEffect* effect = sampler.getEffect();
+ const GrEffect* effect = stage.getEffect();
if (effect) {
const GrBackendEffectFactory& factory = effect->getFactory();
- stage->fEffectKey = factory.glEffectKey(*effect, caps);
+ stageDesc->fEffectKey = factory.glEffectKey(*effect, caps);
effects[index] = effect;
} else {
- stage->fEffectKey = 0;
+ stageDesc->fEffectKey = 0;
effects[index] = NULL;
}
}
}
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- StageDesc& stage = desc->fStages[s];
+ StageDesc& stageDesc = desc->fStages[s];
- stage.fOptFlags = 0;
- stage.setEnabled(this->isStageEnabled(s));
+ stageDesc.fOptFlags = 0;
+ stageDesc.setEnabled(this->isStageEnabled(s));
bool skip = s < drawState.getFirstCoverageStage() ? skipColor :
skipCoverage;
- if (!skip && stage.isEnabled()) {
+ if (!skip && stageDesc.isEnabled()) {
lastEnabledStage = s;
- const GrSamplerState& sampler = drawState.getSampler(s);
+ const GrEffectStage& stage = drawState.getStage(s);
// FIXME: Still assuming one texture per effect
- const GrEffect* effect = drawState.getSampler(s).getEffect();
+ const GrEffect* effect = drawState.getStage(s).getEffect();
if (effect->numTextures() > 0) {
const GrGLTexture* texture = static_cast<const GrGLTexture*>(effect->texture(0));
GrMatrix samplerMatrix;
- sampler.getTotalMatrix(&samplerMatrix);
+ stage.getTotalMatrix(&samplerMatrix);
if (NULL != texture) {
// We call this helper function rather then simply checking the client-specified
// texture matrix. This is because we may have to concat a y-inversion to account
// for texture orientation.
- stage.fOptFlags |= TextureMatrixOptFlags(texture, sampler);
+ stageDesc.fOptFlags |= TextureMatrixOptFlags(texture, stage);
}
} else {
// Set identity to do the minimal amount of extra work for the no texture case.
// This will go away when effects manage their own texture matrix.
- stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit;
+ stageDesc.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit;
}
- setup_effect(&stage, sampler, this->glCaps(), effects, fCurrentProgram.get(), s);
+ setup_effect(&stageDesc, stage, this->glCaps(), effects, fCurrentProgram.get(), s);
} else {
- stage.fOptFlags = 0;
- stage.fEffectKey = 0;
+ stageDesc.fOptFlags = 0;
+ stageDesc.fEffectKey = 0;
effects[s] = NULL;
}
}
SkAutoTUnref<const GrEffect> effects[GrDrawState::kNumStages];
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- StageDesc& stage = pdesc.fStages[s];
+ StageDesc& stageDesc = pdesc.fStages[s];
// enable the stage?
if (random_bool(&random)) {
// use separate tex coords?
int t = random_int(&random, GrDrawState::kMaxTexCoords);
pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t);
}
- stage.setEnabled(true);
+ stageDesc.setEnabled(true);
}
// use text-formatted verts?
if (random_bool(&random)) {
pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit;
}
- stage.fEffectKey = 0;
+ stageDesc.fEffectKey = 0;
+ stageDesc.fOptFlags |= STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
- stage.fOptFlags |= STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
-
- if (stage.isEnabled()) {
+ if (stageDesc.isEnabled()) {
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
- effects[s].reset(create_random_effect(&stage,
+ effects[s].reset(create_random_effect(&stageDesc,
&random,
getContext(),
dummyTextures));
if (NULL != effects[s]) {
- stage.fEffectKey =
+ stageDesc.fEffectKey =
effects[s]->getFactory().glEffectKey(*effects[s], this->glCaps());
}
}