robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 1 | /* |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 2 | * Copyright 2016 Google Inc. |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 8 | #include "GrClipStackClip.h" |
| 9 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 11 | #include "GrContextPriv.h" |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 12 | #include "GrDrawingManager.h" |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 13 | #include "GrDrawContextPriv.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 14 | #include "GrFixedClip.h" |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 15 | #include "GrGpuResourcePriv.h" |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetPriv.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 17 | #include "GrStencilAttachment.h" |
robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 18 | #include "GrSWMaskHelper.h" |
egdaniel | 8d95ffa | 2014-12-08 13:26:43 -0800 | [diff] [blame] | 19 | #include "effects/GrConvexPolyEffect.h" |
| 20 | #include "effects/GrRRectEffect.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 21 | #include "effects/GrTextureDomain.h" |
bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 23 | typedef SkClipStack::Element Element; |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 24 | typedef GrReducedClip::InitialState InitialState; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 25 | typedef GrReducedClip::ElementList ElementList; |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 26 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 27 | static const int kMaxAnalyticElements = 4; |
| 28 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 29 | bool GrClipStackClip::quickContains(const SkRect& rect) const { |
reed | 4d2cce4 | 2016-08-22 13:03:47 -0700 | [diff] [blame] | 30 | if (!fStack || fStack->isWideOpen()) { |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 31 | return true; |
| 32 | } |
| 33 | return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()), |
| 34 | SkIntToScalar(fOrigin.y()))); |
| 35 | } |
| 36 | |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 37 | bool GrClipStackClip::quickContains(const SkRRect& rrect) const { |
reed | 4d2cce4 | 2016-08-22 13:03:47 -0700 | [diff] [blame] | 38 | if (!fStack || fStack->isWideOpen()) { |
bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 39 | return true; |
| 40 | } |
| 41 | return fStack->quickContains(rrect.makeOffset(SkIntToScalar(fOrigin.fX), |
| 42 | SkIntToScalar(fOrigin.fY))); |
| 43 | } |
| 44 | |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 45 | bool GrClipStackClip::isRRect(const SkRect& origRTBounds, SkRRect* rr, bool* aa) const { |
| 46 | if (!fStack) { |
| 47 | return false; |
| 48 | } |
| 49 | const SkRect* rtBounds = &origRTBounds; |
| 50 | SkRect tempRTBounds; |
| 51 | bool origin = fOrigin.fX || fOrigin.fY; |
| 52 | if (origin) { |
| 53 | tempRTBounds = origRTBounds; |
| 54 | tempRTBounds.offset(SkIntToScalar(fOrigin.fX), SkIntToScalar(fOrigin.fY)); |
| 55 | rtBounds = &tempRTBounds; |
| 56 | } |
| 57 | if (fStack->isRRect(*rtBounds, rr, aa)) { |
| 58 | if (origin) { |
| 59 | rr->offset(-SkIntToScalar(fOrigin.fX), -SkIntToScalar(fOrigin.fY)); |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | return false; |
| 64 | } |
| 65 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 66 | void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 67 | bool* isIntersectionOfRects) const { |
| 68 | if (!fStack) { |
| 69 | devResult->setXYWH(0, 0, width, height); |
| 70 | if (isIntersectionOfRects) { |
| 71 | *isIntersectionOfRects = true; |
| 72 | } |
| 73 | return; |
| 74 | } |
| 75 | SkRect devBounds; |
| 76 | fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds, |
| 77 | isIntersectionOfRects); |
| 78 | devBounds.roundOut(devResult); |
| 79 | } |
| 80 | |
bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 81 | //////////////////////////////////////////////////////////////////////////////// |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 82 | // 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] | 83 | // stage matrix this also alters the vertex layout |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 84 | static sk_sp<GrFragmentProcessor> create_fp_for_mask(GrTexture* result, |
| 85 | const SkIRect &devBound) { |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 86 | SkMatrix mat; |
bsalomon | 309d4d5 | 2014-12-18 10:17:44 -0800 | [diff] [blame] | 87 | // We use device coords to compute the texture coordinates. We set our matrix to be a |
| 88 | // translation to the devBound, and then a scaling matrix to normalized coords. |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 89 | mat.setIDiv(result->width(), result->height()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 90 | mat.preTranslate(SkIntToScalar(-devBound.fLeft), |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 91 | SkIntToScalar(-devBound.fTop)); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 92 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 93 | SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 94 | return sk_sp<GrFragmentProcessor>(GrTextureDomainEffect::Make( |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 95 | result, |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 96 | nullptr, |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 97 | mat, |
| 98 | GrTextureDomain::MakeTexelDomain(result, domainTexels), |
| 99 | GrTextureDomain::kDecal_Mode, |
| 100 | GrTextureParams::kNone_FilterMode, |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 101 | kDevice_GrCoordSet)); |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 102 | } |
| 103 | |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 104 | // Does the path in 'element' require SW rendering? If so, return true (and, |
| 105 | // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set |
| 106 | // 'prOut' to the non-SW path renderer that will do the job). |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 107 | bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context, |
| 108 | bool hasUserStencilSettings, |
| 109 | const GrDrawContext* drawContext, |
| 110 | const SkMatrix& viewMatrix, |
| 111 | const Element* element, |
| 112 | GrPathRenderer** prOut, |
| 113 | bool needsStencil) { |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 114 | if (Element::kRect_Type == element->getType()) { |
| 115 | // rects can always be drawn directly w/o using the software path |
| 116 | // TODO: skip rrects once we're drawing them directly. |
| 117 | if (prOut) { |
| 118 | *prOut = nullptr; |
| 119 | } |
| 120 | return false; |
| 121 | } else { |
| 122 | // We shouldn't get here with an empty clip element. |
| 123 | SkASSERT(Element::kEmpty_Type != element->getType()); |
robertphillips | 5c3ea4c | 2015-10-26 08:33:10 -0700 | [diff] [blame] | 124 | |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 125 | // the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer |
| 126 | SkPath path; |
| 127 | element->asPath(&path); |
| 128 | if (path.isInverseFillType()) { |
| 129 | path.toggleInverseFillType(); |
| 130 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 131 | |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 132 | GrPathRendererChain::DrawType type; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 133 | |
robertphillips | 423e337 | 2015-10-27 09:23:38 -0700 | [diff] [blame] | 134 | if (needsStencil) { |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 135 | type = element->isAA() |
| 136 | ? GrPathRendererChain::kStencilAndColorAntiAlias_DrawType |
| 137 | : GrPathRendererChain::kStencilAndColor_DrawType; |
| 138 | } else { |
| 139 | type = element->isAA() |
| 140 | ? GrPathRendererChain::kColorAntiAlias_DrawType |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 141 | : GrPathRendererChain::kColor_DrawType; |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 142 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 143 | |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 144 | GrShape shape(path, GrStyle::SimpleFill()); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 145 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 146 | canDrawArgs.fShaderCaps = context->caps()->shaderCaps(); |
| 147 | canDrawArgs.fViewMatrix = &viewMatrix; |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 148 | canDrawArgs.fShape = &shape; |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 149 | canDrawArgs.fAntiAlias = element->isAA(); |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 150 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 151 | canDrawArgs.fIsStencilBufferMSAA = drawContext->isStencilBufferMultisampled(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 152 | |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 153 | // the 'false' parameter disallows use of the SW path renderer |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 154 | GrPathRenderer* pr = |
| 155 | context->contextPriv().drawingManager()->getPathRenderer(canDrawArgs, false, type); |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 156 | if (prOut) { |
| 157 | *prOut = pr; |
| 158 | } |
| 159 | return SkToBool(!pr); |
| 160 | } |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 161 | } |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 162 | |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 163 | /* |
| 164 | * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
| 165 | * will be used on any element. If so, it returns true to indicate that the |
| 166 | * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
| 167 | */ |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 168 | bool GrClipStackClip::UseSWOnlyPath(GrContext* context, |
| 169 | bool hasUserStencilSettings, |
| 170 | const GrDrawContext* drawContext, |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 171 | const GrReducedClip& reducedClip) { |
robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 172 | // TODO: generalize this function so that when |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 173 | // a clip gets complex enough it can just be done in SW regardless |
| 174 | // of whether it would invoke the GrSoftwarePathRenderer. |
skia.committer@gmail.com | d21444a | 2012-12-07 02:01:25 +0000 | [diff] [blame] | 175 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 176 | // Set the matrix so that rendered clip elements are transformed to mask space from clip |
| 177 | // space. |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 178 | SkMatrix translate; |
| 179 | translate.setTranslate(SkIntToScalar(-reducedClip.left()), SkIntToScalar(-reducedClip.top())); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 180 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 181 | for (ElementList::Iter iter(reducedClip.elements()); iter.get(); iter.next()) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 182 | const Element* element = iter.get(); |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 183 | |
| 184 | SkRegion::Op op = element->getOp(); |
| 185 | bool invert = element->isInverseFilled(); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 186 | bool needsStencil = invert || |
robertphillips | 423e337 | 2015-10-27 09:23:38 -0700 | [diff] [blame] | 187 | SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op; |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 188 | |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 189 | if (PathNeedsSWRenderer(context, hasUserStencilSettings, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 190 | drawContext, translate, element, nullptr, needsStencil)) { |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 191 | return true; |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 192 | } |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 193 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 194 | return false; |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 195 | } |
| 196 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 197 | static bool get_analytic_clip_processor(const ElementList& elements, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 198 | bool abortIfAA, |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 199 | const SkVector& clipToRTOffset, |
bsalomon | bd2bbe4 | 2016-07-08 07:36:42 -0700 | [diff] [blame] | 200 | const SkRect& drawBounds, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 201 | sk_sp<GrFragmentProcessor>* resultFP) { |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 202 | SkRect boundsInClipSpace; |
bsalomon | bd2bbe4 | 2016-07-08 07:36:42 -0700 | [diff] [blame] | 203 | boundsInClipSpace = drawBounds.makeOffset(-clipToRTOffset.fX, -clipToRTOffset.fY); |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 204 | SkASSERT(elements.count() <= kMaxAnalyticElements); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 205 | SkSTArray<kMaxAnalyticElements, sk_sp<GrFragmentProcessor>> fps; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 206 | ElementList::Iter iter(elements); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 207 | while (iter.get()) { |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 208 | SkRegion::Op op = iter.get()->getOp(); |
| 209 | bool invert; |
| 210 | bool skip = false; |
| 211 | switch (op) { |
| 212 | case SkRegion::kReplace_Op: |
| 213 | SkASSERT(iter.get() == elements.head()); |
| 214 | // Fallthrough, handled same as intersect. |
| 215 | case SkRegion::kIntersect_Op: |
| 216 | invert = false; |
bsalomon | bd2bbe4 | 2016-07-08 07:36:42 -0700 | [diff] [blame] | 217 | if (iter.get()->contains(boundsInClipSpace)) { |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 218 | skip = true; |
| 219 | } |
| 220 | break; |
| 221 | case SkRegion::kDifference_Op: |
| 222 | invert = true; |
| 223 | // We don't currently have a cheap test for whether a rect is fully outside an |
| 224 | // element's primitive, so don't attempt to set skip. |
| 225 | break; |
| 226 | default: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 227 | return false; |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 228 | } |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 229 | if (!skip) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 230 | GrPrimitiveEdgeType edgeType; |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 231 | if (iter.get()->isAA()) { |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 232 | if (abortIfAA) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 233 | return false; |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 234 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 235 | edgeType = |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 236 | invert ? kInverseFillAA_GrProcessorEdgeType : kFillAA_GrProcessorEdgeType; |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 237 | } else { |
bsalomon | 0ba8c24 | 2015-10-07 09:20:28 -0700 | [diff] [blame] | 238 | edgeType = |
| 239 | invert ? kInverseFillBW_GrProcessorEdgeType : kFillBW_GrProcessorEdgeType; |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 240 | } |
bsalomon | a912dde | 2015-10-14 15:01:50 -0700 | [diff] [blame] | 241 | |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 242 | switch (iter.get()->getType()) { |
| 243 | case SkClipStack::Element::kPath_Type: |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 244 | fps.emplace_back(GrConvexPolyEffect::Make(edgeType, iter.get()->getPath(), |
| 245 | &clipToRTOffset)); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 246 | break; |
| 247 | case SkClipStack::Element::kRRect_Type: { |
| 248 | SkRRect rrect = iter.get()->getRRect(); |
| 249 | rrect.offset(clipToRTOffset.fX, clipToRTOffset.fY); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 250 | fps.emplace_back(GrRRectEffect::Make(edgeType, rrect)); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | case SkClipStack::Element::kRect_Type: { |
| 254 | SkRect rect = iter.get()->getRect(); |
| 255 | rect.offset(clipToRTOffset.fX, clipToRTOffset.fY); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 256 | fps.emplace_back(GrConvexPolyEffect::Make(edgeType, rect)); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | default: |
| 260 | break; |
| 261 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 262 | if (!fps.back()) { |
| 263 | return false; |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 264 | } |
| 265 | } |
mtklein | 217daa7 | 2014-07-02 12:55:21 -0700 | [diff] [blame] | 266 | iter.next(); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 267 | } |
| 268 | |
bsalomon | 0b5b6b2 | 2015-10-14 08:31:34 -0700 | [diff] [blame] | 269 | *resultFP = nullptr; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 270 | if (fps.count()) { |
| 271 | *resultFP = GrFragmentProcessor::RunInSeries(fps.begin(), fps.count()); |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 272 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 273 | return true; |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 274 | } |
| 275 | |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 276 | //////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 277 | // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 278 | // scissor, or entirely software |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 279 | bool GrClipStackClip::apply(GrContext* context, GrDrawContext* drawContext, bool useHWAA, |
| 280 | bool hasUserStencilSettings, GrAppliedClip* out) const { |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 281 | if (!fStack || fStack->isWideOpen()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 282 | return true; |
joshualitt | 7a6184f | 2014-10-29 18:29:27 -0700 | [diff] [blame] | 283 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 284 | |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 285 | SkRect devBounds = SkRect::MakeIWH(drawContext->width(), drawContext->height()); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 286 | if (!devBounds.intersect(out->clippedDrawBounds())) { |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 287 | return false; |
| 288 | } |
| 289 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 290 | const SkScalar clipX = SkIntToScalar(fOrigin.x()), |
| 291 | clipY = SkIntToScalar(fOrigin.y()); |
csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 292 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 293 | SkRect clipSpaceDevBounds = devBounds.makeOffset(clipX, clipY); |
| 294 | const GrReducedClip reducedClip(*fStack, clipSpaceDevBounds); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 295 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 296 | if (reducedClip.hasIBounds() && |
| 297 | !GrClip::IsInsideClip(reducedClip.ibounds(), clipSpaceDevBounds)) { |
| 298 | SkIRect scissorSpaceIBounds(reducedClip.ibounds()); |
| 299 | scissorSpaceIBounds.offset(-fOrigin); |
| 300 | out->addScissor(scissorSpaceIBounds); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 301 | } |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 302 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 303 | if (reducedClip.elements().isEmpty()) { |
| 304 | return InitialState::kAllIn == reducedClip.initialState(); |
| 305 | } |
| 306 | |
| 307 | SkASSERT(reducedClip.hasIBounds()); |
| 308 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 309 | // Attempt to implement difference clip rects with window rectangles. This will eventually |
| 310 | // become more comprehensive. |
| 311 | if (drawContext->accessRenderTarget()->renderTargetPriv().supportsWindowRectangles() && |
| 312 | 1 == reducedClip.elements().count() && !reducedClip.requiresAA() && |
| 313 | InitialState::kAllIn == reducedClip.initialState()) { |
| 314 | const Element* element = reducedClip.elements().head(); |
| 315 | SkRegion::Op op = element->getOp(); |
| 316 | if (Element::kRect_Type == element->getType() && |
| 317 | (SkRegion::kDifference_Op == op || SkRegion::kXOR_Op == op)) { |
| 318 | SkIRect window; |
| 319 | element->getRect().round(&window); |
| 320 | window.offset(-fOrigin); |
| 321 | out->addWindowRectangle(window); |
| 322 | return true; |
| 323 | } |
| 324 | } |
| 325 | |
commit-bot@chromium.org | e5a041c | 2014-03-07 19:43:43 +0000 | [diff] [blame] | 326 | // An element count of 4 was chosen because of the common pattern in Blink of: |
| 327 | // isect RR |
| 328 | // diff RR |
| 329 | // isect convex_poly |
| 330 | // isect convex_poly |
| 331 | // when drawing rounded div borders. This could probably be tuned based on a |
| 332 | // configuration's relative costs of switching RTs to generate a mask vs |
| 333 | // longer shaders. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 334 | if (reducedClip.elements().count() <= kMaxAnalyticElements) { |
cdalton | ede7574 | 2015-11-11 15:27:57 -0800 | [diff] [blame] | 335 | // When there are multiple samples we want to do per-sample clipping, not compute a |
| 336 | // fractional pixel coverage. |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 337 | bool disallowAnalyticAA = drawContext->isStencilBufferMultisampled(); |
| 338 | if (disallowAnalyticAA && !drawContext->numColorSamples()) { |
cdalton | 3ccf2e7 | 2016-05-06 09:41:16 -0700 | [diff] [blame] | 339 | // With a single color sample, any coverage info is lost from color once it hits the |
| 340 | // color buffer anyway, so we may as well use coverage AA if nothing else in the pipe |
| 341 | // is multisampled. |
robertphillips | 59cf61a | 2016-07-13 09:18:21 -0700 | [diff] [blame] | 342 | disallowAnalyticAA = useHWAA || hasUserStencilSettings; |
cdalton | 3ccf2e7 | 2016-05-06 09:41:16 -0700 | [diff] [blame] | 343 | } |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 344 | sk_sp<GrFragmentProcessor> clipFP; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 345 | if (reducedClip.requiresAA() && |
| 346 | get_analytic_clip_processor(reducedClip.elements(), disallowAnalyticAA, |
| 347 | {-clipX, -clipY}, devBounds, &clipFP)) { |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 348 | out->addCoverageFP(std::move(clipFP)); |
commit-bot@chromium.org | 65ee5f4 | 2014-02-04 17:49:48 +0000 | [diff] [blame] | 349 | return true; |
| 350 | } |
| 351 | } |
bsalomon@google.com | d3066bd | 2014-02-03 20:09:56 +0000 | [diff] [blame] | 352 | |
cdalton | ede7574 | 2015-11-11 15:27:57 -0800 | [diff] [blame] | 353 | // If the stencil buffer is multisampled we can use it to do everything. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 354 | if (!drawContext->isStencilBufferMultisampled() && reducedClip.requiresAA()) { |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 355 | sk_sp<GrTexture> result; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 356 | if (UseSWOnlyPath(context, hasUserStencilSettings, drawContext, reducedClip)) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 357 | // The clip geometry is complex enough that it will be more efficient to create it |
| 358 | // entirely in software |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 359 | result = CreateSoftwareClipMask(context->textureProvider(), reducedClip); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 360 | } else { |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 361 | result = CreateAlphaClipMask(context, reducedClip); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 362 | // If createAlphaClipMask fails it means UseSWOnlyPath has a bug |
robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 363 | SkASSERT(result); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 364 | } |
| 365 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 366 | if (result) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 367 | // The mask's top left coord should be pinned to the rounded-out top left corner of |
| 368 | // clipSpace bounds. We determine the mask's position WRT to the render target here. |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 369 | SkIRect rtSpaceMaskBounds = reducedClip.ibounds(); |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 370 | rtSpaceMaskBounds.offset(-fOrigin); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 371 | out->addCoverageFP(create_fp_for_mask(result.get(), rtSpaceMaskBounds)); |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 372 | return true; |
| 373 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 374 | // 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] | 375 | } |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 376 | |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 377 | // use the stencil clip if we can't represent the clip as a rectangle. |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 378 | // TODO: these need to be swapped over to using a StencilAttachmentProxy |
| 379 | GrStencilAttachment* stencilAttachment = |
| 380 | context->resourceProvider()->attachStencilAttachment(drawContext->accessRenderTarget()); |
| 381 | if (nullptr == stencilAttachment) { |
| 382 | SkDebugf("WARNING: failed to attach stencil buffer for clip mask. Clip will be ignored.\n"); |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | if (stencilAttachment->mustRenderClip(reducedClip.elementsGenID(), reducedClip.ibounds(), |
| 387 | fOrigin)) { |
| 388 | reducedClip.drawStencilClipMask(context, drawContext, fOrigin); |
| 389 | stencilAttachment->setLastClip(reducedClip.elementsGenID(), reducedClip.ibounds(), |
| 390 | fOrigin); |
| 391 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 392 | out->addStencilClip(); |
robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 393 | return true; |
| 394 | } |
| 395 | |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 396 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 397 | // Create a 8-bit clip mask in alpha |
| 398 | |
| 399 | static void GetClipMaskKey(int32_t clipGenID, const SkIRect& bounds, GrUniqueKey* key) { |
| 400 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 401 | GrUniqueKey::Builder builder(key, kDomain, 3); |
| 402 | builder[0] = clipGenID; |
| 403 | builder[1] = SkToU16(bounds.fLeft) | (SkToU16(bounds.fRight) << 16); |
| 404 | builder[2] = SkToU16(bounds.fTop) | (SkToU16(bounds.fBottom) << 16); |
| 405 | } |
| 406 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 407 | sk_sp<GrTexture> GrClipStackClip::CreateAlphaClipMask(GrContext* context, |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 408 | const GrReducedClip& reducedClip) { |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 409 | GrResourceProvider* resourceProvider = context->resourceProvider(); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 410 | GrUniqueKey key; |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 411 | GetClipMaskKey(reducedClip.elementsGenID(), reducedClip.ibounds(), &key); |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 412 | if (GrTexture* texture = resourceProvider->findAndRefTextureByUniqueKey(key)) { |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 413 | return sk_sp<GrTexture>(texture); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 414 | } |
| 415 | |
robertphillips | 544b9aa | 2015-10-28 11:01:41 -0700 | [diff] [blame] | 416 | // There's no texture in the cache. Let's try to allocate it then. |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 417 | GrPixelConfig config = kRGBA_8888_GrPixelConfig; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 418 | if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 419 | config = kAlpha_8_GrPixelConfig; |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 420 | } |
| 421 | |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 422 | sk_sp<GrDrawContext> dc(context->makeDrawContext(SkBackingFit::kApprox, |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 423 | reducedClip.width(), |
| 424 | reducedClip.height(), |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 425 | config, nullptr)); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 426 | if (!dc) { |
| 427 | return nullptr; |
| 428 | } |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 429 | |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 430 | if (!reducedClip.drawAlphaClipMask(dc.get())) { |
| 431 | return nullptr; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 432 | } |
| 433 | |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 434 | sk_sp<GrTexture> texture(dc->asTexture()); |
| 435 | SkASSERT(texture); |
| 436 | texture->resourcePriv().setUniqueKey(key); |
| 437 | return texture; |
robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 438 | } |
| 439 | |
csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 440 | sk_sp<GrTexture> GrClipStackClip::CreateSoftwareClipMask(GrTextureProvider* texProvider, |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 441 | const GrReducedClip& reducedClip) { |
bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 442 | GrUniqueKey key; |
csmartdalton | 8d3f92a | 2016-08-17 09:39:38 -0700 | [diff] [blame] | 443 | GetClipMaskKey(reducedClip.elementsGenID(), reducedClip.ibounds(), &key); |
robertphillips | 0152d73 | 2016-05-20 06:38:43 -0700 | [diff] [blame] | 444 | if (GrTexture* texture = texProvider->findAndRefTextureByUniqueKey(key)) { |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 445 | return sk_sp<GrTexture>(texture); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 446 | } |
| 447 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 448 | // The mask texture may be larger than necessary. We round out the clip space bounds and pin |
| 449 | // the top left corner of the resulting rect to the top left of the texture. |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 450 | SkIRect maskSpaceIBounds = SkIRect::MakeWH(reducedClip.width(), reducedClip.height()); |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 451 | |
robertphillips | 0152d73 | 2016-05-20 06:38:43 -0700 | [diff] [blame] | 452 | GrSWMaskHelper helper(texProvider); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 453 | |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 454 | // Set the matrix so that rendered clip elements are transformed to mask space from clip |
| 455 | // space. |
| 456 | SkMatrix translate; |
csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame^] | 457 | translate.setTranslate(SkIntToScalar(-reducedClip.left()), SkIntToScalar(-reducedClip.top())); |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 458 | |
robertphillips | 9837740 | 2016-05-13 05:47:23 -0700 | [diff] [blame] | 459 | helper.init(maskSpaceIBounds, &translate); |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 460 | helper.clear(InitialState::kAllIn == reducedClip.initialState() ? 0xFF : 0x00); |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 461 | |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 462 | for (ElementList::Iter iter(reducedClip.elements()); iter.get(); iter.next()) { |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 463 | const Element* element = iter.get(); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 464 | SkRegion::Op op = element->getOp(); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 465 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 466 | if (SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { |
| 467 | // Intersect and reverse difference require modifying pixels outside of the geometry |
| 468 | // that is being "drawn". In both cases we erase all the pixels outside of the geometry |
| 469 | // but leave the pixels inside the geometry alone. For reverse difference we invert all |
| 470 | // the pixels before clearing the ones outside the geometry. |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 471 | if (SkRegion::kReverseDifference_Op == op) { |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 472 | SkRect temp = SkRect::Make(reducedClip.ibounds()); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 473 | // invert the entire scene |
robertphillips | 9837740 | 2016-05-13 05:47:23 -0700 | [diff] [blame] | 474 | helper.drawRect(temp, SkRegion::kXOR_Op, false, 0xFF); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 475 | } |
commit-bot@chromium.org | 5c05639 | 2014-02-17 19:50:02 +0000 | [diff] [blame] | 476 | SkPath clipPath; |
| 477 | element->asPath(&clipPath); |
| 478 | clipPath.toggleInverseFillType(); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 479 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| 480 | helper.drawShape(shape, SkRegion::kReplace_Op, element->isAA(), 0x00); |
robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 481 | continue; |
| 482 | } |
| 483 | |
| 484 | // The other ops (union, xor, diff) only affect pixels inside |
| 485 | // the geometry so they can just be drawn normally |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 486 | if (Element::kRect_Type == element->getType()) { |
robertphillips | 9837740 | 2016-05-13 05:47:23 -0700 | [diff] [blame] | 487 | helper.drawRect(element->getRect(), op, element->isAA(), 0xFF); |
bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 488 | } else { |
commit-bot@chromium.org | 5c05639 | 2014-02-17 19:50:02 +0000 | [diff] [blame] | 489 | SkPath path; |
| 490 | element->asPath(&path); |
bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 491 | GrShape shape(path, GrStyle::SimpleFill()); |
| 492 | helper.drawShape(shape, op, element->isAA(), 0xFF); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
krajcevski | ad1dc58 | 2014-06-10 15:06:47 -0700 | [diff] [blame] | 496 | // Allocate clip mask texture |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 497 | GrSurfaceDesc desc; |
csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 498 | desc.fWidth = reducedClip.width(); |
| 499 | desc.fHeight = reducedClip.height(); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 500 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| 501 | |
robertphillips | 0152d73 | 2016-05-20 06:38:43 -0700 | [diff] [blame] | 502 | sk_sp<GrTexture> result(texProvider->createApproxTexture(desc)); |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 503 | if (!result) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 504 | return nullptr; |
krajcevski | ad1dc58 | 2014-06-10 15:06:47 -0700 | [diff] [blame] | 505 | } |
robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 506 | result->resourcePriv().setUniqueKey(key); |
| 507 | |
robertphillips | c99b8f0 | 2016-05-15 07:53:35 -0700 | [diff] [blame] | 508 | helper.toTexture(result.get()); |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 509 | |
bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 510 | return result; |
robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 511 | } |