| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 SkPath p; | 125 SkPath p; |
| 126 m.setTranslate(x, y); | 126 m.setTranslate(x, y); |
| 127 path->transform(m, &p); | 127 path->transform(m, &p); |
| 128 | 128 |
| 129 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; | 129 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; |
| 130 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create(
edgeType, p)); | 130 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create(
edgeType, p)); |
| 131 if (!fp) { | 131 if (!fp) { |
| 132 continue; | 132 continue; |
| 133 } | 133 } |
| 134 | 134 |
| 135 GrDrawState ds; | 135 GrPipelineBuilder pipelineBuilder; |
| 136 SkAutoTUnref<const GrGeometryProcessor> gp( | 136 SkAutoTUnref<const GrGeometryProcessor> gp( |
| 137 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory:
:kPosition_GPType, | 137 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory:
:kPosition_GPType, |
| 138 0xff000000)); | 138 0xff000000)); |
| 139 ds.addCoverageProcessor(fp); | 139 pipelineBuilder.addCoverageProcessor(fp); |
| 140 ds.setRenderTarget(rt); | 140 pipelineBuilder.setRenderTarget(rt); |
| 141 | 141 |
| 142 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer
texStride(), 0); | 142 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer
texStride(), 0); |
| 143 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 143 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 144 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); | 144 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
| 145 | 145 |
| 146 SkRect bounds = p.getBounds(); | 146 SkRect bounds = p.getBounds(); |
| 147 // Make sure any artifacts around the exterior of path are visib
le by using overly | 147 // Make sure any artifacts around the exterior of path are visib
le by using overly |
| 148 // conservative bounding geometry. | 148 // conservative bounding geometry. |
| 149 bounds.outset(5.f, 5.f); | 149 bounds.outset(5.f, 5.f); |
| 150 bounds.toQuad(verts); | 150 bounds.toQuad(verts); |
| 151 | 151 |
| 152 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); | 152 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); |
| 153 tt.target()->drawIndexed(&ds, gp, kTriangleFan_GrPrimitiveType,
0, 0, 4, 6); | 153 tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPr
imitiveType, |
| 154 0, 0, 4, 6); |
| 154 | 155 |
| 155 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); | 156 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); |
| 156 } | 157 } |
| 157 | 158 |
| 158 // Draw AA and non AA paths using normal API for reference. | 159 // Draw AA and non AA paths using normal API for reference. |
| 159 canvas->save(); | 160 canvas->save(); |
| 160 canvas->translate(x, y); | 161 canvas->translate(x, y); |
| 161 SkPaint paint; | 162 SkPaint paint; |
| 162 canvas->drawPath(*path, paint); | 163 canvas->drawPath(*path, paint); |
| 163 canvas->translate(path->getBounds().width() + 10.f, 0); | 164 canvas->translate(path->getBounds().width() + 10.f, 0); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 return; | 183 return; |
| 183 } | 184 } |
| 184 SkRect rect = *iter.get(); | 185 SkRect rect = *iter.get(); |
| 185 rect.offset(x, y); | 186 rect.offset(x, y); |
| 186 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; | 187 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; |
| 187 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create(
edgeType, rect)); | 188 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create(
edgeType, rect)); |
| 188 if (!fp) { | 189 if (!fp) { |
| 189 continue; | 190 continue; |
| 190 } | 191 } |
| 191 | 192 |
| 192 GrDrawState ds; | 193 GrPipelineBuilder pipelineBuilder; |
| 193 SkAutoTUnref<const GrGeometryProcessor> gp( | 194 SkAutoTUnref<const GrGeometryProcessor> gp( |
| 194 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory:
:kPosition_GPType, | 195 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory:
:kPosition_GPType, |
| 195 0xff000000)); | 196 0xff000000)); |
| 196 ds.addCoverageProcessor(fp); | 197 pipelineBuilder.addCoverageProcessor(fp); |
| 197 ds.setRenderTarget(rt); | 198 pipelineBuilder.setRenderTarget(rt); |
| 198 | 199 |
| 199 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer
texStride(), 0); | 200 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, gp->getVer
texStride(), 0); |
| 200 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 201 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 201 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); | 202 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
| 202 | 203 |
| 203 SkRect bounds = rect; | 204 SkRect bounds = rect; |
| 204 bounds.outset(5.f, 5.f); | 205 bounds.outset(5.f, 5.f); |
| 205 bounds.toQuad(verts); | 206 bounds.toQuad(verts); |
| 206 | 207 |
| 207 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); | 208 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer(
)); |
| 208 tt.target()->drawIndexed(&ds, gp, kTriangleFan_GrPrimitiveType,
0, 0, 4, 6); | 209 tt.target()->drawIndexed(&pipelineBuilder, gp, kTriangleFan_GrPr
imitiveType, |
| 210 0, 0, 4, 6); |
| 209 | 211 |
| 210 x += SkScalarCeilToScalar(rect.width() + 10.f); | 212 x += SkScalarCeilToScalar(rect.width() + 10.f); |
| 211 } | 213 } |
| 212 | 214 |
| 213 // Draw rect without and with AA using normal API for reference | 215 // Draw rect without and with AA using normal API for reference |
| 214 canvas->save(); | 216 canvas->save(); |
| 215 canvas->translate(x, y); | 217 canvas->translate(x, y); |
| 216 SkPaint paint; | 218 SkPaint paint; |
| 217 canvas->drawRect(*iter.get(), paint); | 219 canvas->drawRect(*iter.get(), paint); |
| 218 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); | 220 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); |
| 219 paint.setAntiAlias(true); | 221 paint.setAntiAlias(true); |
| 220 canvas->drawRect(*iter.get(), paint); | 222 canvas->drawRect(*iter.get(), paint); |
| 221 canvas->restore(); | 223 canvas->restore(); |
| 222 | 224 |
| 223 y += SkScalarCeilToScalar(iter.get()->height() + 20.f); | 225 y += SkScalarCeilToScalar(iter.get()->height() + 20.f); |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 | 228 |
| 227 private: | 229 private: |
| 228 SkTLList<SkPath> fPaths; | 230 SkTLList<SkPath> fPaths; |
| 229 SkTLList<SkRect> fRects; | 231 SkTLList<SkRect> fRects; |
| 230 | 232 |
| 231 typedef GM INHERITED; | 233 typedef GM INHERITED; |
| 232 }; | 234 }; |
| 233 | 235 |
| 234 DEF_GM( return SkNEW(ConvexPolyEffect); ) | 236 DEF_GM( return SkNEW(ConvexPolyEffect); ) |
| 235 } | 237 } |
| 236 | 238 |
| 237 #endif | 239 #endif |
| OLD | NEW |