OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 // This test only works with the GPU backend. | 9 // This test only works with the GPU backend. |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 ConvexPolyEffect() { | 37 ConvexPolyEffect() { |
38 this->setBGColor(0xFFFFFFFF); | 38 this->setBGColor(0xFFFFFFFF); |
39 } | 39 } |
40 | 40 |
41 protected: | 41 protected: |
42 virtual SkString onShortName() SK_OVERRIDE { | 42 virtual SkString onShortName() SK_OVERRIDE { |
43 return SkString("convex_poly_effect"); | 43 return SkString("convex_poly_effect"); |
44 } | 44 } |
45 | 45 |
46 virtual SkISize onISize() SK_OVERRIDE { | 46 virtual SkISize onISize() SK_OVERRIDE { |
47 return make_isize(475, 530); | 47 return make_isize(475, 800); |
48 } | 48 } |
49 | 49 |
50 virtual uint32_t onGetFlags() const SK_OVERRIDE { | 50 virtual uint32_t onGetFlags() const SK_OVERRIDE { |
51 // This is a GPU-specific GM. | 51 // This is a GPU-specific GM. |
52 return kGPUOnly_Flag; | 52 return kGPUOnly_Flag; |
53 } | 53 } |
54 | 54 |
55 virtual void onOnceBeforeDraw() SK_OVERRIDE { | 55 virtual void onOnceBeforeDraw() SK_OVERRIDE { |
56 SkPath tri; | 56 SkPath tri; |
57 tri.moveTo(5.f, 5.f); | 57 tri.moveTo(5.f, 5.f); |
(...skipping 20 matching lines...) Expand all Loading... |
78 } else { | 78 } else { |
79 ngon.lineTo(point); | 79 ngon.lineTo(point); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 fPaths.addToTail(ngon); | 83 fPaths.addToTail(ngon); |
84 SkMatrix scaleM; | 84 SkMatrix scaleM; |
85 scaleM.setScale(1.1f, 0.4f); | 85 scaleM.setScale(1.1f, 0.4f); |
86 ngon.transform(scaleM); | 86 ngon.transform(scaleM); |
87 fPaths.addToTail(ngon); | 87 fPaths.addToTail(ngon); |
| 88 |
| 89 // integer edges |
| 90 fRects.addToTail(SkRect::MakeLTRB(5.f, 1.f, 30.f, 25.f)); |
| 91 // half-integer edges |
| 92 fRects.addToTail(SkRect::MakeLTRB(5.5f, 0.5f, 29.5f, 24.5f)); |
| 93 // vertically/horizontally thin rects that cover pixel centers |
| 94 fRects.addToTail(SkRect::MakeLTRB(5.25f, 0.5f, 5.75f, 24.5f)); |
| 95 fRects.addToTail(SkRect::MakeLTRB(5.5f, 0.5f, 29.5f, 0.75f)); |
| 96 // vertically/horizontally thin rects that don't cover pixel centers |
| 97 fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f)); |
| 98 fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f)); |
| 99 // small in x and y |
| 100 fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f)); |
| 101 // inverted in x and y |
| 102 fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f)); |
| 103 |
88 } | 104 } |
89 | 105 |
90 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 106 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
91 SkBaseDevice* device = canvas->getTopDevice(); | 107 SkBaseDevice* device = canvas->getTopDevice(); |
92 GrRenderTarget* rt = device->accessRenderTarget(); | 108 GrRenderTarget* rt = device->accessRenderTarget(); |
93 if (NULL == rt) { | 109 if (NULL == rt) { |
94 return; | 110 return; |
95 } | 111 } |
96 GrContext* context = rt->getContext(); | 112 GrContext* context = rt->getContext(); |
97 if (NULL == context) { | 113 if (NULL == context) { |
98 return; | 114 return; |
99 } | 115 } |
100 | 116 |
101 const SkPath* path; | |
102 SkScalar y = 0; | 117 SkScalar y = 0; |
103 for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_I
terStart); | 118 for (SkTLList<SkPath>::Iter iter(fPaths, SkTLList<SkPath>::Iter::kHead_I
terStart); |
104 NULL != (path = iter.get()); | 119 NULL != iter.get(); |
105 iter.next()) { | 120 iter.next()) { |
| 121 const SkPath* path = iter.get(); |
106 SkScalar x = 0; | 122 SkScalar x = 0; |
107 | 123 |
108 for (int et = 0; et < GrConvexPolyEffect::kEdgeTypeCnt; ++et) { | 124 for (int et = 0; et < GrConvexPolyEffect::kEdgeTypeCnt; ++et) { |
109 GrTestTarget tt; | 125 GrTestTarget tt; |
110 context->getTestTarget(&tt); | 126 context->getTestTarget(&tt); |
111 if (NULL == tt.target()) { | 127 if (NULL == tt.target()) { |
112 SkDEBUGFAIL("Couldn't get Gr test target."); | 128 SkDEBUGFAIL("Couldn't get Gr test target."); |
113 return; | 129 return; |
114 } | 130 } |
115 GrDrawState* drawState = tt.target()->drawState(); | 131 GrDrawState* drawState = tt.target()->drawState(); |
(...skipping 19 matching lines...) Expand all Loading... |
135 SkRect bounds = p.getBounds(); | 151 SkRect bounds = p.getBounds(); |
136 // Make sure any artifacts around the exterior of path are visib
le by using overly | 152 // Make sure any artifacts around the exterior of path are visib
le by using overly |
137 // conservative bounding geometry. | 153 // conservative bounding geometry. |
138 bounds.outset(5.f, 5.f); | 154 bounds.outset(5.f, 5.f); |
139 bounds.toQuad(verts); | 155 bounds.toQuad(verts); |
140 | 156 |
141 tt.target()->setVertexSourceToArray(verts, 4); | 157 tt.target()->setVertexSourceToArray(verts, 4); |
142 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); | 158 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); |
143 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4,
6); | 159 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4,
6); |
144 | 160 |
145 x += path->getBounds().width() + 10.f; | 161 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); |
146 } | 162 } |
147 | 163 |
148 // Draw AA and non AA paths using normal API for reference. | 164 // Draw AA and non AA paths using normal API for reference. |
149 canvas->save(); | 165 canvas->save(); |
150 canvas->translate(x, y); | 166 canvas->translate(x, y); |
151 SkPaint paint; | 167 SkPaint paint; |
152 canvas->drawPath(*path, paint); | 168 canvas->drawPath(*path, paint); |
153 canvas->translate(path->getBounds().width() + 10.f, 0); | 169 canvas->translate(path->getBounds().width() + 10.f, 0); |
154 paint.setAntiAlias(true); | 170 paint.setAntiAlias(true); |
155 canvas->drawPath(*path, paint); | 171 canvas->drawPath(*path, paint); |
156 canvas->restore(); | 172 canvas->restore(); |
157 | 173 |
158 y += path->getBounds().height() + 20.f; | 174 y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); |
| 175 } |
| 176 |
| 177 // Draw rects. We only have specialized effect code for the AA case, so
don't do non-AA. |
| 178 for (SkTLList<SkRect>::Iter iter(fRects, SkTLList<SkRect>::Iter::kHead_I
terStart); |
| 179 NULL != iter.get(); |
| 180 iter.next()) { |
| 181 |
| 182 SkScalar x = 0; |
| 183 |
| 184 GrTestTarget tt; |
| 185 context->getTestTarget(&tt); |
| 186 if (NULL == tt.target()) { |
| 187 SkDEBUGFAIL("Couldn't get Gr test target."); |
| 188 return; |
| 189 } |
| 190 |
| 191 SkRect rect = *iter.get(); |
| 192 rect.offset(x, y); |
| 193 SkAutoTUnref<GrEffectRef> effect(GrConvexPolyEffect::CreateForAAFill
Rect(rect)); |
| 194 if (!effect) { |
| 195 SkDEBUGFAIL("Couldn't create convex poly effect."); |
| 196 return; |
| 197 } |
| 198 |
| 199 GrDrawState* drawState = tt.target()->drawState(); |
| 200 drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs)); |
| 201 drawState->addCoverageEffect(effect, 1); |
| 202 drawState->setIdentityViewMatrix(); |
| 203 drawState->setRenderTarget(rt); |
| 204 drawState->setColor(0xff000000); |
| 205 |
| 206 SkPoint verts[4]; |
| 207 SkRect bounds = rect; |
| 208 bounds.outset(5.f, 5.f); |
| 209 bounds.toQuad(verts); |
| 210 |
| 211 tt.target()->setVertexSourceToArray(verts, 4); |
| 212 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer()); |
| 213 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4, 6); |
| 214 |
| 215 x += SkScalarCeilToScalar(rect.width() + 10.f); |
| 216 |
| 217 // Draw AA rect using normal API for reference |
| 218 canvas->save(); |
| 219 canvas->translate(x, y); |
| 220 SkPaint paint; |
| 221 paint.setAntiAlias(true); |
| 222 canvas->drawRect(*iter.get(), paint); |
| 223 canvas->restore(); |
| 224 |
| 225 y += SkScalarCeilToScalar(rect.height() + 20.f); |
159 } | 226 } |
160 } | 227 } |
161 | 228 |
162 private: | 229 private: |
163 SkTLList<SkPath> fPaths; | 230 SkTLList<SkPath> fPaths; |
164 | 231 SkTLList<SkRect> fRects; |
| 232 |
165 typedef GM INHERITED; | 233 typedef GM INHERITED; |
166 }; | 234 }; |
167 | 235 |
168 DEF_GM( return SkNEW(ConvexPolyEffect); ) | 236 DEF_GM( return SkNEW(ConvexPolyEffect); ) |
169 | |
170 } | 237 } |
171 | 238 |
172 #endif | 239 #endif |
OLD | NEW |