OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 SkISize onISize() override { | 90 SkISize onISize() override { |
91 return SkISize::Make(800, 600); | 91 return SkISize::Make(800, 600); |
92 } | 92 } |
93 | 93 |
94 void onOnceBeforeDraw() override { | 94 void onOnceBeforeDraw() override { |
95 SkPictureRecorder recorder; | 95 SkPictureRecorder recorder; |
96 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture
Size); | 96 SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPicture
Size); |
97 draw_scene(pictureCanvas, kPictureSize); | 97 draw_scene(pictureCanvas, kPictureSize); |
98 sk_sp<SkPicture> picture(recorder.endRecording()); | 98 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
99 | 99 |
100 SkPoint offset = SkPoint::Make(100, 100); | 100 SkPoint offset = SkPoint::Make(100, 100); |
101 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off
set.y(), | 101 pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), off
set.y(), |
102 kPictureSize, k
PictureSize)); | 102 kPictureSize, k
PictureSize)); |
103 pictureCanvas->translate(offset.x(), offset.y()); | 103 pictureCanvas->translate(offset.x(), offset.y()); |
104 draw_scene(pictureCanvas, kPictureSize); | 104 draw_scene(pictureCanvas, kPictureSize); |
105 sk_sp<SkPicture> offsetPicture(recorder.endRecording()); | 105 SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording()); |
106 | 106 |
107 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) { | 107 for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) { |
108 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize, | 108 SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize, |
109 tiles[i].y * kPictureSize, | 109 tiles[i].y * kPictureSize, |
110 tiles[i].w * kPictureSize, | 110 tiles[i].w * kPictureSize, |
111 tiles[i].h * kPictureSize); | 111 tiles[i].h * kPictureSize); |
112 SkMatrix localMatrix; | 112 SkMatrix localMatrix; |
113 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize, | 113 localMatrix.setTranslate(tiles[i].offsetX * kPictureSize, |
114 tiles[i].offsetY * kPictureSize); | 114 tiles[i].offsetY * kPictureSize); |
115 localMatrix.postScale(kFillSize / (2 * kPictureSize), | 115 localMatrix.postScale(kFillSize / (2 * kPictureSize), |
116 kFillSize / (2 * kPictureSize)); | 116 kFillSize / (2 * kPictureSize)); |
117 | 117 |
118 sk_sp<SkPicture>& pictureRef = picture; | 118 SkPicture* picturePtr = picture.get(); |
119 SkRect* tilePtr = &tile; | 119 SkRect* tilePtr = &tile; |
120 | 120 |
121 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) { | 121 if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) { |
122 // When the tile == picture bounds, exercise the picture + offse
t path. | 122 // When the tile == picture bounds, exercise the picture + offse
t path. |
123 pictureRef = offsetPicture; | 123 picturePtr = offsetPicture.get(); |
124 tilePtr = nullptr; | 124 tilePtr = nullptr; |
125 } | 125 } |
126 | 126 |
127 fShaders[i] = SkShader::MakePictureShader(pictureRef, SkShader::kRep
eat_TileMode, | 127 fShaders[i].reset(SkShader::CreatePictureShader(picturePtr, |
128 SkShader::kRepeat_TileMode
, &localMatrix, | 128 SkShader::kRepeat_Ti
leMode, |
129 tilePtr); | 129 SkShader::kRepeat_Ti
leMode, |
| 130 &localMatrix, |
| 131 tilePtr)); |
130 } | 132 } |
131 } | 133 } |
132 | 134 |
133 void onDraw(SkCanvas* canvas) override { | 135 void onDraw(SkCanvas* canvas) override { |
134 canvas->clear(SK_ColorBLACK); | 136 canvas->clear(SK_ColorBLACK); |
135 | 137 |
136 SkPaint paint; | 138 SkPaint paint; |
137 paint.setStyle(SkPaint::kFill_Style); | 139 paint.setStyle(SkPaint::kFill_Style); |
138 | 140 |
139 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { | 141 for (unsigned i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
140 paint.setShader(fShaders[i]); | 142 paint.setShader(fShaders[i]); |
141 | 143 |
142 canvas->save(); | 144 canvas->save(); |
143 canvas->translate((i % kRowSize) * kFillSize * 1.1f, | 145 canvas->translate((i % kRowSize) * kFillSize * 1.1f, |
144 (i / kRowSize) * kFillSize * 1.1f); | 146 (i / kRowSize) * kFillSize * 1.1f); |
145 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint); | 147 canvas->drawRect(SkRect::MakeWH(kFillSize, kFillSize), paint); |
146 canvas->restore(); | 148 canvas->restore(); |
147 } | 149 } |
148 } | 150 } |
149 | 151 |
150 private: | 152 private: |
151 sk_sp<SkShader> fShaders[SK_ARRAY_COUNT(tiles)]; | 153 SkAutoTUnref<SkShader> fShaders[SK_ARRAY_COUNT(tiles)]; |
152 | 154 |
153 typedef GM INHERITED; | 155 typedef GM INHERITED; |
154 }; | 156 }; |
155 | 157 |
156 DEF_GM(return new PictureShaderTileGM;) | 158 DEF_GM(return new PictureShaderTileGM;) |
OLD | NEW |