234 {
236
238 }
239
240
241
242 auto runTest = [&](
const T&
src,
246 const bool csConversion =
248 const auto readCT = readInfo.colorType();
249 const auto readAT = readInfo.alphaType();
250 const auto srcCT = srcPixels.info().colorType();
251 const auto srcAT = srcPixels.info().alphaType();
253 const auto surfBounds =
SkIRect::MakeWH(srcPixels.width(), srcPixels.height());
255
256
257 const size_t dstRB = readBpp * readInfo.width() + 10 * readBpp;
258
259 const size_t dstSize = readInfo.computeByteSize(dstRB);
260 std::unique_ptr<char[]> dstData(new char[dstSize]);
261 SkPixmap dstPixels(readInfo, dstData.get(), dstRB);
262
263
264 static constexpr auto kInitialByte = static_cast<char>(0x1B);
265 std::fill_n(static_cast<char*>(dstPixels.writable_addr()),
266 dstPixels.computeByteSize(),
267 kInitialByte);
268
270
277 }
else if (!rules.fUncontainedRectSucceeds && !surfBounds.contains(
rect)) {
280
282 "Read failed. %sSrc CT: %s, Src AT: %s Read CT: %s, Read AT: %s, "
283 "Rect [%d, %d, %d, %d], CS conversion: %d\n",
289 }
290
291 bool guardOk = true;
292 auto guardCheck = [](
char x) {
return x == kInitialByte; };
293
294
295
299
300 const bool lumConversion =
303
304
305
306
307
308 float numer = (lumConversion || csConversion) ? 3.f : 2.f;
309
311 numer += 1;
312 }
314 float tol = numer / (1 << rgbBits);
315 float alphaTol = 0;
317
318
321 8});
322 alphaTol = 2.f / (1 << alphaBits);
323 }
324
325 const float tols[4] = {tol, tol, tol, alphaTol};
326 auto error = std::function<ComparePixmapsErrorReporter>([&](
int x,
int y,
327 const float diffs[4]) {
330 "%sSrc CT: %s, Src AT: %s, Read CT: %s, Read AT: %s, Rect [%d, %d, %d, %d]"
331 ", CS conversion: %d\n"
332 "Error at %d, %d. Diff in floats: (%f, %f, %f, %f)",
337 diffs[0], diffs[1], diffs[2], diffs[3]);
338 });
341 ref.alloc(refInfo);
343
344
346 ref.addr(),
347 ref.rowBytes());
349 srcPixels.addr(),
350 srcPixels.rowBytes());
351
352 unpremulSrc.readPixels(unpremulRef, srcReadRect.
x(), srcReadRect.
y());
353 } else {
354 srcPixels.readPixels(ref, srcReadRect.
x(), srcReadRect.
y());
355 }
356
360
361 const auto* v = dstData.get();
362 const auto*
end = dstData.get() + dstSize;
363 guardOk = std::all_of(v, v + dstWriteRect.
top() * dstPixels.rowBytes(), guardCheck);
364 v += dstWriteRect.
top() * dstPixels.rowBytes();
365 for (
int y = dstWriteRect.
top();
y < dstWriteRect.
bottom(); ++
y) {
366 guardOk |= std::all_of(v, v + dstWriteRect.
left() * readBpp, guardCheck);
367 auto pad = v + dstWriteRect.
right() * readBpp;
368 auto rowEnd =
std::min(
end, v + dstPixels.rowBytes());
369
370 guardOk |= std::all_of(pad, rowEnd, guardCheck);
371 v = rowEnd;
372 }
373 guardOk |= std::all_of(v,
end, guardCheck);
374 } else {
375 guardOk = std::all_of(dstData.get(), dstData.get() + dstSize, guardCheck);
376 }
377 if (!guardOk) {
379 "Result pixels modified result outside read rect [%d, %d, %d, %d]. "
380 "%sSrc CT: %s, Read CT: %s, CS conversion: %d",
383 csConversion);
384 }
386 };
387
388 static constexpr int kW = 16;
389 static constexpr int kH = 16;
390
393
394
395
396
397
398
399
400
401
402 std::array<bool, kLastEnum_SkColorType + 1> srcCTTestedThoroughly = {},
403 readCTTestedThoroughly = {};
407 continue;
408 }
411
414 srcAT,
416
417
418
419
420
423
425
428 srcPixels.
alloc(srcInfo);
429 {
431
432
437 }
438 refPixels.readPixels(readPixmap, 0, 0);
439 }
440
441 std::unique_ptr<skgpu::graphite::Recorder> recorder = context->
makeRecorder();
442
443 auto src = srcFactory(recorder.get(), srcPixels);
445 continue;
446 }
449 continue;
450 }
455 continue;
456 }
459
460
465 continue;
466 }
472
473 continue;
474 }
477 continue;
478 }
483 continue;
484 }
485 const auto& rects =
486 srcCTTestedThoroughly[sct] && readCTTestedThoroughly[rct]
487 ? shortRectArray
488 : longRectArray;
489 for (
const auto&
rect : rects) {
491 readCT, readAT, readCS);
493 Result r = runTest(
src, srcPixels, readInfo,
offset);
495 srcCTTestedThoroughly[sct] = true;
496 readCTTestedThoroughly[rct] = true;
497 }
498 }
499 }
500 }
501 }
502 }
503 }
504}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
std::vector< SkIRect > make_short_rect_array(int w, int h)
std::vector< SkIRect > make_long_rect_array(int w, int h)
static SkAutoPixmapStorage make_ref_data(const SkImageInfo &info, bool forceOpaque)
static constexpr int alpha_channel_bits(SkColorType ct)
static constexpr int min_rgb_channel_bits(SkColorType ct)
@ kUnknown_SkAlphaType
uninitialized
@ kOpaque_SkAlphaType
pixel is opaque
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kLastEnum_SkAlphaType
last valid value
@ kLastEnum_SkColorType
last valid value
@ kGray_SkColorChannelFlag
static bool read(SkStream *stream, void *buffer, size_t amount)
static uint32_t SkColorTypeChannelFlags(SkColorType ct)
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct)
bool ComparePixels(const GrCPixmap &a, const GrCPixmap &b, const float tolRGBA[4], std::function< ComparePixmapsErrorReporter > &error)
#define REPORTER_ASSERT(r, cond,...)
void alloc(const SkImageInfo &)
static bool Equals(const SkColorSpace *, const SkColorSpace *)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > MakeSRGBLinear()
const SkImageInfo & info() const
const void * addr() const
void append(const char text[])
const char * c_str() const
std::unique_ptr< Recorder > makeRecorder(const RecorderOptions &={})
const uint8_t uint32_t uint32_t GError ** error
static float sat(float r, float g, float b)
static float min(float r, float g, float b)
constexpr int32_t x() const
constexpr int32_t y() const
bool intersect(const SkIRect &r)
static bool Intersects(const SkIRect &a, const SkIRect &b)
constexpr int32_t top() const
constexpr SkISize size() const
constexpr int32_t bottom() const
constexpr int32_t right() const
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
constexpr int32_t left() const
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
SkImageInfo makeDimensions(SkISize newSize) const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)