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; |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 22 | class SkTextBlobBuilder; |
skia.committer@gmail.com | db0c875 | 2014-03-18 03:02:11 +0000 | [diff] [blame] | 23 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 24 | namespace sk_tool_utils { |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 25 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 26 | const char* colortype_name(SkColorType); |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 27 | SkColor color_to_565(SkColor color); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 28 | |
| 29 | /** |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 30 | * Sets the paint to use a platform-independent text renderer if FLAGS_portableFonts is set. |
| 31 | * FIXME: will become obsolete as GMs migrate to set portable typeface always. |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 32 | */ |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 33 | void set_portable_typeface(SkPaint* paint, const char* name = NULL, |
| 34 | SkTypeface::Style style = SkTypeface::kNormal); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 35 | void set_portable_typeface_always(SkPaint* paint, const char* name = NULL, |
| 36 | SkTypeface::Style style = SkTypeface::kNormal); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 37 | SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 38 | SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style); |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 39 | /** Call to clean up portable font references. */ |
| 40 | void release_portable_typefaces(); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 41 | void report_used_chars(); |
caryclark | 5fb6bd4 | 2014-06-23 11:25:00 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 44 | * Call canvas->writePixels() by using the pixels from bitmap, but with an info that claims |
| 45 | * the pixels are colorType + alphaType |
| 46 | */ |
| 47 | 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] | 48 | |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 49 | // private to sk_tool_utils |
| 50 | SkTypeface* create_font(const char* name, SkTypeface::Style ); |
| 51 | SkTypeface* resource_font(const char* name, SkTypeface::Style ); |
| 52 | |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 53 | /** Returns a newly created CheckerboardShader. */ |
| 54 | SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size); |
| 55 | |
| 56 | /** Draw a checkerboard pattern in the current canvas, restricted to |
halcanary | f77365f | 2015-01-27 08:38:35 -0800 | [diff] [blame] | 57 | the current clip, using SkXfermode::kSrc_Mode. */ |
halcanary | b0cce2c | 2015-01-26 12:49:00 -0800 | [diff] [blame] | 58 | void draw_checkerboard(SkCanvas* canvas, |
| 59 | SkColor color1, |
| 60 | SkColor color2, |
| 61 | int size); |
| 62 | |
| 63 | /** A default checkerboard. */ |
| 64 | inline void draw_checkerboard(SkCanvas* canvas) { |
| 65 | sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8); |
| 66 | } |
| 67 | |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame] | 68 | // Encodes to PNG, unless there is already encoded data, in which case that gets |
| 69 | // used. |
| 70 | class PngPixelSerializer : public SkPixelSerializer { |
| 71 | public: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 72 | bool onUseEncodedData(const void*, size_t) override { return true; } |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame] | 73 | SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 74 | size_t rowBytes) override { |
robertphillips | 3e5c2b1 | 2015-03-23 05:46:51 -0700 | [diff] [blame] | 75 | return SkImageEncoder::EncodeData(info, pixels, rowBytes, |
| 76 | SkImageEncoder::kPNG_Type, 100); |
| 77 | } |
| 78 | }; |
| 79 | |
joshualitt | 9e36c1a | 2015-04-14 12:17:27 -0700 | [diff] [blame] | 80 | // A helper for inserting a drawtext call into a SkTextBlobBuilder |
| 81 | void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPaint& origPaint, |
| 82 | SkScalar x, SkScalar y); |
| 83 | |
tfarina | 2010891 | 2014-06-21 10:54:17 -0700 | [diff] [blame] | 84 | } // namespace sk_tool_utils |
| 85 | |
| 86 | #endif // sk_tool_utils_DEFINED |