commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrDashingEffect.h" |
| 9 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 10 | #include "../GrAARectRenderer.h" |
| 11 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
| 14 | #include "GrCoordTransform.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 15 | #include "GrDefaultGeoProcFactory.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 16 | #include "GrDrawTarget.h" |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 17 | #include "GrDrawTargetCaps.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 18 | #include "GrInvariantOutput.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 19 | #include "GrProcessor.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 20 | #include "GrStrokeInfo.h" |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 21 | #include "SkGr.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 22 | #include "gl/GrGLGeometryProcessor.h" |
| 23 | #include "gl/GrGLProcessor.h" |
| 24 | #include "gl/GrGLSL.h" |
| 25 | #include "gl/builders/GrGLProgramBuilder.h" |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 29 | // Returns whether or not the gpu can fast path the dash line effect. |
| 30 | static bool can_fast_path_dash(const SkPoint pts[2], const GrStrokeInfo& strokeInfo, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 31 | const GrDrawTarget& target, const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 32 | const SkMatrix& viewMatrix) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 33 | if (pipelineBuilder.getRenderTarget()->isMultisampled()) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 34 | return false; |
| 35 | } |
| 36 | |
| 37 | // Pts must be either horizontal or vertical in src space |
| 38 | if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | // May be able to relax this to include skew. As of now cannot do perspective |
| 43 | // because of the non uniform scaling of bloating a rect |
| 44 | if (!viewMatrix.preservesRightAngles()) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | if (!strokeInfo.isDashed() || 2 != strokeInfo.dashCount()) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
| 53 | if (0 == info.fIntervals[0] && 0 == info.fIntervals[1]) { |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
| 58 | // Current we do don't handle Round or Square cap dashes |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 59 | if (SkPaint::kRound_Cap == cap && info.fIntervals[0] != 0.f) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 60 | return false; |
| 61 | } |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | namespace { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 67 | struct DashLineVertex { |
| 68 | SkPoint fPos; |
| 69 | SkPoint fDashPos; |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 70 | SkScalar fIntervalLength; |
| 71 | SkRect fRect; |
| 72 | }; |
| 73 | struct DashCircleVertex { |
| 74 | SkPoint fPos; |
| 75 | SkPoint fDashPos; |
| 76 | SkScalar fIntervalLength; |
| 77 | SkScalar fRadius; |
| 78 | SkScalar fCenterX; |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 79 | }; |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 82 | static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, |
| 83 | const SkMatrix& viewMatrix, const SkPoint pts[2]) { |
| 84 | SkVector vecSrc = pts[1] - pts[0]; |
| 85 | SkScalar magSrc = vecSrc.length(); |
| 86 | SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0; |
| 87 | vecSrc.scale(invSrc); |
| 88 | |
| 89 | SkVector vecSrcPerp; |
| 90 | vecSrc.rotateCW(&vecSrcPerp); |
| 91 | viewMatrix.mapVectors(&vecSrc, 1); |
| 92 | viewMatrix.mapVectors(&vecSrcPerp, 1); |
| 93 | |
| 94 | // parallelScale tells how much to scale along the line parallel to the dash line |
| 95 | // perpScale tells how much to scale in the direction perpendicular to the dash line |
| 96 | *parallelScale = vecSrc.length(); |
| 97 | *perpScale = vecSrcPerp.length(); |
| 98 | } |
| 99 | |
| 100 | // calculates the rotation needed to aligned pts to the x axis with pts[0] < pts[1] |
| 101 | // Stores the rotation matrix in rotMatrix, and the mapped points in ptsRot |
| 102 | static void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint ptsRot[2] = NULL) { |
| 103 | SkVector vec = pts[1] - pts[0]; |
| 104 | SkScalar mag = vec.length(); |
| 105 | SkScalar inv = mag ? SkScalarInvert(mag) : 0; |
| 106 | |
| 107 | vec.scale(inv); |
| 108 | rotMatrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); |
| 109 | if (ptsRot) { |
| 110 | rotMatrix->mapPoints(ptsRot, pts, 2); |
| 111 | // correction for numerical issues if map doesn't make ptsRot exactly horizontal |
| 112 | ptsRot[1].fY = pts[0].fY; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Assumes phase < sum of all intervals |
| 117 | static SkScalar calc_start_adjustment(const SkPathEffect::DashInfo& info) { |
| 118 | SkASSERT(info.fPhase < info.fIntervals[0] + info.fIntervals[1]); |
| 119 | if (info.fPhase >= info.fIntervals[0] && info.fPhase != 0) { |
| 120 | SkScalar srcIntervalLen = info.fIntervals[0] + info.fIntervals[1]; |
| 121 | return srcIntervalLen - info.fPhase; |
| 122 | } |
| 123 | return 0; |
| 124 | } |
| 125 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 126 | static SkScalar calc_end_adjustment(const SkPathEffect::DashInfo& info, const SkPoint pts[2], |
| 127 | SkScalar phase, SkScalar* endingInt) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 128 | if (pts[1].fX <= pts[0].fX) { |
| 129 | return 0; |
| 130 | } |
| 131 | SkScalar srcIntervalLen = info.fIntervals[0] + info.fIntervals[1]; |
| 132 | SkScalar totalLen = pts[1].fX - pts[0].fX; |
| 133 | SkScalar temp = SkScalarDiv(totalLen, srcIntervalLen); |
| 134 | SkScalar numFullIntervals = SkScalarFloorToScalar(temp); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 135 | *endingInt = totalLen - numFullIntervals * srcIntervalLen + phase; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 136 | temp = SkScalarDiv(*endingInt, srcIntervalLen); |
| 137 | *endingInt = *endingInt - SkScalarFloorToScalar(temp) * srcIntervalLen; |
| 138 | if (0 == *endingInt) { |
| 139 | *endingInt = srcIntervalLen; |
| 140 | } |
| 141 | if (*endingInt > info.fIntervals[0]) { |
| 142 | if (0 == info.fIntervals[0]) { |
commit-bot@chromium.org | ad88340 | 2014-05-19 14:43:45 +0000 | [diff] [blame] | 143 | *endingInt -= 0.01f; // make sure we capture the last zero size pnt (used if has caps) |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 144 | } |
| 145 | return *endingInt - info.fIntervals[0]; |
| 146 | } |
| 147 | return 0; |
| 148 | } |
| 149 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 150 | enum DashCap { |
| 151 | kRound_DashCap, |
| 152 | kNonRound_DashCap, |
| 153 | }; |
| 154 | |
| 155 | static int kDashVertices = 4; |
| 156 | |
| 157 | template <typename T> |
| 158 | void setup_dashed_rect_common(const SkRect& rect, const SkMatrix& matrix, T* vertices, int idx, |
| 159 | SkScalar offset, SkScalar bloat, SkScalar len, SkScalar stroke) { |
| 160 | SkScalar startDashX = offset - bloat; |
| 161 | SkScalar endDashX = offset + len + bloat; |
| 162 | SkScalar startDashY = -stroke - bloat; |
| 163 | SkScalar endDashY = stroke + bloat; |
| 164 | vertices[idx].fDashPos = SkPoint::Make(startDashX , startDashY); |
| 165 | vertices[idx + 1].fDashPos = SkPoint::Make(startDashX, endDashY); |
| 166 | vertices[idx + 2].fDashPos = SkPoint::Make(endDashX, endDashY); |
| 167 | vertices[idx + 3].fDashPos = SkPoint::Make(endDashX, startDashY); |
| 168 | |
| 169 | vertices[idx].fPos = SkPoint::Make(rect.fLeft, rect.fTop); |
| 170 | vertices[idx + 1].fPos = SkPoint::Make(rect.fLeft, rect.fBottom); |
| 171 | vertices[idx + 2].fPos = SkPoint::Make(rect.fRight, rect.fBottom); |
| 172 | vertices[idx + 3].fPos = SkPoint::Make(rect.fRight, rect.fTop); |
| 173 | |
| 174 | matrix.mapPointsWithStride(&vertices[idx].fPos, sizeof(T), 4); |
| 175 | } |
| 176 | |
| 177 | static void setup_dashed_rect(const SkRect& rect, void* vertices, int idx, |
| 178 | const SkMatrix& matrix, SkScalar offset, SkScalar bloat, |
| 179 | SkScalar len, SkScalar stroke, SkScalar startInterval, |
| 180 | SkScalar endInterval, SkScalar strokeWidth, DashCap cap, |
| 181 | const size_t vertexStride) { |
| 182 | SkScalar intervalLength = startInterval + endInterval; |
| 183 | |
| 184 | if (kRound_DashCap == cap) { |
| 185 | SkASSERT(vertexStride == sizeof(DashCircleVertex)); |
| 186 | DashCircleVertex* verts = reinterpret_cast<DashCircleVertex*>(vertices); |
| 187 | |
| 188 | setup_dashed_rect_common<DashCircleVertex>(rect, matrix, verts, idx, offset, bloat, len, |
| 189 | stroke); |
| 190 | |
| 191 | SkScalar radius = SkScalarHalf(strokeWidth) - 0.5f; |
| 192 | SkScalar centerX = SkScalarHalf(endInterval); |
| 193 | |
| 194 | for (int i = 0; i < kDashVertices; i++) { |
| 195 | verts[idx + i].fIntervalLength = intervalLength; |
| 196 | verts[idx + i].fRadius = radius; |
| 197 | verts[idx + i].fCenterX = centerX; |
| 198 | } |
| 199 | |
| 200 | } else { |
| 201 | SkASSERT(kNonRound_DashCap == cap && vertexStride == sizeof(DashLineVertex)); |
| 202 | DashLineVertex* verts = reinterpret_cast<DashLineVertex*>(vertices); |
| 203 | |
| 204 | setup_dashed_rect_common<DashLineVertex>(rect, matrix, verts, idx, offset, bloat, len, |
| 205 | stroke); |
| 206 | |
| 207 | SkScalar halfOffLen = SkScalarHalf(endInterval); |
| 208 | SkScalar halfStroke = SkScalarHalf(strokeWidth); |
| 209 | SkRect rectParam; |
| 210 | rectParam.set(halfOffLen + 0.5f, -halfStroke + 0.5f, |
| 211 | halfOffLen + startInterval - 0.5f, halfStroke - 0.5f); |
| 212 | for (int i = 0; i < kDashVertices; i++) { |
| 213 | verts[idx + i].fIntervalLength = intervalLength; |
| 214 | verts[idx + i].fRect = rectParam; |
| 215 | } |
| 216 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 217 | } |
| 218 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 219 | static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& matrix, |
| 220 | SkPoint* verts) { |
| 221 | verts[idx] = SkPoint::Make(rect.fLeft, rect.fTop); |
| 222 | verts[idx + 1] = SkPoint::Make(rect.fLeft, rect.fBottom); |
| 223 | verts[idx + 2] = SkPoint::Make(rect.fRight, rect.fBottom); |
| 224 | verts[idx + 3] = SkPoint::Make(rect.fRight, rect.fTop); |
| 225 | matrix.mapPoints(&verts[idx], 4); |
| 226 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 227 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 228 | |
| 229 | /** |
| 230 | * An GrGeometryProcessor that renders a dashed line. |
| 231 | * This GrGeometryProcessor is meant for dashed lines that only have a single on/off interval pair. |
| 232 | * Bounding geometry is rendered and the effect computes coverage based on the fragment's |
| 233 | * position relative to the dashed line. |
| 234 | */ |
| 235 | static GrGeometryProcessor* create_dash_gp(GrColor, |
| 236 | GrPrimitiveEdgeType edgeType, |
| 237 | DashCap cap, |
| 238 | const SkMatrix& localMatrix); |
| 239 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 240 | bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, |
| 241 | GrPipelineBuilder* pipelineBuilder, GrColor color, |
| 242 | const SkMatrix& viewMatrix, const SkPoint pts[2], |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 243 | const GrPaint& paint, const GrStrokeInfo& strokeInfo) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 244 | if (!can_fast_path_dash(pts, strokeInfo, *target, *pipelineBuilder, viewMatrix)) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 245 | return false; |
| 246 | } |
| 247 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 248 | const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 249 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 250 | SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 251 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 252 | SkScalar srcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 253 | |
| 254 | // the phase should be normalized to be [0, sum of all intervals) |
| 255 | SkASSERT(info.fPhase >= 0 && info.fPhase < info.fIntervals[0] + info.fIntervals[1]); |
| 256 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 257 | SkScalar srcPhase = info.fPhase; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 258 | |
| 259 | // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[1].fX |
| 260 | SkMatrix srcRotInv; |
| 261 | SkPoint ptsRot[2]; |
| 262 | if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 263 | SkMatrix rotMatrix; |
| 264 | align_to_x_axis(pts, &rotMatrix, ptsRot); |
| 265 | if(!rotMatrix.invert(&srcRotInv)) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 266 | SkDebugf("Failed to create invertible rotation matrix!\n"); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 267 | return false; |
| 268 | } |
| 269 | } else { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 270 | srcRotInv.reset(); |
| 271 | memcpy(ptsRot, pts, 2 * sizeof(SkPoint)); |
| 272 | } |
| 273 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 274 | bool useAA = paint.isAntiAlias(); |
skia.committer@gmail.com | 3b9e8be | 2014-05-20 03:05:34 +0000 | [diff] [blame] | 275 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 276 | // Scale corrections of intervals and stroke from view matrix |
| 277 | SkScalar parallelScale; |
| 278 | SkScalar perpScale; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 279 | calc_dash_scaling(¶llelScale, &perpScale, viewMatrix, ptsRot); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 280 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 281 | bool hasCap = SkPaint::kButt_Cap != cap && 0 != srcStrokeWidth; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 282 | |
| 283 | // We always want to at least stroke out half a pixel on each side in device space |
| 284 | // so 0.5f / perpScale gives us this min in src space |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 285 | SkScalar halfSrcStroke = SkMaxScalar(srcStrokeWidth * 0.5f, 0.5f / perpScale); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 286 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 287 | SkScalar strokeAdj; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 288 | if (!hasCap) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 289 | strokeAdj = 0.f; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 290 | } else { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 291 | strokeAdj = halfSrcStroke; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 292 | } |
| 293 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 294 | SkScalar startAdj = 0; |
| 295 | |
| 296 | SkMatrix combinedMatrix = srcRotInv; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 297 | combinedMatrix.postConcat(viewMatrix); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 298 | |
| 299 | bool lineDone = false; |
| 300 | SkRect startRect; |
| 301 | bool hasStartRect = false; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 302 | // If we are using AA, check to see if we are drawing a partial dash at the start. If so |
| 303 | // draw it separately here and adjust our start point accordingly |
| 304 | if (useAA) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 305 | if (srcPhase > 0 && srcPhase < info.fIntervals[0]) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 306 | SkPoint startPts[2]; |
| 307 | startPts[0] = ptsRot[0]; |
| 308 | startPts[1].fY = startPts[0].fY; |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 309 | startPts[1].fX = SkMinScalar(startPts[0].fX + info.fIntervals[0] - srcPhase, |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 310 | ptsRot[1].fX); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 311 | startRect.set(startPts, 2); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 312 | startRect.outset(strokeAdj, halfSrcStroke); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 313 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 314 | hasStartRect = true; |
| 315 | startAdj = info.fIntervals[0] + info.fIntervals[1] - srcPhase; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | // adjustments for start and end of bounding rect so we only draw dash intervals |
| 320 | // contained in the original line segment. |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 321 | startAdj += calc_start_adjustment(info); |
| 322 | if (startAdj != 0) { |
| 323 | ptsRot[0].fX += startAdj; |
| 324 | srcPhase = 0; |
| 325 | } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 326 | SkScalar endingInterval = 0; |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 327 | SkScalar endAdj = calc_end_adjustment(info, ptsRot, srcPhase, &endingInterval); |
| 328 | ptsRot[1].fX -= endAdj; |
| 329 | if (ptsRot[0].fX >= ptsRot[1].fX) { |
| 330 | lineDone = true; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 331 | } |
| 332 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 333 | SkRect endRect; |
| 334 | bool hasEndRect = false; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 335 | // If we are using AA, check to see if we are drawing a partial dash at then end. If so |
| 336 | // draw it separately here and adjust our end point accordingly |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 337 | if (useAA && !lineDone) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 338 | // If we adjusted the end then we will not be drawing a partial dash at the end. |
| 339 | // If we didn't adjust the end point then we just need to make sure the ending |
| 340 | // dash isn't a full dash |
| 341 | if (0 == endAdj && endingInterval != info.fIntervals[0]) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 342 | SkPoint endPts[2]; |
| 343 | endPts[1] = ptsRot[1]; |
| 344 | endPts[0].fY = endPts[1].fY; |
skia.committer@gmail.com | 3b9e8be | 2014-05-20 03:05:34 +0000 | [diff] [blame] | 345 | endPts[0].fX = endPts[1].fX - endingInterval; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 346 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 347 | endRect.set(endPts, 2); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 348 | endRect.outset(strokeAdj, halfSrcStroke); |
skia.committer@gmail.com | 3b9e8be | 2014-05-20 03:05:34 +0000 | [diff] [blame] | 349 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 350 | hasEndRect = true; |
| 351 | endAdj = endingInterval + info.fIntervals[1]; |
| 352 | |
| 353 | ptsRot[1].fX -= endAdj; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 354 | if (ptsRot[0].fX >= ptsRot[1].fX) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 355 | lineDone = true; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 359 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 360 | if (startAdj != 0) { |
| 361 | srcPhase = 0; |
| 362 | } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 363 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 364 | // Change the dashing info from src space into device space |
| 365 | SkScalar devIntervals[2]; |
| 366 | devIntervals[0] = info.fIntervals[0] * parallelScale; |
| 367 | devIntervals[1] = info.fIntervals[1] * parallelScale; |
| 368 | SkScalar devPhase = srcPhase * parallelScale; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 369 | SkScalar strokeWidth = srcStrokeWidth * perpScale; |
| 370 | |
| 371 | if ((strokeWidth < 1.f && !useAA) || 0.f == strokeWidth) { |
| 372 | strokeWidth = 1.f; |
| 373 | } |
| 374 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 375 | SkScalar halfDevStroke = strokeWidth * 0.5f; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 376 | |
| 377 | if (SkPaint::kSquare_Cap == cap && 0 != srcStrokeWidth) { |
| 378 | // add cap to on interveal and remove from off interval |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 379 | devIntervals[0] += strokeWidth; |
| 380 | devIntervals[1] -= strokeWidth; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 381 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 382 | SkScalar startOffset = devIntervals[1] * 0.5f + devPhase; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 383 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 384 | SkScalar bloatX = useAA ? 0.5f / parallelScale : 0.f; |
| 385 | SkScalar bloatY = useAA ? 0.5f / perpScale : 0.f; |
| 386 | |
| 387 | SkScalar devBloat = useAA ? 0.5f : 0.f; |
| 388 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 389 | if (devIntervals[1] <= 0.f && useAA) { |
| 390 | // Case when we end up drawing a solid AA rect |
| 391 | // Reset the start rect to draw this single solid rect |
| 392 | // but it requires to upload a new intervals uniform so we can mimic |
| 393 | // one giant dash |
| 394 | ptsRot[0].fX -= hasStartRect ? startAdj : 0; |
| 395 | ptsRot[1].fX += hasEndRect ? endAdj : 0; |
| 396 | startRect.set(ptsRot, 2); |
| 397 | startRect.outset(strokeAdj, halfSrcStroke); |
| 398 | hasStartRect = true; |
| 399 | hasEndRect = false; |
| 400 | lineDone = true; |
| 401 | |
| 402 | SkPoint devicePts[2]; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 403 | viewMatrix.mapPoints(devicePts, ptsRot, 2); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 404 | SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); |
| 405 | if (hasCap) { |
| 406 | lineLength += 2.f * halfDevStroke; |
| 407 | } |
| 408 | devIntervals[0] = lineLength; |
| 409 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 410 | |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 411 | // reset to device coordinates |
| 412 | SkMatrix invert; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 413 | if (!viewMatrix.invert(&invert)) { |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 414 | SkDebugf("Failed to invert\n"); |
| 415 | return false; |
| 416 | } |
| 417 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 418 | bool isRoundCap = SkPaint::kRound_Cap == cap; |
| 419 | DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap; |
| 420 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 421 | SkAutoTUnref<const GrGeometryProcessor> gp; |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 422 | bool fullDash = devIntervals[1] > 0.f || useAA; |
| 423 | if (fullDash) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 424 | SkPathEffect::DashInfo devInfo; |
| 425 | devInfo.fPhase = devPhase; |
| 426 | devInfo.fCount = 2; |
| 427 | devInfo.fIntervals = devIntervals; |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 428 | GrPrimitiveEdgeType edgeType = useAA ? kFillAA_GrProcessorEdgeType : |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 429 | kFillBW_GrProcessorEdgeType; |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 430 | gp.reset(create_dash_gp(color, edgeType, capType, invert)); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 431 | } else { |
| 432 | // Set up the vertex data for the line and start/end dashes |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 433 | gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosition_GPType, |
| 434 | color, |
| 435 | SkMatrix::I(), |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 436 | invert)); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 437 | } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 438 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 439 | int totalRectCnt = 0; |
| 440 | |
| 441 | totalRectCnt += !lineDone ? 1 : 0; |
| 442 | totalRectCnt += hasStartRect ? 1 : 0; |
| 443 | totalRectCnt += hasEndRect ? 1 : 0; |
| 444 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 445 | GrDrawTarget::AutoReleaseGeometry geo(target, |
| 446 | totalRectCnt * 4, |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 447 | gp->getVertexStride(), 0); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 448 | if (!geo.succeeded()) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 449 | SkDebugf("Failed to get space for vertices!\n"); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 450 | return false; |
| 451 | } |
| 452 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 453 | int curVIdx = 0; |
| 454 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 455 | if (SkPaint::kRound_Cap == cap && 0 != srcStrokeWidth) { |
| 456 | // need to adjust this for round caps to correctly set the dashPos attrib on vertices |
| 457 | startOffset -= halfDevStroke; |
| 458 | } |
| 459 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 460 | // Draw interior part of dashed line |
| 461 | if (!lineDone) { |
| 462 | SkPoint devicePts[2]; |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 463 | viewMatrix.mapPoints(devicePts, ptsRot, 2); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 464 | SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); |
| 465 | if (hasCap) { |
| 466 | lineLength += 2.f * halfDevStroke; |
| 467 | } |
| 468 | |
| 469 | SkRect bounds; |
| 470 | bounds.set(ptsRot[0].fX, ptsRot[0].fY, ptsRot[1].fX, ptsRot[1].fY); |
| 471 | bounds.outset(bloatX + strokeAdj, bloatY + halfSrcStroke); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 472 | if (fullDash) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 473 | setup_dashed_rect(bounds, geo.vertices(), curVIdx, combinedMatrix, startOffset, |
| 474 | devBloat, lineLength, halfDevStroke, devIntervals[0], devIntervals[1], |
| 475 | strokeWidth, capType, gp->getVertexStride()); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 476 | } else { |
| 477 | SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 478 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 479 | setup_dashed_rect_pos(bounds, curVIdx, combinedMatrix, verts); |
| 480 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 481 | curVIdx += 4; |
| 482 | } |
| 483 | |
| 484 | if (hasStartRect) { |
| 485 | SkASSERT(useAA); // so that we know bloatX and bloatY have been set |
| 486 | startRect.outset(bloatX, bloatY); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 487 | if (fullDash) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 488 | setup_dashed_rect(startRect, geo.vertices(), curVIdx, combinedMatrix, startOffset, |
| 489 | devBloat, devIntervals[0], halfDevStroke, devIntervals[0], |
| 490 | devIntervals[1], strokeWidth, capType, gp->getVertexStride()); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 491 | } else { |
| 492 | SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 493 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 494 | setup_dashed_rect_pos(startRect, curVIdx, combinedMatrix, verts); |
| 495 | } |
| 496 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 497 | curVIdx += 4; |
| 498 | } |
| 499 | |
| 500 | if (hasEndRect) { |
| 501 | SkASSERT(useAA); // so that we know bloatX and bloatY have been set |
| 502 | endRect.outset(bloatX, bloatY); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 503 | if (fullDash) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 504 | setup_dashed_rect(endRect, geo.vertices(), curVIdx, combinedMatrix, startOffset, |
| 505 | devBloat, devIntervals[0], halfDevStroke, devIntervals[0], |
| 506 | devIntervals[1], strokeWidth, capType, gp->getVertexStride()); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 507 | } else { |
| 508 | SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 509 | SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 510 | setup_dashed_rect_pos(endRect, curVIdx, combinedMatrix, verts); |
| 511 | } |
| 512 | |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | target->setIndexSourceToBuffer(gpu->getContext()->getQuadIndexBuffer()); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 516 | target->drawIndexedInstances(pipelineBuilder, gp, kTriangles_GrPrimitiveType, |
| 517 | totalRectCnt, 4, 6); |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 518 | target->resetIndexSource(); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 519 | return true; |
| 520 | } |
| 521 | |
| 522 | ////////////////////////////////////////////////////////////////////////////// |
| 523 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 524 | class GLDashingCircleEffect; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 525 | |
| 526 | struct DashingCircleBatchTracker { |
| 527 | GrGPInput fInputColorType; |
| 528 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 529 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 530 | }; |
| 531 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 532 | /* |
| 533 | * This effect will draw a dotted line (defined as a dashed lined with round caps and no on |
| 534 | * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. |
| 535 | * Both of the previous two parameters are in device space. This effect also requires the setting of |
| 536 | * a vec2 vertex attribute for the the four corners of the bounding rect. This attribute is the |
| 537 | * "dash position" of each vertex. In other words it is the vertex coords (in device space) if we |
| 538 | * transform the line to be horizontal, with the start of line at the origin then shifted to the |
| 539 | * right by half the off interval. The line then goes in the positive x direction. |
| 540 | */ |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 541 | class DashingCircleEffect : public GrGeometryProcessor { |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 542 | public: |
| 543 | typedef SkPathEffect::DashInfo DashInfo; |
| 544 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 545 | static GrGeometryProcessor* Create(GrColor, |
| 546 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 547 | const SkMatrix& localMatrix); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 548 | |
| 549 | virtual ~DashingCircleEffect(); |
| 550 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 551 | const char* name() const SK_OVERRIDE { return "DashingCircleEffect"; } |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 552 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 553 | const Attribute* inPosition() const { return fInPosition; } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 554 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 555 | const Attribute* inDashParams() const { return fInDashParams; } |
| 556 | |
| 557 | const Attribute* inCircleParams() const { return fInCircleParams; } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 558 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 559 | GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 560 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 561 | virtual void getGLProcessorKey(const GrBatchTracker&, |
| 562 | const GrGLCaps&, |
| 563 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 564 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 565 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker&, |
| 566 | const GrGLCaps&) const SK_OVERRIDE; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 567 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 568 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const SK_OVERRIDE; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 569 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 570 | bool onCanMakeEqual(const GrBatchTracker&, |
| 571 | const GrGeometryProcessor&, |
| 572 | const GrBatchTracker&) const SK_OVERRIDE; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 573 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 574 | private: |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 575 | DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 576 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 577 | bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 578 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 579 | void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 580 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 581 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 582 | const Attribute* fInPosition; |
| 583 | const Attribute* fInDashParams; |
| 584 | const Attribute* fInCircleParams; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 585 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 586 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 587 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 588 | typedef GrGeometryProcessor INHERITED; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 589 | }; |
| 590 | |
| 591 | ////////////////////////////////////////////////////////////////////////////// |
| 592 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 593 | class GLDashingCircleEffect : public GrGLGeometryProcessor { |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 594 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 595 | GLDashingCircleEffect(const GrGeometryProcessor&, const GrBatchTracker&); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 596 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 597 | void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 598 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 599 | static inline void GenKey(const GrGeometryProcessor&, |
| 600 | const GrBatchTracker&, |
| 601 | const GrGLCaps&, |
| 602 | GrProcessorKeyBuilder*); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 603 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 604 | virtual void setData(const GrGLProgramDataManager&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 605 | const GrPrimitiveProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 606 | const GrBatchTracker&) SK_OVERRIDE; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 607 | |
| 608 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 609 | UniformHandle fParamUniform; |
| 610 | UniformHandle fColorUniform; |
| 611 | GrColor fColor; |
| 612 | SkScalar fPrevRadius; |
| 613 | SkScalar fPrevCenterX; |
| 614 | SkScalar fPrevIntervalLength; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 615 | typedef GrGLGeometryProcessor INHERITED; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 616 | }; |
| 617 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 618 | GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, |
| 619 | const GrBatchTracker&) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 620 | fColor = GrColor_ILLEGAL; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 621 | fPrevRadius = SK_ScalarMin; |
| 622 | fPrevCenterX = SK_ScalarMin; |
| 623 | fPrevIntervalLength = SK_ScalarMax; |
| 624 | } |
| 625 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 626 | void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 627 | const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 628 | const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTracker>(); |
| 629 | GrGLGPBuilder* pb = args.fPB; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 630 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 631 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 632 | // emit attributes |
| 633 | vsBuilder->emitAttributes(dce); |
| 634 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 635 | // XY are dashPos, Z is dashInterval |
| 636 | GrGLVertToFrag dashParams(kVec3f_GrSLType); |
| 637 | args.fPB->addVarying("DashParam", &dashParams); |
| 638 | vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->fName); |
| 639 | |
| 640 | // xy, refer to circle radius - 0.5, z refers to cicles center x coord |
| 641 | GrGLVertToFrag circleParams(kVec2f_GrSLType); |
| 642 | args.fPB->addVarying("CircleParams", &circleParams); |
| 643 | vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams()->fName); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 644 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 645 | // Setup pass through color |
| 646 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, &fColorUniform); |
| 647 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 648 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame^] | 649 | this->setupPosition(pb, gpArgs, dce.inPosition()->fName, dce.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 650 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 651 | // emit transforms |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 652 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName, dce.localMatrix(), |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 653 | args.fTransformsIn, args.fTransformsOut); |
| 654 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 655 | // transforms all points so that we can compare them to our test circle |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 656 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 657 | fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", |
| 658 | dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn(), |
| 659 | dashParams.fsIn()); |
| 660 | fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashParams.fsIn()); |
| 661 | fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn()); |
| 662 | fsBuilder->codeAppend("float dist = length(center - fragPosShifted);"); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 663 | if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 664 | fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn()); |
| 665 | fsBuilder->codeAppend("diff = 1.0 - diff;"); |
| 666 | fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 667 | } else { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 668 | fsBuilder->codeAppendf("float alpha = 1.0;"); |
| 669 | fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circleParams.fsIn()); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 670 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 671 | fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 672 | } |
| 673 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 674 | void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 675 | const GrPrimitiveProcessor& processor, |
| 676 | const GrBatchTracker& bt) { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 677 | this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
| 678 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 679 | const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(); |
| 680 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 681 | GrGLfloat c[4]; |
| 682 | GrColorToRGBAFloat(local.fColor, c); |
| 683 | pdman.set4fv(fColorUniform, 1, c); |
| 684 | fColor = local.fColor; |
| 685 | } |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 686 | } |
| 687 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 688 | void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 689 | const GrBatchTracker& bt, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 690 | const GrGLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 691 | GrProcessorKeyBuilder* b) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 692 | const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 693 | const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); |
| 694 | uint32_t key = 0; |
| 695 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0; |
| 696 | key |= ComputePosKey(gp.viewMatrix()) << 1; |
| 697 | key |= dce.getEdgeType() << 8; |
| 698 | b->add32(key << 16 | local.fInputColorType); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | ////////////////////////////////////////////////////////////////////////////// |
| 702 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 703 | GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, |
| 704 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 705 | const SkMatrix& localMatrix) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 706 | return SkNEW_ARGS(DashingCircleEffect, (color, edgeType, localMatrix)); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | DashingCircleEffect::~DashingCircleEffect() {} |
| 710 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 711 | void DashingCircleEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const { |
| 712 | out->setUnknownSingleComponent(); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 713 | } |
| 714 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 715 | void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 716 | const GrGLCaps& caps, |
| 717 | GrProcessorKeyBuilder* b) const { |
| 718 | GLDashingCircleEffect::GenKey(*this, bt, caps, b); |
| 719 | } |
| 720 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 721 | GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracker& bt, |
| 722 | const GrGLCaps&) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 723 | return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 724 | } |
| 725 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 726 | DashingCircleEffect::DashingCircleEffect(GrColor color, |
| 727 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 728 | const SkMatrix& localMatrix) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 729 | : INHERITED(color, SkMatrix::I(), localMatrix), fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 730 | this->initClassID<DashingCircleEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 731 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 732 | fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVertexAttribType)); |
| 733 | fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams", |
| 734 | kVec2f_GrVertexAttribType)); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 735 | } |
| 736 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 737 | bool DashingCircleEffect::onIsEqual(const GrGeometryProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 738 | const DashingCircleEffect& dce = other.cast<DashingCircleEffect>(); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 739 | return fEdgeType == dce.fEdgeType; |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 740 | } |
| 741 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 742 | void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 743 | DashingCircleBatchTracker* local = bt->cast<DashingCircleBatchTracker>(); |
| 744 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 745 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 746 | } |
| 747 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 748 | bool DashingCircleEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 749 | const GrGeometryProcessor& that, |
| 750 | const GrBatchTracker& t) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 751 | const DashingCircleBatchTracker& mine = m.cast<DashingCircleBatchTracker>(); |
| 752 | const DashingCircleBatchTracker& theirs = t.cast<DashingCircleBatchTracker>(); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 753 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 754 | that, theirs.fUsesLocalCoords) && |
| 755 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 756 | theirs.fInputColorType, theirs.fColor); |
| 757 | } |
| 758 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 759 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 760 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 761 | GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, |
| 762 | GrContext*, |
| 763 | const GrDrawTargetCaps& caps, |
| 764 | GrTexture*[]) { |
| 765 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->nextULessThan( |
| 766 | kGrProcessorEdgeTypeCnt)); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 767 | return DashingCircleEffect::Create(GrRandomColor(random), |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 768 | edgeType, GrProcessorUnitTest::TestMatrix(random)); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | ////////////////////////////////////////////////////////////////////////////// |
| 772 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 773 | class GLDashingLineEffect; |
| 774 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 775 | struct DashingLineBatchTracker { |
| 776 | GrGPInput fInputColorType; |
| 777 | GrColor fColor; |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 778 | bool fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 779 | }; |
| 780 | |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 781 | /* |
| 782 | * This effect will draw a dashed line. The width of the dash is given by the strokeWidth and the |
| 783 | * length and spacing by the DashInfo. Both of the previous two parameters are in device space. |
| 784 | * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the |
| 785 | * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the |
| 786 | * vertex coords (in device space) if we transform the line to be horizontal, with the start of |
| 787 | * line at the origin then shifted to the right by half the off interval. The line then goes in the |
| 788 | * positive x direction. |
| 789 | */ |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 790 | class DashingLineEffect : public GrGeometryProcessor { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 791 | public: |
| 792 | typedef SkPathEffect::DashInfo DashInfo; |
| 793 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 794 | static GrGeometryProcessor* Create(GrColor, |
| 795 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 796 | const SkMatrix& localMatrix); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 797 | |
| 798 | virtual ~DashingLineEffect(); |
| 799 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 800 | const char* name() const SK_OVERRIDE { return "DashingEffect"; } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 801 | |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 802 | const Attribute* inPosition() const { return fInPosition; } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 803 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 804 | const Attribute* inDashParams() const { return fInDashParams; } |
| 805 | |
| 806 | const Attribute* inRectParams() const { return fInRectParams; } |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 807 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 808 | GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 809 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 810 | virtual void getGLProcessorKey(const GrBatchTracker& bt, |
| 811 | const GrGLCaps& caps, |
| 812 | GrProcessorKeyBuilder* b) const SK_OVERRIDE; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 813 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 814 | virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
| 815 | const GrGLCaps&) const SK_OVERRIDE; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 816 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 817 | void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const SK_OVERRIDE; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 818 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 819 | bool onCanMakeEqual(const GrBatchTracker&, |
| 820 | const GrGeometryProcessor&, |
| 821 | const GrBatchTracker&) const SK_OVERRIDE; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 822 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 823 | private: |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 824 | DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const SkMatrix& localMatrix); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 825 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 826 | bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 827 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 828 | void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_OVERRIDE; |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 829 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 830 | GrPrimitiveEdgeType fEdgeType; |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 831 | const Attribute* fInPosition; |
| 832 | const Attribute* fInDashParams; |
| 833 | const Attribute* fInRectParams; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 834 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 835 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 836 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 837 | typedef GrGeometryProcessor INHERITED; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 838 | }; |
| 839 | |
| 840 | ////////////////////////////////////////////////////////////////////////////// |
| 841 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 842 | class GLDashingLineEffect : public GrGLGeometryProcessor { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 843 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 844 | GLDashingLineEffect(const GrGeometryProcessor&, const GrBatchTracker&); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 845 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 846 | void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 847 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 848 | static inline void GenKey(const GrGeometryProcessor&, |
| 849 | const GrBatchTracker&, |
| 850 | const GrGLCaps&, |
| 851 | GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 852 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 853 | virtual void setData(const GrGLProgramDataManager&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 854 | const GrPrimitiveProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 855 | const GrBatchTracker&) SK_OVERRIDE; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 856 | |
| 857 | private: |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 858 | GrColor fColor; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 859 | UniformHandle fColorUniform; |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 860 | typedef GrGLGeometryProcessor INHERITED; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 861 | }; |
| 862 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 863 | GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, |
| 864 | const GrBatchTracker&) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 865 | fColor = GrColor_ILLEGAL; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 866 | } |
| 867 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 868 | void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 869 | const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 870 | const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker>(); |
| 871 | GrGLGPBuilder* pb = args.fPB; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 872 | |
| 873 | GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 874 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 875 | // emit attributes |
| 876 | vsBuilder->emitAttributes(de); |
| 877 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 878 | // XY refers to dashPos, Z is the dash interval length |
| 879 | GrGLVertToFrag inDashParams(kVec3f_GrSLType); |
| 880 | args.fPB->addVarying("DashParams", &inDashParams); |
| 881 | vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->fName); |
| 882 | |
| 883 | // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5), |
| 884 | // respectively. |
| 885 | GrGLVertToFrag inRectParams(kVec4f_GrSLType); |
| 886 | args.fPB->addVarying("RectParams", &inRectParams); |
| 887 | vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->fName); |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 888 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 889 | // Setup pass through color |
| 890 | this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL, &fColorUniform); |
| 891 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 892 | // Setup position |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame^] | 893 | this->setupPosition(pb, gpArgs, de.inPosition()->fName, de.viewMatrix()); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 894 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 895 | // emit transforms |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 896 | this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(), |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 897 | args.fTransformsIn, args.fTransformsOut); |
| 898 | |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 899 | // transforms all points so that we can compare them to our test rect |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 900 | GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 901 | fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", |
| 902 | inDashParams.fsIn(), inDashParams.fsIn(), inDashParams.fsIn(), |
| 903 | inDashParams.fsIn()); |
| 904 | fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDashParams.fsIn()); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 905 | if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 906 | // The amount of coverage removed in x and y by the edges is computed as a pair of negative |
| 907 | // numbers, xSub and ySub. |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 908 | fsBuilder->codeAppend("float xSub, ySub;"); |
| 909 | fsBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", inRectParams.fsIn()); |
| 910 | fsBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", inRectParams.fsIn()); |
| 911 | fsBuilder->codeAppendf("ySub = min(fragPosShifted.y - %s.y, 0.0);", inRectParams.fsIn()); |
| 912 | fsBuilder->codeAppendf("ySub += min(%s.w - fragPosShifted.y, 0.0);", inRectParams.fsIn()); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 913 | // Now compute coverage in x and y and multiply them to get the fraction of the pixel |
| 914 | // covered. |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 915 | fsBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));"); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 916 | } else { |
| 917 | // Assuming the bounding geometry is tight so no need to check y values |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 918 | fsBuilder->codeAppendf("float alpha = 1.0;"); |
| 919 | fsBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;", |
| 920 | inRectParams.fsIn()); |
| 921 | fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;", |
| 922 | inRectParams.fsIn()); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 923 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 924 | fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 925 | } |
| 926 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 927 | void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 928 | const GrPrimitiveProcessor& processor, |
| 929 | const GrBatchTracker& bt) { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 930 | this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
| 931 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 932 | const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); |
| 933 | if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 934 | GrGLfloat c[4]; |
| 935 | GrColorToRGBAFloat(local.fColor, c); |
| 936 | pdman.set4fv(fColorUniform, 1, c); |
| 937 | fColor = local.fColor; |
| 938 | } |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 939 | } |
| 940 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 941 | void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 942 | const GrBatchTracker& bt, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 943 | const GrGLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 944 | GrProcessorKeyBuilder* b) { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 945 | const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 946 | const DashingLineEffect& de = gp.cast<DashingLineEffect>(); |
| 947 | uint32_t key = 0; |
| 948 | key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0; |
| 949 | key |= ComputePosKey(gp.viewMatrix()) << 1; |
| 950 | key |= de.getEdgeType() << 8; |
| 951 | b->add32(key << 16 | local.fInputColorType); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | ////////////////////////////////////////////////////////////////////////////// |
skia.committer@gmail.com | 3b9e8be | 2014-05-20 03:05:34 +0000 | [diff] [blame] | 955 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 956 | GrGeometryProcessor* DashingLineEffect::Create(GrColor color, |
| 957 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 958 | const SkMatrix& localMatrix) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 959 | return SkNEW_ARGS(DashingLineEffect, (color, edgeType, localMatrix)); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | DashingLineEffect::~DashingLineEffect() {} |
| 963 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 964 | void DashingLineEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const { |
| 965 | out->setUnknownSingleComponent(); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 966 | } |
| 967 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 968 | void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, |
| 969 | const GrGLCaps& caps, |
| 970 | GrProcessorKeyBuilder* b) const { |
| 971 | GLDashingLineEffect::GenKey(*this, bt, caps, b); |
| 972 | } |
| 973 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 974 | GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker& bt, |
| 975 | const GrGLCaps&) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 976 | return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 977 | } |
| 978 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 979 | DashingLineEffect::DashingLineEffect(GrColor color, |
| 980 | GrPrimitiveEdgeType edgeType, |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 981 | const SkMatrix& localMatrix) |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 982 | : INHERITED(color, SkMatrix::I(), localMatrix), fEdgeType(edgeType) { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 983 | this->initClassID<DashingLineEffect>(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 984 | fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType)); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 985 | fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVertexAttribType)); |
| 986 | fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAttribType)); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 987 | } |
| 988 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 989 | bool DashingLineEffect::onIsEqual(const GrGeometryProcessor& other) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 990 | const DashingLineEffect& de = other.cast<DashingLineEffect>(); |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 991 | return fEdgeType == de.fEdgeType; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 992 | } |
| 993 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 994 | void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 995 | DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>(); |
| 996 | local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 997 | local->fUsesLocalCoords = init.fUsesLocalCoords; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 998 | } |
| 999 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 1000 | bool DashingLineEffect::onCanMakeEqual(const GrBatchTracker& m, |
| 1001 | const GrGeometryProcessor& that, |
| 1002 | const GrBatchTracker& t) const { |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 1003 | const DashingLineBatchTracker& mine = m.cast<DashingLineBatchTracker>(); |
| 1004 | const DashingLineBatchTracker& theirs = t.cast<DashingLineBatchTracker>(); |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 1005 | return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
| 1006 | that, theirs.fUsesLocalCoords) && |
| 1007 | CanCombineOutput(mine.fInputColorType, mine.fColor, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 1008 | theirs.fInputColorType, theirs.fColor); |
| 1009 | } |
| 1010 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1011 | GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 1012 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1013 | GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, |
| 1014 | GrContext*, |
| 1015 | const GrDrawTargetCaps& caps, |
| 1016 | GrTexture*[]) { |
| 1017 | GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(random->nextULessThan( |
| 1018 | kGrProcessorEdgeTypeCnt)); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 1019 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 1020 | return DashingLineEffect::Create(GrRandomColor(random), |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 1021 | edgeType, GrProcessorUnitTest::TestMatrix(random)); |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | ////////////////////////////////////////////////////////////////////////////// |
| 1025 | |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 1026 | static GrGeometryProcessor* create_dash_gp(GrColor color, |
| 1027 | GrPrimitiveEdgeType edgeType, |
| 1028 | DashCap cap, |
| 1029 | const SkMatrix& localMatrix) { |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 1030 | switch (cap) { |
joshualitt | 5224ba7 | 2015-02-03 15:07:51 -0800 | [diff] [blame] | 1031 | case kRound_DashCap: |
| 1032 | return DashingCircleEffect::Create(color, edgeType, localMatrix); |
| 1033 | case kNonRound_DashCap: |
| 1034 | return DashingLineEffect::Create(color, edgeType, localMatrix); |
egdaniel | f767e79 | 2014-07-02 06:21:32 -0700 | [diff] [blame] | 1035 | default: |
| 1036 | SkFAIL("Unexpected dashed cap."); |
| 1037 | } |
| 1038 | return NULL; |
commit-bot@chromium.org | 628ed0b | 2014-05-19 14:32:49 +0000 | [diff] [blame] | 1039 | } |