OLD | NEW |
(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 "SkCanvas.h" |
| 9 #include "SkGradientShader.h" |
| 10 #include "gm.h" |
| 11 |
| 12 // This GM reproduces what I think are overflow bugs in the CPU implementations
of a |
| 13 // couple xfermodes. I've marked non-obvious keys to reproducing the bug // Ess
ential! |
| 14 DEF_SIMPLE_GM(buggy_blend_modes, canvas, 800, 200) { |
| 15 const auto tiling = SkShader::kClamp_TileMode; |
| 16 const auto flags = SkGradientShader::kInterpolateColorsInPremul_Flag; // Es
sential! |
| 17 |
| 18 SkAutoTUnref<SkShader> cyanH, magentaV; |
| 19 { |
| 20 SkPoint pts[] = { {0,0}, {200, 0} }; |
| 21 SkColor colors[] = { 0x00000000, 0xFF00FFFF }; |
| 22 cyanH.reset( |
| 23 SkGradientShader::CreateLinear(pts, colors, nullptr, 2, tiling,
flags, nullptr)); |
| 24 } |
| 25 { |
| 26 SkPoint pts[] = { {0,0}, {0, 200} }; |
| 27 SkColor colors[] = { 0x00000000, 0xFFFF00FF }; |
| 28 magentaV.reset( |
| 29 SkGradientShader::CreateLinear(pts, colors, nullptr, 2, tiling,
flags, nullptr)); |
| 30 } |
| 31 |
| 32 SkXfermode::Mode modes[] = { |
| 33 SkXfermode::kDarken_Mode, // Looks ok? |
| 34 SkXfermode::kHardLight_Mode, // Definitely wrong. |
| 35 SkXfermode::kLighten_Mode, // Definitely wrong. |
| 36 SkXfermode::kOverlay_Mode, // Same code as kHardLight_Mode. |
| 37 }; |
| 38 |
| 39 canvas->clear(SK_ColorWHITE); |
| 40 for (auto mode : modes) { |
| 41 canvas->saveLayer(nullptr, nullptr); // Essential! |
| 42 SkPaint h, v; |
| 43 h.setShader(cyanH); |
| 44 v.setShader(magentaV); |
| 45 v.setXfermodeMode(mode); |
| 46 canvas->drawRect(SkRect::MakeWH(200,200), h); |
| 47 canvas->drawRect(SkRect::MakeWH(200,200), v); |
| 48 canvas->restore(); |
| 49 |
| 50 canvas->translate(200, 0); |
| 51 } |
| 52 } |
OLD | NEW |