| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrRectBatchFactory.h" | 8 #include "GrRectBatchFactory.h" |
| 9 | 9 |
| 10 #include "GrAAStrokeRectBatch.h" | 10 #include "GrAAStrokeRectBatch.h" |
| 11 | 11 |
| 12 #include "SkStrokeRec.h" | 12 #include "SkStrokeRec.h" |
| 13 | 13 |
| 14 namespace GrRectBatchFactory { | 14 namespace GrRectBatchFactory { |
| 15 | 15 |
| 16 GrDrawBatch* CreateAAStroke(GrColor color, | |
| 17 const SkMatrix& viewMatrix, | |
| 18 const SkRect& rect, | |
| 19 const SkRect& devRect, | |
| 20 const SkStrokeRec& stroke) { | |
| 21 SkVector devStrokeSize; | |
| 22 SkScalar width = stroke.getWidth(); | |
| 23 if (width > 0) { | |
| 24 devStrokeSize.set(width, width); | |
| 25 viewMatrix.mapVectors(&devStrokeSize, 1); | |
| 26 devStrokeSize.setAbs(devStrokeSize); | |
| 27 } else { | |
| 28 devStrokeSize.set(SK_Scalar1, SK_Scalar1); | |
| 29 } | |
| 30 | |
| 31 const SkScalar dx = devStrokeSize.fX; | |
| 32 const SkScalar dy = devStrokeSize.fY; | |
| 33 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); | |
| 34 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); | |
| 35 | |
| 36 SkRect devOutside(devRect); | |
| 37 devOutside.outset(rx, ry); | |
| 38 | |
| 39 bool miterStroke = true; | |
| 40 // For hairlines, make bevel and round joins appear the same as mitered ones
. | |
| 41 // small miter limit means right angles show bevel... | |
| 42 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || | |
| 43 stroke.getMiter() < SK_ScalarSqrt2)) { | |
| 44 miterStroke = false; | |
| 45 } | |
| 46 | |
| 47 SkRect devInside(devRect); | |
| 48 devInside.inset(rx, ry); | |
| 49 | |
| 50 // If we have a degenerate stroking rect(ie the stroke is larger than inner
rect) then we | |
| 51 // make a degenerate inside rect to avoid double hitting. We will also jam
all of the points | |
| 52 // together when we render these rects. | |
| 53 SkScalar spare; | |
| 54 { | |
| 55 SkScalar w = devRect.width() - dx; | |
| 56 SkScalar h = devRect.height() - dy; | |
| 57 spare = SkTMin(w, h); | |
| 58 } | |
| 59 | |
| 60 bool degenerate = spare <= 0; | |
| 61 if (degenerate) { | |
| 62 devInside.fLeft = devInside.fRight = devRect.centerX(); | |
| 63 devInside.fTop = devInside.fBottom = devRect.centerY(); | |
| 64 } | |
| 65 | |
| 66 SkRect devOutsideAssist(devRect); | |
| 67 | |
| 68 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) | |
| 69 // to draw the outer of the rect. Because there are 8 vertices on the outer | |
| 70 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | |
| 71 if (!miterStroke) { | |
| 72 devOutside.inset(0, ry); | |
| 73 devOutsideAssist.outset(0, ry); | |
| 74 } | |
| 75 | |
| 76 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside
Assist, devInside, | |
| 77 miterStroke, degenerate); | |
| 78 } | |
| 79 | |
| 80 GrDrawBatch* CreateAAFillNestedRects(GrColor color, | 16 GrDrawBatch* CreateAAFillNestedRects(GrColor color, |
| 81 const SkMatrix& viewMatrix, | 17 const SkMatrix& viewMatrix, |
| 82 const SkRect rects[2]) { | 18 const SkRect rects[2]) { |
| 83 SkASSERT(viewMatrix.rectStaysRect()); | 19 SkASSERT(viewMatrix.rectStaysRect()); |
| 84 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); | 20 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty()); |
| 85 | 21 |
| 86 SkRect devOutside, devInside; | 22 SkRect devOutside, devInside; |
| 87 viewMatrix.mapRect(&devOutside, rects[0]); | 23 viewMatrix.mapRect(&devOutside, rects[0]); |
| 88 viewMatrix.mapRect(&devInside, rects[1]); | 24 viewMatrix.mapRect(&devInside, rects[1]); |
| 89 | 25 |
| 90 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside
, devInside, true, | 26 return GrAAStrokeRectBatch::Create(color, viewMatrix, devOutside, devOutside
, devInside, true, |
| 91 devInside.isEmpty()); | 27 devInside.isEmpty()); |
| 92 } | 28 } |
| 93 | 29 |
| 94 }; | 30 }; |
| OLD | NEW |