GrAAHairLinePathRenderer.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. /*
  2. * Copyright 2011 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. #include "include/core/SkPoint3.h"
  8. #include "include/private/SkTemplates.h"
  9. #include "src/core/SkGeometry.h"
  10. #include "src/core/SkMatrixPriv.h"
  11. #include "src/core/SkPointPriv.h"
  12. #include "src/core/SkRectPriv.h"
  13. #include "src/core/SkStroke.h"
  14. #include "src/gpu/GrAuditTrail.h"
  15. #include "src/gpu/GrBuffer.h"
  16. #include "src/gpu/GrCaps.h"
  17. #include "src/gpu/GrClip.h"
  18. #include "src/gpu/GrDefaultGeoProcFactory.h"
  19. #include "src/gpu/GrDrawOpTest.h"
  20. #include "src/gpu/GrOpFlushState.h"
  21. #include "src/gpu/GrProcessor.h"
  22. #include "src/gpu/GrResourceProvider.h"
  23. #include "src/gpu/GrStyle.h"
  24. #include "src/gpu/effects/GrBezierEffect.h"
  25. #include "src/gpu/geometry/GrPathUtils.h"
  26. #include "src/gpu/geometry/GrShape.h"
  27. #include "src/gpu/ops/GrAAHairLinePathRenderer.h"
  28. #include "src/gpu/ops/GrMeshDrawOp.h"
  29. #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
  30. #define PREALLOC_PTARRAY(N) SkSTArray<(N),SkPoint, true>
  31. // quadratics are rendered as 5-sided polys in order to bound the
  32. // AA stroke around the center-curve. See comments in push_quad_index_buffer and
  33. // bloat_quad. Quadratics and conics share an index buffer
  34. // lines are rendered as:
  35. // *______________*
  36. // |\ -_______ /|
  37. // | \ \ / |
  38. // | *--------* |
  39. // | / ______/ \ |
  40. // */_-__________\*
  41. // For: 6 vertices and 18 indices (for 6 triangles)
  42. // Each quadratic is rendered as a five sided polygon. This poly bounds
  43. // the quadratic's bounding triangle but has been expanded so that the
  44. // 1-pixel wide area around the curve is inside the poly.
  45. // If a,b,c are the original control points then the poly a0,b0,c0,c1,a1
  46. // that is rendered would look like this:
  47. // b0
  48. // b
  49. //
  50. // a0 c0
  51. // a c
  52. // a1 c1
  53. // Each is drawn as three triangles ((a0,a1,b0), (b0,c1,c0), (a1,c1,b0))
  54. // specified by these 9 indices:
  55. static const uint16_t kQuadIdxBufPattern[] = {
  56. 0, 1, 2,
  57. 2, 4, 3,
  58. 1, 4, 2
  59. };
  60. static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern);
  61. static const int kQuadNumVertices = 5;
  62. static const int kQuadsNumInIdxBuffer = 256;
  63. GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
  64. static sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) {
  65. GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
  66. return resourceProvider->findOrCreatePatternedIndexBuffer(
  67. kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices,
  68. gQuadsIndexBufferKey);
  69. }
  70. // Each line segment is rendered as two quads and two triangles.
  71. // p0 and p1 have alpha = 1 while all other points have alpha = 0.
  72. // The four external points are offset 1 pixel perpendicular to the
  73. // line and half a pixel parallel to the line.
  74. //
  75. // p4 p5
  76. // p0 p1
  77. // p2 p3
  78. //
  79. // Each is drawn as six triangles specified by these 18 indices:
  80. static const uint16_t kLineSegIdxBufPattern[] = {
  81. 0, 1, 3,
  82. 0, 3, 2,
  83. 0, 4, 5,
  84. 0, 5, 1,
  85. 0, 2, 4,
  86. 1, 5, 3
  87. };
  88. static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern);
  89. static const int kLineSegNumVertices = 6;
  90. static const int kLineSegsNumInIdxBuffer = 256;
  91. GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
  92. static sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) {
  93. GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
  94. return resourceProvider->findOrCreatePatternedIndexBuffer(
  95. kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices,
  96. gLinesIndexBufferKey);
  97. }
  98. // Takes 178th time of logf on Z600 / VC2010
  99. static int get_float_exp(float x) {
  100. GR_STATIC_ASSERT(sizeof(int) == sizeof(float));
  101. #ifdef SK_DEBUG
  102. static bool tested;
  103. if (!tested) {
  104. tested = true;
  105. SkASSERT(get_float_exp(0.25f) == -2);
  106. SkASSERT(get_float_exp(0.3f) == -2);
  107. SkASSERT(get_float_exp(0.5f) == -1);
  108. SkASSERT(get_float_exp(1.f) == 0);
  109. SkASSERT(get_float_exp(2.f) == 1);
  110. SkASSERT(get_float_exp(2.5f) == 1);
  111. SkASSERT(get_float_exp(8.f) == 3);
  112. SkASSERT(get_float_exp(100.f) == 6);
  113. SkASSERT(get_float_exp(1000.f) == 9);
  114. SkASSERT(get_float_exp(1024.f) == 10);
  115. SkASSERT(get_float_exp(3000000.f) == 21);
  116. }
  117. #endif
  118. const int* iptr = (const int*)&x;
  119. return (((*iptr) & 0x7f800000) >> 23) - 127;
  120. }
  121. // Uses the max curvature function for quads to estimate
  122. // where to chop the conic. If the max curvature is not
  123. // found along the curve segment it will return 1 and
  124. // dst[0] is the original conic. If it returns 2 the dst[0]
  125. // and dst[1] are the two new conics.
  126. static int split_conic(const SkPoint src[3], SkConic dst[2], const SkScalar weight) {
  127. SkScalar t = SkFindQuadMaxCurvature(src);
  128. if (t == 0 || t == 1) {
  129. if (dst) {
  130. dst[0].set(src, weight);
  131. }
  132. return 1;
  133. } else {
  134. if (dst) {
  135. SkConic conic;
  136. conic.set(src, weight);
  137. if (!conic.chopAt(t, dst)) {
  138. dst[0].set(src, weight);
  139. return 1;
  140. }
  141. }
  142. return 2;
  143. }
  144. }
  145. // Calls split_conic on the entire conic and then once more on each subsection.
  146. // Most cases will result in either 1 conic (chop point is not within t range)
  147. // or 3 points (split once and then one subsection is split again).
  148. static int chop_conic(const SkPoint src[3], SkConic dst[4], const SkScalar weight) {
  149. SkConic dstTemp[2];
  150. int conicCnt = split_conic(src, dstTemp, weight);
  151. if (2 == conicCnt) {
  152. int conicCnt2 = split_conic(dstTemp[0].fPts, dst, dstTemp[0].fW);
  153. conicCnt = conicCnt2 + split_conic(dstTemp[1].fPts, &dst[conicCnt2], dstTemp[1].fW);
  154. } else {
  155. dst[0] = dstTemp[0];
  156. }
  157. return conicCnt;
  158. }
  159. // returns 0 if quad/conic is degen or close to it
  160. // in this case approx the path with lines
  161. // otherwise returns 1
  162. static int is_degen_quad_or_conic(const SkPoint p[3], SkScalar* dsqd) {
  163. static const SkScalar gDegenerateToLineTol = GrPathUtils::kDefaultTolerance;
  164. static const SkScalar gDegenerateToLineTolSqd =
  165. gDegenerateToLineTol * gDegenerateToLineTol;
  166. if (SkPointPriv::DistanceToSqd(p[0], p[1]) < gDegenerateToLineTolSqd ||
  167. SkPointPriv::DistanceToSqd(p[1], p[2]) < gDegenerateToLineTolSqd) {
  168. return 1;
  169. }
  170. *dsqd = SkPointPriv::DistanceToLineBetweenSqd(p[1], p[0], p[2]);
  171. if (*dsqd < gDegenerateToLineTolSqd) {
  172. return 1;
  173. }
  174. if (SkPointPriv::DistanceToLineBetweenSqd(p[2], p[1], p[0]) < gDegenerateToLineTolSqd) {
  175. return 1;
  176. }
  177. return 0;
  178. }
  179. static int is_degen_quad_or_conic(const SkPoint p[3]) {
  180. SkScalar dsqd;
  181. return is_degen_quad_or_conic(p, &dsqd);
  182. }
  183. // we subdivide the quads to avoid huge overfill
  184. // if it returns -1 then should be drawn as lines
  185. static int num_quad_subdivs(const SkPoint p[3]) {
  186. SkScalar dsqd;
  187. if (is_degen_quad_or_conic(p, &dsqd)) {
  188. return -1;
  189. }
  190. // tolerance of triangle height in pixels
  191. // tuned on windows Quadro FX 380 / Z600
  192. // trade off of fill vs cpu time on verts
  193. // maybe different when do this using gpu (geo or tess shaders)
  194. static const SkScalar gSubdivTol = 175 * SK_Scalar1;
  195. if (dsqd <= gSubdivTol * gSubdivTol) {
  196. return 0;
  197. } else {
  198. static const int kMaxSub = 4;
  199. // subdividing the quad reduces d by 4. so we want x = log4(d/tol)
  200. // = log4(d*d/tol*tol)/2
  201. // = log2(d*d/tol*tol)
  202. // +1 since we're ignoring the mantissa contribution.
  203. int log = get_float_exp(dsqd/(gSubdivTol*gSubdivTol)) + 1;
  204. log = SkTMin(SkTMax(0, log), kMaxSub);
  205. return log;
  206. }
  207. }
  208. /**
  209. * Generates the lines and quads to be rendered. Lines are always recorded in
  210. * device space. We will do a device space bloat to account for the 1pixel
  211. * thickness.
  212. * Quads are recorded in device space unless m contains
  213. * perspective, then in they are in src space. We do this because we will
  214. * subdivide large quads to reduce over-fill. This subdivision has to be
  215. * performed before applying the perspective matrix.
  216. */
  217. static int gather_lines_and_quads(const SkPath& path,
  218. const SkMatrix& m,
  219. const SkIRect& devClipBounds,
  220. SkScalar capLength,
  221. bool convertConicsToQuads,
  222. GrAAHairLinePathRenderer::PtArray* lines,
  223. GrAAHairLinePathRenderer::PtArray* quads,
  224. GrAAHairLinePathRenderer::PtArray* conics,
  225. GrAAHairLinePathRenderer::IntArray* quadSubdivCnts,
  226. GrAAHairLinePathRenderer::FloatArray* conicWeights) {
  227. SkPath::Iter iter(path, false);
  228. int totalQuadCount = 0;
  229. SkRect bounds;
  230. SkIRect ibounds;
  231. bool persp = m.hasPerspective();
  232. // Whenever a degenerate, zero-length contour is encountered, this code will insert a
  233. // 'capLength' x-aligned line segment. Since this is rendering hairlines it is hoped this will
  234. // suffice for AA square & circle capping.
  235. int verbsInContour = 0; // Does not count moves
  236. bool seenZeroLengthVerb = false;
  237. SkPoint zeroVerbPt;
  238. // Adds a quad that has already been chopped to the list and checks for quads that are close to
  239. // lines. Also does a bounding box check. It takes points that are in src space and device
  240. // space. The src points are only required if the view matrix has perspective.
  241. auto addChoppedQuad = [&](const SkPoint srcPts[3], const SkPoint devPts[4],
  242. bool isContourStart) {
  243. SkRect bounds;
  244. SkIRect ibounds;
  245. bounds.setBounds(devPts, 3);
  246. bounds.outset(SK_Scalar1, SK_Scalar1);
  247. bounds.roundOut(&ibounds);
  248. // We only need the src space space pts when not in perspective.
  249. SkASSERT(srcPts || !persp);
  250. if (SkIRect::Intersects(devClipBounds, ibounds)) {
  251. int subdiv = num_quad_subdivs(devPts);
  252. SkASSERT(subdiv >= -1);
  253. if (-1 == subdiv) {
  254. SkPoint* pts = lines->push_back_n(4);
  255. pts[0] = devPts[0];
  256. pts[1] = devPts[1];
  257. pts[2] = devPts[1];
  258. pts[3] = devPts[2];
  259. if (isContourStart && pts[0] == pts[1] && pts[2] == pts[3]) {
  260. seenZeroLengthVerb = true;
  261. zeroVerbPt = pts[0];
  262. }
  263. } else {
  264. // when in perspective keep quads in src space
  265. const SkPoint* qPts = persp ? srcPts : devPts;
  266. SkPoint* pts = quads->push_back_n(3);
  267. pts[0] = qPts[0];
  268. pts[1] = qPts[1];
  269. pts[2] = qPts[2];
  270. quadSubdivCnts->push_back() = subdiv;
  271. totalQuadCount += 1 << subdiv;
  272. }
  273. }
  274. };
  275. // Applies the view matrix to quad src points and calls the above helper.
  276. auto addSrcChoppedQuad = [&](const SkPoint srcSpaceQuadPts[3], bool isContourStart) {
  277. SkPoint devPts[3];
  278. m.mapPoints(devPts, srcSpaceQuadPts, 3);
  279. addChoppedQuad(srcSpaceQuadPts, devPts, isContourStart);
  280. };
  281. for (;;) {
  282. SkPoint pathPts[4];
  283. SkPath::Verb verb = iter.next(pathPts, false);
  284. switch (verb) {
  285. case SkPath::kConic_Verb:
  286. if (convertConicsToQuads) {
  287. SkScalar weight = iter.conicWeight();
  288. SkAutoConicToQuads converter;
  289. const SkPoint* quadPts = converter.computeQuads(pathPts, weight, 0.25f);
  290. for (int i = 0; i < converter.countQuads(); ++i) {
  291. addSrcChoppedQuad(quadPts + 2 * i, !verbsInContour && 0 == i);
  292. }
  293. } else {
  294. SkConic dst[4];
  295. // We chop the conics to create tighter clipping to hide error
  296. // that appears near max curvature of very thin conics. Thin
  297. // hyperbolas with high weight still show error.
  298. int conicCnt = chop_conic(pathPts, dst, iter.conicWeight());
  299. for (int i = 0; i < conicCnt; ++i) {
  300. SkPoint devPts[4];
  301. SkPoint* chopPnts = dst[i].fPts;
  302. m.mapPoints(devPts, chopPnts, 3);
  303. bounds.setBounds(devPts, 3);
  304. bounds.outset(SK_Scalar1, SK_Scalar1);
  305. bounds.roundOut(&ibounds);
  306. if (SkIRect::Intersects(devClipBounds, ibounds)) {
  307. if (is_degen_quad_or_conic(devPts)) {
  308. SkPoint* pts = lines->push_back_n(4);
  309. pts[0] = devPts[0];
  310. pts[1] = devPts[1];
  311. pts[2] = devPts[1];
  312. pts[3] = devPts[2];
  313. if (verbsInContour == 0 && i == 0 && pts[0] == pts[1] &&
  314. pts[2] == pts[3]) {
  315. seenZeroLengthVerb = true;
  316. zeroVerbPt = pts[0];
  317. }
  318. } else {
  319. // when in perspective keep conics in src space
  320. SkPoint* cPts = persp ? chopPnts : devPts;
  321. SkPoint* pts = conics->push_back_n(3);
  322. pts[0] = cPts[0];
  323. pts[1] = cPts[1];
  324. pts[2] = cPts[2];
  325. conicWeights->push_back() = dst[i].fW;
  326. }
  327. }
  328. }
  329. }
  330. verbsInContour++;
  331. break;
  332. case SkPath::kMove_Verb:
  333. // New contour (and last one was unclosed). If it was just a zero length drawing
  334. // operation, and we're supposed to draw caps, then add a tiny line.
  335. if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) {
  336. SkPoint* pts = lines->push_back_n(2);
  337. pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
  338. pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
  339. }
  340. verbsInContour = 0;
  341. seenZeroLengthVerb = false;
  342. break;
  343. case SkPath::kLine_Verb: {
  344. SkPoint devPts[2];
  345. m.mapPoints(devPts, pathPts, 2);
  346. bounds.setBounds(devPts, 2);
  347. bounds.outset(SK_Scalar1, SK_Scalar1);
  348. bounds.roundOut(&ibounds);
  349. if (SkIRect::Intersects(devClipBounds, ibounds)) {
  350. SkPoint* pts = lines->push_back_n(2);
  351. pts[0] = devPts[0];
  352. pts[1] = devPts[1];
  353. if (verbsInContour == 0 && pts[0] == pts[1]) {
  354. seenZeroLengthVerb = true;
  355. zeroVerbPt = pts[0];
  356. }
  357. }
  358. verbsInContour++;
  359. break;
  360. }
  361. case SkPath::kQuad_Verb: {
  362. SkPoint choppedPts[5];
  363. // Chopping the quad helps when the quad is either degenerate or nearly degenerate.
  364. // When it is degenerate it allows the approximation with lines to work since the
  365. // chop point (if there is one) will be at the parabola's vertex. In the nearly
  366. // degenerate the QuadUVMatrix computed for the points is almost singular which
  367. // can cause rendering artifacts.
  368. int n = SkChopQuadAtMaxCurvature(pathPts, choppedPts);
  369. for (int i = 0; i < n; ++i) {
  370. addSrcChoppedQuad(choppedPts + i * 2, !verbsInContour && 0 == i);
  371. }
  372. verbsInContour++;
  373. break;
  374. }
  375. case SkPath::kCubic_Verb: {
  376. SkPoint devPts[4];
  377. m.mapPoints(devPts, pathPts, 4);
  378. bounds.setBounds(devPts, 4);
  379. bounds.outset(SK_Scalar1, SK_Scalar1);
  380. bounds.roundOut(&ibounds);
  381. if (SkIRect::Intersects(devClipBounds, ibounds)) {
  382. PREALLOC_PTARRAY(32) q;
  383. // We convert cubics to quadratics (for now).
  384. // In perspective have to do conversion in src space.
  385. if (persp) {
  386. SkScalar tolScale =
  387. GrPathUtils::scaleToleranceToSrc(SK_Scalar1, m, path.getBounds());
  388. GrPathUtils::convertCubicToQuads(pathPts, tolScale, &q);
  389. } else {
  390. GrPathUtils::convertCubicToQuads(devPts, SK_Scalar1, &q);
  391. }
  392. for (int i = 0; i < q.count(); i += 3) {
  393. if (persp) {
  394. addSrcChoppedQuad(&q[i], !verbsInContour && 0 == i);
  395. } else {
  396. addChoppedQuad(nullptr, &q[i], !verbsInContour && 0 == i);
  397. }
  398. }
  399. }
  400. verbsInContour++;
  401. break;
  402. }
  403. case SkPath::kClose_Verb:
  404. // Contour is closed, so we don't need to grow the starting line, unless it's
  405. // *just* a zero length subpath. (SVG Spec 11.4, 'stroke').
  406. if (capLength > 0) {
  407. if (seenZeroLengthVerb && verbsInContour == 1) {
  408. SkPoint* pts = lines->push_back_n(2);
  409. pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
  410. pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
  411. } else if (verbsInContour == 0) {
  412. // Contour was (moveTo, close). Add a line.
  413. SkPoint devPts[2];
  414. m.mapPoints(devPts, pathPts, 1);
  415. devPts[1] = devPts[0];
  416. bounds.setBounds(devPts, 2);
  417. bounds.outset(SK_Scalar1, SK_Scalar1);
  418. bounds.roundOut(&ibounds);
  419. if (SkIRect::Intersects(devClipBounds, ibounds)) {
  420. SkPoint* pts = lines->push_back_n(2);
  421. pts[0] = SkPoint::Make(devPts[0].fX - capLength, devPts[0].fY);
  422. pts[1] = SkPoint::Make(devPts[1].fX + capLength, devPts[1].fY);
  423. }
  424. }
  425. }
  426. break;
  427. case SkPath::kDone_Verb:
  428. if (seenZeroLengthVerb && verbsInContour == 1 && capLength > 0) {
  429. // Path ended with a dangling (moveTo, line|quad|etc). If the final verb is
  430. // degenerate, we need to draw a line.
  431. SkPoint* pts = lines->push_back_n(2);
  432. pts[0] = SkPoint::Make(zeroVerbPt.fX - capLength, zeroVerbPt.fY);
  433. pts[1] = SkPoint::Make(zeroVerbPt.fX + capLength, zeroVerbPt.fY);
  434. }
  435. return totalQuadCount;
  436. }
  437. }
  438. }
  439. struct LineVertex {
  440. SkPoint fPos;
  441. float fCoverage;
  442. };
  443. struct BezierVertex {
  444. SkPoint fPos;
  445. union {
  446. struct {
  447. SkScalar fKLM[3];
  448. } fConic;
  449. SkVector fQuadCoord;
  450. struct {
  451. SkScalar fBogus[4];
  452. };
  453. };
  454. };
  455. GR_STATIC_ASSERT(sizeof(BezierVertex) == 3 * sizeof(SkPoint));
  456. static void intersect_lines(const SkPoint& ptA, const SkVector& normA,
  457. const SkPoint& ptB, const SkVector& normB,
  458. SkPoint* result) {
  459. SkScalar lineAW = -normA.dot(ptA);
  460. SkScalar lineBW = -normB.dot(ptB);
  461. SkScalar wInv = normA.fX * normB.fY - normA.fY * normB.fX;
  462. wInv = SkScalarInvert(wInv);
  463. if (!SkScalarIsFinite(wInv)) {
  464. // lines are parallel, pick the point in between
  465. *result = (ptA + ptB)*SK_ScalarHalf;
  466. *result += normA;
  467. } else {
  468. result->fX = normA.fY * lineBW - lineAW * normB.fY;
  469. result->fX *= wInv;
  470. result->fY = lineAW * normB.fX - normA.fX * lineBW;
  471. result->fY *= wInv;
  472. }
  473. }
  474. static void set_uv_quad(const SkPoint qpts[3], BezierVertex verts[kQuadNumVertices]) {
  475. // this should be in the src space, not dev coords, when we have perspective
  476. GrPathUtils::QuadUVMatrix DevToUV(qpts);
  477. DevToUV.apply(verts, kQuadNumVertices, sizeof(BezierVertex), sizeof(SkPoint));
  478. }
  479. static void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice,
  480. const SkMatrix* toSrc, BezierVertex verts[kQuadNumVertices]) {
  481. SkASSERT(!toDevice == !toSrc);
  482. // original quad is specified by tri a,b,c
  483. SkPoint a = qpts[0];
  484. SkPoint b = qpts[1];
  485. SkPoint c = qpts[2];
  486. if (toDevice) {
  487. toDevice->mapPoints(&a, 1);
  488. toDevice->mapPoints(&b, 1);
  489. toDevice->mapPoints(&c, 1);
  490. }
  491. // make a new poly where we replace a and c by a 1-pixel wide edges orthog
  492. // to edges ab and bc:
  493. //
  494. // before | after
  495. // | b0
  496. // b |
  497. // |
  498. // | a0 c0
  499. // a c | a1 c1
  500. //
  501. // edges a0->b0 and b0->c0 are parallel to original edges a->b and b->c,
  502. // respectively.
  503. BezierVertex& a0 = verts[0];
  504. BezierVertex& a1 = verts[1];
  505. BezierVertex& b0 = verts[2];
  506. BezierVertex& c0 = verts[3];
  507. BezierVertex& c1 = verts[4];
  508. SkVector ab = b;
  509. ab -= a;
  510. SkVector ac = c;
  511. ac -= a;
  512. SkVector cb = b;
  513. cb -= c;
  514. // After the transform we might have a line, try to do something reasonable
  515. if (toDevice && SkPointPriv::LengthSqd(ab) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) {
  516. ab = cb;
  517. }
  518. if (toDevice && SkPointPriv::LengthSqd(cb) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) {
  519. cb = ab;
  520. }
  521. // We should have already handled degenerates
  522. SkASSERT(toDevice || (ab.length() > 0 && cb.length() > 0));
  523. ab.normalize();
  524. SkVector abN = SkPointPriv::MakeOrthog(ab, SkPointPriv::kLeft_Side);
  525. if (abN.dot(ac) > 0) {
  526. abN.negate();
  527. }
  528. cb.normalize();
  529. SkVector cbN = SkPointPriv::MakeOrthog(cb, SkPointPriv::kLeft_Side);
  530. if (cbN.dot(ac) < 0) {
  531. cbN.negate();
  532. }
  533. a0.fPos = a;
  534. a0.fPos += abN;
  535. a1.fPos = a;
  536. a1.fPos -= abN;
  537. if (toDevice && SkPointPriv::LengthSqd(ac) <= SK_ScalarNearlyZero*SK_ScalarNearlyZero) {
  538. c = b;
  539. }
  540. c0.fPos = c;
  541. c0.fPos += cbN;
  542. c1.fPos = c;
  543. c1.fPos -= cbN;
  544. intersect_lines(a0.fPos, abN, c0.fPos, cbN, &b0.fPos);
  545. if (toSrc) {
  546. SkMatrixPriv::MapPointsWithStride(*toSrc, &verts[0].fPos, sizeof(BezierVertex),
  547. kQuadNumVertices);
  548. }
  549. }
  550. // Equations based off of Loop-Blinn Quadratic GPU Rendering
  551. // Input Parametric:
  552. // P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2)
  553. // Output Implicit:
  554. // f(x, y, w) = f(P) = K^2 - LM
  555. // K = dot(k, P), L = dot(l, P), M = dot(m, P)
  556. // k, l, m are calculated in function GrPathUtils::getConicKLM
  557. static void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kQuadNumVertices],
  558. const SkScalar weight) {
  559. SkMatrix klm;
  560. GrPathUtils::getConicKLM(p, weight, &klm);
  561. for (int i = 0; i < kQuadNumVertices; ++i) {
  562. const SkPoint3 pt3 = {verts[i].fPos.x(), verts[i].fPos.y(), 1.f};
  563. klm.mapHomogeneousPoints((SkPoint3* ) verts[i].fConic.fKLM, &pt3, 1);
  564. }
  565. }
  566. static void add_conics(const SkPoint p[3],
  567. const SkScalar weight,
  568. const SkMatrix* toDevice,
  569. const SkMatrix* toSrc,
  570. BezierVertex** vert) {
  571. bloat_quad(p, toDevice, toSrc, *vert);
  572. set_conic_coeffs(p, *vert, weight);
  573. *vert += kQuadNumVertices;
  574. }
  575. static void add_quads(const SkPoint p[3],
  576. int subdiv,
  577. const SkMatrix* toDevice,
  578. const SkMatrix* toSrc,
  579. BezierVertex** vert) {
  580. SkASSERT(subdiv >= 0);
  581. if (subdiv) {
  582. SkPoint newP[5];
  583. SkChopQuadAtHalf(p, newP);
  584. add_quads(newP + 0, subdiv-1, toDevice, toSrc, vert);
  585. add_quads(newP + 2, subdiv-1, toDevice, toSrc, vert);
  586. } else {
  587. bloat_quad(p, toDevice, toSrc, *vert);
  588. set_uv_quad(p, *vert);
  589. *vert += kQuadNumVertices;
  590. }
  591. }
  592. static void add_line(const SkPoint p[2],
  593. const SkMatrix* toSrc,
  594. uint8_t coverage,
  595. LineVertex** vert) {
  596. const SkPoint& a = p[0];
  597. const SkPoint& b = p[1];
  598. SkVector ortho, vec = b;
  599. vec -= a;
  600. SkScalar lengthSqd = SkPointPriv::LengthSqd(vec);
  601. if (vec.setLength(SK_ScalarHalf)) {
  602. // Create a vector orthogonal to 'vec' and of unit length
  603. ortho.fX = 2.0f * vec.fY;
  604. ortho.fY = -2.0f * vec.fX;
  605. float floatCoverage = GrNormalizeByteToFloat(coverage);
  606. if (lengthSqd >= 1.0f) {
  607. // Relative to points a and b:
  608. // The inner vertices are inset half a pixel along the line a,b
  609. (*vert)[0].fPos = a + vec;
  610. (*vert)[0].fCoverage = floatCoverage;
  611. (*vert)[1].fPos = b - vec;
  612. (*vert)[1].fCoverage = floatCoverage;
  613. } else {
  614. // The inner vertices are inset a distance of length(a,b) from the outer edge of
  615. // geometry. For the "a" inset this is the same as insetting from b by half a pixel.
  616. // The coverage is then modulated by the length. This gives us the correct
  617. // coverage for rects shorter than a pixel as they get translated subpixel amounts
  618. // inside of a pixel.
  619. SkScalar length = SkScalarSqrt(lengthSqd);
  620. (*vert)[0].fPos = b - vec;
  621. (*vert)[0].fCoverage = floatCoverage * length;
  622. (*vert)[1].fPos = a + vec;
  623. (*vert)[1].fCoverage = floatCoverage * length;
  624. }
  625. // Relative to points a and b:
  626. // The outer vertices are outset half a pixel along the line a,b and then a whole pixel
  627. // orthogonally.
  628. (*vert)[2].fPos = a - vec + ortho;
  629. (*vert)[2].fCoverage = 0;
  630. (*vert)[3].fPos = b + vec + ortho;
  631. (*vert)[3].fCoverage = 0;
  632. (*vert)[4].fPos = a - vec - ortho;
  633. (*vert)[4].fCoverage = 0;
  634. (*vert)[5].fPos = b + vec - ortho;
  635. (*vert)[5].fCoverage = 0;
  636. if (toSrc) {
  637. SkMatrixPriv::MapPointsWithStride(*toSrc, &(*vert)->fPos, sizeof(LineVertex),
  638. kLineSegNumVertices);
  639. }
  640. } else {
  641. // just make it degenerate and likely offscreen
  642. for (int i = 0; i < kLineSegNumVertices; ++i) {
  643. (*vert)[i].fPos.set(SK_ScalarMax, SK_ScalarMax);
  644. }
  645. }
  646. *vert += kLineSegNumVertices;
  647. }
  648. ///////////////////////////////////////////////////////////////////////////////
  649. GrPathRenderer::CanDrawPath
  650. GrAAHairLinePathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
  651. if (GrAAType::kCoverage != args.fAAType) {
  652. return CanDrawPath::kNo;
  653. }
  654. if (!IsStrokeHairlineOrEquivalent(args.fShape->style(), *args.fViewMatrix, nullptr)) {
  655. return CanDrawPath::kNo;
  656. }
  657. // We don't currently handle dashing in this class though perhaps we should.
  658. if (args.fShape->style().pathEffect()) {
  659. return CanDrawPath::kNo;
  660. }
  661. if (SkPath::kLine_SegmentMask == args.fShape->segmentMask() ||
  662. args.fCaps->shaderCaps()->shaderDerivativeSupport()) {
  663. return CanDrawPath::kYes;
  664. }
  665. return CanDrawPath::kNo;
  666. }
  667. template <class VertexType>
  668. bool check_bounds(const SkMatrix& viewMatrix, const SkRect& devBounds, void* vertices, int vCount)
  669. {
  670. SkRect tolDevBounds = devBounds;
  671. // The bounds ought to be tight, but in perspective the below code runs the verts
  672. // through the view matrix to get back to dev coords, which can introduce imprecision.
  673. if (viewMatrix.hasPerspective()) {
  674. tolDevBounds.outset(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
  675. } else {
  676. // Non-persp matrices cause this path renderer to draw in device space.
  677. SkASSERT(viewMatrix.isIdentity());
  678. }
  679. SkRect actualBounds;
  680. VertexType* verts = reinterpret_cast<VertexType*>(vertices);
  681. bool first = true;
  682. for (int i = 0; i < vCount; ++i) {
  683. SkPoint pos = verts[i].fPos;
  684. // This is a hack to workaround the fact that we move some degenerate segments offscreen.
  685. if (SK_ScalarMax == pos.fX) {
  686. continue;
  687. }
  688. viewMatrix.mapPoints(&pos, 1);
  689. if (first) {
  690. actualBounds.set(pos.fX, pos.fY, pos.fX, pos.fY);
  691. first = false;
  692. } else {
  693. SkRectPriv::GrowToInclude(&actualBounds, pos);
  694. }
  695. }
  696. if (!first) {
  697. return tolDevBounds.contains(actualBounds);
  698. }
  699. return true;
  700. }
  701. namespace {
  702. class AAHairlineOp final : public GrMeshDrawOp {
  703. private:
  704. using Helper = GrSimpleMeshDrawOpHelperWithStencil;
  705. public:
  706. DEFINE_OP_CLASS_ID
  707. static std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
  708. GrPaint&& paint,
  709. const SkMatrix& viewMatrix,
  710. const SkPath& path,
  711. const GrStyle& style,
  712. const SkIRect& devClipBounds,
  713. const GrUserStencilSettings* stencilSettings) {
  714. SkScalar hairlineCoverage;
  715. uint8_t newCoverage = 0xff;
  716. if (GrPathRenderer::IsStrokeHairlineOrEquivalent(style, viewMatrix, &hairlineCoverage)) {
  717. newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
  718. }
  719. const SkStrokeRec& stroke = style.strokeRec();
  720. SkScalar capLength = SkPaint::kButt_Cap != stroke.getCap() ? hairlineCoverage * 0.5f : 0.0f;
  721. return Helper::FactoryHelper<AAHairlineOp>(context, std::move(paint), newCoverage,
  722. viewMatrix, path,
  723. devClipBounds, capLength, stencilSettings);
  724. }
  725. AAHairlineOp(const Helper::MakeArgs& helperArgs,
  726. const SkPMColor4f& color,
  727. uint8_t coverage,
  728. const SkMatrix& viewMatrix,
  729. const SkPath& path,
  730. SkIRect devClipBounds,
  731. SkScalar capLength,
  732. const GrUserStencilSettings* stencilSettings)
  733. : INHERITED(ClassID())
  734. , fHelper(helperArgs, GrAAType::kCoverage, stencilSettings)
  735. , fColor(color)
  736. , fCoverage(coverage) {
  737. fPaths.emplace_back(PathData{viewMatrix, path, devClipBounds, capLength});
  738. this->setTransformedBounds(path.getBounds(), viewMatrix, HasAABloat::kYes,
  739. IsZeroArea::kYes);
  740. }
  741. const char* name() const override { return "AAHairlineOp"; }
  742. void visitProxies(const VisitProxyFunc& func) const override {
  743. fHelper.visitProxies(func);
  744. }
  745. #ifdef SK_DEBUG
  746. SkString dumpInfo() const override {
  747. SkString string;
  748. string.appendf("Color: 0x%08x Coverage: 0x%02x, Count: %d\n", fColor.toBytes_RGBA(),
  749. fCoverage, fPaths.count());
  750. string += INHERITED::dumpInfo();
  751. string += fHelper.dumpInfo();
  752. return string;
  753. }
  754. #endif
  755. FixedFunctionFlags fixedFunctionFlags() const override { return fHelper.fixedFunctionFlags(); }
  756. GrProcessorSet::Analysis finalize(
  757. const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
  758. GrClampType clampType) override {
  759. // This Op uses uniform (not vertex) color, so doesn't need to track wide color.
  760. return fHelper.finalizeProcessors(caps, clip, hasMixedSampledCoverage, clampType,
  761. GrProcessorAnalysisCoverage::kSingleChannel, &fColor,
  762. nullptr);
  763. }
  764. private:
  765. void onPrepareDraws(Target*) override;
  766. void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
  767. typedef SkTArray<SkPoint, true> PtArray;
  768. typedef SkTArray<int, true> IntArray;
  769. typedef SkTArray<float, true> FloatArray;
  770. CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
  771. AAHairlineOp* that = t->cast<AAHairlineOp>();
  772. if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) {
  773. return CombineResult::kCannotCombine;
  774. }
  775. if (this->viewMatrix().hasPerspective() != that->viewMatrix().hasPerspective()) {
  776. return CombineResult::kCannotCombine;
  777. }
  778. // We go to identity if we don't have perspective
  779. if (this->viewMatrix().hasPerspective() &&
  780. !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
  781. return CombineResult::kCannotCombine;
  782. }
  783. // TODO we can actually combine hairlines if they are the same color in a kind of bulk
  784. // method but we haven't implemented this yet
  785. // TODO investigate going to vertex color and coverage?
  786. if (this->coverage() != that->coverage()) {
  787. return CombineResult::kCannotCombine;
  788. }
  789. if (this->color() != that->color()) {
  790. return CombineResult::kCannotCombine;
  791. }
  792. if (fHelper.usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
  793. return CombineResult::kCannotCombine;
  794. }
  795. fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
  796. return CombineResult::kMerged;
  797. }
  798. const SkPMColor4f& color() const { return fColor; }
  799. uint8_t coverage() const { return fCoverage; }
  800. const SkMatrix& viewMatrix() const { return fPaths[0].fViewMatrix; }
  801. struct PathData {
  802. SkMatrix fViewMatrix;
  803. SkPath fPath;
  804. SkIRect fDevClipBounds;
  805. SkScalar fCapLength;
  806. };
  807. SkSTArray<1, PathData, true> fPaths;
  808. Helper fHelper;
  809. SkPMColor4f fColor;
  810. uint8_t fCoverage;
  811. typedef GrMeshDrawOp INHERITED;
  812. };
  813. } // anonymous namespace
  814. void AAHairlineOp::onPrepareDraws(Target* target) {
  815. // Setup the viewmatrix and localmatrix for the GrGeometryProcessor.
  816. SkMatrix invert;
  817. if (!this->viewMatrix().invert(&invert)) {
  818. return;
  819. }
  820. // we will transform to identity space if the viewmatrix does not have perspective
  821. bool hasPerspective = this->viewMatrix().hasPerspective();
  822. const SkMatrix* geometryProcessorViewM = &SkMatrix::I();
  823. const SkMatrix* geometryProcessorLocalM = &invert;
  824. const SkMatrix* toDevice = nullptr;
  825. const SkMatrix* toSrc = nullptr;
  826. if (hasPerspective) {
  827. geometryProcessorViewM = &this->viewMatrix();
  828. geometryProcessorLocalM = &SkMatrix::I();
  829. toDevice = &this->viewMatrix();
  830. toSrc = &invert;
  831. }
  832. // This is hand inlined for maximum performance.
  833. PREALLOC_PTARRAY(128) lines;
  834. PREALLOC_PTARRAY(128) quads;
  835. PREALLOC_PTARRAY(128) conics;
  836. IntArray qSubdivs;
  837. FloatArray cWeights;
  838. int quadCount = 0;
  839. int instanceCount = fPaths.count();
  840. bool convertConicsToQuads = !target->caps().shaderCaps()->floatIs32Bits();
  841. for (int i = 0; i < instanceCount; i++) {
  842. const PathData& args = fPaths[i];
  843. quadCount += gather_lines_and_quads(args.fPath, args.fViewMatrix, args.fDevClipBounds,
  844. args.fCapLength, convertConicsToQuads, &lines, &quads,
  845. &conics, &qSubdivs, &cWeights);
  846. }
  847. int lineCount = lines.count() / 2;
  848. int conicCount = conics.count() / 3;
  849. int quadAndConicCount = conicCount + quadCount;
  850. static constexpr int kMaxLines = SK_MaxS32 / kLineSegNumVertices;
  851. static constexpr int kMaxQuadsAndConics = SK_MaxS32 / kQuadNumVertices;
  852. if (lineCount > kMaxLines || quadAndConicCount > kMaxQuadsAndConics) {
  853. return;
  854. }
  855. // do lines first
  856. if (lineCount) {
  857. sk_sp<GrGeometryProcessor> lineGP;
  858. {
  859. using namespace GrDefaultGeoProcFactory;
  860. Color color(this->color());
  861. LocalCoords localCoords(fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type
  862. : LocalCoords::kUnused_Type);
  863. localCoords.fMatrix = geometryProcessorLocalM;
  864. lineGP = GrDefaultGeoProcFactory::Make(target->caps().shaderCaps(),
  865. color, Coverage::kAttribute_Type, localCoords,
  866. *geometryProcessorViewM);
  867. }
  868. sk_sp<const GrBuffer> linesIndexBuffer = get_lines_index_buffer(target->resourceProvider());
  869. sk_sp<const GrBuffer> vertexBuffer;
  870. int firstVertex;
  871. SkASSERT(sizeof(LineVertex) == lineGP->vertexStride());
  872. int vertexCount = kLineSegNumVertices * lineCount;
  873. LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace(
  874. sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex));
  875. if (!verts|| !linesIndexBuffer) {
  876. SkDebugf("Could not allocate vertices\n");
  877. return;
  878. }
  879. for (int i = 0; i < lineCount; ++i) {
  880. add_line(&lines[2*i], toSrc, this->coverage(), &verts);
  881. }
  882. GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
  883. mesh->setIndexedPatterned(std::move(linesIndexBuffer), kIdxsPerLineSeg, kLineSegNumVertices,
  884. lineCount, kLineSegsNumInIdxBuffer);
  885. mesh->setVertexData(std::move(vertexBuffer), firstVertex);
  886. target->recordDraw(std::move(lineGP), mesh);
  887. }
  888. if (quadCount || conicCount) {
  889. sk_sp<GrGeometryProcessor> quadGP(GrQuadEffect::Make(this->color(),
  890. *geometryProcessorViewM,
  891. GrClipEdgeType::kHairlineAA,
  892. target->caps(),
  893. *geometryProcessorLocalM,
  894. fHelper.usesLocalCoords(),
  895. this->coverage()));
  896. sk_sp<GrGeometryProcessor> conicGP(GrConicEffect::Make(this->color(),
  897. *geometryProcessorViewM,
  898. GrClipEdgeType::kHairlineAA,
  899. target->caps(),
  900. *geometryProcessorLocalM,
  901. fHelper.usesLocalCoords(),
  902. this->coverage()));
  903. sk_sp<const GrBuffer> vertexBuffer;
  904. int firstVertex;
  905. sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
  906. SkASSERT(sizeof(BezierVertex) == quadGP->vertexStride());
  907. SkASSERT(sizeof(BezierVertex) == conicGP->vertexStride());
  908. int vertexCount = kQuadNumVertices * quadAndConicCount;
  909. void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer,
  910. &firstVertex);
  911. if (!vertices || !quadsIndexBuffer) {
  912. SkDebugf("Could not allocate vertices\n");
  913. return;
  914. }
  915. // Setup vertices
  916. BezierVertex* bezVerts = reinterpret_cast<BezierVertex*>(vertices);
  917. int unsubdivQuadCnt = quads.count() / 3;
  918. for (int i = 0; i < unsubdivQuadCnt; ++i) {
  919. SkASSERT(qSubdivs[i] >= 0);
  920. add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &bezVerts);
  921. }
  922. // Start Conics
  923. for (int i = 0; i < conicCount; ++i) {
  924. add_conics(&conics[3*i], cWeights[i], toDevice, toSrc, &bezVerts);
  925. }
  926. if (quadCount > 0) {
  927. GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
  928. mesh->setIndexedPatterned(quadsIndexBuffer, kIdxsPerQuad, kQuadNumVertices, quadCount,
  929. kQuadsNumInIdxBuffer);
  930. mesh->setVertexData(vertexBuffer, firstVertex);
  931. target->recordDraw(std::move(quadGP), mesh);
  932. firstVertex += quadCount * kQuadNumVertices;
  933. }
  934. if (conicCount > 0) {
  935. GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
  936. mesh->setIndexedPatterned(std::move(quadsIndexBuffer), kIdxsPerQuad, kQuadNumVertices,
  937. conicCount, kQuadsNumInIdxBuffer);
  938. mesh->setVertexData(std::move(vertexBuffer), firstVertex);
  939. target->recordDraw(std::move(conicGP), mesh);
  940. }
  941. }
  942. }
  943. void AAHairlineOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
  944. fHelper.executeDrawsAndUploads(this, flushState, chainBounds);
  945. }
  946. bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
  947. GR_AUDIT_TRAIL_AUTO_FRAME(args.fRenderTargetContext->auditTrail(),
  948. "GrAAHairlinePathRenderer::onDrawPath");
  949. SkASSERT(args.fRenderTargetContext->numSamples() <= 1);
  950. SkIRect devClipBounds;
  951. args.fClip->getConservativeBounds(args.fRenderTargetContext->width(),
  952. args.fRenderTargetContext->height(),
  953. &devClipBounds);
  954. SkPath path;
  955. args.fShape->asPath(&path);
  956. std::unique_ptr<GrDrawOp> op =
  957. AAHairlineOp::Make(args.fContext, std::move(args.fPaint), *args.fViewMatrix, path,
  958. args.fShape->style(), devClipBounds, args.fUserStencilSettings);
  959. args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op));
  960. return true;
  961. }
  962. ///////////////////////////////////////////////////////////////////////////////////////////////////
  963. #if GR_TEST_UTILS
  964. GR_DRAW_OP_TEST_DEFINE(AAHairlineOp) {
  965. SkMatrix viewMatrix = GrTest::TestMatrix(random);
  966. SkPath path = GrTest::TestPath(random);
  967. SkIRect devClipBounds;
  968. devClipBounds.setEmpty();
  969. return AAHairlineOp::Make(context, std::move(paint), viewMatrix, path,
  970. GrStyle::SimpleHairline(), devClipBounds,
  971. GrGetRandomStencil(random, context));
  972. }
  973. #endif