Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: gm/pixelxorxfermode.cpp

Issue 1601743009: Add GM for SkPixelXorXfermode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: eraseRGB -> eraseARGB Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/pixelxorxfermode.cpp
diff --git a/gm/pixelxorxfermode.cpp b/gm/pixelxorxfermode.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8066959cea073f677fb933b380f642907c874b38
--- /dev/null
+++ b/gm/pixelxorxfermode.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "Resources.h"
+
+#include "SkImageDecoder.h"
+#include "SkPixelXorXfermode.h"
+#include "SkStream.h"
+
+class PixelXorXfermodeGM : public skiagm::GM {
+public:
+ PixelXorXfermodeGM() { }
+
+protected:
+ SkString onShortName() override {
+ return SkString("pixelxorxfermode");
+ }
+
+ SkISize onISize() override { return SkISize::Make(512, 512); }
+
+ void onOnceBeforeDraw() override {
+ SkImageDecoder* codec = nullptr;
+ SkString resourcePath = GetResourcePath("mandrill_512.png");
+ SkFILEStream stream(resourcePath.c_str());
+ if (stream.isValid()) {
+ codec = SkImageDecoder::Factory(&stream);
+ }
+ if (codec) {
+ stream.rewind();
+ codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
+ delete codec;
+ } else {
+ fBM.allocN32Pixels(1, 1);
+ fBM.eraseARGB(255, 255, 0 , 0); // red == bad
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ canvas->drawBitmap(fBM, 0, 0);
+
+ SkRect r = SkRect::MakeIWH(256, 256);
+
+ // Negate the red channel of the dst (via the ancillary color) but leave
+ // the green & blue channels alone
+ SkPaint p1;
+ p1.setColor(SK_ColorBLACK); // noop
+ p1.setXfermode(SkPixelXorXfermode::Create(SK_ColorRED));
+
+ canvas->drawRect(r, p1);
+
+ r.offsetTo(256.0f, 0.0f);
+
+ // Negate the dst color via the src color
+ SkPaint p2;
+ p2.setColor(SK_ColorWHITE);
+ p2.setXfermode(SkPixelXorXfermode::Create(SK_ColorBLACK)); // noop
+
+ canvas->drawRect(r, p2);
+
+ r.offsetTo(0.0f, 256.0f);
+
+ // Just return the original color
+ SkPaint p3;
+ p3.setColor(SK_ColorBLACK); // noop
+ p3.setXfermode(SkPixelXorXfermode::Create(SK_ColorBLACK)); // noop
+
+ canvas->drawRect(r, p3);
+
+ r.offsetTo(256.0f, 256.0f);
+
+ // Negate the red & green channels (via the ancillary color) but leave
+ // the blue channel alone
+ SkPaint p4;
+ p4.setColor(SK_ColorBLACK); // noop
+ p4.setXfermode(SkPixelXorXfermode::Create(SK_ColorYELLOW));
+
+ canvas->drawRect(r, p4);
+ }
+
+private:
+ SkBitmap fBM;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return new PixelXorXfermodeGM;)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698