revert 8265-8264 (broke build)
git-svn-id: http://skia.googlecode.com/svn/trunk@8268 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index 1934b5d..b9052f0 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -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 @@
/**
* 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 @@
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
diff --git a/include/gpu/GrBackendEffectFactory.h b/include/gpu/GrBackendEffectFactory.h
index da296c9..99d6a73 100644
--- a/include/gpu/GrBackendEffectFactory.h
+++ b/include/gpu/GrBackendEffectFactory.h
@@ -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 @@
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;
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 2d57660..79edd0b 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -390,23 +390,25 @@
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 @@
this->restore();
if (NULL != paint) {
- if (!paint->localCoordChangeInverse(context->getMatrix())) {
+ if (!paint->sourceCoordChangeByInverse(context->getMatrix())) {
return false;
}
}
@@ -735,7 +737,7 @@
*/
void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) {
if (NULL != paint) {
- paint->localCoordChange(preConcat);
+ paint->sourceCoordChange(preConcat);
}
fContext->concatMatrix(preConcat);
}
diff --git a/include/gpu/GrDrawEffect.h b/include/gpu/GrDrawEffect.h
deleted file mode 100644
index 005de41..0000000
--- a/include/gpu/GrDrawEffect.h
+++ /dev/null
@@ -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
diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h
index 8834386..1b26041 100644
--- a/include/gpu/GrEffect.h
+++ b/include/gpu/GrEffect.h
@@ -70,20 +70,6 @@
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();
/**
diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h
index 94ff779..f4e46b0 100644
--- a/include/gpu/GrEffectStage.h
+++ b/include/gpu/GrEffectStage.h
@@ -58,10 +58,9 @@
/**
* 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 @@
/**
* 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).
*/
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index e0a9203..0fd42f9 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -169,6 +169,54 @@
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 @@
};
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];
diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h
index 8697f8e..1b6f816 100644
--- a/include/gpu/GrTBackendEffectFactory.h
+++ b/include/gpu/GrTBackendEffectFactory.h
@@ -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 @@
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 @@
/** 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.