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 "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 SkPaint paint; | 144 SkPaint paint; |
145 paint.setStyle(SkPaint::kFill_Style); | 145 paint.setStyle(SkPaint::kFill_Style); |
146 paint.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); | 146 paint.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); |
147 | 147 |
148 canvas->save(); | 148 canvas->save(); |
149 canvas->concat(matrix); | 149 canvas->concat(matrix); |
150 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); | 150 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); |
151 canvas->drawRect(SkRect::MakeXYWH(fSceneSize * 1.1f, 0, fSceneSize, fSce
neSize), paint); | 151 canvas->drawRect(SkRect::MakeXYWH(fSceneSize * 1.1f, 0, fSceneSize, fSce
neSize), paint); |
152 | 152 |
153 SkAutoTUnref<SkShader> pictureShader( | 153 paint.setShader(SkShader::MakePictureShader(fPicture, kTileConfigs[tileM
ode].tmx, |
154 SkShader::CreatePictureShader(fPicture, kTileConfigs[tileMode].t
mx, | 154 kTileConfigs[tileMode].tmy,
&localMatrix, |
155 kTileConfigs[tileMode].tmy, &local
Matrix, nullptr)); | 155 nullptr)); |
156 paint.setShader(pictureShader.get()); | |
157 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); | 156 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); |
158 | 157 |
159 canvas->translate(fSceneSize * 1.1f, 0); | 158 canvas->translate(fSceneSize * 1.1f, 0); |
160 | 159 |
161 SkAutoTUnref<SkShader> bitmapShader(SkShader::CreateBitmapShader( | 160 paint.setShader(SkShader::MakeBitmapShader(fBitmap, |
162 fBitmap, | 161 kTileConfigs[tileMode].tmx, |
163 kTileConfigs[tileMode].tmx, | 162 kTileConfigs[tileMode].tmy, |
164 kTileConfigs[tileMode].tmy, | 163 &localMatrix)); |
165 &localMatrix)); | |
166 paint.setShader(bitmapShader.get()); | |
167 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); | 164 canvas->drawRect(SkRect::MakeWH(fSceneSize, fSceneSize), paint); |
168 | 165 |
169 canvas->restore(); | 166 canvas->restore(); |
170 } | 167 } |
171 | 168 |
172 SkScalar fTileSize; | 169 SkScalar fTileSize; |
173 SkScalar fSceneSize; | 170 SkScalar fSceneSize; |
174 | 171 |
175 SkAutoTUnref<SkPicture> fPicture; | 172 sk_sp<SkPicture> fPicture; |
176 SkBitmap fBitmap; | 173 SkBitmap fBitmap; |
177 | 174 |
178 typedef GM INHERITED; | 175 typedef GM INHERITED; |
179 }; | 176 }; |
180 | 177 |
181 DEF_GM(return new PictureShaderGM(50, 100);) | 178 DEF_GM(return new PictureShaderGM(50, 100);) |
182 | 179 |
183 DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) { | 180 DEF_SIMPLE_GM(tiled_picture_shader, canvas, 400, 400) { |
184 // https://code.google.com/p/skia/issues/detail?id=3398 | 181 // https://code.google.com/p/skia/issues/detail?id=3398 |
185 SkRect tile = SkRect::MakeWH(100, 100); | 182 SkRect tile = SkRect::MakeWH(100, 100); |
186 | 183 |
187 SkPictureRecorder recorder; | 184 SkPictureRecorder recorder; |
188 SkCanvas* c = recorder.beginRecording(tile); | 185 SkCanvas* c = recorder.beginRecording(tile); |
189 | 186 |
190 SkRect r = tile; | 187 SkRect r = tile; |
191 r.inset(4, 4); | 188 r.inset(4, 4); |
192 SkPaint p; | 189 SkPaint p; |
193 p.setColor(sk_tool_utils::color_to_565(0xFF303F9F)); // dark blue | 190 p.setColor(sk_tool_utils::color_to_565(0xFF303F9F)); // dark blue |
194 c->drawRect(r, p); | 191 c->drawRect(r, p); |
195 p.setColor(sk_tool_utils::color_to_565(0xFFC5CAE9)); // light blue | 192 p.setColor(sk_tool_utils::color_to_565(0xFFC5CAE9)); // light blue |
196 p.setStrokeWidth(10); | 193 p.setStrokeWidth(10); |
197 c->drawLine(20, 20, 80, 80, p); | 194 c->drawLine(20, 20, 80, 80, p); |
198 | 195 |
199 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 196 sk_sp<SkPicture> picture(recorder.endRecording()); |
200 SkAutoTUnref<SkShader> shader( | 197 sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepea
t_TileMode, |
201 SkShader::CreatePictureShader(picture.get(), SkShader::kRepeat_TileM
ode, | 198 SkShader::kRepeat_TileMod
e, |
202 SkShader::kRepeat_TileMode, nullptr, n
ullptr)); | 199 nullptr, nullptr)); |
203 | 200 |
204 p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A)); // green | 201 p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A)); // green |
205 canvas->drawPaint(p); | 202 canvas->drawPaint(p); |
206 | 203 |
207 canvas->clipRect(SkRect::MakeXYWH(0, 0, 400, 350)); | 204 canvas->clipRect(SkRect::MakeXYWH(0, 0, 400, 350)); |
208 p.setColor(sk_tool_utils::color_to_565(0xFFB6B6B6)); // gray | 205 p.setColor(sk_tool_utils::color_to_565(0xFFB6B6B6)); // gray |
209 canvas->drawPaint(p); | 206 canvas->drawPaint(p); |
210 p.setShader(shader.get()); | 207 p.setShader(shader.get()); |
211 | 208 |
212 canvas->drawPaint(p); | 209 canvas->drawPaint(p); |
213 } | 210 } |
OLD | NEW |