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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 void GrDrawContext::drawPaint(const GrClip& clip, | 238 void GrDrawContext::drawPaint(const GrClip& clip, |
239 const GrPaint& origPaint, | 239 const GrPaint& origPaint, |
240 const SkMatrix& viewMatrix) { | 240 const SkMatrix& viewMatrix) { |
241 ASSERT_SINGLE_OWNER | 241 ASSERT_SINGLE_OWNER |
242 RETURN_IF_ABANDONED | 242 RETURN_IF_ABANDONED |
243 SkDEBUGCODE(this->validate();) | 243 SkDEBUGCODE(this->validate();) |
244 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); | 244 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); |
245 | 245 |
246 // set rect to be big enough to fill the space, but not super-huge, so we | 246 // set rect to be big enough to fill the space, but not super-huge, so we |
247 // don't overflow fixed-point implementations | 247 // don't overflow fixed-point implementations |
248 SkRect r; | 248 |
249 r.setLTRB(0, 0, | 249 SkRect r = fRenderTarget->getBoundsRect(); |
250 SkIntToScalar(fRenderTarget->width()), | |
251 SkIntToScalar(fRenderTarget->height())); | |
252 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); | 250 SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
253 | 251 |
254 SkRRect rrect; | 252 SkRRect rrect; |
255 bool aaRRect; | 253 bool aaRRect; |
256 // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We
only do the | 254 // Check if we can replace a clipRRect()/drawPaint() with a drawRRect(). We
only do the |
257 // transformation for non-rect rrects. Rects caused a performance regression
on an Android | 255 // transformation for non-rect rrects. Rects caused a performance regression
on an Android |
258 // test that needs investigation. We also skip cases where there are fragmen
t processors | 256 // test that needs investigation. We also skip cases where there are fragmen
t processors |
259 // because they may depend on having correct local coords and this path draw
s in device space | 257 // because they may depend on having correct local coords and this path draw
s in device space |
260 // without a local matrix. | 258 // without a local matrix. |
261 if (!paint->numTotalFragmentProcessors() && | 259 if (!paint->numTotalFragmentProcessors() && |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } else { | 312 } else { |
315 if (useHWAA) { | 313 if (useHWAA) { |
316 *useHWAA = rt->isUnifiedMultisampled(); | 314 *useHWAA = rt->isUnifiedMultisampled(); |
317 } | 315 } |
318 return !rt->isUnifiedMultisampled(); | 316 return !rt->isUnifiedMultisampled(); |
319 } | 317 } |
320 } | 318 } |
321 | 319 |
322 // Attempts to crop a rect and optional local rect to the clip boundaries. | 320 // Attempts to crop a rect and optional local rect to the clip boundaries. |
323 // Returns false if the draw can be skipped entirely. | 321 // Returns false if the draw can be skipped entirely. |
324 static bool crop_filled_rect(const GrRenderTarget* rt, const GrClip& clip, | 322 static bool crop_filled_rect(int width, int height, const GrClip& clip, |
325 const SkMatrix& viewMatrix, SkRect* rect, | 323 const SkMatrix& viewMatrix, SkRect* rect, |
326 SkRect* localRect = nullptr) { | 324 SkRect* localRect = nullptr) { |
327 if (!viewMatrix.rectStaysRect()) { | 325 if (!viewMatrix.rectStaysRect()) { |
328 return true; | 326 return true; |
329 } | 327 } |
330 | 328 |
331 SkIRect clipDevBounds; | 329 SkIRect clipDevBounds; |
332 SkRect clipBounds; | 330 SkRect clipBounds; |
333 | 331 |
334 clip.getConservativeBounds(rt->width(), rt->height(), &clipDevBounds); | 332 clip.getConservativeBounds(width, height, &clipDevBounds); |
335 if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clip
DevBounds))) { | 333 if (!SkMatrixPriv::InverseMapRect(viewMatrix, &clipBounds, SkRect::Make(clip
DevBounds))) { |
336 return false; | 334 return false; |
337 } | 335 } |
338 | 336 |
339 if (localRect) { | 337 if (localRect) { |
340 if (!rect->intersects(clipBounds)) { | 338 if (!rect->intersects(clipBounds)) { |
341 return false; | 339 return false; |
342 } | 340 } |
343 const SkScalar dx = localRect->width() / rect->width(); | 341 const SkScalar dx = localRect->width() / rect->width(); |
344 const SkScalar dy = localRect->height() / rect->height(); | 342 const SkScalar dy = localRect->height() / rect->height(); |
(...skipping 18 matching lines...) Expand all Loading... |
363 | 361 |
364 return rect->intersect(clipBounds); | 362 return rect->intersect(clipBounds); |
365 } | 363 } |
366 | 364 |
367 bool GrDrawContext::drawFilledRect(const GrClip& clip, | 365 bool GrDrawContext::drawFilledRect(const GrClip& clip, |
368 const GrPaint& paint, | 366 const GrPaint& paint, |
369 const SkMatrix& viewMatrix, | 367 const SkMatrix& viewMatrix, |
370 const SkRect& rect, | 368 const SkRect& rect, |
371 const GrUserStencilSettings* ss) { | 369 const GrUserStencilSettings* ss) { |
372 SkRect croppedRect = rect; | 370 SkRect croppedRect = rect; |
373 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect))
{ | 371 if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &crop
pedRect)) { |
374 return true; | 372 return true; |
375 } | 373 } |
376 | 374 |
377 SkAutoTUnref<GrDrawBatch> batch; | 375 SkAutoTUnref<GrDrawBatch> batch; |
378 bool useHWAA; | 376 bool useHWAA; |
379 | 377 |
380 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ | 378 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ |
381 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); | 379 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
382 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), | 380 batch.reset(ir->recordRect(croppedRect, viewMatrix, paint.getColor(), |
383 paint.isAntiAlias(), fInstancedPipelineInfo, | 381 paint.isAntiAlias(), fInstancedPipelineInfo, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 SkASSERT(!style->pathEffect()); | 433 SkASSERT(!style->pathEffect()); |
436 | 434 |
437 AutoCheckFlush acf(fDrawingManager); | 435 AutoCheckFlush acf(fDrawingManager); |
438 | 436 |
439 const SkStrokeRec& stroke = style->strokeRec(); | 437 const SkStrokeRec& stroke = style->strokeRec(); |
440 if (stroke.getStyle() == SkStrokeRec::kFill_Style) { | 438 if (stroke.getStyle() == SkStrokeRec::kFill_Style) { |
441 | 439 |
442 if (!fContext->caps()->useDrawInsteadOfClear()) { | 440 if (!fContext->caps()->useDrawInsteadOfClear()) { |
443 // Check if this is a full RT draw and can be replaced with a clear.
We don't bother | 441 // Check if this is a full RT draw and can be replaced with a clear.
We don't bother |
444 // checking cases where the RT is fully inside a stroke. | 442 // checking cases where the RT is fully inside a stroke. |
445 SkRect rtRect; | 443 SkRect rtRect = fRenderTarget->getBoundsRect(); |
446 fRenderTarget->getBoundsRect(&rtRect); | |
447 // Does the clip contain the entire RT? | 444 // Does the clip contain the entire RT? |
448 if (clip.quickContains(rtRect)) { | 445 if (clip.quickContains(rtRect)) { |
449 SkMatrix invM; | 446 SkMatrix invM; |
450 if (!viewMatrix.invert(&invM)) { | 447 if (!viewMatrix.invert(&invM)) { |
451 return; | 448 return; |
452 } | 449 } |
453 // Does the rect bound the RT? | 450 // Does the rect bound the RT? |
454 SkPoint srcSpaceRTQuad[4]; | 451 SkPoint srcSpaceRTQuad[4]; |
455 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); | 452 invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
456 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && | 453 if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 const SkMatrix& viewMatrix, | 610 const SkMatrix& viewMatrix, |
614 const SkRect& rectToDraw, | 611 const SkRect& rectToDraw, |
615 const SkRect& localRect) { | 612 const SkRect& localRect) { |
616 ASSERT_SINGLE_OWNER | 613 ASSERT_SINGLE_OWNER |
617 RETURN_IF_ABANDONED | 614 RETURN_IF_ABANDONED |
618 SkDEBUGCODE(this->validate();) | 615 SkDEBUGCODE(this->validate();) |
619 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); | 616 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectToRect"); |
620 | 617 |
621 SkRect croppedRect = rectToDraw; | 618 SkRect croppedRect = rectToDraw; |
622 SkRect croppedLocalRect = localRect; | 619 SkRect croppedLocalRect = localRect; |
623 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect, &
croppedLocalRect)) { | 620 if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, |
| 621 &croppedRect, &croppedLocalRect)) { |
624 return; | 622 return; |
625 } | 623 } |
626 | 624 |
627 AutoCheckFlush acf(fDrawingManager); | 625 AutoCheckFlush acf(fDrawingManager); |
628 bool useHWAA; | 626 bool useHWAA; |
629 | 627 |
630 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ | 628 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ |
631 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); | 629 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
632 SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix,
paint.getColor(), | 630 SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix,
paint.getColor(), |
633 croppedLocalRect, paint.i
sAntiAlias(), | 631 croppedLocalRect, paint.i
sAntiAlias(), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 const GrPaint& paint, | 670 const GrPaint& paint, |
673 const SkMatrix& viewMatrix, | 671 const SkMatrix& viewMatrix, |
674 const SkRect& rectToDraw, | 672 const SkRect& rectToDraw, |
675 const SkMatrix& localMatrix) { | 673 const SkMatrix& localMatrix) { |
676 ASSERT_SINGLE_OWNER | 674 ASSERT_SINGLE_OWNER |
677 RETURN_IF_ABANDONED | 675 RETURN_IF_ABANDONED |
678 SkDEBUGCODE(this->validate();) | 676 SkDEBUGCODE(this->validate();) |
679 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); | 677 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::fillRectWithLocalMatr
ix"); |
680 | 678 |
681 SkRect croppedRect = rectToDraw; | 679 SkRect croppedRect = rectToDraw; |
682 if (!crop_filled_rect(fRenderTarget.get(), clip, viewMatrix, &croppedRect))
{ | 680 if (!crop_filled_rect(this->width(), this->height(), clip, viewMatrix, &crop
pedRect)) { |
683 return; | 681 return; |
684 } | 682 } |
685 | 683 |
686 AutoCheckFlush acf(fDrawingManager); | 684 AutoCheckFlush acf(fDrawingManager); |
687 bool useHWAA; | 685 bool useHWAA; |
688 | 686 |
689 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ | 687 if (GrCaps::InstancedSupport::kNone != fContext->caps()->instancedSupport())
{ |
690 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); | 688 InstancedRendering* ir = this->getDrawTarget()->instancedRendering(); |
691 SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix,
paint.getColor(), | 689 SkAutoTUnref<GrDrawBatch> batch(ir->recordRect(croppedRect, viewMatrix,
paint.getColor(), |
692 localMatrix, paint.isAnti
Alias(), | 690 localMatrix, paint.isAnti
Alias(), |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 fDrawContext->height())); | 1248 fDrawContext->height())); |
1251 return true; | 1249 return true; |
1252 } | 1250 } |
1253 | 1251 |
1254 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 1252 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
1255 | 1253 |
1256 // An Assumption here is that path renderer would use some form of tweaking | 1254 // An Assumption here is that path renderer would use some form of tweaking |
1257 // the src color (either the input alpha or in the frag shader) to implement | 1255 // the src color (either the input alpha or in the frag shader) to implement |
1258 // aa. If we have some future driver-mojo path AA that can do the right | 1256 // aa. If we have some future driver-mojo path AA that can do the right |
1259 // thing WRT to the blend then we'll need some query on the PR. | 1257 // thing WRT to the blend then we'll need some query on the PR. |
1260 bool useCoverageAA = doAA && !fDrawContext->fRenderTarget->isUnifiedMultisam
pled(); | 1258 bool useCoverageAA = doAA && !fDrawContext->isUnifiedMultisampled(); |
1261 bool hasUserStencilSettings = !ss->isUnused(); | 1259 bool hasUserStencilSettings = !ss->isUnused(); |
1262 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti
sampled(); | 1260 bool isStencilBufferMSAA = fDrawContext->isStencilBufferMultisampled(); |
1263 | 1261 |
1264 const GrPathRendererChain::DrawType type = | 1262 const GrPathRendererChain::DrawType type = |
1265 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType | 1263 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
1266 : GrPathRendererChain::kColor_DrawType; | 1264 : GrPathRendererChain::kColor_DrawType; |
1267 | 1265 |
1268 GrShape shape(path, GrStyle::SimpleFill()); | 1266 GrShape shape(path, GrStyle::SimpleFill()); |
1269 GrPathRenderer::CanDrawPathArgs canDrawArgs; | 1267 GrPathRenderer::CanDrawPathArgs canDrawArgs; |
1270 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps(
)->shaderCaps(); | 1268 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps(
)->shaderCaps(); |
1271 canDrawArgs.fViewMatrix = &viewMatrix; | 1269 canDrawArgs.fViewMatrix = &viewMatrix; |
1272 canDrawArgs.fShape = &shape; | 1270 canDrawArgs.fShape = &shape; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 const GrPaint& paint, | 1311 const GrPaint& paint, |
1314 const SkMatrix& viewMatrix, | 1312 const SkMatrix& viewMatrix, |
1315 const SkPath& path, | 1313 const SkPath& path, |
1316 const GrStyle& style) { | 1314 const GrStyle& style) { |
1317 ASSERT_SINGLE_OWNER | 1315 ASSERT_SINGLE_OWNER |
1318 RETURN_IF_ABANDONED | 1316 RETURN_IF_ABANDONED |
1319 SkASSERT(!path.isEmpty()); | 1317 SkASSERT(!path.isEmpty()); |
1320 | 1318 |
1321 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); | 1319 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); |
1322 constexpr bool kHasUserStencilSettings = false; | 1320 constexpr bool kHasUserStencilSettings = false; |
1323 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); | 1321 bool isStencilBufferMSAA = this->isStencilBufferMultisampled(); |
1324 | 1322 |
1325 const GrPathRendererChain::DrawType type = | 1323 const GrPathRendererChain::DrawType type = |
1326 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType | 1324 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
1327 : GrPathRendererChain::kColor_DrawType; | 1325 : GrPathRendererChain::kColor_DrawType; |
1328 | 1326 |
1329 GrShape shape(path, style); | 1327 GrShape shape(path, style); |
1330 if (shape.isEmpty()) { | 1328 if (shape.isEmpty()) { |
1331 return; | 1329 return; |
1332 } | 1330 } |
1333 GrPathRenderer::CanDrawPathArgs canDrawArgs; | 1331 GrPathRenderer::CanDrawPathArgs canDrawArgs; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1381 |
1384 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, | 1382 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, |
1385 GrDrawBatch* batch) { | 1383 GrDrawBatch* batch) { |
1386 ASSERT_SINGLE_OWNER | 1384 ASSERT_SINGLE_OWNER |
1387 RETURN_IF_ABANDONED | 1385 RETURN_IF_ABANDONED |
1388 SkDEBUGCODE(this->validate();) | 1386 SkDEBUGCODE(this->validate();) |
1389 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1387 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
1390 | 1388 |
1391 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1389 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
1392 } | 1390 } |
OLD | NEW |