blob: 4bf9ad6ac5fa3ec07275b082e86a5dfdebdee869 [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;
halcanaryb0cce2c2015-01-26 12:49:00 -080020class SkShader;
Cary Clark992c7b02014-07-31 08:58:44 -040021class SkTestFont;
joshualitt9e36c1a2015-04-14 12:17:27 -070022class SkTextBlobBuilder;
skia.committer@gmail.comdb0c8752014-03-18 03:02:11 +000023
Cary Clark992c7b02014-07-31 08:58:44 -040024namespace sk_tool_utils {
caryclark5fb6bd42014-06-23 11:25:00 -070025
commit-bot@chromium.orga713f9c2014-03-17 21:31:26 +000026 const char* colortype_name(SkColorType);
caryclark65cdba62015-06-15 06:51:08 -070027 SkColor color_to_565(SkColor color);
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000028
29 /**
caryclark83ca6282015-06-10 09:31:09 -070030 * 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.
caryclark5fb6bd42014-06-23 11:25:00 -070032 */
Cary Clark992c7b02014-07-31 08:58:44 -040033 void set_portable_typeface(SkPaint* paint, const char* name = NULL,
34 SkTypeface::Style style = SkTypeface::kNormal);
caryclark83ca6282015-06-10 09:31:09 -070035 void set_portable_typeface_always(SkPaint* paint, const char* name = NULL,
36 SkTypeface::Style style = SkTypeface::kNormal);
Cary Clark992c7b02014-07-31 08:58:44 -040037 SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style);
caryclark83ca6282015-06-10 09:31:09 -070038 SkTypeface* create_portable_typeface_always(const char* name, SkTypeface::Style style);
caryclarkf53ce802015-06-15 06:48:30 -070039 /** Call to clean up portable font references. */
40 void release_portable_typefaces();
Cary Clark992c7b02014-07-31 08:58:44 -040041 void report_used_chars();
caryclark5fb6bd42014-06-23 11:25:00 -070042
43 /**
commit-bot@chromium.org4cd9e212014-03-07 03:25:16 +000044 * 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.org4cd9e212014-03-07 03:25:16 +000048
Cary Clark992c7b02014-07-31 08:58:44 -040049 // private to sk_tool_utils
50 SkTypeface* create_font(const char* name, SkTypeface::Style );
51 SkTypeface* resource_font(const char* name, SkTypeface::Style );
52
halcanaryb0cce2c2015-01-26 12:49:00 -080053 /** 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
halcanaryf77365f2015-01-27 08:38:35 -080057 the current clip, using SkXfermode::kSrc_Mode. */
halcanaryb0cce2c2015-01-26 12:49:00 -080058 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
robertphillips3e5c2b12015-03-23 05:46:51 -070068 // Encodes to PNG, unless there is already encoded data, in which case that gets
69 // used.
70 class PngPixelSerializer : public SkPixelSerializer {
71 public:
mtklein36352bf2015-03-25 18:17:31 -070072 bool onUseEncodedData(const void*, size_t) override { return true; }
robertphillips3e5c2b12015-03-23 05:46:51 -070073 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
mtklein36352bf2015-03-25 18:17:31 -070074 size_t rowBytes) override {
robertphillips3e5c2b12015-03-23 05:46:51 -070075 return SkImageEncoder::EncodeData(info, pixels, rowBytes,
76 SkImageEncoder::kPNG_Type, 100);
77 }
78 };
79
joshualitt9e36c1a2015-04-14 12:17:27 -070080 // 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
tfarina20108912014-06-21 10:54:17 -070084} // namespace sk_tool_utils
85
86#endif // sk_tool_utils_DEFINED