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
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4e0e587..4a16d9d 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -868,8 +868,6 @@
filter = GrSamplerState::kBilinear_Filter;
}
- GrMatrix sampleM;
-
GrTexture* src = record->fOffscreen0.texture();
int scale;
@@ -888,11 +886,10 @@
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 @@
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 aa5cf20..4211da9 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -1085,7 +1085,7 @@
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 fb16b22..f266368 100644
--- a/src/gpu/GrGpuGL.cpp
+++ b/src/gpu/GrGpuGL.cpp
@@ -518,7 +518,7 @@
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 5534d05..5fe90b8 100644
--- a/src/gpu/GrGpuGLShaders.cpp
+++ b/src/gpu/GrGpuGLShaders.cpp
@@ -374,7 +374,7 @@
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 bf00fa3..b80d3a6 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -473,10 +473,10 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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);