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

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

Issue 23712005: Add bevel-stroke support in GrAARectRenderer (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: fix small bugs Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.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 "GrAARectRenderer.h" 8 #include "GrAARectRenderer.h"
9 #include "GrGpu.h" 9 #include "GrGpu.h"
10 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 static void set_inset_fan(GrPoint* pts, size_t stride, 282 static void set_inset_fan(GrPoint* pts, size_t stride,
283 const SkRect& r, SkScalar dx, SkScalar dy) { 283 const SkRect& r, SkScalar dx, SkScalar dy) {
284 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 284 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
285 r.fRight - dx, r.fBottom - dy, stride); 285 r.fRight - dx, r.fBottom - dy, stride);
286 } 286 }
287 287
288 }; 288 };
289 289
290 void GrAARectRenderer::reset() { 290 void GrAARectRenderer::reset() {
291 SkSafeSetNull(fAAFillRectIndexBuffer); 291 SkSafeSetNull(fAAFillRectIndexBuffer);
292 SkSafeSetNull(fAAStrokeRectIndexBuffer); 292 SkSafeSetNull(fAAMiterStrokeRectIndexBuffer);
293 SkSafeSetNull(fAABevelStrokeRectIndexBuffer);
293 } 294 }
294 295
295 static const uint16_t gFillAARectIdx[] = { 296 static const uint16_t gFillAARectIdx[] = {
296 0, 1, 5, 5, 4, 0, 297 0, 1, 5, 5, 4, 0,
297 1, 2, 6, 6, 5, 1, 298 1, 2, 6, 6, 5, 1,
298 2, 3, 7, 7, 6, 2, 299 2, 3, 7, 7, 6, 2,
299 3, 0, 4, 4, 7, 3, 300 3, 0, 4, 4, 7, 3,
300 4, 5, 6, 6, 7, 4, 301 4, 5, 6, 6, 7, 4,
301 }; 302 };
302 303
(...skipping 30 matching lines...) Expand all
333 SkDELETE_ARRAY(data); 334 SkDELETE_ARRAY(data);
334 } else { 335 } else {
335 fAAFillRectIndexBuffer->unlock(); 336 fAAFillRectIndexBuffer->unlock();
336 } 337 }
337 } 338 }
338 } 339 }
339 340
340 return fAAFillRectIndexBuffer; 341 return fAAFillRectIndexBuffer;
341 } 342 }
342 343
343 static const uint16_t gStrokeAARectIdx[] = { 344 static const uint16_t gMiterStrokeAARectIdx[] = {
344 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, 345 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0,
345 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, 346 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0,
346 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, 347 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0,
347 3 + 0, 0 + 0, 4 + 0, 4 + 0, 7 + 0, 3 + 0, 348 3 + 0, 0 + 0, 4 + 0, 4 + 0, 7 + 0, 3 + 0,
348 349
349 0 + 4, 1 + 4, 5 + 4, 5 + 4, 4 + 4, 0 + 4, 350 0 + 4, 1 + 4, 5 + 4, 5 + 4, 4 + 4, 0 + 4,
350 1 + 4, 2 + 4, 6 + 4, 6 + 4, 5 + 4, 1 + 4, 351 1 + 4, 2 + 4, 6 + 4, 6 + 4, 5 + 4, 1 + 4,
351 2 + 4, 3 + 4, 7 + 4, 7 + 4, 6 + 4, 2 + 4, 352 2 + 4, 3 + 4, 7 + 4, 7 + 4, 6 + 4, 2 + 4,
352 3 + 4, 0 + 4, 4 + 4, 4 + 4, 7 + 4, 3 + 4, 353 3 + 4, 0 + 4, 4 + 4, 4 + 4, 7 + 4, 3 + 4,
353 354
354 0 + 8, 1 + 8, 5 + 8, 5 + 8, 4 + 8, 0 + 8, 355 0 + 8, 1 + 8, 5 + 8, 5 + 8, 4 + 8, 0 + 8,
355 1 + 8, 2 + 8, 6 + 8, 6 + 8, 5 + 8, 1 + 8, 356 1 + 8, 2 + 8, 6 + 8, 6 + 8, 5 + 8, 1 + 8,
356 2 + 8, 3 + 8, 7 + 8, 7 + 8, 6 + 8, 2 + 8, 357 2 + 8, 3 + 8, 7 + 8, 7 + 8, 6 + 8, 2 + 8,
357 3 + 8, 0 + 8, 4 + 8, 4 + 8, 7 + 8, 3 + 8, 358 3 + 8, 0 + 8, 4 + 8, 4 + 8, 7 + 8, 3 + 8,
358 }; 359 };
359 360
360 int GrAARectRenderer::aaStrokeRectIndexCount() { 361 /**
361 return GR_ARRAY_COUNT(gStrokeAARectIdx); 362 * As in miter-stroke, index = a + b, and a is the current index, b is the shift
363 * from the first index. The index layout:
364 * outer AA line: 0~3, 4~7
365 * outer edge: 8~11, 12~15
366 * inner edge: 16~19
367 * inner AA line: 20~23
368 * Following comes a bevel-stroke rect and its indices:
369 *
370 * 4 7
371 * *********************************
372 * * ______________________________ *
373 * * / 12 15 \ *
374 * * / \ *
375 * 0 * |8 16_____________________19 11 | * 3
376 * * | | | | *
377 * * | | **************** | | *
378 * * | | * 20 23 * | | *
379 * * | | * * | | *
380 * * | | * 21 22 * | | *
381 * * | | **************** | | *
382 * * | |____________________| | *
383 * 1 * |9 17 18 10| * 2
384 * * \ / *
385 * * \13 __________________________14/ *
386 * * *
387 * **********************************
388 * 5 6
389 */
390 static const uint16_t gBevelStrokeAARectIdx[] = {
391 // Draw outer AA, from outer AA line to outer edge, shift is 0.
392 0 + 0, 1 + 0, 9 + 0, 9 + 0, 8 + 0, 0 + 0,
393 1 + 0, 5 + 0, 13 + 0, 13 + 0, 9 + 0, 1 + 0,
394 5 + 0, 6 + 0, 14 + 0, 14 + 0, 13 + 0, 5 + 0,
395 6 + 0, 2 + 0, 10 + 0, 10 + 0, 14 + 0, 6 + 0,
396 2 + 0, 3 + 0, 11 + 0, 11 + 0, 10 + 0, 2 + 0,
397 3 + 0, 7 + 0, 15 + 0, 15 + 0, 11 + 0, 3 + 0,
398 7 + 0, 4 + 0, 12 + 0, 12 + 0, 15 + 0, 7 + 0,
399 4 + 0, 0 + 0, 8 + 0, 8 + 0, 12 + 0, 4 + 0,
400
401 // Draw the stroke, from outer edge to inner edge, shift is 8.
402 0 + 8, 1 + 8, 9 + 8, 9 + 8, 8 + 8, 0 + 8,
403 1 + 8, 5 + 8, 9 + 8,
404 5 + 8, 6 + 8, 10 + 8, 10 + 8, 9 + 8, 5 + 8,
405 6 + 8, 2 + 8, 10 + 8,
406 2 + 8, 3 + 8, 11 + 8, 11 + 8, 10 + 8, 2 + 8,
407 3 + 8, 7 + 8, 11 + 8,
408 7 + 8, 4 + 8, 8 + 8, 8 + 8, 11 + 8, 7 + 8,
409 4 + 8, 0 + 8, 8 + 8,
410
411 // Draw the inner AA, from inner edge to inner AA line, shift is 16.
412 0 + 16, 1 + 16, 5 + 16, 5 + 16, 4 + 16, 0 + 16,
413 1 + 16, 2 + 16, 6 + 16, 6 + 16, 5 + 16, 1 + 16,
414 2 + 16, 3 + 16, 7 + 16, 7 + 16, 6 + 16, 2 + 16,
415 3 + 16, 0 + 16, 4 + 16, 4 + 16, 7 + 16, 3 + 16,
416 };
417
418 int GrAARectRenderer::aaStrokeRectIndexCount(bool miterStroke) {
419 return miterStroke ? GR_ARRAY_COUNT(gMiterStrokeAARectIdx) :
420 GR_ARRAY_COUNT(gBevelStrokeAARectIdx);
362 } 421 }
363 422
364 GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(GrGpu* gpu) { 423 GrIndexBuffer* GrAARectRenderer::aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterS troke) {
365 if (NULL == fAAStrokeRectIndexBuffer) { 424 if (miterStroke) {
366 fAAStrokeRectIndexBuffer = 425 if (NULL == fAAMiterStrokeRectIndexBuffer) {
367 gpu->createIndexBuffer(sizeof(gStrokeAARectIdx), false); 426 fAAMiterStrokeRectIndexBuffer =
368 if (NULL != fAAStrokeRectIndexBuffer) { 427 gpu->createIndexBuffer(sizeof(gMiterStrokeAARectIdx), false);
428 if (NULL != fAAMiterStrokeRectIndexBuffer) {
369 #ifdef SK_DEBUG 429 #ifdef SK_DEBUG
370 bool updated = 430 bool updated =
371 #endif 431 #endif
372 fAAStrokeRectIndexBuffer->updateData(gStrokeAARectIdx, 432 fAAMiterStrokeRectIndexBuffer->updateData(gMiterStrokeAARectIdx,
373 sizeof(gStrokeAARectIdx)); 433 sizeof(gMiterStrokeAAR ectIdx));
374 GR_DEBUGASSERT(updated); 434 GR_DEBUGASSERT(updated);
435 }
375 } 436 }
437 return fAAMiterStrokeRectIndexBuffer;
438 } else {
439 if (NULL == fAABevelStrokeRectIndexBuffer) {
440 fAABevelStrokeRectIndexBuffer =
441 gpu->createIndexBuffer(sizeof(gBevelStrokeAARectIdx), false);
442 if (NULL != fAABevelStrokeRectIndexBuffer) {
443 #ifdef SK_DEBUG
444 bool updated =
445 #endif
446 fAABevelStrokeRectIndexBuffer->updateData(gBevelStrokeAARectIdx,
447 sizeof(gBevelStrokeAAR ectIdx));
448 GR_DEBUGASSERT(updated);
449 }
450 }
451 return fAABevelStrokeRectIndexBuffer;
376 } 452 }
377 return fAAStrokeRectIndexBuffer;
378 } 453 }
379 454
380 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu, 455 void GrAARectRenderer::geometryFillAARect(GrGpu* gpu,
381 GrDrawTarget* target, 456 GrDrawTarget* target,
382 const SkRect& rect, 457 const SkRect& rect,
383 const SkMatrix& combinedMatrix, 458 const SkMatrix& combinedMatrix,
384 const SkRect& devRect, 459 const SkRect& devRect,
385 bool useVertexCoverage) { 460 bool useVertexCoverage) {
386 GrDrawState* drawState = target->drawState(); 461 GrDrawState* drawState = target->drawState();
387 462
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); 721 target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer());
647 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6); 722 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6);
648 target->resetIndexSource(); 723 target->resetIndexSource();
649 } 724 }
650 725
651 void GrAARectRenderer::strokeAARect(GrGpu* gpu, 726 void GrAARectRenderer::strokeAARect(GrGpu* gpu,
652 GrDrawTarget* target, 727 GrDrawTarget* target,
653 const SkRect& rect, 728 const SkRect& rect,
654 const SkMatrix& combinedMatrix, 729 const SkMatrix& combinedMatrix,
655 const SkRect& devRect, 730 const SkRect& devRect,
656 SkScalar width, 731 const SkStrokeRec* stroke,
657 bool useVertexCoverage) { 732 bool useVertexCoverage) {
658 GrVec devStrokeSize; 733 GrVec devStrokeSize;
734 SkScalar width = stroke->getWidth();
659 if (width > 0) { 735 if (width > 0) {
660 devStrokeSize.set(width, width); 736 devStrokeSize.set(width, width);
661 combinedMatrix.mapVectors(&devStrokeSize, 1); 737 combinedMatrix.mapVectors(&devStrokeSize, 1);
662 devStrokeSize.setAbs(devStrokeSize); 738 devStrokeSize.setAbs(devStrokeSize);
663 } else { 739 } else {
664 devStrokeSize.set(SK_Scalar1, SK_Scalar1); 740 devStrokeSize.set(SK_Scalar1, SK_Scalar1);
665 } 741 }
666 742
667 const SkScalar dx = devStrokeSize.fX; 743 const SkScalar dx = devStrokeSize.fX;
668 const SkScalar dy = devStrokeSize.fY; 744 const SkScalar dy = devStrokeSize.fY;
(...skipping 11 matching lines...) Expand all
680 SkScalar spare; 756 SkScalar spare;
681 { 757 {
682 SkScalar w = devRect.width() - dx; 758 SkScalar w = devRect.width() - dx;
683 SkScalar h = devRect.height() - dy; 759 SkScalar h = devRect.height() - dy;
684 spare = GrMin(w, h); 760 spare = GrMin(w, h);
685 } 761 }
686 762
687 SkRect devOutside(devRect); 763 SkRect devOutside(devRect);
688 devOutside.outset(rx, ry); 764 devOutside.outset(rx, ry);
689 765
690 if (spare <= 0) { 766 bool miterStroke = true;
767 // small miter limit means right angles show bevel...
768 if (stroke->getJoin() != SkPaint::kMiter_Join || stroke->getMiter() < SK_Sca larSqrt2) {
769 miterStroke = false;
770 }
771
772 if (spare <= 0 && miterStroke) {
691 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), 773 this->fillAARect(gpu, target, devOutside, SkMatrix::I(),
692 devOutside, useVertexCoverage); 774 devOutside, useVertexCoverage);
693 return; 775 return;
694 } 776 }
695 777
696 SkRect devInside(devRect); 778 SkRect devInside(devRect);
697 devInside.inset(rx, ry); 779 devInside.inset(rx, ry);
698 780
699 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 781 SkRect devOutsideAssist(devRect);
782
783 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist)
784 // to draw the outer of the rect. Because there are 8 vertices on the outer
785 // edge, while vertex number of inner edge is 4, the same as miter-stroke.
786 if (!miterStroke) {
787 devOutside.inset(0, ry);
788 devOutsideAssist.outset(0, ry);
789 }
790
791 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist,
792 devInside, useVertexCoverage, miterStroke);
700 } 793 }
701 794
702 void GrAARectRenderer::geometryStrokeAARect(GrGpu* gpu, 795 void GrAARectRenderer::geometryStrokeAARect(GrGpu* gpu,
703 GrDrawTarget* target, 796 GrDrawTarget* target,
704 const SkRect& devOutside, 797 const SkRect& devOutside,
798 const SkRect& devOutsideAssist,
705 const SkRect& devInside, 799 const SkRect& devInside,
706 bool useVertexCoverage) { 800 bool useVertexCoverage,
801 bool miterStroke) {
707 GrDrawState* drawState = target->drawState(); 802 GrDrawState* drawState = target->drawState();
708 803
709 set_aa_rect_vertex_attributes(drawState, useVertexCoverage); 804 set_aa_rect_vertex_attributes(drawState, useVertexCoverage);
710 805
711 GrDrawTarget::AutoReleaseGeometry geo(target, 16, 0); 806 int innerVertexNum = 4;
807 int outerVertexNum = miterStroke ? 4 : 8;
808 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2;
809
810 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, 0);
712 if (!geo.succeeded()) { 811 if (!geo.succeeded()) {
713 GrPrintf("Failed to get space for vertices!\n"); 812 GrPrintf("Failed to get space for vertices!\n");
714 return; 813 return;
715 } 814 }
716 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu); 815 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(gpu, miterStroke) ;
717 if (NULL == indexBuffer) { 816 if (NULL == indexBuffer) {
718 GrPrintf("Failed to create index buffer!\n"); 817 GrPrintf("Failed to create index buffer!\n");
719 return; 818 return;
720 } 819 }
721 820
722 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); 821 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
723 size_t vsize = drawState->getVertexSize(); 822 size_t vsize = drawState->getVertexSize();
724 SkASSERT(sizeof(GrPoint) + sizeof(GrColor) == vsize); 823 SkASSERT(sizeof(GrPoint) + sizeof(GrColor) == vsize);
725 824
726 // We create vertices for four nested rectangles. There are two ramps from 0 to full 825 // We create vertices for four nested rectangles. There are two ramps from 0 to full
727 // coverage, one on the exterior of the stroke and the other on the interior . 826 // coverage, one on the exterior of the stroke and the other on the interior .
728 // The following pointers refer to the four rects, from outermost to innermo st. 827 // The following pointers refer to the four rects, from outermost to innermo st.
729 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); 828 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts);
730 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); 829 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + outerVertexNum * vsize );
731 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize); 830 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 2 * outerVertexNum * v size);
732 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize); 831 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + (2 * outerVertexNum + innerVertexNum) * vsize);
733 832
734 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX 833 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX
735 // TODO: this only really works if the X & Y margins are the same all around 834 // TODO: this only really works if the X & Y margins are the same all around
736 // the rect 835 // the rect
737 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t); 836 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh t);
738 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); 837 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft);
739 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); 838 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop);
740 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fB ottom); 839 if (miterStroke) {
840 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInsid e.fBottom);
841 } else {
842 inset = SK_ScalarHalf * SkMinScalar(inset, devOutsideAssist.fBottom - de vInside.fBottom);
843 }
741 SkASSERT(inset >= 0); 844 SkASSERT(inset >= 0);
742 #else 845 #else
743 SkScalar inset = SK_ScalarHalf; 846 SkScalar inset = SK_ScalarHalf;
744 #endif 847 #endif
745 848
746 // outermost 849 if (miterStroke) {
747 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf); 850 // outermost
748 // inner two 851 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf );
749 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); 852 // inner two
750 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); 853 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
751 // innermost 854 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
752 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf); 855 // innermost
856 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf );
857 } else {
858 GrPoint* fan0AssistPos = reinterpret_cast<GrPoint*>(verts + 4 * vsize);
859 GrPoint* fan1AssistPos = reinterpret_cast<GrPoint*>(verts + (outerVertex Num + 4) * vsize);
860 // outermost
861 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf );
862 set_inset_fan(fan0AssistPos, vsize, devOutsideAssist, -SK_ScalarHalf, -S K_ScalarHalf);
863 // outer one of the inner two
864 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset);
865 set_inset_fan(fan1AssistPos, vsize, devOutsideAssist, inset, inset);
866 // inner one of the inner two
867 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset);
868 // innermost
869 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf );
870 }
753 871
754 // The outermost rect has 0 coverage 872 // The outermost rect has 0 coverage
755 verts += sizeof(GrPoint); 873 verts += sizeof(GrPoint);
756 for (int i = 0; i < 4; ++i) { 874 for (int i = 0; i < outerVertexNum; ++i) {
757 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 875 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
758 } 876 }
759 877
760 int scale; 878 int scale;
761 if (inset < SK_ScalarHalf) { 879 if (inset < SK_ScalarHalf) {
762 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); 880 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf));
763 SkASSERT(scale >= 0 && scale <= 255); 881 SkASSERT(scale >= 0 && scale <= 255);
764 } else { 882 } else {
765 scale = 0xff; 883 scale = 0xff;
766 } 884 }
767 885
768 // The inner two rects have full coverage 886 // The inner two rects have full coverage
769 GrColor innerColor; 887 GrColor innerColor;
770 if (useVertexCoverage) { 888 if (useVertexCoverage) {
771 innerColor = GrColorPackRGBA(scale, scale, scale, scale); 889 innerColor = GrColorPackRGBA(scale, scale, scale, scale);
772 } else { 890 } else {
773 if (0xff == scale) { 891 if (0xff == scale) {
774 innerColor = target->getDrawState().getColor(); 892 innerColor = target->getDrawState().getColor();
775 } else { 893 } else {
776 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale); 894 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);
777 } 895 }
778 } 896 }
779 897
780 verts += 4 * vsize; 898 verts += outerVertexNum * vsize;
781 for (int i = 0; i < 8; ++i) { 899 for (int i = 0; i < outerVertexNum + innerVertexNum; ++i) {
782 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; 900 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor;
783 } 901 }
784 902
785 // The innermost rect has 0 coverage 903 // The innermost rect has 0 coverage
786 verts += 8 * vsize; 904 verts += (outerVertexNum + innerVertexNum) * vsize;
yunchao 2013/11/05 04:58:30 variable 'verts' needs to move 2*outerVertexNum+in
787 for (int i = 0; i < 4; ++i) { 905 for (int i = 0; i < innerVertexNum; ++i) {
788 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; 906 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0;
789 } 907 }
790 908
791 target->setIndexSourceToBuffer(indexBuffer); 909 target->setIndexSourceToBuffer(indexBuffer);
792 target->drawIndexed(kTriangles_GrPrimitiveType, 910 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0,
793 0, 0, 16, aaStrokeRectIndexCount()); 911 totalVertexNum, aaStrokeRectIndexCount(miterStroke));
794 } 912 }
795 913
796 void GrAARectRenderer::fillAANestedRects(GrGpu* gpu, 914 void GrAARectRenderer::fillAANestedRects(GrGpu* gpu,
797 GrDrawTarget* target, 915 GrDrawTarget* target,
798 const SkRect rects[2], 916 const SkRect rects[2],
799 const SkMatrix& combinedMatrix, 917 const SkMatrix& combinedMatrix,
800 bool useVertexCoverage) { 918 bool useVertexCoverage) {
801 SkASSERT(combinedMatrix.rectStaysRect()); 919 SkASSERT(combinedMatrix.rectStaysRect());
802 SkASSERT(!rects[1].isEmpty()); 920 SkASSERT(!rects[1].isEmpty());
803 921
804 SkRect devOutside, devInside; 922 SkRect devOutside, devOutsideAssist, devInside;
805 combinedMatrix.mapRect(&devOutside, rects[0]); 923 combinedMatrix.mapRect(&devOutside, rects[0]);
806 // can't call mapRect for devInside since it calls sort 924 // can't call mapRect for devInside since it calls sort
807 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 925 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
808 926
809 if (devInside.isEmpty()) { 927 if (devInside.isEmpty()) {
810 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 928 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
811 return; 929 return;
812 } 930 }
813 931
814 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 932 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist,
933 devInside, useVertexCoverage, true);
815 } 934 }
OLDNEW
« no previous file with comments | « src/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698