| 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 19 matching lines...) Expand all Loading... |
| 30 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| 31 namespace { | 31 namespace { |
| 32 // set up the draw state to enable the aa clipping mask. Besides setting up the | 32 // set up the draw state to enable the aa clipping mask. Besides setting up the |
| 33 // stage matrix this also alters the vertex layout | 33 // stage matrix this also alters the vertex layout |
| 34 void setup_drawstate_aaclip(GrGpu* gpu, | 34 void setup_drawstate_aaclip(GrGpu* gpu, |
| 35 GrTexture* result, | 35 GrTexture* result, |
| 36 const GrIRect &devBound) { | 36 const GrIRect &devBound) { |
| 37 GrDrawState* drawState = gpu->drawState(); | 37 GrDrawState* drawState = gpu->drawState(); |
| 38 GrAssert(drawState); | 38 GrAssert(drawState); |
| 39 | 39 |
| 40 static const int kMaskStage = GrPaint::kTotalStages+1; | |
| 41 | |
| 42 SkMatrix mat; | 40 SkMatrix mat; |
| 43 // We want to use device coords to compute the texture coordinates. We set o
ur matrix to be | 41 // We want to use device coords to compute the texture coordinates. We set o
ur matrix to be |
| 44 // equal to the view matrix followed by an offset to the devBound, and then
a scaling matrix to | 42 // equal to the view matrix followed by an offset to the devBound, and then
a scaling matrix to |
| 45 // normalized coords. We apply this matrix to the vertex positions rather th
an local coords. | 43 // normalized coords. We apply this matrix to the vertex positions rather th
an local coords. |
| 46 mat.setIDiv(result->width(), result->height()); | 44 mat.setIDiv(result->width(), result->height()); |
| 47 mat.preTranslate(SkIntToScalar(-devBound.fLeft), | 45 mat.preTranslate(SkIntToScalar(-devBound.fLeft), |
| 48 SkIntToScalar(-devBound.fTop)); | 46 SkIntToScalar(-devBound.fTop)); |
| 49 mat.preConcat(drawState->getViewMatrix()); | 47 mat.preConcat(drawState->getViewMatrix()); |
| 50 | 48 |
| 51 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); | 49 SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
| 52 // This could be a long-lived effect that is cached with the alpha-mask. | 50 // This could be a long-lived effect that is cached with the alpha-mask. |
| 53 drawState->setEffect(kMaskStage, | 51 drawState->addCoverageEffect( |
| 54 GrTextureDomainEffect::Create(result, | 52 GrTextureDomainEffect::Create(result, |
| 55 mat, | 53 mat, |
| 56 GrTextureDomainEffect::MakeTexelDomain(res
ult, domainTexels), | 54 GrTextureDomainEffect::MakeTexelDomain(res
ult, domainTexels), |
| 57 GrTextureDomainEffect::kDecal_WrapMode, | 55 GrTextureDomainEffect::kDecal_WrapMode, |
| 58 false, | 56 false, |
| 59 GrEffect::kPosition_CoordsType))->unref(); | 57 GrEffect::kPosition_CoordsType))->unref(); |
| 60 } | 58 } |
| 61 | 59 |
| 62 bool path_needs_SW_renderer(GrContext* context, | 60 bool path_needs_SW_renderer(GrContext* context, |
| 63 GrGpu* gpu, | 61 GrGpu* gpu, |
| 64 const SkPath& origPath, | 62 const SkPath& origPath, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 element->isAA())) { | 100 element->isAA())) { |
| 103 return true; | 101 return true; |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 return false; | 104 return false; |
| 107 } | 105 } |
| 108 | 106 |
| 109 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
| 110 // sort out what kind of clip mask needs to be created: alpha, stencil, | 108 // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 111 // scissor, or entirely software | 109 // scissor, or entirely software |
| 112 bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn) { | 110 bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn, |
| 111 GrDrawState::AutoRestoreEffects* are) { |
| 113 fCurrClipMaskType = kNone_ClipMaskType; | 112 fCurrClipMaskType = kNone_ClipMaskType; |
| 114 | 113 |
| 115 ElementList elements(16); | 114 ElementList elements(16); |
| 116 InitialState initialState; | 115 InitialState initialState; |
| 117 SkIRect clipSpaceIBounds; | 116 SkIRect clipSpaceIBounds; |
| 118 bool requiresAA; | 117 bool requiresAA; |
| 119 bool isRect = false; | 118 bool isRect = false; |
| 120 | 119 |
| 121 GrDrawState* drawState = fGpu->drawState(); | 120 GrDrawState* drawState = fGpu->drawState(); |
| 122 | 121 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 initialState, | 170 initialState, |
| 172 elements, | 171 elements, |
| 173 clipSpaceIBounds); | 172 clipSpaceIBounds); |
| 174 } | 173 } |
| 175 | 174 |
| 176 if (NULL != result) { | 175 if (NULL != result) { |
| 177 // The mask's top left coord should be pinned to the rounded-out top
left corner of | 176 // The mask's top left coord should be pinned to the rounded-out top
left corner of |
| 178 // clipSpace bounds. We determine the mask's position WRT to the ren
der target here. | 177 // clipSpace bounds. We determine the mask's position WRT to the ren
der target here. |
| 179 SkIRect rtSpaceMaskBounds = clipSpaceIBounds; | 178 SkIRect rtSpaceMaskBounds = clipSpaceIBounds; |
| 180 rtSpaceMaskBounds.offset(-clipDataIn->fOrigin); | 179 rtSpaceMaskBounds.offset(-clipDataIn->fOrigin); |
| 180 are->set(fGpu->drawState()); |
| 181 setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds); | 181 setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds); |
| 182 fGpu->disableScissor(); | 182 fGpu->disableScissor(); |
| 183 this->setGpuStencil(); | 183 this->setGpuStencil(); |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 // if alpha clip mask creation fails fall through to the non-AA code pat
hs | 186 // if alpha clip mask creation fails fall through to the non-AA code pat
hs |
| 187 } | 187 } |
| 188 #endif // GR_AA_CLIP | 188 #endif // GR_AA_CLIP |
| 189 | 189 |
| 190 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a
liased clip couldn't | 190 // Either a hard (stencil buffer) clip was explicitly requested or an anti-a
liased clip couldn't |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::AutoViewMatrixRestore avmr; |
| 351 GrDrawState* drawState = fGpu->drawState(); | 351 GrDrawState* drawState = fGpu->drawState(); |
| 352 SkAssertResult(avmr.setIdentity(drawState)); | 352 SkAssertResult(avmr.setIdentity(drawState)); |
| 353 GrDrawState::AutoRestoreEffects are(drawState); |
| 353 | 354 |
| 354 drawState->setRenderTarget(dstMask->asRenderTarget()); | 355 drawState->setRenderTarget(dstMask->asRenderTarget()); |
| 355 | 356 |
| 356 setup_boolean_blendcoeffs(drawState, op); | 357 setup_boolean_blendcoeffs(drawState, op); |
| 357 | 358 |
| 358 SkMatrix sampleM; | 359 SkMatrix sampleM; |
| 359 sampleM.setIDiv(srcMask->width(), srcMask->height()); | 360 sampleM.setIDiv(srcMask->width(), srcMask->height()); |
| 360 drawState->setEffect(0, | 361 drawState->addColorEffect( |
| 361 GrTextureDomainEffect::Create(srcMask, | 362 GrTextureDomainEffect::Create(srcMask, |
| 362 sampleM, | 363 sampleM, |
| 363 GrTextureDomainEffect::MakeTexelDomain(src
Mask, srcBound), | 364 GrTextureDomainEffect::MakeTexelDomain(src
Mask, srcBound), |
| 364 GrTextureDomainEffect::kDecal_WrapMode, | 365 GrTextureDomainEffect::kDecal_WrapMode, |
| 365 false))->unref(); | 366 false))->unref(); |
| 366 fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL); | 367 fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL); |
| 367 | |
| 368 drawState->disableStage(0); | |
| 369 } | 368 } |
| 370 | 369 |
| 371 // get a texture to act as a temporary buffer for AA clip boolean operations | 370 // get a texture to act as a temporary buffer for AA clip boolean operations |
| 372 // TODO: given the expense of createTexture we may want to just cache this too | 371 // TODO: given the expense of createTexture we may want to just cache this too |
| 373 void GrClipMaskManager::getTemp(int width, int height, GrAutoScratchTexture* tem
p) { | 372 void GrClipMaskManager::getTemp(int width, int height, GrAutoScratchTexture* tem
p) { |
| 374 if (NULL != temp->texture()) { | 373 if (NULL != temp->texture()) { |
| 375 // we've already allocated the temp texture | 374 // we've already allocated the temp texture |
| 376 return; | 375 return; |
| 377 } | 376 } |
| 378 | 377 |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 | 1001 |
| 1003 //////////////////////////////////////////////////////////////////////////////// | 1002 //////////////////////////////////////////////////////////////////////////////// |
| 1004 void GrClipMaskManager::releaseResources() { | 1003 void GrClipMaskManager::releaseResources() { |
| 1005 fAACache.releaseResources(); | 1004 fAACache.releaseResources(); |
| 1006 } | 1005 } |
| 1007 | 1006 |
| 1008 void GrClipMaskManager::setGpu(GrGpu* gpu) { | 1007 void GrClipMaskManager::setGpu(GrGpu* gpu) { |
| 1009 fGpu = gpu; | 1008 fGpu = gpu; |
| 1010 fAACache.setContext(gpu->getContext()); | 1009 fAACache.setContext(gpu->getContext()); |
| 1011 } | 1010 } |
| OLD | NEW |