From 5aacfe9ffcf1849727dca6761b4a221bd4315f26 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 2 May 2014 21:23:52 +0000 Subject: Remove setLocalMatrix calls from picture shader GM. This makes all --skr tests pass for me. Enabling it by default in DM. BUG=skia:2378 Committed: http://code.google.com/p/skia/source/detail?r=14549 R=reed@google.com, mtklein@google.com, fmalita@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/260863007 git-svn-id: http://skia.googlecode.com/svn/trunk@14551 2bbb7eff-a529-9590-31e7-b0007b416f81 --- dm/DMRecordTask.cpp | 2 +- gm/pictureshader.cpp | 45 +++++++++++++++++++------------------------- include/core/SkShader.h | 3 ++- src/core/SkPictureShader.cpp | 12 ++++++++---- src/core/SkPictureShader.h | 4 ++-- src/core/SkShader.cpp | 5 +++-- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/dm/DMRecordTask.cpp b/dm/DMRecordTask.cpp index eb8ceecbbd..d1c552f569 100644 --- a/dm/DMRecordTask.cpp +++ b/dm/DMRecordTask.cpp @@ -4,7 +4,7 @@ #include "SkCommandLineFlags.h" #include "SkRecording.h" -DEFINE_bool(skr, false, "If true, run SKR tests."); +DEFINE_bool(skr, true, "If true, run SKR tests."); namespace DM { diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp index 44db338fc2..8b26e48663 100644 --- a/gm/pictureshader.cpp +++ b/gm/pictureshader.cpp @@ -13,8 +13,6 @@ #include "SkPictureRecorder.h" #include "SkShader.h" -namespace skiagm { - static struct { SkShader::TileMode tmx; SkShader::TileMode tmy; @@ -24,9 +22,8 @@ static struct { { SkShader::kMirror_TileMode, SkShader::kRepeat_TileMode }, }; -class PictureShaderGM : public GM { +class PictureShaderGM : public skiagm::GM { public: - PictureShaderGM(SkScalar tileSize, SkScalar sceneSize) : fTileSize(tileSize) , fSceneSize(sceneSize) { @@ -37,24 +34,13 @@ public: SkScalarRoundToInt(tileSize), NULL, 0); this->drawTile(pictureCanvas); - SkAutoTUnref p(recorder.endRecording()); + fPicture.reset(recorder.endRecording()); // Build a reference bitmap. - SkBitmap bm; - bm.allocN32Pixels(SkScalarRoundToInt(tileSize), SkScalarRoundToInt(tileSize)); - bm.eraseColor(SK_ColorTRANSPARENT); - SkCanvas bitmapCanvas(bm); + fBitmap.allocN32Pixels(SkScalarRoundToInt(tileSize), SkScalarRoundToInt(tileSize)); + fBitmap.eraseColor(SK_ColorTRANSPARENT); + SkCanvas bitmapCanvas(fBitmap); this->drawTile(&bitmapCanvas); - - for (unsigned i = 0; i < SK_ARRAY_COUNT(kTileConfigs); ++i) { - fPictureShaders[i].reset(SkShader::CreatePictureShader(p, - kTileConfigs[i].tmx, - kTileConfigs[i].tmy)); - - fBitmapShaders[i].reset(SkShader::CreateBitmapShader(bm, - kTileConfigs[i].tmx, - kTileConfigs[i].tmy)); - } } protected: @@ -145,14 +131,22 @@ private: canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); canvas->drawRect(SkRect::MakeXYWH(fSceneSize * 1.1f, 0, fSceneSize, fSceneSize), paint); - fPictureShaders[tileMode]->setLocalMatrix(localMatrix); - paint.setShader(fPictureShaders[tileMode].get()); + SkAutoTUnref pictureShader(SkShader::CreatePictureShader( + fPicture, + kTileConfigs[tileMode].tmx, + kTileConfigs[tileMode].tmy, + &localMatrix)); + paint.setShader(pictureShader.get()); canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); canvas->translate(fSceneSize * 1.1f, 0); - fBitmapShaders[tileMode]->setLocalMatrix(localMatrix); - paint.setShader(fBitmapShaders[tileMode].get()); + SkAutoTUnref bitmapShader(SkShader::CreateBitmapShader( + fBitmap, + kTileConfigs[tileMode].tmx, + kTileConfigs[tileMode].tmy, + &localMatrix)); + paint.setShader(bitmapShader.get()); canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); canvas->restore(); @@ -161,11 +155,10 @@ private: SkScalar fTileSize; SkScalar fSceneSize; - SkAutoTUnref fPictureShaders[SK_ARRAY_COUNT(kTileConfigs)]; - SkAutoTUnref fBitmapShaders[SK_ARRAY_COUNT(kTileConfigs)]; + SkAutoTUnref fPicture; + SkBitmap fBitmap; typedef GM INHERITED; }; DEF_GM( return SkNEW_ARGS(PictureShaderGM, (50, 100)); ) -} diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 32707d7313..bcb229d767 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -402,7 +402,8 @@ public: * @param tmy The tiling mode to use when sampling the bitmap in the y-direction. * @return Returns a new shader object. Note: this function never returns null. */ - static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy); + static SkShader* CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix = NULL); SK_TO_STRING_VIRT() SK_DEFINE_FLATTENABLE_TYPE(SkShader) diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 27cbb00f63..81f9242854 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -18,8 +18,10 @@ #include "GrContext.h" #endif -SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy) - : fPicture(SkRef(picture)) +SkPictureShader::SkPictureShader(SkPicture* picture, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix) + : INHERITED(localMatrix) + , fPicture(SkRef(picture)) , fTmx(tmx) , fTmy(tmy) { } @@ -34,11 +36,12 @@ SkPictureShader::~SkPictureShader() { fPicture->unref(); } -SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileMode tmy) { +SkPictureShader* SkPictureShader::Create(SkPicture* picture, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix) { if (!picture || 0 == picture->width() || 0 == picture->height()) { return NULL; } - return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy)); + return SkNEW_ARGS(SkPictureShader, (picture, tmx, tmy, localMatrix)); } void SkPictureShader::flatten(SkWriteBuffer& buffer) const { @@ -79,6 +82,7 @@ SkShader* SkPictureShader::refBitmapShader(const SkMatrix& matrix) const { SkAutoMutexAcquire ama(fCachedBitmapShaderMutex); + // TODO(fmalita): remove fCachedLocalMatrix from this key after getLocalMatrix is removed. if (!fCachedBitmapShader || tileScale != fCachedTileScale || this->getLocalMatrix() != fCachedLocalMatrix) { SkBitmap bm; diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h index 510c9888f5..2ef6c1c92a 100644 --- a/src/core/SkPictureShader.h +++ b/src/core/SkPictureShader.h @@ -21,7 +21,7 @@ class SkPicture; */ class SkPictureShader : public SkShader { public: - static SkPictureShader* Create(SkPicture*, TileMode, TileMode); + static SkPictureShader* Create(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL); virtual ~SkPictureShader(); virtual bool validContext(const ContextRec&, SkMatrix* totalInverse) const SK_OVERRIDE; @@ -59,7 +59,7 @@ protected: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; private: - SkPictureShader(SkPicture*, TileMode, TileMode); + SkPictureShader(SkPicture*, TileMode, TileMode, const SkMatrix* = NULL); SkShader* validInternal(const ContextRec&, SkMatrix* totalInverse) const; SkShader* refBitmapShader(const SkMatrix&) const; diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 0f6ba4ce9f..67dd581543 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -193,8 +193,9 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileMo return ::CreateBitmapShader(src, tmx, tmy, localMatrix, NULL); } -SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy) { - return SkPictureShader::Create(src, tmx, tmy); +SkShader* SkShader::CreatePictureShader(SkPicture* src, TileMode tmx, TileMode tmy, + const SkMatrix* localMatrix) { + return SkPictureShader::Create(src, tmx, tmy, localMatrix); } #ifndef SK_IGNORE_TO_STRING -- cgit v1.2.3