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() : |
| 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)) { |
338 viewMatrix, | 346 SkAutoTUnref<GrDrawBatch> batch(GrAAFillRectBatch::CreateWithLocalRect( |
339 rectToDraw, | 347 paint.getColor(), viewMatrix, rectToDraw, localRect)); |
340 localRect); | 348 if (batch) { |
| 349 this->drawBatch(&pipelineBuilder, batch); |
| 350 } |
| 351 } else { |
| 352 this->getDrawTarget()->drawNonAARect(pipelineBuilder, |
| 353 paint.getColor(), |
| 354 viewMatrix, |
| 355 rectToDraw, |
| 356 localRect); |
| 357 } |
341 } | 358 } |
342 | 359 |
343 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, | 360 void GrDrawContext::fillRectWithLocalMatrix(const GrClip& clip, |
344 const GrPaint& paint, | 361 const GrPaint& paint, |
345 const SkMatrix& viewMatrix, | 362 const SkMatrix& viewMatrix, |
346 const SkRect& rectToDraw, | 363 const SkRect& rectToDraw, |
347 const SkMatrix& localMatrix) { | 364 const SkMatrix& localMatrix) { |
348 RETURN_IF_ABANDONED | 365 RETURN_IF_ABANDONED |
349 SkDEBUGCODE(this->validate();) | 366 SkDEBUGCODE(this->validate();) |
350 | 367 |
351 AutoCheckFlush acf(fDrawingManager); | 368 AutoCheckFlush acf(fDrawingManager); |
352 | 369 |
353 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 370 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
354 this->getDrawTarget()->drawNonAARect(pipelineBuilder, | 371 if (should_apply_coverage_aa(paint, pipelineBuilder.getRenderTarget()) && |
355 paint.getColor(), | 372 view_matrix_ok_for_aa_fill_rect(viewMatrix)) { |
356 viewMatrix, | 373 SkAutoTUnref<GrDrawBatch> batch(GrAAFillRectBatch::Create( |
357 rectToDraw, | 374 paint.getColor(), viewMatrix, localMatrix, rectToDraw)); |
358 localMatrix); | 375 this->drawBatch(&pipelineBuilder, batch); |
| 376 } else { |
| 377 this->getDrawTarget()->drawNonAARect(pipelineBuilder, |
| 378 paint.getColor(), |
| 379 viewMatrix, |
| 380 rectToDraw, |
| 381 localMatrix); |
| 382 } |
359 } | 383 } |
360 | 384 |
361 void GrDrawContext::drawVertices(const GrClip& clip, | 385 void GrDrawContext::drawVertices(const GrClip& clip, |
362 const GrPaint& paint, | 386 const GrPaint& paint, |
363 const SkMatrix& viewMatrix, | 387 const SkMatrix& viewMatrix, |
364 GrPrimitiveType primitiveType, | 388 GrPrimitiveType primitiveType, |
365 int vertexCount, | 389 int vertexCount, |
366 const SkPoint positions[], | 390 const SkPoint positions[], |
367 const SkPoint texCoords[], | 391 const SkPoint texCoords[], |
368 const GrColor colors[], | 392 const GrColor colors[], |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 649 |
626 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 650 // 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 | 651 // Scratch textures can be recycled after they are returned to the texture |
628 // cache. This presents a potential hazard for buffered drawing. However, | 652 // 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 | 653 // the writePixels that uploads to the scratch will perform a flush so we're |
630 // OK. | 654 // OK. |
631 AutoCheckFlush acf(fDrawingManager); | 655 AutoCheckFlush acf(fDrawingManager); |
632 | 656 |
633 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); | 657 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip); |
634 if (!strokeInfo.isDashed()) { | 658 if (!strokeInfo.isDashed()) { |
635 bool useCoverageAA = paint.isAntiAlias() && | 659 bool useCoverageAA = should_apply_coverage_aa(paint, pipelineBuilder.get
RenderTarget()); |
636 !pipelineBuilder.getRenderTarget()->isUnifiedMultisampled(); | |
637 | 660 |
638 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { | 661 if (useCoverageAA && strokeInfo.getWidth() < 0 && !path.isConvex()) { |
639 // Concave AA paths are expensive - try to avoid them for special ca
ses | 662 // Concave AA paths are expensive - try to avoid them for special ca
ses |
640 SkRect rects[2]; | 663 SkRect rects[2]; |
641 | 664 |
642 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { | 665 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
643 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( | 666 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( |
644 color, viewMatrix, rects)); | 667 color, viewMatrix, rects)); |
645 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 668 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
646 return; | 669 return; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 args.fAntiAlias = useCoverageAA; | 788 args.fAntiAlias = useCoverageAA; |
766 pr->drawPath(args); | 789 pr->drawPath(args); |
767 } | 790 } |
768 | 791 |
769 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { | 792 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
770 RETURN_IF_ABANDONED | 793 RETURN_IF_ABANDONED |
771 SkDEBUGCODE(this->validate();) | 794 SkDEBUGCODE(this->validate();) |
772 | 795 |
773 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 796 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
774 } | 797 } |
OLD | NEW |