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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
9 #include "sk_tool_utils_flags.h" | 9 #include "sk_tool_utils_flags.h" |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkShader.h" |
13 #include "SkTestScalerContext.h" | 14 #include "SkTestScalerContext.h" |
14 | 15 |
15 DEFINE_bool(portableFonts, false, "Use portable fonts"); | 16 DEFINE_bool(portableFonts, false, "Use portable fonts"); |
16 DEFINE_bool(resourceFonts, false, "Use resource fonts"); | 17 DEFINE_bool(resourceFonts, false, "Use resource fonts"); |
17 | 18 |
18 namespace sk_tool_utils { | 19 namespace sk_tool_utils { |
19 | 20 |
20 const char* colortype_name(SkColorType ct) { | 21 const char* colortype_name(SkColorType ct) { |
21 switch (ct) { | 22 switch (ct) { |
22 case kUnknown_SkColorType: return "Unknown"; | 23 case kUnknown_SkColorType: return "Unknown"; |
(...skipping 29 matching lines...) Expand all Loading... |
52 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, | 53 void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y, |
53 SkColorType colorType, SkAlphaType alphaType) { | 54 SkColorType colorType, SkAlphaType alphaType) { |
54 SkBitmap tmp(bitmap); | 55 SkBitmap tmp(bitmap); |
55 tmp.lockPixels(); | 56 tmp.lockPixels(); |
56 | 57 |
57 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); | 58 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); |
58 | 59 |
59 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); | 60 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
60 } | 61 } |
61 | 62 |
| 63 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) { |
| 64 SkBitmap bm; |
| 65 bm.allocN32Pixels(2 * size, 2 * size); |
| 66 bm.eraseColor(c1); |
| 67 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); |
| 68 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); |
| 69 return SkShader::CreateBitmapShader( |
| 70 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
| 71 } |
| 72 |
| 73 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { |
| 74 SkPaint paint; |
| 75 paint.setShader(create_checkerboard_shader(c1, c2, size))->unref(); |
| 76 canvas->drawPaint(paint); |
| 77 } |
| 78 |
62 } // namespace sk_tool_utils | 79 } // namespace sk_tool_utils |
OLD | NEW |