2010-12-23 00:39:39 +03:00
|
|
|
|
2011-07-28 18:26:00 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2010-12-23 00:39:39 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 18:26:00 +04:00
|
|
|
|
2012-10-26 21:53:18 +04:00
|
|
|
#ifndef GrEffectStage_DEFINED
|
|
|
|
#define GrEffectStage_DEFINED
|
2010-12-23 00:39:39 +03:00
|
|
|
|
2012-10-29 23:51:22 +04:00
|
|
|
#include "GrBackendEffectFactory.h"
|
2012-10-24 22:28:34 +04:00
|
|
|
#include "GrEffect.h"
|
2012-11-01 22:02:54 +04:00
|
|
|
#include "SkMatrix.h"
|
2012-04-20 22:35:38 +04:00
|
|
|
#include "GrTypes.h"
|
2010-12-23 00:39:39 +03:00
|
|
|
|
2012-07-26 01:27:09 +04:00
|
|
|
#include "SkShader.h"
|
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
class GrEffectStage {
|
2012-07-26 01:27:09 +04:00
|
|
|
public:
|
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
GrEffectStage()
|
2012-10-24 23:07:10 +04:00
|
|
|
: fEffect (NULL) {
|
2012-10-17 16:53:54 +04:00
|
|
|
GR_DEBUGCODE(fSavedCoordChangeCnt = 0;)
|
2010-12-23 00:39:39 +03:00
|
|
|
}
|
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
~GrEffectStage() {
|
2012-10-24 23:07:10 +04:00
|
|
|
GrSafeUnref(fEffect);
|
2012-10-17 16:53:54 +04:00
|
|
|
GrAssert(0 == fSavedCoordChangeCnt);
|
2012-04-20 22:35:38 +04:00
|
|
|
}
|
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
bool operator ==(const GrEffectStage& other) const {
|
2012-10-24 23:07:10 +04:00
|
|
|
// first handle cases where one or the other has no effect
|
|
|
|
if (NULL == fEffect) {
|
|
|
|
return NULL == other.fEffect;
|
|
|
|
} else if (NULL == other.fEffect) {
|
2012-10-17 16:53:54 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-24 23:07:10 +04:00
|
|
|
if (fEffect->getFactory() != other.fEffect->getFactory()) {
|
2012-10-17 16:53:54 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-24 23:07:10 +04:00
|
|
|
if (!fEffect->isEqual(*other.fEffect)) {
|
2012-10-17 16:53:54 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fMatrix == other.fMatrix && fCoordChangeMatrix == other.fCoordChangeMatrix;
|
2012-05-01 00:19:07 +04:00
|
|
|
}
|
2012-10-17 16:53:54 +04:00
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
bool operator !=(const GrEffectStage& s) const { return !(*this == s); }
|
2012-05-01 00:19:07 +04:00
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
GrEffectStage& operator =(const GrEffectStage& other) {
|
2012-10-24 23:07:10 +04:00
|
|
|
GrSafeAssign(fEffect, other.fEffect);
|
|
|
|
if (NULL != fEffect) {
|
2012-10-17 16:53:54 +04:00
|
|
|
fMatrix = other.fMatrix;
|
|
|
|
fCoordChangeMatrix = other.fCoordChangeMatrix;
|
|
|
|
}
|
2012-05-01 00:19:07 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-02-17 19:43:10 +03:00
|
|
|
/**
|
2012-10-17 16:53:54 +04:00
|
|
|
* This is called when the coordinate system in which the geometry is specified will change.
|
2011-02-17 19:43:10 +03:00
|
|
|
*
|
2012-10-18 06:01:23 +04:00
|
|
|
* @param matrix The transformation from the old coord system to the new one.
|
2011-02-17 19:43:10 +03:00
|
|
|
*/
|
2012-11-01 22:02:54 +04:00
|
|
|
void preConcatCoordChange(const SkMatrix& matrix) { fCoordChangeMatrix.preConcat(matrix); }
|
2012-10-17 16:53:54 +04:00
|
|
|
|
|
|
|
class SavedCoordChange {
|
|
|
|
private:
|
2012-11-01 22:02:54 +04:00
|
|
|
SkMatrix fCoordChangeMatrix;
|
2012-10-29 20:25:04 +04:00
|
|
|
GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;)
|
2012-10-17 16:53:54 +04:00
|
|
|
|
2012-10-26 17:01:20 +04:00
|
|
|
friend class GrEffectStage;
|
2012-10-17 16:53:54 +04:00
|
|
|
};
|
2011-02-17 19:43:10 +03:00
|
|
|
|
2012-10-16 19:19:45 +04:00
|
|
|
/**
|
2012-10-17 16:53:54 +04:00
|
|
|
* This gets the current coordinate system change. It is the accumulation of
|
2012-10-24 23:07:10 +04:00
|
|
|
* preConcatCoordChange calls since the effect was installed. It is used when then caller
|
2012-10-17 16:53:54 +04:00
|
|
|
* wants to temporarily change the source geometry coord system, draw something, and then
|
2012-10-26 21:53:18 +04:00
|
|
|
* restore the previous coord system (e.g. temporarily draw in device coords).
|
2012-10-16 19:19:45 +04:00
|
|
|
*/
|
2012-10-17 16:53:54 +04:00
|
|
|
void saveCoordChange(SavedCoordChange* savedCoordChange) const {
|
|
|
|
savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
|
2012-10-24 23:07:10 +04:00
|
|
|
GrAssert(NULL == savedCoordChange->fEffect.get());
|
|
|
|
GR_DEBUGCODE(GrSafeRef(fEffect);)
|
|
|
|
GR_DEBUGCODE(savedCoordChange->fEffect.reset(fEffect);)
|
2012-10-17 16:53:54 +04:00
|
|
|
GR_DEBUGCODE(++fSavedCoordChangeCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This balances the saveCoordChange call.
|
|
|
|
*/
|
|
|
|
void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
|
|
|
|
fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
|
2012-10-24 23:07:10 +04:00
|
|
|
GrAssert(savedCoordChange.fEffect.get() == fEffect);
|
2012-10-17 16:53:54 +04:00
|
|
|
GR_DEBUGCODE(--fSavedCoordChangeCnt);
|
2012-10-24 23:07:10 +04:00
|
|
|
GR_DEBUGCODE(savedCoordChange.fEffect.reset(NULL);)
|
2012-10-17 16:53:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-10-24 22:28:34 +04:00
|
|
|
* Gets the texture matrix. This is will be removed soon and be managed by GrEffect.
|
2012-10-17 16:53:54 +04:00
|
|
|
*/
|
2012-11-01 22:02:54 +04:00
|
|
|
const SkMatrix& getMatrix() const { return fMatrix; }
|
2012-10-17 16:53:54 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the matrix to apply at draw time. This is the original texture matrix combined with
|
2012-10-26 21:53:18 +04:00
|
|
|
* any coord system changes. This will be removed when the matrix is managed by GrEffect.
|
2012-10-17 16:53:54 +04:00
|
|
|
*/
|
2012-11-01 22:02:54 +04:00
|
|
|
void getTotalMatrix(SkMatrix* matrix) const {
|
2012-10-17 16:53:54 +04:00
|
|
|
*matrix = fMatrix;
|
|
|
|
matrix->preConcat(fCoordChangeMatrix);
|
|
|
|
}
|
2012-09-18 18:14:49 +04:00
|
|
|
|
2012-10-26 21:53:18 +04:00
|
|
|
/**
|
|
|
|
* Gets the matrix representing all changes of coordinate system since the GrEffect was
|
|
|
|
* installed in the stage.
|
|
|
|
*/
|
2012-11-01 22:02:54 +04:00
|
|
|
const SkMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; }
|
2012-10-26 21:53:18 +04:00
|
|
|
|
2011-12-12 22:45:07 +04:00
|
|
|
void reset() {
|
2012-10-24 23:07:10 +04:00
|
|
|
GrSafeSetNull(fEffect);
|
2011-12-06 20:30:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-29 20:25:04 +04:00
|
|
|
const GrEffect* setEffect(const GrEffect* effect) {
|
2012-10-17 16:53:54 +04:00
|
|
|
GrAssert(0 == fSavedCoordChangeCnt);
|
2012-10-24 23:07:10 +04:00
|
|
|
GrSafeAssign(fEffect, effect);
|
2012-10-16 19:19:45 +04:00
|
|
|
fMatrix.reset();
|
2012-10-17 16:53:54 +04:00
|
|
|
fCoordChangeMatrix.reset();
|
2012-10-24 23:07:10 +04:00
|
|
|
return effect;
|
2012-04-20 22:35:38 +04:00
|
|
|
}
|
2012-10-16 19:19:45 +04:00
|
|
|
|
2012-11-01 22:02:54 +04:00
|
|
|
const GrEffect* setEffect(const GrEffect* effect, const SkMatrix& matrix) {
|
2012-10-17 16:53:54 +04:00
|
|
|
GrAssert(0 == fSavedCoordChangeCnt);
|
2012-10-24 23:07:10 +04:00
|
|
|
GrSafeAssign(fEffect, effect);
|
2012-10-16 19:19:45 +04:00
|
|
|
fMatrix = matrix;
|
2012-10-17 16:53:54 +04:00
|
|
|
fCoordChangeMatrix.reset();
|
2012-10-24 23:07:10 +04:00
|
|
|
return effect;
|
2012-10-16 19:19:45 +04:00
|
|
|
}
|
|
|
|
|
2012-10-24 23:07:10 +04:00
|
|
|
const GrEffect* getEffect() const { return fEffect; }
|
2012-04-20 22:35:38 +04:00
|
|
|
|
2010-12-23 00:39:39 +03:00
|
|
|
private:
|
2012-11-01 22:02:54 +04:00
|
|
|
SkMatrix fCoordChangeMatrix;
|
|
|
|
SkMatrix fMatrix; // TODO: remove this, store in GrEffect
|
2012-10-29 20:25:04 +04:00
|
|
|
const GrEffect* fEffect;
|
2012-10-17 16:53:54 +04:00
|
|
|
|
|
|
|
GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
|
2010-12-23 00:39:39 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|