| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "GrDrawTarget.h" | 8 #include "GrDrawTarget.h" |
| 9 | 9 |
| 10 #include "GrAuditTrail.h" | 10 #include "GrAuditTrail.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 | 264 |
| 265 #ifdef ENABLE_MDB | 265 #ifdef ENABLE_MDB |
| 266 SkASSERT(fRenderTarget); | 266 SkASSERT(fRenderTarget); |
| 267 batch->pipeline()->addDependenciesTo(fRenderTarget); | 267 batch->pipeline()->addDependenciesTo(fRenderTarget); |
| 268 #endif | 268 #endif |
| 269 | 269 |
| 270 this->recordBatch(batch); | 270 this->recordBatch(batch); |
| 271 } | 271 } |
| 272 | 272 |
| 273 inline static const GrUserStencilSettings& get_path_stencil_settings_for_fill( | |
| 274 GrPathRendering::FillType fill) { | |
| 275 static constexpr GrUserStencilSettings kWindingStencilSettings( | |
| 276 GrUserStencilSettings::StaticInit< | |
| 277 0xffff, | |
| 278 GrUserStencilTest::kAlwaysIfInClip, | |
| 279 0xffff, | |
| 280 GrUserStencilOp::kIncMaybeClamp, // TODO: Use wrap ops for NVPR. | |
| 281 GrUserStencilOp::kIncMaybeClamp, | |
| 282 0xffff>() | |
| 283 ); | |
| 284 | |
| 285 static constexpr GrUserStencilSettings kEvenOddStencilSettings( | |
| 286 GrUserStencilSettings::StaticInit< | |
| 287 0xffff, | |
| 288 GrUserStencilTest::kAlwaysIfInClip, | |
| 289 0xffff, | |
| 290 GrUserStencilOp::kInvert, | |
| 291 GrUserStencilOp::kInvert, | |
| 292 0xffff>() | |
| 293 ); | |
| 294 | |
| 295 switch (fill) { | |
| 296 default: | |
| 297 SkFAIL("Unexpected path fill."); | |
| 298 case GrPathRendering::kWinding_FillType: | |
| 299 return kWindingStencilSettings; | |
| 300 case GrPathRendering::kEvenOdd_FillType: | |
| 301 return kEvenOddStencilSettings; | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, | 273 void GrDrawTarget::stencilPath(const GrPipelineBuilder& pipelineBuilder, |
| 306 const SkMatrix& viewMatrix, | 274 const SkMatrix& viewMatrix, |
| 307 const GrPath* path, | 275 const GrPath* path, |
| 308 GrPathRendering::FillType fill) { | 276 GrPathRendering::FillType fill) { |
| 309 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 277 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 310 SkASSERT(path); | 278 SkASSERT(path); |
| 311 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); | 279 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
| 312 | 280 |
| 313 // Setup clip | 281 // Setup clip |
| 314 GrAppliedClip clip; | 282 GrAppliedClip clip; |
| 315 if (!fClipMaskManager->setupClipping(pipelineBuilder, nullptr, &clip)) { | 283 if (!fClipMaskManager->setupClipping(pipelineBuilder, nullptr, &clip)) { |
| 316 return; | 284 return; |
| 317 } | 285 } |
| 318 | 286 |
| 319 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 287 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 320 if (clip.clipCoverageFragmentProcessor()) { | 288 if (clip.clipCoverageFragmentProcessor()) { |
| 321 arfps.set(&pipelineBuilder); | 289 arfps.set(&pipelineBuilder); |
| 322 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | 290 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; |
| 323 } | 291 } |
| 324 | 292 |
| 325 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 293 const GrRenderTargetPriv& rtPriv = pipelineBuilder.getRenderTarget()->render
TargetPriv(); |
| 326 GrStencilAttachment* stencilAttachment = rt->renderTargetPriv().getStencilAt
tachment(); | |
| 327 SkASSERT(stencilAttachment) | |
| 328 | 294 |
| 329 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, | 295 GrBatch* batch = GrStencilPathBatch::Create(viewMatrix, |
| 330 pipelineBuilder.isHWAntialias(), | 296 pipelineBuilder.isHWAntialias(), |
| 331 get_path_stencil_settings_for_fi
ll(fill), | 297 fill, |
| 332 clip.hasStencilClip(), | 298 clip.hasStencilClip(), |
| 333 stencilAttachment->bits(), | 299 rtPriv.numStencilBits(), |
| 334 clip.scissorState(), | 300 clip.scissorState(), |
| 335 pipelineBuilder.getRenderTarget(
), | 301 pipelineBuilder.getRenderTarget(
), |
| 336 path); | 302 path); |
| 337 this->recordBatch(batch); | 303 this->recordBatch(batch); |
| 338 batch->unref(); | 304 batch->unref(); |
| 339 } | 305 } |
| 340 | 306 |
| 341 void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, | |
| 342 GrDrawPathBatchBase* batch) { | |
| 343 // This looks like drawBatch() but there is an added wrinkle that stencil se
ttings get inserted | |
| 344 // after setting up clipping but before onDrawBatch(). TODO: Figure out a be
tter model for | |
| 345 // handling stencil settings WRT interactions between pipeline(builder), cli
pmaskmanager, and | |
| 346 // batches. | |
| 347 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); | |
| 348 | |
| 349 GrAppliedClip clip; | |
| 350 if (!fClipMaskManager->setupClipping(pipelineBuilder, &batch->bounds(), &cli
p)) { | |
| 351 return; | |
| 352 } | |
| 353 | |
| 354 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | |
| 355 if (clip.clipCoverageFragmentProcessor()) { | |
| 356 arfps.set(&pipelineBuilder); | |
| 357 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | |
| 358 } | |
| 359 | |
| 360 // Ensure the render target has a stencil buffer and get the stencil setting
s. | |
| 361 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | |
| 362 GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt); | |
| 363 // TODO: Move this step into GrDrawPathPath::onPrepare(). | |
| 364 batch->setStencilSettings(get_path_stencil_settings_for_fill(batch->fillType
()), | |
| 365 clip.hasStencilClip(), | |
| 366 sb->bits()); | |
| 367 | |
| 368 GrPipeline::CreateArgs args; | |
| 369 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState()
, | |
| 370 clip.hasStencilClip(), batch)) { | |
| 371 return; | |
| 372 } | |
| 373 | |
| 374 this->recordBatch(batch); | |
| 375 } | |
| 376 | |
| 377 void GrDrawTarget::clear(const SkIRect* rect, | 307 void GrDrawTarget::clear(const SkIRect* rect, |
| 378 GrColor color, | 308 GrColor color, |
| 379 bool canIgnoreRect, | 309 bool canIgnoreRect, |
| 380 GrRenderTarget* renderTarget) { | 310 GrRenderTarget* renderTarget) { |
| 381 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height
()); | 311 SkIRect rtRect = SkIRect::MakeWH(renderTarget->width(), renderTarget->height
()); |
| 382 SkIRect clippedRect; | 312 SkIRect clippedRect; |
| 383 if (!rect || | 313 if (!rect || |
| 384 (canIgnoreRect && this->caps()->fullClearIsFree()) || | 314 (canIgnoreRect && this->caps()->fullClearIsFree()) || |
| 385 rect->contains(rtRect)) { | 315 rect->contains(rtRect)) { |
| 386 rect = &rtRect; | 316 rect = &rtRect; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 481 |
| 552 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, | 482 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, |
| 553 const GrScissorState* scissor, | 483 const GrScissorState* scissor, |
| 554 bool hasStencilClip, | 484 bool hasStencilClip, |
| 555 GrDrawBatch* batch) { | 485 GrDrawBatch* batch) { |
| 556 GrPipeline::CreateArgs args; | 486 GrPipeline::CreateArgs args; |
| 557 args.fPipelineBuilder = pipelineBuilder; | 487 args.fPipelineBuilder = pipelineBuilder; |
| 558 args.fCaps = this->caps(); | 488 args.fCaps = this->caps(); |
| 559 args.fScissor = scissor; | 489 args.fScissor = scissor; |
| 560 if (pipelineBuilder->hasUserStencilSettings() || hasStencilClip) { | 490 if (pipelineBuilder->hasUserStencilSettings() || hasStencilClip) { |
| 561 GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); | 491 fResourceProvider->attachStencilAttachment(pipelineBuilder->getRenderTar
get()); |
| 562 GrStencilAttachment* sb = fResourceProvider->attachStencilAttachment(rt)
; | |
| 563 args.fNumStencilBits = sb->bits(); | |
| 564 } else { | |
| 565 args.fNumStencilBits = 0; | |
| 566 } | 492 } |
| 567 args.fHasStencilClip = hasStencilClip; | 493 args.fHasStencilClip = hasStencilClip; |
| 568 batch->getPipelineOptimizations(&args.fOpts); | 494 batch->getPipelineOptimizations(&args.fOpts); |
| 569 GrScissorState finalScissor; | 495 GrScissorState finalScissor; |
| 570 if (args.fOpts.fOverrides.fUsePLSDstRead) { | 496 if (args.fOpts.fOverrides.fUsePLSDstRead) { |
| 571 GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); | 497 GrRenderTarget* rt = pipelineBuilder->getRenderTarget(); |
| 572 GrGLIRect viewport; | 498 GrGLIRect viewport; |
| 573 viewport.fLeft = 0; | 499 viewport.fLeft = 0; |
| 574 viewport.fBottom = 0; | 500 viewport.fBottom = 0; |
| 575 viewport.fWidth = rt->width(); | 501 viewport.fWidth = rt->width(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 606 } | 532 } |
| 607 | 533 |
| 608 return true; | 534 return true; |
| 609 } | 535 } |
| 610 | 536 |
| 611 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 537 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
| 612 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 538 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
| 613 this->recordBatch(batch); | 539 this->recordBatch(batch); |
| 614 batch->unref(); | 540 batch->unref(); |
| 615 } | 541 } |
| OLD | NEW |