2015-10-12 17:39:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
#ifndef GrSamplerParams_DEFINED
|
|
|
|
#define GrSamplerParams_DEFINED
|
2015-10-12 17:39:46 +00:00
|
|
|
|
|
|
|
#include "GrTypes.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the filtering and tile modes used to access a texture.
|
|
|
|
*/
|
2016-11-17 20:17:07 +00:00
|
|
|
class GrSamplerParams {
|
2015-10-12 17:39:46 +00:00
|
|
|
public:
|
2016-11-17 20:17:07 +00:00
|
|
|
static const GrSamplerParams& ClampNoFilter() {
|
|
|
|
static const GrSamplerParams gParams;
|
2015-10-12 17:39:46 +00:00
|
|
|
return gParams;
|
|
|
|
}
|
2016-11-17 20:17:07 +00:00
|
|
|
static const GrSamplerParams& ClampBilerp() {
|
|
|
|
static const GrSamplerParams gParams(SkShader::kClamp_TileMode, kBilerp_FilterMode);
|
2015-10-12 17:39:46 +00:00
|
|
|
return gParams;
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
GrSamplerParams() {
|
2015-10-12 17:39:46 +00:00
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
enum FilterMode {
|
|
|
|
kNone_FilterMode,
|
|
|
|
kBilerp_FilterMode,
|
|
|
|
kMipMap_FilterMode
|
|
|
|
};
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
GrSamplerParams(SkShader::TileMode tileXAndY, FilterMode filterMode) {
|
2015-10-12 17:39:46 +00:00
|
|
|
this->reset(tileXAndY, filterMode);
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
GrSamplerParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) {
|
2015-10-12 17:39:46 +00:00
|
|
|
this->reset(tileModes, filterMode);
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
GrSamplerParams(const GrSamplerParams& params) {
|
2015-10-12 17:39:46 +00:00
|
|
|
*this = params;
|
|
|
|
}
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
GrSamplerParams& operator= (const GrSamplerParams& params) {
|
2015-10-12 17:39:46 +00:00
|
|
|
fTileModes[0] = params.fTileModes[0];
|
|
|
|
fTileModes[1] = params.fTileModes[1];
|
|
|
|
fFilterMode = params.fFilterMode;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
this->reset(SkShader::kClamp_TileMode, kNone_FilterMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) {
|
|
|
|
fTileModes[0] = fTileModes[1] = tileXAndY;
|
|
|
|
fFilterMode = filterMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) {
|
|
|
|
fTileModes[0] = tileModes[0];
|
|
|
|
fTileModes[1] = tileModes[1];
|
|
|
|
fFilterMode = filterMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setClampNoFilter() {
|
|
|
|
fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
|
|
|
|
fFilterMode = kNone_FilterMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setClamp() {
|
|
|
|
fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFilterMode(FilterMode filterMode) { fFilterMode = filterMode; }
|
|
|
|
|
|
|
|
void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; }
|
|
|
|
void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; }
|
|
|
|
void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; }
|
|
|
|
|
|
|
|
SkShader::TileMode getTileModeX() const { return fTileModes[0]; }
|
|
|
|
|
|
|
|
SkShader::TileMode getTileModeY() const { return fTileModes[1]; }
|
|
|
|
|
|
|
|
bool isTiled() const {
|
|
|
|
return SkShader::kClamp_TileMode != fTileModes[0] ||
|
|
|
|
SkShader::kClamp_TileMode != fTileModes[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterMode filterMode() const { return fFilterMode; }
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
bool operator== (const GrSamplerParams& other) const {
|
2015-10-12 17:39:46 +00:00
|
|
|
return fTileModes[0] == other.fTileModes[0] &&
|
|
|
|
fTileModes[1] == other.fTileModes[1] &&
|
2016-05-24 13:18:48 +00:00
|
|
|
fFilterMode == other.fFilterMode;
|
2015-10-12 17:39:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 20:17:07 +00:00
|
|
|
bool operator!= (const GrSamplerParams& other) const { return !(*this == other); }
|
2015-10-12 17:39:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkShader::TileMode fTileModes[2];
|
|
|
|
FilterMode fFilterMode;
|
|
|
|
};
|
|
|
|
#endif
|