| 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 |
| (...skipping 796 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 |