Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tools/sk_tool_utils.cpp

Issue 873333004: s/sk_tools::DrawCheckerboard/sk_tool_utils::draw_checkerboard/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/sk_tool_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « tools/sk_tool_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698