Remove easily-removable uses of setTexture(), instead creating a GrSingleTextureEffect -
where feasible, through convenience function on GrDrawState. http://codereview.appspot.com/6425055/ git-svn-id: http://skia.googlecode.com/svn/trunk@4694 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
96291dfa70
commit
1e8f016305
@ -51,6 +51,9 @@ public:
|
|||||||
|
|
||||||
GrTexture* getTexture(int i) const {
|
GrTexture* getTexture(int i) const {
|
||||||
GrAssert((unsigned)i < kMaxTextures);
|
GrAssert((unsigned)i < kMaxTextures);
|
||||||
|
//if (this->getTextureSampler(i).getCustomStage()) {
|
||||||
|
//return this->getTextureSampler(i).getCustomStage()->texture(i);
|
||||||
|
//}
|
||||||
return fTextures[i];
|
return fTextures[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +84,9 @@ public:
|
|||||||
|
|
||||||
GrTexture* getMask(int i) const {
|
GrTexture* getMask(int i) const {
|
||||||
GrAssert((unsigned)i < kMaxMasks);
|
GrAssert((unsigned)i < kMaxMasks);
|
||||||
|
//if (this->getMaskSampler(i).getCustomStage()) {
|
||||||
|
//return this->getMaskSampler(i).getCustomStage()->texture(i);
|
||||||
|
//}
|
||||||
return fMaskTextures[i];
|
return fMaskTextures[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ void setup_drawstate_aaclip(GrGpu* gpu,
|
|||||||
GrSamplerState::kNearest_Filter,
|
GrSamplerState::kNearest_Filter,
|
||||||
mat);
|
mat);
|
||||||
|
|
||||||
drawState->setTexture(maskStage, result);
|
drawState->createTextureEffect(maskStage, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool path_needs_SW_renderer(GrContext* context,
|
bool path_needs_SW_renderer(GrContext* context,
|
||||||
@ -431,11 +431,11 @@ void GrClipMaskManager::drawTexture(GrTexture* target,
|
|||||||
|
|
||||||
GrMatrix sampleM;
|
GrMatrix sampleM;
|
||||||
sampleM.setIDiv(texture->width(), texture->height());
|
sampleM.setIDiv(texture->width(), texture->height());
|
||||||
drawState->setTexture(0, texture);
|
|
||||||
|
|
||||||
drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
|
drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
|
||||||
GrSamplerState::kNearest_Filter,
|
GrSamplerState::kNearest_Filter,
|
||||||
sampleM);
|
sampleM);
|
||||||
|
drawState->createTextureEffect(0, texture);
|
||||||
|
|
||||||
GrRect rect = GrRect::MakeWH(SkIntToScalar(target->width()),
|
GrRect rect = GrRect::MakeWH(SkIntToScalar(target->width()),
|
||||||
SkIntToScalar(target->height()));
|
SkIntToScalar(target->height()));
|
||||||
|
@ -368,8 +368,7 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture(
|
|||||||
GrDrawTarget::kReset_ASRInit);
|
GrDrawTarget::kReset_ASRInit);
|
||||||
GrDrawState* drawState = fGpu->drawState();
|
GrDrawState* drawState = fGpu->drawState();
|
||||||
drawState->setRenderTarget(texture->asRenderTarget());
|
drawState->setRenderTarget(texture->asRenderTarget());
|
||||||
drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect,
|
drawState->createTextureEffect(0, clampEntry.texture());
|
||||||
(clampEntry.texture())))->unref();
|
|
||||||
|
|
||||||
GrSamplerState::Filter filter;
|
GrSamplerState::Filter filter;
|
||||||
// if filtering is not desired then we want to ensure all
|
// if filtering is not desired then we want to ensure all
|
||||||
@ -1405,7 +1404,7 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target,
|
|||||||
matrix.postIDiv(src->width(), src->height());
|
matrix.postIDiv(src->width(), src->height());
|
||||||
drawState->sampler(0)->reset(matrix);
|
drawState->sampler(0)->reset(matrix);
|
||||||
drawState->sampler(0)->setRAndBSwap(swapRAndB);
|
drawState->sampler(0)->setRAndBSwap(swapRAndB);
|
||||||
drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (src)))->unref();
|
drawState->createTextureEffect(0, src);
|
||||||
GrRect rect;
|
GrRect rect;
|
||||||
rect.setXYWH(0, 0, SK_Scalar1 * width, SK_Scalar1 * height);
|
rect.setXYWH(0, 0, SK_Scalar1 * width, SK_Scalar1 * height);
|
||||||
fGpu->drawSimpleRect(rect, NULL);
|
fGpu->drawSimpleRect(rect, NULL);
|
||||||
@ -1445,7 +1444,7 @@ void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst) {
|
|||||||
GrMatrix sampleM;
|
GrMatrix sampleM;
|
||||||
sampleM.setIDiv(src->width(), src->height());
|
sampleM.setIDiv(src->width(), src->height());
|
||||||
drawState->sampler(0)->reset(sampleM);
|
drawState->sampler(0)->reset(sampleM);
|
||||||
drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (src)))->unref();
|
drawState->createTextureEffect(0, src);
|
||||||
SkRect rect = SkRect::MakeXYWH(0, 0,
|
SkRect rect = SkRect::MakeXYWH(0, 0,
|
||||||
SK_Scalar1 * src->width(),
|
SK_Scalar1 * src->width(),
|
||||||
SK_Scalar1 * src->height());
|
SK_Scalar1 * src->height());
|
||||||
@ -1544,7 +1543,7 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target,
|
|||||||
drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
|
drawState->sampler(0)->reset(GrSamplerState::kClamp_WrapMode,
|
||||||
GrSamplerState::kNearest_Filter,
|
GrSamplerState::kNearest_Filter,
|
||||||
matrix);
|
matrix);
|
||||||
drawState->sampler(0)->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
|
drawState->createTextureEffect(0, texture);
|
||||||
drawState->sampler(0)->setRAndBSwap(swapRAndB);
|
drawState->sampler(0)->setRAndBSwap(swapRAndB);
|
||||||
|
|
||||||
static const GrVertexLayout layout = 0;
|
static const GrVertexLayout layout = 0;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "GrStencil.h"
|
#include "GrStencil.h"
|
||||||
#include "GrTexture.h"
|
#include "GrTexture.h"
|
||||||
#include "GrRenderTarget.h"
|
#include "GrRenderTarget.h"
|
||||||
|
#include "effects/GrSingleTextureEffect.h"
|
||||||
|
|
||||||
#include "SkXfermode.h"
|
#include "SkXfermode.h"
|
||||||
|
|
||||||
@ -187,6 +188,8 @@ public:
|
|||||||
*
|
*
|
||||||
* @param texture The texture to set. Can be NULL though there is no
|
* @param texture The texture to set. Can be NULL though there is no
|
||||||
* advantage to settings a NULL texture if doing non-textured drawing
|
* advantage to settings a NULL texture if doing non-textured drawing
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
void setTexture(int stage, GrTexture* texture) {
|
void setTexture(int stage, GrTexture* texture) {
|
||||||
GrAssert((unsigned)stage < kNumStages);
|
GrAssert((unsigned)stage < kNumStages);
|
||||||
@ -194,6 +197,17 @@ public:
|
|||||||
GrSafeAssign(fTextures[stage], texture);
|
GrSafeAssign(fTextures[stage], texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a GrSingleTextureEffect.
|
||||||
|
*
|
||||||
|
* Replacement for setTexture.
|
||||||
|
*/
|
||||||
|
void createTextureEffect(int stage, GrTexture* texture) {
|
||||||
|
GrAssert(!this->getSampler(stage).getCustomStage());
|
||||||
|
this->sampler(stage)->setCustomStage(
|
||||||
|
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the currently set texture.
|
* Retrieves the currently set texture.
|
||||||
*
|
*
|
||||||
|
@ -212,8 +212,8 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
|
|||||||
kPathMaskStage = GrPaint::kTotalStages,
|
kPathMaskStage = GrPaint::kTotalStages,
|
||||||
};
|
};
|
||||||
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
|
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
|
||||||
drawState->setTexture(kPathMaskStage, texture);
|
|
||||||
drawState->sampler(kPathMaskStage)->reset();
|
drawState->sampler(kPathMaskStage)->reset();
|
||||||
|
drawState->createTextureEffect(kPathMaskStage, texture);
|
||||||
GrScalar w = GrIntToScalar(rect.width());
|
GrScalar w = GrIntToScalar(rect.width());
|
||||||
GrScalar h = GrIntToScalar(rect.height());
|
GrScalar h = GrIntToScalar(rect.height());
|
||||||
GrRect maskRect = GrRect::MakeWH(w / texture->width(),
|
GrRect maskRect = GrRect::MakeWH(w / texture->width(),
|
||||||
|
@ -40,7 +40,7 @@ void GrTextContext::flushGlyphs() {
|
|||||||
|
|
||||||
GrAssert(GrIsALIGN4(fCurrVertex));
|
GrAssert(GrIsALIGN4(fCurrVertex));
|
||||||
GrAssert(fCurrTexture);
|
GrAssert(fCurrTexture);
|
||||||
drawState->setTexture(kGlyphMaskStage, fCurrTexture);
|
drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture);
|
||||||
|
|
||||||
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
|
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
|
||||||
if (kOne_GrBlendCoeff != fPaint.fSrcBlendCoeff ||
|
if (kOne_GrBlendCoeff != fPaint.fSrcBlendCoeff ||
|
||||||
|
@ -425,7 +425,13 @@ SkGpuRenderTarget* SkGpuDevice::accessRenderTarget() {
|
|||||||
|
|
||||||
bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
|
bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
|
||||||
if (NULL != fTexture) {
|
if (NULL != fTexture) {
|
||||||
|
// FIXME: cannot use GrSingleTextureEffect here: fails
|
||||||
|
// assert in line 1617: null != devTex; generalizing GrPaint::getTexture()
|
||||||
|
// to grab textures off of GrCustomStages breaks gms in various ways -
|
||||||
|
// particularly since table color filter requires multiple textures
|
||||||
paint->setTexture(kBitmapTextureIdx, fTexture);
|
paint->setTexture(kBitmapTextureIdx, fTexture);
|
||||||
|
//paint->textureSampler(kBitmapTextureIdx)->setCustomStage(
|
||||||
|
//SkNEW_ARGS(GrSingleTextureEffect, (fTexture)))->unref();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -486,7 +492,7 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
|
|||||||
GrAssert(!constantColor);
|
GrAssert(!constantColor);
|
||||||
} else {
|
} else {
|
||||||
grPaint->fColor = SkColor2GrColor(skPaint.getColor());
|
grPaint->fColor = SkColor2GrColor(skPaint.getColor());
|
||||||
grPaint->setTexture(kShaderTextureIdx, NULL);
|
GrAssert(NULL == grPaint->getTexture(kShaderTextureIdx));
|
||||||
}
|
}
|
||||||
SkColorFilter* colorFilter = skPaint.getColorFilter();
|
SkColorFilter* colorFilter = skPaint.getColorFilter();
|
||||||
SkColor color;
|
SkColor color;
|
||||||
@ -616,9 +622,7 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
|||||||
} else {
|
} else {
|
||||||
sampler->setFilter(GrSamplerState::kNearest_Filter);
|
sampler->setFilter(GrSamplerState::kNearest_Filter);
|
||||||
}
|
}
|
||||||
// TODO - once we have a trivial GrCustomStage for texture drawing,
|
sampler->setCustomStage(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
|
||||||
// create that here & get rid of the paint's texture
|
|
||||||
grPaint->setTexture(kShaderTextureIdx, texture);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sampler->setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
|
sampler->setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
|
||||||
@ -904,7 +908,8 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
|
|||||||
pathTexture->height());
|
pathTexture->height());
|
||||||
// Blend pathTexture over blurTexture.
|
// Blend pathTexture over blurTexture.
|
||||||
context->setRenderTarget(blurTexture->asRenderTarget());
|
context->setRenderTarget(blurTexture->asRenderTarget());
|
||||||
paint.setTexture(0, pathTexture);
|
paint.textureSampler(0)->setCustomStage(SkNEW_ARGS
|
||||||
|
(GrSingleTextureEffect, (pathTexture)))->unref();
|
||||||
if (SkMaskFilter::kInner_BlurType == blurType) {
|
if (SkMaskFilter::kInner_BlurType == blurType) {
|
||||||
// inner: dst = dst * src
|
// inner: dst = dst * src
|
||||||
paint.fSrcBlendCoeff = kDC_GrBlendCoeff;
|
paint.fSrcBlendCoeff = kDC_GrBlendCoeff;
|
||||||
@ -1409,7 +1414,8 @@ void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
grPaint->setTexture(kBitmapTextureIdx, texture);
|
grPaint->textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
|
||||||
|
(GrSingleTextureEffect, (texture)))->unref();
|
||||||
|
|
||||||
GrRect dstRect = SkRect::MakeWH(GrIntToScalar(srcRect.width()),
|
GrRect dstRect = SkRect::MakeWH(GrIntToScalar(srcRect.width()),
|
||||||
GrIntToScalar(srcRect.height()));
|
GrIntToScalar(srcRect.height()));
|
||||||
@ -1558,14 +1564,16 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
|||||||
GrTexture* texture;
|
GrTexture* texture;
|
||||||
sampler->reset();
|
sampler->reset();
|
||||||
SkAutoCachedTexture act(this, bitmap, sampler, &texture);
|
SkAutoCachedTexture act(this, bitmap, sampler, &texture);
|
||||||
grPaint.setTexture(kBitmapTextureIdx, texture);
|
grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
|
||||||
|
(GrSingleTextureEffect, (texture)))->unref();
|
||||||
|
|
||||||
SkImageFilter* filter = paint.getImageFilter();
|
SkImageFilter* filter = paint.getImageFilter();
|
||||||
if (NULL != filter) {
|
if (NULL != filter) {
|
||||||
GrTexture* filteredTexture = filter_texture(fContext, texture, filter,
|
GrTexture* filteredTexture = filter_texture(fContext, texture, filter,
|
||||||
GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
|
GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
|
||||||
if (filteredTexture) {
|
if (filteredTexture) {
|
||||||
grPaint.setTexture(kBitmapTextureIdx, filteredTexture);
|
grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
|
||||||
|
(GrSingleTextureEffect, (filteredTexture)))->unref();
|
||||||
texture = filteredTexture;
|
texture = filteredTexture;
|
||||||
filteredTexture->unref();
|
filteredTexture->unref();
|
||||||
}
|
}
|
||||||
@ -1608,7 +1616,8 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device,
|
|||||||
GrTexture* filteredTexture = filter_texture(fContext, devTex, filter,
|
GrTexture* filteredTexture = filter_texture(fContext, devTex, filter,
|
||||||
rect);
|
rect);
|
||||||
if (filteredTexture) {
|
if (filteredTexture) {
|
||||||
grPaint.setTexture(kBitmapTextureIdx, filteredTexture);
|
grPaint.textureSampler(kBitmapTextureIdx)->setCustomStage(SkNEW_ARGS
|
||||||
|
(GrSingleTextureEffect, (filteredTexture)))->unref();
|
||||||
devTex = filteredTexture;
|
devTex = filteredTexture;
|
||||||
filteredTexture->unref();
|
filteredTexture->unref();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user