| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "GrClipMaskManager.h" | 9 #include "GrClipMaskManager.h" |
| 10 #include "GrAAConvexPathRenderer.h" | 10 #include "GrAAConvexPathRenderer.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 GrCrash("Unexpected element type"); | 340 GrCrash("Unexpected element type"); |
| 341 return false; | 341 return false; |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 void GrClipMaskManager::mergeMask(GrTexture* dstMask, | 345 void GrClipMaskManager::mergeMask(GrTexture* dstMask, |
| 346 GrTexture* srcMask, | 346 GrTexture* srcMask, |
| 347 SkRegion::Op op, | 347 SkRegion::Op op, |
| 348 const GrIRect& dstBound, | 348 const GrIRect& dstBound, |
| 349 const GrIRect& srcBound) { | 349 const GrIRect& srcBound) { |
| 350 GrDrawState::AutoViewMatrixRestore avmr; |
| 350 GrDrawState* drawState = fGpu->drawState(); | 351 GrDrawState* drawState = fGpu->drawState(); |
| 351 SkMatrix oldMatrix = drawState->getViewMatrix(); | 352 SkAssertResult(avmr.setIdentity(drawState)); |
| 352 drawState->viewMatrix()->reset(); | |
| 353 | 353 |
| 354 drawState->setRenderTarget(dstMask->asRenderTarget()); | 354 drawState->setRenderTarget(dstMask->asRenderTarget()); |
| 355 | 355 |
| 356 setup_boolean_blendcoeffs(drawState, op); | 356 setup_boolean_blendcoeffs(drawState, op); |
| 357 | 357 |
| 358 SkMatrix sampleM; | 358 SkMatrix sampleM; |
| 359 sampleM.setIDiv(srcMask->width(), srcMask->height()); | 359 sampleM.setIDiv(srcMask->width(), srcMask->height()); |
| 360 drawState->setEffect(0, | 360 drawState->setEffect(0, |
| 361 GrTextureDomainEffect::Create(srcMask, | 361 GrTextureDomainEffect::Create(srcMask, |
| 362 sampleM, | 362 sampleM, |
| 363 GrTextureDomainEffect::MakeTexelDomain(src
Mask, srcBound), | 363 GrTextureDomainEffect::MakeTexelDomain(src
Mask, srcBound), |
| 364 GrTextureDomainEffect::kDecal_WrapMode, | 364 GrTextureDomainEffect::kDecal_WrapMode, |
| 365 false))->unref(); | 365 false))->unref(); |
| 366 fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL); | 366 fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL); |
| 367 | 367 |
| 368 drawState->disableStage(0); | 368 drawState->disableStage(0); |
| 369 drawState->setViewMatrix(oldMatrix); | |
| 370 } | 369 } |
| 371 | 370 |
| 372 // get a texture to act as a temporary buffer for AA clip boolean operations | 371 // get a texture to act as a temporary buffer for AA clip boolean operations |
| 373 // TODO: given the expense of createTexture we may want to just cache this too | 372 // TODO: given the expense of createTexture we may want to just cache this too |
| 374 void GrClipMaskManager::getTemp(int width, int height, GrAutoScratchTexture* tem
p) { | 373 void GrClipMaskManager::getTemp(int width, int height, GrAutoScratchTexture* tem
p) { |
| 375 if (NULL != temp->texture()) { | 374 if (NULL != temp->texture()) { |
| 376 // we've already allocated the temp texture | 375 // we've already allocated the temp texture |
| 377 return; | 376 return; |
| 378 } | 377 } |
| 379 | 378 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result)) { | 429 if (this->getMaskTexture(clipStackGenID, clipSpaceIBounds, &result)) { |
| 431 fCurrClipMaskType = kAlpha_ClipMaskType; | 430 fCurrClipMaskType = kAlpha_ClipMaskType; |
| 432 return result; | 431 return result; |
| 433 } | 432 } |
| 434 | 433 |
| 435 if (NULL == result) { | 434 if (NULL == result) { |
| 436 fAACache.reset(); | 435 fAACache.reset(); |
| 437 return NULL; | 436 return NULL; |
| 438 } | 437 } |
| 439 | 438 |
| 440 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit); | |
| 441 GrDrawState* drawState = fGpu->drawState(); | |
| 442 | |
| 443 // The top-left of the mask corresponds to the top-left corner of the bounds
. | 439 // The top-left of the mask corresponds to the top-left corner of the bounds
. |
| 444 SkVector clipToMaskOffset = { | 440 SkVector clipToMaskOffset = { |
| 445 SkIntToScalar(-clipSpaceIBounds.fLeft), | 441 SkIntToScalar(-clipSpaceIBounds.fLeft), |
| 446 SkIntToScalar(-clipSpaceIBounds.fTop) | 442 SkIntToScalar(-clipSpaceIBounds.fTop) |
| 447 }; | 443 }; |
| 448 // The texture may be larger than necessary, this rect represents the part o
f the texture | 444 // The texture may be larger than necessary, this rect represents the part o
f the texture |
| 449 // we populate with a rasterization of the clip. | 445 // we populate with a rasterization of the clip. |
| 450 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); | 446 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); |
| 451 | 447 |
| 448 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip space. |
| 449 SkMatrix translate; |
| 450 translate.setTranslate(clipToMaskOffset); |
| 451 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRI
nit, &translate); |
| 452 |
| 453 GrDrawState* drawState = fGpu->drawState(); |
| 454 |
| 452 // We're drawing a coverage mask and want coverage to be run through the ble
nd function. | 455 // We're drawing a coverage mask and want coverage to be run through the ble
nd function. |
| 453 drawState->enableState(GrDrawState::kCoverageDrawing_StateBit); | 456 drawState->enableState(GrDrawState::kCoverageDrawing_StateBit); |
| 454 | 457 |
| 455 // Set the matrix so that rendered clip elements are transformed to mask spa
ce from clip space. | |
| 456 drawState->viewMatrix()->setTranslate(clipToMaskOffset); | |
| 457 | |
| 458 // The scratch texture that we are drawing into can be substantially larger
than the mask. Only | 458 // The scratch texture that we are drawing into can be substantially larger
than the mask. Only |
| 459 // clear the part that we care about. | 459 // clear the part that we care about. |
| 460 fGpu->clear(&maskSpaceIBounds, | 460 fGpu->clear(&maskSpaceIBounds, |
| 461 kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000, | 461 kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000, |
| 462 result->asRenderTarget()); | 462 result->asRenderTarget()); |
| 463 | 463 |
| 464 // When we use the stencil in the below loop it is important to have this cl
ip installed. | 464 // When we use the stencil in the below loop it is important to have this cl
ip installed. |
| 465 // The second pass that zeros the stencil buffer renders the rect maskSpaceI
Bounds so the first | 465 // The second pass that zeros the stencil buffer renders the rect maskSpaceI
Bounds so the first |
| 466 // pass must not set values outside of this bounds or stencil values outside
the rect won't be | 466 // pass must not set values outside of this bounds or stencil values outside
the rect won't be |
| 467 // cleared. | 467 // cleared. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 GrStencilBuffer* stencilBuffer = rt->getStencilBuffer(); | 582 GrStencilBuffer* stencilBuffer = rt->getStencilBuffer(); |
| 583 if (NULL == stencilBuffer) { | 583 if (NULL == stencilBuffer) { |
| 584 return false; | 584 return false; |
| 585 } | 585 } |
| 586 int32_t genID = elements.tail()->getGenID(); | 586 int32_t genID = elements.tail()->getGenID(); |
| 587 | 587 |
| 588 if (stencilBuffer->mustRenderClip(genID, clipSpaceIBounds, clipSpaceToStenci
lOffset)) { | 588 if (stencilBuffer->mustRenderClip(genID, clipSpaceIBounds, clipSpaceToStenci
lOffset)) { |
| 589 | 589 |
| 590 stencilBuffer->setLastClip(genID, clipSpaceIBounds, clipSpaceToStencilOf
fset); | 590 stencilBuffer->setLastClip(genID, clipSpaceIBounds, clipSpaceToStencilOf
fset); |
| 591 | 591 |
| 592 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_
ASRInit); | 592 // Set the matrix so that rendered clip elements are transformed from cl
ip to stencil space. |
| 593 SkVector translate = { |
| 594 SkIntToScalar(clipSpaceToStencilOffset.fX), |
| 595 SkIntToScalar(clipSpaceToStencilOffset.fY) |
| 596 }; |
| 597 SkMatrix matrix; |
| 598 matrix.setTranslate(translate); |
| 599 GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_
ASRInit, &matrix); |
| 593 drawState = fGpu->drawState(); | 600 drawState = fGpu->drawState(); |
| 601 |
| 594 drawState->setRenderTarget(rt); | 602 drawState->setRenderTarget(rt); |
| 595 | 603 |
| 596 // We set the current clip to the bounds so that our recursive draws are
scissored to them. | 604 // We set the current clip to the bounds so that our recursive draws are
scissored to them. |
| 597 SkIRect stencilSpaceIBounds(clipSpaceIBounds); | 605 SkIRect stencilSpaceIBounds(clipSpaceIBounds); |
| 598 stencilSpaceIBounds.offset(clipSpaceToStencilOffset); | 606 stencilSpaceIBounds.offset(clipSpaceToStencilOffset); |
| 599 GrDrawTarget::AutoClipRestore acr(fGpu, stencilSpaceIBounds); | 607 GrDrawTarget::AutoClipRestore acr(fGpu, stencilSpaceIBounds); |
| 600 drawState->enableState(GrDrawState::kClip_StateBit); | 608 drawState->enableState(GrDrawState::kClip_StateBit); |
| 601 | 609 |
| 602 // Set the matrix so that rendered clip elements are transformed from cl
ip to stencil space. | |
| 603 SkVector translate = { | |
| 604 SkIntToScalar(clipSpaceToStencilOffset.fX), | |
| 605 SkIntToScalar(clipSpaceToStencilOffset.fY) | |
| 606 }; | |
| 607 drawState->viewMatrix()->setTranslate(translate); | |
| 608 | |
| 609 #if !VISUALIZE_COMPLEX_CLIP | 610 #if !VISUALIZE_COMPLEX_CLIP |
| 610 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 611 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 611 #endif | 612 #endif |
| 612 | 613 |
| 613 int clipBit = stencilBuffer->bits(); | 614 int clipBit = stencilBuffer->bits(); |
| 614 SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil
buffers"); | 615 SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil
buffers"); |
| 615 clipBit = (1 << (clipBit-1)); | 616 clipBit = (1 << (clipBit-1)); |
| 616 | 617 |
| 617 fGpu->clearStencilClip(stencilSpaceIBounds, kAllIn_InitialState == initi
alState); | 618 fGpu->clearStencilClip(stencilSpaceIBounds, kAllIn_InitialState == initi
alState); |
| 618 | 619 |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1002 |
| 1002 //////////////////////////////////////////////////////////////////////////////// | 1003 //////////////////////////////////////////////////////////////////////////////// |
| 1003 void GrClipMaskManager::releaseResources() { | 1004 void GrClipMaskManager::releaseResources() { |
| 1004 fAACache.releaseResources(); | 1005 fAACache.releaseResources(); |
| 1005 } | 1006 } |
| 1006 | 1007 |
| 1007 void GrClipMaskManager::setGpu(GrGpu* gpu) { | 1008 void GrClipMaskManager::setGpu(GrGpu* gpu) { |
| 1008 fGpu = gpu; | 1009 fGpu = gpu; |
| 1009 fAACache.setContext(gpu->getContext()); | 1010 fAACache.setContext(gpu->getContext()); |
| 1010 } | 1011 } |
| OLD | NEW |