OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrBatchTest.h" | 8 #include "GrBatchTest.h" |
9 #include "GrColor.h" | 9 #include "GrColor.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
11 #include "GrDrawContextPriv.h" | 11 #include "GrDrawContextPriv.h" |
12 #include "GrDrawingManager.h" | 12 #include "GrDrawingManager.h" |
13 #include "GrOvalRenderer.h" | 13 #include "GrOvalRenderer.h" |
14 #include "GrPathRenderer.h" | 14 #include "GrPathRenderer.h" |
15 #include "GrRenderTarget.h" | 15 #include "GrRenderTarget.h" |
16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
17 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
| 18 #include "GrInstancedRendering.h" |
18 #include "SkSurfacePriv.h" | 19 #include "SkSurfacePriv.h" |
19 | 20 |
20 #include "batches/GrBatch.h" | 21 #include "batches/GrBatch.h" |
21 #include "batches/GrDrawAtlasBatch.h" | 22 #include "batches/GrDrawAtlasBatch.h" |
22 #include "batches/GrDrawVerticesBatch.h" | 23 #include "batches/GrDrawVerticesBatch.h" |
23 #include "batches/GrRectBatchFactory.h" | 24 #include "batches/GrRectBatchFactory.h" |
24 #include "batches/GrNinePatch.h" // TODO Factory | 25 #include "batches/GrNinePatch.h" // TODO Factory |
25 | 26 |
26 #include "effects/GrRRectEffect.h" | 27 #include "effects/GrRRectEffect.h" |
27 | 28 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 : fDrawingManager(drawingMgr) | 65 : fDrawingManager(drawingMgr) |
65 , fRenderTarget(rt) | 66 , fRenderTarget(rt) |
66 , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) | 67 , fDrawTarget(SkSafeRef(rt->getLastDrawTarget())) |
67 , fContext(context) | 68 , fContext(context) |
68 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) | 69 , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) |
69 , fAuditTrail(auditTrail) | 70 , fAuditTrail(auditTrail) |
70 #ifdef SK_DEBUG | 71 #ifdef SK_DEBUG |
71 , fSingleOwner(singleOwner) | 72 , fSingleOwner(singleOwner) |
72 #endif | 73 #endif |
73 { | 74 { |
| 75 fInstancedRenderingFlags = GrInstancedRendering::kColorWrite_Flag; |
| 76 if (fRenderTarget->isStencilBufferMultisampled()) { |
| 77 fInstancedRenderingFlags |= GrInstancedRendering::kStencilBufferMSAA_Fla
g; |
| 78 } |
| 79 if (fRenderTarget->isUnifiedMultisampled()) { |
| 80 fInstancedRenderingFlags |= GrInstancedRendering::kColorBufferMSAA_Flag; |
| 81 } |
74 SkDEBUGCODE(this->validate();) | 82 SkDEBUGCODE(this->validate();) |
75 } | 83 } |
76 | 84 |
77 #ifdef SK_DEBUG | 85 #ifdef SK_DEBUG |
78 void GrDrawContext::validate() const { | 86 void GrDrawContext::validate() const { |
79 SkASSERT(fRenderTarget); | 87 SkASSERT(fRenderTarget); |
80 ASSERT_OWNED_RESOURCE(fRenderTarget); | 88 ASSERT_OWNED_RESOURCE(fRenderTarget); |
81 | 89 |
82 if (fDrawTarget && !fDrawTarget->isClosed()) { | 90 if (fDrawTarget && !fDrawTarget->isClosed()) { |
83 SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); | 91 SkASSERT(fRenderTarget->getLastDrawTarget() == fDrawTarget); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 250 |
243 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { | 251 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { |
244 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 252 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
245 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 253 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
246 } | 254 } |
247 | 255 |
248 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { | 256 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { |
249 return viewMatrix.preservesRightAngles(); | 257 return viewMatrix.preservesRightAngles(); |
250 } | 258 } |
251 | 259 |
252 static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt) { | 260 static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt, b
ool* useHWAA) { |
253 return paint.isAntiAlias() && !rt->isUnifiedMultisampled(); | 261 if (!paint.isAntiAlias()) { |
| 262 *useHWAA = false; |
| 263 return false; |
| 264 } else { |
| 265 *useHWAA = rt->isUnifiedMultisampled(); |
| 266 return !rt->isUnifiedMultisampled(); |
| 267 } |
254 } | 268 } |
255 | 269 |
256 GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, | 270 GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, |
257 const SkMatrix& viewMatrix, | 271 const SkMatrix& viewMatrix, |
258 const SkRect& rect) { | 272 const SkRect& rect, |
259 | 273 uint32_t extraInstRenderFlags, |
260 GrDrawBatch* batch = nullptr; | 274 bool* useHWAA) { |
261 if (should_apply_coverage_aa(paint, fRenderTarget)) { | 275 if (GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering())
{ |
| 276 if (GrDrawBatch* batch = ir->recordRect(rect, viewMatrix, paint.getColor
(), |
| 277 paint.isAntiAlias(), |
| 278 fInstancedRenderingFlags | extra
InstRenderFlags, |
| 279 useHWAA)) { |
| 280 return batch; |
| 281 } |
| 282 } |
| 283 if (should_apply_coverage_aa(paint, fRenderTarget, useHWAA)) { |
262 // The fill path can handle rotation but not skew. | 284 // The fill path can handle rotation but not skew. |
263 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 285 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
264 SkRect devBoundRect; | 286 SkRect devBoundRect; |
265 viewMatrix.mapRect(&devBoundRect, rect); | 287 viewMatrix.mapRect(&devBoundRect, rect); |
266 batch = GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatri
x, | 288 return GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatrix
, rect, |
267 rect, devBoundRect); | 289 devBoundRect); |
268 } | 290 } |
269 } else { | 291 } else { |
270 // filled BW rect | 292 // filled BW rect |
271 batch = GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix
, rect, | 293 return GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix,
rect, nullptr, |
272 nullptr, nullptr); | 294 nullptr); |
273 } | 295 } |
274 | 296 |
275 return batch; | 297 return nullptr; |
276 } | 298 } |
277 | 299 |
278 void GrDrawContext::drawRect(const GrClip& clip, | 300 void GrDrawContext::drawRect(const GrClip& clip, |
279 const GrPaint& paint, | 301 const GrPaint& paint, |
280 const SkMatrix& viewMatrix, | 302 const SkMatrix& viewMatrix, |
281 const SkRect& rect, | 303 const SkRect& rect, |
282 const GrStrokeInfo* strokeInfo) { | 304 const GrStrokeInfo* strokeInfo) { |
283 ASSERT_SINGLE_OWNER | 305 ASSERT_SINGLE_OWNER |
284 RETURN_IF_ABANDONED | 306 RETURN_IF_ABANDONED |
285 SkDEBUGCODE(this->validate();) | 307 SkDEBUGCODE(this->validate();) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 GrColor clearColor; | 342 GrColor clearColor; |
321 if (paint.isConstantBlendedColor(&clearColor)) { | 343 if (paint.isConstantBlendedColor(&clearColor)) { |
322 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen
derTarget); | 344 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen
derTarget); |
323 return; | 345 return; |
324 } | 346 } |
325 } | 347 } |
326 } | 348 } |
327 } | 349 } |
328 | 350 |
329 bool snapToPixelCenters = false; | 351 bool snapToPixelCenters = false; |
| 352 bool useHWAA; |
330 SkAutoTUnref<GrDrawBatch> batch; | 353 SkAutoTUnref<GrDrawBatch> batch; |
331 if (width < 0) { | 354 if (width < 0) { |
332 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect)); | 355 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, 0, &useHWAA)
); |
333 } else { | 356 } else { |
334 GrColor color = paint.getColor(); | 357 GrColor color = paint.getColor(); |
335 | 358 |
336 if (should_apply_coverage_aa(paint, fRenderTarget)) { | 359 if (should_apply_coverage_aa(paint, fRenderTarget, &useHWAA)) { |
337 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). | 360 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). |
338 if (viewMatrix.rectStaysRect()) { | 361 if (viewMatrix.rectStaysRect()) { |
339 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, | 362 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, |
340 *strokeInfo)); | 363 *strokeInfo)); |
341 } | 364 } |
342 } else { | 365 } else { |
343 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit | 366 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit |
344 // deterministic | 367 // deterministic |
345 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); | 368 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); |
346 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, | 369 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, |
347 width, snapToPixel
Centers)); | 370 width, snapToPixel
Centers)); |
348 | 371 |
349 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of | 372 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of |
350 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not | 373 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not |
351 // when MSAA is enabled because it can cause ugly artifacts. | 374 // when MSAA is enabled because it can cause ugly artifacts. |
352 } | 375 } |
353 } | 376 } |
354 | 377 |
355 if (batch) { | 378 if (batch) { |
356 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 379 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 380 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
357 | 381 |
358 if (snapToPixelCenters) { | 382 if (snapToPixelCenters) { |
359 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, | 383 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, |
360 snapToPixelCenters); | 384 snapToPixelCenters); |
361 } | 385 } |
362 | 386 |
363 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 387 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
364 return; | 388 return; |
365 } | 389 } |
366 | 390 |
(...skipping 15 matching lines...) Expand all Loading... |
382 RETURN_FALSE_IF_ABANDONED_PRIV | 406 RETURN_FALSE_IF_ABANDONED_PRIV |
383 SkDEBUGCODE(fDrawContext->validate();) | 407 SkDEBUGCODE(fDrawContext->validate();) |
384 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); | 408 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); |
385 | 409 |
386 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 410 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
387 | 411 |
388 GrPaint paint; | 412 GrPaint paint; |
389 paint.setAntiAlias(doAA); | 413 paint.setAntiAlias(doAA); |
390 paint.setCoverageSetOpXPFactory(op, invert); | 414 paint.setCoverageSetOpXPFactory(op, invert); |
391 | 415 |
392 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa
trix, rect)); | 416 bool useHWAA; |
| 417 SkAutoTUnref<GrDrawBatch> batch( |
| 418 fDrawContext->getFillRectBatch(paint, viewMatrix, rect, |
| 419 GrInstancedRendering::kStencilWrite_Flag,
&useHWAA)); |
393 if (batch) { | 420 if (batch) { |
394 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, Gr
Clip::WideOpen()); | 421 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, Gr
Clip::WideOpen()); |
| 422 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
395 pipelineBuilder.setStencil(ss); | 423 pipelineBuilder.setStencil(ss); |
396 | 424 |
397 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissor
Rect); | 425 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissor
Rect); |
398 return true; | 426 return true; |
399 } | 427 } |
400 | 428 |
401 SkPath path; | 429 SkPath path; |
402 path.setIsVolatile(true); | 430 path.setIsVolatile(true); |
403 path.addRect(rect); | 431 path.addRect(rect); |
404 return this->drawAndStencilPath(scissorRect, ss, op, invert, doAA, viewMatri
x, path); | 432 return this->drawAndStencilPath(scissorRect, ss, op, invert, doAA, viewMatri
x, path); |
405 } | 433 } |
406 | 434 |
407 void GrDrawContext::fillRectToRect(const GrClip& clip, | 435 void GrDrawContext::fillRectToRect(const GrClip& clip, |
408 const GrPaint& paint, | 436 const GrPaint& paint, |
409 const SkMatrix& viewMatrix, | 437 const SkMatrix& viewMatrix, |
410 const SkRect& rectToDraw, | 438 const SkRect& rectToDraw, |
411 const SkRect& localRect) { | 439 const SkRect& localRect) { |
412 ASSERT_SINGLE_OWNER | 440 ASSERT_SINGLE_OWNER |
413 RETURN_IF_ABANDONED | 441 RETURN_IF_ABANDONED |
414 SkDEBUGCODE(this->validate();) | 442 SkDEBUGCODE(this->validate();) |
415 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); | 443 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
416 | 444 |
417 AutoCheckFlush acf(fDrawingManager); | 445 AutoCheckFlush acf(fDrawingManager); |
418 | 446 |
| 447 bool useHWAA; |
419 SkAutoTUnref<GrDrawBatch> batch; | 448 SkAutoTUnref<GrDrawBatch> batch; |
420 if (should_apply_coverage_aa(paint, fRenderTarget) && | 449 if (GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering())
{ |
421 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 450 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc
alRect, |
422 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie
wMatrix, rectToDraw, | 451 paint.isAntiAlias(), fInstancedRenderingFlags
, &useHWAA)); |
423 localRect)); | 452 } |
424 } else { | 453 if (!batch) { |
425 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 454 if (should_apply_coverage_aa(paint, fRenderTarget, &useHWAA) && |
426 &localRect, nullptr)); | 455 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 456 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(),
viewMatrix, |
| 457 rectToDraw, local
Rect)); |
| 458 } else { |
| 459 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), vi
ewMatrix, |
| 460 rectToDraw, &localRe
ct, nullptr)); |
| 461 } |
427 } | 462 } |
428 | 463 |
429 if (batch) { | 464 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
430 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 465 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
431 this->drawBatch(&pipelineBuilder, batch); | 466 this->drawBatch(&pipelineBuilder, batch); |
432 } | |
433 } | 467 } |
434 | 468 |
435 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, | 469 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
436 const GrPaint& paint, | 470 const GrPaint& paint, |
437 const SkMatrix& viewMatrix, | 471 const SkMatrix& viewMatrix, |
438 const SkRect& rectToDraw, | 472 const SkRect& rectToDraw, |
439 const SkMatrix& localMatrix) { | 473 const SkMatrix& localMatrix) { |
440 ASSERT_SINGLE_OWNER | 474 ASSERT_SINGLE_OWNER |
441 RETURN_IF_ABANDONED | 475 RETURN_IF_ABANDONED |
442 SkDEBUGCODE(this->validate();) | 476 SkDEBUGCODE(this->validate();) |
443 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); | 477 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); |
444 | 478 |
445 AutoCheckFlush acf(fDrawingManager); | 479 AutoCheckFlush acf(fDrawingManager); |
446 | 480 |
| 481 bool useHWAA; |
447 SkAutoTUnref<GrDrawBatch> batch; | 482 SkAutoTUnref<GrDrawBatch> batch; |
448 if (should_apply_coverage_aa(paint, fRenderTarget) && | 483 if (GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering())
{ |
449 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 484 batch.reset(ir->recordRect(rectToDraw, viewMatrix, paint.getColor(), loc
alMatrix, |
450 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca
lMatrix, | 485 paint.isAntiAlias(), fInstancedRenderingFlags
, &useHWAA)); |
451 rectToDraw)); | 486 } |
452 } else { | 487 if (!batch) { |
453 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 488 if (should_apply_coverage_aa(paint, fRenderTarget, &useHWAA) && |
454 nullptr, &localMatrix)); | 489 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 490 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix,
localMatrix, |
| 491 rectToDraw)); |
| 492 } else { |
| 493 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), vi
ewMatrix, |
| 494 rectToDraw, nullptr,
&localMatrix)); |
| 495 } |
455 } | 496 } |
456 | 497 |
457 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 498 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 499 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
458 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 500 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
459 } | 501 } |
460 | 502 |
461 void GrDrawContext::drawVertices(const GrClip& clip, | 503 void GrDrawContext::drawVertices(const GrClip& clip, |
462 const GrPaint& paint, | 504 const GrPaint& paint, |
463 const SkMatrix& viewMatrix, | 505 const SkMatrix& viewMatrix, |
464 GrPrimitiveType primitiveType, | 506 GrPrimitiveType primitiveType, |
465 int vertexCount, | 507 int vertexCount, |
466 const SkPoint positions[], | 508 const SkPoint positions[], |
467 const SkPoint texCoords[], | 509 const SkPoint texCoords[], |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); | 583 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); |
542 | 584 |
543 if (rrect.isEmpty()) { | 585 if (rrect.isEmpty()) { |
544 return; | 586 return; |
545 } | 587 } |
546 | 588 |
547 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice | 589 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
548 | 590 |
549 AutoCheckFlush acf(fDrawingManager); | 591 AutoCheckFlush acf(fDrawingManager); |
550 | 592 |
551 if (should_apply_coverage_aa(paint, fRenderTarget)) { | 593 bool useHWAA; |
552 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 594 SkAutoTUnref<GrDrawBatch> batch; |
553 | 595 if (this->getDrawTarget()->instancedRendering() && strokeInfo.isFillStyle())
{ |
554 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g
etColor(), | 596 GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
555 viewMat
rix, | 597 batch.reset(ir->recordRRect(rrect, viewMatrix, paint.getColor(), paint.i
sAntiAlias(), |
556 rrect, | 598 fInstancedRenderingFlags, &useHWAA)); |
557 strokeI
nfo, | 599 } |
558 shaderC
aps)); | 600 if (!batch && should_apply_coverage_aa(paint, fRenderTarget, &useHWAA)) { |
559 if (batch) { | 601 batch.reset(GrOvalRenderer::CreateRRectBatch(paint.getColor(), viewMatri
x, rrect, |
560 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 602 strokeInfo, fContext->caps(
)->shaderCaps())); |
561 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | |
562 return; | |
563 } | |
564 } | 603 } |
565 | 604 |
566 SkPath path; | 605 if (batch) { |
567 path.setIsVolatile(true); | 606 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
568 path.addRRect(rrect); | 607 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
569 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); | 608 this->drawBatch(&pipelineBuilder, batch); |
| 609 } else { |
| 610 SkPath path; |
| 611 path.setIsVolatile(true); |
| 612 path.addRRect(rrect); |
| 613 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 614 } |
570 } | 615 } |
571 | 616 |
572 bool GrDrawContext::drawFilledDRRect(const GrClip& clip, | 617 bool GrDrawContext::drawFilledDRRect(const GrClip& clip, |
573 const GrPaint& paintIn, | 618 const GrPaint& paintIn, |
574 const SkMatrix& viewMatrix, | 619 const SkMatrix& viewMatrix, |
575 const SkRRect& origOuter, | 620 const SkRRect& origOuter, |
576 const SkRRect& origInner) { | 621 const SkRRect& origInner) { |
577 SkASSERT(!origInner.isEmpty()); | 622 SkASSERT(!origInner.isEmpty()); |
578 SkASSERT(!origOuter.isEmpty()); | 623 SkASSERT(!origOuter.isEmpty()); |
579 | 624 |
| 625 if (GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering())
{ |
| 626 bool useHWAA; |
| 627 SkAutoTUnref<GrDrawBatch> batch(ir->recordDRRect(origOuter, origInner, v
iewMatrix, |
| 628 paintIn.getColor(), pai
ntIn.isAntiAlias(), |
| 629 fInstancedRenderingFlag
s, &useHWAA)); |
| 630 if (batch) { |
| 631 GrPipelineBuilder pipelineBuilder(paintIn, fRenderTarget, clip); |
| 632 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHW
AA); |
| 633 this->drawBatch(&pipelineBuilder, batch); |
| 634 return true; |
| 635 } |
| 636 } |
| 637 |
580 bool applyAA = paintIn.isAntiAlias() && !fRenderTarget->isUnifiedMultisample
d(); | 638 bool applyAA = paintIn.isAntiAlias() && !fRenderTarget->isUnifiedMultisample
d(); |
581 | 639 |
582 GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdge
Type : | 640 GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdge
Type : |
583 kInverseFillBW_GrProcessorEdge
Type; | 641 kInverseFillBW_GrProcessorEdge
Type; |
584 GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : | 642 GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
585 kFillBW_GrProcessorEdgeType; | 643 kFillBW_GrProcessorEdgeType; |
586 | 644 |
587 SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); | 645 SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
588 SkMatrix inverseVM; | 646 SkMatrix inverseVM; |
589 if (!viewMatrix.isIdentity()) { | 647 if (!viewMatrix.isIdentity()) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); | 726 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); |
669 | 727 |
670 if (oval.isEmpty()) { | 728 if (oval.isEmpty()) { |
671 return; | 729 return; |
672 } | 730 } |
673 | 731 |
674 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice | 732 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
675 | 733 |
676 AutoCheckFlush acf(fDrawingManager); | 734 AutoCheckFlush acf(fDrawingManager); |
677 | 735 |
678 if (should_apply_coverage_aa(paint, fRenderTarget)) { | 736 bool useHWAA; |
679 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 737 SkAutoTUnref<GrDrawBatch> batch; |
680 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge
tColor(), | 738 if (this->getDrawTarget()->instancedRendering() && strokeInfo.isFillStyle())
{ |
681 viewMatr
ix, | 739 GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
682 oval, | 740 batch.reset(ir->recordOval(oval, viewMatrix, paint.getColor(), paint.isA
ntiAlias(), |
683 strokeIn
fo, | 741 fInstancedRenderingFlags, &useHWAA)); |
684 shaderCa
ps)); | 742 } |
685 if (batch) { | 743 if (!batch && should_apply_coverage_aa(paint, fRenderTarget, &useHWAA)) { |
686 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 744 batch.reset(GrOvalRenderer::CreateOvalBatch(paint.getColor(), viewMatrix
, oval, strokeInfo, |
687 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 745 fContext->caps()->shaderCaps
())); |
688 return; | |
689 } | |
690 } | 746 } |
691 | 747 |
692 SkPath path; | 748 if (batch) { |
693 path.setIsVolatile(true); | 749 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
694 path.addOval(oval); | 750 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
695 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); | 751 this->drawBatch(&pipelineBuilder, batch); |
| 752 } else { |
| 753 SkPath path; |
| 754 path.setIsVolatile(true); |
| 755 path.addOval(oval); |
| 756 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 757 } |
696 } | 758 } |
697 | 759 |
698 void GrDrawContext::drawImageNine(const GrClip& clip, | 760 void GrDrawContext::drawImageNine(const GrClip& clip, |
699 const GrPaint& paint, | 761 const GrPaint& paint, |
700 const SkMatrix& viewMatrix, | 762 const SkMatrix& viewMatrix, |
701 int imageWidth, | 763 int imageWidth, |
702 int imageHeight, | 764 int imageHeight, |
703 const SkIRect& center, | 765 const SkIRect& center, |
704 const SkRect& dst) { | 766 const SkRect& dst) { |
705 ASSERT_SINGLE_OWNER | 767 ASSERT_SINGLE_OWNER |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); | 866 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); |
805 | 867 |
806 if (path.isEmpty()) { | 868 if (path.isEmpty()) { |
807 if (path.isInverseFillType()) { | 869 if (path.isInverseFillType()) { |
808 this->drawPaint(clip, paint, viewMatrix); | 870 this->drawPaint(clip, paint, viewMatrix); |
809 } | 871 } |
810 return; | 872 return; |
811 } | 873 } |
812 | 874 |
813 AutoCheckFlush acf(fDrawingManager); | 875 AutoCheckFlush acf(fDrawingManager); |
| 876 SkAutoTUnref<GrDrawBatch> fastBatch; |
| 877 bool useHWAA; |
814 | 878 |
815 if (should_apply_coverage_aa(paint, fRenderTarget) && !strokeInfo.isDashed()
) { | 879 // Paths are expensive - try to avoid them for special cases |
816 if (strokeInfo.getWidth() < 0 && !path.isConvex()) { | 880 SkRect nestedRects[2]; |
817 // Concave AA paths are expensive - try to avoid them for special ca
ses | 881 SkRect ovalRect; |
818 SkRect rects[2]; | 882 if (strokeInfo.isFillStyle() && !path.isConvex() && |
819 | 883 is_nested_rects(viewMatrix, path, strokeInfo, nestedRects)) { |
820 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { | 884 if (GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering
()) { |
821 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( | 885 SkASSERT(nestedRects[0].contains(nestedRects[1])); |
822 paint.getColor(), viewMatrix, rects)); | 886 fastBatch.reset(ir->recordDRRect(SkRRect::MakeRect(nestedRects[0]), |
823 | 887 SkRRect::MakeRect(nestedRects[1]),
viewMatrix, |
824 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 888 paint.getColor(), paint.isAntiAlias
(), |
825 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 889 fInstancedRenderingFlags, &useHWAA)
); |
826 return; | |
827 } | |
828 } | 890 } |
829 SkRect ovalRect; | 891 if (!fastBatch && should_apply_coverage_aa(paint, fRenderTarget, &useHWA
A)) { |
830 bool isOval = path.isOval(&ovalRect); | 892 fastBatch.reset(GrRectBatchFactory::CreateAAFillNestedRects(paint.ge
tColor(), |
831 | 893 viewMatr
ix, nestedRects)); |
832 if (isOval && !path.isInverseFillType()) { | 894 } |
833 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 895 } else if (!path.isInverseFillType() && path.isOval(&ovalRect)) { |
834 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain
t.getColor(), | 896 if (this->getDrawTarget()->instancedRendering() && strokeInfo.isFillStyl
e()) { |
835 view
Matrix, | 897 GrInstancedRendering* ir = this->getDrawTarget()->instancedRendering
(); |
836 oval
Rect, | 898 fastBatch.reset(ir->recordOval(ovalRect, viewMatrix, paint.getColor(
), |
837 stro
keInfo, | 899 paint.isAntiAlias(), fInstancedRender
ingFlags, |
838 shad
erCaps)); | 900 &useHWAA)); |
839 if (batch) { | 901 } |
840 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 902 if (!fastBatch && !strokeInfo.isDashed() && |
841 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 903 should_apply_coverage_aa(paint, fRenderTarget, &useHWAA)) { |
842 return; | 904 fastBatch.reset(GrOvalRenderer::CreateOvalBatch(paint.getColor(), vi
ewMatrix, |
843 } | 905 ovalRect, strokeInfo
, |
| 906 fContext->caps()->sh
aderCaps())); |
844 } | 907 } |
845 } | 908 } |
846 | 909 |
847 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 910 if (fastBatch) { |
848 // Scratch textures can be recycled after they are returned to the texture | 911 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
849 // cache. This presents a potential hazard for buffered drawing. However, | 912 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
850 // the writePixels that uploads to the scratch will perform a flush so we're | 913 this->drawBatch(&pipelineBuilder, fastBatch); |
851 // OK. | 914 } else { |
852 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); | 915 // Note that internalDrawPath may sw-rasterize the path into a scratch t
exture. |
| 916 // Scratch textures can be recycled after they are returned to the textu
re |
| 917 // cache. This presents a potential hazard for buffered drawing. However
, |
| 918 // the writePixels that uploads to the scratch will perform a flush so w
e're |
| 919 // OK. |
| 920 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 921 } |
853 } | 922 } |
854 | 923 |
855 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, | 924 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, |
856 const GrStencilSettings& ss, | 925 const GrStencilSettings& ss, |
857 SkRegion::Op op, | 926 SkRegion::Op op, |
858 bool invert, | 927 bool invert, |
859 bool doAA, | 928 bool doAA, |
860 const SkMatrix& viewMatrix, | 929 const SkMatrix& viewMatrix, |
861 const SkPath& path) { | 930 const SkPath& path) { |
862 ASSERT_SINGLE_OWNER_PRIV | 931 ASSERT_SINGLE_OWNER_PRIV |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 const SkPath& path, | 1002 const SkPath& path, |
934 const GrStrokeInfo& strokeInfo) { | 1003 const GrStrokeInfo& strokeInfo) { |
935 ASSERT_SINGLE_OWNER | 1004 ASSERT_SINGLE_OWNER |
936 RETURN_IF_ABANDONED | 1005 RETURN_IF_ABANDONED |
937 SkASSERT(!path.isEmpty()); | 1006 SkASSERT(!path.isEmpty()); |
938 | 1007 |
939 // An Assumption here is that path renderer would use some form of tweaking | 1008 // An Assumption here is that path renderer would use some form of tweaking |
940 // the src color (either the input alpha or in the frag shader) to implement | 1009 // the src color (either the input alpha or in the frag shader) to implement |
941 // aa. If we have some future driver-mojo path AA that can do the right | 1010 // aa. If we have some future driver-mojo path AA that can do the right |
942 // thing WRT to the blend then we'll need some query on the PR. | 1011 // thing WRT to the blend then we'll need some query on the PR. |
943 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget); | 1012 bool useHWAA; |
| 1013 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget, &useHWAA
); |
944 const bool isStencilDisabled = true; | 1014 const bool isStencilDisabled = true; |
945 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); | 1015 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); |
946 | 1016 |
947 const GrPathRendererChain::DrawType type = | 1017 const GrPathRendererChain::DrawType type = |
948 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType | 1018 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
949 : GrPathRendererChain::kColor_DrawType; | 1019 : GrPathRendererChain::kColor_DrawType; |
950 | 1020 |
951 const SkPath* pathPtr = &path; | 1021 const SkPath* pathPtr = &path; |
952 SkTLazy<SkPath> tmpPath; | 1022 SkTLazy<SkPath> tmpPath; |
953 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; | 1023 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 } | 1079 } |
1010 | 1080 |
1011 if (nullptr == pr) { | 1081 if (nullptr == pr) { |
1012 #ifdef SK_DEBUG | 1082 #ifdef SK_DEBUG |
1013 SkDebugf("Unable to find path renderer compatible with path.\n"); | 1083 SkDebugf("Unable to find path renderer compatible with path.\n"); |
1014 #endif | 1084 #endif |
1015 return; | 1085 return; |
1016 } | 1086 } |
1017 | 1087 |
1018 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 1088 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 1089 pipelineBuilder.setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
1019 | 1090 |
1020 GrPathRenderer::DrawPathArgs args; | 1091 GrPathRenderer::DrawPathArgs args; |
1021 args.fTarget = this->getDrawTarget(); | 1092 args.fTarget = this->getDrawTarget(); |
1022 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); | 1093 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); |
1023 args.fPipelineBuilder = &pipelineBuilder; | 1094 args.fPipelineBuilder = &pipelineBuilder; |
1024 args.fColor = paint.getColor(); | 1095 args.fColor = paint.getColor(); |
1025 args.fViewMatrix = &viewMatrix; | 1096 args.fViewMatrix = &viewMatrix; |
1026 args.fPath = pathPtr; | 1097 args.fPath = pathPtr; |
1027 args.fStroke = strokeInfoPtr; | 1098 args.fStroke = strokeInfoPtr; |
1028 args.fAntiAlias = useCoverageAA; | 1099 args.fAntiAlias = useCoverageAA; |
1029 args.fGammaCorrect = this->isGammaCorrect(); | 1100 args.fGammaCorrect = this->isGammaCorrect(); |
1030 pr->drawPath(args); | 1101 pr->drawPath(args); |
1031 } | 1102 } |
1032 | 1103 |
1033 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { | 1104 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
1034 ASSERT_SINGLE_OWNER | 1105 ASSERT_SINGLE_OWNER |
1035 RETURN_IF_ABANDONED | 1106 RETURN_IF_ABANDONED |
1036 SkDEBUGCODE(this->validate();) | 1107 SkDEBUGCODE(this->validate();) |
1037 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1108 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
1038 | 1109 |
1039 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 1110 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
1040 } | 1111 } |
OLD | NEW |