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

Side by Side Diff: tests/GrGetCoeffBlendKnownComponentsTest.cpp

Issue 1334293003: Create fragment processor for performing input color blend with child processor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « tests/GpuColorFilterTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9
10 #if SK_SUPPORT_GPU
11
12 #include "GrBlend.h"
13 #include "SkGr.h"
14 #include "SkRandom.h"
15 #include "SkXfermode.h"
16
17 static GrColor make_baseline_color(GrColor src, GrColor dst, const SkXfermode* x m) {
18 SkPMColor skSrc = GrColorToSkPMColor(src);
19 SkPMColor skDst = GrColorToSkPMColor(dst);
20 if (xm) {
21 xm->xfer32(&skDst, &skSrc, 1, nullptr);
22 } else {
23 // null means src-over
24 skDst = SkPMSrcOver(skSrc, skDst);
25 }
26 return SkPMColorToGrColor(skDst);
27 }
28
29 DEF_TEST(GrGetCoeffBlendKnownComponents, reporter) {
30 SkRandom random;
31 for (int i = 0; i < SkXfermode::kLastCoeffMode; ++i) {
32 SkXfermode::Mode mode = (SkXfermode::Mode)i;
33 SkAutoTUnref<SkXfermode> xm(SkXfermode::Create(mode));
34 SkXfermode::Coeff srcCoeff, dstCoeff;
35 SkAssertResult(SkXfermode::ModeAsCoeff(mode, &srcCoeff, &dstCoeff));
36 for (int j = 0; j < 1000; ++j) {
37 GrColor src = GrPremulColor(random.nextU());
38 GrColor dst = GrPremulColor(random.nextU());
39 GrColor outColor;
40 GrColorComponentFlags outFlags;
41 GrGetCoeffBlendKnownComponents(SkXfermodeCoeffToGrBlendCoeff(srcCoef f),
42 SkXfermodeCoeffToGrBlendCoeff(dstCoef f),
43 src, kRGBA_GrColorComponentFlags,
44 dst, kRGBA_GrColorComponentFlags,
45 &outColor, &outFlags);
46 GrColor baselineColor = make_baseline_color(src, dst, xm);
47 if (SkAbs32(GrColorUnpackA(baselineColor) - GrColorUnpackA(outColor) ) > 1 ||
48 SkAbs32(GrColorUnpackR(baselineColor) - GrColorUnpackR(outColor) ) > 1 ||
49 SkAbs32(GrColorUnpackG(baselineColor) - GrColorUnpackG(outColor) ) > 1 ||
50 SkAbs32(GrColorUnpackB(baselineColor) - GrColorUnpackB(outColor) ) > 1) {
51 ERRORF(reporter, "Blended color is 0x%08x, expected 0x%08x", out Color,
52 baselineColor);
53 }
54 GrColorIsPMAssert(outColor);
55 }
56 }
57 GrColor outColor;
58 GrColorComponentFlags outFlags;
59 GrGetCoeffBlendKnownComponents(kZero_GrBlendCoeff, kZero_GrBlendCoeff,
60 0xFFFFFFFF, kNone_GrColorComponentFlags,
61 0xFFFFFFFF, kNone_GrColorComponentFlags,
62 &outColor, &outFlags);
63 REPORTER_ASSERT(reporter, GrColor_TRANSPARENT_BLACK == outColor &&
64 kRGBA_GrColorComponentFlags == outFlags);
65 GrGetCoeffBlendKnownComponents(
66 kOne_GrBlendCoeff, kOne_GrBlendCoeff,
67 0x80FF0100, (kG_GrColorComponentFlag | kB_GrColorComponentFlag | kA_GrCo lorComponentFlag),
68 0x7F00FFFF, (kR_GrColorComponentFlag | kG_GrColorComponentFlag | kA_GrCo lorComponentFlag),
69 &outColor, &outFlags);
70 REPORTER_ASSERT(reporter, GrColor_WHITE == outColor && kRGBA_GrColorComponen tFlags == outFlags);
71
72 GrGetCoeffBlendKnownComponents(
73 kOne_GrBlendCoeff, kISA_GrBlendCoeff,
74 0x0000000, kRGBA_GrColorComponentFlags,
75 0x80010203, kRGBA_GrColorComponentFlags,
76 &outColor, &outFlags);
77 REPORTER_ASSERT(reporter, 0x80010203 == outColor && kRGBA_GrColorComponentFl ags == outFlags);
78
79 GrGetCoeffBlendKnownComponents(kZero_GrBlendCoeff, kISA_GrBlendCoeff,
80 0x0000000, kA_GrColorComponentFlag,
81 0x80010203, kRGBA_GrColorComponentFlags,
82 &outColor, &outFlags);
83 REPORTER_ASSERT(reporter, 0x80010203 == outColor && kRGBA_GrColorComponentFl ags == outFlags);
84
85 GrGetCoeffBlendKnownComponents(
86 kIDC_GrBlendCoeff, kSC_GrBlendCoeff,
87 0x0, kNone_GrColorComponentFlags,
88 0x0, kRGBA_GrColorComponentFlags,
89 &outColor, &outFlags);
90 REPORTER_ASSERT(reporter, kNone_GrColorComponentFlags == outFlags);
91
92 GrGetCoeffBlendKnownComponents(
93 kOne_GrBlendCoeff, kISA_GrBlendCoeff,
94 0xFF808080, (kG_GrColorComponentFlag | kB_GrColorComponentFlag | kA_GrCo lorComponentFlag),
95 0xFF606060, kRGBA_GrColorComponentFlags,
96 &outColor, &outFlags);
97 REPORTER_ASSERT(reporter,
98 (kG_GrColorComponentFlag | kB_GrColorComponentFlag | kA_GrCo lorComponentFlag) == outFlags &&
99 (outColor & 0xFFFFFF00) == 0xFF808000);
100 }
101
102 #endif
OLDNEW
« no previous file with comments | « tests/GpuColorFilterTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698