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, 800); | 47 return make_isize(720, 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // vertically/horizontally thin rects that cover pixel centers | 93 // vertically/horizontally thin rects that cover pixel centers |
94 fRects.addToTail(SkRect::MakeLTRB(5.25f, 0.5f, 5.75f, 24.5f)); | 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)); | 95 fRects.addToTail(SkRect::MakeLTRB(5.5f, 0.5f, 29.5f, 0.75f)); |
96 // vertically/horizontally thin rects that don't cover pixel centers | 96 // vertically/horizontally thin rects that don't cover pixel centers |
97 fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f)); | 97 fRects.addToTail(SkRect::MakeLTRB(5.55f, 0.5f, 5.75f, 24.5f)); |
98 fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f)); | 98 fRects.addToTail(SkRect::MakeLTRB(5.5f, .05f, 29.5f, .25f)); |
99 // small in x and y | 99 // small in x and y |
100 fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f)); | 100 fRects.addToTail(SkRect::MakeLTRB(5.05f, .55f, 5.45f, .85f)); |
101 // inverted in x and y | 101 // inverted in x and y |
102 fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f)); | 102 fRects.addToTail(SkRect::MakeLTRB(100.f, 50.5f, 5.f, 0.5f)); |
103 | |
104 } | 103 } |
105 | 104 |
106 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 105 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
107 SkBaseDevice* device = canvas->getTopDevice(); | 106 SkBaseDevice* device = canvas->getTopDevice(); |
108 GrRenderTarget* rt = device->accessRenderTarget(); | 107 GrRenderTarget* rt = device->accessRenderTarget(); |
109 if (NULL == rt) { | 108 if (NULL == rt) { |
110 return; | 109 return; |
111 } | 110 } |
112 GrContext* context = rt->getContext(); | 111 GrContext* context = rt->getContext(); |
113 if (NULL == context) { | 112 if (NULL == context) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 SkPaint paint; | 166 SkPaint paint; |
168 canvas->drawPath(*path, paint); | 167 canvas->drawPath(*path, paint); |
169 canvas->translate(path->getBounds().width() + 10.f, 0); | 168 canvas->translate(path->getBounds().width() + 10.f, 0); |
170 paint.setAntiAlias(true); | 169 paint.setAntiAlias(true); |
171 canvas->drawPath(*path, paint); | 170 canvas->drawPath(*path, paint); |
172 canvas->restore(); | 171 canvas->restore(); |
173 | 172 |
174 y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); | 173 y += SkScalarCeilToScalar(path->getBounds().height() + 20.f); |
175 } | 174 } |
176 | 175 |
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); | 176 for (SkTLList<SkRect>::Iter iter(fRects, SkTLList<SkRect>::Iter::kHead_I
terStart); |
179 NULL != iter.get(); | 177 NULL != iter.get(); |
180 iter.next()) { | 178 iter.next()) { |
181 | 179 |
182 SkScalar x = 0; | 180 SkScalar x = 0; |
183 | 181 |
184 GrTestTarget tt; | 182 for (int et = 0; et < GrConvexPolyEffect::kEdgeTypeCnt; ++et) { |
185 context->getTestTarget(&tt); | 183 GrTestTarget tt; |
186 if (NULL == tt.target()) { | 184 context->getTestTarget(&tt); |
187 SkDEBUGFAIL("Couldn't get Gr test target."); | 185 if (NULL == tt.target()) { |
188 return; | 186 SkDEBUGFAIL("Couldn't get Gr test target."); |
| 187 return; |
| 188 } |
| 189 SkRect rect = *iter.get(); |
| 190 rect.offset(x, y); |
| 191 GrConvexPolyEffect::EdgeType edgeType = (GrConvexPolyEffect::Edg
eType) et; |
| 192 SkAutoTUnref<GrEffectRef> effect(GrConvexPolyEffect::Create(edge
Type, rect)); |
| 193 if (!effect) { |
| 194 SkDEBUGFAIL("Couldn't create convex poly effect."); |
| 195 return; |
| 196 } |
| 197 |
| 198 GrDrawState* drawState = tt.target()->drawState(); |
| 199 drawState->setVertexAttribs<kAttribs>(SK_ARRAY_COUNT(kAttribs)); |
| 200 drawState->addCoverageEffect(effect, 1); |
| 201 drawState->setIdentityViewMatrix(); |
| 202 drawState->setRenderTarget(rt); |
| 203 drawState->setColor(0xff000000); |
| 204 |
| 205 SkPoint verts[4]; |
| 206 SkRect bounds = rect; |
| 207 bounds.outset(5.f, 5.f); |
| 208 bounds.toQuad(verts); |
| 209 |
| 210 tt.target()->setVertexSourceToArray(verts, 4); |
| 211 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); |
| 212 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4,
6); |
| 213 |
| 214 x += SkScalarCeilToScalar(rect.width() + 10.f); |
189 } | 215 } |
190 | 216 |
191 SkRect rect = *iter.get(); | 217 // Draw rect without and with AA using normal API for reference |
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(); | 218 canvas->save(); |
219 canvas->translate(x, y); | 219 canvas->translate(x, y); |
220 SkPaint paint; | 220 SkPaint paint; |
| 221 canvas->drawRect(*iter.get(), paint); |
| 222 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); |
221 paint.setAntiAlias(true); | 223 paint.setAntiAlias(true); |
222 canvas->drawRect(*iter.get(), paint); | 224 canvas->drawRect(*iter.get(), paint); |
223 canvas->restore(); | 225 canvas->restore(); |
224 | 226 |
225 y += SkScalarCeilToScalar(rect.height() + 20.f); | 227 y += SkScalarCeilToScalar(iter.get()->height() + 20.f); |
226 } | 228 } |
227 } | 229 } |
228 | 230 |
229 private: | 231 private: |
230 SkTLList<SkPath> fPaths; | 232 SkTLList<SkPath> fPaths; |
231 SkTLList<SkRect> fRects; | 233 SkTLList<SkRect> fRects; |
232 | 234 |
233 typedef GM INHERITED; | 235 typedef GM INHERITED; |
234 }; | 236 }; |
235 | 237 |
236 DEF_GM( return SkNEW(ConvexPolyEffect); ) | 238 DEF_GM( return SkNEW(ConvexPolyEffect); ) |
237 } | 239 } |
238 | 240 |
239 #endif | 241 #endif |
OLD | NEW |