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