blob: 6a4bd92b54cf62e6a8435bfd97751c1e2c5a95ee [file] [log] [blame]
commit-bot@chromium.org63972172013-10-16 13:53:54 +00001/*
2 * Copyright 2013 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 "gm.h"
9#include "SkColorFilter.h"
10#include "SkBlurMaskFilter.h"
11
12namespace skiagm {
13
14/**
15 * This test exercises bug 1719. An anti-aliased blurred path is rendered through a soft clip. On
16 * the GPU a scratch texture was used to hold the original path mask as well as the blurred path
17 * result. The same texture is then incorrectly used to generate the soft clip mask for the draw.
18 * Thus the same texture is used for both the blur mask and soft mask in a single draw.
19 *
20 * The correct image should look like a thin stroked round rect.
21 */
22class SkBug1719GM : public GM {
23public:
24 SkBug1719GM() {}
25
26protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000027 virtual uint32_t onGetFlags() const SK_OVERRIDE {
28 return kSkipTiled_Flag;
29 }
30
commit-bot@chromium.org63972172013-10-16 13:53:54 +000031 virtual SkString onShortName() SK_OVERRIDE {
32 return SkString("skbug1719");
33 }
34
35 virtual SkISize onISize() SK_OVERRIDE {
tfarinaf5393182014-06-09 23:59:03 -070036 return SkISize::Make(300, 100);
commit-bot@chromium.org63972172013-10-16 13:53:54 +000037 }
38
39 virtual void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE {
40 SkPaint bgPaint;
41 bgPaint.setColor(0xFF303030);
42 canvas->drawPaint(bgPaint);
43 }
44
45 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
46 canvas->translate(SkIntToScalar(-800), SkIntToScalar(-650));
47
48 // The data is lifted from an SKP that exhibited the bug.
49
50 // This is a round rect.
51 SkPath clipPath;
52 clipPath.moveTo(832.f, 654.f);
53 clipPath.lineTo(1034.f, 654.f);
54 clipPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f);
55 clipPath.lineTo(1042.f, 724.f);
56 clipPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f);
57 clipPath.lineTo(832.f, 732.f);
58 clipPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f);
59 clipPath.lineTo(824.f, 662.f);
60 clipPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f);
61 clipPath.close();
62
63 // This is a round rect nested inside a rect.
64 SkPath drawPath;
65 drawPath.moveTo(823.f, 653.f);
66 drawPath.lineTo(1043.f, 653.f);
67 drawPath.lineTo(1043.f, 733.f);
68 drawPath.lineTo(823.f, 733.f);
69 drawPath.lineTo(823.f, 653.f);
70 drawPath.close();
71 drawPath.moveTo(832.f, 654.f);
72 drawPath.lineTo(1034.f, 654.f);
73 drawPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f);
74 drawPath.lineTo(1042.f, 724.f);
75 drawPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f);
76 drawPath.lineTo(832.f, 732.f);
77 drawPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f);
78 drawPath.lineTo(824.f, 662.f);
79 drawPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f);
80 drawPath.close();
81 drawPath.setFillType(SkPath::kEvenOdd_FillType);
82
83 SkPaint paint;
84 paint.setAntiAlias(true);
85 paint.setColor(0xFF000000);
86 paint.setMaskFilter(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000087 SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
commit-bot@chromium.org63972172013-10-16 13:53:54 +000088 0.78867501f,
89 SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
90 paint.setColorFilter(
91 SkColorFilter::CreateModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode))->unref();
92
93 canvas->clipPath(clipPath, SkRegion::kIntersect_Op, true);
94 canvas->drawPath(drawPath, paint);
95 }
96
97private:
98
99 typedef GM INHERITED;
100};
101
102//////////////////////////////////////////////////////////////////////////////
103
104DEF_GM(return new SkBug1719GM;)
105
106}