aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-01-29 05:22:59 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-29 05:22:59 -0800
commitfbc1e296b2e98dc76de533a2bb45d9ccc8c2498f (patch)
treef0f5e0a5d9b34519a0f5c9774ea316f4e0efe76c /gm
parentaa9cb62901075e9d2858353cb041e5e6d4719614 (diff)
starter procs for blending with pm4f
curr/maxrss loops min median mean max stddev samples config bench 8/8 MB 4 87.1µs 91µs 89.8µs 92µs 2% ▇▇▇▇█▇▅▁▁▁ nonrendering xfer4f_srcover_N_opaque_linear 9/9 MB 2 196µs 196µs 215µs 383µs 27% ▁▁▁▁█▁▁▁▁▁ nonrendering xfer4f_srcover_N_opaque_srgb 9/9 MB 1 313µs 313µs 313µs 313µs 0% ▁▄▅▅▅▂████ nonrendering xfer4f_srcover_N_alpha_linear 9/9 MB 1 580µs 580µs 582µs 602µs 1% ▁▁▁▁▁▁▂▁▁█ nonrendering xfer4f_srcover_N_alpha_srgb 9/9 MB 23 13.1µs 13.1µs 13.1µs 13.1µs 0% ▆▄▄█▂▂▂▁▂▁ nonrendering xfer4f_srcover_1_opaque_linear 9/9 MB 23 13.2µs 13.2µs 13.2µs 13.2µs 0% █▄▂▁▃▁▂▂▂▂ nonrendering xfer4f_srcover_1_opaque_srgb 9/9 MB 2 178µs 183µs 183µs 185µs 1% ▇▇▇█▇▇▇▇▇▁ nonrendering xfer4f_srcover_1_alpha_linear 9/9 MB 1 517µs 517µs 517µs 517µs 0% ▇█▄▃▄▁▂▁▂▄ nonrendering xfer4f_srcover_1_alpha_srgb BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1642703003 TBR= landing now so these incremental types/functions can be used to collaborate with herb's work. nothing is active at this point Review URL: https://codereview.chromium.org/1642703003
Diffstat (limited to 'gm')
-rw-r--r--gm/xfer4f.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/gm/xfer4f.cpp b/gm/xfer4f.cpp
new file mode 100644
index 0000000000..1951fdbde2
--- /dev/null
+++ b/gm/xfer4f.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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 "SkCanvas.h"
+#include "SkImageInfo.h"
+#include "SkXfer4f.h"
+
+static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfileType profile) {
+ const SkIRect ir = r.round();
+
+ SkBitmap bm;
+ bm.allocN32Pixels(ir.width(), ir.height());
+ bm.eraseColor(0xFFFFFFFF);
+ SkPixmap pm;
+ bm.peekPixels(&pm);
+
+ uint32_t flags = 0;
+ if (SkColorGetA(c) == 0xFF) {
+ flags |= kSrcIsOpaque_SkXfer4fFlag;
+ }
+ if (kSRGB_SkColorProfileType == profile) {
+ flags |= kDstIsSRGB_SkXfer4fFlag;
+ }
+
+ const SkPM4f src = SkPM4f::FromPMColor(SkPreMultiplyColor(c));
+ auto proc1 = SkPM4fXfer1ProcFactory(SkXfermode::kSrcOver_Mode, flags);
+ for (int y = 0; y < ir.height()/2; ++y) {
+ proc1(pm.writable_addr32(0, y), src, ir.width());
+ }
+
+ SkPM4f srcRow[1000];
+ for (int i = 0; i < ir.width(); ++i) {
+ srcRow[i] = src;
+ }
+ auto procN = SkPM4fXferNProcFactory(SkXfermode::kSrcOver_Mode, flags);
+ // +1 to skip a row, so we can see the boundary between proc1 and procN
+ for (int y = ir.height()/2 + 1; y < ir.height(); ++y) {
+ procN(pm.writable_addr32(0, y), srcRow, ir.width());
+ }
+
+ canvas->drawBitmap(bm, r.left(), r.top(), nullptr);
+}
+
+/*
+ * Test SkXfer4fProcs directly for src-over, comparing them to current SkColor blits.
+ */
+DEF_SIMPLE_GM(xfer4f_srcover, canvas, 580, 380) {
+ const SkScalar W = 50;
+ const SkScalar H = 100;
+
+ const int profiles[] = {
+ -1,
+ kLinear_SkColorProfileType,
+ kSRGB_SkColorProfileType,
+ };
+ const SkColor colors[] = {
+ SK_ColorBLACK, SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE,
+ 0x88000000, 0x88FF0000, 0x8800FF00, 0x880000FF
+ };
+ canvas->translate(20, 20);
+
+ const SkRect r = SkRect::MakeWH(W, H);
+ for (auto profile : profiles) {
+ canvas->save();
+ for (SkColor c : colors) {
+ if (profile < 0) {
+ SkPaint p;
+ p.setColor(c);
+ canvas->drawRect(r, p);
+ } else {
+ draw_rect(canvas, r, c, (SkColorProfileType)profile);
+ }
+ canvas->translate(W + 20, 0);
+ }
+ canvas->restore();
+ canvas->translate(0, H + 20);
+ }
+}