robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrAARectRenderer.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 10 | #include "GrAtlasTextContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 11 | #include "GrBatchTest.h" |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 12 | #include "GrColor.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 13 | #include "GrDrawContext.h" |
| 14 | #include "GrOvalRenderer.h" |
| 15 | #include "GrPathRenderer.h" |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 16 | #include "GrRenderTarget.h" |
| 17 | #include "GrRenderTargetPriv.h" |
| 18 | #include "GrStencilAndCoverTextContext.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 19 | |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 20 | #include "batches/GrBatch.h" |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 21 | #include "batches/GrDrawAtlasBatch.h" |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame^] | 22 | #include "batches/GrDrawVerticesBatch.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 23 | #include "batches/GrStrokeRectBatch.h" |
| 24 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 25 | #include "SkGr.h" |
| 26 | #include "SkRSXform.h" |
| 27 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 28 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == fContext) |
| 29 | #define RETURN_IF_ABANDONED if (!fDrawTarget) { return; } |
| 30 | #define RETURN_FALSE_IF_ABANDONED if (!fDrawTarget) { return false; } |
| 31 | #define RETURN_NULL_IF_ABANDONED if (!fDrawTarget) { return NULL; } |
| 32 | |
| 33 | class AutoCheckFlush { |
| 34 | public: |
| 35 | AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } |
| 36 | ~AutoCheckFlush() { fContext->flushIfNecessary(); } |
| 37 | |
| 38 | private: |
| 39 | GrContext* fContext; |
| 40 | }; |
| 41 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 42 | GrDrawContext::GrDrawContext(GrContext* context, |
| 43 | GrDrawTarget* drawTarget, |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 44 | const SkSurfaceProps& surfaceProps) |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 45 | : fContext(context) |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 46 | , fDrawTarget(SkRef(drawTarget)) |
| 47 | , fTextContext(NULL) |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 48 | , fSurfaceProps(surfaceProps) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 49 | } |
| 50 | |
robertphillips | 4b195e5 | 2015-05-26 14:37:00 -0700 | [diff] [blame] | 51 | GrDrawContext::~GrDrawContext() { |
| 52 | SkSafeUnref(fDrawTarget); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 53 | SkDELETE(fTextContext); |
robertphillips | 4b195e5 | 2015-05-26 14:37:00 -0700 | [diff] [blame] | 54 | } |
| 55 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 56 | void GrDrawContext::copySurface(GrRenderTarget* dst, GrSurface* src, |
| 57 | const SkIRect& srcRect, const SkIPoint& dstPoint) { |
| 58 | if (!this->prepareToDraw(dst)) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | fDrawTarget->copySurface(dst, src, srcRect, dstPoint); |
| 63 | } |
| 64 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 65 | GrTextContext* GrDrawContext::createTextContext(GrRenderTarget* renderTarget, |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 66 | const SkSurfaceProps& surfaceProps) { |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 67 | if (fContext->caps()->shaderCaps()->pathRenderingSupport() && |
cdalton | e04edd8 | 2015-06-29 14:15:19 -0700 | [diff] [blame] | 68 | renderTarget->isStencilBufferMultisampled() && |
| 69 | fSurfaceProps.isUseDistanceFieldFonts()) { // FIXME: Rename the dff flag to be more general. |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 70 | GrStencilAttachment* sb = renderTarget->renderTargetPriv().attachStencilAttachment(); |
| 71 | if (sb) { |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 72 | return GrStencilAndCoverTextContext::Create(fContext, this, surfaceProps); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 76 | return GrAtlasTextContext::Create(fContext, this, surfaceProps); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void GrDrawContext::drawText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, |
| 80 | const SkPaint& skPaint, |
| 81 | const SkMatrix& viewMatrix, |
| 82 | const char text[], size_t byteLength, |
| 83 | SkScalar x, SkScalar y, const SkIRect& clipBounds) { |
| 84 | if (!fTextContext) { |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 85 | fTextContext = this->createTextContext(rt, fSurfaceProps); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | fTextContext->drawText(rt, clip, grPaint, skPaint, viewMatrix, |
| 89 | text, byteLength, x, y, clipBounds); |
| 90 | |
| 91 | } |
| 92 | void GrDrawContext::drawPosText(GrRenderTarget* rt, const GrClip& clip, const GrPaint& grPaint, |
| 93 | const SkPaint& skPaint, |
| 94 | const SkMatrix& viewMatrix, |
| 95 | const char text[], size_t byteLength, |
| 96 | const SkScalar pos[], int scalarsPerPosition, |
| 97 | const SkPoint& offset, const SkIRect& clipBounds) { |
| 98 | if (!fTextContext) { |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 99 | fTextContext = this->createTextContext(rt, fSurfaceProps); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | fTextContext->drawPosText(rt, clip, grPaint, skPaint, viewMatrix, text, byteLength, |
| 103 | pos, scalarsPerPosition, offset, clipBounds); |
| 104 | |
| 105 | } |
| 106 | void GrDrawContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, const SkPaint& skPaint, |
| 107 | const SkMatrix& viewMatrix, const SkTextBlob* blob, |
| 108 | SkScalar x, SkScalar y, |
| 109 | SkDrawFilter* filter, const SkIRect& clipBounds) { |
| 110 | if (!fTextContext) { |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 111 | fTextContext = this->createTextContext(rt, fSurfaceProps); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | fTextContext->drawTextBlob(rt, clip, skPaint, viewMatrix, blob, x, y, filter, clipBounds); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void GrDrawContext::drawPaths(GrPipelineBuilder* pipelineBuilder, |
| 118 | const GrPathProcessor* pathProc, |
| 119 | const GrPathRange* pathRange, |
| 120 | const void* indices, |
| 121 | int /*GrDrawTarget::PathIndexType*/ indexType, |
| 122 | const float transformValues[], |
| 123 | int /*GrDrawTarget::PathTransformType*/ transformType, |
| 124 | int count, |
| 125 | int /*GrPathRendering::FillType*/ fill) { |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 126 | fDrawTarget->drawPaths(*pipelineBuilder, pathProc, pathRange, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 127 | indices, (GrDrawTarget::PathIndexType) indexType, |
| 128 | transformValues, |
| 129 | (GrDrawTarget::PathTransformType) transformType, |
| 130 | count, (GrPathRendering::FillType) fill); |
| 131 | } |
| 132 | |
| 133 | void GrDrawContext::discard(GrRenderTarget* renderTarget) { |
| 134 | RETURN_IF_ABANDONED |
| 135 | SkASSERT(renderTarget); |
| 136 | AutoCheckFlush acf(fContext); |
| 137 | if (!this->prepareToDraw(renderTarget)) { |
| 138 | return; |
| 139 | } |
| 140 | fDrawTarget->discard(renderTarget); |
| 141 | } |
| 142 | |
| 143 | void GrDrawContext::clear(GrRenderTarget* renderTarget, |
| 144 | const SkIRect* rect, |
| 145 | const GrColor color, |
| 146 | bool canIgnoreRect) { |
| 147 | RETURN_IF_ABANDONED |
| 148 | SkASSERT(renderTarget); |
| 149 | |
| 150 | AutoCheckFlush acf(fContext); |
| 151 | if (!this->prepareToDraw(renderTarget)) { |
| 152 | return; |
| 153 | } |
| 154 | fDrawTarget->clear(rect, color, canIgnoreRect, renderTarget); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | void GrDrawContext::drawPaint(GrRenderTarget* rt, |
| 159 | const GrClip& clip, |
| 160 | const GrPaint& origPaint, |
| 161 | const SkMatrix& viewMatrix) { |
| 162 | RETURN_IF_ABANDONED |
| 163 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 164 | // don't overflow fixed-point implementations |
| 165 | SkRect r; |
| 166 | r.setLTRB(0, 0, |
| 167 | SkIntToScalar(rt->width()), |
| 168 | SkIntToScalar(rt->height())); |
| 169 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
| 170 | |
| 171 | // by definition this fills the entire clip, no need for AA |
| 172 | if (paint->isAntiAlias()) { |
| 173 | paint.writable()->setAntiAlias(false); |
| 174 | } |
| 175 | |
| 176 | bool isPerspective = viewMatrix.hasPerspective(); |
| 177 | |
| 178 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 179 | // map the four corners and bound them with a new rect. This will not |
| 180 | // produce a correct result for some perspective matrices. |
| 181 | if (!isPerspective) { |
| 182 | SkMatrix inverse; |
| 183 | if (!viewMatrix.invert(&inverse)) { |
| 184 | SkDebugf("Could not invert matrix\n"); |
| 185 | return; |
| 186 | } |
| 187 | inverse.mapRect(&r); |
| 188 | this->drawRect(rt, clip, *paint, viewMatrix, r); |
| 189 | } else { |
| 190 | SkMatrix localMatrix; |
| 191 | if (!viewMatrix.invert(&localMatrix)) { |
| 192 | SkDebugf("Could not invert matrix\n"); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 197 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 201 | GrPipelineBuilder pipelineBuilder(*paint, rt, clip); |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 202 | fDrawTarget->drawBWRect(pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 203 | paint->getColor(), |
| 204 | SkMatrix::I(), |
| 205 | r, |
| 206 | NULL, |
| 207 | &localMatrix); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static inline bool is_irect(const SkRect& r) { |
| 212 | return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 213 | SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
| 214 | } |
| 215 | |
| 216 | static bool apply_aa_to_rect(GrDrawTarget* target, |
| 217 | GrPipelineBuilder* pipelineBuilder, |
| 218 | SkRect* devBoundRect, |
| 219 | const SkRect& rect, |
| 220 | SkScalar strokeWidth, |
| 221 | const SkMatrix& combinedMatrix, |
| 222 | GrColor color) { |
robertphillips | d8aa59d | 2015-08-05 09:07:12 -0700 | [diff] [blame] | 223 | if (pipelineBuilder->getRenderTarget()->isUnifiedMultisampled() || |
| 224 | !combinedMatrix.preservesAxisAlignment()) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 225 | return false; |
| 226 | } |
| 227 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 228 | combinedMatrix.mapRect(devBoundRect, rect); |
| 229 | if (!combinedMatrix.rectStaysRect()) { |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | if (strokeWidth < 0) { |
| 234 | return !is_irect(*devBoundRect); |
| 235 | } |
| 236 | |
| 237 | return true; |
| 238 | } |
| 239 | |
| 240 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 241 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 242 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 243 | } |
| 244 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 245 | void GrDrawContext::drawRect(GrRenderTarget* rt, |
| 246 | const GrClip& clip, |
| 247 | const GrPaint& paint, |
| 248 | const SkMatrix& viewMatrix, |
| 249 | const SkRect& rect, |
| 250 | const GrStrokeInfo* strokeInfo) { |
| 251 | RETURN_IF_ABANDONED |
| 252 | if (strokeInfo && strokeInfo->isDashed()) { |
| 253 | SkPath path; |
| 254 | path.setIsVolatile(true); |
| 255 | path.addRect(rect); |
| 256 | this->drawPath(rt, clip, paint, viewMatrix, path, *strokeInfo); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 261 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 262 | return; |
| 263 | } |
| 264 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 265 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
| 266 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 267 | SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getWidth(); |
| 268 | |
| 269 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking |
| 270 | // cases where the RT is fully inside a stroke. |
| 271 | if (width < 0) { |
| 272 | SkRect rtRect; |
| 273 | pipelineBuilder.getRenderTarget()->getBoundsRect(&rtRect); |
| 274 | SkRect clipSpaceRTRect = rtRect; |
| 275 | bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); |
| 276 | if (checkClip) { |
| 277 | clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), |
| 278 | SkIntToScalar(clip.origin().fY)); |
| 279 | } |
| 280 | // Does the clip contain the entire RT? |
| 281 | if (!checkClip || clip.quickContains(clipSpaceRTRect)) { |
| 282 | SkMatrix invM; |
| 283 | if (!viewMatrix.invert(&invM)) { |
| 284 | return; |
| 285 | } |
| 286 | // Does the rect bound the RT? |
| 287 | SkPoint srcSpaceRTQuad[4]; |
| 288 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 289 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 290 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 291 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 292 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 293 | // Will it blend? |
| 294 | GrColor clearColor; |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 295 | if (paint.isConstantBlendedColor(&clearColor)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 296 | fDrawTarget->clear(NULL, clearColor, true, rt); |
| 297 | return; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | GrColor color = paint.getColor(); |
| 304 | SkRect devBoundRect; |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 305 | bool needAA = paint.isAntiAlias() && |
| 306 | !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 307 | bool doAA = needAA && apply_aa_to_rect(fDrawTarget, &pipelineBuilder, &devBoundRect, rect, |
| 308 | width, viewMatrix, color); |
| 309 | |
| 310 | if (doAA) { |
| 311 | if (width >= 0) { |
| 312 | GrAARectRenderer::StrokeAARect(fDrawTarget, |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 313 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 314 | color, |
| 315 | viewMatrix, |
| 316 | rect, |
| 317 | devBoundRect, |
| 318 | *strokeInfo); |
| 319 | } else { |
| 320 | // filled AA rect |
| 321 | GrAARectRenderer::FillAARect(fDrawTarget, |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 322 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 323 | color, |
| 324 | viewMatrix, |
| 325 | rect, |
| 326 | devBoundRect); |
| 327 | } |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (width >= 0) { |
bsalomon | ee14a62 | 2015-08-05 10:34:05 -0700 | [diff] [blame] | 332 | GrStrokeRectBatch::Geometry geometry; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 333 | geometry.fViewMatrix = viewMatrix; |
| 334 | geometry.fColor = color; |
| 335 | geometry.fRect = rect; |
| 336 | geometry.fStrokeWidth = width; |
| 337 | |
| 338 | // Non-AA hairlines are snapped to pixel centers to make which pixels are hit deterministic |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 339 | bool snapToPixelCenters = (0 == width && !rt->isUnifiedMultisampled()); |
bsalomon | ee14a62 | 2015-08-05 10:34:05 -0700 | [diff] [blame] | 340 | SkAutoTUnref<GrBatch> batch(GrStrokeRectBatch::Create(geometry, snapToPixelCenters)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 341 | |
| 342 | // Depending on sub-pixel coordinates and the particular GPU, we may lose a corner of |
| 343 | // hairline rects. We jam all the vertices to pixel centers to avoid this, but not when MSAA |
| 344 | // is enabled because it can cause ugly artifacts. |
| 345 | pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag, |
| 346 | snapToPixelCenters); |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 347 | fDrawTarget->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 348 | } else { |
| 349 | // filled BW rect |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 350 | fDrawTarget->drawSimpleRect(pipelineBuilder, color, viewMatrix, rect); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | void GrDrawContext::drawNonAARectToRect(GrRenderTarget* rt, |
| 355 | const GrClip& clip, |
| 356 | const GrPaint& paint, |
| 357 | const SkMatrix& viewMatrix, |
| 358 | const SkRect& rectToDraw, |
| 359 | const SkRect& localRect, |
| 360 | const SkMatrix* localMatrix) { |
| 361 | RETURN_IF_ABANDONED |
| 362 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 363 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 364 | return; |
| 365 | } |
| 366 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 367 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 368 | fDrawTarget->drawBWRect(pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 369 | paint.getColor(), |
| 370 | viewMatrix, |
| 371 | rectToDraw, |
| 372 | &localRect, |
| 373 | localMatrix); |
| 374 | } |
| 375 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 376 | void GrDrawContext::drawVertices(GrRenderTarget* rt, |
| 377 | const GrClip& clip, |
| 378 | const GrPaint& paint, |
| 379 | const SkMatrix& viewMatrix, |
| 380 | GrPrimitiveType primitiveType, |
| 381 | int vertexCount, |
| 382 | const SkPoint positions[], |
| 383 | const SkPoint texCoords[], |
| 384 | const GrColor colors[], |
| 385 | const uint16_t indices[], |
| 386 | int indexCount) { |
| 387 | RETURN_IF_ABANDONED |
| 388 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 389 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 390 | return; |
| 391 | } |
| 392 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 393 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
| 394 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 395 | // TODO clients should give us bounds |
| 396 | SkRect bounds; |
| 397 | if (!bounds.setBoundsCheck(positions, vertexCount)) { |
| 398 | SkDebugf("drawVertices call empty bounds\n"); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | viewMatrix.mapRect(&bounds); |
| 403 | |
| 404 | // If we don't have AA then we outset for a half pixel in each direction to account for |
| 405 | // snapping |
| 406 | if (!paint.isAntiAlias()) { |
| 407 | bounds.outset(0.5f, 0.5f); |
| 408 | } |
| 409 | |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame^] | 410 | GrDrawVerticesBatch::Geometry geometry; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 411 | geometry.fColor = paint.getColor(); |
joshualitt | 2771b56 | 2015-08-07 12:46:26 -0700 | [diff] [blame^] | 412 | SkAutoTUnref<GrBatch> batch(GrDrawVerticesBatch::Create(geometry, primitiveType, viewMatrix, |
| 413 | positions, vertexCount, indices, |
| 414 | indexCount, colors, texCoords, |
| 415 | bounds)); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 416 | |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 417 | fDrawTarget->drawBatch(pipelineBuilder, batch); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /////////////////////////////////////////////////////////////////////////////// |
| 421 | |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 422 | void GrDrawContext::drawAtlas(GrRenderTarget* rt, |
| 423 | const GrClip& clip, |
| 424 | const GrPaint& paint, |
| 425 | const SkMatrix& viewMatrix, |
| 426 | int spriteCount, |
| 427 | const SkRSXform xform[], |
| 428 | const SkRect texRect[], |
| 429 | const SkColor colors[]) { |
| 430 | RETURN_IF_ABANDONED |
| 431 | AutoCheckFlush acf(fContext); |
| 432 | if (!this->prepareToDraw(rt)) { |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
| 437 | |
| 438 | // now build the renderable geometry |
| 439 | const int vertCount = spriteCount * 4; |
| 440 | SkAutoTMalloc<SkPoint> vertStorage(vertCount * 2); |
| 441 | SkPoint* verts = vertStorage.get(); |
| 442 | SkPoint* texs = verts + vertCount; |
| 443 | |
| 444 | for (int i = 0; i < spriteCount; ++i) { |
| 445 | xform[i].toQuad(texRect[i].width(), texRect[i].height(), verts); |
| 446 | texRect[i].toQuad(texs); |
| 447 | verts += 4; |
| 448 | texs += 4; |
| 449 | } |
| 450 | |
| 451 | // TODO clients should give us bounds |
| 452 | SkRect bounds; |
| 453 | if (!bounds.setBoundsCheck(vertStorage.get(), vertCount)) { |
| 454 | SkDebugf("drawAtlas call empty bounds\n"); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | viewMatrix.mapRect(&bounds); |
| 459 | |
| 460 | // If we don't have AA then we outset for a half pixel in each direction to account for |
| 461 | // snapping |
| 462 | if (!paint.isAntiAlias()) { |
| 463 | bounds.outset(0.5f, 0.5f); |
| 464 | } |
| 465 | |
| 466 | SkAutoTMalloc<GrColor> colorStorage; |
| 467 | GrColor* vertCols = NULL; |
| 468 | if (colors) { |
| 469 | colorStorage.reset(vertCount); |
| 470 | vertCols = colorStorage.get(); |
| 471 | |
| 472 | int paintAlpha = GrColorUnpackA(paint.getColor()); |
| 473 | |
| 474 | // need to convert byte order and from non-PM to PM |
| 475 | for (int i = 0; i < spriteCount; ++i) { |
| 476 | SkColor color = colors[i]; |
| 477 | if (paintAlpha != 255) { |
| 478 | color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paintAlpha)); |
| 479 | } |
| 480 | GrColor grColor = SkColor2GrColor(color); |
| 481 | |
| 482 | vertCols[0] = vertCols[1] = vertCols[2] = vertCols[3] = grColor; |
| 483 | vertCols += 4; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | verts = vertStorage.get(); |
| 488 | texs = verts + vertCount; |
| 489 | vertCols = colorStorage.get(); |
| 490 | |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 491 | GrDrawAtlasBatch::Geometry geometry; |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 492 | geometry.fColor = paint.getColor(); |
jvanverth | 14b8803 | 2015-08-07 12:18:54 -0700 | [diff] [blame] | 493 | SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, verts, vertCount, |
| 494 | vertCols, texs, bounds)); |
jvanverth | 31ff762 | 2015-08-07 10:09:28 -0700 | [diff] [blame] | 495 | |
| 496 | fDrawTarget->drawBatch(pipelineBuilder, batch); |
| 497 | } |
| 498 | |
| 499 | /////////////////////////////////////////////////////////////////////////////// |
| 500 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 501 | void GrDrawContext::drawRRect(GrRenderTarget*rt, |
| 502 | const GrClip& clip, |
| 503 | const GrPaint& paint, |
| 504 | const SkMatrix& viewMatrix, |
| 505 | const SkRRect& rrect, |
| 506 | const GrStrokeInfo& strokeInfo) { |
| 507 | RETURN_IF_ABANDONED |
| 508 | if (rrect.isEmpty()) { |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | if (strokeInfo.isDashed()) { |
| 513 | SkPath path; |
| 514 | path.setIsVolatile(true); |
| 515 | path.addRRect(rrect); |
| 516 | this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 521 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 522 | return; |
| 523 | } |
| 524 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 525 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 526 | GrColor color = paint.getColor(); |
| 527 | if (!GrOvalRenderer::DrawRRect(fDrawTarget, |
joshualitt | ae3d63a | 2015-07-13 08:44:06 -0700 | [diff] [blame] | 528 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 529 | color, |
| 530 | viewMatrix, |
| 531 | paint.isAntiAlias(), |
| 532 | rrect, |
| 533 | strokeInfo)) { |
| 534 | SkPath path; |
| 535 | path.setIsVolatile(true); |
| 536 | path.addRRect(rrect); |
| 537 | this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, |
| 538 | paint.isAntiAlias(), path, strokeInfo); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /////////////////////////////////////////////////////////////////////////////// |
| 543 | |
| 544 | void GrDrawContext::drawDRRect(GrRenderTarget* rt, |
| 545 | const GrClip& clip, |
| 546 | const GrPaint& paint, |
| 547 | const SkMatrix& viewMatrix, |
| 548 | const SkRRect& outer, |
| 549 | const SkRRect& inner) { |
| 550 | RETURN_IF_ABANDONED |
| 551 | if (outer.isEmpty()) { |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 556 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
| 559 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 560 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 561 | GrColor color = paint.getColor(); |
| 562 | if (!GrOvalRenderer::DrawDRRect(fDrawTarget, |
joshualitt | ae3d63a | 2015-07-13 08:44:06 -0700 | [diff] [blame] | 563 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 564 | color, |
| 565 | viewMatrix, |
| 566 | paint.isAntiAlias(), |
| 567 | outer, |
| 568 | inner)) { |
| 569 | SkPath path; |
| 570 | path.setIsVolatile(true); |
| 571 | path.addRRect(inner); |
| 572 | path.addRRect(outer); |
| 573 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 574 | |
| 575 | GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
| 576 | this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, |
| 577 | paint.isAntiAlias(), path, fillRec); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | /////////////////////////////////////////////////////////////////////////////// |
| 582 | |
| 583 | void GrDrawContext::drawOval(GrRenderTarget* rt, |
| 584 | const GrClip& clip, |
| 585 | const GrPaint& paint, |
| 586 | const SkMatrix& viewMatrix, |
| 587 | const SkRect& oval, |
| 588 | const GrStrokeInfo& strokeInfo) { |
| 589 | RETURN_IF_ABANDONED |
| 590 | if (oval.isEmpty()) { |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | if (strokeInfo.isDashed()) { |
| 595 | SkPath path; |
| 596 | path.setIsVolatile(true); |
| 597 | path.addOval(oval); |
| 598 | this->drawPath(rt, clip, paint, viewMatrix, path, strokeInfo); |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 603 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 604 | return; |
| 605 | } |
| 606 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 607 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 608 | GrColor color = paint.getColor(); |
| 609 | if (!GrOvalRenderer::DrawOval(fDrawTarget, |
joshualitt | ae3d63a | 2015-07-13 08:44:06 -0700 | [diff] [blame] | 610 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 611 | color, |
| 612 | viewMatrix, |
| 613 | paint.isAntiAlias(), |
| 614 | oval, |
| 615 | strokeInfo)) { |
| 616 | SkPath path; |
| 617 | path.setIsVolatile(true); |
| 618 | path.addOval(oval); |
| 619 | this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, |
| 620 | paint.isAntiAlias(), path, strokeInfo); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | // Can 'path' be drawn as a pair of filled nested rectangles? |
joshualitt | f9c5db2 | 2015-07-10 11:31:01 -0700 | [diff] [blame] | 625 | static bool is_nested_rects(const SkMatrix& viewMatrix, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 626 | const SkPath& path, |
| 627 | const SkStrokeRec& stroke, |
| 628 | SkRect rects[2]) { |
| 629 | SkASSERT(stroke.isFillStyle()); |
| 630 | |
| 631 | if (path.isInverseFillType()) { |
| 632 | return false; |
| 633 | } |
| 634 | |
| 635 | // TODO: this restriction could be lifted if we were willing to apply |
| 636 | // the matrix to all the points individually rather than just to the rect |
| 637 | if (!viewMatrix.preservesAxisAlignment()) { |
| 638 | return false; |
| 639 | } |
| 640 | |
| 641 | SkPath::Direction dirs[2]; |
| 642 | if (!path.isNestedFillRects(rects, dirs)) { |
| 643 | return false; |
| 644 | } |
| 645 | |
| 646 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
| 647 | // The two rects need to be wound opposite to each other |
| 648 | return false; |
| 649 | } |
| 650 | |
| 651 | // Right now, nested rects where the margin is not the same width |
| 652 | // all around do not render correctly |
| 653 | const SkScalar* outer = rects[0].asScalars(); |
| 654 | const SkScalar* inner = rects[1].asScalars(); |
| 655 | |
| 656 | bool allEq = true; |
| 657 | |
| 658 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 659 | bool allGoE1 = margin >= SK_Scalar1; |
| 660 | |
| 661 | for (int i = 1; i < 4; ++i) { |
| 662 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 663 | if (temp < SK_Scalar1) { |
| 664 | allGoE1 = false; |
| 665 | } |
| 666 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 667 | allEq = false; |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | return allEq || allGoE1; |
| 672 | } |
| 673 | |
| 674 | void GrDrawContext::drawPath(GrRenderTarget* rt, |
| 675 | const GrClip& clip, |
| 676 | const GrPaint& paint, |
| 677 | const SkMatrix& viewMatrix, |
| 678 | const SkPath& path, |
| 679 | const GrStrokeInfo& strokeInfo) { |
| 680 | RETURN_IF_ABANDONED |
| 681 | if (path.isEmpty()) { |
| 682 | if (path.isInverseFillType()) { |
| 683 | this->drawPaint(rt, clip, paint, viewMatrix); |
| 684 | } |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | GrColor color = paint.getColor(); |
| 689 | |
| 690 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
| 691 | // Scratch textures can be recycled after they are returned to the texture |
| 692 | // cache. This presents a potential hazard for buffered drawing. However, |
| 693 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 694 | // OK. |
| 695 | AutoCheckFlush acf(fContext); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 696 | if (!this->prepareToDraw(rt)) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 697 | return; |
| 698 | } |
| 699 | |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 700 | GrPipelineBuilder pipelineBuilder(paint, rt, clip); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 701 | if (!strokeInfo.isDashed()) { |
| 702 | bool useCoverageAA = paint.isAntiAlias() && |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 703 | !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 704 | |
| 705 | if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 706 | // Concave AA paths are expensive - try to avoid them for special cases |
| 707 | SkRect rects[2]; |
| 708 | |
joshualitt | f9c5db2 | 2015-07-10 11:31:01 -0700 | [diff] [blame] | 709 | if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 710 | GrAARectRenderer::FillAANestedRects(fDrawTarget, pipelineBuilder, color, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 711 | viewMatrix, rects); |
| 712 | return; |
| 713 | } |
| 714 | } |
| 715 | SkRect ovalRect; |
| 716 | bool isOval = path.isOval(&ovalRect); |
| 717 | |
| 718 | if (isOval && !path.isInverseFillType()) { |
| 719 | if (GrOvalRenderer::DrawOval(fDrawTarget, |
joshualitt | ae3d63a | 2015-07-13 08:44:06 -0700 | [diff] [blame] | 720 | pipelineBuilder, |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 721 | color, |
| 722 | viewMatrix, |
| 723 | paint.isAntiAlias(), |
| 724 | ovalRect, |
| 725 | strokeInfo)) { |
| 726 | return; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | this->internalDrawPath(fDrawTarget, &pipelineBuilder, viewMatrix, color, paint.isAntiAlias(), |
| 731 | path, strokeInfo); |
| 732 | } |
| 733 | |
| 734 | void GrDrawContext::internalDrawPath(GrDrawTarget* target, |
| 735 | GrPipelineBuilder* pipelineBuilder, |
| 736 | const SkMatrix& viewMatrix, |
| 737 | GrColor color, |
| 738 | bool useAA, |
| 739 | const SkPath& path, |
| 740 | const GrStrokeInfo& strokeInfo) { |
| 741 | RETURN_IF_ABANDONED |
| 742 | SkASSERT(!path.isEmpty()); |
| 743 | |
| 744 | |
| 745 | // An Assumption here is that path renderer would use some form of tweaking |
| 746 | // the src color (either the input alpha or in the frag shader) to implement |
| 747 | // aa. If we have some future driver-mojo path AA that can do the right |
| 748 | // thing WRT to the blend then we'll need some query on the PR. |
| 749 | bool useCoverageAA = useAA && |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 750 | !pipelineBuilder->getRenderTarget()->isUnifiedMultisampled(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 751 | |
| 752 | |
| 753 | GrPathRendererChain::DrawType type = |
| 754 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
| 755 | GrPathRendererChain::kColor_DrawType; |
| 756 | |
| 757 | const SkPath* pathPtr = &path; |
| 758 | SkTLazy<SkPath> tmpPath; |
| 759 | const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
| 760 | |
| 761 | // Try a 1st time without stroking the path and without allowing the SW renderer |
| 762 | GrPathRenderer* pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, |
| 763 | *strokeInfoPtr, false, type); |
| 764 | |
| 765 | GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
| 766 | if (NULL == pr && strokeInfo.isDashed()) { |
| 767 | // It didn't work above, so try again with dashed stroke converted to a dashless stroke. |
| 768 | if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pathPtr)) { |
| 769 | return; |
| 770 | } |
| 771 | pathPtr = tmpPath.get(); |
| 772 | if (pathPtr->isEmpty()) { |
| 773 | return; |
| 774 | } |
| 775 | strokeInfoPtr = &dashlessStrokeInfo; |
| 776 | pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr, |
| 777 | false, type); |
| 778 | } |
| 779 | |
| 780 | if (NULL == pr) { |
| 781 | if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMatrix, NULL) && |
| 782 | !strokeInfoPtr->isFillStyle()) { |
| 783 | // It didn't work above, so try again with stroke converted to a fill. |
| 784 | if (!tmpPath.isValid()) { |
| 785 | tmpPath.init(); |
| 786 | } |
| 787 | dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())); |
| 788 | if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { |
| 789 | return; |
| 790 | } |
| 791 | pathPtr = tmpPath.get(); |
| 792 | if (pathPtr->isEmpty()) { |
| 793 | return; |
| 794 | } |
| 795 | dashlessStrokeInfo.setFillStyle(); |
| 796 | strokeInfoPtr = &dashlessStrokeInfo; |
| 797 | } |
| 798 | |
| 799 | // This time, allow SW renderer |
| 800 | pr = fContext->getPathRenderer(target, pipelineBuilder, viewMatrix, *pathPtr, *strokeInfoPtr, |
| 801 | true, type); |
| 802 | } |
| 803 | |
| 804 | if (NULL == pr) { |
| 805 | #ifdef SK_DEBUG |
| 806 | SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 807 | #endif |
| 808 | return; |
| 809 | } |
| 810 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 811 | GrPathRenderer::DrawPathArgs args; |
| 812 | args.fTarget = target; |
| 813 | args.fResourceProvider = fContext->resourceProvider(); |
| 814 | args.fPipelineBuilder = pipelineBuilder; |
| 815 | args.fColor = color; |
| 816 | args.fViewMatrix = &viewMatrix; |
| 817 | args.fPath = pathPtr; |
| 818 | args.fStroke = strokeInfoPtr; |
| 819 | args.fAntiAlias = useCoverageAA; |
| 820 | pr->drawPath(args); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 821 | } |
| 822 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 823 | bool GrDrawContext::prepareToDraw(GrRenderTarget* rt) { |
| 824 | RETURN_FALSE_IF_ABANDONED |
| 825 | |
| 826 | ASSERT_OWNED_RESOURCE(rt); |
| 827 | SkASSERT(rt); |
| 828 | return true; |
| 829 | } |
| 830 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 831 | void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrBatch* batch) { |
joshualitt | 1c73548 | 2015-07-13 08:08:25 -0700 | [diff] [blame] | 832 | fDrawTarget->drawBatch(*pipelineBuilder, batch); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 833 | } |