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 17 matching lines...) Expand all Loading... |
28 : fTileSize(tileSize) | 28 : fTileSize(tileSize) |
29 , fSceneSize(sceneSize) { | 29 , fSceneSize(sceneSize) { |
30 } | 30 } |
31 | 31 |
32 protected: | 32 protected: |
33 void onOnceBeforeDraw() override { | 33 void onOnceBeforeDraw() override { |
34 // Build the picture. | 34 // Build the picture. |
35 SkPictureRecorder recorder; | 35 SkPictureRecorder recorder; |
36 SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize,
nullptr, 0); | 36 SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize,
nullptr, 0); |
37 this->drawTile(pictureCanvas); | 37 this->drawTile(pictureCanvas); |
38 fPicture.reset(recorder.endRecording()); | 38 fPicture = recorder.finishRecordingAsPicture(); |
39 | 39 |
40 // Build a reference bitmap. | 40 // Build a reference bitmap. |
41 fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(f
TileSize)); | 41 fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(f
TileSize)); |
42 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 42 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
43 SkCanvas bitmapCanvas(fBitmap); | 43 SkCanvas bitmapCanvas(fBitmap); |
44 this->drawTile(&bitmapCanvas); | 44 this->drawTile(&bitmapCanvas); |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 SkString onShortName() override { | 48 SkString onShortName() override { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 SkRect r = tile; | 187 SkRect r = tile; |
188 r.inset(4, 4); | 188 r.inset(4, 4); |
189 SkPaint p; | 189 SkPaint p; |
190 p.setColor(sk_tool_utils::color_to_565(0xFF303F9F)); // dark blue | 190 p.setColor(sk_tool_utils::color_to_565(0xFF303F9F)); // dark blue |
191 c->drawRect(r, p); | 191 c->drawRect(r, p); |
192 p.setColor(sk_tool_utils::color_to_565(0xFFC5CAE9)); // light blue | 192 p.setColor(sk_tool_utils::color_to_565(0xFFC5CAE9)); // light blue |
193 p.setStrokeWidth(10); | 193 p.setStrokeWidth(10); |
194 c->drawLine(20, 20, 80, 80, p); | 194 c->drawLine(20, 20, 80, 80, p); |
195 | 195 |
196 sk_sp<SkPicture> picture(recorder.endRecording()); | 196 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture()); |
197 sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepea
t_TileMode, | 197 sk_sp<SkShader> shader(SkShader::MakePictureShader(picture, SkShader::kRepea
t_TileMode, |
198 SkShader::kRepeat_TileMod
e, | 198 SkShader::kRepeat_TileMod
e, |
199 nullptr, nullptr)); | 199 nullptr, nullptr)); |
200 | 200 |
201 p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A)); // green | 201 p.setColor(sk_tool_utils::color_to_565(0xFF8BC34A)); // green |
202 canvas->drawPaint(p); | 202 canvas->drawPaint(p); |
203 | 203 |
204 canvas->clipRect(SkRect::MakeXYWH(0, 0, 400, 350)); | 204 canvas->clipRect(SkRect::MakeXYWH(0, 0, 400, 350)); |
205 p.setColor(sk_tool_utils::color_to_565(0xFFB6B6B6)); // gray | 205 p.setColor(sk_tool_utils::color_to_565(0xFFB6B6B6)); // gray |
206 canvas->drawPaint(p); | 206 canvas->drawPaint(p); |
207 p.setShader(shader.get()); | 207 p.setShader(shader.get()); |
208 | 208 |
209 canvas->drawPaint(p); | 209 canvas->drawPaint(p); |
210 } | 210 } |
OLD | NEW |