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 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 SkBitmap tmp(bitmap); | 193 SkBitmap tmp(bitmap); |
194 tmp.lockPixels(); | 194 tmp.lockPixels(); |
195 | 195 |
196 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); | 196 const SkImageInfo info = SkImageInfo::Make(tmp.width(), tmp.height(), colorT
ype, alphaType); |
197 | 197 |
198 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); | 198 canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y); |
199 } | 199 } |
200 | 200 |
201 sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size) { | 201 sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size) { |
202 SkBitmap bm; | 202 SkBitmap bm; |
203 bm.allocPixels(SkImageInfo::MakeS32(2 * size, 2 * size, kPremul_SkAlphaType)
); | 203 bm.allocN32Pixels(2 * size, 2 * size); |
204 bm.eraseColor(c1); | 204 bm.eraseColor(c1); |
205 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); | 205 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2); |
206 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); | 206 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2); |
207 return SkShader::MakeBitmapShader( | 207 return SkShader::MakeBitmapShader( |
208 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 208 bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
209 } | 209 } |
210 | 210 |
211 SkBitmap create_checkerboard_bitmap(int w, int h, SkColor c1, SkColor c2, int ch
eckSize) { | 211 SkBitmap create_checkerboard_bitmap(int w, int h, SkColor c1, SkColor c2, int ch
eckSize) { |
212 SkBitmap bitmap; | 212 SkBitmap bitmap; |
213 bitmap.allocPixels(SkImageInfo::MakeS32(w, h, kPremul_SkAlphaType)); | 213 bitmap.allocN32Pixels(w, h); |
214 SkCanvas canvas(bitmap); | 214 SkCanvas canvas(bitmap); |
215 | 215 |
216 sk_tool_utils::draw_checkerboard(&canvas, c1, c2, checkSize); | 216 sk_tool_utils::draw_checkerboard(&canvas, c1, c2, checkSize); |
217 return bitmap; | 217 return bitmap; |
218 } | 218 } |
219 | 219 |
220 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { | 220 void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) { |
221 SkPaint paint; | 221 SkPaint paint; |
222 paint.setShader(create_checkerboard_shader(c1, c2, size)); | 222 paint.setShader(create_checkerboard_shader(c1, c2, size)); |
223 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 223 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 const SkVector& ll = rr.radii(SkRRect::kLowerLeft_Corner); | 539 const SkVector& ll = rr.radii(SkRRect::kLowerLeft_Corner); |
540 | 540 |
541 SkScalar maxL = SkTMax(ul.fX, ll.fX); | 541 SkScalar maxL = SkTMax(ul.fX, ll.fX); |
542 SkScalar maxR = SkTMax(ur.fX, lr.fX); | 542 SkScalar maxR = SkTMax(ur.fX, lr.fX); |
543 | 543 |
544 return SkRect::MakeLTRB(r.fLeft + maxL, r.fTop, r.fRight - maxR, r.fBottom); | 544 return SkRect::MakeLTRB(r.fLeft + maxL, r.fTop, r.fRight - maxR, r.fBottom); |
545 } | 545 } |
546 | 546 |
547 | 547 |
548 } // namespace sk_tool_utils | 548 } // namespace sk_tool_utils |
OLD | NEW |