robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrClipMaskManager.h" |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 10 | #include "GrAAConvexPathRenderer.h" |
| 11 | #include "GrAAHairLinePathRenderer.h" |
jvanverth@google.com | bfe2b9d | 2013-09-06 16:57:29 +0000 | [diff] [blame] | 12 | #include "GrAARectRenderer.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 13 | #include "GrDrawTargetCaps.h" |
| 14 | #include "GrGpu.h" |
| 15 | #include "GrPaint.h" |
| 16 | #include "GrPathRenderer.h" |
| 17 | #include "GrRenderTarget.h" |
| 18 | #include "GrStencilBuffer.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 19 | #include "GrSWMaskHelper.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 20 | #include "effects/GrTextureDomainEffect.h" |
| 21 | #include "SkRasterClip.h" |
| 22 | #include "SkStrokeRec.h" |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 23 | #include "SkTLazy.h" |
| 24 | |
robertphillips@google.com | ba998f2 | 2012-10-12 11:33:56 +0000 | [diff] [blame] | 25 | #define GR_AA_CLIP 1 |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 26 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 27 | typedef SkClipStack::Element Element; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 28 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 29 | using namespace GrReducedClip; |
| 30 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 31 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 32 | namespace { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 33 | // set up the draw state to enable the aa clipping mask. Besides setting up the |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 34 | // stage matrix this also alters the vertex layout |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 35 | void setup_drawstate_aaclip(GrGpu* gpu, |
| 36 | GrTexture* result, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 37 | const SkIRect &devBound) { |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 38 | GrDrawState* drawState = gpu->drawState(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 39 | SkASSERT(drawState); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 40 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 41 | SkMatrix mat; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 42 | // We want to use device coords to compute the texture coordinates. We set our matrix to be |
| 43 | // equal to the view matrix followed by an offset to the devBound, and then a scaling matrix to |
| 44 | // normalized coords. We apply this matrix to the vertex positions rather than local coords. |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 45 | mat.setIDiv(result->width(), result->height()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 46 | mat.preTranslate(SkIntToScalar(-devBound.fLeft), |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 47 | SkIntToScalar(-devBound.fTop)); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 48 | mat.preConcat(drawState->getViewMatrix()); |
| 49 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 50 | SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 51 | // This could be a long-lived effect that is cached with the alpha-mask. |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 52 | drawState->addCoverageEffect( |
| 53 | GrTextureDomainEffect::Create(result, |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 54 | mat, |
| 55 | GrTextureDomainEffect::MakeTexelDomain(result, domainTexels), |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 56 | GrTextureDomainEffect::kDecal_WrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 57 | GrTextureParams::kNone_FilterMode, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 58 | kPosition_GrCoordSet))->unref(); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 59 | } |
| 60 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 61 | bool path_needs_SW_renderer(GrContext* context, |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 62 | GrGpu* gpu, |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 63 | const SkPath& origPath, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 64 | const SkStrokeRec& stroke, |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 65 | bool doAA) { |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 66 | // the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer |
| 67 | SkTCopyOnFirstWrite<SkPath> path(origPath); |
| 68 | if (path->isInverseFillType()) { |
| 69 | path.writable()->toggleInverseFillType(); |
| 70 | } |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 71 | // last (false) parameter disallows use of the SW path renderer |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 72 | GrPathRendererChain::DrawType type = doAA ? |
| 73 | GrPathRendererChain::kColorAntiAlias_DrawType : |
| 74 | GrPathRendererChain::kColor_DrawType; |
| 75 | |
| 76 | return NULL == context->getPathRenderer(*path, stroke, gpu, false, type); |
robertphillips@google.com | a6f11c4 | 2012-07-23 17:39:44 +0000 | [diff] [blame] | 77 | } |
| 78 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 79 | } |
| 80 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 81 | /* |
| 82 | * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
| 83 | * will be used on any element. If so, it returns true to indicate that the |
| 84 | * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
| 85 | */ |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 86 | bool GrClipMaskManager::useSWOnlyPath(const ElementList& elements) { |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 87 | |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 88 | // TODO: generalize this function so that when |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 89 | // a clip gets complex enough it can just be done in SW regardless |
| 90 | // of whether it would invoke the GrSoftwarePathRenderer. |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 91 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
skia.committer@gmail.com | d21444a | 2012-12-07 02:01:25 +0000 | [diff] [blame] | 92 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 93 | for (ElementList::Iter iter(elements.headIter()); iter.get(); iter.next()) { |
| 94 | const Element* element = iter.get(); |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame] | 95 | // rects can always be drawn directly w/o using the software path |
| 96 | // so only paths need to be checked |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 97 | if (Element::kPath_Type == element->getType() && |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 98 | path_needs_SW_renderer(this->getContext(), fGpu, |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 99 | element->getPath(), |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 100 | stroke, |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 101 | element->isAA())) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 102 | return true; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 103 | } |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 104 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 105 | return false; |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 106 | } |
| 107 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 108 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 109 | // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 110 | // scissor, or entirely software |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 111 | bool GrClipMaskManager::setupClipping(const GrClipData* clipDataIn, |
| 112 | GrDrawState::AutoRestoreEffects* are) { |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 113 | fCurrClipMaskType = kNone_ClipMaskType; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 114 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 115 | ElementList elements(16); |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 116 | int32_t genID; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 117 | InitialState initialState; |
| 118 | SkIRect clipSpaceIBounds; |
| 119 | bool requiresAA; |
| 120 | bool isRect = false; |
| 121 | |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 122 | GrDrawState* drawState = fGpu->drawState(); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 123 | |
| 124 | const GrRenderTarget* rt = drawState->getRenderTarget(); |
| 125 | // GrDrawTarget should have filtered this for us |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 126 | SkASSERT(NULL != rt); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 127 | |
| 128 | bool ignoreClip = !drawState->isClipState() || clipDataIn->fClipStack->isWideOpen(); |
| 129 | |
| 130 | if (!ignoreClip) { |
| 131 | SkIRect clipSpaceRTIBounds = SkIRect::MakeWH(rt->width(), rt->height()); |
| 132 | clipSpaceRTIBounds.offset(clipDataIn->fOrigin); |
| 133 | ReduceClipStack(*clipDataIn->fClipStack, |
| 134 | clipSpaceRTIBounds, |
| 135 | &elements, |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 136 | &genID, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 137 | &initialState, |
| 138 | &clipSpaceIBounds, |
| 139 | &requiresAA); |
| 140 | if (elements.isEmpty()) { |
| 141 | if (kAllIn_InitialState == initialState) { |
| 142 | ignoreClip = clipSpaceIBounds == clipSpaceRTIBounds; |
| 143 | isRect = true; |
| 144 | } else { |
| 145 | return false; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if (ignoreClip) { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 151 | fGpu->disableScissor(); |
| 152 | this->setGpuStencil(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 153 | return true; |
| 154 | } |
| 155 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 156 | #if GR_AA_CLIP |
| 157 | // TODO: catch isRect && requiresAA and use clip planes if available rather than a mask. |
robertphillips@google.com | b99225c | 2012-07-24 18:20:10 +0000 | [diff] [blame] | 158 | |
robertphillips@google.com | a3e5c63 | 2012-05-22 18:09:26 +0000 | [diff] [blame] | 159 | // If MSAA is enabled we can do everything in the stencil buffer. |
robertphillips@google.com | b99225c | 2012-07-24 18:20:10 +0000 | [diff] [blame] | 160 | if (0 == rt->numSamples() && requiresAA) { |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 161 | GrTexture* result = NULL; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 162 | |
| 163 | if (this->useSWOnlyPath(elements)) { |
| 164 | // The clip geometry is complex enough that it will be more efficient to create it |
| 165 | // entirely in software |
| 166 | result = this->createSoftwareClipMask(genID, |
| 167 | initialState, |
| 168 | elements, |
| 169 | clipSpaceIBounds); |
| 170 | } else { |
| 171 | result = this->createAlphaClipMask(genID, |
| 172 | initialState, |
| 173 | elements, |
| 174 | clipSpaceIBounds); |
| 175 | } |
| 176 | |
| 177 | if (NULL != result) { |
| 178 | // The mask's top left coord should be pinned to the rounded-out top left corner of |
| 179 | // clipSpace bounds. We determine the mask's position WRT to the render target here. |
| 180 | SkIRect rtSpaceMaskBounds = clipSpaceIBounds; |
| 181 | rtSpaceMaskBounds.offset(-clipDataIn->fOrigin); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 182 | are->set(fGpu->drawState()); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 183 | setup_drawstate_aaclip(fGpu, result, rtSpaceMaskBounds); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 184 | fGpu->disableScissor(); |
| 185 | this->setGpuStencil(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 186 | return true; |
| 187 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 188 | // if alpha clip mask creation fails fall through to the non-AA code paths |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 189 | } |
| 190 | #endif // GR_AA_CLIP |
| 191 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 192 | // Either a hard (stencil buffer) clip was explicitly requested or an anti-aliased clip couldn't |
| 193 | // be created. In either case, free up the texture in the anti-aliased mask cache. |
| 194 | // TODO: this may require more investigation. Ganesh performs a lot of utility draws (e.g., |
| 195 | // clears, InOrderDrawBuffer playbacks) that hit the stencil buffer path. These may be |
| 196 | // "incorrectly" clearing the AA cache. |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 197 | fAACache.reset(); |
| 198 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 199 | // If the clip is a rectangle then just set the scissor. Otherwise, create |
| 200 | // a stencil mask. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 201 | if (isRect) { |
| 202 | SkIRect clipRect = clipSpaceIBounds; |
| 203 | clipRect.offset(-clipDataIn->fOrigin); |
| 204 | fGpu->enableScissor(clipRect); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 205 | this->setGpuStencil(); |
| 206 | return true; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 207 | } |
| 208 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 209 | // use the stencil clip if we can't represent the clip as a rectangle. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 210 | SkIPoint clipSpaceToStencilSpaceOffset = -clipDataIn->fOrigin; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 211 | this->createStencilClipMask(genID, |
| 212 | initialState, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 213 | elements, |
| 214 | clipSpaceIBounds, |
| 215 | clipSpaceToStencilSpaceOffset); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 216 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 217 | // This must occur after createStencilClipMask. That function may change the scissor. Also, it |
| 218 | // only guarantees that the stencil mask is correct within the bounds it was passed, so we must |
| 219 | // use both stencil and scissor test to the bounds for the final draw. |
| 220 | SkIRect scissorSpaceIBounds(clipSpaceIBounds); |
| 221 | scissorSpaceIBounds.offset(clipSpaceToStencilSpaceOffset); |
| 222 | fGpu->enableScissor(scissorSpaceIBounds); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 223 | this->setGpuStencil(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 224 | return true; |
| 225 | } |
| 226 | |
| 227 | #define VISUALIZE_COMPLEX_CLIP 0 |
| 228 | |
| 229 | #if VISUALIZE_COMPLEX_CLIP |
tfarina@chromium.org | 223137f | 2012-11-21 22:38:36 +0000 | [diff] [blame] | 230 | #include "SkRandom.h" |
| 231 | SkRandom gRandom; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 232 | #define SET_RANDOM_COLOR drawState->setColor(0xff000000 | gRandom.nextU()); |
| 233 | #else |
| 234 | #define SET_RANDOM_COLOR |
| 235 | #endif |
| 236 | |
| 237 | namespace { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 238 | |
| 239 | //////////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 240 | // set up the OpenGL blend function to perform the specified |
| 241 | // boolean operation for alpha clip mask creation |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 242 | void setup_boolean_blendcoeffs(GrDrawState* drawState, SkRegion::Op op) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 243 | |
| 244 | switch (op) { |
| 245 | case SkRegion::kReplace_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 246 | drawState->setBlendFunc(kOne_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 247 | break; |
| 248 | case SkRegion::kIntersect_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 249 | drawState->setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 250 | break; |
| 251 | case SkRegion::kUnion_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 252 | drawState->setBlendFunc(kOne_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 253 | break; |
| 254 | case SkRegion::kXOR_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 255 | drawState->setBlendFunc(kIDC_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 256 | break; |
| 257 | case SkRegion::kDifference_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 258 | drawState->setBlendFunc(kZero_GrBlendCoeff, kISC_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 259 | break; |
| 260 | case SkRegion::kReverseDifference_Op: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 261 | drawState->setBlendFunc(kIDC_GrBlendCoeff, kZero_GrBlendCoeff); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 262 | break; |
| 263 | default: |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 264 | SkASSERT(false); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 265 | break; |
| 266 | } |
| 267 | } |
| 268 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 269 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 270 | |
| 271 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 272 | bool GrClipMaskManager::drawElement(GrTexture* target, |
| 273 | const SkClipStack::Element* element, |
| 274 | GrPathRenderer* pr) { |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 275 | GrDrawState* drawState = fGpu->drawState(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 276 | |
| 277 | drawState->setRenderTarget(target->asRenderTarget()); |
| 278 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 279 | switch (element->getType()) { |
| 280 | case Element::kRect_Type: |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 281 | // TODO: Do rects directly to the accumulator using a aa-rect GrEffect that covers the |
| 282 | // entire mask bounds and writes 0 outside the rect. |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 283 | if (element->isAA()) { |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 284 | getContext()->getAARectRenderer()->fillAARect(fGpu, |
| 285 | fGpu, |
| 286 | element->getRect(), |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 287 | SkMatrix::I(), |
robertphillips@google.com | afd1cba | 2013-05-14 19:47:47 +0000 | [diff] [blame] | 288 | element->getRect(), |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 289 | false); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 290 | } else { |
| 291 | fGpu->drawSimpleRect(element->getRect(), NULL); |
| 292 | } |
| 293 | return true; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 294 | case Element::kPath_Type: { |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 295 | SkTCopyOnFirstWrite<SkPath> path(element->getPath()); |
| 296 | if (path->isInverseFillType()) { |
| 297 | path.writable()->toggleInverseFillType(); |
| 298 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 299 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 300 | if (NULL == pr) { |
| 301 | GrPathRendererChain::DrawType type; |
| 302 | type = element->isAA() ? GrPathRendererChain::kColorAntiAlias_DrawType : |
| 303 | GrPathRendererChain::kColor_DrawType; |
| 304 | pr = this->getContext()->getPathRenderer(*path, stroke, fGpu, false, type); |
| 305 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 306 | if (NULL == pr) { |
| 307 | return false; |
| 308 | } |
| 309 | pr->drawPath(element->getPath(), stroke, fGpu, element->isAA()); |
| 310 | break; |
| 311 | } |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 312 | default: |
| 313 | // something is wrong if we're trying to draw an empty element. |
| 314 | GrCrash("Unexpected element type"); |
| 315 | return false; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 316 | } |
| 317 | return true; |
| 318 | } |
| 319 | |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 320 | bool GrClipMaskManager::canStencilAndDrawElement(GrTexture* target, |
| 321 | const SkClipStack::Element* element, |
| 322 | GrPathRenderer** pr) { |
| 323 | GrDrawState* drawState = fGpu->drawState(); |
| 324 | drawState->setRenderTarget(target->asRenderTarget()); |
| 325 | |
| 326 | switch (element->getType()) { |
| 327 | case Element::kRect_Type: |
| 328 | return true; |
| 329 | case Element::kPath_Type: { |
| 330 | SkTCopyOnFirstWrite<SkPath> path(element->getPath()); |
| 331 | if (path->isInverseFillType()) { |
| 332 | path.writable()->toggleInverseFillType(); |
| 333 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 334 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 335 | GrPathRendererChain::DrawType type = element->isAA() ? |
| 336 | GrPathRendererChain::kStencilAndColorAntiAlias_DrawType : |
| 337 | GrPathRendererChain::kStencilAndColor_DrawType; |
| 338 | *pr = this->getContext()->getPathRenderer(*path, stroke, fGpu, false, type); |
| 339 | return NULL != *pr; |
| 340 | } |
| 341 | default: |
| 342 | // something is wrong if we're trying to draw an empty element. |
| 343 | GrCrash("Unexpected element type"); |
| 344 | return false; |
| 345 | } |
| 346 | } |
| 347 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 348 | void GrClipMaskManager::mergeMask(GrTexture* dstMask, |
| 349 | GrTexture* srcMask, |
| 350 | SkRegion::Op op, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 351 | const SkIRect& dstBound, |
| 352 | const SkIRect& srcBound) { |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 353 | GrDrawState::AutoViewMatrixRestore avmr; |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 354 | GrDrawState* drawState = fGpu->drawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 355 | SkAssertResult(avmr.setIdentity(drawState)); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 356 | GrDrawState::AutoRestoreEffects are(drawState); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 357 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 358 | drawState->setRenderTarget(dstMask->asRenderTarget()); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 359 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 360 | setup_boolean_blendcoeffs(drawState, op); |
skia.committer@gmail.com | 72b2e6f | 2012-11-08 02:03:56 +0000 | [diff] [blame] | 361 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 362 | SkMatrix sampleM; |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 363 | sampleM.setIDiv(srcMask->width(), srcMask->height()); |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 364 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 365 | drawState->addColorEffect( |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 366 | GrTextureDomainEffect::Create(srcMask, |
| 367 | sampleM, |
| 368 | GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound), |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 369 | GrTextureDomainEffect::kDecal_WrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 370 | GrTextureParams::kNone_FilterMode))->unref(); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 371 | fGpu->drawSimpleRect(SkRect::Make(dstBound), NULL); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 372 | } |
| 373 | |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 374 | // get a texture to act as a temporary buffer for AA clip boolean operations |
| 375 | // TODO: given the expense of createTexture we may want to just cache this too |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 376 | void GrClipMaskManager::getTemp(int width, int height, GrAutoScratchTexture* temp) { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 377 | if (NULL != temp->texture()) { |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 378 | // we've already allocated the temp texture |
| 379 | return; |
| 380 | } |
| 381 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 382 | GrTextureDesc desc; |
| 383 | desc.fFlags = kRenderTarget_GrTextureFlagBit|kNoStencil_GrTextureFlagBit; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 384 | desc.fWidth = width; |
| 385 | desc.fHeight = height; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 386 | desc.fConfig = kAlpha_8_GrPixelConfig; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 387 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 388 | temp->set(this->getContext(), desc); |
robertphillips@google.com | 6d62df4 | 2012-05-07 18:07:36 +0000 | [diff] [blame] | 389 | } |
| 390 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 391 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 392 | // Handles caching & allocation (if needed) of a clip alpha-mask texture for both the sw-upload |
| 393 | // or gpu-rendered cases. Returns true if there is no more work to be done (i.e., we got a cache |
| 394 | // hit) |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 395 | bool GrClipMaskManager::getMaskTexture(int32_t elementsGenID, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 396 | const SkIRect& clipSpaceIBounds, |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 397 | GrTexture** result, |
| 398 | bool willUpload) { |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 399 | bool cached = fAACache.canReuse(elementsGenID, clipSpaceIBounds); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 400 | if (!cached) { |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 401 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 402 | // There isn't a suitable entry in the cache so we create a new texture to store the mask. |
| 403 | // Since we are setting up the cache we know the last lookup was a miss. Free up the |
| 404 | // currently cached mask so it can be reused. |
| 405 | fAACache.reset(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 406 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 407 | GrTextureDesc desc; |
robertphillips@google.com | 2d2e5c4 | 2013-10-30 21:30:43 +0000 | [diff] [blame] | 408 | desc.fFlags = willUpload ? kNone_GrTextureFlags : kRenderTarget_GrTextureFlagBit; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 409 | desc.fWidth = clipSpaceIBounds.width(); |
| 410 | desc.fHeight = clipSpaceIBounds.height(); |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 411 | desc.fConfig = kRGBA_8888_GrPixelConfig; |
robertphillips@google.com | 94bdd7e | 2013-10-31 15:50:43 +0000 | [diff] [blame] | 412 | if (willUpload || this->getContext()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 413 | // We would always like A8 but it isn't supported on all platforms |
| 414 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 415 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 416 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 417 | fAACache.acquireMask(elementsGenID, desc, clipSpaceIBounds); |
robertphillips@google.com | 8fff356 | 2012-05-11 12:53:50 +0000 | [diff] [blame] | 418 | } |
| 419 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 420 | *result = fAACache.getLastMask(); |
| 421 | return cached; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 422 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 423 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 424 | //////////////////////////////////////////////////////////////////////////////// |
| 425 | // Create a 8-bit clip mask in alpha |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 426 | GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 427 | InitialState initialState, |
| 428 | const ElementList& elements, |
| 429 | const SkIRect& clipSpaceIBounds) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 430 | SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 431 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 432 | GrTexture* result; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 433 | if (this->getMaskTexture(elementsGenID, clipSpaceIBounds, &result, false)) { |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 434 | fCurrClipMaskType = kAlpha_ClipMaskType; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 435 | return result; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 436 | } |
| 437 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 438 | if (NULL == result) { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 439 | fAACache.reset(); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 440 | return NULL; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 441 | } |
| 442 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 443 | // The top-left of the mask corresponds to the top-left corner of the bounds. |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 444 | SkVector clipToMaskOffset = { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 445 | SkIntToScalar(-clipSpaceIBounds.fLeft), |
| 446 | SkIntToScalar(-clipSpaceIBounds.fTop) |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 447 | }; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 448 | // The texture may be larger than necessary, this rect represents the part of the texture |
| 449 | // we populate with a rasterization of the clip. |
| 450 | SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpaceIBounds.height()); |
| 451 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 452 | // Set the matrix so that rendered clip elements are transformed to mask space from clip space. |
| 453 | SkMatrix translate; |
| 454 | translate.setTranslate(clipToMaskOffset); |
| 455 | GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit, &translate); |
| 456 | |
| 457 | GrDrawState* drawState = fGpu->drawState(); |
| 458 | |
bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 459 | // We're drawing a coverage mask and want coverage to be run through the blend function. |
| 460 | drawState->enableState(GrDrawState::kCoverageDrawing_StateBit); |
| 461 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 462 | // The scratch texture that we are drawing into can be substantially larger than the mask. Only |
| 463 | // clear the part that we care about. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 464 | fGpu->clear(&maskSpaceIBounds, |
| 465 | kAllIn_InitialState == initialState ? 0xffffffff : 0x00000000, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 466 | true, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 467 | result->asRenderTarget()); |
skia.committer@gmail.com | d9f7503 | 2012-11-09 02:01:24 +0000 | [diff] [blame] | 468 | |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 469 | // When we use the stencil in the below loop it is important to have this clip installed. |
| 470 | // The second pass that zeros the stencil buffer renders the rect maskSpaceIBounds so the first |
| 471 | // pass must not set values outside of this bounds or stencil values outside the rect won't be |
| 472 | // cleared. |
| 473 | GrDrawTarget::AutoClipRestore acr(fGpu, maskSpaceIBounds); |
| 474 | drawState->enableState(GrDrawState::kClip_StateBit); |
| 475 | |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 476 | GrAutoScratchTexture temp; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 477 | // walk through each clip element and perform its set op |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 478 | for (ElementList::Iter iter = elements.headIter(); iter.get(); iter.next()) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 479 | const Element* element = iter.get(); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 480 | SkRegion::Op op = element->getOp(); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 481 | bool invert = element->isInverseFilled(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 482 | |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 483 | if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { |
| 484 | GrPathRenderer* pr = NULL; |
| 485 | bool useTemp = !this->canStencilAndDrawElement(result, element, &pr); |
| 486 | GrTexture* dst; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 487 | // This is the bounds of the clip element in the space of the alpha-mask. The temporary |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 488 | // mask buffer can be substantially larger than the actually clip stack element. We |
| 489 | // touch the minimum number of pixels necessary and use decal mode to combine it with |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 490 | // the accumulator. |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 491 | SkIRect maskSpaceElementIBounds; |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 492 | |
| 493 | if (useTemp) { |
| 494 | if (invert) { |
| 495 | maskSpaceElementIBounds = maskSpaceIBounds; |
| 496 | } else { |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 497 | SkRect elementBounds = element->getBounds(); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 498 | elementBounds.offset(clipToMaskOffset); |
| 499 | elementBounds.roundOut(&maskSpaceElementIBounds); |
| 500 | } |
| 501 | |
| 502 | this->getTemp(maskSpaceIBounds.fRight, maskSpaceIBounds.fBottom, &temp); |
| 503 | if (NULL == temp.texture()) { |
| 504 | fAACache.reset(); |
| 505 | return NULL; |
skia.committer@gmail.com | a7aedfe | 2012-12-15 02:03:10 +0000 | [diff] [blame] | 506 | } |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 507 | dst = temp.texture(); |
| 508 | // clear the temp target and set blend to replace |
| 509 | fGpu->clear(&maskSpaceElementIBounds, |
| 510 | invert ? 0xffffffff : 0x00000000, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 511 | true, |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 512 | dst->asRenderTarget()); |
| 513 | setup_boolean_blendcoeffs(drawState, SkRegion::kReplace_Op); |
skia.committer@gmail.com | a7aedfe | 2012-12-15 02:03:10 +0000 | [diff] [blame] | 514 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 515 | } else { |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 516 | // draw directly into the result with the stencil set to make the pixels affected |
| 517 | // by the clip shape be non-zero. |
| 518 | dst = result; |
| 519 | GR_STATIC_CONST_SAME_STENCIL(kStencilInElement, |
| 520 | kReplace_StencilOp, |
| 521 | kReplace_StencilOp, |
| 522 | kAlways_StencilFunc, |
| 523 | 0xffff, |
| 524 | 0xffff, |
| 525 | 0xffff); |
| 526 | drawState->setStencil(kStencilInElement); |
skia.committer@gmail.com | a7aedfe | 2012-12-15 02:03:10 +0000 | [diff] [blame] | 527 | setup_boolean_blendcoeffs(drawState, op); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 528 | } |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 529 | |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 530 | drawState->setAlpha(invert ? 0x00 : 0xff); |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 531 | |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 532 | if (!this->drawElement(dst, element, pr)) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 533 | fAACache.reset(); |
| 534 | return NULL; |
| 535 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 536 | |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 537 | if (useTemp) { |
| 538 | // Now draw into the accumulator using the real operation and the temp buffer as a |
| 539 | // texture |
| 540 | this->mergeMask(result, |
| 541 | temp.texture(), |
| 542 | op, |
| 543 | maskSpaceIBounds, |
| 544 | maskSpaceElementIBounds); |
| 545 | } else { |
| 546 | // Draw to the exterior pixels (those with a zero stencil value). |
| 547 | drawState->setAlpha(invert ? 0xff : 0x00); |
| 548 | GR_STATIC_CONST_SAME_STENCIL(kDrawOutsideElement, |
| 549 | kZero_StencilOp, |
| 550 | kZero_StencilOp, |
| 551 | kEqual_StencilFunc, |
| 552 | 0xffff, |
| 553 | 0x0000, |
| 554 | 0xffff); |
| 555 | drawState->setStencil(kDrawOutsideElement); |
| 556 | fGpu->drawSimpleRect(clipSpaceIBounds); |
| 557 | drawState->disableStencil(); |
| 558 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 559 | } else { |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 560 | // all the remaining ops can just be directly draw into the accumulation buffer |
| 561 | drawState->setAlpha(0xff); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 562 | setup_boolean_blendcoeffs(drawState, op); |
bsalomon@google.com | b68addd | 2012-12-14 13:36:53 +0000 | [diff] [blame] | 563 | this->drawElement(result, element); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 567 | fCurrClipMaskType = kAlpha_ClipMaskType; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 568 | return result; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | //////////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 572 | // Create a 1-bit clip mask in the stencil buffer. 'devClipBounds' are in device |
robertphillips@google.com | f8d904a | 2012-07-31 12:18:16 +0000 | [diff] [blame] | 573 | // (as opposed to canvas) coordinates |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 574 | bool GrClipMaskManager::createStencilClipMask(int32_t elementsGenID, |
| 575 | InitialState initialState, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 576 | const ElementList& elements, |
| 577 | const SkIRect& clipSpaceIBounds, |
| 578 | const SkIPoint& clipSpaceToStencilOffset) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 579 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 580 | SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 581 | |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 582 | GrDrawState* drawState = fGpu->drawState(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 583 | SkASSERT(drawState->isClipState()); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 584 | |
| 585 | GrRenderTarget* rt = drawState->getRenderTarget(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 586 | SkASSERT(NULL != rt); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 587 | |
| 588 | // TODO: dynamically attach a SB when needed. |
| 589 | GrStencilBuffer* stencilBuffer = rt->getStencilBuffer(); |
| 590 | if (NULL == stencilBuffer) { |
| 591 | return false; |
| 592 | } |
| 593 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 594 | if (stencilBuffer->mustRenderClip(elementsGenID, clipSpaceIBounds, clipSpaceToStencilOffset)) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 595 | |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 596 | stencilBuffer->setLastClip(elementsGenID, clipSpaceIBounds, clipSpaceToStencilOffset); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 597 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 598 | // Set the matrix so that rendered clip elements are transformed from clip to stencil space. |
| 599 | SkVector translate = { |
| 600 | SkIntToScalar(clipSpaceToStencilOffset.fX), |
| 601 | SkIntToScalar(clipSpaceToStencilOffset.fY) |
| 602 | }; |
| 603 | SkMatrix matrix; |
| 604 | matrix.setTranslate(translate); |
| 605 | GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit, &matrix); |
bsalomon@google.com | 13b85aa | 2012-06-15 21:09:40 +0000 | [diff] [blame] | 606 | drawState = fGpu->drawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 607 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 608 | drawState->setRenderTarget(rt); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 609 | |
bsalomon@google.com | 9f13174 | 2012-12-13 20:43:56 +0000 | [diff] [blame] | 610 | // We set the current clip to the bounds so that our recursive draws are scissored to them. |
| 611 | SkIRect stencilSpaceIBounds(clipSpaceIBounds); |
| 612 | stencilSpaceIBounds.offset(clipSpaceToStencilOffset); |
| 613 | GrDrawTarget::AutoClipRestore acr(fGpu, stencilSpaceIBounds); |
| 614 | drawState->enableState(GrDrawState::kClip_StateBit); |
| 615 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 616 | #if !VISUALIZE_COMPLEX_CLIP |
| 617 | drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 618 | #endif |
| 619 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 620 | int clipBit = stencilBuffer->bits(); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 621 | SkASSERT((clipBit <= 16) && "Ganesh only handles 16b or smaller stencil buffers"); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 622 | clipBit = (1 << (clipBit-1)); |
| 623 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 624 | fGpu->clearStencilClip(stencilSpaceIBounds, kAllIn_InitialState == initialState); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 625 | |
| 626 | // walk through each clip element and perform its set op |
| 627 | // with the existing clip. |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 628 | for (ElementList::Iter iter(elements.headIter()); NULL != iter.get(); iter.next()) { |
| 629 | const Element* element = iter.get(); |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 630 | bool fillInverted = false; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 631 | // enabled at bottom of loop |
| 632 | drawState->disableState(GrGpu::kModifyStencilClip_StateBit); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 633 | // if the target is MSAA then we want MSAA enabled when the clip is soft |
| 634 | if (rt->isMultisampled()) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 635 | drawState->setState(GrDrawState::kHWAntialias_StateBit, element->isAA()); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 636 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 637 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 638 | // This will be used to determine whether the clip shape can be rendered into the |
| 639 | // stencil with arbitrary stencil settings. |
| 640 | GrPathRenderer::StencilSupport stencilSupport; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 641 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 642 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 643 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 644 | SkRegion::Op op = element->getOp(); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 645 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 646 | GrPathRenderer* pr = NULL; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 647 | SkTCopyOnFirstWrite<SkPath> clipPath; |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 648 | if (Element::kRect_Type == element->getType()) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 649 | stencilSupport = GrPathRenderer::kNoRestriction_StencilSupport; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 650 | fillInverted = false; |
tomhudson@google.com | 8afae61 | 2012-08-14 15:03:35 +0000 | [diff] [blame] | 651 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 652 | SkASSERT(Element::kPath_Type == element->getType()); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 653 | clipPath.init(element->getPath()); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 654 | fillInverted = clipPath->isInverseFillType(); |
| 655 | if (fillInverted) { |
| 656 | clipPath.writable()->toggleInverseFillType(); |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 657 | } |
| 658 | pr = this->getContext()->getPathRenderer(*clipPath, |
| 659 | stroke, |
| 660 | fGpu, |
| 661 | false, |
| 662 | GrPathRendererChain::kStencilOnly_DrawType, |
| 663 | &stencilSupport); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 664 | if (NULL == pr) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 665 | return false; |
| 666 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 667 | } |
| 668 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 669 | int passes; |
| 670 | GrStencilSettings stencilSettings[GrStencilSettings::kMaxStencilClipPasses]; |
| 671 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 672 | bool canRenderDirectToStencil = |
| 673 | GrPathRenderer::kNoRestriction_StencilSupport == stencilSupport; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 674 | bool canDrawDirectToClip; // Given the renderer, the element, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 675 | // fill rule, and set operation can |
| 676 | // we render the element directly to |
| 677 | // stencil bit used for clipping. |
| 678 | canDrawDirectToClip = GrStencilSettings::GetClipPasses(op, |
| 679 | canRenderDirectToStencil, |
| 680 | clipBit, |
| 681 | fillInverted, |
| 682 | &passes, |
| 683 | stencilSettings); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 684 | |
| 685 | // draw the element to the client stencil bits if necessary |
| 686 | if (!canDrawDirectToClip) { |
| 687 | GR_STATIC_CONST_SAME_STENCIL(gDrawToStencil, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 688 | kIncClamp_StencilOp, |
| 689 | kIncClamp_StencilOp, |
| 690 | kAlways_StencilFunc, |
| 691 | 0xffff, |
| 692 | 0x0000, |
| 693 | 0xffff); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 694 | SET_RANDOM_COLOR |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 695 | if (Element::kRect_Type == element->getType()) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 696 | *drawState->stencil() = gDrawToStencil; |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 697 | fGpu->drawSimpleRect(element->getRect(), NULL); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 698 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 699 | SkASSERT(Element::kPath_Type == element->getType()); |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 700 | if (!clipPath->isEmpty()) { |
| 701 | if (canRenderDirectToStencil) { |
| 702 | *drawState->stencil() = gDrawToStencil; |
| 703 | pr->drawPath(*clipPath, stroke, fGpu, false); |
| 704 | } else { |
| 705 | pr->stencilPath(*clipPath, stroke, fGpu); |
| 706 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | // now we modify the clip bit by rendering either the clip |
| 712 | // element directly or a bounding rect of the entire clip. |
| 713 | drawState->enableState(GrGpu::kModifyStencilClip_StateBit); |
| 714 | for (int p = 0; p < passes; ++p) { |
| 715 | *drawState->stencil() = stencilSettings[p]; |
| 716 | if (canDrawDirectToClip) { |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 717 | if (Element::kRect_Type == element->getType()) { |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 718 | SET_RANDOM_COLOR |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 719 | fGpu->drawSimpleRect(element->getRect(), NULL); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 720 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 721 | SkASSERT(Element::kPath_Type == element->getType()); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 722 | SET_RANDOM_COLOR |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 723 | pr->drawPath(*clipPath, stroke, fGpu, false); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 724 | } |
| 725 | } else { |
| 726 | SET_RANDOM_COLOR |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 727 | // The view matrix is setup to do clip space -> stencil space translation, so |
| 728 | // draw rect in clip space. |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 729 | fGpu->drawSimpleRect(SkRect::Make(clipSpaceIBounds), NULL); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | } |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 733 | } |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 734 | // set this last because recursive draws may overwrite it back to kNone. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 735 | SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 736 | fCurrClipMaskType = kStencil_ClipMaskType; |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 737 | return true; |
| 738 | } |
| 739 | |
robertphillips@google.com | f8d904a | 2012-07-31 12:18:16 +0000 | [diff] [blame] | 740 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 741 | // mapping of clip-respecting stencil funcs to normal stencil funcs |
| 742 | // mapping depends on whether stencil-clipping is in effect. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 743 | static const GrStencilFunc |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 744 | gSpecialToBasicStencilFunc[2][kClipStencilFuncCount] = { |
| 745 | {// Stencil-Clipping is DISABLED, we are effectively always inside the clip |
| 746 | // In the Clip Funcs |
| 747 | kAlways_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 748 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 749 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 750 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 751 | // Special in the clip func that forces user's ref to be 0. |
| 752 | kNotEqual_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 753 | // make ref 0 and do normal nequal. |
| 754 | }, |
| 755 | {// Stencil-Clipping is ENABLED |
| 756 | // In the Clip Funcs |
| 757 | kEqual_StencilFunc, // kAlwaysIfInClip_StencilFunc |
| 758 | // eq stencil clip bit, mask |
| 759 | // out user bits. |
| 760 | |
| 761 | kEqual_StencilFunc, // kEqualIfInClip_StencilFunc |
| 762 | // add stencil bit to mask and ref |
| 763 | |
| 764 | kLess_StencilFunc, // kLessIfInClip_StencilFunc |
| 765 | kLEqual_StencilFunc, // kLEqualIfInClip_StencilFunc |
| 766 | // for both of these we can add |
| 767 | // the clip bit to the mask and |
| 768 | // ref and compare as normal |
| 769 | // Special in the clip func that forces user's ref to be 0. |
| 770 | kLess_StencilFunc, // kNonZeroIfInClip_StencilFunc |
| 771 | // make ref have only the clip bit set |
| 772 | // and make comparison be less |
| 773 | // 10..0 < 1..user_bits.. |
| 774 | } |
| 775 | }; |
| 776 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 777 | namespace { |
| 778 | // Sets the settings to clip against the stencil buffer clip while ignoring the |
| 779 | // client bits. |
| 780 | const GrStencilSettings& basic_apply_stencil_clip_settings() { |
| 781 | // stencil settings to use when clip is in stencil |
| 782 | GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
| 783 | kKeep_StencilOp, |
| 784 | kKeep_StencilOp, |
| 785 | kAlwaysIfInClip_StencilFunc, |
| 786 | 0x0000, |
| 787 | 0x0000, |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 788 | 0x0000); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 789 | return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | void GrClipMaskManager::setGpuStencil() { |
| 794 | // We make two copies of the StencilSettings here (except in the early |
| 795 | // exit scenario. One copy from draw state to the stack var. Then another |
| 796 | // from the stack var to the gpu. We could make this class hold a ptr to |
| 797 | // GrGpu's fStencilSettings and eliminate the stack copy here. |
| 798 | |
| 799 | const GrDrawState& drawState = fGpu->getDrawState(); |
| 800 | |
| 801 | // use stencil for clipping if clipping is enabled and the clip |
| 802 | // has been written into the stencil. |
| 803 | GrClipMaskManager::StencilClipMode clipMode; |
| 804 | if (this->isClipInStencil() && drawState.isClipState()) { |
| 805 | clipMode = GrClipMaskManager::kRespectClip_StencilClipMode; |
| 806 | // We can't be modifying the clip and respecting it at the same time. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 807 | SkASSERT(!drawState.isStateFlagEnabled( |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 808 | GrGpu::kModifyStencilClip_StateBit)); |
| 809 | } else if (drawState.isStateFlagEnabled( |
| 810 | GrGpu::kModifyStencilClip_StateBit)) { |
| 811 | clipMode = GrClipMaskManager::kModifyClip_StencilClipMode; |
| 812 | } else { |
| 813 | clipMode = GrClipMaskManager::kIgnoreClip_StencilClipMode; |
| 814 | } |
| 815 | |
| 816 | GrStencilSettings settings; |
| 817 | // The GrGpu client may not be using the stencil buffer but we may need to |
| 818 | // enable it in order to respect a stencil clip. |
| 819 | if (drawState.getStencil().isDisabled()) { |
| 820 | if (GrClipMaskManager::kRespectClip_StencilClipMode == clipMode) { |
| 821 | settings = basic_apply_stencil_clip_settings(); |
| 822 | } else { |
| 823 | fGpu->disableStencil(); |
| 824 | return; |
| 825 | } |
| 826 | } else { |
| 827 | settings = drawState.getStencil(); |
| 828 | } |
| 829 | |
| 830 | // TODO: dynamically attach a stencil buffer |
| 831 | int stencilBits = 0; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 832 | GrStencilBuffer* stencilBuffer = |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 833 | drawState.getRenderTarget()->getStencilBuffer(); |
| 834 | if (NULL != stencilBuffer) { |
| 835 | stencilBits = stencilBuffer->bits(); |
| 836 | } |
| 837 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 838 | SkASSERT(fGpu->caps()->stencilWrapOpsSupport() || !settings.usesWrapOp()); |
| 839 | SkASSERT(fGpu->caps()->twoSidedStencilSupport() || !settings.isTwoSided()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 840 | this->adjustStencilParams(&settings, clipMode, stencilBits); |
| 841 | fGpu->setStencilSettings(settings); |
| 842 | } |
| 843 | |
| 844 | void GrClipMaskManager::adjustStencilParams(GrStencilSettings* settings, |
| 845 | StencilClipMode mode, |
| 846 | int stencilBitCnt) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 847 | SkASSERT(stencilBitCnt > 0); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 848 | |
| 849 | if (kModifyClip_StencilClipMode == mode) { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 850 | // We assume that this clip manager itself is drawing to the GrGpu and |
| 851 | // has already setup the correct values. |
| 852 | return; |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 853 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 854 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 855 | unsigned int clipBit = (1 << (stencilBitCnt - 1)); |
| 856 | unsigned int userBits = clipBit - 1; |
| 857 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 858 | GrStencilSettings::Face face = GrStencilSettings::kFront_Face; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 859 | bool twoSided = fGpu->caps()->twoSidedStencilSupport(); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 860 | |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 861 | bool finished = false; |
| 862 | while (!finished) { |
| 863 | GrStencilFunc func = settings->func(face); |
| 864 | uint16_t writeMask = settings->writeMask(face); |
| 865 | uint16_t funcMask = settings->funcMask(face); |
| 866 | uint16_t funcRef = settings->funcRef(face); |
| 867 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 868 | SkASSERT((unsigned) func < kStencilFuncCount); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 869 | |
| 870 | writeMask &= userBits; |
| 871 | |
| 872 | if (func >= kBasicStencilFuncCount) { |
| 873 | int respectClip = kRespectClip_StencilClipMode == mode; |
| 874 | if (respectClip) { |
| 875 | // The GrGpu class should have checked this |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 876 | SkASSERT(this->isClipInStencil()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 877 | switch (func) { |
| 878 | case kAlwaysIfInClip_StencilFunc: |
| 879 | funcMask = clipBit; |
| 880 | funcRef = clipBit; |
| 881 | break; |
| 882 | case kEqualIfInClip_StencilFunc: |
| 883 | case kLessIfInClip_StencilFunc: |
| 884 | case kLEqualIfInClip_StencilFunc: |
| 885 | funcMask = (funcMask & userBits) | clipBit; |
| 886 | funcRef = (funcRef & userBits) | clipBit; |
| 887 | break; |
| 888 | case kNonZeroIfInClip_StencilFunc: |
| 889 | funcMask = (funcMask & userBits) | clipBit; |
| 890 | funcRef = clipBit; |
| 891 | break; |
| 892 | default: |
| 893 | GrCrash("Unknown stencil func"); |
| 894 | } |
| 895 | } else { |
| 896 | funcMask &= userBits; |
| 897 | funcRef &= userBits; |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 898 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 899 | const GrStencilFunc* table = |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 900 | gSpecialToBasicStencilFunc[respectClip]; |
| 901 | func = table[func - kBasicStencilFuncCount]; |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 902 | SkASSERT(func >= 0 && func < kBasicStencilFuncCount); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 903 | } else { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 904 | funcMask &= userBits; |
| 905 | funcRef &= userBits; |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 906 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 907 | |
| 908 | settings->setFunc(face, func); |
| 909 | settings->setWriteMask(face, writeMask); |
| 910 | settings->setFuncMask(face, funcMask); |
| 911 | settings->setFuncRef(face, funcRef); |
| 912 | |
| 913 | if (GrStencilSettings::kFront_Face == face) { |
| 914 | face = GrStencilSettings::kBack_Face; |
| 915 | finished = !twoSided; |
| 916 | } else { |
| 917 | finished = true; |
| 918 | } |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 919 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 920 | if (!twoSided) { |
| 921 | settings->copyFrontSettingsToBack(); |
| 922 | } |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 926 | GrTexture* GrClipMaskManager::createSoftwareClipMask(int32_t elementsGenID, |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 927 | GrReducedClip::InitialState initialState, |
| 928 | const GrReducedClip::ElementList& elements, |
| 929 | const SkIRect& clipSpaceIBounds) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 930 | SkASSERT(kNone_ClipMaskType == fCurrClipMaskType); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 931 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 932 | GrTexture* result; |
commit-bot@chromium.org | d3e5842 | 2013-11-05 15:03:08 +0000 | [diff] [blame^] | 933 | if (this->getMaskTexture(elementsGenID, clipSpaceIBounds, &result, true)) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 934 | return result; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 935 | } |
| 936 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 937 | if (NULL == result) { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 938 | fAACache.reset(); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 939 | return NULL; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 940 | } |
| 941 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 942 | // The mask texture may be larger than necessary. We round out the clip space bounds and pin |
| 943 | // the top left corner of the resulting rect to the top left of the texture. |
| 944 | SkIRect maskSpaceIBounds = SkIRect::MakeWH(clipSpaceIBounds.width(), clipSpaceIBounds.height()); |
| 945 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 946 | GrSWMaskHelper helper(this->getContext()); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 947 | |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 948 | SkMatrix matrix; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 949 | matrix.setTranslate(SkIntToScalar(-clipSpaceIBounds.fLeft), |
| 950 | SkIntToScalar(-clipSpaceIBounds.fTop)); |
| 951 | helper.init(maskSpaceIBounds, &matrix); |
| 952 | |
| 953 | helper.clear(kAllIn_InitialState == initialState ? 0xFF : 0x00); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 954 | |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 955 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 956 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 957 | for (ElementList::Iter iter(elements.headIter()) ; NULL != iter.get(); iter.next()) { |
robertphillips@google.com | a6f11c4 | 2012-07-23 17:39:44 +0000 | [diff] [blame] | 958 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 959 | const Element* element = iter.get(); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 960 | SkRegion::Op op = element->getOp(); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 961 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 962 | if (SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { |
| 963 | // Intersect and reverse difference require modifying pixels outside of the geometry |
| 964 | // that is being "drawn". In both cases we erase all the pixels outside of the geometry |
| 965 | // but leave the pixels inside the geometry alone. For reverse difference we invert all |
| 966 | // the pixels before clearing the ones outside the geometry. |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 967 | if (SkRegion::kReverseDifference_Op == op) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 968 | SkRect temp = SkRect::Make(clipSpaceIBounds); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 969 | // invert the entire scene |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 970 | helper.draw(temp, SkRegion::kXOR_Op, false, 0xFF); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 971 | } |
| 972 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 973 | if (Element::kRect_Type == element->getType()) { |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 974 | // convert the rect to a path so we can invert the fill |
| 975 | SkPath temp; |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 976 | temp.addRect(element->getRect()); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 977 | temp.setFillType(SkPath::kInverseEvenOdd_FillType); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 978 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 979 | helper.draw(temp, stroke, SkRegion::kReplace_Op, |
| 980 | element->isAA(), |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 981 | 0x00); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 982 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 983 | SkASSERT(Element::kPath_Type == element->getType()); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 984 | SkPath clipPath = element->getPath(); |
| 985 | clipPath.toggleInverseFillType(); |
skia.committer@gmail.com | d21444a | 2012-12-07 02:01:25 +0000 | [diff] [blame] | 986 | helper.draw(clipPath, stroke, |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 987 | SkRegion::kReplace_Op, |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 988 | element->isAA(), |
robertphillips@google.com | 366f1c6 | 2012-06-29 21:38:47 +0000 | [diff] [blame] | 989 | 0x00); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | continue; |
| 993 | } |
| 994 | |
| 995 | // The other ops (union, xor, diff) only affect pixels inside |
| 996 | // the geometry so they can just be drawn normally |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 997 | if (Element::kRect_Type == element->getType()) { |
| 998 | helper.draw(element->getRect(), op, element->isAA(), 0xFF); |
| 999 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1000 | SkASSERT(Element::kPath_Type == element->getType()); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1001 | helper.draw(element->getPath(), stroke, op, element->isAA(), 0xFF); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
robertphillips@google.com | d92cf2e | 2013-07-19 18:13:02 +0000 | [diff] [blame] | 1005 | helper.toTexture(result); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1006 | |
bsalomon@google.com | c8f7f47 | 2012-06-18 13:44:51 +0000 | [diff] [blame] | 1007 | fCurrClipMaskType = kAlpha_ClipMaskType; |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 1008 | return result; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 1011 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 1012 | void GrClipMaskManager::releaseResources() { |
robertphillips@google.com | f105b10 | 2012-05-14 12:18:26 +0000 | [diff] [blame] | 1013 | fAACache.releaseResources(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1014 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1015 | |
| 1016 | void GrClipMaskManager::setGpu(GrGpu* gpu) { |
| 1017 | fGpu = gpu; |
| 1018 | fAACache.setContext(gpu->getContext()); |
| 1019 | } |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 1020 | |
| 1021 | void GrClipMaskManager::adjustPathStencilParams(GrStencilSettings* settings) { |
| 1022 | const GrDrawState& drawState = fGpu->getDrawState(); |
| 1023 | GrClipMaskManager::StencilClipMode clipMode; |
| 1024 | if (this->isClipInStencil() && drawState.isClipState()) { |
| 1025 | clipMode = GrClipMaskManager::kRespectClip_StencilClipMode; |
| 1026 | // We can't be modifying the clip and respecting it at the same time. |
| 1027 | SkASSERT(!drawState.isStateFlagEnabled( |
| 1028 | GrGpu::kModifyStencilClip_StateBit)); |
| 1029 | } else if (drawState.isStateFlagEnabled( |
| 1030 | GrGpu::kModifyStencilClip_StateBit)) { |
| 1031 | clipMode = GrClipMaskManager::kModifyClip_StencilClipMode; |
| 1032 | } else { |
| 1033 | clipMode = GrClipMaskManager::kIgnoreClip_StencilClipMode; |
| 1034 | } |
| 1035 | |
| 1036 | // TODO: dynamically attach a stencil buffer |
| 1037 | int stencilBits = 0; |
| 1038 | GrStencilBuffer* stencilBuffer = |
| 1039 | drawState.getRenderTarget()->getStencilBuffer(); |
| 1040 | if (NULL != stencilBuffer) { |
| 1041 | stencilBits = stencilBuffer->bits(); |
| 1042 | this->adjustStencilParams(settings, clipMode, stencilBits); |
| 1043 | } |
| 1044 | } |