diff options
author | fmalita <fmalita@chromium.org> | 2014-12-08 11:13:27 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-08 11:13:27 -0800 |
commit | a2bd24fd15378d0a25d79b4aa2d76dddc4cf564c (patch) | |
tree | 7a503f1cffb0e8026a5845798b53fc5a70d15e4e /gm/pictureshadertile.cpp | |
parent | cf56009d9058d25933d9840bf6cf9fdf6a80f647 (diff) |
Tweak SkPictureShader's tile semantics.
Currently, the tile offset is added when drawing the picture. This might
have made a tiny bit of sense when the picture was always positioned at
origin, but with a picture cull rect offset things looks really strange.
For example, to specify a tile == the picture cull rect we have to pass
in [-cullrect.x, -cullrect.y, cullrect.width, cullrect.height]. Yikes.
(there's also a bug when not passing a tile, as we use a default tile
== cullrect but don't compensate for the above oddity)
This changes the semantics of the tile offset: it is now subtracted when
drawing the picture tile. As a consequence, one can pass in a tile equal
to the cull rect and get the expected behavior (same when not passing
a tile).
This will require a minor Blink change with the roll, as one client
works around the current behavior:
https://codereview.chromium.org/789503003
R=reed@google.com,robertphillips@google.com
BUG=440046
Review URL: https://codereview.chromium.org/733203005
Diffstat (limited to 'gm/pictureshadertile.cpp')
-rw-r--r-- | gm/pictureshadertile.cpp | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/gm/pictureshadertile.cpp b/gm/pictureshadertile.cpp index ecea55334b..ae87a5534d 100644 --- a/gm/pictureshadertile.cpp +++ b/gm/pictureshadertile.cpp @@ -21,50 +21,69 @@ static const struct { SkScalar offsetX, offsetY; } tiles[] = { { 0, 0, 1, 1, 0, 0 }, - { 0.5f, 0.5f, 1, 1, 0, 0 }, { -0.5f, -0.5f, 1, 1, 0, 0 }, + { 0.5f, 0.5f, 1, 1, 0, 0 }, { 0, 0, 1.5f, 1.5f, 0, 0 }, - { 0.5f, 0.5f, 1.5f, 1.5f, 0, 0 }, { -0.5f, -0.5f, 1.5f, 1.5f, 0, 0 }, + { 0.5f, 0.5f, 1.5f, 1.5f, 0, 0 }, { 0, 0, 0.5f, 0.5f, 0, 0 }, - { -0.25f, -0.25f, 0.5f, 0.5f, 0, 0 }, { 0.25f, 0.25f, 0.5f, 0.5f, 0, 0 }, + { -0.25f, -0.25f, 0.5f, 0.5f, 0, 0 }, { 0, 0, 1, 1, 0.5f, 0.5f }, - { 0.5f, 0.5f, 1, 1, 0.5f, 0.5f }, { -0.5f, -0.5f, 1, 1, 0.5f, 0.5f }, + { 0.5f, 0.5f, 1, 1, 0.5f, 0.5f }, { 0, 0, 1.5f, 1.5f, 0.5f, 0.5f }, - { 0.5f, 0.5f, 1.5f, 1.5f, 0.5f, 0.5f }, { -0.5f, -0.5f, 1.5f, 1.5f, 0.5f, 0.5f }, + { 0.5f, 0.5f, 1.5f, 1.5f, 0.5f, 0.5f }, { 0, 0, 1.5f, 1, 0, 0 }, - { 0.5f, 0.5f, 1.5f, 1, 0, 0 }, { -0.5f, -0.5f, 1.5f, 1, 0, 0 }, + { 0.5f, 0.5f, 1.5f, 1, 0, 0 }, { 0, 0, 0.5f, 1, 0, 0 }, - { -0.25f, -0.25f, 0.5f, 1, 0, 0 }, { 0.25f, 0.25f, 0.5f, 1, 0, 0 }, + { -0.25f, -0.25f, 0.5f, 1, 0, 0 }, { 0, 0, 1, 1.5f, 0, 0 }, - { 0.5f, 0.5f, 1, 1.5f, 0, 0 }, { -0.5f, -0.5f, 1, 1.5f, 0, 0 }, + { 0.5f, 0.5f, 1, 1.5f, 0, 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, @@ -75,27 +94,24 @@ public: 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); |