| 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" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (!viewMatrix.invert(&localMatrix)) { | 233 if (!viewMatrix.invert(&localMatrix)) { |
| 234 SkDebugf("Could not invert matrix\n"); | 234 SkDebugf("Could not invert matrix\n"); |
| 235 return; | 235 return; |
| 236 } | 236 } |
| 237 | 237 |
| 238 AutoCheckFlush acf(fDrawingManager); | 238 AutoCheckFlush acf(fDrawingManager); |
| 239 | 239 |
| 240 SkAutoTUnref<GrDrawBatch> batch( | 240 SkAutoTUnref<GrDrawBatch> batch( |
| 241 GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix:
:I(), r, nullptr, | 241 GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix:
:I(), r, nullptr, |
| 242 &localMatrix)); | 242 &localMatrix)); |
| 243 GrPipelineBuilder pipelineBuilder(*paint, this->isUnifiedMultisampled())
; | 243 GrPipelineBuilder pipelineBuilder(*paint); // Create a pipeline builder
without hwaa. |
| 244 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 244 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { | 248 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
int) { |
| 249 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 249 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 250 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 250 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 251 } | 251 } |
| 252 | 252 |
| 253 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { | 253 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { |
| 254 return viewMatrix.preservesRightAngles(); | 254 return viewMatrix.preservesRightAngles(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt) { | 257 static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt, |
| 258 return paint.isAntiAlias() && !rt->isUnifiedMultisampled(); | 258 bool* useHWAA = nullptr) { |
| 259 if (!paint.isAntiAlias()) { |
| 260 if (useHWAA) { |
| 261 *useHWAA = false; |
| 262 } |
| 263 return false; |
| 264 } else { |
| 265 if (useHWAA) { |
| 266 *useHWAA = rt->isUnifiedMultisampled(); |
| 267 } |
| 268 return !rt->isUnifiedMultisampled(); |
| 269 } |
| 259 } | 270 } |
| 260 | 271 |
| 261 GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, | 272 GrDrawBatch* GrDrawContext::getFillRectBatch(const GrPaint& paint, |
| 262 const SkMatrix& viewMatrix, | 273 const SkMatrix& viewMatrix, |
| 263 const SkRect& rect) { | 274 const SkRect& rect, |
| 275 bool* useHWAA) { |
| 264 | 276 |
| 265 GrDrawBatch* batch = nullptr; | 277 GrDrawBatch* batch = nullptr; |
| 266 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 278 if (should_apply_coverage_aa(paint, fRenderTarget.get(), useHWAA)) { |
| 267 // The fill path can handle rotation but not skew. | 279 // The fill path can handle rotation but not skew. |
| 268 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 280 if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 269 SkRect devBoundRect; | 281 SkRect devBoundRect; |
| 270 viewMatrix.mapRect(&devBoundRect, rect); | 282 viewMatrix.mapRect(&devBoundRect, rect); |
| 271 batch = GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatri
x, | 283 batch = GrRectBatchFactory::CreateAAFill(paint.getColor(), viewMatri
x, |
| 272 rect, devBoundRect); | 284 rect, devBoundRect); |
| 273 } | 285 } |
| 274 } else { | 286 } else { |
| 275 // filled BW rect | 287 // filled BW rect |
| 276 batch = GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix
, rect, | 288 batch = GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMatrix
, rect, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // Will it blend? | 334 // Will it blend? |
| 323 GrColor clearColor; | 335 GrColor clearColor; |
| 324 if (paint.isConstantBlendedColor(&clearColor)) { | 336 if (paint.isConstantBlendedColor(&clearColor)) { |
| 325 this->getDrawTarget()->clear(nullptr, clearColor, true, this
); | 337 this->getDrawTarget()->clear(nullptr, clearColor, true, this
); |
| 326 return; | 338 return; |
| 327 } | 339 } |
| 328 } | 340 } |
| 329 } | 341 } |
| 330 } | 342 } |
| 331 | 343 |
| 344 bool useHWAA; |
| 332 bool snapToPixelCenters = false; | 345 bool snapToPixelCenters = false; |
| 333 SkAutoTUnref<GrDrawBatch> batch; | 346 SkAutoTUnref<GrDrawBatch> batch; |
| 334 if (width < 0) { | 347 if (width < 0) { |
| 335 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect)); | 348 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
| 336 } else { | 349 } else { |
| 337 GrColor color = paint.getColor(); | 350 GrColor color = paint.getColor(); |
| 338 | 351 |
| 339 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 352 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
| 340 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). | 353 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). |
| 341 if (viewMatrix.rectStaysRect()) { | 354 if (viewMatrix.rectStaysRect()) { |
| 342 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, | 355 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, |
| 343 stroke)); | 356 stroke)); |
| 344 } | 357 } |
| 345 } else { | 358 } else { |
| 346 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit | 359 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit |
| 347 // deterministic | 360 // deterministic |
| 348 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); | 361 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); |
| 349 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, | 362 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, |
| 350 width, snapToPixel
Centers)); | 363 width, snapToPixel
Centers)); |
| 351 | 364 |
| 352 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of | 365 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of |
| 353 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not | 366 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not |
| 354 // when MSAA is enabled because it can cause ugly artifacts. | 367 // when MSAA is enabled because it can cause ugly artifacts. |
| 355 } | 368 } |
| 356 } | 369 } |
| 357 | 370 |
| 358 if (batch) { | 371 if (batch) { |
| 359 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 372 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 360 | 373 |
| 361 if (snapToPixelCenters) { | 374 if (snapToPixelCenters) { |
| 362 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, | 375 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, |
| 363 snapToPixelCenters); | 376 snapToPixelCenters); |
| 364 } | 377 } |
| 365 | 378 |
| 366 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 379 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 367 return; | 380 return; |
| 368 } | 381 } |
| 369 | 382 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 RETURN_IF_ABANDONED_PRIV | 415 RETURN_IF_ABANDONED_PRIV |
| 403 SkDEBUGCODE(fDrawContext->validate();) | 416 SkDEBUGCODE(fDrawContext->validate();) |
| 404 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); | 417 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); |
| 405 | 418 |
| 406 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 419 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 407 | 420 |
| 408 GrPaint paint; | 421 GrPaint paint; |
| 409 paint.setAntiAlias(doAA); | 422 paint.setAntiAlias(doAA); |
| 410 SkSafeUnref(paint.setXPFactory(GrDisableColorXPFactory::Create())); | 423 SkSafeUnref(paint.setXPFactory(GrDisableColorXPFactory::Create())); |
| 411 | 424 |
| 412 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa
trix, rect)); | 425 bool useHWAA; |
| 426 SkAutoTUnref<GrDrawBatch> batch( |
| 427 fDrawContext->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
| 413 SkASSERT(batch); | 428 SkASSERT(batch); |
| 414 | 429 |
| 415 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisampled
()); | 430 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 416 pipelineBuilder.setUserStencil(ss); | 431 pipelineBuilder.setUserStencil(ss); |
| 417 | 432 |
| 418 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip
, batch); | 433 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext, clip
, batch); |
| 419 } | 434 } |
| 420 | 435 |
| 421 bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, | 436 bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, |
| 422 const GrUserStencilSettings* ss, | 437 const GrUserStencilSettings* ss, |
| 423 SkRegion::Op op, | 438 SkRegion::Op op, |
| 424 bool invert, | 439 bool invert, |
| 425 bool doAA, | 440 bool doAA, |
| 426 const SkMatrix& viewMatrix, | 441 const SkMatrix& viewMatrix, |
| 427 const SkRect& rect) { | 442 const SkRect& rect) { |
| 428 ASSERT_SINGLE_OWNER_PRIV | 443 ASSERT_SINGLE_OWNER_PRIV |
| 429 RETURN_FALSE_IF_ABANDONED_PRIV | 444 RETURN_FALSE_IF_ABANDONED_PRIV |
| 430 SkDEBUGCODE(fDrawContext->validate();) | 445 SkDEBUGCODE(fDrawContext->validate();) |
| 431 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); | 446 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); |
| 432 | 447 |
| 433 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 448 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 434 | 449 |
| 435 GrPaint paint; | 450 GrPaint paint; |
| 436 paint.setAntiAlias(doAA); | 451 paint.setAntiAlias(doAA); |
| 437 paint.setCoverageSetOpXPFactory(op, invert); | 452 paint.setCoverageSetOpXPFactory(op, invert); |
| 438 | 453 |
| 439 SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMa
trix, rect)); | 454 bool useHWAA; |
| 455 SkAutoTUnref<GrDrawBatch> batch( |
| 456 fDrawContext->getFillRectBatch(paint, viewMatrix, rect, &useHWAA)); |
| 440 if (batch) { | 457 if (batch) { |
| 441 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->isUnifiedMultisam
pled()); | 458 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 442 pipelineBuilder.setUserStencil(ss); | 459 pipelineBuilder.setUserStencil(ss); |
| 443 | 460 |
| 444 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext,
clip, batch); | 461 fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, fDrawContext,
clip, batch); |
| 445 return true; | 462 return true; |
| 446 } | 463 } |
| 447 | 464 |
| 448 SkPath path; | 465 SkPath path; |
| 449 path.setIsVolatile(true); | 466 path.setIsVolatile(true); |
| 450 path.addRect(rect); | 467 path.addRect(rect); |
| 451 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path
); | 468 return this->drawAndStencilPath(clip, ss, op, invert, doAA, viewMatrix, path
); |
| 452 } | 469 } |
| 453 | 470 |
| 454 void GrDrawContext::fillRectToRect(const GrClip& clip, | 471 void GrDrawContext::fillRectToRect(const GrClip& clip, |
| 455 const GrPaint& paint, | 472 const GrPaint& paint, |
| 456 const SkMatrix& viewMatrix, | 473 const SkMatrix& viewMatrix, |
| 457 const SkRect& rectToDraw, | 474 const SkRect& rectToDraw, |
| 458 const SkRect& localRect) { | 475 const SkRect& localRect) { |
| 459 ASSERT_SINGLE_OWNER | 476 ASSERT_SINGLE_OWNER |
| 460 RETURN_IF_ABANDONED | 477 RETURN_IF_ABANDONED |
| 461 SkDEBUGCODE(this->validate();) | 478 SkDEBUGCODE(this->validate();) |
| 462 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); | 479 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
| 463 | 480 |
| 464 AutoCheckFlush acf(fDrawingManager); | 481 AutoCheckFlush acf(fDrawingManager); |
| 465 | 482 |
| 483 bool useHWAA; |
| 466 SkAutoTUnref<GrDrawBatch> batch; | 484 SkAutoTUnref<GrDrawBatch> batch; |
| 467 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && | 485 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
| 468 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 486 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 469 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie
wMatrix, rectToDraw, | 487 batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), vie
wMatrix, rectToDraw, |
| 470 localRect)); | 488 localRect)); |
| 471 } else { | 489 } else { |
| 472 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 490 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, |
| 473 &localRect, nullptr)); | 491 &localRect, nullptr)); |
| 474 } | 492 } |
| 475 | 493 |
| 476 if (batch) { | 494 if (batch) { |
| 477 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 495 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 478 this->drawBatch(pipelineBuilder, clip, batch); | 496 this->drawBatch(pipelineBuilder, clip, batch); |
| 479 } | 497 } |
| 480 } | 498 } |
| 481 | 499 |
| 482 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, | 500 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
| 483 const GrPaint& paint, | 501 const GrPaint& paint, |
| 484 const SkMatrix& viewMatrix, | 502 const SkMatrix& viewMatrix, |
| 485 const SkRect& rectToDraw, | 503 const SkRect& rectToDraw, |
| 486 const SkMatrix& localMatrix) { | 504 const SkMatrix& localMatrix) { |
| 487 ASSERT_SINGLE_OWNER | 505 ASSERT_SINGLE_OWNER |
| 488 RETURN_IF_ABANDONED | 506 RETURN_IF_ABANDONED |
| 489 SkDEBUGCODE(this->validate();) | 507 SkDEBUGCODE(this->validate();) |
| 490 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); | 508 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); |
| 491 | 509 |
| 492 AutoCheckFlush acf(fDrawingManager); | 510 AutoCheckFlush acf(fDrawingManager); |
| 493 | 511 |
| 512 bool useHWAA; |
| 494 SkAutoTUnref<GrDrawBatch> batch; | 513 SkAutoTUnref<GrDrawBatch> batch; |
| 495 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && | 514 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && |
| 496 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { | 515 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 497 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca
lMatrix, | 516 batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, loca
lMatrix, |
| 498 rectToDraw)); | 517 rectToDraw)); |
| 499 } else { | 518 } else { |
| 500 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, | 519 batch.reset(GrRectBatchFactory::CreateNonAAFill(paint.getColor(), viewMa
trix, rectToDraw, |
| 501 nullptr, &localMatrix)); | 520 nullptr, &localMatrix)); |
| 502 } | 521 } |
| 503 | 522 |
| 504 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 523 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 505 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 524 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 506 } | 525 } |
| 507 | 526 |
| 508 void GrDrawContext::drawVertices(const GrClip& clip, | 527 void GrDrawContext::drawVertices(const GrClip& clip, |
| 509 const GrPaint& paint, | 528 const GrPaint& paint, |
| 510 const SkMatrix& viewMatrix, | 529 const SkMatrix& viewMatrix, |
| 511 GrPrimitiveType primitiveType, | 530 GrPrimitiveType primitiveType, |
| 512 int vertexCount, | 531 int vertexCount, |
| 513 const SkPoint positions[], | 532 const SkPoint positions[], |
| 514 const SkPoint texCoords[], | 533 const SkPoint texCoords[], |
| (...skipping 24 matching lines...) Expand all Loading... |
| 539 bounds.outset(0.5f, 0.5f); | 558 bounds.outset(0.5f, 0.5f); |
| 540 } | 559 } |
| 541 | 560 |
| 542 GrDrawVerticesBatch::Geometry geometry; | 561 GrDrawVerticesBatch::Geometry geometry; |
| 543 geometry.fColor = paint.getColor(); | 562 geometry.fColor = paint.getColor(); |
| 544 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit
iveType, viewMatrix, | 563 SkAutoTUnref<GrDrawBatch> batch(GrDrawVerticesBatch::Create(geometry, primit
iveType, viewMatrix, |
| 545 positions, verte
xCount, indices, | 564 positions, verte
xCount, indices, |
| 546 indexCount, colo
rs, texCoords, | 565 indexCount, colo
rs, texCoords, |
| 547 bounds)); | 566 bounds)); |
| 548 | 567 |
| 549 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 568 GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
| 550 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 569 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 551 } | 570 } |
| 552 | 571 |
| 553 /////////////////////////////////////////////////////////////////////////////// | 572 /////////////////////////////////////////////////////////////////////////////// |
| 554 | 573 |
| 555 void GrDrawContext::drawAtlas(const GrClip& clip, | 574 void GrDrawContext::drawAtlas(const GrClip& clip, |
| 556 const GrPaint& paint, | 575 const GrPaint& paint, |
| 557 const SkMatrix& viewMatrix, | 576 const SkMatrix& viewMatrix, |
| 558 int spriteCount, | 577 int spriteCount, |
| 559 const SkRSXform xform[], | 578 const SkRSXform xform[], |
| 560 const SkRect texRect[], | 579 const SkRect texRect[], |
| 561 const SkColor colors[]) { | 580 const SkColor colors[]) { |
| 562 ASSERT_SINGLE_OWNER | 581 ASSERT_SINGLE_OWNER |
| 563 RETURN_IF_ABANDONED | 582 RETURN_IF_ABANDONED |
| 564 SkDEBUGCODE(this->validate();) | 583 SkDEBUGCODE(this->validate();) |
| 565 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); | 584 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawAtlas"); |
| 566 | 585 |
| 567 AutoCheckFlush acf(fDrawingManager); | 586 AutoCheckFlush acf(fDrawingManager); |
| 568 | 587 |
| 569 GrDrawAtlasBatch::Geometry geometry; | 588 GrDrawAtlasBatch::Geometry geometry; |
| 570 geometry.fColor = paint.getColor(); | 589 geometry.fColor = paint.getColor(); |
| 571 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri
x, spriteCount, | 590 SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatri
x, spriteCount, |
| 572 xform, texRect, col
ors)); | 591 xform, texRect, col
ors)); |
| 573 | 592 |
| 574 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 593 GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
| 575 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 594 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 576 } | 595 } |
| 577 | 596 |
| 578 /////////////////////////////////////////////////////////////////////////////// | 597 /////////////////////////////////////////////////////////////////////////////// |
| 579 | 598 |
| 580 void GrDrawContext::drawRRect(const GrClip& clip, | 599 void GrDrawContext::drawRRect(const GrClip& clip, |
| 581 const GrPaint& paint, | 600 const GrPaint& paint, |
| 582 const SkMatrix& viewMatrix, | 601 const SkMatrix& viewMatrix, |
| 583 const SkRRect& rrect, | 602 const SkRRect& rrect, |
| 584 const GrStyle& style) { | 603 const GrStyle& style) { |
| 585 ASSERT_SINGLE_OWNER | 604 ASSERT_SINGLE_OWNER |
| 586 RETURN_IF_ABANDONED | 605 RETURN_IF_ABANDONED |
| 587 SkDEBUGCODE(this->validate();) | 606 SkDEBUGCODE(this->validate();) |
| 588 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); | 607 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); |
| 589 | 608 |
| 590 if (rrect.isEmpty()) { | 609 if (rrect.isEmpty()) { |
| 591 return; | 610 return; |
| 592 } | 611 } |
| 593 | 612 |
| 594 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice | 613 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice |
| 595 const SkStrokeRec stroke = style.strokeRec(); | 614 const SkStrokeRec stroke = style.strokeRec(); |
| 596 AutoCheckFlush acf(fDrawingManager); | 615 AutoCheckFlush acf(fDrawingManager); |
| 597 | 616 |
| 598 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 617 bool useHWAA; |
| 618 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
| 599 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 619 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 600 | 620 |
| 601 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g
etColor(), | 621 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g
etColor(), |
| 602 viewMat
rix, | 622 viewMat
rix, |
| 603 rrect, | 623 rrect, |
| 604 stroke, | 624 stroke, |
| 605 shaderC
aps)); | 625 shaderC
aps)); |
| 606 if (batch) { | 626 if (batch) { |
| 607 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled
()); | 627 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 608 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; | 628 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; |
| 609 return; | 629 return; |
| 610 } | 630 } |
| 611 } | 631 } |
| 612 | 632 |
| 613 SkPath path; | 633 SkPath path; |
| 614 path.setIsVolatile(true); | 634 path.setIsVolatile(true); |
| 615 path.addRRect(rrect); | 635 path.addRRect(rrect); |
| 616 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 636 this->internalDrawPath(clip, paint, viewMatrix, path, style); |
| 617 } | 637 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); | 734 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); |
| 715 | 735 |
| 716 if (oval.isEmpty()) { | 736 if (oval.isEmpty()) { |
| 717 return; | 737 return; |
| 718 } | 738 } |
| 719 | 739 |
| 720 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice | 740 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice |
| 721 | 741 |
| 722 AutoCheckFlush acf(fDrawingManager); | 742 AutoCheckFlush acf(fDrawingManager); |
| 723 const SkStrokeRec& stroke = style.strokeRec(); | 743 const SkStrokeRec& stroke = style.strokeRec(); |
| 724 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 744 bool useHWAA; |
| 745 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA)) { |
| 725 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 746 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 726 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge
tColor(), | 747 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge
tColor(), |
| 727 viewMatr
ix, | 748 viewMatr
ix, |
| 728 oval, | 749 oval, |
| 729 stroke, | 750 stroke, |
| 730 shaderCa
ps)); | 751 shaderCa
ps)); |
| 731 if (batch) { | 752 if (batch) { |
| 732 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled
()); | 753 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 733 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; | 754 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch)
; |
| 734 return; | 755 return; |
| 735 } | 756 } |
| 736 } | 757 } |
| 737 | 758 |
| 738 SkPath path; | 759 SkPath path; |
| 739 path.setIsVolatile(true); | 760 path.setIsVolatile(true); |
| 740 path.addOval(oval); | 761 path.addOval(oval); |
| 741 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 762 this->internalDrawPath(clip, paint, viewMatrix, path, style); |
| 742 } | 763 } |
| 743 | 764 |
| 744 void GrDrawContext::drawImageNine(const GrClip& clip, | 765 void GrDrawContext::drawImageNine(const GrClip& clip, |
| 745 const GrPaint& paint, | 766 const GrPaint& paint, |
| 746 const SkMatrix& viewMatrix, | 767 const SkMatrix& viewMatrix, |
| 747 int imageWidth, | 768 int imageWidth, |
| 748 int imageHeight, | 769 int imageHeight, |
| 749 const SkIRect& center, | 770 const SkIRect& center, |
| 750 const SkRect& dst) { | 771 const SkRect& dst) { |
| 751 ASSERT_SINGLE_OWNER | 772 ASSERT_SINGLE_OWNER |
| 752 RETURN_IF_ABANDONED | 773 RETURN_IF_ABANDONED |
| 753 SkDEBUGCODE(this->validate();) | 774 SkDEBUGCODE(this->validate();) |
| 754 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); | 775 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); |
| 755 | 776 |
| 756 AutoCheckFlush acf(fDrawingManager); | 777 AutoCheckFlush acf(fDrawingManager); |
| 757 | 778 |
| 758 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v
iewMatrix, | 779 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v
iewMatrix, |
| 759 imageWidth, imageHe
ight, | 780 imageWidth, imageHe
ight, |
| 760 center, dst)); | 781 center, dst)); |
| 761 | 782 |
| 762 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | 783 GrPipelineBuilder pipelineBuilder(paint, this->mustUseHWAA(paint)); |
| 763 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 784 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 764 } | 785 } |
| 765 | 786 |
| 766 | 787 |
| 767 // Can 'path' be drawn as a pair of filled nested rectangles? | 788 // Can 'path' be drawn as a pair of filled nested rectangles? |
| 768 static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path
, SkRect rects[2]) { | 789 static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path
, SkRect rects[2]) { |
| 769 | 790 |
| 770 if (path.isInverseFillType()) { | 791 if (path.isInverseFillType()) { |
| 771 return false; | 792 return false; |
| 772 } | 793 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 803 allGoE1 = false; | 824 allGoE1 = false; |
| 804 } | 825 } |
| 805 if (!SkScalarNearlyEqual(margin, temp)) { | 826 if (!SkScalarNearlyEqual(margin, temp)) { |
| 806 allEq = false; | 827 allEq = false; |
| 807 } | 828 } |
| 808 } | 829 } |
| 809 | 830 |
| 810 return allEq || allGoE1; | 831 return allEq || allGoE1; |
| 811 } | 832 } |
| 812 | 833 |
| 813 void GrDrawContext::drawBatch(const GrClip& clip, | |
| 814 const GrPaint& paint, GrDrawBatch* batch) { | |
| 815 ASSERT_SINGLE_OWNER | |
| 816 RETURN_IF_ABANDONED | |
| 817 SkDEBUGCODE(this->validate();) | |
| 818 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | |
| 819 | |
| 820 AutoCheckFlush acf(fDrawingManager); | |
| 821 | |
| 822 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisampled()); | |
| 823 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | |
| 824 } | |
| 825 | |
| 826 void GrDrawContext::drawPath(const GrClip& clip, | 834 void GrDrawContext::drawPath(const GrClip& clip, |
| 827 const GrPaint& paint, | 835 const GrPaint& paint, |
| 828 const SkMatrix& viewMatrix, | 836 const SkMatrix& viewMatrix, |
| 829 const SkPath& path, | 837 const SkPath& path, |
| 830 const GrStyle& style) { | 838 const GrStyle& style) { |
| 831 ASSERT_SINGLE_OWNER | 839 ASSERT_SINGLE_OWNER |
| 832 RETURN_IF_ABANDONED | 840 RETURN_IF_ABANDONED |
| 833 SkDEBUGCODE(this->validate();) | 841 SkDEBUGCODE(this->validate();) |
| 834 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); | 842 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); |
| 835 | 843 |
| 836 if (path.isEmpty()) { | 844 if (path.isEmpty()) { |
| 837 if (path.isInverseFillType()) { | 845 if (path.isInverseFillType()) { |
| 838 this->drawPaint(clip, paint, viewMatrix); | 846 this->drawPaint(clip, paint, viewMatrix); |
| 839 } | 847 } |
| 840 return; | 848 return; |
| 841 } | 849 } |
| 842 | 850 |
| 843 AutoCheckFlush acf(fDrawingManager); | 851 AutoCheckFlush acf(fDrawingManager); |
| 844 | 852 |
| 845 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && !style.pathEffec
t()) { | 853 bool useHWAA; |
| 854 if (should_apply_coverage_aa(paint, fRenderTarget.get(), &useHWAA) && !style
.pathEffect()) { |
| 846 if (style.isSimpleFill() && !path.isConvex()) { | 855 if (style.isSimpleFill() && !path.isConvex()) { |
| 847 // Concave AA paths are expensive - try to avoid them for special ca
ses | 856 // Concave AA paths are expensive - try to avoid them for special ca
ses |
| 848 SkRect rects[2]; | 857 SkRect rects[2]; |
| 849 | 858 |
| 850 if (fills_as_nested_rects(viewMatrix, path, rects)) { | 859 if (fills_as_nested_rects(viewMatrix, path, rects)) { |
| 851 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( | 860 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( |
| 852 paint.getColor(), viewMatrix, rects)); | 861 paint.getColor(), viewMatrix, rects)); |
| 853 if (batch) { | 862 if (batch) { |
| 854 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMult
isampled()); | 863 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 855 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip
, batch); | 864 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip
, batch); |
| 856 } | 865 } |
| 857 return; | 866 return; |
| 858 } | 867 } |
| 859 } | 868 } |
| 860 SkRect ovalRect; | 869 SkRect ovalRect; |
| 861 bool isOval = path.isOval(&ovalRect); | 870 bool isOval = path.isOval(&ovalRect); |
| 862 | 871 |
| 863 if (isOval && !path.isInverseFillType()) { | 872 if (isOval && !path.isInverseFillType()) { |
| 864 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 873 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 865 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain
t.getColor(), | 874 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain
t.getColor(), |
| 866 view
Matrix, | 875 view
Matrix, |
| 867 oval
Rect, | 876 oval
Rect, |
| 868 styl
e.strokeRec(), | 877 styl
e.strokeRec(), |
| 869 shad
erCaps)); | 878 shad
erCaps)); |
| 870 if (batch) { | 879 if (batch) { |
| 871 GrPipelineBuilder pipelineBuilder(paint, this->isUnifiedMultisam
pled()); | 880 GrPipelineBuilder pipelineBuilder(paint, useHWAA); |
| 872 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba
tch); | 881 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, ba
tch); |
| 873 return; | 882 return; |
| 874 } | 883 } |
| 875 } | 884 } |
| 876 } | 885 } |
| 877 | 886 |
| 878 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 887 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 879 // Scratch textures can be recycled after they are returned to the texture | 888 // Scratch textures can be recycled after they are returned to the texture |
| 880 // cache. This presents a potential hazard for buffered drawing. However, | 889 // cache. This presents a potential hazard for buffered drawing. However, |
| 881 // the writePixels that uploads to the scratch will perform a flush so we're | 890 // the writePixels that uploads to the scratch will perform a flush so we're |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 | 1064 |
| 1056 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, | 1065 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, |
| 1057 GrDrawBatch* batch) { | 1066 GrDrawBatch* batch) { |
| 1058 ASSERT_SINGLE_OWNER | 1067 ASSERT_SINGLE_OWNER |
| 1059 RETURN_IF_ABANDONED | 1068 RETURN_IF_ABANDONED |
| 1060 SkDEBUGCODE(this->validate();) | 1069 SkDEBUGCODE(this->validate();) |
| 1061 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1070 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
| 1062 | 1071 |
| 1063 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1072 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 1064 } | 1073 } |
| OLD | NEW |