OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
9 #include "GrBatch.h" | 9 #include "GrBatch.h" |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 }; | 306 }; |
307 | 307 |
308 namespace { | 308 namespace { |
309 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 309 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
310 enum CoverageAttribType { | 310 enum CoverageAttribType { |
311 kUseColor_CoverageAttribType, | 311 kUseColor_CoverageAttribType, |
312 kUseCoverage_CoverageAttribType, | 312 kUseCoverage_CoverageAttribType, |
313 }; | 313 }; |
314 } | 314 } |
315 | 315 |
316 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, | 316 void GrAARectRenderer::GeometryFillAARect(GrDrawTarget* target, |
317 GrPipelineBuilder* pipelineBuilder, | 317 GrPipelineBuilder* pipelineBuilder, |
318 GrColor color, | 318 GrColor color, |
319 const SkMatrix& viewMatrix, | 319 const SkMatrix& viewMatrix, |
320 const SkRect& rect, | 320 const SkRect& rect, |
321 const SkRect& devRect) { | 321 const SkRect& devRect) { |
322 AAFillRectBatch::Geometry geometry; | 322 AAFillRectBatch::Geometry geometry; |
323 geometry.fRect = rect; | 323 geometry.fRect = rect; |
324 geometry.fViewMatrix = viewMatrix; | 324 geometry.fViewMatrix = viewMatrix; |
325 geometry.fDevRect = devRect; | 325 geometry.fDevRect = devRect; |
326 geometry.fColor = color; | 326 geometry.fColor = color; |
327 | 327 |
328 | 328 |
329 SkAutoTUnref<GrBatch> batch(AAFillRectBatch::Create(geometry)); | 329 SkAutoTUnref<GrBatch> batch(AAFillRectBatch::Create(geometry)); |
330 target->drawBatch(pipelineBuilder, batch); | 330 target->drawBatch(pipelineBuilder, batch); |
331 } | 331 } |
332 | 332 |
333 void GrAARectRenderer::strokeAARect(GrDrawTarget* target, | 333 void GrAARectRenderer::StrokeAARect(GrDrawTarget* target, |
334 GrPipelineBuilder* pipelineBuilder, | 334 GrPipelineBuilder* pipelineBuilder, |
335 GrColor color, | 335 GrColor color, |
336 const SkMatrix& viewMatrix, | 336 const SkMatrix& viewMatrix, |
337 const SkRect& rect, | 337 const SkRect& rect, |
338 const SkRect& devRect, | 338 const SkRect& devRect, |
339 const SkStrokeRec& stroke) { | 339 const SkStrokeRec& stroke) { |
340 SkVector devStrokeSize; | 340 SkVector devStrokeSize; |
341 SkScalar width = stroke.getWidth(); | 341 SkScalar width = stroke.getWidth(); |
342 if (width > 0) { | 342 if (width > 0) { |
343 devStrokeSize.set(width, width); | 343 devStrokeSize.set(width, width); |
(...skipping 20 matching lines...) Expand all Loading... |
364 | 364 |
365 bool miterStroke = true; | 365 bool miterStroke = true; |
366 // For hairlines, make bevel and round joins appear the same as mitered ones
. | 366 // For hairlines, make bevel and round joins appear the same as mitered ones
. |
367 // small miter limit means right angles show bevel... | 367 // small miter limit means right angles show bevel... |
368 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || | 368 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || |
369 stroke.getMiter() < SK_ScalarSqrt2)) { | 369 stroke.getMiter() < SK_ScalarSqrt2)) { |
370 miterStroke = false; | 370 miterStroke = false; |
371 } | 371 } |
372 | 372 |
373 if (spare <= 0 && miterStroke) { | 373 if (spare <= 0 && miterStroke) { |
374 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); | 374 FillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, devOu
tside); |
375 return; | 375 return; |
376 } | 376 } |
377 | 377 |
378 SkRect devInside(devRect); | 378 SkRect devInside(devRect); |
379 devInside.inset(rx, ry); | 379 devInside.inset(rx, ry); |
380 | 380 |
381 SkRect devOutsideAssist(devRect); | 381 SkRect devOutsideAssist(devRect); |
382 | 382 |
383 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) | 383 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) |
384 // to draw the outer of the rect. Because there are 8 vertices on the outer | 384 // to draw the outer of the rect. Because there are 8 vertices on the outer |
385 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | 385 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
386 if (!miterStroke) { | 386 if (!miterStroke) { |
387 devOutside.inset(0, ry); | 387 devOutside.inset(0, ry); |
388 devOutsideAssist.outset(0, ry); | 388 devOutsideAssist.outset(0, ry); |
389 } | 389 } |
390 | 390 |
391 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, | 391 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside, |
392 devOutsideAssist, devInside, miterStroke); | 392 devOutsideAssist, devInside, miterStroke); |
393 } | 393 } |
394 | 394 |
395 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); | 395 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); |
396 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); | 396 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); |
397 | 397 |
398 class AAStrokeRectBatch : public GrBatch { | 398 class AAStrokeRectBatch : public GrBatch { |
399 public: | 399 public: |
400 // TODO support AA rotated stroke rects by copying around view matrices | 400 // TODO support AA rotated stroke rects by copying around view matrices |
401 struct Geometry { | 401 struct Geometry { |
402 GrColor fColor; | 402 GrColor fColor; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 bool fColorIgnored; | 766 bool fColorIgnored; |
767 bool fCoverageIgnored; | 767 bool fCoverageIgnored; |
768 bool fMiterStroke; | 768 bool fMiterStroke; |
769 bool fCanTweakAlphaForCoverage; | 769 bool fCanTweakAlphaForCoverage; |
770 }; | 770 }; |
771 | 771 |
772 BatchTracker fBatch; | 772 BatchTracker fBatch; |
773 SkSTArray<1, Geometry, true> fGeoData; | 773 SkSTArray<1, Geometry, true> fGeoData; |
774 }; | 774 }; |
775 | 775 |
776 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, | 776 void GrAARectRenderer::GeometryStrokeAARect(GrDrawTarget* target, |
777 GrPipelineBuilder* pipelineBuilder, | 777 GrPipelineBuilder* pipelineBuilder, |
778 GrColor color, | 778 GrColor color, |
779 const SkMatrix& viewMatrix, | 779 const SkMatrix& viewMatrix, |
780 const SkRect& devOutside, | 780 const SkRect& devOutside, |
781 const SkRect& devOutsideAssist, | 781 const SkRect& devOutsideAssist, |
782 const SkRect& devInside, | 782 const SkRect& devInside, |
783 bool miterStroke) { | 783 bool miterStroke) { |
784 AAStrokeRectBatch::Geometry geometry; | 784 AAStrokeRectBatch::Geometry geometry; |
785 geometry.fColor = color; | 785 geometry.fColor = color; |
786 geometry.fDevOutside = devOutside; | 786 geometry.fDevOutside = devOutside; |
787 geometry.fDevOutsideAssist = devOutsideAssist; | 787 geometry.fDevOutsideAssist = devOutsideAssist; |
788 geometry.fDevInside = devInside; | 788 geometry.fDevInside = devInside; |
789 geometry.fMiterStroke = miterStroke; | 789 geometry.fMiterStroke = miterStroke; |
790 | 790 |
791 SkAutoTUnref<GrBatch> batch(AAStrokeRectBatch::Create(geometry, viewMatrix))
; | 791 SkAutoTUnref<GrBatch> batch(AAStrokeRectBatch::Create(geometry, viewMatrix))
; |
792 target->drawBatch(pipelineBuilder, batch); | 792 target->drawBatch(pipelineBuilder, batch); |
793 } | 793 } |
794 | 794 |
795 void GrAARectRenderer::fillAANestedRects(GrDrawTarget* target, | 795 void GrAARectRenderer::FillAANestedRects(GrDrawTarget* target, |
796 GrPipelineBuilder* pipelineBuilder, | 796 GrPipelineBuilder* pipelineBuilder, |
797 GrColor color, | 797 GrColor color, |
798 const SkMatrix& viewMatrix, | 798 const SkMatrix& viewMatrix, |
799 const SkRect rects[2]) { | 799 const SkRect rects[2]) { |
800 SkASSERT(viewMatrix.rectStaysRect()); | 800 SkASSERT(viewMatrix.rectStaysRect()); |
801 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); | 801 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); |
802 | 802 |
803 SkRect devOutside, devInside; | 803 SkRect devOutside, devInside; |
804 viewMatrix.mapRect(&devOutside, rects[0]); | 804 viewMatrix.mapRect(&devOutside, rects[0]); |
805 viewMatrix.mapRect(&devInside, rects[1]); | 805 viewMatrix.mapRect(&devInside, rects[1]); |
806 | 806 |
807 if (devInside.isEmpty()) { | 807 if (devInside.isEmpty()) { |
808 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); | 808 FillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, devOu
tside); |
809 return; | 809 return; |
810 } | 810 } |
811 | 811 |
812 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, | 812 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside, |
813 devOutside, devInside, true); | 813 devOutside, devInside, true); |
814 } | 814 } |
815 | 815 |
816 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 816 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
817 | 817 |
818 #ifdef GR_TEST_UTILS | 818 #ifdef GR_TEST_UTILS |
819 | 819 |
820 BATCH_TEST_DEFINE(AAFillRectBatch) { | 820 BATCH_TEST_DEFINE(AAFillRectBatch) { |
821 AAFillRectBatch::Geometry geo; | 821 AAFillRectBatch::Geometry geo; |
822 geo.fColor = GrRandomColor(random); | 822 geo.fColor = GrRandomColor(random); |
823 geo.fViewMatrix = GrTest::TestMatrix(random); | 823 geo.fViewMatrix = GrTest::TestMatrix(random); |
(...skipping 18 matching lines...) Expand all Loading... |
842 geo.fColor = GrRandomColor(random); | 842 geo.fColor = GrRandomColor(random); |
843 geo.fDevOutside = outside; | 843 geo.fDevOutside = outside; |
844 geo.fDevOutsideAssist = outsideAssist; | 844 geo.fDevOutsideAssist = outsideAssist; |
845 geo.fDevInside = inside; | 845 geo.fDevInside = inside; |
846 geo.fMiterStroke = miterStroke; | 846 geo.fMiterStroke = miterStroke; |
847 | 847 |
848 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 848 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
849 } | 849 } |
850 | 850 |
851 #endif | 851 #endif |
OLD | NEW |