Flutter Engine
The Flutter Engine
Classes | Typedefs | Enumerations | Functions
ToolUtils Namespace Reference

Classes

struct  EmojiTestSample
 
class  HilbertGenerator
 
class  PixelIter
 
class  TopoTestNode
 
class  VariationSliders
 

Typedefs

using PathSniffCallback = void(const SkMatrix &, const SkPath &, const SkPaint &)
 

Enumerations

enum class  EmojiFontFormat {
  Cbdt , Sbix , ColrV0 , Test ,
  Svg
}
 

Functions

bool DecodeDataToBitmap (sk_sp< SkData > data, SkBitmap *dst)
 
bool GetResourceAsBitmap (const char *resource, SkBitmap *dst)
 
sk_sp< SkImageGetResourceAsImage (const char *resource)
 
bool BitmapToBase64DataURI (const SkBitmap &bitmap, SkString *dst)
 
bool EncodeImageToPngFile (const char *path, const SkBitmap &src)
 
bool EncodeImageToPngFile (const char *path, const SkPixmap &src)
 
static DEFINE_bool (nativeFonts, true, "If true, use native font manager and rendering. " "If false, fonts will draw as portably as possible.")
 
sk_sp< SkTypefacePlanetTypeface ()
 
EmojiTestSample EmojiSample ()
 
EmojiTestSample EmojiSample (EmojiFontFormat format)
 
SkString NameForFontFormat (EmojiFontFormat format)
 
sk_sp< SkTypefaceSampleUserTypeface ()
 
sk_sp< SkTypefaceCreatePortableTypeface (const char *name, SkFontStyle style)
 
sk_sp< SkTypefaceDefaultPortableTypeface ()
 
SkFont DefaultPortableFont ()
 
SkBitmap CreateStringBitmap (int w, int h, SkColor c, int x, int y, int textSize, const char *str)
 
sk_sp< SkImageCreateStringImage (int w, int h, SkColor c, int x, int y, int textSize, const char *str)
 
sk_sp< SkFontMgrTestFontMgr ()
 
bool FontMgrIsGDI ()
 
void UsePortableFontMgr ()
 
sk_sp< SkTypefaceDefaultTypeface ()
 
sk_sp< SkTypefaceCreateTestTypeface (const char *name, SkFontStyle style)
 
sk_sp< SkTypefaceCreateTypefaceFromResource (const char *resource, int ttcIndex)
 
SkFont DefaultFont ()
 
sk_sp< SkFontMgrMakePortableFontMgr ()
 
sk_sp< SkImageMakeTextureImage (SkCanvas *canvas, sk_sp< SkImage > orig)
 
void ExtractPaths (const char filepath[], std::function< PathSniffCallback > callback)
 
void ExtractPathsFromSVG (const char filepath[], std::function< PathSniffCallback >)
 
const char * alphatype_name (SkAlphaType at)
 
const char * colortype_name (SkColorType ct)
 
const char * colortype_depth (SkColorType ct)
 
const char * tilemode_name (SkTileMode mode)
 
SkColor color_to_565 (SkColor color)
 
sk_sp< SkShadercreate_checkerboard_shader (SkColor c1, SkColor c2, int size)
 
SkBitmap create_checkerboard_bitmap (int w, int h, SkColor c1, SkColor c2, int checkSize)
 
sk_sp< SkImagecreate_checkerboard_image (int w, int h, SkColor c1, SkColor c2, int checkSize)
 
void draw_checkerboard (SkCanvas *canvas, SkColor c1, SkColor c2, int size)
 
int make_pixmaps (SkColorType ct, SkAlphaType at, bool withMips, const SkColor4f colors[6], SkPixmap pixmaps[6], std::unique_ptr< char[]> *mem)
 
void add_to_text_blob_w_len (SkTextBlobBuilder *builder, const char *text, size_t len, SkTextEncoding encoding, const SkFont &font, SkScalar x, SkScalar y)
 
void add_to_text_blob (SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
 
void get_text_path (const SkFont &font, const void *text, size_t length, SkTextEncoding encoding, SkPath *dst, const SkPoint pos[])
 
SkPath make_star (const SkRect &bounds, int numPts, int step)
 
static void norm_to_rgb (SkBitmap *bm, int x, int y, const SkVector3 &norm)
 
void create_hemi_normal_map (SkBitmap *bm, const SkIRect &dst)
 
void create_frustum_normal_map (SkBitmap *bm, const SkIRect &dst)
 
void create_tetra_normal_map (SkBitmap *bm, const SkIRect &dst)
 
bool copy_to (SkBitmap *dst, SkColorType dstColorType, const SkBitmap &src)
 
void copy_to_g8 (SkBitmap *dst, const SkBitmap &src)
 
bool equal_pixels (const SkPixmap &a, const SkPixmap &b)
 
bool equal_pixels (const SkBitmap &bm0, const SkBitmap &bm1)
 
bool equal_pixels (const SkImage *a, const SkImage *b)
 
sk_sp< SkSurfacemakeSurface (SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
 
void ExtractPathsFromSKP (const char filepath[], std::function< PathSniffCallback > callback)
 
void get_text_path (const SkFont &, const void *text, size_t length, SkTextEncoding, SkPath *, const SkPoint *positions=nullptr)
 
void draw_checkerboard (SkCanvas *canvas)
 

Typedef Documentation

◆ PathSniffCallback

using ToolUtils::PathSniffCallback = typedef void(const SkMatrix&, const SkPath&, const SkPaint&)

Definition at line 311 of file ToolUtils.h.

Enumeration Type Documentation

◆ EmojiFontFormat

enum class ToolUtils::EmojiFontFormat
strong
Enumerator
Cbdt 
Sbix 
ColrV0 
Test 
Svg 

Definition at line 39 of file FontToolUtils.h.

Function Documentation

◆ add_to_text_blob()

void ToolUtils::add_to_text_blob ( SkTextBlobBuilder builder,
const char *  text,
const SkFont font,
SkScalar  x,
SkScalar  y 
)

Definition at line 228 of file ToolUtils.cpp.

232 {
234}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
std::u16string text
double y
double x
void add_to_text_blob_w_len(SkTextBlobBuilder *builder, const char *text, size_t len, SkTextEncoding encoding, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:213
font
Font Metadata and Metrics.

◆ add_to_text_blob_w_len()

void ToolUtils::add_to_text_blob_w_len ( SkTextBlobBuilder builder,
const char *  text,
size_t  len,
SkTextEncoding  encoding,
const SkFont font,
SkScalar  x,
SkScalar  y 
)

Definition at line 213 of file ToolUtils.cpp.

219 {
220 int count = font.countText(text, len, encoding);
221 if (count < 1) {
222 return;
223 }
224 auto run = builder->allocRun(font, count, x, y);
225 font.textToGlyphs(text, len, encoding, run.glyphs, count);
226}
int count
Definition: FontMgrTest.cpp:50
Definition: run.py:1

◆ alphatype_name()

const char * ToolUtils::alphatype_name ( SkAlphaType  at)

Definition at line 55 of file ToolUtils.cpp.

55 {
56 switch (at) {
57 case kUnknown_SkAlphaType: return "Unknown";
58 case kOpaque_SkAlphaType: return "Opaque";
59 case kPremul_SkAlphaType: return "Premul";
60 case kUnpremul_SkAlphaType: return "Unpremul";
61 }
63}
kUnpremul_SkAlphaType
@ kUnknown_SkAlphaType
uninitialized
Definition: SkAlphaType.h:27
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkUNREACHABLE
Definition: SkAssert.h:135

◆ BitmapToBase64DataURI()

bool ToolUtils::BitmapToBase64DataURI ( const SkBitmap bitmap,
SkString dst 
)

Definition at line 25 of file EncodeUtils.cpp.

25 {
26 SkPixmap pm;
27 if (!bitmap.peekPixels(&pm)) {
28 dst->set("peekPixels failed");
29 return false;
30 }
31
32 // We're going to embed this PNG in a data URI, so make it as small as possible
35 options.fZLibLevel = 9;
36
38 if (!SkPngEncoder::Encode(&wStream, pm, options)) {
39 dst->set("SkPngEncoder::Encode failed");
40 return false;
41 }
42
43 sk_sp<SkData> pngData = wStream.detachAsData();
44 size_t len = SkBase64::EncodedSize(pngData->size());
45
46 // The PNG can be almost arbitrarily large. We don't want to fill our logs with enormous URLs.
47 // Infra says these can be pretty big, as long as we're only outputting them on failure.
48 static const size_t kMaxBase64Length = 1024 * 1024;
49 if (len > kMaxBase64Length) {
50 dst->printf("Encoded image too large (%u bytes)", static_cast<uint32_t>(len));
51 return false;
52 }
53
54 dst->resize(len);
55 SkBase64::Encode(pngData->data(), pngData->size(), dst->data());
56 dst->prepend("data:image/png;base64,");
57 return true;
58}
const char * options
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
sk_sp< SkData > detachAsData()
Definition: SkStream.cpp:707
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
Definition: bitmap.py:1
dst
Definition: cp.py:12
static size_t EncodedSize(size_t srcDataLength)
Definition: SkBase64.h:40
static size_t Encode(const void *src, size_t length, void *dst, const char *encode=nullptr)
Definition: SkBase64.cpp:113

◆ color_to_565()

SkColor ToolUtils::color_to_565 ( SkColor  color)

Map opaque colors from 8888 to 565.

Definition at line 139 of file ToolUtils.cpp.

139 {
140 // Not a good idea to use this function for greyscale colors...
141 // it will add an obvious purple or green tint.
144
146 U16CPU color16 = SkPixel32ToPixel16(pmColor);
147 return SkPixel16ToColor(color16);
148}
#define SkASSERT(cond)
Definition: SkAssert.h:116
unsigned U16CPU
Definition: SkCPUTypes.h:23
static U16CPU SkPixel32ToPixel16(SkPMColor c)
Definition: SkColorData.h:317
static SkColor SkPixel16ToColor(U16CPU src)
Definition: SkColorData.h:332
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
uint32_t SkPMColor
Definition: SkColor.h:205
#define SkColorGetB(color)
Definition: SkColor.h:73
DlColor color

◆ colortype_depth()

const char * ToolUtils::colortype_depth ( SkColorType  ct)

Definition at line 97 of file ToolUtils.cpp.

97 {
98 switch (ct) {
99 case kUnknown_SkColorType: return "Unknown";
100 case kAlpha_8_SkColorType: return "A8";
101 case kA16_unorm_SkColorType: return "A16";
102 case kA16_float_SkColorType: return "AF16";
103 case kRGB_565_SkColorType: return "565";
104 case kARGB_4444_SkColorType: return "4444";
105 case kRGBA_8888_SkColorType: return "8888";
106 case kSRGBA_8888_SkColorType: return "8888";
107 case kRGB_888x_SkColorType: return "888";
108 case kBGRA_8888_SkColorType: return "8888";
109 case kRGBA_1010102_SkColorType: return "1010102";
110 case kBGRA_1010102_SkColorType: return "1010102";
111 case kRGB_101010x_SkColorType: return "101010";
112 case kBGR_101010x_SkColorType: return "101010";
113 case kBGR_101010x_XR_SkColorType: return "101010";
114 case kBGRA_10101010_XR_SkColorType: return "10101010";
115 case kRGBA_10x6_SkColorType: return "10101010";
116 case kGray_8_SkColorType: return "G8";
117 case kRGBA_F16Norm_SkColorType: return "F16Norm";
118 case kRGBA_F16_SkColorType: return "F16";
119 case kRGBA_F32_SkColorType: return "F32";
120 case kR8G8_unorm_SkColorType: return "88";
121 case kR16G16_unorm_SkColorType: return "1616";
122 case kR16G16_float_SkColorType: return "F16F16";
123 case kR16G16B16A16_unorm_SkColorType: return "16161616";
124 case kR8_unorm_SkColorType: return "R8";
125 }
127}
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition: SkColorType.h:50
@ kRGBA_10x6_SkColorType
pixel with 10 used bits (most significant) followed by 6 unused
Definition: SkColorType.h:33
@ kR8_unorm_SkColorType
Definition: SkColorType.h:54
@ kBGR_101010x_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word
Definition: SkColorType.h:30
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kR8G8_unorm_SkColorType
pixel with a uint8_t for red and green
Definition: SkColorType.h:43
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition: SkColorType.h:48
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
@ kRGB_101010x_SkColorType
pixel with 10 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:29
@ kSRGBA_8888_SkColorType
Definition: SkColorType.h:53
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
Definition: SkColorType.h:32
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
Definition: SkColorType.h:25
@ kBGRA_1010102_SkColorType
10 bits for blue, green, red; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:28
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition: SkColorType.h:45
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition: SkColorType.h:40
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
Definition: SkColorType.h:31
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition: SkColorType.h:49
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition: SkColorType.h:36
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition: SkColorType.h:46

◆ colortype_name()

const char * ToolUtils::colortype_name ( SkColorType  ct)

Definition at line 65 of file ToolUtils.cpp.

65 {
66 switch (ct) {
67 case kUnknown_SkColorType: return "Unknown";
68 case kAlpha_8_SkColorType: return "Alpha_8";
69 case kA16_unorm_SkColorType: return "Alpha_16";
70 case kA16_float_SkColorType: return "A16_float";
71 case kRGB_565_SkColorType: return "RGB_565";
72 case kARGB_4444_SkColorType: return "ARGB_4444";
73 case kRGBA_8888_SkColorType: return "RGBA_8888";
74 case kSRGBA_8888_SkColorType: return "SRGBA_8888";
75 case kRGB_888x_SkColorType: return "RGB_888x";
76 case kBGRA_8888_SkColorType: return "BGRA_8888";
77 case kRGBA_1010102_SkColorType: return "RGBA_1010102";
78 case kBGRA_1010102_SkColorType: return "BGRA_1010102";
79 case kRGB_101010x_SkColorType: return "RGB_101010x";
80 case kBGR_101010x_SkColorType: return "BGR_101010x";
81 case kBGR_101010x_XR_SkColorType: return "BGR_101010x_XR";
82 case kRGBA_10x6_SkColorType: return "RGBA_10x6";
83 case kGray_8_SkColorType: return "Gray_8";
84 case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm";
85 case kRGBA_F16_SkColorType: return "RGBA_F16";
86 case kRGBA_F32_SkColorType: return "RGBA_F32";
87 case kR8G8_unorm_SkColorType: return "R8G8_unorm";
88 case kR16G16_unorm_SkColorType: return "R16G16_unorm";
89 case kR16G16_float_SkColorType: return "R16G16_float";
90 case kR16G16B16A16_unorm_SkColorType: return "R16G16B16A16_unorm";
91 case kR8_unorm_SkColorType: return "R8_unorm";
92 case kBGRA_10101010_XR_SkColorType: return "BGRA_10101010_XR";
93 }
95}

◆ copy_to()

bool ToolUtils::copy_to ( SkBitmap dst,
SkColorType  dstColorType,
const SkBitmap src 
)

Definition at line 394 of file ToolUtils.cpp.

394 {
395 SkPixmap srcPM;
396 if (!src.peekPixels(&srcPM)) {
397 return false;
398 }
399
400 SkBitmap tmpDst;
401 SkImageInfo dstInfo = srcPM.info().makeColorType(dstColorType);
402 if (!tmpDst.setInfo(dstInfo)) {
403 return false;
404 }
405
406 if (!tmpDst.tryAllocPixels()) {
407 return false;
408 }
409
410 SkPixmap dstPM;
411 if (!tmpDst.peekPixels(&dstPM)) {
412 return false;
413 }
414
415 if (!srcPM.readPixels(dstPM)) {
416 return false;
417 }
418
419 dst->swap(tmpDst);
420 return true;
421}
bool peekPixels(SkPixmap *pixmap) const
Definition: SkBitmap.cpp:635
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition: SkBitmap.cpp:114
bool tryAllocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:271
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
Definition: SkPixmap.h:592
const SkImageInfo & info() const
Definition: SkPixmap.h:135
SkImageInfo makeColorType(SkColorType newColorType) const
Definition: SkImageInfo.h:475

◆ copy_to_g8()

void ToolUtils::copy_to_g8 ( SkBitmap dst,
const SkBitmap src 
)

Definition at line 423 of file ToolUtils.cpp.

423 {
424 SkASSERT(kBGRA_8888_SkColorType == src.colorType() ||
425 kRGBA_8888_SkColorType == src.colorType());
426
427 SkImageInfo grayInfo = src.info().makeColorType(kGray_8_SkColorType);
428 dst->allocPixels(grayInfo);
429 uint8_t* dst8 = (uint8_t*)dst->getPixels();
430 const uint32_t* src32 = (const uint32_t*)src.getPixels();
431
432 const int w = src.width();
433 const int h = src.height();
434 const bool isBGRA = (kBGRA_8888_SkColorType == src.colorType());
435 for (int y = 0; y < h; ++y) {
436 if (isBGRA) {
437 // BGRA
438 for (int x = 0; x < w; ++x) {
439 uint32_t s = src32[x];
440 dst8[x] = SkComputeLuminance((s >> 16) & 0xFF, (s >> 8) & 0xFF, s & 0xFF);
441 }
442 } else {
443 // RGBA
444 for (int x = 0; x < w; ++x) {
445 uint32_t s = src32[x];
446 dst8[x] = SkComputeLuminance(s & 0xFF, (s >> 8) & 0xFF, (s >> 16) & 0xFF);
447 }
448 }
449 src32 = (const uint32_t*)((const char*)src32 + src.rowBytes());
450 dst8 += dst->rowBytes();
451 }
452}
static U8CPU SkComputeLuminance(U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorData.h:118
struct MyStruct s
SkScalar w
SkScalar h

◆ create_checkerboard_bitmap()

SkBitmap ToolUtils::create_checkerboard_bitmap ( int  w,
int  h,
SkColor  c1,
SkColor  c2,
int  checkSize 
)

Make it easier to create a bitmap-based checkerboard

Definition at line 159 of file ToolUtils.cpp.

159 {
162 SkCanvas canvas(bitmap);
163
164 ToolUtils::draw_checkerboard(&canvas, c1, c2, checkSize);
165 return bitmap;
166}
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)

◆ create_checkerboard_image()

sk_sp< SkImage > ToolUtils::create_checkerboard_image ( int  w,
int  h,
SkColor  c1,
SkColor  c2,
int  checkSize 
)

Definition at line 168 of file ToolUtils.cpp.

168 {
170 ToolUtils::draw_checkerboard(surf->getCanvas(), c1, c2, checkSize);
171 return surf->makeImageSnapshot();
172}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ create_checkerboard_shader()

sk_sp< SkShader > ToolUtils::create_checkerboard_shader ( SkColor  c1,
SkColor  c2,
int  size 
)

Returns a newly created CheckerboardShader.

Definition at line 150 of file ToolUtils.cpp.

150 {
151 SkBitmap bm;
153 bm.eraseColor(c1);
154 bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
155 bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
157}
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
void eraseArea(const SkIRect &area, SkColor c) const
Definition: SkBitmap.h:854
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b)
Definition: SkRect.h:91

◆ create_frustum_normal_map()

void ToolUtils::create_frustum_normal_map ( SkBitmap bm,
const SkIRect dst 
)

Definition at line 318 of file ToolUtils.cpp.

318 {
319 const SkPoint center =
320 SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), dst.fTop + (dst.height() / 2.0f));
321
322 SkIRect inner = dst;
323 inner.inset(dst.width() / 4, dst.height() / 4);
324
325 SkPoint3 norm;
330
331 for (int y = dst.fTop; y < dst.fBottom; ++y) {
332 for (int x = dst.fLeft; x < dst.fRight; ++x) {
333 if (inner.contains(x, y)) {
334 norm.set(0.0f, 0.0f, 1.0f);
335 } else {
336 SkScalar locX = x + 0.5f - center.fX;
337 SkScalar locY = y + 0.5f - center.fY;
338
339 if (locX >= 0.0f) {
340 if (locY > 0.0f) {
341 norm = locX >= locY ? right : down; // LR corner
342 } else {
343 norm = locX > -locY ? right : up; // UR corner
344 }
345 } else {
346 if (locY > 0.0f) {
347 norm = -locX > locY ? left : down; // LL corner
348 } else {
349 norm = locX > locY ? up : left; // UL corner
350 }
351 }
352 }
353
354 norm_to_rgb(bm, x, y, norm);
355 }
356 }
357}
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SK_ScalarRoot2Over2
Definition: SkScalar.h:23
static SkScalar center(float pos0, float pos1)
float SkScalar
Definition: extension.cpp:12
static void norm_to_rgb(SkBitmap *bm, int x, int y, const SkVector3 &norm)
Definition: ToolUtils.cpp:286
Definition: SkRect.h:32
void inset(int32_t dx, int32_t dy)
Definition: SkRect.h:411
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
void set(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:28
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ create_hemi_normal_map()

void ToolUtils::create_hemi_normal_map ( SkBitmap bm,
const SkIRect dst 
)

Definition at line 294 of file ToolUtils.cpp.

294 {
295 const SkPoint center =
296 SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), dst.fTop + (dst.height() / 2.0f));
297 const SkPoint halfSize = SkPoint::Make(dst.width() / 2.0f, dst.height() / 2.0f);
298
299 SkVector3 norm;
300
301 for (int y = dst.fTop; y < dst.fBottom; ++y) {
302 for (int x = dst.fLeft; x < dst.fRight; ++x) {
303 norm.fX = (x + 0.5f - center.fX) / halfSize.fX;
304 norm.fY = (y + 0.5f - center.fY) / halfSize.fY;
305
306 SkScalar tmp = norm.fX * norm.fX + norm.fY * norm.fY;
307 if (tmp >= 1.0f) {
308 norm.set(0.0f, 0.0f, 1.0f);
309 } else {
310 norm.fZ = sqrtf(1.0f - tmp);
311 }
312
313 norm_to_rgb(bm, x, y, norm);
314 }
315 }
316}
SkScalar fX
Definition: SkPoint3.h:16
SkScalar fZ
Definition: SkPoint3.h:16
SkScalar fY
Definition: SkPoint3.h:16
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ create_tetra_normal_map()

void ToolUtils::create_tetra_normal_map ( SkBitmap bm,
const SkIRect dst 
)

Definition at line 359 of file ToolUtils.cpp.

359 {
360 const SkPoint center =
361 SkPoint::Make(dst.fLeft + (dst.width() / 2.0f), dst.fTop + (dst.height() / 2.0f));
362
363 static const SkScalar k1OverRoot3 = 0.5773502692f;
364
365 SkPoint3 norm;
366 const SkPoint3 leftUp = SkPoint3::Make(-k1OverRoot3, -k1OverRoot3, k1OverRoot3);
367 const SkPoint3 rightUp = SkPoint3::Make(k1OverRoot3, -k1OverRoot3, k1OverRoot3);
369
370 for (int y = dst.fTop; y < dst.fBottom; ++y) {
371 for (int x = dst.fLeft; x < dst.fRight; ++x) {
372 SkScalar locX = x + 0.5f - center.fX;
373 SkScalar locY = y + 0.5f - center.fY;
374
375 if (locX >= 0.0f) {
376 if (locY > 0.0f) {
377 norm = locX >= locY ? rightUp : down; // LR corner
378 } else {
379 norm = rightUp;
380 }
381 } else {
382 if (locY > 0.0f) {
383 norm = -locX > locY ? leftUp : down; // LL corner
384 } else {
385 norm = leftUp;
386 }
387 }
388
389 norm_to_rgb(bm, x, y, norm);
390 }
391 }
392}

◆ CreatePortableTypeface()

sk_sp< SkTypeface > ToolUtils::CreatePortableTypeface ( const char *  name,
SkFontStyle  style 
)

Returns a platform-independent text renderer.

Definition at line 187 of file FontToolUtils.cpp.

187 {
188 static sk_sp<SkFontMgr> portableFontMgr = MakePortableFontMgr();
189 SkASSERT_RELEASE(portableFontMgr);
190 sk_sp<SkTypeface> face = portableFontMgr->legacyMakeTypeface(name, style);
191 SkASSERT_RELEASE(face);
192 return face;
193}
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
Definition: SkFontMgr.cpp:150
sk_sp< SkFontMgr > MakePortableFontMgr()
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ CreateStringBitmap()

SkBitmap ToolUtils::CreateStringBitmap ( int  w,
int  h,
SkColor  c,
int  x,
int  y,
int  textSize,
const char *  str 
)

Definition at line 206 of file FontToolUtils.cpp.

207 {
209 bitmap.allocN32Pixels(w, h);
210 SkCanvas canvas(bitmap);
211
213 paint.setColor(c);
214
216
217 canvas.clear(0x00000000);
218 canvas.drawSimpleText(str,
219 strlen(str),
223 font,
224 paint);
225
226 // Tag data as sRGB (without doing any color space conversion). Color-space aware configs
227 // will process this correctly but legacy configs will render as if this returned N32.
230 result.setPixelRef(sk_ref_sp(bitmap.pixelRef()), 0, 0);
231 return result;
232}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
#define SkIntToScalar(x)
Definition: SkScalar.h:57
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
GAsyncResult * result
sk_sp< SkTypeface > DefaultPortableTypeface()

◆ CreateStringImage()

sk_sp< SkImage > ToolUtils::CreateStringImage ( int  w,
int  h,
SkColor  c,
int  x,
int  y,
int  textSize,
const char *  str 
)

Definition at line 234 of file FontToolUtils.cpp.

235 {
236 return CreateStringBitmap(w, h, c, x, y, textSize, str).asImage();
237}
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
SkBitmap CreateStringBitmap(int w, int h, SkColor c, int x, int y, int textSize, const char *str)

◆ CreateTestTypeface()

sk_sp< SkTypeface > ToolUtils::CreateTestTypeface ( const char *  name,
SkFontStyle  style 
)

Definition at line 307 of file FontToolUtils.cpp.

307 {
310 sk_sp<SkTypeface> face = fm->legacyMakeTypeface(name, style);
311 if (face) {
312 return face;
313 }
314 return CreatePortableTypeface(name, style);
315}
sk_sp< SkTypeface > CreatePortableTypeface(const char *name, SkFontStyle style)
sk_sp< SkFontMgr > TestFontMgr()

◆ CreateTypefaceFromResource()

sk_sp< SkTypeface > ToolUtils::CreateTypefaceFromResource ( const char *  resource,
int  ttcIndex 
)

Definition at line 317 of file FontToolUtils.cpp.

317 {
320 return fm->makeFromStream(GetResourceAsStream(resource), ttcIndex);
321}
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition: Resources.cpp:31
static SkString resource(SkPDFResourceType type, int index)
sk_sp< SkTypeface > makeFromStream(std::unique_ptr< SkStreamAsset >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:127

◆ DecodeDataToBitmap()

bool ToolUtils::DecodeDataToBitmap ( sk_sp< SkData data,
SkBitmap dst 
)

Definition at line 22 of file DecodeUtils.cpp.

22 {
23 std::unique_ptr<SkImageGenerator> gen(SkImageGenerators::MakeFromEncoded(std::move(data)));
24 return gen && dst->tryAllocPixels(gen->getInfo()) &&
25 gen->getPixels(
26 gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes());
27}
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)
def gen()
Definition: dom.py:77
Definition: gen.py:1
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ DefaultFont()

SkFont ToolUtils::DefaultFont ( )

Definition at line 323 of file FontToolUtils.cpp.

323 {
324 return SkFont(DefaultTypeface(), 12);
325}
sk_sp< SkTypeface > DefaultTypeface()

◆ DefaultPortableFont()

SkFont ToolUtils::DefaultPortableFont ( )

Returns a font that has a non-empty typeface. This could change, so don't depend on things like how it looks, font metrics, etc.

Definition at line 202 of file FontToolUtils.cpp.

202 {
203 return SkFont(DefaultPortableTypeface(), 12);
204}

◆ DefaultPortableTypeface()

sk_sp< SkTypeface > ToolUtils::DefaultPortableTypeface ( )

Definition at line 195 of file FontToolUtils.cpp.

195 {
196 // At last check, the default typeface is a serif font.
198 SkASSERT_RELEASE(face);
199 return face;
200}

◆ DefaultTypeface()

sk_sp< SkTypeface > ToolUtils::DefaultTypeface ( )

Definition at line 303 of file FontToolUtils.cpp.

303 {
304 return CreateTestTypeface(nullptr, SkFontStyle());
305}
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)

◆ DEFINE_bool()

static ToolUtils::DEFINE_bool ( nativeFonts  ,
true  ,
"If  true,
use native font manager and rendering. " "If  false,
fonts will draw as portably as possible."   
)
static

◆ draw_checkerboard() [1/2]

void ToolUtils::draw_checkerboard ( SkCanvas canvas)
inline

A default checkerboard.

Definition at line 95 of file ToolUtils.h.

95 {
96 ToolUtils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
97}

◆ draw_checkerboard() [2/2]

void ToolUtils::draw_checkerboard ( SkCanvas canvas,
SkColor  color1,
SkColor  color2,
int  checkSize 
)

Draw a checkerboard pattern in the current canvas, restricted to the current clip, using SkBlendMode::kSrc.

Definition at line 174 of file ToolUtils.cpp.

174 {
176 paint.setShader(create_checkerboard_shader(c1, c2, size));
177 paint.setBlendMode(SkBlendMode::kSrc);
178 canvas->drawPaint(paint);
179}
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
static sk_sp< SkShader > create_checkerboard_shader(SkColor c1, SkColor c2, int size)

◆ EmojiSample() [1/2]

EmojiTestSample ToolUtils::EmojiSample ( )

Return a color emoji typeface if available.

Definition at line 92 of file FontToolUtils.cpp.

92 {
93 static const EmojiTestSample emojiSample = []() {
94 EmojiTestSample sample = {nullptr, ""};
95#if defined(SK_BUILD_FOR_WIN)
96 sample = EmojiSample(EmojiFontFormat::ColrV0);
97#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
98 sample = EmojiSample(EmojiFontFormat::Sbix);
99#else
100 sample = EmojiSample(EmojiFontFormat::Cbdt);
101#endif
102 if (sample.typeface) {
103 return sample;
104 }
105 return EmojiSample(EmojiFontFormat::Test);
106 }();
107 return emojiSample;
108}
EmojiTestSample EmojiSample(EmojiFontFormat format)
sk_sp< SkTypeface > typeface
Definition: FontToolUtils.h:48

◆ EmojiSample() [2/2]

EmojiTestSample ToolUtils::EmojiSample ( EmojiFontFormat  format)

Return a color emoji typeface of a specific color font format if available.

Definition at line 110 of file FontToolUtils.cpp.

110 {
111 EmojiTestSample sample;
112 sample.sampleText = "\U0001F600 \u2662"; // 😀 ♢
113 switch (format) {
114 case EmojiFontFormat::Cbdt:
115 sample.typeface = CreateTypefaceFromResource("fonts/cbdt.ttf");
116 break;
117 case EmojiFontFormat::Sbix:
118 sample.typeface = CreateTypefaceFromResource("fonts/sbix.ttf");
119 break;
120 case EmojiFontFormat::ColrV0:
121 sample.typeface = CreateTypefaceFromResource("fonts/colr.ttf");
122 break;
123 case EmojiFontFormat::Svg:
124 sample.typeface = CreateTypefaceFromResource("fonts/SampleSVG.ttf");
125 sample.sampleText = "abcdefghij";
126 break;
127 case EmojiFontFormat::Test:
128 sample.typeface = CreatePortableTypeface("Emoji", SkFontStyle());
129 }
130 return sample;
131}
uint32_t uint32_t * format
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)

◆ EncodeImageToPngFile() [1/2]

bool ToolUtils::EncodeImageToPngFile ( const char *  path,
const SkBitmap src 
)

Definition at line 60 of file EncodeUtils.cpp.

60 {
62 return file.isValid() && SkPngEncoder::Encode(&file, src.pixmap(), {});
63}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57

◆ EncodeImageToPngFile() [2/2]

bool ToolUtils::EncodeImageToPngFile ( const char *  path,
const SkPixmap src 
)

Definition at line 65 of file EncodeUtils.cpp.

65 {
67 return file.isValid() && SkPngEncoder::Encode(&file, src, {});
68}

◆ equal_pixels() [1/3]

bool ToolUtils::equal_pixels ( const SkBitmap bm0,
const SkBitmap bm1 
)

Definition at line 480 of file ToolUtils.cpp.

480 {
481 SkPixmap pm0, pm1;
482 if (!bm0.peekPixels(&pm0)) {
483 SkDebugf("Could not read pixels from A\n");
484 return false;
485 }
486 if (!bm1.peekPixels(&pm1)) {
487 SkDebugf("Could not read pixels from B\n");
488 return false;
489 }
490 return equal_pixels(pm0, pm1);
491}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool equal_pixels(const SkImage *a, const SkImage *b)
Definition: ToolUtils.cpp:493

◆ equal_pixels() [2/3]

bool ToolUtils::equal_pixels ( const SkImage a,
const SkImage b 
)

Definition at line 493 of file ToolUtils.cpp.

493 {
496 // ensure that peekPixels will succeed
497 auto imga = a->makeRasterImage();
498 auto imgb = b->makeRasterImage();
499
500 SkPixmap pm0, pm1;
501 if (!imga->peekPixels(&pm0)) {
502 SkDebugf("Could not read pixels from A\n");
503 return false;
504 }
505 if (!imgb->peekPixels(&pm1)) {
506 SkDebugf("Could not read pixels from B\n");
507 return false;
508 }
509 return equal_pixels(pm0, pm1);
510}
static bool b
struct MyStruct a[10]

◆ equal_pixels() [3/3]

bool ToolUtils::equal_pixels ( const SkPixmap ,
const SkPixmap  
)

Returns true iff all of the pixels between the two images are identical.

If the configs differ, return false.

Definition at line 456 of file ToolUtils.cpp.

456 {
457 if (a.width() != b.width() || a.height() != b.height()) {
458 SkDebugf("[ToolUtils::equal_pixels] Dimensions do not match (%d x %d) != (%d x %d)\n",
459 a.width(), a.height(), b.width(), b.height());
460 return false;
461 }
462
463 if (a.colorType() != b.colorType()) {
464 SkDebugf("[ToolUtils::equal_pixels] colorType does not match %d != %d\n",
465 (int) a.colorType(), (int) b.colorType());
466 return false;
467 }
468
469 for (int y = 0; y < a.height(); ++y) {
470 const char* aptr = (const char*)a.addr(0, y);
471 const char* bptr = (const char*)b.addr(0, y);
472 if (0 != memcmp(aptr, bptr, a.width() * a.info().bytesPerPixel())) {
473 SkDebugf("[ToolUtils::equal_pixels] row %d does not match byte for byte\n", y);
474 return false;
475 }
476 }
477 return true;
478}

◆ ExtractPaths()

void ToolUtils::ExtractPaths ( const char  filepath[],
std::function< PathSniffCallback callback 
)

Definition at line 26 of file SvgPathExtractor.cpp.

26 {
27 SkFILEStream stream(filepath);
28 if (!stream.isValid()) {
29 SkDebugf("ExtractPaths: invalid input file at \"%s\"\n", filepath);
30 return;
31 }
32
33 class PathSniffer : public SkCanvas {
34 public:
35 PathSniffer(std::function<PathSniffCallback> callback)
36 : SkCanvas(4096, 4096, nullptr)
37 , fPathSniffCallback(callback) {}
38 private:
39 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
40 fPathSniffCallback(this->getTotalMatrix(), path, paint);
41 }
42 std::function<PathSniffCallback> fPathSniffCallback;
43 };
44
46 if (!svg) {
47 SkDebugf("ExtractPaths: couldn't load svg at \"%s\"\n", filepath);
48 return;
49 }
50 PathSniffer pathSniffer(callback);
51 svg->setContainerSize(SkSize::Make(pathSniffer.getBaseLayerSize()));
52 svg->render(&pathSniffer);
53}
virtual void onDrawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:2144
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
Definition: SkPath.h:59
static sk_sp< SkSVGDOM > MakeFromStream(SkStream &str)
Definition: SkSVGDOM.h:57
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
const char * svg

◆ ExtractPathsFromSKP()

void ToolUtils::ExtractPathsFromSKP ( const char  filepath[],
std::function< PathSniffCallback callback 
)

Definition at line 757 of file ToolUtils.cpp.

757 {
758 SkFILEStream stream(filepath);
759 if (!stream.isValid()) {
760 SkDebugf("ExtractPaths: invalid input file at \"%s\"\n", filepath);
761 return;
762 }
763
764 class PathSniffer : public SkCanvas {
765 public:
766 PathSniffer(std::function<PathSniffCallback> callback)
767 : SkCanvas(4096, 4096, nullptr)
768 , fPathSniffCallback(callback) {}
769 private:
770 void onDrawPath(const SkPath& path, const SkPaint& paint) override {
771 fPathSniffCallback(this->getTotalMatrix(), path, paint);
772 }
773 std::function<PathSniffCallback> fPathSniffCallback;
774 };
775
777 if (!skp) {
778 SkDebugf("ExtractPaths: couldn't load skp at \"%s\"\n", filepath);
779 return;
780 }
781 PathSniffer pathSniffer(callback);
782 skp->playback(&pathSniffer);
783}
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Definition: SkPicture.cpp:147
Definition: __init__.py:1

◆ ExtractPathsFromSVG()

void ToolUtils::ExtractPathsFromSVG ( const char  filepath[],
std::function< PathSniffCallback  
)

◆ FontMgrIsGDI()

bool ToolUtils::FontMgrIsGDI ( )

Definition at line 289 of file FontToolUtils.cpp.

289 {
290 if (!FLAGS_nativeFonts) {
291 return false;
292 }
293#if defined(SK_BUILD_FOR_WIN)
294 if (FLAGS_gdi) {
295 return true;
296 }
297#endif
298 return false;
299}

◆ get_text_path() [1/2]

void ToolUtils::get_text_path ( const SkFont ,
const void *  text,
size_t  length,
SkTextEncoding  ,
SkPath ,
const SkPoint positions = nullptr 
)

◆ get_text_path() [2/2]

void ToolUtils::get_text_path ( const SkFont font,
const void *  text,
size_t  length,
SkTextEncoding  encoding,
SkPath dst,
const SkPoint  pos[] 
)

Definition at line 236 of file ToolUtils.cpp.

241 {
242 SkAutoToGlyphs atg(font, text, length, encoding);
243 const int count = atg.count();
244 AutoTArray<SkPoint> computedPos;
245 if (pos == nullptr) {
246 computedPos.reset(count);
247 font.getPos(atg.glyphs(), count, &computedPos[0]);
248 pos = computedPos.get();
249 }
250
251 struct Rec {
252 SkPath* fDst;
253 const SkPoint* fPos;
254 } rec = {dst, pos};
255 font.getPaths(atg.glyphs(),
256 atg.count(),
257 [](const SkPath* src, const SkMatrix& mx, void* ctx) {
258 Rec* rec = (Rec*)ctx;
259 if (src) {
260 SkMatrix tmp(mx);
261 tmp.postTranslate(rec->fPos->fX, rec->fPos->fY);
262 rec->fDst->addPath(*src, tmp);
263 }
264 rec->fPos += 1;
265 },
266 &rec);
267}
SkPoint pos
SkRect fDst
Definition: LatticeOp.cpp:381
void reset(size_t count=0)
Definition: SkTemplates.h:123
size_t length

◆ GetResourceAsBitmap()

bool ToolUtils::GetResourceAsBitmap ( const char *  resource,
SkBitmap dst 
)
inline

Definition at line 21 of file DecodeUtils.h.

21 {
23}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
bool DecodeDataToBitmap(sk_sp< SkData > data, SkBitmap *dst)
Definition: DecodeUtils.cpp:22

◆ GetResourceAsImage()

sk_sp< SkImage > ToolUtils::GetResourceAsImage ( const char *  resource)
inline

Definition at line 25 of file DecodeUtils.h.

25 {
27}
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)

◆ make_pixmaps()

int ToolUtils::make_pixmaps ( SkColorType  ,
SkAlphaType  ,
bool  withMips,
const SkColor4f  colors[6],
SkPixmap  pixmaps[6],
std::unique_ptr< char[]> *  mem 
)

Create pixmaps to initialize a 32x32 image w/ or w/o mipmaps. Returns the number of levels (either 1 or 6). The mipmap levels will be colored as specified in 'colors'

Definition at line 181 of file ToolUtils.cpp.

186 {
187
188 int levelSize = 32;
189 int numMipLevels = withMips ? 6 : 1;
190 size_t size = 0;
191 SkImageInfo ii[6];
192 size_t rowBytes[6];
193 for (int level = 0; level < numMipLevels; ++level) {
194 ii[level] = SkImageInfo::Make(levelSize, levelSize, ct, at);
195 rowBytes[level] = ii[level].minRowBytes();
196 // Make sure we test row bytes that aren't tight.
197 if (!(level % 2)) {
198 rowBytes[level] += (level + 1)*SkColorTypeBytesPerPixel(ii[level].colorType());
199 }
200 size += rowBytes[level]*ii[level].height();
201 levelSize /= 2;
202 }
203 mem->reset(new char[size]);
204 char* addr = mem->get();
205 for (int level = 0; level < numMipLevels; ++level) {
206 pixmaps[level].reset(ii[level], addr, rowBytes[level]);
207 addr += rowBytes[level]*ii[level].height();
208 pixmaps[level].erase(colors[level]);
209 }
210 return numMipLevels;
211}
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
Definition: SkImageInfo.cpp:16
bool erase(SkColor color, const SkIRect &subset) const
Definition: SkPixmap.cpp:742
void reset()
Definition: SkPixmap.cpp:32
PODArray< SkColor > colors
Definition: SkRecords.h:276
size_t minRowBytes() const
Definition: SkImageInfo.h:517
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
int height() const
Definition: SkImageInfo.h:371

◆ make_star()

SkPath ToolUtils::make_star ( const SkRect bounds,
int  numPts,
int  step 
)

Definition at line 269 of file ToolUtils.cpp.

269 {
270 SkASSERT(numPts != step);
273 builder.moveTo(0, -1);
274 for (int i = 1; i < numPts; ++i) {
275 int idx = i * step % numPts;
276 SkScalar theta = idx * 2 * SK_ScalarPI / numPts + SK_ScalarPI / 2;
277 SkScalar x = SkScalarCos(theta);
278 SkScalar y = -SkScalarSin(theta);
279 builder.lineTo(x, y);
280 }
281 SkPath path = builder.detach();
282 path.transform(SkMatrix::RectToRect(path.getBounds(), bounds));
283 return path;
284}
static int step(int x, SkScalar min, SkScalar max)
Definition: BlurTest.cpp:215
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ MakePortableFontMgr()

sk_sp< SkFontMgr > ToolUtils::MakePortableFontMgr ( )

Definition at line 175 of file TestFontMgr.cpp.

175{ return sk_make_sp<FontMgr>(); }

◆ makeSurface()

sk_sp< SkSurface > ToolUtils::makeSurface ( SkCanvas canvas,
const SkImageInfo info,
const SkSurfaceProps props 
)

Definition at line 512 of file ToolUtils.cpp.

514 {
515 auto surf = canvas->makeSurface(info, props);
516 if (!surf) {
517 surf = SkSurfaces::Raster(info, props);
518 }
519 return surf;
520}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195

◆ MakeTextureImage()

sk_sp< SkImage > ToolUtils::MakeTextureImage ( SkCanvas canvas,
sk_sp< SkImage orig 
)

Definition at line 32 of file GpuToolUtils.cpp.

32 {
33 if (!orig) {
34 return nullptr;
35 }
36
37#if defined(SK_GANESH)
38 if (canvas->recordingContext() && canvas->recordingContext()->asDirectContext()) {
39 GrDirectContext* dContext = canvas->recordingContext()->asDirectContext();
40 const GrCaps* caps = dContext->priv().caps();
41
42 if (orig->width() >= caps->maxTextureSize() || orig->height() >= caps->maxTextureSize()) {
43 // Ganesh is able to tile large SkImage draws. Always forcing SkImages to be uploaded
44 // prevents this feature from being tested by our tools. For now, leave excessively
45 // large SkImages as bitmaps.
46 return orig;
47 }
48
49 return SkImages::TextureFromImage(dContext, orig);
50 }
51#endif
52#if defined(SK_GRAPHITE)
53 if (canvas->recorder()) {
54 return SkImages::TextureFromImage(canvas->recorder(), orig, {false});
55 }
56#endif
57 return orig;
58}
const GrCaps * caps() const
Definition: GrCaps.h:57
int maxTextureSize() const
Definition: GrCaps.h:229
virtual GrDirectContext * asDirectContext()
GrDirectContextPriv priv()
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)

◆ NameForFontFormat()

SkString ToolUtils::NameForFontFormat ( EmojiFontFormat  format)

Return a string representation of the requeste format. Useful for suffixing test names.

Definition at line 133 of file FontToolUtils.cpp.

133 {
134 switch (format) {
135 case EmojiFontFormat::Cbdt:
136 return SkString("cbdt");
137 case EmojiFontFormat::Sbix:
138 return SkString("sbix");
139 case EmojiFontFormat::ColrV0:
140 return SkString("colrv0");
141 case EmojiFontFormat::Test:
142 return SkString("test");
143 case EmojiFontFormat::Svg:
144 return SkString("svg");
145 }
146 return SkString();
147}

◆ norm_to_rgb()

static void ToolUtils::norm_to_rgb ( SkBitmap bm,
int  x,
int  y,
const SkVector3 norm 
)
inlinestatic

Definition at line 286 of file ToolUtils.cpp.

286 {
287 SkASSERT(SkScalarNearlyEqual(norm.length(), 1.0f));
288 unsigned char r = static_cast<unsigned char>((0.5f * norm.fX + 0.5f) * 255);
289 unsigned char g = static_cast<unsigned char>((-0.5f * norm.fY + 0.5f) * 255);
290 unsigned char b = static_cast<unsigned char>((0.5f * norm.fZ + 0.5f) * 255);
291 *bm->getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b);
292}
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColorPriv.h:106
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
SkScalar length() const
Definition: SkPoint3.h:44

◆ PlanetTypeface()

sk_sp< SkTypeface > ToolUtils::PlanetTypeface ( )

Definition at line 73 of file FontToolUtils.cpp.

73 {
74 static const sk_sp<SkTypeface> planetTypeface = []() {
75 const char* filename;
76#if defined(SK_BUILD_FOR_WIN)
77 filename = "fonts/planetcolr.ttf";
78#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
79 filename = "fonts/planetsbix.ttf";
80#else
81 filename = "fonts/planetcbdt.ttf";
82#endif
84 if (typeface) {
85 return typeface;
86 }
87 return CreateTestTypeface("Planet", SkFontStyle());
88 }();
89 return planetTypeface;
90}

◆ SampleUserTypeface()

sk_sp< SkTypeface > ToolUtils::SampleUserTypeface ( )

A simple SkUserTypeface for testing.

Definition at line 149 of file FontToolUtils.cpp.

149 {
151 SkFont font;
152 const float upem = 200;
153
154 {
155 SkFontMetrics metrics;
156 metrics.fFlags = 0;
157 metrics.fTop = -200;
158 metrics.fAscent = -150;
159 metrics.fDescent = 50;
160 metrics.fBottom = -75;
161 metrics.fLeading = 10;
162 metrics.fAvgCharWidth = 150;
163 metrics.fMaxCharWidth = 300;
164 metrics.fXMin = -20;
165 metrics.fXMax = 290;
166 metrics.fXHeight = -100;
167 metrics.fCapHeight = 0;
168 metrics.fUnderlineThickness = 5;
169 metrics.fUnderlinePosition = 2;
170 metrics.fStrikeoutThickness = 5;
171 metrics.fStrikeoutPosition = -50;
172 builder.setMetrics(metrics, 1.0f/upem);
173 }
174 builder.setFontStyle(SkFontStyle(367, 3, SkFontStyle::kOblique_Slant));
175
176 const SkMatrix scale = SkMatrix::Scale(1.0f/upem, 1.0f/upem);
177 for (SkGlyphID index = 0; index <= 67; ++index) {
179 width = 100;
180
181 builder.setGlyph(index, width/upem, SkPath::Circle(50, -50, 75).makeTransform(scale));
182 }
183
184 return builder.detach();
185}
uint16_t SkGlyphID
Definition: SkTypes.h:179
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:3598
int32_t width
const Scalar scale
SkScalar fTop
greatest extent above origin of any glyph bounding box, typically negative; deprecated with variable ...
Definition: SkFontMetrics.h:53
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAvgCharWidth
average character width, zero if unknown
Definition: SkFontMetrics.h:58
SkScalar fStrikeoutPosition
distance from baseline to bottom of stroke, typically negative
Definition: SkFontMetrics.h:67
SkScalar fStrikeoutThickness
strikeout thickness
Definition: SkFontMetrics.h:66
SkScalar fMaxCharWidth
maximum character width, zero if unknown
Definition: SkFontMetrics.h:59
SkScalar fBottom
greatest extent below origin of any glyph bounding box, typically positive; deprecated with variable ...
Definition: SkFontMetrics.h:56
uint32_t fFlags
FontMetricsFlags indicating which metrics are valid.
Definition: SkFontMetrics.h:52
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fXHeight
height of lower-case 'x', zero if unknown, typically negative
Definition: SkFontMetrics.h:62
SkScalar fUnderlineThickness
underline thickness
Definition: SkFontMetrics.h:64
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55
SkScalar fCapHeight
height of an upper-case letter, zero if unknown, typically negative
Definition: SkFontMetrics.h:63
SkScalar fXMin
greatest extent to left of origin of any glyph bounding box, typically negative; deprecated with vari...
Definition: SkFontMetrics.h:60
SkScalar fUnderlinePosition
distance from baseline to top of stroke, typically positive
Definition: SkFontMetrics.h:65
SkScalar fXMax
greatest extent to right of origin of any glyph bounding box, typically positive; deprecated with var...
Definition: SkFontMetrics.h:61

◆ TestFontMgr()

sk_sp< SkFontMgr > ToolUtils::TestFontMgr ( )

Definition at line 247 of file FontToolUtils.cpp.

247 {
248 static sk_sp<SkFontMgr> mgr;
249 static SkOnce once;
250 once([] {
251 if (!FLAGS_nativeFonts) {
252 mgr = MakePortableFontMgr();
253 }
254#if defined(SK_BUILD_FOR_WIN) && defined(SK_FONTMGR_GDI_AVAILABLE)
255 else if (FLAGS_gdi) {
256 mgr = SkFontMgr_New_GDI();
257 }
258#endif
259#if defined(SK_FONTMGR_FONTATIONS_AVAILABLE)
260 else if (FLAGS_fontations) {
262 }
263#endif
264 else {
265#if defined(SK_BUILD_FOR_ANDROID) && defined(SK_FONTMGR_ANDROID_AVAILABLE)
266 mgr = SkFontMgr_New_Android(nullptr, std::make_unique<SkFontScanner_FreeType>());
267#elif defined(SK_BUILD_FOR_WIN) && defined(SK_FONTMGR_DIRECTWRITE_AVAILABLE)
268 mgr = SkFontMgr_New_DirectWrite();
269#elif defined(SK_FONTMGR_CORETEXT_AVAILABLE) && (defined(SK_BUILD_FOR_IOS) || \
270 defined(SK_BUILD_FOR_MAC))
271 mgr = SkFontMgr_New_CoreText(nullptr);
272#elif defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
273 mgr = SkFontMgr_New_FontConfig(nullptr);
274#elif defined(SK_FONTMGR_FREETYPE_DIRECTORY_AVAILABLE)
275 // In particular, this is used on ChromeOS, which is Linux-like but doesn't have
276 // FontConfig.
278#elif defined(SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE)
280#else
281 mgr = SkFontMgr::RefEmpty();
282#endif
283 }
284 SkASSERT_RELEASE(mgr);
285 });
286 return mgr;
287}
#define SK_FONT_FILE_PREFIX
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Fontations_Empty()
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts *custom)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Directory(const char *dir)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Empty()
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_CoreText(CTFontCollectionRef)
static sk_sp< SkFontMgr > RefEmpty()
Definition: SkFontMgr.cpp:154
Definition: SkOnce.h:22

◆ tilemode_name()

const char * ToolUtils::tilemode_name ( SkTileMode  mode)

Definition at line 129 of file ToolUtils.cpp.

129 {
130 switch (mode) {
131 case SkTileMode::kClamp: return "clamp";
132 case SkTileMode::kRepeat: return "repeat";
133 case SkTileMode::kMirror: return "mirror";
134 case SkTileMode::kDecal: return "decal";
135 }
137}
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228

◆ UsePortableFontMgr()

void ToolUtils::UsePortableFontMgr ( )

Definition at line 301 of file FontToolUtils.cpp.

301{ FLAGS_nativeFonts = false; }