aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkShader.h10
-rw-r--r--samplecode/SampleFatBits.cpp10
-rw-r--r--src/core/SkPictureShader.cpp6
-rw-r--r--src/core/SkShader.cpp15
-rw-r--r--src/effects/SkRectShaderImageFilter.cpp6
-rw-r--r--src/pdf/SkPDFDeviceFlattener.cpp7
6 files changed, 24 insertions, 30 deletions
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 2f3764c0be..87e10ceb2f 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -38,14 +38,15 @@ public:
virtual ~SkShader();
/**
- * Returns true if the local matrix is not an identity matrix.
+ * Returns the local matrix.
*/
- bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); }
+ const SkMatrix& getLocalMatrix() const { return fLocalMatrix; }
+#ifdef SK_SUPPORT_LEGACY_SHADER_LOCALMATRIX
/**
- * Returns the local matrix.
+ * Returns true if the local matrix is not an identity matrix.
*/
- const SkMatrix& getLocalMatrix() const { return fLocalMatrix; }
+ bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); }
/**
* Set the shader's local matrix.
@@ -57,6 +58,7 @@ public:
* Reset the shader's local matrix to identity.
*/
void resetLocalMatrix() { fLocalMatrix.reset(); }
+#endif
enum TileMode {
/** replicate the edge color if the shader draws outside of its
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp
index 9ea1d9e479..6057c68fde 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -35,7 +35,7 @@ static void erase(SkSurface* surface) {
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
}
-static SkShader* createChecker() {
+static SkShader* createChecker(const SkMatrix& localMatrix) {
// SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
SkBitmap bm;
@@ -43,15 +43,13 @@ static SkShader* createChecker() {
bm.lockPixels();
*bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
*bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
- SkMatrix m;
- m.setScale(12, 12);
return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
- SkShader::kRepeat_TileMode, &m);
+ SkShader::kRepeat_TileMode, &localMatrix);
}
class FatBits {
public:
- FatBits() : fShader(createChecker()) {
+ FatBits() {
fAA = false;
fStyle = kHair_Style;
fGrid = true;
@@ -100,7 +98,7 @@ public:
fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom));
fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
- fShader->setLocalMatrix(fMatrix);
+ fShader.reset(createChecker(fMatrix));
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
fMinSurface.reset(SkSurface::NewRaster(info));
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 9655e85bd1..21eba80230 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -56,11 +56,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
SkMatrix m;
- if (this->hasLocalMatrix()) {
- m.setConcat(matrix, this->getLocalMatrix());
- } else {
- m = matrix;
- }
+ m.setConcat(matrix, this->getLocalMatrix());
if (localM) {
m.preConcat(*localM);
}
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index ebe1a74cc2..8dbe6d7029 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -60,7 +60,7 @@ SkShader::~SkShader() {
void SkShader::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer);
- bool hasLocalM = this->hasLocalMatrix();
+ bool hasLocalM = !fLocalMatrix.isIdentity();
buffer.writeBool(hasLocalM);
if (hasLocalM) {
buffer.writeMatrix(fLocalMatrix);
@@ -68,13 +68,10 @@ void SkShader::flatten(SkWriteBuffer& buffer) const {
}
bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse) const {
- const SkMatrix* m = rec.fMatrix;
- SkMatrix total;
+ SkMatrix total;
+ total.setConcat(*rec.fMatrix, fLocalMatrix);
- if (this->hasLocalMatrix()) {
- total.setConcat(*m, this->getLocalMatrix());
- m = &total;
- }
+ const SkMatrix* m = &total;
if (rec.fLocalMatrix) {
total.setConcat(*m, *rec.fLocalMatrix);
m = &total;
@@ -235,9 +232,9 @@ SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
#ifndef SK_IGNORE_TO_STRING
void SkShader::toString(SkString* str) const {
- if (this->hasLocalMatrix()) {
+ if (!fLocalMatrix.isIdentity()) {
str->append(" ");
- this->getLocalMatrix().toString(str);
+ fLocalMatrix.toString(str);
}
}
#endif
diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp
index 13e59c2c27..bed017c326 100644
--- a/src/effects/SkRectShaderImageFilter.cpp
+++ b/src/effects/SkRectShaderImageFilter.cpp
@@ -66,13 +66,15 @@ bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
return false;
}
SkCanvas canvas(device.get());
+
SkPaint paint;
- paint.setShader(fShader);
SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
- fShader->setLocalMatrix(matrix);
+ paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matrix))->unref();
+
SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height()));
canvas.drawRect(rect, paint);
+
*result = device.get()->accessBitmap(false);
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
diff --git a/src/pdf/SkPDFDeviceFlattener.cpp b/src/pdf/SkPDFDeviceFlattener.cpp
index 91c9803c32..aea87f6546 100644
--- a/src/pdf/SkPDFDeviceFlattener.cpp
+++ b/src/pdf/SkPDFDeviceFlattener.cpp
@@ -6,7 +6,6 @@
*/
#include "SkPDFDeviceFlattener.h"
-
#include "SkDraw.h"
static SkISize SkSizeToISize(const SkSize& size) {
@@ -25,9 +24,9 @@ SkPDFDeviceFlattener::~SkPDFDeviceFlattener() {
static void flattenPaint(const SkDraw& d, SkPaint* paint) {
if (paint->getShader()) {
- SkMatrix local = paint->getShader()->getLocalMatrix();
- local.preConcat(*d.fMatrix);
- paint->getShader()->setLocalMatrix(local);
+ SkAutoTUnref<SkShader> lms(SkShader::CreateLocalMatrixShader(paint->getShader(),
+ *d.fMatrix));
+ paint->setShader(lms);
}
}