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 "GrGpu.h" | 9 #include "GrGpu.h" |
10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 GrTexture* textures[]) { | 258 GrTexture* textures[]) { |
259 return GrRectEffect::Create(); | 259 return GrRectEffect::Create(); |
260 } | 260 } |
261 | 261 |
262 /////////////////////////////////////////////////////////////////////////////// | 262 /////////////////////////////////////////////////////////////////////////////// |
263 | 263 |
264 namespace { | 264 namespace { |
265 extern const GrVertexAttrib gAARectAttribs[] = { | 265 extern const GrVertexAttrib gAARectAttribs[] = { |
266 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | 266 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, |
267 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 267 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
268 {kUByte_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_GrV
ertexAttribBinding}, | 268 {kFloat_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_Gr
VertexAttribBinding}, |
269 }; | 269 }; |
270 | 270 |
271 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 271 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
272 enum CoverageAttribType { | 272 enum CoverageAttribType { |
273 kUseColor_CoverageAttribType, | 273 kUseColor_CoverageAttribType, |
274 kUseCoverage_CoverageAttribType, | 274 kUseCoverage_CoverageAttribType, |
275 }; | 275 }; |
276 } | 276 } |
277 | 277 |
278 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { | 278 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { |
279 if (drawState->canTweakAlphaForCoverage()) { | 279 if (drawState->canTweakAlphaForCoverage()) { |
280 drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof(
SkColor)); | 280 drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof(
SkColor)); |
281 return kUseColor_CoverageAttribType; | 281 return kUseColor_CoverageAttribType; |
282 } else { | 282 } else { |
283 drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + 2 * siz
eof(SkColor)); | 283 drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + sizeof(
SkColor) + |
| 284 sizeof(float)); |
284 return kUseCoverage_CoverageAttribType; | 285 return kUseCoverage_CoverageAttribType; |
285 } | 286 } |
286 } | 287 } |
287 | 288 |
288 static void set_inset_fan(SkPoint* pts, size_t stride, | 289 static void set_inset_fan(SkPoint* pts, size_t stride, |
289 const SkRect& r, SkScalar dx, SkScalar dy) { | 290 const SkRect& r, SkScalar dx, SkScalar dy) { |
290 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 291 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
291 r.fRight - dx, r.fBottom - dy, stride); | 292 r.fRight - dx, r.fBottom - dy, stride); |
292 } | 293 } |
293 | 294 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 *((SkPoint*)((intptr_t)fan1Pos + 3 * vstride)) = | 506 *((SkPoint*)((intptr_t)fan1Pos + 3 * vstride)) = |
506 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) - vec[0] + vec[1]; | 507 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) - vec[0] + vec[1]; |
507 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) += vec[0] - vec[1]; | 508 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) += vec[0] - vec[1]; |
508 } | 509 } |
509 | 510 |
510 // Make verts point to vertex color and then set all the color and coverage
vertex attrs values. | 511 // Make verts point to vertex color and then set all the color and coverage
vertex attrs values. |
511 verts += sizeof(SkPoint); | 512 verts += sizeof(SkPoint); |
512 for (int i = 0; i < 4; ++i) { | 513 for (int i = 0; i < 4; ++i) { |
513 if (kUseCoverage_CoverageAttribType == covAttribType) { | 514 if (kUseCoverage_CoverageAttribType == covAttribType) { |
514 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 515 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
515 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; | 516 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = 0
; |
516 } else { | 517 } else { |
517 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; | 518 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; |
518 } | 519 } |
519 } | 520 } |
520 | 521 |
521 int scale; | 522 int scale; |
522 if (inset < SK_ScalarHalf) { | 523 if (inset < SK_ScalarHalf) { |
523 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 524 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
524 SkASSERT(scale >= 0 && scale <= 255); | 525 SkASSERT(scale >= 0 && scale <= 255); |
525 } else { | 526 } else { |
526 scale = 0xff; | 527 scale = 0xff; |
527 } | 528 } |
528 | 529 |
529 GrColor innerCoverage; | |
530 if (kUseCoverage_CoverageAttribType == covAttribType) { | |
531 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale); | |
532 } else { | |
533 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale); | |
534 } | |
535 verts += 4 * vstride; | 530 verts += 4 * vstride; |
| 531 |
| 532 float innerCoverage = GrNormalizeByteToFloat(scale); |
| 533 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 534 |
536 for (int i = 0; i < 4; ++i) { | 535 for (int i = 0; i < 4; ++i) { |
537 if (kUseCoverage_CoverageAttribType == covAttribType) { | 536 if (kUseCoverage_CoverageAttribType == covAttribType) { |
538 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 537 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
539 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
innerCoverage; | 538 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = i
nnerCoverage; |
540 } else { | 539 } else { |
541 *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage; | 540 *reinterpret_cast<GrColor*>(verts + i * vstride) = scaledColor; |
542 } | 541 } |
543 } | 542 } |
544 | 543 |
545 target->setIndexSourceToBuffer(indexBuffer); | 544 target->setIndexSourceToBuffer(indexBuffer); |
546 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, | 545 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, |
547 kVertsPerAAFillRect, | 546 kVertsPerAAFillRect, |
548 kIndicesPerAAFillRect); | 547 kIndicesPerAAFillRect); |
549 target->resetIndexSource(); | 548 target->resetIndexSource(); |
550 } | 549 } |
551 | 550 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 // innermost | 842 // innermost |
844 set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHa
lf); | 843 set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHa
lf); |
845 } | 844 } |
846 | 845 |
847 // Make verts point to vertex color and then set all the color and coverage
vertex attrs values. | 846 // Make verts point to vertex color and then set all the color and coverage
vertex attrs values. |
848 // The outermost rect has 0 coverage | 847 // The outermost rect has 0 coverage |
849 verts += sizeof(SkPoint); | 848 verts += sizeof(SkPoint); |
850 for (int i = 0; i < outerVertexNum; ++i) { | 849 for (int i = 0; i < outerVertexNum; ++i) { |
851 if (kUseCoverage_CoverageAttribType == covAttribType) { | 850 if (kUseCoverage_CoverageAttribType == covAttribType) { |
852 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 851 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
853 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; | 852 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = 0
; |
854 } else { | 853 } else { |
855 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; | 854 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; |
856 } | 855 } |
857 } | 856 } |
858 | 857 |
859 // scale is the coverage for the the inner two rects. | 858 // scale is the coverage for the the inner two rects. |
860 int scale; | 859 int scale; |
861 if (inset < SK_ScalarHalf) { | 860 if (inset < SK_ScalarHalf) { |
862 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 861 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
863 SkASSERT(scale >= 0 && scale <= 255); | 862 SkASSERT(scale >= 0 && scale <= 255); |
864 } else { | 863 } else { |
865 scale = 0xff; | 864 scale = 0xff; |
866 } | 865 } |
867 | 866 |
| 867 float innerCoverage = GrNormalizeByteToFloat(scale); |
| 868 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| 869 |
868 verts += outerVertexNum * vstride; | 870 verts += outerVertexNum * vstride; |
869 GrColor innerCoverage; | |
870 if (kUseCoverage_CoverageAttribType == covAttribType) { | |
871 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale); | |
872 } else { | |
873 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale); | |
874 } | |
875 | |
876 for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) { | 871 for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) { |
877 if (kUseCoverage_CoverageAttribType == covAttribType) { | 872 if (kUseCoverage_CoverageAttribType == covAttribType) { |
878 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 873 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
879 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
innerCoverage; | 874 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = i
nnerCoverage; |
880 } else { | 875 } else { |
881 *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage; | 876 *reinterpret_cast<GrColor*>(verts + i * vstride) = scaledColor; |
882 } | 877 } |
883 } | 878 } |
884 | 879 |
885 // The innermost rect has 0 coverage | 880 // The innermost rect has 0 coverage |
886 verts += (outerVertexNum + innerVertexNum) * vstride; | 881 verts += (outerVertexNum + innerVertexNum) * vstride; |
887 for (int i = 0; i < innerVertexNum; ++i) { | 882 for (int i = 0; i < innerVertexNum; ++i) { |
888 if (kUseCoverage_CoverageAttribType == covAttribType) { | 883 if (kUseCoverage_CoverageAttribType == covAttribType) { |
889 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 884 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
890 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; | 885 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; |
891 } else { | 886 } else { |
(...skipping 18 matching lines...) Expand all Loading... |
910 // can't call mapRect for devInside since it calls sort | 905 // can't call mapRect for devInside since it calls sort |
911 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 906 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
912 | 907 |
913 if (devInside.isEmpty()) { | 908 if (devInside.isEmpty()) { |
914 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); | 909 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); |
915 return; | 910 return; |
916 } | 911 } |
917 | 912 |
918 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
true); | 913 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
true); |
919 } | 914 } |
OLD | NEW |