commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef sk_tool_utils_DEFINED |
| 9 | #define sk_tool_utils_DEFINED |
| 10 | |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 11 | #include "SkColor.h" |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame^] | 12 | #include "SkImageEncoder.h" |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 13 | #include "SkImageInfo.h" |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame^] | 14 | #include "SkPixelSerializer.h" |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 15 | #include "SkTypeface.h" |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 16 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 17 | class SkBitmap; |
| 18 | class SkCanvas; |
| 19 | class SkPaint; |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 20 | class SkShader; |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 21 | class SkTestFont; |
skia.committer@gmail.com | db0c875 | 2014-03-18 03:02:11 +0000 | [diff] [blame] | 22 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 23 | namespace sk_tool_utils { |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 24 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 25 | const char* colortype_name(SkColorType); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 26 | |
| 27 | /** |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 28 | * Sets the paint to use a platform-independent text renderer. |
| 29 | */ |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 30 | void set_portable_typeface(SkPaint* paint, const char* name = NULL, |
| 31 | SkTypeface::Style style = SkTypeface::kNormal); |
| 32 | SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style); |
| 33 | void report_used_chars(); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 36 | * Call canvas->writePixels() by using the pixels from bitmap, but with an info that claims |
| 37 | * the pixels are colorType + alphaType |
| 38 | */ |
| 39 | void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkAlphaType); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 40 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 41 | // private to sk_tool_utils |
| 42 | SkTypeface* create_font(const char* name, SkTypeface::Style ); |
| 43 | SkTypeface* resource_font(const char* name, SkTypeface::Style ); |
| 44 | |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 45 | /** Returns a newly created CheckerboardShader. */ |
| 46 | SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size); |
| 47 | |
| 48 | /** Draw a checkerboard pattern in the current canvas, restricted to |
halcanary | f77365f | 2015-01-27 08:38:35 -0800 | [diff] [blame] | 49 | the current clip, using SkXfermode::kSrc_Mode. */ |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 50 | void draw_checkerboard(SkCanvas* canvas, |
| 51 | SkColor color1, |
| 52 | SkColor color2, |
| 53 | int size); |
| 54 | |
| 55 | /** A default checkerboard. */ |
| 56 | inline void draw_checkerboard(SkCanvas* canvas) { |
| 57 | sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8); |
| 58 | } |
| 59 | |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame^] | 60 | // Encodes to PNG, unless there is already encoded data, in which case that gets |
| 61 | // used. |
| 62 | class PngPixelSerializer : public SkPixelSerializer { |
| 63 | public: |
| 64 | bool onUseEncodedData(const void*, size_t) SK_OVERRIDE { return true; } |
| 65 | SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
| 66 | size_t rowBytes) SK_OVERRIDE { |
| 67 | return SkImageEncoder::EncodeData(info, pixels, rowBytes, |
| 68 | SkImageEncoder::kPNG_Type, 100); |
| 69 | } |
| 70 | }; |
| 71 | |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 72 | } // namespace sk_tool_utils |
| 73 | |
| 74 | #endif // sk_tool_utils_DEFINED |