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 = rrect.width() + 2 * kGap; | |
27 fTestHeight = 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::MakeWH(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 canvas->restore(); | |
102 x = x + fTestOffsetX; | |
robertphillips
2015/12/09 17:19:09
Do we need this wrap around code any more ?
bsalomon
2015/12/09 17:53:05
Done.
| |
103 if (x + fTestWidth > fWidth) { | |
104 x = kPad; | |
105 y += fTestOffsetY; | |
101 } | 106 } |
102 } | 107 } |
103 } | 108 } |
104 | 109 |
105 void setUpRRects() { | 110 private: |
106 SkScalar maxSize = SkIntToScalar(kMaxSize); | 111 // pad between test cases |
107 fRRects.push()->setRect(SkRect::MakeWH(maxSize, maxSize)); | 112 static const int kPad = 5; |
robertphillips
2015/12/09 17:19:09
cap -> gap ?
bsalomon
2015/12/09 17:53:05
Done.
| |
108 fRRects.push()->setOval(SkRect::MakeWH(maxSize, maxSize)); | 113 // cap between rect for each case that is rendered and exterior of rrect |
109 fRRects.push()->setOval(SkRect::MakeWH(maxSize - 1.f, maxSize - 10.f)); | 114 static const int kGap = 1; |
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 | 115 |
116 private: | 116 SkRRect fRRect; |
117 static const int kPad = 5; | 117 int fWidth; |
118 static const int kMaxSize = 300; | 118 int fHeight; |
119 static const int kDrawOffset = kMaxSize + kPad; | 119 int fTestWidth; |
120 | 120 int fTestHeight; |
121 static const int kImageWidth = 4 * kDrawOffset + kPad; | 121 int fTestOffsetX; |
122 static const int kImageHeight = 3 * kDrawOffset + kPad; | 122 int fTestOffsetY; |
123 | 123 const char* fName; |
124 | |
125 SkTDArray<SkRRect> fRRects; | |
126 typedef GM INHERITED; | 124 typedef GM INHERITED; |
127 }; | 125 }; |
128 | 126 |
129 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
robertphillips
2015/12/09 17:19:09
// This value is motivated by bug XXX. It has to b
bsalomon
2015/12/09 17:53:05
Done.
| |
128 static const int kSize = 700; | |
130 | 129 |
131 DEF_GM( return new BigRRectAAEffectGM (); ) | 130 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRect(SkRect::MakeWH(kSize, k Size)), "rect"); ) |
131 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeWH(kSize, k Size)), "circle"); ) | |
132 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeOval(SkRect::MakeWH(kSize - 1.f, kSize - 10.f)), "ellipse"); ) | |
robertphillips
2015/12/09 17:19:09
// The next two have small linear segments between
bsalomon
2015/12/09 17:53:05
Done.
| |
133 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeWH(kSize - 1.f, kSize - 10.f), kSize/2.f - 10.f, kSize/2.f - 10.f), "circular_corner"); ) | |
134 DEF_GM( return new BigRRectAAEffectGM (SkRRect::MakeRectXY(SkRect::MakeWH(kSize - 1.f, kSize - 10.f), kSize/2.f - 10.f, kSize/2.f - 15.f), "elliptical_corner"); ) | |
132 | 135 |
133 } | 136 } |
134 #endif | 137 #endif |
OLD | NEW |