| 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" |
| 11 #include "GrBatchTest.h" |
| 11 #include "GrBufferAllocPool.h" | 12 #include "GrBufferAllocPool.h" |
| 13 #include "GrContext.h" |
| 12 #include "GrDefaultGeoProcFactory.h" | 14 #include "GrDefaultGeoProcFactory.h" |
| 13 #include "GrGeometryProcessor.h" | 15 #include "GrGeometryProcessor.h" |
| 14 #include "GrGpu.h" | 16 #include "GrGpu.h" |
| 15 #include "GrInvariantOutput.h" | 17 #include "GrInvariantOutput.h" |
| 18 #include "GrTestUtils.h" |
| 16 #include "SkColorPriv.h" | 19 #include "SkColorPriv.h" |
| 17 #include "gl/GrGLProcessor.h" | 20 #include "gl/GrGLProcessor.h" |
| 18 #include "gl/GrGLGeometryProcessor.h" | 21 #include "gl/GrGLGeometryProcessor.h" |
| 19 #include "gl/builders/GrGLProgramBuilder.h" | 22 #include "gl/builders/GrGLProgramBuilder.h" |
| 20 | 23 |
| 21 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
| 22 | 25 |
| 23 static void set_inset_fan(SkPoint* pts, size_t stride, | 26 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 24 const SkRect& r, SkScalar dx, SkScalar dy) { | 27 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 25 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 28 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 bool fColorIgnored; | 317 bool fColorIgnored; |
| 315 bool fCoverageIgnored; | 318 bool fCoverageIgnored; |
| 316 bool fCanTweakAlphaForCoverage; | 319 bool fCanTweakAlphaForCoverage; |
| 317 }; | 320 }; |
| 318 | 321 |
| 319 BatchTracker fBatch; | 322 BatchTracker fBatch; |
| 320 const GrIndexBuffer* fIndexBuffer; | 323 const GrIndexBuffer* fIndexBuffer; |
| 321 SkSTArray<1, Geometry, true> fGeoData; | 324 SkSTArray<1, Geometry, true> fGeoData; |
| 322 }; | 325 }; |
| 323 | 326 |
| 327 BATCH_TEST_DEFINE(AAFillRectBatch) { |
| 328 AAFillRectBatch::Geometry geo; |
| 329 geo.fColor = GrRandomColor(random); |
| 330 geo.fViewMatrix = GrTest::TestMatrix(random); |
| 331 geo.fRect = GrTest::TestRect(random); |
| 332 geo.fDevRect = GrTest::TestRect(random); |
| 333 |
| 334 static GrIndexBuffer* aaFillRectIndexBuffer = NULL; |
| 335 if (!aaFillRectIndexBuffer) { |
| 336 aaFillRectIndexBuffer = |
| 337 context->getGpu()->createInstancedIndexBuffer(gFillAARectIdx, |
| 338 kIndicesPerAAFillR
ect, |
| 339 kNumAAFillRectsInI
ndexBuffer, |
| 340 kVertsPerAAFillRec
t); |
| 341 } |
| 342 |
| 343 return AAFillRectBatch::Create(geo, aaFillRectIndexBuffer); |
| 344 } |
| 345 |
| 324 namespace { | 346 namespace { |
| 325 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 347 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
| 326 enum CoverageAttribType { | 348 enum CoverageAttribType { |
| 327 kUseColor_CoverageAttribType, | 349 kUseColor_CoverageAttribType, |
| 328 kUseCoverage_CoverageAttribType, | 350 kUseCoverage_CoverageAttribType, |
| 329 }; | 351 }; |
| 330 } | 352 } |
| 331 | 353 |
| 332 void GrAARectRenderer::reset() { | 354 void GrAARectRenderer::reset() { |
| 333 SkSafeSetNull(fAAFillRectIndexBuffer); | 355 SkSafeSetNull(fAAFillRectIndexBuffer); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 437 |
| 416 static const int kIndicesPerBevelStrokeRect = SK_ARRAY_COUNT(gBevelStrokeAARectI
dx); | 438 static const int kIndicesPerBevelStrokeRect = SK_ARRAY_COUNT(gBevelStrokeAARectI
dx); |
| 417 static const int kVertsPerBevelStrokeRect = 24; | 439 static const int kVertsPerBevelStrokeRect = 24; |
| 418 static const int kNumBevelStrokeRectsInIndexBuffer = 256; | 440 static const int kNumBevelStrokeRectsInIndexBuffer = 256; |
| 419 | 441 |
| 420 static int aa_stroke_rect_index_count(bool miterStroke) { | 442 static int aa_stroke_rect_index_count(bool miterStroke) { |
| 421 return miterStroke ? SK_ARRAY_COUNT(gMiterStrokeAARectIdx) : | 443 return miterStroke ? SK_ARRAY_COUNT(gMiterStrokeAARectIdx) : |
| 422 SK_ARRAY_COUNT(gBevelStrokeAARectIdx); | 444 SK_ARRAY_COUNT(gBevelStrokeAARectIdx); |
| 423 } | 445 } |
| 424 | 446 |
| 425 GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(bool miterStroke) { | 447 static GrIndexBuffer* setup_aa_stroke_rect_indexbuffer(GrIndexBuffer** aaMiterSt
rokeRectIndexBuffer, |
| 448 GrIndexBuffer** aaBevelSt
rokeRectIndexBuffer, |
| 449 GrGpu* gpu, |
| 450 bool miterStroke) { |
| 426 if (miterStroke) { | 451 if (miterStroke) { |
| 427 if (NULL == fAAMiterStrokeRectIndexBuffer) { | 452 if (!*aaMiterStrokeRectIndexBuffer) { |
| 428 fAAMiterStrokeRectIndexBuffer = | 453 *aaMiterStrokeRectIndexBuffer = |
| 429 fGpu->createInstancedIndexBuffer(gMiterStrokeAARectIdx, | 454 gpu->createInstancedIndexBuffer(gMiterStrokeAARectIdx, |
| 430 kIndicesPerMiterStrokeRect, | 455 kIndicesPerMiterStrokeRect, |
| 431 kNumMiterStrokeRectsInIndex
Buffer, | 456 kNumMiterStrokeRectsInIndexB
uffer, |
| 432 kVertsPerMiterStrokeRect); | 457 kVertsPerMiterStrokeRect); |
| 433 } | 458 } |
| 434 return fAAMiterStrokeRectIndexBuffer; | 459 return *aaMiterStrokeRectIndexBuffer; |
| 435 } else { | 460 } else { |
| 436 if (NULL == fAABevelStrokeRectIndexBuffer) { | 461 if (!*aaBevelStrokeRectIndexBuffer) { |
| 437 fAABevelStrokeRectIndexBuffer = | 462 *aaBevelStrokeRectIndexBuffer = |
| 438 fGpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx, | 463 gpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx, |
| 439 kIndicesPerBevelStrokeRect, | 464 kIndicesPerBevelStrokeRect, |
| 440 kNumBevelStrokeRectsInIndex
Buffer, | 465 kNumBevelStrokeRectsInIndexB
uffer, |
| 441 kVertsPerBevelStrokeRect); | 466 kVertsPerBevelStrokeRect); |
| 442 } | 467 } |
| 443 return fAABevelStrokeRectIndexBuffer; | 468 return *aaBevelStrokeRectIndexBuffer; |
| 444 } | 469 } |
| 445 } | 470 } |
| 446 | 471 |
| 447 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, | 472 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, |
| 448 GrPipelineBuilder* pipelineBuilder, | 473 GrPipelineBuilder* pipelineBuilder, |
| 449 GrColor color, | 474 GrColor color, |
| 450 const SkMatrix& viewMatrix, | 475 const SkMatrix& viewMatrix, |
| 451 const SkRect& rect, | 476 const SkRect& rect, |
| 452 const SkRect& devRect) { | 477 const SkRect& devRect) { |
| 453 if (!fAAFillRectIndexBuffer) { | 478 if (!fAAFillRectIndexBuffer) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 bool fCoverageIgnored; | 869 bool fCoverageIgnored; |
| 845 bool fMiterStroke; | 870 bool fMiterStroke; |
| 846 bool fCanTweakAlphaForCoverage; | 871 bool fCanTweakAlphaForCoverage; |
| 847 }; | 872 }; |
| 848 | 873 |
| 849 BatchTracker fBatch; | 874 BatchTracker fBatch; |
| 850 const GrIndexBuffer* fIndexBuffer; | 875 const GrIndexBuffer* fIndexBuffer; |
| 851 SkSTArray<1, Geometry, true> fGeoData; | 876 SkSTArray<1, Geometry, true> fGeoData; |
| 852 }; | 877 }; |
| 853 | 878 |
| 879 BATCH_TEST_DEFINE(AAStrokeRectBatch) { |
| 880 static GrIndexBuffer* aaMiterStrokeRectIndexBuffer = NULL; |
| 881 static GrIndexBuffer* aaBevelStrokeRectIndexBuffer = NULL; |
| 882 |
| 883 bool miterStroke = random->nextBool(); |
| 884 |
| 885 GrIndexBuffer* indexBuffer = setup_aa_stroke_rect_indexbuffer(&aaMiterStroke
RectIndexBuffer, |
| 886 &aaBevelStroke
RectIndexBuffer, |
| 887 context->getGp
u(), |
| 888 miterStroke); |
| 889 |
| 890 // Create mock stroke rect |
| 891 SkRect outside = GrTest::TestRect(random); |
| 892 SkScalar minDim = SkMinScalar(outside.width(), outside.height()); |
| 893 SkScalar strokeWidth = minDim * 0.1f; |
| 894 SkRect outsideAssist = outside; |
| 895 outsideAssist.outset(strokeWidth, strokeWidth); |
| 896 SkRect inside = outside; |
| 897 inside.inset(strokeWidth, strokeWidth); |
| 898 |
| 899 AAStrokeRectBatch::Geometry geo; |
| 900 geo.fColor = GrRandomColor(random); |
| 901 geo.fDevOutside = outside; |
| 902 geo.fDevOutsideAssist = outsideAssist; |
| 903 geo.fDevInside = inside; |
| 904 geo.fMiterStroke = miterStroke; |
| 905 |
| 906 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffe
r); |
| 907 } |
| 854 | 908 |
| 855 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, | 909 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, |
| 856 GrPipelineBuilder* pipelineBuilder, | 910 GrPipelineBuilder* pipelineBuilder, |
| 857 GrColor color, | 911 GrColor color, |
| 858 const SkMatrix& viewMatrix, | 912 const SkMatrix& viewMatrix, |
| 859 const SkRect& devOutside, | 913 const SkRect& devOutside, |
| 860 const SkRect& devOutsideAssist, | 914 const SkRect& devOutsideAssist, |
| 861 const SkRect& devInside, | 915 const SkRect& devInside, |
| 862 bool miterStroke) { | 916 bool miterStroke) { |
| 863 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); | 917 GrIndexBuffer* indexBuffer = setup_aa_stroke_rect_indexbuffer(&fAAMiterStrok
eRectIndexBuffer, |
| 918 &fAABevelStrok
eRectIndexBuffer, |
| 919 fGpu, |
| 920 miterStroke); |
| 864 if (!indexBuffer) { | 921 if (!indexBuffer) { |
| 865 SkDebugf("Failed to create index buffer!\n"); | 922 SkDebugf("Failed to create index buffer!\n"); |
| 866 return; | 923 return; |
| 867 } | 924 } |
| 868 | 925 |
| 869 AAStrokeRectBatch::Geometry geometry; | 926 AAStrokeRectBatch::Geometry geometry; |
| 870 geometry.fColor = color; | 927 geometry.fColor = color; |
| 871 geometry.fDevOutside = devOutside; | 928 geometry.fDevOutside = devOutside; |
| 872 geometry.fDevOutsideAssist = devOutsideAssist; | 929 geometry.fDevOutsideAssist = devOutsideAssist; |
| 873 geometry.fDevInside = devInside; | 930 geometry.fDevInside = devInside; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 891 viewMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2); | 948 viewMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2); |
| 892 | 949 |
| 893 if (devInside.isEmpty()) { | 950 if (devInside.isEmpty()) { |
| 894 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); | 951 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); |
| 895 return; | 952 return; |
| 896 } | 953 } |
| 897 | 954 |
| 898 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, | 955 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, |
| 899 devOutsideAssist, devInside, true); | 956 devOutsideAssist, devInside, true); |
| 900 } | 957 } |
| OLD | NEW |