Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
blob_cache_sim.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/encode/SkPngEncoder.h"
#include "include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "src/core/SkScalerContext.h"
#include "tools/text/SkTextBlobTrace.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file blob_cache_sim.cpp.

23 {
24 std::unordered_map<uint64_t, uint32_t> counts;
25 size_t total = 0;
26
27 for (int i = 1; i < argc; i++) {
28 const char* filename = argv[i];
29
30 SkFILEStream in{filename};
31 std::vector<SkTextBlobTrace::Record> trace = SkTextBlobTrace::CreateBlobTrace(&in, nullptr);
32 for (const SkTextBlobTrace::Record& record : trace) {
33 total++;
34 const SkPaint paint = record.paint;
35 bool fastByPass = paint.getStyle() == SkPaint::kFill_Style
36 && paint.getPathEffect() == nullptr
37 && paint.getMaskFilter() == nullptr;
38 if (fastByPass) {
39 uint64_t blobID = record.origUniqueID;
40 SkPoint offset = record.offset;
42 uint32_t colorBits =
43 (SkColorGetR(c) >> 5u) << 6u
44 | (SkColorGetG(c) >> 5u) << 3u
45 | SkColorGetB(c) >> 5u;
46
47 SkFixed fx = (SkScalarToFixed(offset.x()) >> 13) & 7;
48 SkFixed fy = (SkScalarToFixed(offset.y()) >> 13) & 7;
49 uint32_t posBits = (fx << 3 | fy) << 12;
50
51 uint64_t blobKey = blobID << 32u | posBits | colorBits;
52 auto lookup = counts.find(blobKey);
53 if (lookup == counts.end()) {
54 bool ok;
55 std::tie(lookup, ok) = counts.insert({blobKey, 0});
56 SkASSERT(ok);
57 }
58 lookup->second += 1;
59 std::cout << std::hex << blobKey << "\n";
60 }
61 }
62 std::cerr << "trace: " << filename
63 << " unique: " << counts.size()
64 << " all: " << total
65 << " ratio: " << (float)total/counts.size() << "\n";
66
67 SkRect bounds = {0, 0, 0, 0};
68 for (const SkTextBlobTrace::Record& record : trace) {
69 bounds.join(record.blob->bounds().makeOffset(record.offset.x(), record.offset.y()));
70 }
71 SkIRect iBounds = bounds.roundOut();
72 if (iBounds.size().isEmpty()) {
73 continue;
74 }
75 static constexpr SkColor kBackground = SK_ColorWHITE;
77 SkImageInfo::MakeN32Premul(iBounds.width() + 16, iBounds.height() + 16));
78 SkCanvas* canvas = surf->getCanvas();
79 canvas->translate(8.0f - iBounds.x(), 8.0f - iBounds.y());
80 canvas->clear(kBackground);
81
82 for (const SkTextBlobTrace::Record& record : trace) {
83 canvas->drawTextBlob(
84 record.blob.get(), record.offset.x(), record.offset.y(), record.paint);
85 }
86
87 sk_sp<SkImage> img(surf->makeImageSnapshot());
88 if (img) {
89 sk_sp<SkData> png = SkPngEncoder::Encode(nullptr, img.get(), {});
90 if (png) {
91 SkString path = SkStringPrintf("text_blob_trace_%04d.png", i);
92 SkFILEWStream(path.c_str()).write(png->data(), png->size());
93 }
94 }
95 }
96 return 0;
97}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkColorGetR(color)
Definition SkColor.h:65
#define SkColorGetG(color)
Definition SkColor.h:69
uint32_t SkColor
Definition SkColor.h:37
#define SkColorGetB(color)
Definition SkColor.h:73
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
int32_t SkFixed
Definition SkFixed.h:25
#define SkScalarToFixed(x)
Definition SkFixed.h:125
static bool ok(int result)
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
bool write(const void *buffer, size_t size) override
Definition SkStream.cpp:426
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
static SkColor CanonicalColor(SkColor color)
const Paint & paint
@ kBackground
Suitable for threads that shouldn't disrupt high priority work.
Definition embedder.h:258
char ** argv
Definition library.h:9
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
Optional< SkRect > bounds
Definition SkRecords.h:189
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
std::vector< SkTextBlobTrace::Record > CreateBlobTrace(SkStream *stream, sk_sp< SkFontMgr > lastResortMgr)
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
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 counts
Definition switches.h:239
Point offset
constexpr int32_t x() const
Definition SkRect.h:141
constexpr int32_t y() const
Definition SkRect.h:148
constexpr SkISize size() const
Definition SkRect.h:172
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
bool isEmpty() const
Definition SkSize.h:31
static SkImageInfo MakeN32Premul(int width, int height)
void offset(float dx, float dy)