Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Task Struct Reference

Public Member Functions

 Task (const TaggedSrc &src, const TaggedSink &sink)
 

Static Public Member Functions

static void Run (const Task &task)
 
static SkString identify_gamut (SkColorSpace *cs)
 
static SkString identify_transfer_fn (SkColorSpace *cs)
 
static void WriteToDisk (const Task &task, SkString md5, const char *ext, SkStream *data, size_t len, const SkBitmap *bitmap, const HashAndEncode *hashAndEncode)
 

Public Attributes

const TaggedSrcsrc
 
const TaggedSinksink
 

Detailed Description

Definition at line 1161 of file DM.cpp.

Constructor & Destructor Documentation

◆ Task()

Task::Task ( const TaggedSrc src,
const TaggedSink sink 
)
inline

Definition at line 1162 of file DM.cpp.

1162: src(src), sink(sink) {}
const TaggedSrc & src
Definition DM.cpp:1163
const TaggedSink & sink
Definition DM.cpp:1164

Member Function Documentation

◆ identify_gamut()

static SkString Task::identify_gamut ( SkColorSpace cs)
inlinestatic

Definition at line 1300 of file DM.cpp.

1300 {
1301 if (!cs) {
1302 return SkString("untagged");
1303 }
1304
1305 skcms_Matrix3x3 gamut;
1306 if (cs->toXYZD50(&gamut)) {
1307 auto eq = [](skcms_Matrix3x3 x, skcms_Matrix3x3 y) {
1308 for (int i = 0; i < 3; i++)
1309 for (int j = 0; j < 3; j++) {
1310 if (x.vals[i][j] != y.vals[i][j]) { return false; }
1311 }
1312 return true;
1313 };
1314
1315 if (eq(gamut, SkNamedGamut::kSRGB )) { return SkString("sRGB"); }
1316 if (eq(gamut, SkNamedGamut::kAdobeRGB )) { return SkString("Adobe"); }
1317 if (eq(gamut, SkNamedGamut::kDisplayP3)) { return SkString("P3"); }
1318 if (eq(gamut, SkNamedGamut::kRec2020 )) { return SkString("2020"); }
1319 if (eq(gamut, SkNamedGamut::kXYZ )) { return SkString("XYZ"); }
1320 if (eq(gamut, gNarrow_toXYZD50 )) { return SkString("narrow"); }
1321 return SkString("other");
1322 }
1323 return SkString("non-XYZ");
1324 }
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition M44Test.cpp:18
static constexpr skcms_Matrix3x3 gNarrow_toXYZD50
bool toXYZD50(skcms_Matrix3x3 *toXYZD50) const
double y
double x
static constexpr skcms_Matrix3x3 kSRGB
static constexpr skcms_Matrix3x3 kAdobeRGB
static constexpr skcms_Matrix3x3 kXYZ
static constexpr skcms_Matrix3x3 kRec2020
static constexpr skcms_Matrix3x3 kDisplayP3

◆ identify_transfer_fn()

static SkString Task::identify_transfer_fn ( SkColorSpace cs)
inlinestatic

Definition at line 1326 of file DM.cpp.

1326 {
1327 if (!cs) {
1328 return SkString("untagged");
1329 }
1330
1332 return x.g == y.g
1333 && x.a == y.a
1334 && x.b == y.b
1335 && x.c == y.c
1336 && x.d == y.d
1337 && x.e == y.e
1338 && x.f == y.f;
1339 };
1340
1342 cs->transferFn(&tf);
1343 switch (skcms_TransferFunction_getType(&tf)) {
1345 if (tf.a == 1 && tf.b == 0 && tf.c == 0 && tf.d == 0 && tf.e == 0 && tf.f == 0) {
1346 return SkStringPrintf("gamma %.3g", tf.g);
1347 }
1348 if (eq(tf, SkNamedTransferFn::kSRGB)) { return SkString("sRGB"); }
1349 if (eq(tf, SkNamedTransferFn::kRec2020)) { return SkString("2020"); }
1350 return SkStringPrintf("%.3g %.3g %.3g %.3g %.3g %.3g %.3g",
1351 tf.g, tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1352
1353 case skcms_TFType_PQish:
1354 if (eq(tf, SkNamedTransferFn::kPQ)) { return SkString("PQ"); }
1355 return SkStringPrintf("PQish %.3g %.3g %.3g %.3g %.3g %.3g",
1356 tf.a, tf.b, tf.c, tf.d, tf.e, tf.f);
1357
1359 if (eq(tf, SkNamedTransferFn::kHLG)) { return SkString("HLG"); }
1360 return SkStringPrintf("HLGish %.3g %.3g %.3g %.3g %.3g (%.3g)",
1361 tf.a, tf.b, tf.c, tf.d, tf.e, tf.f+1);
1362
1363 case skcms_TFType_HLGinvish: break;
1364 case skcms_TFType_Invalid: break;
1365 }
1366 return SkString("non-numeric");
1367 }
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
void transferFn(float gabcdef[7]) const
static constexpr skcms_TransferFunction kRec2020
static constexpr skcms_TransferFunction kSRGB
static constexpr skcms_TransferFunction kHLG
static constexpr skcms_TransferFunction kPQ
skcms_TFType skcms_TransferFunction_getType(const skcms_TransferFunction *tf)
Definition skcms.cc:183
@ skcms_TFType_Invalid
@ skcms_TFType_HLGish
@ skcms_TFType_sRGBish
@ skcms_TFType_HLGinvish
@ skcms_TFType_PQish

◆ Run()

static void Task::Run ( const Task task)
inlinestatic

Definition at line 1166 of file DM.cpp.

1166 {
1168 SkString name = task.src->name();
1169
1170 SkString log;
1171 if (!FLAGS_dryRun) {
1174 start(task.sink.tag.c_str(), task.src.tag.c_str(),
1175 task.src.options.c_str(), name.c_str());
1176 Result result = task.sink->draw(*task.src, &bitmap, &stream, &log);
1177 if (!log.isEmpty()) {
1178 info("%s %s %s %s:\n%s\n", task.sink.tag.c_str()
1179 , task.src.tag.c_str()
1180 , task.src.options.c_str()
1181 , name.c_str()
1182 , log.c_str());
1183 }
1184 if (result.isSkip()) {
1185 done(task.sink.tag.c_str(), task.src.tag.c_str(),
1186 task.src.options.c_str(), name.c_str());
1187 return;
1188 }
1189 if (result.isFatal()) {
1190 fail(SkStringPrintf("%s %s %s %s: %s",
1191 task.sink.tag.c_str(),
1192 task.src.tag.c_str(),
1193 task.src.options.c_str(),
1194 name.c_str(),
1195 result.c_str()));
1196 }
1197
1198 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
1199 SkStreamAsset* data = stream.detachAsStream().release();
1201 std::unique_ptr<SkStreamAsset> ownedData(data);
1202
1203 std::unique_ptr<HashAndEncode> hashAndEncode;
1204
1205 SkString md5;
1206 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
1207 SkMD5 hash;
1208 if (data->getLength()) {
1209 hash.writeStream(data, data->getLength());
1210 data->rewind();
1211 } else {
1212 hashAndEncode = std::make_unique<HashAndEncode>(bitmap);
1213 hashAndEncode->feedHash(&hash);
1214 }
1215 md5 = hash.finish().toLowercaseHexString();
1216 }
1217
1218 if (!FLAGS_readPath.isEmpty() &&
1219 !gGold->contains(Gold(task.sink.tag, task.src.tag,
1220 task.src.options, name, md5))) {
1221 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
1222 md5.c_str(),
1223 task.sink.tag.c_str(),
1224 task.src.tag.c_str(),
1225 task.src.options.c_str(),
1226 name.c_str(),
1227 FLAGS_readPath[0]));
1228 }
1229
1230 // Tests sometimes use a nullptr ext to indicate no image should be uploaded.
1231 const char* ext = task.sink->fileExtension();
1232 if (ext && !FLAGS_writePath.isEmpty()) {
1233 #if defined(SK_BUILD_FOR_MAC)
1234 if (FLAGS_rasterize_pdf && SkString("pdf").equals(ext)) {
1235 SkASSERT(data->getLength() > 0);
1236
1237 sk_sp<SkData> blob = SkData::MakeFromStream(data, data->getLength());
1238
1239 SkUniqueCFRef<CGDataProviderRef> provider{
1240 CGDataProviderCreateWithData(nullptr,
1241 blob->data(),
1242 blob->size(),
1243 nullptr)};
1244
1245 SkUniqueCFRef<CGPDFDocumentRef> pdf{
1246 CGPDFDocumentCreateWithProvider(provider.get())};
1247
1248 CGPDFPageRef page = CGPDFDocumentGetPage(pdf.get(), 1);
1249
1250 CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
1251 const int w = (int)CGRectGetWidth (bounds),
1252 h = (int)CGRectGetHeight(bounds);
1253
1254 SkBitmap rasterized;
1255 rasterized.allocPixels(SkImageInfo::Make(
1257 rasterized.eraseColor(SK_ColorWHITE);
1258
1259 SkUniqueCFRef<CGColorSpaceRef> cs{CGColorSpaceCreateDeviceRGB()};
1260 CGBitmapInfo info = kCGBitmapByteOrder32Big |
1261 (CGBitmapInfo)kCGImageAlphaPremultipliedLast;
1262
1263 SkUniqueCFRef<CGContextRef> ctx{CGBitmapContextCreate(
1264 rasterized.getPixels(), w,h,8, rasterized.rowBytes(), cs.get(), info)};
1265 CGContextDrawPDFPage(ctx.get(), page);
1266
1267 // Skip calling hashAndEncode->feedHash(SkMD5*)... we want the .pdf's hash.
1268 hashAndEncode = std::make_unique<HashAndEncode>(rasterized);
1269 WriteToDisk(task, md5, "png", nullptr,0, &rasterized, hashAndEncode.get());
1270 } else
1271 #endif
1272 if (data->getLength()) {
1273 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr, nullptr);
1274 SkASSERT(bitmap.drawsNothing());
1275 } else if (!bitmap.drawsNothing()) {
1276 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap, hashAndEncode.get());
1277 }
1278 }
1279
1280 SkPixmap pm;
1281 if (FLAGS_checkF16 && bitmap.colorType() == kRGBA_F16Norm_SkColorType &&
1282 bitmap.peekPixels(&pm)) {
1283 bool unclamped = false;
1284 for (int y = 0; y < pm.height() && !unclamped; ++y)
1285 for (int x = 0; x < pm.width() && !unclamped; ++x) {
1287 float a = rgba[3];
1288 if (a > 1.0f || any(rgba < 0.0f) || any(rgba > a)) {
1289 SkDebugf("[%s] F16Norm pixel [%d, %d] unclamped: (%g, %g, %g, %g)\n",
1290 name.c_str(), x, y, rgba[0], rgba[1], rgba[2], rgba[3]);
1291 unclamped = true;
1292 }
1293 }
1294 }
1295 });
1296 }
1297 done(task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(), name.c_str());
1298 }
AutoreleasePool pool
static SkMD5::Digest md5(const SkBitmap &bm)
Definition CodecTest.cpp:77
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
Definition DM.cpp:263
static THashSet< Gold, Gold::Hash > * gGold
Definition DM.cpp:443
static void fail(const SkString &err)
Definition DM.cpp:234
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static SkTaskGroup * gDefinitelyThreadSafeWork
Definition DM.cpp:1157
static const uint32_t rgba[kNumPixels]
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
@ kRGBA_F16Norm_SkColorType
pixel with half floats in [0,1] for red, green, blue, alpha;
Definition SkColorType.h:36
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static uint32_t hash(const SkShaderBase::GradientInfo &v)
static bool equals(T *a, T *b)
Type::kYUV Type::kRGBA() int(0.7 *637)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
size_t rowBytes() const
Definition SkBitmap.h:238
void * getPixels() const
Definition SkBitmap.h:283
void eraseColor(SkColor4f) const
Definition SkBitmap.cpp:442
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition SkData.cpp:208
Definition SkMD5.h:19
const uint64_t * addr64() const
Definition SkPixmap.h:365
int width() const
Definition SkPixmap.h:160
int height() const
Definition SkPixmap.h:166
const char * c_str() const
Definition SkString.h:133
void add(std::function< void(void)> fn)
bool writeStream(SkStream *input, size_t length)
Definition SkStream.cpp:142
struct MyStruct a[10]
GAsyncResult * result
const char * name
Definition fuchsia.cc:50
Optional< SkRect > bounds
Definition SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
-comparison
SIN Vec< N, float > from_half(const Vec< N, uint16_t > &x)
Definition SkVx.h:790
SIT bool any(const Vec< 1, T > &x)
Definition SkVx.h:530
SkScalar w
SkScalar h
Definition DM.cpp:425
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
SkString toLowercaseHexString() const
Definition SkMD5.cpp:116
SkString tag
Definition DM.cpp:499
SkString tag
Definition DM.cpp:494
SkString options
Definition DM.cpp:495
static void WriteToDisk(const Task &task, SkString md5, const char *ext, SkStream *data, size_t len, const SkBitmap *bitmap, const HashAndEncode *hashAndEncode)
Definition DM.cpp:1369
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition SkVx.h:109

◆ WriteToDisk()

static void Task::WriteToDisk ( const Task task,
SkString  md5,
const char *  ext,
SkStream data,
size_t  len,
const SkBitmap bitmap,
const HashAndEncode hashAndEncode 
)
inlinestatic

Definition at line 1369 of file DM.cpp.

1374 {
1375
1376 // Determine whether or not the OldestSupportedSkpVersion extra_config is provided.
1377 bool isOldestSupportedSkp = false;
1378 for (int i = 1; i < FLAGS_key.size(); i += 2) {
1379 if (0 == strcmp(FLAGS_key[i-1], "extra_config") &&
1380 0 == strcmp(FLAGS_key[i], "OldestSupportedSkpVersion")) {
1381 isOldestSupportedSkp = true;
1382 break;
1383 }
1384 }
1385
1387 result.name = task.src->name();
1388 result.config = task.sink.tag;
1389 result.sourceType = task.src.tag;
1390 // If the OldestSupportedSkpVersion extra_config is provided, override the "skp"
1391 // source_type with "old-skp". This has the effect of grouping the oldest supported SKPs in
1392 // a separate Gold corpus for easier triaging.
1393 if (isOldestSupportedSkp && 0 == strcmp(result.sourceType.c_str(), "skp")) {
1394 result.sourceType = "old-skp";
1395 }
1396 result.sourceOptions = task.src.options;
1397 result.ext = ext;
1398 result.md5 = md5;
1399 if (bitmap) {
1400 result.gamut = identify_gamut (bitmap->colorSpace());
1401 result.transferFn = identify_transfer_fn (bitmap->colorSpace());
1402 result.colorType = ToolUtils::colortype_name (bitmap->colorType());
1403 result.alphaType = ToolUtils::alphatype_name (bitmap->alphaType());
1404 result.colorDepth = ToolUtils::colortype_depth(bitmap->colorType());
1405 }
1407
1408 // If an MD5 is uninteresting, we want it noted in the JSON file,
1409 // but don't want to dump it out as a .png (or whatever ext is).
1410 if (gUninterestingHashes->contains(md5)) {
1411 return;
1412 }
1413
1414 const char* dir = FLAGS_writePath[0];
1415 SkString resources = GetResourcePath();
1416 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1417 dir = resources.c_str();
1418 }
1419 sk_mkdir(dir);
1420
1421 SkString path;
1422 if (FLAGS_nameByHash) {
1423 path = SkOSPath::Join(dir, result.md5.c_str());
1424 path.append(".");
1425 path.append(ext);
1426 if (sk_exists(path.c_str())) {
1427 return; // Content-addressed. If it exists already, we're done.
1428 }
1429 } else {
1430 path = SkOSPath::Join(dir, task.sink.tag.c_str());
1431 sk_mkdir(path.c_str());
1432 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
1433 sk_mkdir(path.c_str());
1434 if (0 != strcmp(task.src.options.c_str(), "")) {
1436 sk_mkdir(path.c_str());
1437 }
1438 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1439 path.append(".");
1440 path.append(ext);
1441 }
1442
1444 if (!file.isValid()) {
1445 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1446 return;
1447 }
1448 if (bitmap) {
1449 SkASSERT(hashAndEncode);
1450 if (!hashAndEncode->encodePNG(&file,
1451 result.md5.c_str(),
1452 FLAGS_key,
1453 FLAGS_properties)) {
1454 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1455 return;
1456 }
1457 } else {
1458 if (!file.writeStream(data, len)) {
1459 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1460 return;
1461 }
1462 }
1463 }
static THashSet< SkString > * gUninterestingHashes
Definition DM.cpp:467
SkString GetResourcePath(const char *resource)
Definition Resources.cpp:23
bool sk_mkdir(const char *path)
bool sk_exists(const char *path, SkFILE_Flags=(SkFILE_Flags) 0)
static void AddBitmapResult(const BitmapResult &)
bool encodePNG(SkWStream *, const char *md5, CommandLineFlags::StringArray key, CommandLineFlags::StringArray properties) const
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14
void append(const char text[])
Definition SkString.h:203
const char * colortype_depth(SkColorType ct)
Definition ToolUtils.cpp:97
const char * colortype_name(SkColorType ct)
Definition ToolUtils.cpp:65
const char * alphatype_name(SkAlphaType at)
Definition ToolUtils.cpp:55
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
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition switches.h:145
static SkString identify_transfer_fn(SkColorSpace *cs)
Definition DM.cpp:1326
static SkString identify_gamut(SkColorSpace *cs)
Definition DM.cpp:1300

Member Data Documentation

◆ sink

const TaggedSink& Task::sink

Definition at line 1164 of file DM.cpp.

◆ src

const TaggedSrc& Task::src

Definition at line 1163 of file DM.cpp.


The documentation for this struct was generated from the following file: