2010-12-22 21:39:39 +00:00
|
|
|
|
2011-07-28 14:26:00 +00: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-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#ifndef GrSamplerState_DEFINED
|
|
|
|
#define GrSamplerState_DEFINED
|
|
|
|
|
2012-04-20 18:35:38 +00:00
|
|
|
#include "GrCustomStage.h"
|
2011-02-17 16:43:10 +00:00
|
|
|
#include "GrMatrix.h"
|
2012-04-20 18:35:38 +00:00
|
|
|
#include "GrTypes.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-07-25 21:27:09 +00:00
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
class GrSamplerState {
|
|
|
|
public:
|
|
|
|
static const bool kBilerpDefault = false;
|
|
|
|
|
|
|
|
static const SkShader::TileMode kTileModeDefault = SkShader::kClamp_TileMode;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-17 16:43:10 +00:00
|
|
|
* Default sampler state is set to clamp, use normal sampling mode, be
|
|
|
|
* unfiltered, and use identity matrix.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2011-06-21 20:32:12 +00:00
|
|
|
GrSamplerState()
|
2012-06-01 20:42:15 +00:00
|
|
|
: fCustomStage (NULL) {
|
2012-05-31 20:35:27 +00:00
|
|
|
memset(this, 0, sizeof(GrSamplerState));
|
2011-12-06 16:30:36 +00:00
|
|
|
this->reset();
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 18:35:38 +00:00
|
|
|
~GrSamplerState() {
|
|
|
|
GrSafeUnref(fCustomStage);
|
|
|
|
}
|
|
|
|
|
2012-04-30 20:19:07 +00:00
|
|
|
bool operator ==(const GrSamplerState& s) const {
|
2012-05-01 12:48:07 +00:00
|
|
|
/* We must be bit-identical as far as the CustomStage;
|
|
|
|
there may be multiple CustomStages that will produce
|
2012-08-23 18:09:54 +00:00
|
|
|
the same shader code and so are equivalent.
|
2012-05-01 12:48:07 +00:00
|
|
|
Can't take the address of fWrapX because it's :8 */
|
|
|
|
int bitwiseRegion = (intptr_t) &fCustomStage - (intptr_t) this;
|
|
|
|
GrAssert(sizeof(GrSamplerState) ==
|
|
|
|
bitwiseRegion + sizeof(fCustomStage));
|
|
|
|
return !memcmp(this, &s, bitwiseRegion) &&
|
|
|
|
((fCustomStage == s.fCustomStage) ||
|
|
|
|
(fCustomStage && s.fCustomStage &&
|
2012-05-10 12:13:36 +00:00
|
|
|
(fCustomStage->getFactory() ==
|
|
|
|
s.fCustomStage->getFactory()) &&
|
2012-05-31 18:40:36 +00:00
|
|
|
fCustomStage->isEqual(*s.fCustomStage)));
|
2012-04-30 20:19:07 +00:00
|
|
|
}
|
|
|
|
bool operator !=(const GrSamplerState& s) const { return !(*this == s); }
|
|
|
|
|
2012-06-01 19:50:02 +00:00
|
|
|
GrSamplerState& operator =(const GrSamplerState& s) {
|
2012-05-31 14:23:28 +00:00
|
|
|
fMatrix = s.fMatrix;
|
2012-06-19 15:27:50 +00:00
|
|
|
GrSafeAssign(fCustomStage, s.fCustomStage);
|
2012-04-30 20:19:07 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-02-17 16:43:10 +00:00
|
|
|
const GrMatrix& getMatrix() const { return fMatrix; }
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-02-17 16:43:10 +00:00
|
|
|
/**
|
2011-12-12 18:45:07 +00:00
|
|
|
* Access the sampler's matrix. See SampleMode for explanation of
|
2011-02-17 16:43:10 +00:00
|
|
|
* relationship between the matrix and sample mode.
|
|
|
|
*/
|
2011-12-12 18:45:07 +00:00
|
|
|
GrMatrix* matrix() { return &fMatrix; }
|
|
|
|
|
2011-02-17 16:43:10 +00:00
|
|
|
/**
|
|
|
|
* Multiplies the current sampler matrix a matrix
|
|
|
|
*
|
|
|
|
* After this call M' = M*m where M is the old matrix, m is the parameter
|
|
|
|
* to this function, and M' is the new matrix. (We consider points to
|
2012-08-23 18:09:54 +00:00
|
|
|
* be column vectors so tex cood vector t is transformed by matrix X as
|
2011-02-17 16:43:10 +00:00
|
|
|
* t' = X*t.)
|
|
|
|
*
|
|
|
|
* @param matrix the matrix used to modify the matrix.
|
|
|
|
*/
|
|
|
|
void preConcatMatrix(const GrMatrix& matrix) { fMatrix.preConcat(matrix); }
|
|
|
|
|
2012-09-18 14:14:49 +00:00
|
|
|
void reset(const GrMatrix& matrix) {
|
2011-12-06 16:30:36 +00:00
|
|
|
fMatrix = matrix;
|
2012-04-20 18:35:38 +00:00
|
|
|
GrSafeSetNull(fCustomStage);
|
2011-12-12 16:11:33 +00:00
|
|
|
}
|
2012-09-18 14:14:49 +00:00
|
|
|
|
2011-12-12 18:45:07 +00:00
|
|
|
void reset() {
|
2012-09-18 14:14:49 +00:00
|
|
|
fMatrix.reset();
|
|
|
|
GrSafeSetNull(fCustomStage);
|
2011-12-06 16:30:36 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 19:58:30 +00:00
|
|
|
GrCustomStage* setCustomStage(GrCustomStage* stage) {
|
2012-04-20 18:35:38 +00:00
|
|
|
GrSafeAssign(fCustomStage, stage);
|
2012-06-04 19:58:30 +00:00
|
|
|
return stage;
|
2012-04-20 18:35:38 +00:00
|
|
|
}
|
2012-07-30 13:09:05 +00:00
|
|
|
const GrCustomStage* getCustomStage() const { return fCustomStage; }
|
2012-04-20 18:35:38 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
private:
|
2012-06-01 20:42:15 +00:00
|
|
|
GrMatrix fMatrix;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2012-04-30 20:19:07 +00:00
|
|
|
GrCustomStage* fCustomStage;
|
2010-12-22 21:39:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|