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 "GrAADistanceFieldPathRenderer.h" | 8 #include "GrAADistanceFieldPathRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 SkPath fPath; | 141 SkPath fPath; |
142 // The unique ID of the path involved in this draw. This may be differen
t than the ID | 142 // The unique ID of the path involved in this draw. This may be differen
t than the ID |
143 // in fPath since that path may have resulted from a SkStrokeRec::applyT
oPath call. | 143 // in fPath since that path may have resulted from a SkStrokeRec::applyT
oPath call. |
144 uint32_t fGenID; | 144 uint32_t fGenID; |
145 SkStrokeRec fStroke; | 145 SkStrokeRec fStroke; |
146 GrColor fColor; | 146 GrColor fColor; |
147 bool fAntiAlias; | 147 bool fAntiAlias; |
148 }; | 148 }; |
149 | 149 |
150 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix, | 150 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix, |
151 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList) { | 151 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList, |
152 return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, pathCac
he, pathList); | 152 bool srgbOutput) { |
| 153 return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, pathCac
he, pathList, |
| 154 srgbOutput); |
153 } | 155 } |
154 | 156 |
155 const char* name() const override { return "AADistanceFieldPathBatch"; } | 157 const char* name() const override { return "AADistanceFieldPathBatch"; } |
156 | 158 |
157 void computePipelineOptimizations(GrInitInvariantOutput* color, | 159 void computePipelineOptimizations(GrInitInvariantOutput* color, |
158 GrInitInvariantOutput* coverage, | 160 GrInitInvariantOutput* coverage, |
159 GrBatchToXPOverrides* overrides) const ove
rride { | 161 GrBatchToXPOverrides* overrides) const ove
rride { |
160 color->setKnownFourComponents(fGeoData[0].fColor); | 162 color->setKnownFourComponents(fGeoData[0].fColor); |
161 coverage->setUnknownSingleComponent(); | 163 coverage->setUnknownSingleComponent(); |
162 } | 164 } |
(...skipping 26 matching lines...) Expand all Loading... |
189 SkMatrix invert; | 191 SkMatrix invert; |
190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 192 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
191 SkDebugf("Could not invert viewmatrix\n"); | 193 SkDebugf("Could not invert viewmatrix\n"); |
192 return; | 194 return; |
193 } | 195 } |
194 | 196 |
195 const SkMatrix& ctm = this->viewMatrix(); | 197 const SkMatrix& ctm = this->viewMatrix(); |
196 uint32_t flags = 0; | 198 uint32_t flags = 0; |
197 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0
; | 199 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0
; |
198 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; | 200 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 201 flags |= fSRGBOutput ? kSRGB_DistanceFieldEffectFlag : 0; |
199 | 202 |
200 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); | 203 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); |
201 | 204 |
202 FlushInfo flushInfo; | 205 FlushInfo flushInfo; |
203 | 206 |
204 // Setup GrGeometryProcessor | 207 // Setup GrGeometryProcessor |
205 GrBatchAtlas* atlas = fAtlas; | 208 GrBatchAtlas* atlas = fAtlas; |
206 flushInfo.fGeometryProcessor.reset( | 209 flushInfo.fGeometryProcessor.reset( |
207 GrDistanceFieldPathGeoProc::Create(this->color(), | 210 GrDistanceFieldPathGeoProc::Create(this->color(), |
208 this->viewMatrix(), | 211 this->viewMatrix(), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 292 } |
290 | 293 |
291 this->flush(target, &flushInfo); | 294 this->flush(target, &flushInfo); |
292 } | 295 } |
293 | 296 |
294 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 297 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
295 | 298 |
296 AADistanceFieldPathBatch(const Geometry& geometry, | 299 AADistanceFieldPathBatch(const Geometry& geometry, |
297 const SkMatrix& viewMatrix, | 300 const SkMatrix& viewMatrix, |
298 GrBatchAtlas* atlas, | 301 GrBatchAtlas* atlas, |
299 PathCache* pathCache, PathDataList* pathList) | 302 PathCache* pathCache, PathDataList* pathList, |
| 303 bool srgbOutput) |
300 : INHERITED(ClassID()) { | 304 : INHERITED(ClassID()) { |
301 fBatch.fViewMatrix = viewMatrix; | 305 fBatch.fViewMatrix = viewMatrix; |
302 fGeoData.push_back(geometry); | 306 fGeoData.push_back(geometry); |
303 | 307 |
304 fAtlas = atlas; | 308 fAtlas = atlas; |
305 fPathCache = pathCache; | 309 fPathCache = pathCache; |
306 fPathList = pathList; | 310 fPathList = pathList; |
| 311 fSRGBOutput = srgbOutput; |
307 | 312 |
308 // Compute bounds | 313 // Compute bounds |
309 fBounds = geometry.fPath.getBounds(); | 314 fBounds = geometry.fPath.getBounds(); |
310 viewMatrix.mapRect(&fBounds); | 315 viewMatrix.mapRect(&fBounds); |
311 } | 316 } |
312 | 317 |
313 bool addPathToAtlas(GrVertexBatch::Target* target, | 318 bool addPathToAtlas(GrVertexBatch::Target* target, |
314 FlushInfo* flushInfo, | 319 FlushInfo* flushInfo, |
315 GrBatchAtlas* atlas, | 320 GrBatchAtlas* atlas, |
316 PathData* pathData, | 321 PathData* pathData, |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 bool fUsesLocalCoords; | 522 bool fUsesLocalCoords; |
518 bool fColorIgnored; | 523 bool fColorIgnored; |
519 bool fCoverageIgnored; | 524 bool fCoverageIgnored; |
520 }; | 525 }; |
521 | 526 |
522 BatchTracker fBatch; | 527 BatchTracker fBatch; |
523 SkSTArray<1, Geometry, true> fGeoData; | 528 SkSTArray<1, Geometry, true> fGeoData; |
524 GrBatchAtlas* fAtlas; | 529 GrBatchAtlas* fAtlas; |
525 PathCache* fPathCache; | 530 PathCache* fPathCache; |
526 PathDataList* fPathList; | 531 PathDataList* fPathList; |
| 532 bool fSRGBOutput; |
527 | 533 |
528 typedef GrVertexBatch INHERITED; | 534 typedef GrVertexBatch INHERITED; |
529 }; | 535 }; |
530 | 536 |
531 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { | 537 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { |
532 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 538 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
533 "GrAADistanceFieldPathRenderer::onDrawPath"); | 539 "GrAADistanceFieldPathRenderer::onDrawPath"); |
534 // we've already bailed on inverse filled paths, so this is safe | 540 // we've already bailed on inverse filled paths, so this is safe |
535 if (args.fPath->isEmpty()) { | 541 if (args.fPath->isEmpty()) { |
536 return true; | 542 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
553 } else { | 559 } else { |
554 args.fStroke->applyToPath(&geometry.fPath, *args.fPath); | 560 args.fStroke->applyToPath(&geometry.fPath, *args.fPath); |
555 } | 561 } |
556 geometry.fColor = args.fColor; | 562 geometry.fColor = args.fColor; |
557 geometry.fAntiAlias = args.fAntiAlias; | 563 geometry.fAntiAlias = args.fAntiAlias; |
558 // Note: this is the generation ID of the _original_ path. When a new path i
s | 564 // Note: this is the generation ID of the _original_ path. When a new path i
s |
559 // generated due to stroking it is important that the original path's id is
used | 565 // generated due to stroking it is important that the original path's id is
used |
560 // for caching. | 566 // for caching. |
561 geometry.fGenID = args.fPath->getGenerationID(); | 567 geometry.fGenID = args.fPath->getGenerationID(); |
562 | 568 |
| 569 bool srgbOutput = GrPixelConfigIsSRGB(args.fTarget->config()) && |
| 570 !args.fPipelineBuilder->getDisableOutputConversionToSRGB(); |
| 571 |
563 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, | 572 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, |
564 *args.fView
Matrix, fAtlas, | 573 *args.fView
Matrix, fAtlas, |
565 &fPathCache
, &fPathList)); | 574 &fPathCache
, &fPathList, |
| 575 srgbOutput)
); |
566 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); | 576 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
567 | 577 |
568 return true; | 578 return true; |
569 } | 579 } |
570 | 580 |
571 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 581 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
572 | 582 |
573 #ifdef GR_TEST_UTILS | 583 #ifdef GR_TEST_UTILS |
574 | 584 |
575 struct PathTestStruct { | 585 struct PathTestStruct { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 640 |
631 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 641 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
632 GrColor color = GrRandomColor(random); | 642 GrColor color = GrRandomColor(random); |
633 | 643 |
634 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); | 644 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); |
635 geometry.fColor = color; | 645 geometry.fColor = color; |
636 geometry.fPath = GrTest::TestPath(random); | 646 geometry.fPath = GrTest::TestPath(random); |
637 geometry.fAntiAlias = random->nextBool(); | 647 geometry.fAntiAlias = random->nextBool(); |
638 geometry.fGenID = random->nextU(); | 648 geometry.fGenID = random->nextU(); |
639 | 649 |
| 650 bool srgbOutput = random->nextBool(); |
| 651 |
640 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 652 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
641 gTestStruct.fAtlas, | 653 gTestStruct.fAtlas, |
642 &gTestStruct.fPathCache, | 654 &gTestStruct.fPathCache, |
643 &gTestStruct.fPathList); | 655 &gTestStruct.fPathList, |
| 656 srgbOutput); |
644 } | 657 } |
645 | 658 |
646 #endif | 659 #endif |
OLD | NEW |