| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 void GrDrawContext::clear(const SkIRect* rect, | 189 void GrDrawContext::clear(const SkIRect* rect, |
| 190 const GrColor color, | 190 const GrColor color, |
| 191 bool canIgnoreRect) { | 191 bool canIgnoreRect) { |
| 192 ASSERT_SINGLE_OWNER | 192 ASSERT_SINGLE_OWNER |
| 193 RETURN_IF_ABANDONED | 193 RETURN_IF_ABANDONED |
| 194 SkDEBUGCODE(this->validate();) | 194 SkDEBUGCODE(this->validate();) |
| 195 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); | 195 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear"); |
| 196 | 196 |
| 197 AutoCheckFlush acf(fDrawingManager); | 197 AutoCheckFlush acf(fDrawingManager); |
| 198 this->internalClear(rect ? GrFixedClip(*rect) : GrFixedClip::Disabled(), col
or, canIgnoreRect); |
| 199 } |
| 198 | 200 |
| 199 const SkIRect rtRect = SkIRect::MakeWH(this->width(), this->height()); | 201 void GrDrawContextPriv::clear(const GrFixedClip& clip, |
| 200 SkIRect clippedRect; | 202 const GrColor color, |
| 201 bool isFull = false; | 203 bool canIgnoreClip) { |
| 202 if (!rect || | 204 ASSERT_SINGLE_OWNER_PRIV |
| 203 (canIgnoreRect && fContext->caps()->fullClearIsFree()) || | 205 RETURN_IF_ABANDONED_PRIV |
| 204 rect->contains(rtRect)) { | 206 SkDEBUGCODE(fDrawContext->validate();) |
| 205 rect = &rtRect; | 207 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::cle
ar"); |
| 206 isFull = true; | 208 |
| 207 } else { | 209 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 208 clippedRect = *rect; | 210 fDrawContext->internalClear(clip, color, canIgnoreClip); |
| 209 if (!clippedRect.intersect(rtRect)) { | 211 } |
| 210 return; | 212 |
| 211 } | 213 void GrDrawContext::internalClear(const GrFixedClip& clip, |
| 212 rect = &clippedRect; | 214 const GrColor color, |
| 213 } | 215 bool canIgnoreClip) { |
| 216 bool isFull = !clip.scissorEnabled() || |
| 217 (canIgnoreClip && fContext->caps()->fullClearIsFree()) || |
| 218 clip.scissorRect().contains(SkIRect::MakeWH(this->width(), thi
s->height())); |
| 214 | 219 |
| 215 if (fContext->caps()->useDrawInsteadOfClear()) { | 220 if (fContext->caps()->useDrawInsteadOfClear()) { |
| 216 // This works around a driver bug with clear by drawing a rect instead. | 221 // This works around a driver bug with clear by drawing a rect instead. |
| 217 // The driver will ignore a clear if it is the only thing rendered to a | 222 // The driver will ignore a clear if it is the only thing rendered to a |
| 218 // target before the target is read. | 223 // target before the target is read. |
| 219 if (rect == &rtRect) { | 224 SkRect clearRect = SkRect::MakeIWH(this->width(), this->height()); |
| 225 if (isFull) { |
| 220 this->discard(); | 226 this->discard(); |
| 227 } else if (!clearRect.intersect(SkRect::Make(clip.scissorRect()))) { |
| 228 return; |
| 221 } | 229 } |
| 222 | 230 |
| 223 GrPaint paint; | 231 GrPaint paint; |
| 224 paint.setColor4f(GrColor4f::FromGrColor(color)); | 232 paint.setColor4f(GrColor4f::FromGrColor(color)); |
| 225 paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); | 233 paint.setXPFactory(GrPorterDuffXPFactory::Make(SkXfermode::kSrc_Mode)); |
| 226 | 234 |
| 227 this->drawRect(GrNoClip(), paint, SkMatrix::I(), SkRect::Make(*rect)); | 235 this->drawRect(clip, paint, SkMatrix::I(), clearRect); |
| 228 } else if (isFull) { | 236 } else if (isFull) { |
| 229 this->getDrawTarget()->fullClear(this->accessRenderTarget(), color); | 237 this->getDrawTarget()->fullClear(this->accessRenderTarget(), color); |
| 230 } else { | 238 } else { |
| 231 sk_sp<GrBatch> batch(GrClearBatch::Make(*rect, color, this->accessRender
Target())); | 239 sk_sp<GrBatch> batch(GrClearBatch::Make(clip, color, this->accessRenderT
arget())); |
| 240 if (!batch) { |
| 241 return; |
| 242 } |
| 232 this->getDrawTarget()->addBatch(std::move(batch)); | 243 this->getDrawTarget()->addBatch(std::move(batch)); |
| 233 } | 244 } |
| 234 } | 245 } |
| 235 | 246 |
| 236 | |
| 237 void GrDrawContext::drawPaint(const GrClip& clip, | 247 void GrDrawContext::drawPaint(const GrClip& clip, |
| 238 const GrPaint& origPaint, | 248 const GrPaint& origPaint, |
| 239 const SkMatrix& viewMatrix) { | 249 const SkMatrix& viewMatrix) { |
| 240 ASSERT_SINGLE_OWNER | 250 ASSERT_SINGLE_OWNER |
| 241 RETURN_IF_ABANDONED | 251 RETURN_IF_ABANDONED |
| 242 SkDEBUGCODE(this->validate();) | 252 SkDEBUGCODE(this->validate();) |
| 243 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); | 253 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPaint"); |
| 244 | 254 |
| 245 // set rect to be big enough to fill the space, but not super-huge, so we | 255 // set rect to be big enough to fill the space, but not super-huge, so we |
| 246 // don't overflow fixed-point implementations | 256 // don't overflow fixed-point implementations |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 return; | 531 return; |
| 522 } | 532 } |
| 523 } | 533 } |
| 524 | 534 |
| 525 SkPath path; | 535 SkPath path; |
| 526 path.setIsVolatile(true); | 536 path.setIsVolatile(true); |
| 527 path.addRect(rect); | 537 path.addRect(rect); |
| 528 this->internalDrawPath(clip, paint, viewMatrix, path, *style); | 538 this->internalDrawPath(clip, paint, viewMatrix, path, *style); |
| 529 } | 539 } |
| 530 | 540 |
| 531 void GrDrawContextPriv::clearStencilClip(const SkIRect& rect, bool insideClip) { | 541 void GrDrawContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideSte
ncilMask) { |
| 532 ASSERT_SINGLE_OWNER_PRIV | 542 ASSERT_SINGLE_OWNER_PRIV |
| 533 RETURN_IF_ABANDONED_PRIV | 543 RETURN_IF_ABANDONED_PRIV |
| 534 SkDEBUGCODE(fDrawContext->validate();) | 544 SkDEBUGCODE(fDrawContext->validate();) |
| 535 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::cle
arStencilClip"); | 545 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContextPriv::cle
arStencilClip"); |
| 536 | 546 |
| 537 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 547 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 538 fDrawContext->getDrawTarget()->clearStencilClip(rect, insideClip, | 548 fDrawContext->getDrawTarget()->clearStencilClip(clip, insideStencilMask, |
| 539 fDrawContext->accessRenderTa
rget()); | 549 fDrawContext->accessRenderTa
rget()); |
| 540 } | 550 } |
| 541 | 551 |
| 542 void GrDrawContextPriv::stencilPath(const GrClip& clip, | 552 void GrDrawContextPriv::stencilPath(const GrClip& clip, |
| 543 bool useHWAA, | 553 bool useHWAA, |
| 544 const SkMatrix& viewMatrix, | 554 const SkMatrix& viewMatrix, |
| 545 const GrPath* path) { | 555 const GrPath* path) { |
| 546 fDrawContext->getDrawTarget()->stencilPath(fDrawContext, clip, useHWAA, view
Matrix, path); | 556 fDrawContext->getDrawTarget()->stencilPath(fDrawContext, clip, useHWAA, view
Matrix, path); |
| 547 } | 557 } |
| 548 | 558 |
| 549 void GrDrawContextPriv::stencilRect(const GrFixedClip& clip, | 559 void GrDrawContextPriv::stencilRect(const GrClip& clip, |
| 550 const GrUserStencilSettings* ss, | 560 const GrUserStencilSettings* ss, |
| 551 bool useHWAA, | 561 bool useHWAA, |
| 552 const SkMatrix& viewMatrix, | 562 const SkMatrix& viewMatrix, |
| 553 const SkRect& rect) { | 563 const SkRect& rect) { |
| 554 ASSERT_SINGLE_OWNER_PRIV | 564 ASSERT_SINGLE_OWNER_PRIV |
| 555 RETURN_IF_ABANDONED_PRIV | 565 RETURN_IF_ABANDONED_PRIV |
| 556 SkDEBUGCODE(fDrawContext->validate();) | 566 SkDEBUGCODE(fDrawContext->validate();) |
| 557 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); | 567 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::stencil
Rect"); |
| 558 | 568 |
| 559 AutoCheckFlush acf(fDrawContext->fDrawingManager); | 569 AutoCheckFlush acf(fDrawContext->fDrawingManager); |
| 560 | 570 |
| 561 GrPaint paint; | 571 GrPaint paint; |
| 562 paint.setAntiAlias(useHWAA); | 572 paint.setAntiAlias(useHWAA); |
| 563 paint.setXPFactory(GrDisableColorXPFactory::Make()); | 573 paint.setXPFactory(GrDisableColorXPFactory::Make()); |
| 564 | 574 |
| 565 fDrawContext->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nu
llptr, ss, useHWAA); | 575 fDrawContext->drawNonAAFilledRect(clip, paint, viewMatrix, rect, nullptr, nu
llptr, ss, useHWAA); |
| 566 } | 576 } |
| 567 | 577 |
| 568 bool GrDrawContextPriv::drawAndStencilRect(const GrFixedClip& clip, | 578 bool GrDrawContextPriv::drawAndStencilRect(const GrClip& clip, |
| 569 const GrUserStencilSettings* ss, | 579 const GrUserStencilSettings* ss, |
| 570 SkRegion::Op op, | 580 SkRegion::Op op, |
| 571 bool invert, | 581 bool invert, |
| 572 bool doAA, | 582 bool doAA, |
| 573 const SkMatrix& viewMatrix, | 583 const SkMatrix& viewMatrix, |
| 574 const SkRect& rect) { | 584 const SkRect& rect) { |
| 575 ASSERT_SINGLE_OWNER_PRIV | 585 ASSERT_SINGLE_OWNER_PRIV |
| 576 RETURN_FALSE_IF_ABANDONED_PRIV | 586 RETURN_FALSE_IF_ABANDONED_PRIV |
| 577 SkDEBUGCODE(fDrawContext->validate();) | 587 SkDEBUGCODE(fDrawContext->validate();) |
| 578 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); | 588 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawAnd
StencilRect"); |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } | 1197 } |
| 1188 | 1198 |
| 1189 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 1199 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 1190 // Scratch textures can be recycled after they are returned to the texture | 1200 // Scratch textures can be recycled after they are returned to the texture |
| 1191 // cache. This presents a potential hazard for buffered drawing. However, | 1201 // cache. This presents a potential hazard for buffered drawing. However, |
| 1192 // the writePixels that uploads to the scratch will perform a flush so we're | 1202 // the writePixels that uploads to the scratch will perform a flush so we're |
| 1193 // OK. | 1203 // OK. |
| 1194 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 1204 this->internalDrawPath(clip, paint, viewMatrix, path, style); |
| 1195 } | 1205 } |
| 1196 | 1206 |
| 1197 bool GrDrawContextPriv::drawAndStencilPath(const GrFixedClip& clip, | 1207 bool GrDrawContextPriv::drawAndStencilPath(const GrClip& clip, |
| 1198 const GrUserStencilSettings* ss, | 1208 const GrUserStencilSettings* ss, |
| 1199 SkRegion::Op op, | 1209 SkRegion::Op op, |
| 1200 bool invert, | 1210 bool invert, |
| 1201 bool doAA, | 1211 bool doAA, |
| 1202 const SkMatrix& viewMatrix, | 1212 const SkMatrix& viewMatrix, |
| 1203 const SkPath& path) { | 1213 const SkPath& path) { |
| 1204 ASSERT_SINGLE_OWNER_PRIV | 1214 ASSERT_SINGLE_OWNER_PRIV |
| 1205 RETURN_FALSE_IF_ABANDONED_PRIV | 1215 RETURN_FALSE_IF_ABANDONED_PRIV |
| 1206 SkDEBUGCODE(fDrawContext->validate();) | 1216 SkDEBUGCODE(fDrawContext->validate();) |
| 1207 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPat
h"); | 1217 GR_AUDIT_TRAIL_AUTO_FRAME(fDrawContext->fAuditTrail, "GrDrawContext::drawPat
h"); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 | 1355 |
| 1346 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, | 1356 void GrDrawContext::drawBatch(const GrPipelineBuilder& pipelineBuilder, const Gr
Clip& clip, |
| 1347 GrDrawBatch* batch) { | 1357 GrDrawBatch* batch) { |
| 1348 ASSERT_SINGLE_OWNER | 1358 ASSERT_SINGLE_OWNER |
| 1349 RETURN_IF_ABANDONED | 1359 RETURN_IF_ABANDONED |
| 1350 SkDEBUGCODE(this->validate();) | 1360 SkDEBUGCODE(this->validate();) |
| 1351 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1361 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
| 1352 | 1362 |
| 1353 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); | 1363 this->getDrawTarget()->drawBatch(pipelineBuilder, this, clip, batch); |
| 1354 } | 1364 } |
| OLD | NEW |