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