aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-01-30 18:52:31 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-30 18:52:31 -0800
commit395eabeb0e72334c45324874c6e009b54634df21 (patch)
treeb6ff3f497e98db84417c3c6f6e8e2235c277101b /gm
parentafd25f703d9bbc9cd80b03b63b30abd14db4911d (diff)
float components in xfermodes
Diffstat (limited to 'gm')
-rw-r--r--gm/color4f.cpp69
-rw-r--r--gm/xfer4f.cpp18
2 files changed, 79 insertions, 8 deletions
diff --git a/gm/color4f.cpp b/gm/color4f.cpp
new file mode 100644
index 0000000000..98ce0824cc
--- /dev/null
+++ b/gm/color4f.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011 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 "SkColorPriv.h"
+#include "SkShader.h"
+#include "SkSurface.h"
+
+#include "SkColorMatrixFilter.h"
+#include "SkGradientShader.h"
+
+static SkShader* make_opaque_color() {
+ return SkShader::CreateColorShader(0xFFFF0000);
+}
+
+static SkShader* make_alpha_color() {
+ return SkShader::CreateColorShader(0x80FF0000);
+}
+
+static SkColorFilter* make_cf_null() {
+ return nullptr;
+}
+
+static SkColorFilter* make_cf0() {
+ SkColorMatrix cm;
+ cm.setSaturation(0.75f);
+ return SkColorMatrixFilter::Create(cm);
+}
+
+static void draw_into_canvas(SkCanvas* canvas) {
+ const SkRect r = SkRect::MakeWH(100, 100);
+ SkShader* (*shaders[])() { make_opaque_color, make_alpha_color };
+ SkColorFilter* (*filters[])() { make_cf_null, make_cf0 };
+
+ SkPaint paint;
+ for (auto shProc : shaders) {
+ paint.setShader(shProc())->unref();
+ for (auto cfProc : filters) {
+ SkSafeUnref(paint.setColorFilter(cfProc()));
+ canvas->drawRect(r, paint);
+ canvas->translate(120, 0);
+ }
+ }
+}
+
+DEF_SIMPLE_GM(color4f, canvas, 510, 250) {
+ canvas->translate(20, 20);
+
+ SkPaint bg;
+ // need the target to be opaque, so we can draw it to the screen
+ // even if it holds sRGB values.
+ bg.setColor(0xFFFFFFFF);
+
+ SkColorProfileType const profiles[] { kLinear_SkColorProfileType, kSRGB_SkColorProfileType };
+ for (auto profile : profiles) {
+ const SkImageInfo info = SkImageInfo::Make(500, 100, kN32_SkColorType, kPremul_SkAlphaType,
+ profile);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
+ surface->getCanvas()->drawPaint(bg);
+ draw_into_canvas(surface->getCanvas());
+ surface->draw(canvas, 0, 0, nullptr);
+ canvas->translate(0, 120);
+ }
+}
diff --git a/gm/xfer4f.cpp b/gm/xfer4f.cpp
index 1951fdbde2..b74b6e0685 100644
--- a/gm/xfer4f.cpp
+++ b/gm/xfer4f.cpp
@@ -8,7 +8,7 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkImageInfo.h"
-#include "SkXfer4f.h"
+#include "SkXfermode.h"
static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfileType profile) {
const SkIRect ir = r.round();
@@ -21,26 +21,28 @@ static void draw_rect(SkCanvas* canvas, const SkRect& r, SkColor c, SkColorProfi
uint32_t flags = 0;
if (SkColorGetA(c) == 0xFF) {
- flags |= kSrcIsOpaque_SkXfer4fFlag;
+ flags |= SkXfermode::kSrcIsOpaque_PM4fFlag;
}
if (kSRGB_SkColorProfileType == profile) {
- flags |= kDstIsSRGB_SkXfer4fFlag;
+ flags |= SkXfermode::kDstIsSRGB_PM4fFlag;
}
- const SkPM4f src = SkPM4f::FromPMColor(SkPreMultiplyColor(c));
- auto proc1 = SkPM4fXfer1ProcFactory(SkXfermode::kSrcOver_Mode, flags);
+ const SkXfermode::PM4fState state { nullptr, flags };
+
+ const SkPM4f src = SkColor4f::FromColor(c).premul();
+ auto proc1 = SkXfermode::GetPM4fProc1(SkXfermode::kSrcOver_Mode, flags);
for (int y = 0; y < ir.height()/2; ++y) {
- proc1(pm.writable_addr32(0, y), src, ir.width());
+ proc1(state, pm.writable_addr32(0, y), src, ir.width(), nullptr);
}
SkPM4f srcRow[1000];
for (int i = 0; i < ir.width(); ++i) {
srcRow[i] = src;
}
- auto procN = SkPM4fXferNProcFactory(SkXfermode::kSrcOver_Mode, flags);
+ auto procN = SkXfermode::GetPM4fProcN(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());
+ procN(state, pm.writable_addr32(0, y), srcRow, ir.width(), nullptr);
}
canvas->drawBitmap(bm, r.left(), r.top(), nullptr);