Reason for revert:
broke gms

Original issue's description:
> hide get/setLocalMatrix
>
> BUG=skia:
>
> Committed: http://code.google.com/p/skia/source/detail?r=14675

R=fmalita@google.com, dominikg@chromium.org, fmalita@chromium.org
TBR=dominikg@chromium.org, fmalita@chromium.org, fmalita@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Author: reed@google.com

Review URL: https://codereview.chromium.org/278903002

git-svn-id: http://skia.googlecode.com/svn/trunk@14677 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-09 15:42:07 +00:00
parent 5d20caea15
commit d12de02542
6 changed files with 31 additions and 25 deletions

View File

@ -37,17 +37,16 @@ public:
SkShader(const SkMatrix* localMatrix = NULL); SkShader(const SkMatrix* localMatrix = NULL);
virtual ~SkShader(); virtual ~SkShader();
/**
* Returns the local matrix.
*/
const SkMatrix& getLocalMatrix() const { return fLocalMatrix; }
#ifdef SK_SUPPORT_LEGACY_SHADER_LOCALMATRIX
/** /**
* Returns true if the local matrix is not an identity matrix. * Returns true if the local matrix is not an identity matrix.
*/ */
bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); } bool hasLocalMatrix() const { return !fLocalMatrix.isIdentity(); }
/**
* Returns the local matrix.
*/
const SkMatrix& getLocalMatrix() const { return fLocalMatrix; }
/** /**
* Set the shader's local matrix. * Set the shader's local matrix.
* @param localM The shader's new local matrix. * @param localM The shader's new local matrix.
@ -58,7 +57,6 @@ public:
* Reset the shader's local matrix to identity. * Reset the shader's local matrix to identity.
*/ */
void resetLocalMatrix() { fLocalMatrix.reset(); } void resetLocalMatrix() { fLocalMatrix.reset(); }
#endif
enum TileMode { enum TileMode {
/** replicate the edge color if the shader draws outside of its /** replicate the edge color if the shader draws outside of its

View File

@ -35,7 +35,7 @@ static void erase(SkSurface* surface) {
surface->getCanvas()->clear(SK_ColorTRANSPARENT); surface->getCanvas()->clear(SK_ColorTRANSPARENT);
} }
static SkShader* createChecker(const SkMatrix& localMatrix) { static SkShader* createChecker() {
// SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 }; // SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 };
SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF }; SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF };
SkBitmap bm; SkBitmap bm;
@ -43,13 +43,15 @@ static SkShader* createChecker(const SkMatrix& localMatrix) {
bm.lockPixels(); bm.lockPixels();
*bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]); *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]);
*bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]); *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]);
SkMatrix m;
m.setScale(12, 12);
return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode, &localMatrix); SkShader::kRepeat_TileMode, &m);
} }
class FatBits { class FatBits {
public: public:
FatBits() { FatBits() : fShader(createChecker()) {
fAA = false; fAA = false;
fStyle = kHair_Style; fStyle = kHair_Style;
fGrid = true; fGrid = true;
@ -98,7 +100,7 @@ public:
fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom)); fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom));
fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom));
fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
fShader.reset(createChecker(fMatrix)); fShader->setLocalMatrix(fMatrix);
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
fMinSurface.reset(SkSurface::NewRaster(info)); fMinSurface.reset(SkSurface::NewRaster(info));

View File

@ -56,7 +56,11 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix, const SkMatri
SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0); SkASSERT(fPicture && fPicture->width() > 0 && fPicture->height() > 0);
SkMatrix m; SkMatrix m;
m.setConcat(matrix, this->getLocalMatrix()); if (this->hasLocalMatrix()) {
m.setConcat(matrix, this->getLocalMatrix());
} else {
m = matrix;
}
if (localM) { if (localM) {
m.preConcat(*localM); m.preConcat(*localM);
} }

View File

@ -60,7 +60,7 @@ SkShader::~SkShader() {
void SkShader::flatten(SkWriteBuffer& buffer) const { void SkShader::flatten(SkWriteBuffer& buffer) const {
this->INHERITED::flatten(buffer); this->INHERITED::flatten(buffer);
bool hasLocalM = !fLocalMatrix.isIdentity(); bool hasLocalM = this->hasLocalMatrix();
buffer.writeBool(hasLocalM); buffer.writeBool(hasLocalM);
if (hasLocalM) { if (hasLocalM) {
buffer.writeMatrix(fLocalMatrix); buffer.writeMatrix(fLocalMatrix);
@ -68,10 +68,13 @@ void SkShader::flatten(SkWriteBuffer& buffer) const {
} }
bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse) const { bool SkShader::computeTotalInverse(const ContextRec& rec, SkMatrix* totalInverse) const {
SkMatrix total; const SkMatrix* m = rec.fMatrix;
total.setConcat(*rec.fMatrix, fLocalMatrix); SkMatrix total;
const SkMatrix* m = &total; if (this->hasLocalMatrix()) {
total.setConcat(*m, this->getLocalMatrix());
m = &total;
}
if (rec.fLocalMatrix) { if (rec.fLocalMatrix) {
total.setConcat(*m, *rec.fLocalMatrix); total.setConcat(*m, *rec.fLocalMatrix);
m = &total; m = &total;
@ -232,9 +235,9 @@ SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode t
#ifndef SK_IGNORE_TO_STRING #ifndef SK_IGNORE_TO_STRING
void SkShader::toString(SkString* str) const { void SkShader::toString(SkString* str) const {
if (!fLocalMatrix.isIdentity()) { if (this->hasLocalMatrix()) {
str->append(" "); str->append(" ");
fLocalMatrix.toString(str); this->getLocalMatrix().toString(str);
} }
} }
#endif #endif

View File

@ -66,15 +66,13 @@ bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy,
return false; return false;
} }
SkCanvas canvas(device.get()); SkCanvas canvas(device.get());
SkPaint paint; SkPaint paint;
paint.setShader(fShader);
SkMatrix matrix(ctx.ctm()); SkMatrix matrix(ctx.ctm());
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top())); matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
paint.setShader(SkShader::CreateLocalMatrixShader(fShader, matrix))->unref(); fShader->setLocalMatrix(matrix);
SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height())); SkRect rect = SkRect::MakeWH(SkIntToScalar(bounds.width()), SkIntToScalar(bounds.height()));
canvas.drawRect(rect, paint); canvas.drawRect(rect, paint);
*result = device.get()->accessBitmap(false); *result = device.get()->accessBitmap(false);
offset->fX = bounds.fLeft; offset->fX = bounds.fLeft;
offset->fY = bounds.fTop; offset->fY = bounds.fTop;

View File

@ -6,6 +6,7 @@
*/ */
#include "SkPDFDeviceFlattener.h" #include "SkPDFDeviceFlattener.h"
#include "SkDraw.h" #include "SkDraw.h"
static SkISize SkSizeToISize(const SkSize& size) { static SkISize SkSizeToISize(const SkSize& size) {
@ -24,9 +25,9 @@ SkPDFDeviceFlattener::~SkPDFDeviceFlattener() {
static void flattenPaint(const SkDraw& d, SkPaint* paint) { static void flattenPaint(const SkDraw& d, SkPaint* paint) {
if (paint->getShader()) { if (paint->getShader()) {
SkAutoTUnref<SkShader> lms(SkShader::CreateLocalMatrixShader(paint->getShader(), SkMatrix local = paint->getShader()->getLocalMatrix();
*d.fMatrix)); local.preConcat(*d.fMatrix);
paint->setShader(lms); paint->getShader()->setLocalMatrix(local);
} }
} }