Skip to content

Commit

Permalink
[WTR][Skia] Draw repaint rects mask
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271236

Reviewed by Alejandro G. Castro.

* Tools/WebKitTestRunner/skia/TestInvocationSkia.cpp:
(WTR::TestInvocation::dumpPixelsAndCompareWithExpected):

Canonical link: https://commits.webkit.org/276391@main
  • Loading branch information
carlosgcampos committed Mar 20, 2024
1 parent 1007bd9 commit c8dbfdb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Tools/WebKitTestRunner/skia/TestInvocationSkia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "PixelDumpSupport.h"
#include "PlatformWebView.h"
#include "TestController.h"
#include <skia/core/SkCanvas.h>
#include <skia/core/SkStream.h>
IGNORE_CLANG_WARNINGS_BEGIN("cast-align")
#include <skia/encode/SkPngEncoder.h>
Expand Down Expand Up @@ -66,7 +67,7 @@ static void dumpPixmap(const SkPixmap& pixmap, const std::string& checksum)
printPNG(data->bytes(), data->size(), checksum.c_str());
}

void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef, WKImageRef)
void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapshotType, WKArrayRef repaintRects, WKImageRef)
{
sk_sp<SkImage> image;
switch (snapshotType) {
Expand All @@ -78,12 +79,27 @@ void TestInvocation::dumpPixelsAndCompareWithExpected(SnapshotResultType snapsho
break;
}

// FIXME: support repaint rects.

SkPixmap pixmap;
if (!image->peekPixels(&pixmap))
return;

if (repaintRects) {
auto canvas = SkCanvas::MakeRasterDirect(image->imageInfo(), pixmap.writable_addr(), image->imageInfo().minRowBytes());
canvas->saveLayer(SkRect::MakeWH(image->width(), image->height()), nullptr);
canvas->drawColor(SkColor4f { 0, 0, 0, 0.66 });

SkPaint paint;
paint.setColor(SkColor4f { 0, 0, 0, 0 });
paint.setBlendMode(SkBlendMode::kSrc);

size_t count = WKArrayGetSize(repaintRects);
for (size_t i = 0; i < count; ++i) {
WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i)));
canvas->drawRect(SkRect::MakeXYWH(static_cast<float>(rect.origin.x), static_cast<float>(rect.origin.y), static_cast<float>(rect.size.width), static_cast<float>(rect.size.height)), paint);
}
canvas->restore();
}

auto snapshotHash = computeSHA1HashStringForPixmap(pixmap);
if (!compareActualHashToExpectedAndDumpResults(snapshotHash))
dumpPixmap(pixmap, snapshotHash);
Expand Down

0 comments on commit c8dbfdb

Please sign in to comment.