diff options
author | mtklein <mtklein@chromium.org> | 2015-07-16 07:01:39 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-16 07:01:40 -0700 |
commit | 767d273ea0948e4f61d318bec58ce417cdc470df (patch) | |
tree | 2fbdd42be5a05f32f8300c4adbe9ddaed2d9e3dd /tests | |
parent | 6fb0b6779e40ce05c20cf279f0ecff31fa3cd60d (diff) |
Replace buggy_blend_modes GM with an exhaustive test.
The new test is disabled by default, as it's quite slow.
We can run it if we suspect problems by passing -x to DM.
This test would have been failing before the bug fix, and now is passing.
Assuming the Priv on the end means it's not considered public API...
TBR=reed@google.com
BUG=skia:4052
Review URL: https://codereview.chromium.org/1228333003
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BlendTest.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/BlendTest.cpp b/tests/BlendTest.cpp index a0a84d7a7b..d816b72250 100644 --- a/tests/BlendTest.cpp +++ b/tests/BlendTest.cpp @@ -1,5 +1,15 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #include "Test.h" #include "SkColor.h" +#include "SkColorPriv.h" +#include "SkTaskGroup.h" +#include "SkXfermode.h" #define ASSERT(x) REPORTER_ASSERT(r, x) @@ -256,3 +266,36 @@ DEF_TEST(Blend_dst_Exhaustive, r) { // all others // // Algorithms that make sense to use in Skia: blend_256_round, blend_256_round_alt, blend_perfect + +DEF_TEST(Blend_premul_begets_premul, r) { + // This test is quite slow, even if you have enough cores to run each mode in parallel. + if (!r->allowExtendedTest()) { + return; + } + + // No matter what xfermode we use, premul inputs should create premul outputs. + auto test_mode = [&](int m) { + SkXfermode::Mode mode = (SkXfermode::Mode)m; + if (mode == SkXfermode::kSrcOver_Mode) { + return; // TODO: can't create a SrcOver xfermode. + } + SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(mode)); + SkASSERT(xfermode); + // We'll test all alphas and legal color values, assuming all colors work the same. + // This is not true for non-separable blend modes, but this test still can't hurt. + for (int sa = 0; sa <= 255; sa++) { + for (int da = 0; da <= 255; da++) { + for (int s = 0; s <= sa; s++) { + for (int d = 0; d <= da; d++) { + SkPMColor src = SkPackARGB32(sa, s, s, s), + dst = SkPackARGB32(da, d, d, d); + xfermode->xfer32(&dst, &src, 1, nullptr); // To keep it simple, no AA. + if (!SkPMColorValid(dst)) { + ERRORF(r, "%08x is not premul using %s", dst, SkXfermode::ModeName(mode)); + } + }}}} + }; + + // Parallelism helps speed things up on my desktop from ~725s to ~50s. + sk_parallel_for(SkXfermode::kLastMode, test_mode); +} |