diff options
author | 2011-12-06 16:30:36 +0000 | |
---|---|---|
committer | 2011-12-06 16:30:36 +0000 | |
commit | 9791291347db8b5e92f16b139df30e28186626c8 (patch) | |
tree | 370e99ce8c8b5b4bdc8f05b05b80259a3c89be5f | |
parent | b4b49ccc41b717a4274470d73785f9b913d97b59 (diff) |
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
-rw-r--r-- | include/gpu/GrPaint.h | 4 | ||||
-rw-r--r-- | include/gpu/GrSamplerState.h | 83 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 32 | ||||
-rw-r--r-- | src/gpu/GrGpu.cpp | 10 | ||||
-rw-r--r-- | src/gpu/GrTextContext.cpp | 1 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 10 |
6 files changed, 52 insertions, 88 deletions
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index aadd648434..ace11cc074 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -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(); } } }; diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h index 7c9bf133f1..42e9d0d6eb 100644 --- a/include/gpu/GrSamplerState.h +++ b/include/gpu/GrSamplerState.h @@ -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 diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 335b9f4354..de80f654a7 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -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()); diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 764ccd3eaf..1583630ecd 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -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; diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp index 657841c3a7..4b78d4a8c7 100644 --- a/src/gpu/GrTextContext.cpp +++ b/src/gpu/GrTextContext.cpp @@ -34,7 +34,6 @@ void GrTextContext::flushGlyphs() { filter = GrSamplerState::kBilinear_Filter; } GrSamplerState sampler(GrSamplerState::kRepeat_WrapMode, - GrSamplerState::kRepeat_WrapMode, filter); fDrawTarget->setSamplerState(kGlyphMaskStage, sampler); diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 0ad0a5c7b6..5daf42cd91 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -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), |