Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 502533004: Revert of Make setVertexAttribs in GrDrawState take a stride parameter. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrAARectRenderer.h" 9 #include "GrAARectRenderer.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 // Should the coverage be multiplied into the color attrib or use a separate att rib. 270 // Should the coverage be multiplied into the color attrib or use a separate att rib.
271 enum CoverageAttribType { 271 enum CoverageAttribType {
272 kUseColor_CoverageAttribType, 272 kUseColor_CoverageAttribType,
273 kUseCoverage_CoverageAttribType, 273 kUseCoverage_CoverageAttribType,
274 }; 274 };
275 } 275 }
276 276
277 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { 277 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) {
278 if (drawState->canTweakAlphaForCoverage()) { 278 if (drawState->canTweakAlphaForCoverage()) {
279 drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof( SkColor)); 279 drawState->setVertexAttribs<gAARectAttribs>(2);
280 return kUseColor_CoverageAttribType; 280 return kUseColor_CoverageAttribType;
281 } else { 281 } else {
282 drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + 2 * siz eof(SkColor)); 282 drawState->setVertexAttribs<gAARectAttribs>(3);
283 return kUseCoverage_CoverageAttribType; 283 return kUseCoverage_CoverageAttribType;
284 } 284 }
285 } 285 }
286 286
287 static void set_inset_fan(SkPoint* pts, size_t stride, 287 static void set_inset_fan(SkPoint* pts, size_t stride,
288 const SkRect& r, SkScalar dx, SkScalar dy) { 288 const SkRect& r, SkScalar dx, SkScalar dy) {
289 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 289 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
290 r.fRight - dx, r.fBottom - dy, stride); 290 r.fRight - dx, r.fBottom - dy, stride);
291 } 291 }
292 292
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 return; 475 return;
476 } 476 }
477 477
478 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu); 478 GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu);
479 if (NULL == indexBuffer) { 479 if (NULL == indexBuffer) {
480 GrPrintf("Failed to create index buffer!\n"); 480 GrPrintf("Failed to create index buffer!\n");
481 return; 481 return;
482 } 482 }
483 483
484 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); 484 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
485 size_t vstride = drawState->getVertexStride(); 485 size_t vsize = drawState->getVertexSize();
486 486
487 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); 487 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts);
488 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride); 488 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vsize);
489 489
490 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); 490 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1);
491 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); 491 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height());
492 492
493 if (combinedMatrix.rectStaysRect()) { 493 if (combinedMatrix.rectStaysRect()) {
494 // Temporarily #if'ed out. We don't want to pass in the devRect but 494 // Temporarily #if'ed out. We don't want to pass in the devRect but
495 // right now it is computed in GrContext::apply_aa_to_rect and we don't 495 // right now it is computed in GrContext::apply_aa_to_rect and we don't
496 // want to throw away the work 496 // want to throw away the work
497 #if 0 497 #if 0
498 SkRect devRect; 498 SkRect devRect;
499 combinedMatrix.mapRect(&devRect, rect); 499 combinedMatrix.mapRect(&devRect, rect);
500 #endif 500 #endif
501 501
502 set_inset_fan(fan0Pos, vstride, devRect, -SK_ScalarHalf, -SK_ScalarHalf) ; 502 set_inset_fan(fan0Pos, vsize, devRect, -SK_ScalarHalf, -SK_ScalarHalf);
503 set_inset_fan(fan1Pos, vstride, devRect, inset, inset); 503 set_inset_fan(fan1Pos, vsize, devRect, inset, inset);
504 } else { 504 } else {
505 // compute transformed (1, 0) and (0, 1) vectors 505 // compute transformed (1, 0) and (0, 1) vectors
506 SkVector vec[2] = { 506 SkVector vec[2] = {
507 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] }, 507 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY ] },
508 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] } 508 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScale Y] }
509 }; 509 };
510 510
511 vec[0].normalize(); 511 vec[0].normalize();
512 vec[0].scale(SK_ScalarHalf); 512 vec[0].scale(SK_ScalarHalf);
513 vec[1].normalize(); 513 vec[1].normalize();
514 vec[1].scale(SK_ScalarHalf); 514 vec[1].scale(SK_ScalarHalf);
515 515
516 // create the rotated rect 516 // create the rotated rect
517 fan0Pos->setRectFan(rect.fLeft, rect.fTop, 517 fan0Pos->setRectFan(rect.fLeft, rect.fTop,
518 rect.fRight, rect.fBottom, vstride); 518 rect.fRight, rect.fBottom, vsize);
519 combinedMatrix.mapPointsWithStride(fan0Pos, vstride, 4); 519 combinedMatrix.mapPointsWithStride(fan0Pos, vsize, 4);
520 520
521 // Now create the inset points and then outset the original 521 // Now create the inset points and then outset the original
522 // rotated points 522 // rotated points
523 523
524 // TL 524 // TL
525 *((SkPoint*)((intptr_t)fan1Pos + 0 * vstride)) = 525 *((SkPoint*)((intptr_t)fan1Pos + 0 * vsize)) =
526 *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) + vec[0] + vec[1]; 526 *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) + vec[0] + vec[1];
527 *((SkPoint*)((intptr_t)fan0Pos + 0 * vstride)) -= vec[0] + vec[1]; 527 *((SkPoint*)((intptr_t)fan0Pos + 0 * vsize)) -= vec[0] + vec[1];
528 // BL 528 // BL
529 *((SkPoint*)((intptr_t)fan1Pos + 1 * vstride)) = 529 *((SkPoint*)((intptr_t)fan1Pos + 1 * vsize)) =
530 *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) + vec[0] - vec[1]; 530 *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) + vec[0] - vec[1];
531 *((SkPoint*)((intptr_t)fan0Pos + 1 * vstride)) -= vec[0] - vec[1]; 531 *((SkPoint*)((intptr_t)fan0Pos + 1 * vsize)) -= vec[0] - vec[1];
532 // BR 532 // BR
533 *((SkPoint*)((intptr_t)fan1Pos + 2 * vstride)) = 533 *((SkPoint*)((intptr_t)fan1Pos + 2 * vsize)) =
534 *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) - vec[0] - vec[1]; 534 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) - vec[0] - vec[1];
535 *((SkPoint*)((intptr_t)fan0Pos + 2 * vstride)) += vec[0] + vec[1]; 535 *((SkPoint*)((intptr_t)fan0Pos + 2 * vsize)) += vec[0] + vec[1];
536 // TR 536 // TR
537 *((SkPoint*)((intptr_t)fan1Pos + 3 * vstride)) = 537 *((SkPoint*)((intptr_t)fan1Pos + 3 * vsize)) =
538 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) - vec[0] + vec[1]; 538 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) - vec[0] + vec[1];
539 *((SkPoint*)((intptr_t)fan0Pos + 3 * vstride)) += vec[0] - vec[1]; 539 *((SkPoint*)((intptr_t)fan0Pos + 3 * vsize)) += vec[0] - vec[1];
540 } 540 }
541 541
542 // Make verts point to vertex color and then set all the color and coverage vertex attrs values. 542 // Make verts point to vertex color and then set all the color and coverage vertex attrs values.
543 verts += sizeof(SkPoint); 543 verts += sizeof(SkPoint);
544 for (int i = 0; i < 4; ++i) { 544 for (int i = 0; i < 4; ++i) {
545 if (kUseCoverage_CoverageAttribType == covAttribType) { 545 if (kUseCoverage_CoverageAttribType == covAttribType) {
546 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; 546 *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
547 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0; 547 *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0 ;
548 } else { 548 } else {
549 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; 549 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
550 } 550 }
551 } 551 }
552 552
553 int scale; 553 int scale;
554 if (inset < SK_ScalarHalf) { 554 if (inset < SK_ScalarHalf) {
555 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); 555 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
556 SkASSERT(scale >= 0 && scale <= 255); 556 SkASSERT(scale >= 0 && scale <= 255);
557 } else { 557 } else {
558 scale = 0xff; 558 scale = 0xff;
559 } 559 }
560 560
561 GrColor innerCoverage; 561 GrColor innerCoverage;
562 if (kUseCoverage_CoverageAttribType == covAttribType) { 562 if (kUseCoverage_CoverageAttribType == covAttribType) {
563 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale); 563 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale);
564 } else { 564 } else {
565 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale); 565 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
566 } 566 }
567 verts += 4 * vstride; 567 verts += 4 * vsize;
568 for (int i = 0; i < 4; ++i) { 568 for (int i = 0; i < 4; ++i) {
569 if (kUseCoverage_CoverageAttribType == covAttribType) { 569 if (kUseCoverage_CoverageAttribType == covAttribType) {
570 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; 570 *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
571 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage; 571 *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = i nnerCoverage;
572 } else { 572 } else {
573 *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage; 573 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerCoverage;
574 } 574 }
575 } 575 }
576 576
577 target->setIndexSourceToBuffer(indexBuffer); 577 target->setIndexSourceToBuffer(indexBuffer);
578 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 578 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1,
579 kVertsPerAAFillRect, 579 kVertsPerAAFillRect,
580 kIndicesPerAAFillRect); 580 kIndicesPerAAFillRect);
581 target->resetIndexSource(); 581 target->resetIndexSource();
582 } 582 }
583 583
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 dir.normalize(); 627 dir.normalize();
628 628
629 // compute transformed (width, 0) and (0, height) vectors 629 // compute transformed (width, 0) and (0, height) vectors
630 SkVector vec[2] = { 630 SkVector vec[2] = {
631 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY] }, 631 { combinedMatrix[SkMatrix::kMScaleX], combinedMatrix[SkMatrix::kMSkewY] },
632 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScaleY] } 632 { combinedMatrix[SkMatrix::kMSkewX], combinedMatrix[SkMatrix::kMScaleY] }
633 }; 633 };
634 634
635 SkScalar newWidth = SkScalarHalf(rect.width() * vec[0].length()) + SK_Scalar Half; 635 SkScalar newWidth = SkScalarHalf(rect.width() * vec[0].length()) + SK_Scalar Half;
636 SkScalar newHeight = SkScalarHalf(rect.height() * vec[1].length()) + SK_Scal arHalf; 636 SkScalar newHeight = SkScalarHalf(rect.height() * vec[1].length()) + SK_Scal arHalf;
637 drawState->setVertexAttribs<gAARectVertexAttribs>(SK_ARRAY_COUNT(gAARectVert exAttribs), 637 drawState->setVertexAttribs<gAARectVertexAttribs>(SK_ARRAY_COUNT(gAARectVert exAttribs));
638 sizeof(RectVertex)); 638 SkASSERT(sizeof(RectVertex) == drawState->getVertexSize());
639 639
640 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 640 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
641 if (!geo.succeeded()) { 641 if (!geo.succeeded()) {
642 GrPrintf("Failed to get space for vertices!\n"); 642 GrPrintf("Failed to get space for vertices!\n");
643 return; 643 return;
644 } 644 }
645 645
646 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices()); 646 RectVertex* verts = reinterpret_cast<RectVertex*>(geo.vertices());
647 647
648 GrEffect* effect = GrRectEffect::Create(); 648 GrEffect* effect = GrRectEffect::Create();
(...skipping 28 matching lines...) Expand all
677 target->resetIndexSource(); 677 target->resetIndexSource();
678 } 678 }
679 679
680 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu, 680 void GrAARectRenderer::shaderFillAlignedAARect(GrGpu* gpu,
681 GrDrawTarget* target, 681 GrDrawTarget* target,
682 const SkRect& rect, 682 const SkRect& rect,
683 const SkMatrix& combinedMatrix) { 683 const SkMatrix& combinedMatrix) {
684 GrDrawState* drawState = target->drawState(); 684 GrDrawState* drawState = target->drawState();
685 SkASSERT(combinedMatrix.rectStaysRect()); 685 SkASSERT(combinedMatrix.rectStaysRect());
686 686
687 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect VertexAttribs), 687 drawState->setVertexAttribs<gAAAARectVertexAttribs>(SK_ARRAY_COUNT(gAAAARect VertexAttribs));
688 sizeof(AARectVertex)); 688 SkASSERT(sizeof(AARectVertex) == drawState->getVertexSize());
689 689
690 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0); 690 GrDrawTarget::AutoReleaseGeometry geo(target, 4, 0);
691 if (!geo.succeeded()) { 691 if (!geo.succeeded()) {
692 GrPrintf("Failed to get space for vertices!\n"); 692 GrPrintf("Failed to get space for vertices!\n");
693 return; 693 return;
694 } 694 }
695 695
696 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices()); 696 AARectVertex* verts = reinterpret_cast<AARectVertex*>(geo.vertices());
697 697
698 GrEffect* effect = GrAlignedRectEffect::Create(); 698 GrEffect* effect = GrAlignedRectEffect::Create();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 GrPrintf("Failed to get space for vertices!\n"); 827 GrPrintf("Failed to get space for vertices!\n");
828 return; 828 return;
829 } 829 }
830 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu, miterStroke) ; 830 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu, miterStroke) ;
831 if (NULL == indexBuffer) { 831 if (NULL == indexBuffer) {
832 GrPrintf("Failed to create index buffer!\n"); 832 GrPrintf("Failed to create index buffer!\n");
833 return; 833 return;
834 } 834 }
835 835
836 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); 836 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
837 size_t vstride = drawState->getVertexStride(); 837 size_t vsize = drawState->getVertexSize();
838 838
839 // We create vertices for four nested rectangles. There are two ramps from 0 to full 839 // We create vertices for four nested rectangles. There are two ramps from 0 to full
840 // coverage, one on the exterior of the stroke and the other on the interior . 840 // coverage, one on the exterior of the stroke and the other on the interior .
841 // The following pointers refer to the four rects, from outermost to innermo st. 841 // The following pointers refer to the four rects, from outermost to innermo st.
842 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); 842 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts);
843 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstri de); 843 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vsize );
844 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v stride); 844 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v size);
845 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum + innerVertexNum) * vstride); 845 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum + innerVertexNum) * vsize);
846 846
847 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX 847 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX
848 // TODO: this only really works if the X & Y margins are the same all around 848 // TODO: this only really works if the X & Y margins are the same all around
849 // the rect 849 // the rect
850 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t); 850 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t);
851 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); 851 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
852 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); 852 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
853 if (miterStroke) { 853 if (miterStroke) {
854 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInsid e.fBottom); 854 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInsid e.fBottom);
855 } else { 855 } else {
856 inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom - de vInside.fBottom); 856 inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom - de vInside.fBottom);
857 } 857 }
858 SkASSERT(inset >= 0); 858 SkASSERT(inset >= 0);
859 #else 859 #else
860 SkScalar inset = SK_ScalarHalf; 860 SkScalar inset = SK_ScalarHalf;
861 #endif 861 #endif
862 862
863 if (miterStroke) { 863 if (miterStroke) {
864 // outermost 864 // outermost
865 set_inset_fan(fan0Pos, vstride, devOutside, -SK_ScalarHalf, -SK_ScalarHa lf); 865 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf );
866 // inner two 866 // inner two
867 set_inset_fan(fan1Pos, vstride, devOutside, inset, inset); 867 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
868 set_inset_fan(fan2Pos, vstride, devInside, -inset, -inset); 868 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
869 // innermost 869 // innermost
870 set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHa lf); 870 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf );
871 } else { 871 } else {
872 SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vstride) ; 872 SkPoint* fan0AssistPos = reinterpret_cast<SkPoint*>(verts + 4 * vsize);
873 SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts + (outerVertex Num + 4) * vstride); 873 SkPoint* fan1AssistPos = reinterpret_cast<SkPoint*>(verts + (outerVertex Num + 4) * vsize);
874 // outermost 874 // outermost
875 set_inset_fan(fan0Pos, vstride, devOutside, -SK_ScalarHalf, -SK_ScalarHa lf); 875 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf );
876 set_inset_fan(fan0AssistPos, vstride, devOutsideAssist, -SK_ScalarHalf, -SK_ScalarHalf); 876 set_inset_fan(fan0AssistPos, vsize, devOutsideAssist, -SK_ScalarHalf, -S K_ScalarHalf);
877 // outer one of the inner two 877 // outer one of the inner two
878 set_inset_fan(fan1Pos, vstride, devOutside, inset, inset); 878 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
879 set_inset_fan(fan1AssistPos, vstride, devOutsideAssist, inset, inset); 879 set_inset_fan(fan1AssistPos, vsize, devOutsideAssist, inset, inset);
880 // inner one of the inner two 880 // inner one of the inner two
881 set_inset_fan(fan2Pos, vstride, devInside, -inset, -inset); 881 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
882 // innermost 882 // innermost
883 set_inset_fan(fan3Pos, vstride, devInside, SK_ScalarHalf, SK_ScalarHa lf); 883 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf );
884 } 884 }
885 885
886 // Make verts point to vertex color and then set all the color and coverage vertex attrs values. 886 // Make verts point to vertex color and then set all the color and coverage vertex attrs values.
887 // The outermost rect has 0 coverage 887 // The outermost rect has 0 coverage
888 verts += sizeof(SkPoint); 888 verts += sizeof(SkPoint);
889 for (int i = 0; i < outerVertexNum; ++i) { 889 for (int i = 0; i < outerVertexNum; ++i) {
890 if (kUseCoverage_CoverageAttribType == covAttribType) { 890 if (kUseCoverage_CoverageAttribType == covAttribType) {
891 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; 891 *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
892 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0; 892 *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0 ;
893 } else { 893 } else {
894 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; 894 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
895 } 895 }
896 } 896 }
897 897
898 // scale is the coverage for the the inner two rects. 898 // scale is the coverage for the the inner two rects.
899 int scale; 899 int scale;
900 if (inset < SK_ScalarHalf) { 900 if (inset < SK_ScalarHalf) {
901 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); 901 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
902 SkASSERT(scale >= 0 && scale <= 255); 902 SkASSERT(scale >= 0 && scale <= 255);
903 } else { 903 } else {
904 scale = 0xff; 904 scale = 0xff;
905 } 905 }
906 906
907 verts += outerVertexNum * vstride; 907 verts += outerVertexNum * vsize;
908 GrColor innerCoverage; 908 GrColor innerCoverage;
909 if (kUseCoverage_CoverageAttribType == covAttribType) { 909 if (kUseCoverage_CoverageAttribType == covAttribType) {
910 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale); 910 innerCoverage = GrColorPackRGBA(scale, scale, scale, scale);
911 } else { 911 } else {
912 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale); 912 innerCoverage = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
913 } 913 }
914 914
915 for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) { 915 for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) {
916 if (kUseCoverage_CoverageAttribType == covAttribType) { 916 if (kUseCoverage_CoverageAttribType == covAttribType) {
917 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; 917 *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
918 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = innerCoverage; 918 *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = i nnerCoverage;
919 } else { 919 } else {
920 *reinterpret_cast<GrColor*>(verts + i * vstride) = innerCoverage; 920 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerCoverage;
921 } 921 }
922 } 922 }
923 923
924 // The innermost rect has 0 coverage 924 // The innermost rect has 0 coverage
925 verts += (outerVertexNum + innerVertexNum) * vstride; 925 verts += (outerVertexNum + innerVertexNum) * vsize;
926 for (int i = 0; i < innerVertexNum; ++i) { 926 for (int i = 0; i < innerVertexNum; ++i) {
927 if (kUseCoverage_CoverageAttribType == covAttribType) { 927 if (kUseCoverage_CoverageAttribType == covAttribType) {
928 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; 928 *reinterpret_cast<GrColor*>(verts + i * vsize) = color;
929 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) = 0; 929 *reinterpret_cast<GrColor*>(verts + i * vsize + sizeof(GrColor)) = 0 ;
930 } else { 930 } else {
931 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; 931 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
932 } 932 }
933 } 933 }
934 934
935 target->setIndexSourceToBuffer(indexBuffer); 935 target->setIndexSourceToBuffer(indexBuffer);
936 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 936 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0,
937 totalVertexNum, aaStrokeRectIndexCount(miterStroke)); 937 totalVertexNum, aaStrokeRectIndexCount(miterStroke));
938 } 938 }
939 939
940 void GrAARectRenderer::fillAANestedRects(GrGpu* gpu, 940 void GrAARectRenderer::fillAANestedRects(GrGpu* gpu,
941 GrDrawTarget* target, 941 GrDrawTarget* target,
942 const SkRect rects[2], 942 const SkRect rects[2],
943 const SkMatrix& combinedMatrix) { 943 const SkMatrix& combinedMatrix) {
944 SkASSERT(combinedMatrix.rectStaysRect()); 944 SkASSERT(combinedMatrix.rectStaysRect());
945 SkASSERT(!rects[1].isEmpty()); 945 SkASSERT(!rects[1].isEmpty());
946 946
947 SkRect devOutside, devOutsideAssist, devInside; 947 SkRect devOutside, devOutsideAssist, devInside;
948 combinedMatrix.mapRect(&devOutside, rects[0]); 948 combinedMatrix.mapRect(&devOutside, rects[0]);
949 // can't call mapRect for devInside since it calls sort 949 // can't call mapRect for devInside since it calls sort
950 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 950 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
951 951
952 if (devInside.isEmpty()) { 952 if (devInside.isEmpty()) {
953 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); 953 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside);
954 return; 954 return;
955 } 955 }
956 956
957 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true); 957 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true);
958 } 958 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698