OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrTest.h" | 10 #include "GrTest.h" |
11 #include "effects/GrRRectEffect.h" | 11 #include "effects/GrRRectEffect.h" |
12 #include "SkDevice.h" | 12 #include "SkDevice.h" |
13 #include "SkRRect.h" | 13 #include "SkRRect.h" |
14 | 14 |
15 namespace skiagm { | 15 namespace skiagm { |
16 | 16 |
17 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
18 | 18 |
19 class BigRRectAAEffectGM : public GM { | 19 class BigRRectAAEffectGM : public GM { |
20 public: | 20 public: |
21 BigRRectAAEffectGM() { | 21 BigRRectAAEffectGM(const SkRRect& rrect, const char* name) |
22 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 22 : fRRect(rrect) |
23 this->setUpRRects(); | 23 , fName(name) { |
| 24 this->setBGColor(sk_tool_utils::color_to_565(SK_ColorBLUE)); |
| 25 // Each test case draws the rrect with gaps around it. |
| 26 fTestWidth = SkScalarCeilToInt(rrect.width()) + 2 * kGap; |
| 27 fTestHeight = SkScalarCeilToInt(rrect.height()) + 2 * kGap; |
| 28 |
| 29 // Add a pad between test cases. |
| 30 fTestOffsetX = fTestWidth + kPad; |
| 31 fTestOffsetY = fTestHeight + kPad; |
| 32 |
| 33 // We draw two tests in x (fill and inv-fill) and pad around |
| 34 // all four sides of the image. |
| 35 fWidth = 2 * fTestOffsetX + kPad; |
| 36 fHeight = fTestOffsetY + kPad; |
24 } | 37 } |
25 | 38 |
26 protected: | 39 protected: |
27 SkString onShortName() override { | 40 SkString onShortName() override { |
28 return SkString("big_rrect_aa_effect"); | 41 SkString name; |
| 42 name.printf("big_rrect_%s_aa_effect", fName); |
| 43 return name; |
29 } | 44 } |
30 | 45 |
31 SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight)
; } | 46 SkISize onISize() override { return SkISize::Make(fWidth, fHeight); } |
32 | 47 |
33 void onDraw(SkCanvas* canvas) override { | 48 void onDraw(SkCanvas* canvas) override { |
34 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); | 49 GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget
(); |
35 GrContext* context = rt ? rt->getContext() : nullptr; | 50 GrContext* context = rt ? rt->getContext() : nullptr; |
36 if (!context) { | 51 if (!context) { |
37 skiagm::GM::DrawGpuOnlyMessage(canvas); | 52 skiagm::GM::DrawGpuOnlyMessage(canvas); |
38 return; | 53 return; |
39 } | 54 } |
40 | 55 |
41 SkPaint paint; | 56 SkPaint paint; |
42 | 57 |
43 #ifdef SK_DEBUG | |
44 static const SkRect kMaxRRectBound = SkRect::MakeWH(SkIntToScalar(kMaxSi
ze), | |
45 SkIntToScalar(kMaxSi
ze)); | |
46 static const SkRect kMaxImageBound = SkRect::MakeWH(SkIntToScalar(kImage
Width), | |
47 SkIntToScalar(kImage
Height)); | |
48 #endif | |
49 | |
50 int y = kPad; | 58 int y = kPad; |
51 int x = kPad; | 59 int x = kPad; |
52 static const GrPrimitiveEdgeType kEdgeTypes[] = { | 60 static const GrPrimitiveEdgeType kEdgeTypes[] = { |
53 kFillAA_GrProcessorEdgeType, | 61 kFillAA_GrProcessorEdgeType, |
54 kInverseFillAA_GrProcessorEdgeType, | 62 kInverseFillAA_GrProcessorEdgeType, |
55 }; | 63 }; |
| 64 SkRect testBounds = SkRect::MakeIWH(fTestWidth, fTestHeight); |
56 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) { | 65 for (size_t et = 0; et < SK_ARRAY_COUNT(kEdgeTypes); ++et) { |
57 GrPrimitiveEdgeType edgeType = kEdgeTypes[et]; | 66 GrPrimitiveEdgeType edgeType = kEdgeTypes[et]; |
58 for (int curRRect = 0; curRRect < fRRects.count(); ++curRRect) { | 67 canvas->save(); |
59 #ifdef SK_DEBUG | 68 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
60 SkASSERT(kMaxRRectBound.contains(fRRects[curRRect].getBounds()))
; | |
61 SkRect imageSpaceBounds = fRRects[curRRect].getBounds(); | |
62 imageSpaceBounds.offset(SkIntToScalar(x), SkIntToScalar(y)); | |
63 SkASSERT(kMaxImageBound.contains(imageSpaceBounds)); | |
64 #endif | |
65 canvas->save(); | |
66 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | |
67 GrTestTarget tt; | |
68 context->getTestTarget(&tt, rt); | |
69 if (nullptr == tt.target()) { | |
70 SkDEBUGFAIL("Couldn't get Gr test target."); | |
71 return; | |
72 } | |
73 GrPipelineBuilder pipelineBuilder; | |
74 pipelineBuilder.setXPFactory( | |
75 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->u
nref(); | |
76 | 69 |
77 SkRRect rrect = fRRects[curRRect]; | 70 // Draw a background for the test case |
78 rrect.offset(SkIntToScalar(x), SkIntToScalar(y)); | 71 SkPaint paint; |
79 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(e
dgeType, rrect)); | 72 paint.setColor(SK_ColorWHITE); |
80 SkASSERT(fp); | 73 canvas->drawRect(testBounds, paint); |
81 if (fp) { | |
82 pipelineBuilder.addCoverageFragmentProcessor(fp); | |
83 pipelineBuilder.setRenderTarget(rt); | |
84 | 74 |
85 SkRect bounds = SkRect::MakeWH(SkIntToScalar(kMaxSize), | 75 GrTestTarget tt; |
86 SkIntToScalar(kMaxSize)); | 76 context->getTestTarget(&tt, rt); |
87 bounds.outset(2.f, 2.f); | 77 if (!tt.target()) { |
88 bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); | 78 SkDEBUGFAIL("Couldn't get Gr test target."); |
| 79 return; |
| 80 } |
| 81 GrPipelineBuilder pipelineBuilder; |
| 82 pipelineBuilder.setXPFactory( |
| 83 GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref
(); |
89 | 84 |
90 tt.target()->drawNonAARect(pipelineBuilder, | 85 SkRRect rrect = fRRect; |
91 0xff000000, | 86 rrect.offset(SkIntToScalar(x + kGap), SkIntToScalar(y + kGap)); |
92 SkMatrix::I(), | 87 SkAutoTUnref<GrFragmentProcessor> fp(GrRRectEffect::Create(edgeT
ype, rrect)); |
93 bounds); | 88 SkASSERT(fp); |
94 } | 89 if (fp) { |
95 canvas->restore(); | 90 pipelineBuilder.addCoverageFragmentProcessor(fp); |
96 x = x + kDrawOffset; | 91 pipelineBuilder.setRenderTarget(rt); |
97 if (x + kMaxSize> kImageWidth) { | 92 |
98 x = kPad; | 93 SkRect bounds = testBounds; |
99 y += kDrawOffset; | 94 bounds.offset(SkIntToScalar(x), SkIntToScalar(y)); |
| 95 |
| 96 tt.target()->drawNonAARect(pipelineBuilder, |
| 97 0xff000000, |
| 98 SkMatrix::I(), |
| 99 bounds); |
100 } | 100 } |
101 } | 101 canvas->restore(); |
| 102 x = x + fTestOffsetX; |
102 } | 103 } |
103 } | 104 } |
104 | 105 |
105 void setUpRRects() { | 106 private: |
106 SkScalar maxSize = SkIntToScalar(kMaxSize); | 107 // pad between test cases |
107 fRRects.push()->setRect(SkRect::MakeWH(maxSize, maxSize)); | 108 static const int kPad = 7; |
108 fRRects.push()->setOval(SkRect::MakeWH(maxSize, maxSize)); | 109 // gap between rect for each case that is rendered and exterior of rrect |
109 fRRects.push()->setOval(SkRect::MakeWH(maxSize - 1.f, maxSize - 10.f)); | 110 static const int kGap = 3; |
110 fRRects.push()->setRectXY(SkRect::MakeWH(maxSize - 1.f, maxSize - 10.f), | |
111 maxSize/2.f - 10.f, maxSize/2.f - 10.f); | |
112 fRRects.push()->setRectXY(SkRect::MakeWH(maxSize - 1.f, maxSize - 10), | |
113 maxSize/2.f - 10.f, maxSize/2.f - 20.f); | |
114 } | |
115 | 111 |
116 private: | 112 SkRRect fRRect; |
117 static const int kPad = 5; | 113 int fWidth; |
118 static const int kMaxSize = 300; | 114 int fHeight; |
119 static const int kDrawOffset = kMaxSize + kPad; | 115 int fTestWidth; |
120 | 116 int fTestHeight; |
121 static const int kImageWidth = 4 * kDrawOffset + kPad; | 117 int fTestOffsetX; |
122 static const int kImageHeight = 3 * kDrawOffset + kPad; | 118 int fTestOffsetY; |
123 | 119 const char* fName; |
124 | |
125 SkTDArray<SkRRect> fRRects; | |
126 typedef GM INHERITED; | 120 typedef GM INHERITED; |
127 }; | 121 }; |
128 | 122 |
129 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
| 124 // This value is motivated by bug chromium:477684. It has to be large to cause o
verflow in |
| 125 // the shader |
| 126 static const int kSize = 700; |
130 | 127 |
131 DEF_GM( return new BigRRectAAEffectGM (); ) | 128 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeIWH(kSize,
kSize)), "rect"); ) |
| 129 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize,
kSize)), "circle"); ) |
| 130 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeIWH(kSize -
1, kSize - 10)), "ellipse"); ) |
| 131 // The next two have small linear segments between the corners |
| 132 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize
- 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 10.f), "circular_corner"); ) |
| 133 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeIWH(kSize
- 1, kSize - 10), kSize/2.f - 10.f, kSize/2.f - 15.f), "elliptical_corner"); ) |
132 | 134 |
133 } | 135 } |
134 #endif | 136 #endif |
OLD | NEW |