aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-12-12 18:45:07 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-12-12 18:45:07 +0000
commitaa814fe4a148b05f9160a5f77cb4e630406ea62d (patch)
tree7c6cabf3451402200f130cdb5b42d5d9bcccaa49 /src/gpu
parent4d4f281b28c3db0513ea1a68db4577e2518002b3 (diff)
Access sampler matrices directly, cleanup GrSamplerState::reset()s
Review URL: http://codereview.appspot.com/5488048/ git-svn-id: http://skia.googlecode.com/svn/trunk@2854 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp18
-rw-r--r--src/gpu/GrDrawTarget.cpp2
-rw-r--r--src/gpu/GrGpuGL.cpp2
-rw-r--r--src/gpu/GrGpuGLShaders.cpp2
-rw-r--r--src/gpu/SkGpuDevice.cpp46
5 files changed, 29 insertions, 41 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4e0e587c2a..4a16d9d377 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -868,8 +868,6 @@ void GrContext::doOffscreenAAPass2(GrDrawTarget* target,
filter = GrSamplerState::kBilinear_Filter;
}
- GrMatrix sampleM;
-
GrTexture* src = record->fOffscreen0.texture();
int scale;
@@ -888,11 +886,10 @@ void GrContext::doOffscreenAAPass2(GrDrawTarget* target,
drawState->setTexture(kOffscreenStage, src);
drawState->setRenderTarget(dst);
drawState->setViewMatrix(GrMatrix::I());
- sampleM.setScale(scale * GR_Scalar1 / src->width(),
- scale * GR_Scalar1 / src->height());
GrSamplerState* sampler = drawState->sampler(kOffscreenStage);
sampler->reset(GrSamplerState::kClamp_WrapMode, filter);
- sampler->setMatrix(sampleM);
+ sampler->matrix()->setScale(scale * GR_Scalar1 / src->width(),
+ scale * GR_Scalar1 / src->height());
GrRect rect = SkRect::MakeWH(SkIntToScalar(scale * tileRect.width()),
SkIntToScalar(scale * tileRect.height()));
target->drawSimpleRect(rect, NULL, 1 << kOffscreenStage);
@@ -930,13 +927,10 @@ void GrContext::doOffscreenAAPass2(GrDrawTarget* target,
drawState->setTexture(kOffscreenStage, src);
GrSamplerState* sampler = drawState->sampler(kOffscreenStage);
sampler->reset(GrSamplerState::kClamp_WrapMode, filter);
- sampleM.setScale(scale * GR_Scalar1 / src->width(),
- scale * GR_Scalar1 / src->height());
-
- sampler->setMatrix(sampleM);
- sampleM.setTranslate(SkIntToScalar(-tileRect.fLeft),
- SkIntToScalar(-tileRect.fTop));
- sampler->preConcatMatrix(sampleM);
+ sampler->matrix()->setScale(scale * GR_Scalar1 / src->width(),
+ scale * GR_Scalar1 / src->height());
+ sampler->matrix()->preTranslate(SkIntToScalar(-tileRect.fLeft),
+ SkIntToScalar(-tileRect.fTop));
GrRect dstRect;
int stages = (1 << kOffscreenStage) | stageMask;
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index aa5cf201d2..4211da97e2 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -1085,7 +1085,7 @@ GrDrawTarget::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
drawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fStageMask & (1 << s)) {
- drawState->sampler(s)->setMatrix(fSamplerMatrices[s]);
+ *drawState->sampler(s)->matrix() = fSamplerMatrices[s];
}
}
}
diff --git a/src/gpu/GrGpuGL.cpp b/src/gpu/GrGpuGL.cpp
index fb16b22ec3..f2663689e1 100644
--- a/src/gpu/GrGpuGL.cpp
+++ b/src/gpu/GrGpuGL.cpp
@@ -518,7 +518,7 @@ void GrGpuGL::onResetContext() {
fHWDrawState.sampler(s)->setRadial2Params(-GR_ScalarMax,
-GR_ScalarMax,
true);
- fHWDrawState.sampler(s)->setMatrix(GrMatrix::InvalidMatrix());
+ *fHWDrawState.sampler(s)->matrix() = GrMatrix::InvalidMatrix();
fHWDrawState.sampler(s)->setConvolutionParams(0, NULL, NULL);
}
diff --git a/src/gpu/GrGpuGLShaders.cpp b/src/gpu/GrGpuGLShaders.cpp
index 5534d050bd..5fe90b8b12 100644
--- a/src/gpu/GrGpuGLShaders.cpp
+++ b/src/gpu/GrGpuGLShaders.cpp
@@ -374,7 +374,7 @@ void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) {
GrAssert(fProgramData);
if (GrGLProgram::kSetAsAttribute ==
fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) {
- fHWDrawState.sampler(stage)->setMatrix(matrix);
+ *fHWDrawState.sampler(stage)->matrix() = matrix;
} else {
fProgramData->fTextureMatrices[stage] = matrix;
}
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index bf00fa3d73..b80d3a6063 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -473,10 +473,10 @@ bool SkGpuDevice::skPaint2GrPaintShader(const SkPaint& skPaint,
}
SkBitmap bitmap;
- SkMatrix matrix;
+ SkMatrix* matrix = grPaint->textureSampler(kShaderTextureIdx)->matrix();
SkShader::TileMode tileModes[2];
SkScalar twoPointParams[3];
- SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix,
+ SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, matrix,
tileModes, twoPointParams);
GrSamplerState::SampleMode sampleMode = sk_bmp_type_to_sample_mode[bmptype];
@@ -528,18 +528,17 @@ bool SkGpuDevice::skPaint2GrPaintShader(const SkPaint& skPaint,
if (shader->getLocalMatrix(&localM)) {
SkMatrix inverse;
if (localM.invert(&inverse)) {
- matrix.preConcat(inverse);
+ matrix->preConcat(inverse);
}
}
if (SkShader::kDefault_BitmapType == bmptype) {
GrScalar sx = GrFixedToScalar(GR_Fixed1 / bitmap.width());
GrScalar sy = GrFixedToScalar(GR_Fixed1 / bitmap.height());
- matrix.postScale(sx, sy);
+ matrix->postScale(sx, sy);
} else if (SkShader::kRadial_BitmapType == bmptype) {
GrScalar s = GrFixedToScalar(GR_Fixed1 / bitmap.width());
- matrix.postScale(s, s);
+ matrix->postScale(s, s);
}
- sampler->setMatrix(matrix);
return true;
}
@@ -762,9 +761,8 @@ static GrTexture* gaussianBlur(GrContext* context, GrTexture* srcTexture,
paint.textureSampler(0)->setFilter(GrSamplerState::kBilinear_Filter);
for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
- GrMatrix sampleM;
- sampleM.setIDiv(srcTexture->width(), srcTexture->height());
- paint.textureSampler(0)->setMatrix(sampleM);
+ paint.textureSampler(0)->matrix()->setIDiv(srcTexture->width(),
+ srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
SkRect dstRect(srcRect);
scaleRect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
@@ -826,9 +824,8 @@ static GrTexture* gaussianBlur(GrContext* context, GrTexture* srcTexture,
context->clear(&clearRect, 0x0);
// FIXME: This should be mitchell, not bilinear.
paint.textureSampler(0)->setFilter(GrSamplerState::kBilinear_Filter);
- GrMatrix sampleM;
- sampleM.setIDiv(srcTexture->width(), srcTexture->height());
- paint.textureSampler(0)->setMatrix(sampleM);
+ paint.textureSampler(0)->matrix()->setIDiv(srcTexture->width(),
+ srcTexture->height());
context->setRenderTarget(dstTexture->asRenderTarget());
paint.setTexture(0, srcTexture);
SkRect dstRect(srcRect);
@@ -935,9 +932,8 @@ static bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
GrPaint paint;
paint.reset();
paint.textureSampler(0)->setFilter(GrSamplerState::kNearest_Filter);
- GrMatrix sampleM;
- sampleM.setIDiv(pathTexture->width(), pathTexture->height());
- paint.textureSampler(0)->setMatrix(sampleM);
+ paint.textureSampler(0)->matrix()->setIDiv(pathTexture->width(),
+ pathTexture->height());
// Blend pathTexture over blurTexture.
context->setRenderTarget(blurTexture->asRenderTarget());
paint.setTexture(0, pathTexture);
@@ -975,10 +971,10 @@ static bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
grp->setMask(MASK_IDX, blurTexture);
grp->maskSampler(MASK_IDX)->reset();
- GrMatrix m;
- m.setTranslate(-finalRect.fLeft, -finalRect.fTop);
- m.postIDiv(blurTexture->width(), blurTexture->height());
- grp->maskSampler(MASK_IDX)->setMatrix(m);
+ grp->maskSampler(MASK_IDX)->matrix()->setTranslate(-finalRect.fLeft,
+ -finalRect.fTop);
+ grp->maskSampler(MASK_IDX)->matrix()->postIDiv(blurTexture->width(),
+ blurTexture->height());
context->drawRect(*grp, finalRect);
return true;
}
@@ -1049,12 +1045,10 @@ static bool drawWithMaskFilter(GrContext* context, const SkPath& path,
GrIntToScalar(dstM.fBounds.fRight),
GrIntToScalar(dstM.fBounds.fBottom));
- GrMatrix m;
- m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1,
- -dstM.fBounds.fTop*SK_Scalar1);
- m.postIDiv(texture->width(), texture->height());
- grp->maskSampler(MASK_IDX)->setMatrix(m);
-
+ GrMatrix* m = grp->maskSampler(MASK_IDX)->matrix();
+ m->setTranslate(-dstM.fBounds.fLeft*SK_Scalar1,
+ -dstM.fBounds.fTop*SK_Scalar1);
+ m->postIDiv(texture->width(), texture->height());
context->drawRect(*grp, d);
return true;
}
@@ -1404,7 +1398,7 @@ void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
sampler->setWrapX(GrSamplerState::kClamp_WrapMode);
sampler->setWrapY(GrSamplerState::kClamp_WrapMode);
sampler->setSampleMode(GrSamplerState::kNormal_SampleMode);
- sampler->setMatrix(GrMatrix::I());
+ sampler->matrix()->reset();
GrTexture* texture;
SkAutoCachedTexture act(this, bitmap, sampler, &texture);