OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrDashingEffect.h" | 8 #include "GrDashingEffect.h" |
9 | 9 |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 SkScalar fHalfDevStroke; | 293 SkScalar fHalfDevStroke; |
294 SkScalar fDevBloatX; | 294 SkScalar fDevBloatX; |
295 SkScalar fDevBloatY; | 295 SkScalar fDevBloatY; |
296 bool fLineDone; | 296 bool fLineDone; |
297 bool fHasStartRect; | 297 bool fHasStartRect; |
298 bool fHasEndRect; | 298 bool fHasEndRect; |
299 }; | 299 }; |
300 | 300 |
301 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 301 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
302 int instanceCount = fGeoData.count(); | 302 int instanceCount = fGeoData.count(); |
| 303 SkPaint::Cap cap = this->cap(); |
| 304 bool isRoundCap = SkPaint::kRound_Cap == cap; |
| 305 DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap; |
303 | 306 |
304 SkMatrix invert; | 307 SkAutoTUnref<const GrGeometryProcessor> gp; |
305 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 308 if (this->fullDash()) { |
306 SkDebugf("Failed to invert\n"); | 309 gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, this
->viewMatrix(), |
| 310 this->usesLocalCoords())); |
| 311 } else { |
| 312 // Set up the vertex data for the line and start/end dashes |
| 313 using namespace GrDefaultGeoProcFactory; |
| 314 Color color(this->color()); |
| 315 Coverage coverage(this->coverageIgnored() ? Coverage::kNone_Type : |
| 316 Coverage::kSolid_Type); |
| 317 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP
osition_Type : |
| 318 LocalCoords::kUnus
ed_Type); |
| 319 gp.reset(CreateForDeviceSpace(color, coverage, localCoords, this->vi
ewMatrix())); |
| 320 } |
| 321 |
| 322 if (!gp) { |
| 323 SkDebugf("Could not create GrGeometryProcessor\n"); |
307 return; | 324 return; |
308 } | 325 } |
309 | 326 |
310 SkPaint::Cap cap = this->cap(); | |
311 | |
312 SkAutoTUnref<const GrGeometryProcessor> gp; | |
313 | |
314 bool isRoundCap = SkPaint::kRound_Cap == cap; | |
315 DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap; | |
316 if (this->fullDash()) { | |
317 gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, inve
rt, | |
318 this->usesLocalCoords())); | |
319 } else { | |
320 // Set up the vertex data for the line and start/end dashes | |
321 gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kP
osition_GPType, | |
322 this->color(), | |
323 this->usesLocalCoords(), | |
324 this->coverageIgnored(), | |
325 SkMatrix::I(), | |
326 invert)); | |
327 } | |
328 | |
329 batchTarget->initDraw(gp, pipeline); | 327 batchTarget->initDraw(gp, pipeline); |
330 | 328 |
331 // useAA here means Edge AA or MSAA | 329 // useAA here means Edge AA or MSAA |
332 bool useAA = this->aaMode() != kBW_DashAAMode; | 330 bool useAA = this->aaMode() != kBW_DashAAMode; |
333 bool fullDash = this->fullDash(); | 331 bool fullDash = this->fullDash(); |
334 | 332 |
335 // We do two passes over all of the dashes. First we setup the start, e
nd, and bounds, | 333 // We do two passes over all of the dashes. First we setup the start, e
nd, and bounds, |
336 // rectangles. We preserve all of this work in the rects / draws arrays
below. Then we | 334 // rectangles. We preserve all of this work in the rects / draws arrays
below. Then we |
337 // iterate again over these decomposed dashes to generate vertices | 335 // iterate again over these decomposed dashes to generate vertices |
338 SkSTArray<128, SkRect, true> rects; | 336 SkSTArray<128, SkRect, true> rects; |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 return DashingLineEffect::Create(GrRandomColor(d->fRandom), | 1200 return DashingLineEffect::Create(GrRandomColor(d->fRandom), |
1203 aaMode, GrTest::TestMatrix(d->fRandom), | 1201 aaMode, GrTest::TestMatrix(d->fRandom), |
1204 d->fRandom->nextBool()); | 1202 d->fRandom->nextBool()); |
1205 } | 1203 } |
1206 | 1204 |
1207 ////////////////////////////////////////////////////////////////////////////// | 1205 ////////////////////////////////////////////////////////////////////////////// |
1208 | 1206 |
1209 static GrGeometryProcessor* create_dash_gp(GrColor color, | 1207 static GrGeometryProcessor* create_dash_gp(GrColor color, |
1210 DashAAMode dashAAMode, | 1208 DashAAMode dashAAMode, |
1211 DashCap cap, | 1209 DashCap cap, |
1212 const SkMatrix& localMatrix, | 1210 const SkMatrix& viewMatrix, |
1213 bool usesLocalCoords) { | 1211 bool usesLocalCoords) { |
| 1212 SkMatrix invert; |
| 1213 if (usesLocalCoords && !viewMatrix.invert(&invert)) { |
| 1214 SkDebugf("Failed to invert\n"); |
| 1215 return NULL; |
| 1216 } |
| 1217 |
1214 switch (cap) { | 1218 switch (cap) { |
1215 case kRound_DashCap: | 1219 case kRound_DashCap: |
1216 return DashingCircleEffect::Create(color, dashAAMode, localMatrix, u
sesLocalCoords); | 1220 return DashingCircleEffect::Create(color, dashAAMode, invert, usesLo
calCoords); |
1217 case kNonRound_DashCap: | 1221 case kNonRound_DashCap: |
1218 return DashingLineEffect::Create(color, dashAAMode, localMatrix, use
sLocalCoords); | 1222 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca
lCoords); |
1219 default: | |
1220 SkFAIL("Unexpected dashed cap."); | |
1221 } | 1223 } |
1222 return NULL; | 1224 return NULL; |
1223 } | 1225 } |
1224 | 1226 |
1225 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 1227 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
1226 | 1228 |
1227 #ifdef GR_TEST_UTILS | 1229 #ifdef GR_TEST_UTILS |
1228 | 1230 |
1229 BATCH_TEST_DEFINE(DashBatch) { | 1231 BATCH_TEST_DEFINE(DashBatch) { |
1230 GrColor color = GrRandomColor(random); | 1232 GrColor color = GrRandomColor(random); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1295 info.fIntervals = intervals; | 1297 info.fIntervals = intervals; |
1296 info.fCount = 2; | 1298 info.fCount = 2; |
1297 info.fPhase = phase; | 1299 info.fPhase = phase; |
1298 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1300 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
1299 SkASSERT(success); | 1301 SkASSERT(success); |
1300 | 1302 |
1301 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1303 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
1302 } | 1304 } |
1303 | 1305 |
1304 #endif | 1306 #endif |
OLD | NEW |