Index: gm/pictureshader.cpp |
diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp |
index 44db338fc203bf38fd6ec698e26757bfcd9a3fda..8b26e48663b8339f750752a7478eb105645da0ea 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<SkPicture> 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<SkShader> 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<SkShader> 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<SkShader> fPictureShaders[SK_ARRAY_COUNT(kTileConfigs)]; |
- SkAutoTUnref<SkShader> fBitmapShaders[SK_ARRAY_COUNT(kTileConfigs)]; |
+ SkAutoTUnref<SkPicture> fPicture; |
+ SkBitmap fBitmap; |
typedef GM INHERITED; |
}; |
DEF_GM( return SkNEW_ARGS(PictureShaderGM, (50, 100)); ) |
-} |