Index: tests/RecordOptsTest.cpp |
diff --git a/tests/RecordOptsTest.cpp b/tests/RecordOptsTest.cpp |
index 4341b870bf4d46a6433461023bba92cabcdda579..4567a01409b7d5bdbfc6c8a6c778496428db3c27 100644 |
--- a/tests/RecordOptsTest.cpp |
+++ b/tests/RecordOptsTest.cpp |
@@ -16,6 +16,7 @@ |
#include "SkXfermode.h" |
#include "SkPictureRecorder.h" |
#include "SkPictureImageFilter.h" |
+#include "SkSurface.h" |
static const int W = 1920, H = 1080; |
@@ -343,3 +344,71 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) { |
assert_type<SkRecords::Restore>(r, record, index + 3); |
index += 4; |
} |
+ |
+static void do_draw(SkCanvas* canvas, SkColor color, bool doLayer) { |
+ canvas->drawColor(SK_ColorWHITE); |
+ |
+ SkPaint p; |
+ p.setColor(color); |
+ |
+ if (doLayer) { |
+ canvas->saveLayer(nullptr, nullptr); |
+ p.setXfermodeMode(SkXfermode::kSrc_Mode); |
+ canvas->drawPaint(p); |
+ canvas->restore(); |
+ } else { |
+ canvas->drawPaint(p); |
+ } |
+} |
+ |
+static bool is_equal(SkSurface* a, SkSurface* b) { |
+ const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); |
+ SkPMColor ca, cb; |
+ a->readPixels(info, &ca, sizeof(SkPMColor), 0, 0); |
+ b->readPixels(info, &cb, sizeof(SkPMColor), 0, 0); |
+ return ca == cb; |
+} |
+ |
+// Test drawing w/ and w/o a simple layer (no bounds or paint), so see that drawing ops |
+// that *should* draw the same in fact do. |
+// |
+// Perform this test twice : once directly, and once via a picture |
+// |
+static void do_savelayer_srcmode(skiatest::Reporter* r, SkColor color) { |
+ for (int doPicture = 0; doPicture <= 1; ++doPicture) { |
+ sk_sp<SkSurface> surf0 = SkSurface::MakeRasterN32Premul(10, 10); |
+ sk_sp<SkSurface> surf1 = SkSurface::MakeRasterN32Premul(10, 10); |
+ SkCanvas* c0 = surf0->getCanvas(); |
+ SkCanvas* c1 = surf1->getCanvas(); |
+ |
+ SkPictureRecorder rec0, rec1; |
+ if (doPicture) { |
+ c0 = rec0.beginRecording(10, 10); |
+ c1 = rec1.beginRecording(10, 10); |
+ } |
+ |
+ do_draw(c0, color, false); |
+ do_draw(c1, color, true); |
+ |
+ if (doPicture) { |
+ surf0->getCanvas()->drawPicture(rec0.finishRecordingAsPicture()); |
+ surf1->getCanvas()->drawPicture(rec1.finishRecordingAsPicture()); |
+ } |
+ |
+ // we replicate the assert so we can see which line is reported if there is a failure |
+ if (doPicture) { |
+ REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get())); |
+ } else { |
+ REPORTER_ASSERT(r, is_equal(surf0.get(), surf1.get())); |
+ } |
+ } |
+} |
+ |
+DEF_TEST(savelayer_srcmode_opaque, r) { |
+ do_savelayer_srcmode(r, SK_ColorRED); |
+} |
+ |
+DEF_TEST(savelayer_srcmode_alpha, r) { |
+ do_savelayer_srcmode(r, 0x80FF0000); |
+} |
+ |