OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef sk_tool_utils_DEFINED | 8 #ifndef sk_tool_utils_DEFINED |
9 #define sk_tool_utils_DEFINED | 9 #define sk_tool_utils_DEFINED |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 /** Call to clean up portable font references. */ | 79 /** Call to clean up portable font references. */ |
80 void release_portable_typefaces(); | 80 void release_portable_typefaces(); |
81 | 81 |
82 /** | 82 /** |
83 * Call canvas->writePixels() by using the pixels from bitmap, but with an
info that claims | 83 * Call canvas->writePixels() by using the pixels from bitmap, but with an
info that claims |
84 * the pixels are colorType + alphaType | 84 * the pixels are colorType + alphaType |
85 */ | 85 */ |
86 void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkA
lphaType); | 86 void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkA
lphaType); |
87 | 87 |
88 // private to sk_tool_utils | 88 // private to sk_tool_utils |
89 SkTypeface* create_font(const char* name, SkTypeface::Style ); | 89 SkTypeface* create_font(const char* name, SkTypeface::Style); |
90 | 90 |
91 /** Returns a newly created CheckerboardShader. */ | 91 /** Returns a newly created CheckerboardShader. */ |
92 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size); | 92 SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size); |
93 | 93 |
94 /** Draw a checkerboard pattern in the current canvas, restricted to | 94 /** Draw a checkerboard pattern in the current canvas, restricted to |
95 the current clip, using SkXfermode::kSrc_Mode. */ | 95 the current clip, using SkXfermode::kSrc_Mode. */ |
96 void draw_checkerboard(SkCanvas* canvas, | 96 void draw_checkerboard(SkCanvas* canvas, |
97 SkColor color1, | 97 SkColor color1, |
98 SkColor color2, | 98 SkColor color2, |
99 int size); | 99 int checkSize); |
| 100 |
| 101 /** Make it easier to create a bitmap-based checkerboard */ |
| 102 SkBitmap create_checkerboard_bitmap(int w, int h, |
| 103 SkColor c1, SkColor c2, |
| 104 int checkSize); |
100 | 105 |
101 /** A default checkerboard. */ | 106 /** A default checkerboard. */ |
102 inline void draw_checkerboard(SkCanvas* canvas) { | 107 inline void draw_checkerboard(SkCanvas* canvas) { |
103 sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8); | 108 sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8); |
104 } | 109 } |
105 | 110 |
| 111 SkBitmap create_string_bitmap(int w, int h, SkColor c, int x, int y, |
| 112 int textSize, const char* str); |
| 113 |
106 // Encodes to PNG, unless there is already encoded data, in which case that
gets | 114 // Encodes to PNG, unless there is already encoded data, in which case that
gets |
107 // used. | 115 // used. |
108 class PngPixelSerializer : public SkPixelSerializer { | 116 class PngPixelSerializer : public SkPixelSerializer { |
109 public: | 117 public: |
110 bool onUseEncodedData(const void*, size_t) override { return true; } | 118 bool onUseEncodedData(const void*, size_t) override { return true; } |
111 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, | 119 SkData* onEncodePixels(const SkImageInfo& info, const void* pixels, |
112 size_t rowBytes) override { | 120 size_t rowBytes) override { |
113 return SkImageEncoder::EncodeData(info, pixels, rowBytes, | 121 return SkImageEncoder::EncodeData(info, pixels, rowBytes, |
114 SkImageEncoder::kPNG_Type, 100); | 122 SkImageEncoder::kPNG_Type, 100); |
115 } | 123 } |
116 }; | 124 }; |
117 | 125 |
118 // A helper for inserting a drawtext call into a SkTextBlobBuilder | 126 // A helper for inserting a drawtext call into a SkTextBlobBuilder |
119 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const Sk
Paint& origPaint, | 127 void add_to_text_blob(SkTextBlobBuilder* builder, const char* text, const Sk
Paint& origPaint, |
120 SkScalar x, SkScalar y); | 128 SkScalar x, SkScalar y); |
121 | 129 |
122 void create_hemi_normal_map(SkBitmap* bm, const SkIRect& dst); | 130 void create_hemi_normal_map(SkBitmap* bm, const SkIRect& dst); |
123 | 131 |
124 void create_frustum_normal_map(SkBitmap* bm, const SkIRect& dst); | 132 void create_frustum_normal_map(SkBitmap* bm, const SkIRect& dst); |
125 | 133 |
126 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst); | 134 void create_tetra_normal_map(SkBitmap* bm, const SkIRect& dst); |
127 | 135 |
128 } // namespace sk_tool_utils | 136 } // namespace sk_tool_utils |
129 | 137 |
130 #endif // sk_tool_utils_DEFINED | 138 #endif // sk_tool_utils_DEFINED |
OLD | NEW |