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 0 },
{ 0, 0, 1, 0.5f, 0, 0 },
- { -0.25f, -0.25f, 1, 0.5f, 0, 0 },
{ 0.25f, 0.25f, 1, 0.5f, 0, 0 },
+ { -0.25f, -0.25f, 1, 0.5f, 0, 0 },
};
class PictureShaderTileGM : public skiagm::GM {
-public:
- PictureShaderTileGM() {
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("pictureshadertile");
+ }
+
+ virtual SkISize onISize() SK_OVERRIDE {
+ return SkISize::Make(800, 600);
+ }
+
+ virtual void onOnceBeforeDraw() SK_OVERRIDE {
SkPictureRecorder recorder;
- SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize, NULL, 0);
+ SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
drawScene(pictureCanvas, kPictureSize);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+ SkPoint offset = SkPoint::Make(100, 100);
+ pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
+ kPictureSize, kPictureSize));
+ pictureCanvas->translate(offset.x(), offset.y());
+ drawScene(pictureCanvas, kPictureSize);
+ SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());
+
for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
tiles[i].y * kPictureSize,
tiles[i].offsetY * kPictureSize);
localMatrix.postScale(kFillSize / (2 * kPictureSize),
kFillSize / (2 * kPictureSize));
- fShaders[i].reset(SkShader::CreatePictureShader(picture,
+
+ SkPicture* picturePtr = picture.get();
+ SkRect* tilePtr = &tile;
+
+ if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
+ // When the tile == picture bounds, exercise the picture + offset path.
+ picturePtr = offsetPicture.get();
+ tilePtr = NULL;
+ }
+
+ fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode,
&localMatrix,
- &tile));
+ tilePtr));
}
}
-protected:
- virtual uint32_t onGetFlags() const SK_OVERRIDE {
- return kSkipTiled_Flag;
- }
-
- virtual SkString onShortName() SK_OVERRIDE {
- return SkString("pictureshadertile");
- }
-
- virtual SkISize onISize() SK_OVERRIDE {
- return SkISize::Make(800, 600);
- }
-
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
canvas->clear(SK_ColorBLACK);