| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrClipMaskManager.h" | 8 #include "GrClipMaskManager.h" |
| 9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // last (false) parameter disallows use of the SW path renderer | 61 // last (false) parameter disallows use of the SW path renderer |
| 62 GrPathRendererChain::DrawType type = doAA ? | 62 GrPathRendererChain::DrawType type = doAA ? |
| 63 GrPathRendererChain::kColorAntiAlias_Dr
awType : | 63 GrPathRendererChain::kColorAntiAlias_Dr
awType : |
| 64 GrPathRendererChain::kColor_DrawType; | 64 GrPathRendererChain::kColor_DrawType; |
| 65 | 65 |
| 66 return nullptr == context->getPathRenderer(gpu, &pipelineBuilder, viewMatrix
, *path, stroke, | 66 return nullptr == context->getPathRenderer(gpu, &pipelineBuilder, viewMatrix
, *path, stroke, |
| 67 false, type); | 67 false, type); |
| 68 } | 68 } |
| 69 | 69 |
| 70 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget) | 70 GrClipMaskManager::GrClipMaskManager(GrDrawTarget* drawTarget) |
| 71 : fCurrClipMaskType(kNone_ClipMaskType) | 71 : fDrawTarget(drawTarget) |
| 72 , fDrawTarget(drawTarget) | |
| 73 , fClipMode(kIgnoreClip_StencilClipMode) { | 72 , fClipMode(kIgnoreClip_StencilClipMode) { |
| 74 } | 73 } |
| 75 | 74 |
| 76 GrContext* GrClipMaskManager::getContext() { return fDrawTarget->cmmAccess().con
text(); } | 75 GrContext* GrClipMaskManager::getContext() { return fDrawTarget->cmmAccess().con
text(); } |
| 77 | 76 |
| 78 /* | 77 /* |
| 79 * This method traverses the clip stack to see if the GrSoftwarePathRenderer | 78 * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
| 80 * will be used on any element. If so, it returns true to indicate that the | 79 * will be used on any element. If so, it returns true to indicate that the |
| 81 * entire clip should be rendered in SW and then uploaded en masse to the gpu. | 80 * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
| 82 */ | 81 */ |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 201 } |
| 203 | 202 |
| 204 //////////////////////////////////////////////////////////////////////////////// | 203 //////////////////////////////////////////////////////////////////////////////// |
| 205 // sort out what kind of clip mask needs to be created: alpha, stencil, | 204 // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 206 // scissor, or entirely software | 205 // scissor, or entirely software |
| 207 bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder, | 206 bool GrClipMaskManager::setupClipping(const GrPipelineBuilder& pipelineBuilder, |
| 208 GrPipelineBuilder::AutoRestoreStencil* ars
, | 207 GrPipelineBuilder::AutoRestoreStencil* ars
, |
| 209 GrScissorState* scissorState, | 208 GrScissorState* scissorState, |
| 210 const SkRect* devBounds, | 209 const SkRect* devBounds, |
| 211 GrAppliedClip* out) { | 210 GrAppliedClip* out) { |
| 212 fCurrClipMaskType = kNone_ClipMaskType; | |
| 213 if (kRespectClip_StencilClipMode == fClipMode) { | 211 if (kRespectClip_StencilClipMode == fClipMode) { |
| 214 fClipMode = kIgnoreClip_StencilClipMode; | 212 fClipMode = kIgnoreClip_StencilClipMode; |
| 215 } | 213 } |
| 216 | 214 |
| 217 GrReducedClip::ElementList elements(16); | 215 GrReducedClip::ElementList elements(16); |
| 218 int32_t genID = 0; | 216 int32_t genID = 0; |
| 219 GrReducedClip::InitialState initialState = GrReducedClip::kAllIn_InitialStat
e; | 217 GrReducedClip::InitialState initialState = GrReducedClip::kAllIn_InitialStat
e; |
| 220 SkIRect clipSpaceIBounds; | 218 SkIRect clipSpaceIBounds; |
| 221 bool requiresAA = false; | 219 bool requiresAA = false; |
| 222 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); | 220 GrRenderTarget* rt = pipelineBuilder.getRenderTarget(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 526 } |
| 529 texture->resourcePriv().setUniqueKey(key); | 527 texture->resourcePriv().setUniqueKey(key); |
| 530 return texture; | 528 return texture; |
| 531 } | 529 } |
| 532 | 530 |
| 533 GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID, | 531 GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID, |
| 534 GrReducedClip::InitialState in
itialState, | 532 GrReducedClip::InitialState in
itialState, |
| 535 const GrReducedClip::ElementLi
st& elements, | 533 const GrReducedClip::ElementLi
st& elements, |
| 536 const SkVector& clipToMaskOffs
et, | 534 const SkVector& clipToMaskOffs
et, |
| 537 const SkIRect& clipSpaceIBound
s) { | 535 const SkIRect& clipSpaceIBound
s) { |
| 538 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | |
| 539 GrResourceProvider* resourceProvider = fDrawTarget->cmmAccess().resourceProv
ider(); | 536 GrResourceProvider* resourceProvider = fDrawTarget->cmmAccess().resourceProv
ider(); |
| 540 GrUniqueKey key; | 537 GrUniqueKey key; |
| 541 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); | 538 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); |
| 542 if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)
) { | 539 if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)
) { |
| 543 fCurrClipMaskType = kAlpha_ClipMaskType; | |
| 544 return texture; | 540 return texture; |
| 545 } | 541 } |
| 546 | 542 |
| 547 SkAutoTUnref<GrTexture> texture(this->createCachedMask( | 543 SkAutoTUnref<GrTexture> texture(this->createCachedMask( |
| 548 clipSpaceIBounds.width(), clipSpaceIBounds.height(), key, true)); | 544 clipSpaceIBounds.width(), clipSpaceIBounds.height(), key, true)); |
| 549 | 545 |
| 550 // There's no texture in the cache. Let's try to allocate it then. | 546 // There's no texture in the cache. Let's try to allocate it then. |
| 551 if (!texture) { | 547 if (!texture) { |
| 552 return nullptr; | 548 return nullptr; |
| 553 } | 549 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } else { | 667 } else { |
| 672 GrPipelineBuilder pipelineBuilder; | 668 GrPipelineBuilder pipelineBuilder; |
| 673 | 669 |
| 674 // all the remaining ops can just be directly draw into the accumula
tion buffer | 670 // all the remaining ops can just be directly draw into the accumula
tion buffer |
| 675 set_coverage_drawing_xpf(op, false, &pipelineBuilder); | 671 set_coverage_drawing_xpf(op, false, &pipelineBuilder); |
| 676 // The color passed in here does not matter since the coverageSetOpX
P won't read it. | 672 // The color passed in here does not matter since the coverageSetOpX
P won't read it. |
| 677 this->drawElement(&pipelineBuilder, translate, texture, element); | 673 this->drawElement(&pipelineBuilder, translate, texture, element); |
| 678 } | 674 } |
| 679 } | 675 } |
| 680 | 676 |
| 681 fCurrClipMaskType = kAlpha_ClipMaskType; | |
| 682 return texture.detach(); | 677 return texture.detach(); |
| 683 } | 678 } |
| 684 | 679 |
| 685 //////////////////////////////////////////////////////////////////////////////// | 680 //////////////////////////////////////////////////////////////////////////////// |
| 686 // Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device | 681 // Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device |
| 687 // (as opposed to canvas) coordinates | 682 // (as opposed to canvas) coordinates |
| 688 bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, | 683 bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt, |
| 689 int32_t elementsGenID, | 684 int32_t elementsGenID, |
| 690 GrReducedClip::InitialState initia
lState, | 685 GrReducedClip::InitialState initia
lState, |
| 691 const GrReducedClip::ElementList&
elements, | 686 const GrReducedClip::ElementList&
elements, |
| 692 const SkIRect& clipSpaceIBounds, | 687 const SkIRect& clipSpaceIBounds, |
| 693 const SkIPoint& clipSpaceToStencil
Offset) { | 688 const SkIPoint& clipSpaceToStencil
Offset) { |
| 694 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | |
| 695 SkASSERT(rt); | 689 SkASSERT(rt); |
| 696 | 690 |
| 697 GrStencilAttachment* stencilAttachment = | 691 GrStencilAttachment* stencilAttachment = |
| 698 fDrawTarget->cmmAccess().resourceProvider()->attachStencilAttachment(rt)
; | 692 fDrawTarget->cmmAccess().resourceProvider()->attachStencilAttachment(rt)
; |
| 699 if (nullptr == stencilAttachment) { | 693 if (nullptr == stencilAttachment) { |
| 700 return false; | 694 return false; |
| 701 } | 695 } |
| 702 | 696 |
| 703 if (stencilAttachment->mustRenderClip(elementsGenID, clipSpaceIBounds, clipS
paceToStencilOffset)) { | 697 if (stencilAttachment->mustRenderClip(elementsGenID, clipSpaceIBounds, clipS
paceToStencilOffset)) { |
| 704 stencilAttachment->setLastClip(elementsGenID, clipSpaceIBounds, clipSpac
eToStencilOffset); | 698 stencilAttachment->setLastClip(elementsGenID, clipSpaceIBounds, clipSpac
eToStencilOffset); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 // The view matrix is setup to do clip space -> stencil spac
e translation, so | 858 // The view matrix is setup to do clip space -> stencil spac
e translation, so |
| 865 // draw rect in clip space. | 859 // draw rect in clip space. |
| 866 fDrawTarget->drawNonAARect(pipelineBuilder, | 860 fDrawTarget->drawNonAARect(pipelineBuilder, |
| 867 GrColor_WHITE, | 861 GrColor_WHITE, |
| 868 viewMatrix, | 862 viewMatrix, |
| 869 SkRect::Make(clipSpaceIBounds)); | 863 SkRect::Make(clipSpaceIBounds)); |
| 870 } | 864 } |
| 871 } | 865 } |
| 872 } | 866 } |
| 873 } | 867 } |
| 874 // set this last because recursive draws may overwrite it back to kNone. | |
| 875 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | |
| 876 fCurrClipMaskType = kStencil_ClipMaskType; | |
| 877 fClipMode = kRespectClip_StencilClipMode; | 868 fClipMode = kRespectClip_StencilClipMode; |
| 878 return true; | 869 return true; |
| 879 } | 870 } |
| 880 | 871 |
| 881 // mapping of clip-respecting stencil funcs to normal stencil funcs | 872 // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 882 // mapping depends on whether stencil-clipping is in effect. | 873 // mapping depends on whether stencil-clipping is in effect. |
| 883 static const GrStencilFunc | 874 static const GrStencilFunc |
| 884 gSpecialToBasicStencilFunc[2][kClipStencilFuncCount] = { | 875 gSpecialToBasicStencilFunc[2][kClipStencilFuncCount] = { |
| 885 {// Stencil-Clipping is DISABLED, we are effectively always inside the clip | 876 {// Stencil-Clipping is DISABLED, we are effectively always inside the clip |
| 886 // In the Clip Funcs | 877 // In the Clip Funcs |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 uint16_t funcMask = settings->funcMask(face); | 983 uint16_t funcMask = settings->funcMask(face); |
| 993 uint16_t funcRef = settings->funcRef(face); | 984 uint16_t funcRef = settings->funcRef(face); |
| 994 | 985 |
| 995 SkASSERT((unsigned) func < kStencilFuncCount); | 986 SkASSERT((unsigned) func < kStencilFuncCount); |
| 996 | 987 |
| 997 writeMask &= userBits; | 988 writeMask &= userBits; |
| 998 | 989 |
| 999 if (func >= kBasicStencilFuncCount) { | 990 if (func >= kBasicStencilFuncCount) { |
| 1000 int respectClip = kRespectClip_StencilClipMode == mode; | 991 int respectClip = kRespectClip_StencilClipMode == mode; |
| 1001 if (respectClip) { | 992 if (respectClip) { |
| 1002 // The GrGpu class should have checked this | |
| 1003 SkASSERT(this->isClipInStencil()); | |
| 1004 switch (func) { | 993 switch (func) { |
| 1005 case kAlwaysIfInClip_StencilFunc: | 994 case kAlwaysIfInClip_StencilFunc: |
| 1006 funcMask = clipBit; | 995 funcMask = clipBit; |
| 1007 funcRef = clipBit; | 996 funcRef = clipBit; |
| 1008 break; | 997 break; |
| 1009 case kEqualIfInClip_StencilFunc: | 998 case kEqualIfInClip_StencilFunc: |
| 1010 case kLessIfInClip_StencilFunc: | 999 case kLessIfInClip_StencilFunc: |
| 1011 case kLEqualIfInClip_StencilFunc: | 1000 case kLEqualIfInClip_StencilFunc: |
| 1012 funcMask = (funcMask & userBits) | clipBit; | 1001 funcMask = (funcMask & userBits) | clipBit; |
| 1013 funcRef = (funcRef & userBits) | clipBit; | 1002 funcRef = (funcRef & userBits) | clipBit; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 settings->copyFrontSettingsToBack(); | 1037 settings->copyFrontSettingsToBack(); |
| 1049 } | 1038 } |
| 1050 } | 1039 } |
| 1051 | 1040 |
| 1052 //////////////////////////////////////////////////////////////////////////////// | 1041 //////////////////////////////////////////////////////////////////////////////// |
| 1053 GrTexture* GrClipMaskManager::createSoftwareClipMask(int32_t elementsGenID, | 1042 GrTexture* GrClipMaskManager::createSoftwareClipMask(int32_t elementsGenID, |
| 1054 GrReducedClip::InitialState
initialState, | 1043 GrReducedClip::InitialState
initialState, |
| 1055 const GrReducedClip::Elemen
tList& elements, | 1044 const GrReducedClip::Elemen
tList& elements, |
| 1056 const SkVector& clipToMaskO
ffset, | 1045 const SkVector& clipToMaskO
ffset, |
| 1057 const SkIRect& clipSpaceIBo
unds) { | 1046 const SkIRect& clipSpaceIBo
unds) { |
| 1058 SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); | |
| 1059 GrUniqueKey key; | 1047 GrUniqueKey key; |
| 1060 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); | 1048 GetClipMaskKey(elementsGenID, clipSpaceIBounds, &key); |
| 1061 GrResourceProvider* resourceProvider = fDrawTarget->cmmAccess().resourceProv
ider(); | 1049 GrResourceProvider* resourceProvider = fDrawTarget->cmmAccess().resourceProv
ider(); |
| 1062 if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)
) { | 1050 if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)
) { |
| 1063 return texture; | 1051 return texture; |
| 1064 } | 1052 } |
| 1065 | 1053 |
| 1066 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin | 1054 // The mask texture may be larger than necessary. We round out the clip spac
e bounds and pin |
| 1067 // the top left corner of the resulting rect to the top left of the texture. | 1055 // the top left corner of the resulting rect to the top left of the texture. |
| 1068 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); | 1056 SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpa
ceIBounds.height()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 } | 1099 } |
| 1112 | 1100 |
| 1113 // Allocate clip mask texture | 1101 // Allocate clip mask texture |
| 1114 GrTexture* result = this->createCachedMask(clipSpaceIBounds.width(), clipSpa
ceIBounds.height(), | 1102 GrTexture* result = this->createCachedMask(clipSpaceIBounds.width(), clipSpa
ceIBounds.height(), |
| 1115 key, false); | 1103 key, false); |
| 1116 if (nullptr == result) { | 1104 if (nullptr == result) { |
| 1117 return nullptr; | 1105 return nullptr; |
| 1118 } | 1106 } |
| 1119 helper.toTexture(result); | 1107 helper.toTexture(result); |
| 1120 | 1108 |
| 1121 fCurrClipMaskType = kAlpha_ClipMaskType; | |
| 1122 return result; | 1109 return result; |
| 1123 } | 1110 } |
| 1124 | 1111 |
| 1125 //////////////////////////////////////////////////////////////////////////////// | 1112 //////////////////////////////////////////////////////////////////////////////// |
| 1126 | 1113 |
| 1127 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, | 1114 void GrClipMaskManager::adjustPathStencilParams(const GrStencilAttachment* stenc
ilAttachment, |
| 1128 GrStencilSettings* settings) { | 1115 GrStencilSettings* settings) { |
| 1129 if (stencilAttachment) { | 1116 if (stencilAttachment) { |
| 1130 int stencilBits = stencilAttachment->bits(); | 1117 int stencilBits = stencilAttachment->bits(); |
| 1131 this->adjustStencilParams(settings, fClipMode, stencilBits); | 1118 this->adjustStencilParams(settings, fClipMode, stencilBits); |
| 1132 } | 1119 } |
| 1133 } | 1120 } |
| OLD | NEW |