Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
| 10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 r, | 218 r, |
| 219 localMatrix); | 219 localMatrix); |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { | 223 static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po int) { |
| 224 return point.fX >= rect.fLeft && point.fX <= rect.fRight && | 224 return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 225 point.fY >= rect.fTop && point.fY <= rect.fBottom; | 225 point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 226 } | 226 } |
| 227 | 227 |
| 228 static bool view_matrix_ok_for_aa_fill_rect(const SkMatrix& viewMatrix) { | |
| 229 return viewMatrix.preservesRightAngles(); | |
| 230 } | |
| 231 | |
| 232 static bool should_apply_coverage_aa(const GrPaint& paint, GrRenderTarget* rt) { | |
| 233 return paint.isAntiAlias() && !rt->isUnifiedMultisampled(); | |
| 234 } | |
| 235 | |
| 228 void GrDrawContext::drawRect(const GrClip& clip, | 236 void GrDrawContext::drawRect(const GrClip& clip, |
| 229 const GrPaint& paint, | 237 const GrPaint& paint, |
| 230 const SkMatrix& viewMatrix, | 238 const SkMatrix& viewMatrix, |
| 231 const SkRect& rect, | 239 const SkRect& rect, |
| 232 const GrStrokeInfo* strokeInfo) { | 240 const GrStrokeInfo* strokeInfo) { |
| 233 RETURN_IF_ABANDONED | 241 RETURN_IF_ABANDONED |
| 234 SkDEBUGCODE(this->validate();) | 242 SkDEBUGCODE(this->validate();) |
| 235 | 243 |
| 236 if (strokeInfo && strokeInfo->isDashed()) { | 244 if (strokeInfo && strokeInfo->isDashed()) { |
| 237 SkPath path; | 245 SkPath path; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 GrColor clearColor; | 283 GrColor clearColor; |
| 276 if (paint.isConstantBlendedColor(&clearColor)) { | 284 if (paint.isConstantBlendedColor(&clearColor)) { |
| 277 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen derTarget); | 285 this->getDrawTarget()->clear(nullptr, clearColor, true, fRen derTarget); |
| 278 return; | 286 return; |
| 279 } | 287 } |
| 280 } | 288 } |
| 281 } | 289 } |
| 282 } | 290 } |
| 283 | 291 |
| 284 GrColor color = paint.getColor(); | 292 GrColor color = paint.getColor(); |
| 285 bool needAA = paint.isAntiAlias() && | 293 bool needAA = should_apply_coverage_aa(paint, pipelineBuilder.getRenderTarge t()); |
| 286 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | |
| 287 | 294 |
| 288 // The fill path can handle rotation but not skew | 295 // The fill path can handle rotation but not skew |
| 289 // The stroke path needs the rect to remain axis aligned (no rotation or ske w) | 296 // The stroke path needs the rect to remain axis aligned (no rotation or ske w) |
| 290 // None of our AA draw rect calls can handle perspective yet | 297 // None of our AA draw rect calls can handle perspective yet |
| 291 bool canApplyAA = width >=0 ? viewMatrix.rectStaysRect() : viewMatrix.preser vesRightAngles(); | 298 bool canApplyAA = width >=0 ? viewMatrix.rectStaysRect() : |
|
joshualitt
2015/11/05 19:53:12
view_matrix_ok_for_aa_stroke_rect? Though I guess
bsalomon
2015/11/05 20:10:37
I only pulled the other one out in order to share
| |
| 299 view_matrix_ok_for_aa_fill_rect(viewMatrix); | |
| 292 | 300 |
| 293 if (needAA && canApplyAA) { | 301 if (needAA && canApplyAA) { |
| 294 SkASSERT(!viewMatrix.hasPerspective()); | 302 SkASSERT(!viewMatrix.hasPerspective()); |
| 295 SkAutoTUnref<GrDrawBatch> batch; | 303 SkAutoTUnref<GrDrawBatch> batch; |
| 296 if (width >= 0) { | 304 if (width >= 0) { |
| 297 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, re ct, *strokeInfo)); | 305 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, re ct, *strokeInfo)); |
| 298 } else { | 306 } else { |
| 299 SkRect devBoundRect; | 307 SkRect devBoundRect; |
| 300 viewMatrix.mapRect(&devBoundRect, rect); | 308 viewMatrix.mapRect(&devBoundRect, rect); |
| 301 batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect , devBoundRect)); | 309 batch.reset(GrRectBatchFactory::CreateAAFill(color, viewMatrix, rect , devBoundRect)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 326 const GrPaint& paint, | 334 const GrPaint& paint, |
| 327 const SkMatrix& viewMatrix, | 335 const SkMatrix& viewMatrix, |
| 328 const SkRect& rectToDraw, | 336 const SkRect& rectToDraw, |
| 329 const SkRect& localRect) { | 337 const SkRect& localRect) { |
| 330 RETURN_IF_ABANDONED | 338 RETURN_IF_ABANDONED |
| 331 SkDEBUGCODE(this->validate();) | 339 SkDEBUGCODE(this->validate();) |
| 332 | 340 |
| 333 AutoCheckFlush acf(fDrawingManager); | 341 AutoCheckFlush acf(fDrawingManager); |
| 334 | 342 |
| 335 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 343 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 336 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 344 if (should_apply_coverage_aa(paint, fRenderTarget) && |
| 337 paint.getColor(), | 345 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
|
robertphillips
2015/11/05 20:13:24
SkAutoTUnref<GrDrawBatch> batch( ...
?
bsalomon
2015/11/06 15:24:25
I relent
| |
| 338 viewMatrix, | 346 GrDrawBatch* batch = GrAAFillRectBatch::CreateWithLocalRect( |
|
joshualitt
2015/11/05 19:53:12
Is there a reason not to use SkAutoTUnref here?
bsalomon
2015/11/05 20:10:37
I already had to branch on nullptr
| |
| 339 rectToDraw, | 347 paint.getColor(), viewMatrix, rectToDraw, localRect); |
| 340 localRect); | 348 if (batch) { |
| 349 this->drawBatch(&pipelineBuilder, batch); | |
| 350 batch->unref(); | |
| 351 } | |
| 352 } else { | |
| 353 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | |
| 354 paint.getColor(), | |
|
joshualitt
2015/11/05 19:53:12
extra spaces
bsalomon
2015/11/05 20:10:37
will fix
bsalomon
2015/11/06 15:24:25
Done.
| |
| 355 viewMatrix, | |
| 356 rectToDraw, | |
| 357 localRect); | |
| 358 } | |
| 341 } | 359 } |
| 342 | 360 |
| 343 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, | 361 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
| 344 const GrPaint& paint, | 362 const GrPaint& paint, |
| 345 const SkMatrix& viewMatrix, | 363 const SkMatrix& viewMatrix, |
| 346 const SkRect& rectToDraw, | 364 const SkRect& rectToDraw, |
| 347 const SkMatrix& localMatrix) { | 365 const SkMatrix& localMatrix) { |
| 348 RETURN_IF_ABANDONED | 366 RETURN_IF_ABANDONED |
| 349 SkDEBUGCODE(this->validate();) | 367 SkDEBUGCODE(this->validate();) |
| 350 | 368 |
| 351 AutoCheckFlush acf(fDrawingManager); | 369 AutoCheckFlush acf(fDrawingManager); |
| 352 | 370 |
| 353 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 371 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 354 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 372 if (should_apply_coverage_aa(paint, pipelineBuilder.getRenderTarget()) && |
| 355 paint.getColor(), | 373 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
| 356 viewMatrix, | 374 SkAutoTUnref<GrDrawBatch> batch(GrAAFillRectBatch::Create( |
| 357 rectToDraw, | 375 paint.getColor(), viewMatrix, localMatrix, rectToDraw)); |
| 358 localMatrix); | 376 this->drawBatch(&pipelineBuilder, batch); |
|
joshualitt
2015/11/05 19:53:12
Its outside the scope of this CL but it'd be nice
bsalomon
2015/11/05 20:10:37
You mean not have GrDrawContext create GrBatches a
| |
| 377 } else { | |
| 378 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | |
| 379 paint.getColor(), | |
| 380 viewMatrix, | |
| 381 rectToDraw, | |
| 382 localMatrix); | |
| 383 } | |
| 359 } | 384 } |
| 360 | 385 |
| 361 void GrDrawContext::drawVertices(const GrClip& clip, | 386 void GrDrawContext::drawVertices(const GrClip& clip, |
| 362 const GrPaint& paint, | 387 const GrPaint& paint, |
| 363 const SkMatrix& viewMatrix, | 388 const SkMatrix& viewMatrix, |
| 364 GrPrimitiveType primitiveType, | 389 GrPrimitiveType primitiveType, |
| 365 int vertexCount, | 390 int vertexCount, |
| 366 const SkPoint positions[], | 391 const SkPoint positions[], |
| 367 const SkPoint texCoords[], | 392 const SkPoint texCoords[], |
| 368 const GrColor colors[], | 393 const GrColor colors[], |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 | 650 |
| 626 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. | 651 // Note that internalDrawPath may sw-rasterize the path into a scratch textu re. |
| 627 // Scratch textures can be recycled after they are returned to the texture | 652 // Scratch textures can be recycled after they are returned to the texture |
| 628 // cache. This presents a potential hazard for buffered drawing. However, | 653 // cache. This presents a potential hazard for buffered drawing. However, |
| 629 // the writePixels that uploads to the scratch will perform a flush so we're | 654 // the writePixels that uploads to the scratch will perform a flush so we're |
| 630 // OK. | 655 // OK. |
| 631 AutoCheckFlush acf(fDrawingManager); | 656 AutoCheckFlush acf(fDrawingManager); |
| 632 | 657 |
| 633 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 658 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
| 634 if (!strokeInfo.isDashed()) { | 659 if (!strokeInfo.isDashed()) { |
| 635 bool useCoverageAA = paint.isAntiAlias() && | 660 bool useCoverageAA = should_apply_coverage_aa(paint, pipelineBuilder.get RenderTarget()); |
| 636 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | |
| 637 | 661 |
| 638 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 662 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 639 // Concave AA paths are expensive - try to avoid them for special ca ses | 663 // Concave AA paths are expensive - try to avoid them for special ca ses |
| 640 SkRect rects[2]; | 664 SkRect rects[2]; |
| 641 | 665 |
| 642 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { | 666 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
| 643 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects( | 667 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill NestedRects( |
| 644 color, viewMatrix, rects)); | 668 color, viewMatrix, rects)); |
| 645 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 669 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 646 return; | 670 return; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 args.fAntiAlias = useCoverageAA; | 789 args.fAntiAlias = useCoverageAA; |
| 766 pr->drawPath(args); | 790 pr->drawPath(args); |
| 767 } | 791 } |
| 768 | 792 |
| 769 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { | 793 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b atch) { |
| 770 RETURN_IF_ABANDONED | 794 RETURN_IF_ABANDONED |
| 771 SkDEBUGCODE(this->validate();) | 795 SkDEBUGCODE(this->validate();) |
| 772 | 796 |
| 773 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 797 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
| 774 } | 798 } |
| OLD | NEW |