Prep for GrDrawState as a class Part 2

Review URL: http://codereview.appspot.com/5450105/



git-svn-id: http://skia.googlecode.com/svn/trunk@2810 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2011-12-06 16:30:36 +00:00
parent b4b49ccc41
commit 9791291347
6 changed files with 52 additions and 88 deletions

View File

@ -239,14 +239,14 @@ private:
void resetTextures() {
for (int i = 0; i < kMaxTextures; ++i) {
this->setTexture(i, NULL);
fTextureSamplers[i].setClampNoFilter();
fTextureSamplers[i].reset();
}
}
void resetMasks() {
for (int i = 0; i < kMaxMasks; ++i) {
this->setMask(i, NULL);
fMaskSamplers[i].setClampNoFilter();
fMaskSamplers[i].reset();
}
}
};

View File

@ -88,60 +88,15 @@ public:
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
this->setClampNoFilter();
this->reset();
}
explicit GrSamplerState(Filter filter)
GrSamplerState(WrapMode wrapXAndY,
Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = kClamp_WrapMode;
fWrapY = kClamp_WrapMode;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix.setIdentity();
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix.setIdentity();
fSwapRAndB = false;
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy,
const GrMatrix& matrix, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix = matrix;
fSwapRAndB = false;
fTextureDomain.setEmpty();
}
GrSamplerState(WrapMode wx, WrapMode wy, SampleMode sample,
const GrMatrix& matrix, Filter filter)
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
fWrapX = wx;
fWrapY = wy;
fSampleMode = sample;
fMatrix = matrix;
fFilter = filter;
fSwapRAndB = false;
fTextureDomain.setEmpty();
this->reset(wrapXAndY, filter);
}
WrapMode getWrapX() const { return fWrapX; }
@ -204,7 +159,7 @@ public:
*/
void setFilter(Filter filter) { fFilter = filter; }
void setClampNoFilter() {
void reset() {
fWrapX = kClamp_WrapMode;
fWrapY = kClamp_WrapMode;
fSampleMode = kNormal_SampleMode;
@ -214,6 +169,28 @@ public:
fSwapRAndB = false;
}
void reset(WrapMode wrapXAndY,
Filter filter) {
fWrapX = wrapXAndY;
fWrapY = wrapXAndY;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix.setIdentity();
fTextureDomain.setEmpty();
fSwapRAndB = false;
}
void reset(WrapMode wrapXAndY,
Filter filter,
const GrMatrix& matrix) {
fWrapX = wrapXAndY;
fWrapY = wrapXAndY;
fSampleMode = kNormal_SampleMode;
fFilter = filter;
fMatrix = matrix;
fTextureDomain.setEmpty();
fSwapRAndB = false;
}
GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
bool isRadial2PosRoot() const { return SkToBool(fRadial2PosRoot); }
@ -247,9 +224,7 @@ public:
}
}
static const GrSamplerState& ClampNoFilter() {
return gClampNoFilter;
}
static const GrSamplerState& ClampNearest() { return gClampNearest; }
private:
WrapMode fWrapX : 8;
@ -270,7 +245,7 @@ private:
float fImageIncrement[2];
float fKernel[MAX_KERNEL_WIDTH];
static const GrSamplerState gClampNoFilter;
static const GrSamplerState gClampNearest;
};
#endif

View File

@ -330,11 +330,11 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture(TextureKey key,
if (special) {
TextureCacheEntry clampEntry =
findAndLockTexture(key, desc.fWidth, desc.fHeight,
GrSamplerState::ClampNoFilter());
GrSamplerState::ClampNearest());
if (NULL == clampEntry.texture()) {
clampEntry = createAndLockTexture(key,
GrSamplerState::ClampNoFilter(),
GrSamplerState::ClampNearest(),
desc, srcData, rowBytes);
GrAssert(NULL != clampEntry.texture());
if (NULL == clampEntry.texture()) {
@ -367,7 +367,6 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture(TextureKey key,
filter = GrSamplerState::kBilinear_Filter;
}
GrSamplerState stretchSampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode,
filter);
fGpu->setSamplerState(0, stretchSampler);
@ -434,7 +433,7 @@ inline void gen_scratch_tex_key_values(const GrGpu* gpu,
((uint64_t) desc.fConfig << 32);
// this code path isn't friendly to tiling with NPOT restricitons
// We just pass ClampNoFilter()
gen_texture_key_values(gpu, GrSamplerState::ClampNoFilter(), descKey,
gen_texture_key_values(gpu, GrSamplerState::ClampNearest(), descKey,
desc.fWidth, desc.fHeight, true, v);
}
}
@ -864,8 +863,7 @@ void GrContext::doOffscreenAAPass2(GrDrawTarget* target,
}
GrMatrix sampleM;
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode, filter);
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode, filter);
GrTexture* src = record->fOffscreen0.texture();
int scale;
@ -1787,9 +1785,6 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target,
fGpu->setRenderTarget(target);
GrSamplerState sampler;
sampler.setClampNoFilter();
sampler.setRAndBSwap(swapRAndB);
GrMatrix matrix;
if (flipY) {
matrix.setTranslate(SK_Scalar1 * left,
@ -1799,7 +1794,11 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target,
matrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top);
}
matrix.postIDiv(src->width(), src->height());
sampler.setMatrix(matrix);
GrSamplerState sampler;
sampler.reset(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kNearest_Filter,
matrix);
sampler.setRAndBSwap(swapRAndB);
fGpu->setSamplerState(0, sampler);
fGpu->setTexture(0, src);
GrRect rect;
@ -1822,8 +1821,7 @@ void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst) {
GrDrawTarget::AutoStateRestore asr(fGpu);
reset_target_state(fGpu);
fGpu->setRenderTarget(dst);
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode,
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kNearest_Filter);
GrMatrix sampleM;
sampleM.setIDiv(src->width(), src->height());
@ -1899,10 +1897,11 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target,
fGpu->setRenderTarget(target);
fGpu->setTexture(0, texture);
GrSamplerState sampler;
sampler.setClampNoFilter();
matrix.setIDiv(texture->width(), texture->height());
sampler.setMatrix(matrix);
GrSamplerState sampler;
sampler.reset(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kNearest_Filter,
matrix);
sampler.setRAndBSwap(swapRAndB);
fGpu->setSamplerState(0, sampler);
@ -2145,8 +2144,7 @@ void GrContext::convolve(GrTexture* texture,
GrDrawTarget::AutoStateRestore asr(fGpu);
GrMatrix sampleM;
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode,
GrSamplerState sampler(GrSamplerState::kClamp_WrapMode,
GrSamplerState::kConvolution_Filter);
sampler.setConvolutionParams(kernelWidth, kernel, imageIncrement);
sampleM.setIDiv(texture->width(), texture->height());

View File

@ -960,13 +960,5 @@ void GrGpu::printStats() const {
}
////////////////////////////////////////////////////////////////////////////////
const GrSamplerState GrSamplerState::gClampNoFilter(
GrSamplerState::kClamp_WrapMode,
GrSamplerState::kClamp_WrapMode,
GrSamplerState::kNormal_SampleMode,
GrMatrix::I(),
GrSamplerState::kNearest_Filter);
const GrSamplerState GrSamplerState::gClampNearest;

View File

@ -34,7 +34,6 @@ void GrTextContext::flushGlyphs() {
filter = GrSamplerState::kBilinear_Filter;
}
GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode,
GrSamplerState::kRepeat_WrapMode,
filter);
fDrawTarget->setSamplerState(kGlyphMaskStage, sampler);

View File

@ -195,7 +195,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context, SkBitmap::Config config, int width,
TexType type = (kSaveLayer_Usage == usage) ?
kSaveLayerDeviceRenderTarget_TexType :
kDeviceRenderTarget_TexType;
fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNoFilter(), type);
fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNearest(), type);
fTexture = fCache.texture();
if (fTexture) {
SkASSERT(NULL != fTexture->asRenderTarget());
@ -969,7 +969,7 @@ static bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
// we assume the last mask index is available for use
GrAssert(NULL == grp->getMask(MASK_IDX));
grp->setMask(MASK_IDX, blurTexture);
grp->maskSampler(MASK_IDX)->setClampNoFilter();
grp->maskSampler(MASK_IDX)->reset();
GrMatrix m;
m.setTranslate(-finalRect.fLeft, -finalRect.fTop);
@ -1037,7 +1037,7 @@ static bool drawWithMaskFilter(GrContext* context, const SkPath& path,
// we assume the last mask index is available for use
GrAssert(NULL == grp->getMask(MASK_IDX));
grp->setMask(MASK_IDX, texture);
grp->maskSampler(MASK_IDX)->setClampNoFilter();
grp->maskSampler(MASK_IDX)->reset();
GrRect d;
d.setLTRB(GrIntToScalar(dstM.fBounds.fLeft),
@ -1465,7 +1465,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
GrSamplerState* sampler = grPaint.textureSampler(kBitmapTextureIdx);
GrTexture* texture;
sampler->setClampNoFilter();
sampler->reset();
SkAutoCachedTexture act(this, bitmap, *sampler, &texture);
grPaint.setTexture(kBitmapTextureIdx, texture);
@ -1497,7 +1497,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* dev,
GrAutoMatrix avm(fContext, GrMatrix::I());
grPaint.textureSampler(kBitmapTextureIdx)->setClampNoFilter();
grPaint.textureSampler(kBitmapTextureIdx)->reset();
GrRect dstRect = GrRect::MakeXYWH(GrIntToScalar(x),
GrIntToScalar(y),