blob: e0ad1df3ecca7a7a38b0b57fc1a2c87d45a03e13 [file] [log] [blame]
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +00001/*
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
halcanaryb0cce2c2015-01-26 12:49:00 -080011#include "SkColor.h"
robertphillips3e5c2b12015-03-23 05:46:51 -070012#include "SkImageEncoder.h"
tfarina20108912014-06-21 10:54:17 -070013#include "SkImageInfo.h"
robertphillips3e5c2b12015-03-23 05:46:51 -070014#include "SkPixelSerializer.h"
caryclark5fb6bd42014-06-23 11:25:00 -070015#include "SkTypeface.h"
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000016
Cary Clark992c7b02014-07-31 08:58:44 -040017class SkBitmap;
18class SkCanvas;
19class SkPaint;
joshualitt98d2e2f2015-10-05 07:23:30 -070020class SkPath;
halcanaryb0cce2c2015-01-26 12:49:00 -080021class SkShader;
Cary Clark992c7b02014-07-31 08:58:44 -040022class SkTestFont;
joshualitt9e36c1a2015-04-14 12:17:27 -070023class SkTextBlobBuilder;
skia.committer@gmail.comdb0c8752014-03-18 03:02:11 +000024
Cary Clark992c7b02014-07-31 08:58:44 -040025namespace sk_tool_utils {
caryclark5fb6bd42014-06-23 11:25:00 -070026
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000027 const char* colortype_name(SkColorType);
caryclark37213552015-07-24 11:08:01 -070028
29 /**
30 * Map opaque colors from 8888 to 565.
31 */
caryclark65cdba62015-06-15 06:51:08 -070032 SkColor color_to_565(SkColor color);
caryclark37213552015-07-24 11:08:01 -070033
34 /**
35 * Return a color emoji typeface if available.
36 */
caryclark3b0f98e2015-07-23 11:52:01 -070037 void emoji_typeface(SkAutoTUnref<SkTypeface>* );
caryclark37213552015-07-24 11:08:01 -070038
39 /**
40 * If the platform supports color emoji, return sample text the emoji can render.
41 */
caryclarkc3dcb672015-07-21 12:27:36 -070042 const char* emoji_sample_text();
caryclark37213552015-07-24 11:08:01 -070043
44 /**
45 * If the platform supports color emoji, return the type (i.e. "CBDT", "SBIX", "").
46 */
caryclarkc3dcb672015-07-21 12:27:36 -070047 const char* platform_os_emoji();
caryclark37213552015-07-24 11:08:01 -070048
49 /**
50 * Return the platform name with the version number ("Mac10.9", "Win8", etc.) if available.
51 */
caryclark6531c362015-07-20 13:38:56 -070052 const char* platform_os_name();
caryclark37213552015-07-24 11:08:01 -070053
54 /**
55 * Return the platform name without the version number ("Mac", "Win", etc.) if available.
56 */
57 SkString major_platform_os_name();
58
59 /**
60 * Return the platform extra config (e.g. "GDI") if available.
61 */
caryclark6531c362015-07-20 13:38:56 -070062 const char* platform_extra_config(const char* config);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000063
64 /**
caryclark37213552015-07-24 11:08:01 -070065 * Map serif, san-serif, and monospace to the platform-specific font name.
66 */
67 const char* platform_font_name(const char* name);
68
69 /**
caryclark1818acb2015-07-24 12:09:25 -070070 * Sets the paint to use a platform-independent text renderer
caryclark5fb6bd42014-06-23 11:25:00 -070071 */
halcanary96fcdcc2015-08-27 07:41:13 -070072 void set_portable_typeface(SkPaint* paint, const char* name = nullptr,
Cary Clark992c7b02014-07-31 08:58:44 -040073 SkTypeface::Style style = SkTypeface::kNormal);
caryclark37213552015-07-24 11:08:01 -070074
75 /**
caryclark37213552015-07-24 11:08:01 -070076 * Returns a platform-independent text renderer.
77 */
caryclark1818acb2015-07-24 12:09:25 -070078 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style);
caryclark37213552015-07-24 11:08:01 -070079
caryclarkf53ce802015-06-15 06:48:30 -070080 /** Call to clean up portable font references. */
81 void release_portable_typefaces();
caryclark5fb6bd42014-06-23 11:25:00 -070082
83 /**
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000084 * Call canvas->writePixels() by using the pixels from bitmap, but with an info that claims
85 * the pixels are colorType + alphaType
86 */
87 void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkAlphaType);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000088
Cary Clark992c7b02014-07-31 08:58:44 -040089 // private to sk_tool_utils
robertphillips943a4622015-09-03 13:32:33 -070090 SkTypeface* create_font(const char* name, SkTypeface::Style);
Cary Clark992c7b02014-07-31 08:58:44 -040091
halcanaryb0cce2c2015-01-26 12:49:00 -080092 /** Returns a newly created CheckerboardShader. */
93 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size);
94
95 /** Draw a checkerboard pattern in the current canvas, restricted to
halcanaryf77365f2015-01-27 08:38:35 -080096 the current clip, using SkXfermode::kSrc_Mode. */
halcanaryb0cce2c2015-01-26 12:49:00 -080097 void draw_checkerboard(SkCanvas* canvas,
98 SkColor color1,
99 SkColor color2,
robertphillips943a4622015-09-03 13:32:33 -0700100 int checkSize);
101
102 /** Make it easier to create a bitmap-based checkerboard */
103 SkBitmap create_checkerboard_bitmap(int w, int h,
104 SkColor c1, SkColor c2,
105 int checkSize);
halcanaryb0cce2c2015-01-26 12:49:00 -0800106
107 /** A default checkerboard. */
108 inline void draw_checkerboard(SkCanvas* canvas) {
109 sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
110 }
111
robertphillips943a4622015-09-03 13:32:33 -0700112 SkBitmap create_string_bitmap(int w, int h, SkColor c, int x, int y,
113 int textSize, const char* str);
114
robertphillips3e5c2b12015-03-23 05:46:51 -0700115 // Encodes to PNG, unless there is already encoded data, in which case that gets
116 // used.
117 class PngPixelSerializer : public SkPixelSerializer {
118 public:
reedc9e190d2015-09-28 09:58:41 -0700119 bool onUseEncodedData(const void*, size_t) override { return true; }
robertphillips3e5c2b12015-03-23 05:46:51 -0700120 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
mtklein36352bf2015-03-25 18:17:31 -0700121 size_t rowBytes) override {
robertphillips3e5c2b12015-03-23 05:46:51 -0700122 return SkImageEncoder::EncodeData(info, pixels, rowBytes,
123 SkImageEncoder::kPNG_Type, 100);
124 }
125 };
126
joshualitt9e36c1a2015-04-14 12:17:27 -0700127 // A helper for inserting a drawtext call into a SkTextBlobBuilder
128 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const SkPaint& origPaint,
129 SkScalar x, SkScalar y);
130
robertphillipsea4529d2015-08-17 15:04:47 -0700131 void create_hemi_normal_map(SkBitmap* bm, const SkIRect& dst);
132
133 void create_frustum_normal_map(SkBitmap* bm, const SkIRect& dst);
134
135 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst);
136
joshualitt98d2e2f2015-10-05 07:23:30 -0700137 void make_big_path(SkPath& path);
tfarina20108912014-06-21 10:54:17 -0700138} // namespace sk_tool_utils
139
140#endif // sk_tool_utils_DEFINED