2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef sk_tool_utils_DEFINED
9 #define sk_tool_utils_DEFINED
12 #include "SkImageEncoder.h"
13 #include "SkImageInfo.h"
14 #include "SkPixelSerializer.h"
15 #include "SkTypeface.h"
23 namespace sk_tool_utils {
25 const char* colortype_name(SkColorType);
28 * Sets the paint to use a platform-independent text renderer.
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();
36 * Call canvas->writePixels() by using the pixels from bitmap, but with an info that claims
37 * the pixels are colorType + alphaType
39 void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkAlphaType);
41 // private to sk_tool_utils
42 SkTypeface* create_font(const char* name, SkTypeface::Style );
43 SkTypeface* resource_font(const char* name, SkTypeface::Style );
45 /** Returns a newly created CheckerboardShader. */
46 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size);
48 /** Draw a checkerboard pattern in the current canvas, restricted to
49 the current clip, using SkXfermode::kSrc_Mode. */
50 void draw_checkerboard(SkCanvas* canvas,
55 /** A default checkerboard. */
56 inline void draw_checkerboard(SkCanvas* canvas) {
57 sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
60 // Encodes to PNG, unless there is already encoded data, in which case that gets
62 class PngPixelSerializer : public SkPixelSerializer {
64 bool onUseEncodedData(const void*, size_t) override { return true; }
65 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels,
66 size_t rowBytes) override {
67 return SkImageEncoder::EncodeData(info, pixels, rowBytes,
68 SkImageEncoder::kPNG_Type, 100);
72 } // namespace sk_tool_utils
74 #endif // sk_tool_utils_DEFINED