| 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" |
| Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 12 | #include "GrDeferredProxyUploader.h" |
| robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 13 | #include "GrDrawingManager.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" |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 16 | #include "GrRenderTargetContextPriv.h" |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 17 | #include "GrProxyProvider.h" |
| egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 18 | #include "GrStencilAttachment.h" |
| robertphillips@google.com | 58b2021 | 2012-06-27 20:44:52 +0000 | [diff] [blame] | 19 | #include "GrSWMaskHelper.h" |
| Robert Phillips | e305cc1f | 2016-12-14 12:19:05 -0500 | [diff] [blame] | 20 | #include "GrTextureProxy.h" |
| egdaniel | 8d95ffa | 2014-12-08 13:26:43 -0800 | [diff] [blame] | 21 | #include "effects/GrConvexPolyEffect.h" |
| 22 | #include "effects/GrRRectEffect.h" |
| egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | #include "effects/GrTextureDomain.h" |
| Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 24 | #include "SkClipOpPriv.h" |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 25 | #include "SkMakeUnique.h" |
| 26 | #include "SkTaskGroup.h" |
| 27 | #include "SkTraceEvent.h" |
| bsalomon@google.com | c6b3e48 | 2012-12-07 20:43:52 +0000 | [diff] [blame] | 28 | |
| bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 29 | typedef SkClipStack::Element Element; |
| csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 30 | typedef GrReducedClip::InitialState InitialState; |
| csmartdalton | 77f2fae | 2016-08-08 09:55:06 -0700 | [diff] [blame] | 31 | typedef GrReducedClip::ElementList ElementList; |
| bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 32 | |
| Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 33 | const char GrClipStackClip::kMaskTestTag[] = "clip_mask"; |
| robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 34 | |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 35 | bool GrClipStackClip::quickContains(const SkRect& rect) const { |
| reed | 4d2cce4 | 2016-08-22 13:03:47 -0700 | [diff] [blame] | 36 | if (!fStack || fStack->isWideOpen()) { |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 37 | return true; |
| 38 | } |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 39 | return fStack->quickContains(rect); |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 42 | bool GrClipStackClip::quickContains(const SkRRect& rrect) const { |
| reed | 4d2cce4 | 2016-08-22 13:03:47 -0700 | [diff] [blame] | 43 | if (!fStack || fStack->isWideOpen()) { |
| bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 44 | return true; |
| 45 | } |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 46 | return fStack->quickContains(rrect); |
| bsalomon | 7f0d9f3 | 2016-08-15 14:49:10 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 49 | bool GrClipStackClip::isRRect(const SkRect& origRTBounds, SkRRect* rr, GrAA* aa) const { |
| bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 50 | if (!fStack) { |
| 51 | return false; |
| 52 | } |
| 53 | const SkRect* rtBounds = &origRTBounds; |
| Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 54 | bool isAA; |
| 55 | if (fStack->isRRect(*rtBounds, rr, &isAA)) { |
| Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 56 | *aa = GrAA(isAA); |
| bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 57 | return true; |
| 58 | } |
| 59 | return false; |
| 60 | } |
| 61 | |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 62 | void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 63 | bool* isIntersectionOfRects) const { |
| 64 | if (!fStack) { |
| 65 | devResult->setXYWH(0, 0, width, height); |
| 66 | if (isIntersectionOfRects) { |
| 67 | *isIntersectionOfRects = true; |
| 68 | } |
| 69 | return; |
| 70 | } |
| 71 | SkRect devBounds; |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 72 | fStack->getConservativeBounds(0, 0, width, height, &devBounds, isIntersectionOfRects); |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 73 | devBounds.roundOut(devResult); |
| 74 | } |
| 75 | |
| bsalomon@google.com | 51a6286 | 2012-11-26 21:19:43 +0000 | [diff] [blame] | 76 | //////////////////////////////////////////////////////////////////////////////// |
| Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 77 | // set up the draw state to enable the aa clipping mask. |
| Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 78 | static std::unique_ptr<GrFragmentProcessor> create_fp_for_mask(sk_sp<GrTextureProxy> mask, |
| 79 | const SkIRect& devBound) { |
| bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 80 | SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height()); |
| Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 81 | return GrDeviceSpaceTextureDecalFragmentProcessor::Make(std::move(mask), domainTexels, |
| Brian Salomon | 2ebd0c8 | 2016-10-03 17:15:28 -0400 | [diff] [blame] | 82 | {devBound.fLeft, devBound.fTop}); |
| robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 85 | // Does the path in 'element' require SW rendering? If so, return true (and, |
| 86 | // optionally, set 'prOut' to NULL. If not, return false (and, optionally, set |
| 87 | // 'prOut' to the non-SW path renderer that will do the job). |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 88 | bool GrClipStackClip::PathNeedsSWRenderer(GrContext* context, |
| Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 89 | const SkIRect& scissorRect, |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 90 | bool hasUserStencilSettings, |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 91 | const GrRenderTargetContext* renderTargetContext, |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 92 | const SkMatrix& viewMatrix, |
| 93 | const Element* element, |
| 94 | GrPathRenderer** prOut, |
| 95 | bool needsStencil) { |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 96 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 97 | // rects can always be drawn directly w/o using the software path |
| 98 | // TODO: skip rrects once we're drawing them directly. |
| 99 | if (prOut) { |
| 100 | *prOut = nullptr; |
| 101 | } |
| 102 | return false; |
| 103 | } else { |
| 104 | // We shouldn't get here with an empty clip element. |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 105 | SkASSERT(Element::DeviceSpaceType::kEmpty != element->getDeviceSpaceType()); |
| robertphillips | 5c3ea4c | 2015-10-26 08:33:10 -0700 | [diff] [blame] | 106 | |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 107 | // the gpu alpha mask will draw the inverse paths as non-inverse to a temp buffer |
| 108 | SkPath path; |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 109 | element->asDeviceSpacePath(&path); |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 110 | if (path.isInverseFillType()) { |
| 111 | path.toggleInverseFillType(); |
| 112 | } |
| halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 113 | |
| Brian Salomon | 82125e9 | 2016-12-10 09:35:48 -0500 | [diff] [blame] | 114 | GrPathRendererChain::DrawType type = |
| 115 | needsStencil ? GrPathRendererChain::DrawType::kStencilAndColor |
| 116 | : GrPathRendererChain::DrawType::kColor; |
| halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 117 | |
| bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 118 | GrShape shape(path, GrStyle::SimpleFill()); |
| robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 119 | GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 120 | canDrawArgs.fCaps = context->caps(); |
| Chris Dalton | db91c6e | 2017-09-08 16:25:08 -0600 | [diff] [blame] | 121 | canDrawArgs.fClipConservativeBounds = &scissorRect; |
| robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 122 | canDrawArgs.fViewMatrix = &viewMatrix; |
| bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 123 | canDrawArgs.fShape = &shape; |
| Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 124 | canDrawArgs.fAAType = GrChooseAAType(GrAA(element->isAA()), |
| Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 125 | renderTargetContext->fsaaType(), |
| Brian Salomon | e225b56 | 2017-06-14 13:00:03 -0400 | [diff] [blame] | 126 | GrAllowMixedSamples::kYes, |
| 127 | *context->caps()); |
| cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 128 | canDrawArgs.fHasUserStencilSettings = hasUserStencilSettings; |
| robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 129 | |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 130 | // the 'false' parameter disallows use of the SW path renderer |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 131 | GrPathRenderer* pr = |
| 132 | context->contextPriv().drawingManager()->getPathRenderer(canDrawArgs, false, type); |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 133 | if (prOut) { |
| 134 | *prOut = pr; |
| 135 | } |
| 136 | return SkToBool(!pr); |
| 137 | } |
| robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 138 | } |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 139 | |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 140 | /* |
| 141 | * This method traverses the clip stack to see if the GrSoftwarePathRenderer |
| 142 | * will be used on any element. If so, it returns true to indicate that the |
| 143 | * entire clip should be rendered in SW and then uploaded en masse to the gpu. |
| 144 | */ |
| csmartdalton | c6f411e | 2016-08-05 22:32:12 -0700 | [diff] [blame] | 145 | bool GrClipStackClip::UseSWOnlyPath(GrContext* context, |
| 146 | bool hasUserStencilSettings, |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 147 | const GrRenderTargetContext* renderTargetContext, |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 148 | const GrReducedClip& reducedClip) { |
| robertphillips@google.com | 8a4fc40 | 2012-05-24 12:42:24 +0000 | [diff] [blame] | 149 | // TODO: generalize this function so that when |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 150 | // a clip gets complex enough it can just be done in SW regardless |
| 151 | // of whether it would invoke the GrSoftwarePathRenderer. |
| skia.committer@gmail.com | d21444a | 2012-12-07 02:01:25 +0000 | [diff] [blame] | 152 | |
| Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 153 | // If we're avoiding stencils, always use SW: |
| 154 | if (context->caps()->avoidStencilBuffers()) |
| 155 | return true; |
| 156 | |
| joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 157 | // Set the matrix so that rendered clip elements are transformed to mask space from clip |
| 158 | // space. |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 159 | SkMatrix translate; |
| 160 | translate.setTranslate(SkIntToScalar(-reducedClip.left()), SkIntToScalar(-reducedClip.top())); |
| joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 161 | |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 162 | for (ElementList::Iter iter(reducedClip.maskElements()); iter.get(); iter.next()) { |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 163 | const Element* element = iter.get(); |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 164 | |
| Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 165 | SkClipOp op = element->getOp(); |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 166 | bool invert = element->isInverseFilled(); |
| halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 167 | bool needsStencil = invert || |
| Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 168 | kIntersect_SkClipOp == op || kReverseDifference_SkClipOp == op; |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 169 | |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 170 | if (PathNeedsSWRenderer(context, reducedClip.scissor(), hasUserStencilSettings, |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 171 | renderTargetContext, translate, element, nullptr, needsStencil)) { |
| robertphillips | 3f7357f | 2015-10-27 07:17:33 -0700 | [diff] [blame] | 172 | return true; |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 173 | } |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 174 | } |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 175 | return false; |
| robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 178 | //////////////////////////////////////////////////////////////////////////////// |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 179 | // sort out what kind of clip mask needs to be created: alpha, stencil, |
| 180 | // scissor, or entirely software |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 181 | bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTargetContext, |
| Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 182 | bool useHWAA, bool hasUserStencilSettings, GrAppliedClip* out, |
| 183 | SkRect* bounds) const { |
| Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 184 | SkRect devBounds = SkRect::MakeIWH(renderTargetContext->width(), renderTargetContext->height()); |
| 185 | if (!devBounds.intersect(*bounds)) { |
| csmartdalton | cbecb08 | 2016-07-22 08:59:08 -0700 | [diff] [blame] | 186 | return false; |
| 187 | } |
| 188 | |
| Brian Salomon | 510dd42 | 2017-03-16 12:15:22 -0400 | [diff] [blame] | 189 | if (!fStack || fStack->isWideOpen()) { |
| 190 | return true; |
| 191 | } |
| 192 | |
| Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 193 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 194 | const auto* caps = context->caps()->shaderCaps(); |
| 195 | int maxWindowRectangles = renderTargetContext->priv().maxWindowRectangles(); |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 196 | int maxAnalyticFPs = context->caps()->maxClipAnalyticFPs(); |
| 197 | if (GrFSAAType::kNone != renderTargetContext->fsaaType()) { |
| 198 | // With mixed samples (non-msaa color buffer), any coverage info is lost from color once it |
| 199 | // hits the color buffer anyway, so we may as well use coverage AA if nothing else in the |
| 200 | // pipe is multisampled. |
| Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 201 | if (renderTargetContext->numColorSamples() > 1 || useHWAA || hasUserStencilSettings) { |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 202 | maxAnalyticFPs = 0; |
| 203 | } |
| 204 | SkASSERT(!context->caps()->avoidStencilBuffers()); // We disable MSAA when avoiding stencil. |
| 205 | } |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 206 | auto* ccpr = context->contextPriv().drawingManager()->getCoverageCountingPathRenderer(); |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 207 | |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 208 | GrReducedClip reducedClip(*fStack, devBounds, caps, maxWindowRectangles, maxAnalyticFPs, ccpr); |
| 209 | if (InitialState::kAllOut == reducedClip.initialState() && |
| 210 | reducedClip.maskElements().isEmpty()) { |
| 211 | return false; |
| 212 | } |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 213 | |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 214 | if (reducedClip.hasScissor() && !GrClip::IsInsideClip(reducedClip.scissor(), devBounds)) { |
| Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 215 | out->hardClip().addScissor(reducedClip.scissor(), bounds); |
| cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 216 | } |
| cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 217 | |
| csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 218 | if (!reducedClip.windowRectangles().empty()) { |
| Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 219 | out->hardClip().addWindowRectangles(reducedClip.windowRectangles(), |
| 220 | GrWindowRectsState::Mode::kExclusive); |
| csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 223 | if (!reducedClip.maskElements().isEmpty()) { |
| 224 | if (!this->applyClipMask(context, renderTargetContext, reducedClip, hasUserStencilSettings, |
| 225 | out)) { |
| 226 | return false; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // The opList ID must not be looked up until AFTER producing the clip mask (if any). That step |
| 231 | // can cause a flush or otherwise change which opList our draw is going into. |
| 232 | uint32_t opListID = renderTargetContext->getOpList()->uniqueID(); |
| 233 | int rtWidth = renderTargetContext->width(), rtHeight = renderTargetContext->height(); |
| Robert Phillips | 777707b | 2018-01-17 11:40:14 -0500 | [diff] [blame] | 234 | if (auto clipFPs = reducedClip.finishAndDetachAnalyticFPs(proxyProvider, opListID, |
| 235 | rtWidth, rtHeight)) { |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 236 | out->addCoverageFP(std::move(clipFPs)); |
| 237 | } |
| 238 | |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 239 | return true; |
| 240 | } |
| csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 241 | |
| Chris Dalton | a32a3c3 | 2017-12-05 10:05:21 -0700 | [diff] [blame] | 242 | bool GrClipStackClip::applyClipMask(GrContext* context, GrRenderTargetContext* renderTargetContext, |
| 243 | const GrReducedClip& reducedClip, bool hasUserStencilSettings, |
| 244 | GrAppliedClip* out) const { |
| csmartdalton | 3affdc1 | 2016-10-28 12:01:10 -0700 | [diff] [blame] | 245 | #ifdef SK_DEBUG |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 246 | SkASSERT(reducedClip.hasScissor()); |
| Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 247 | SkIRect rtIBounds = SkIRect::MakeWH(renderTargetContext->width(), |
| 248 | renderTargetContext->height()); |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 249 | const SkIRect& scissor = reducedClip.scissor(); |
| 250 | SkASSERT(rtIBounds.contains(scissor)); // Mask shouldn't be larger than the RT. |
| csmartdalton | 3affdc1 | 2016-10-28 12:01:10 -0700 | [diff] [blame] | 251 | #endif |
| csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 252 | |
| cdalton | ede7574 | 2015-11-11 15:27:57 -0800 | [diff] [blame] | 253 | // If the stencil buffer is multisampled we can use it to do everything. |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 254 | if ((GrFSAAType::kNone == renderTargetContext->fsaaType() && reducedClip.maskRequiresAA()) || |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 255 | context->caps()->avoidStencilBuffers()) { |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 256 | sk_sp<GrTextureProxy> result; |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 257 | if (UseSWOnlyPath(context, hasUserStencilSettings, renderTargetContext, reducedClip)) { |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 258 | // The clip geometry is complex enough that it will be more efficient to create it |
| 259 | // entirely in software |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 260 | result = this->createSoftwareClipMask(context, reducedClip, renderTargetContext); |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 261 | } else { |
| Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 262 | result = this->createAlphaClipMask(context, reducedClip); |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 265 | if (result) { |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 266 | // The mask's top left coord should be pinned to the rounded-out top left corner of |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 267 | // the clip's device space bounds. |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 268 | out->addCoverageFP(create_fp_for_mask(std::move(result), reducedClip.scissor())); |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 269 | return true; |
| 270 | } |
| Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 271 | |
| 272 | // If alpha or software clip mask creation fails, fall through to the stencil code paths, |
| 273 | // unless stencils are disallowed. |
| 274 | if (context->caps()->avoidStencilBuffers()) { |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 275 | SkDebugf("WARNING: Clip mask requires stencil, but stencil unavailable. " |
| 276 | "Clip will be ignored.\n"); |
| Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 277 | return false; |
| 278 | } |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 279 | } |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 280 | |
| Robert Phillips | 6504813 | 2017-08-10 08:44:49 -0400 | [diff] [blame] | 281 | renderTargetContext->setNeedsStencil(); |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 282 | |
| csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 283 | // This relies on the property that a reduced sub-rect of the last clip will contain all the |
| 284 | // relevant window rectangles that were in the last clip. This subtle requirement will go away |
| 285 | // after clipping is overhauled. |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 286 | if (renderTargetContext->priv().mustRenderClip(reducedClip.maskGenID(), reducedClip.scissor(), |
| 287 | reducedClip.numAnalyticFPs())) { |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 288 | reducedClip.drawStencilClipMask(context, renderTargetContext); |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 289 | renderTargetContext->priv().setLastClip(reducedClip.maskGenID(), reducedClip.scissor(), |
| 290 | reducedClip.numAnalyticFPs()); |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 291 | } |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 292 | // GrAppliedClip doesn't need to figure numAnalyticFPs into its key (used by operator==) because |
| 293 | // it verifies the FPs are also equal. |
| Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 294 | out->hardClip().addStencilClip(reducedClip.maskGenID()); |
| robertphillips@google.com | 1e945b7 | 2012-04-16 18:03:03 +0000 | [diff] [blame] | 295 | return true; |
| 296 | } |
| 297 | |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 298 | //////////////////////////////////////////////////////////////////////////////// |
| bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 299 | // Create a 8-bit clip mask in alpha |
| 300 | |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 301 | static void create_clip_mask_key(uint32_t clipGenID, const SkIRect& bounds, int numAnalyticFPs, |
| 302 | GrUniqueKey* key) { |
| bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 303 | static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 304 | GrUniqueKey::Builder builder(key, kDomain, 4, GrClipStackClip::kMaskTestTag); |
| bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 305 | builder[0] = clipGenID; |
| csmartdalton | 3affdc1 | 2016-10-28 12:01:10 -0700 | [diff] [blame] | 306 | // SkToS16 because image filters outset layers to a size indicated by the filter, which can |
| Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 307 | // sometimes result in negative coordinates from device space. |
| csmartdalton | 3affdc1 | 2016-10-28 12:01:10 -0700 | [diff] [blame] | 308 | builder[1] = SkToS16(bounds.fLeft) | (SkToS16(bounds.fRight) << 16); |
| 309 | builder[2] = SkToS16(bounds.fTop) | (SkToS16(bounds.fBottom) << 16); |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 310 | builder[3] = numAnalyticFPs; |
| bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 313 | static void add_invalidate_on_pop_message(const SkClipStack& stack, uint32_t clipGenID, |
| Brian Salomon | 19f0ed5 | 2017-01-06 13:54:58 -0500 | [diff] [blame] | 314 | const GrUniqueKey& clipMaskKey) { |
| 315 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 316 | while (const Element* element = iter.prev()) { |
| 317 | if (element->getGenID() == clipGenID) { |
| 318 | std::unique_ptr<GrUniqueKeyInvalidatedMessage> msg( |
| 319 | new GrUniqueKeyInvalidatedMessage(clipMaskKey)); |
| 320 | element->addResourceInvalidationMessage(std::move(msg)); |
| 321 | return; |
| 322 | } |
| 323 | } |
| 324 | SkDEBUGFAIL("Gen ID was not found in stack."); |
| 325 | } |
| 326 | |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 327 | sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context, |
| 328 | const GrReducedClip& reducedClip) const { |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 329 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| bsalomon | 473addf | 2015-10-02 07:49:05 -0700 | [diff] [blame] | 330 | GrUniqueKey key; |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 331 | create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), |
| 332 | reducedClip.numAnalyticFPs(), &key); |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 333 | |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 334 | sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey( |
| Robert Phillips | 066f020 | 2017-07-25 10:16:35 -0400 | [diff] [blame] | 335 | key, kBottomLeft_GrSurfaceOrigin)); |
| Robert Phillips | d374948 | 2017-03-14 09:17:43 -0400 | [diff] [blame] | 336 | if (proxy) { |
| 337 | return proxy; |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 340 | sk_sp<GrRenderTargetContext> rtc(context->makeDeferredRenderTargetContextWithFallback( |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 341 | SkBackingFit::kApprox, |
| 342 | reducedClip.width(), |
| 343 | reducedClip.height(), |
| 344 | kAlpha_8_GrPixelConfig, |
| 345 | nullptr)); |
| 346 | if (!rtc) { |
| robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 347 | return nullptr; |
| 348 | } |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 349 | |
| Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 350 | if (!reducedClip.drawAlphaClipMask(rtc.get())) { |
| csmartdalton | bde96c6 | 2016-08-31 12:54:46 -0700 | [diff] [blame] | 351 | return nullptr; |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 354 | sk_sp<GrTextureProxy> result(rtc->asTextureProxyRef()); |
| 355 | if (!result) { |
| Robert Phillips | e60ad62 | 2016-11-17 10:22:48 -0500 | [diff] [blame] | 356 | return nullptr; |
| 357 | } |
| 358 | |
| Robert Phillips | 019ff27 | 2017-07-24 14:47:57 -0400 | [diff] [blame] | 359 | SkASSERT(result->origin() == kBottomLeft_GrSurfaceOrigin); |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 360 | proxyProvider->assignUniqueKeyToProxy(key, result.get()); |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 361 | add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key); |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 362 | |
| 363 | return result; |
| robertphillips@google.com | f294b77 | 2012-04-27 14:29:26 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 366 | namespace { |
| Robert Phillips | 875218e | 2017-02-24 08:37:13 -0500 | [diff] [blame] | 367 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 368 | /** |
| Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 369 | * Payload class for use with GrTDeferredProxyUploader. The clip mask code renders multiple |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 370 | * elements, each storing their own AA setting (and already transformed into device space). This |
| 371 | * stores all of the information needed by the worker thread to draw all clip elements (see below, |
| 372 | * in createSoftwareClipMask). |
| 373 | */ |
| 374 | class ClipMaskData { |
| 375 | public: |
| 376 | ClipMaskData(const GrReducedClip& reducedClip) |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 377 | : fScissor(reducedClip.scissor()) |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 378 | , fInitialState(reducedClip.initialState()) { |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 379 | for (ElementList::Iter iter(reducedClip.maskElements()); iter.get(); iter.next()) { |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 380 | fElements.addToTail(*iter.get()); |
| 381 | } |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 384 | const SkIRect& scissor() const { return fScissor; } |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 385 | InitialState initialState() const { return fInitialState; } |
| 386 | const ElementList& elements() const { return fElements; } |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 387 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 388 | private: |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 389 | SkIRect fScissor; |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 390 | InitialState fInitialState; |
| 391 | ElementList fElements; |
| 392 | }; |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 393 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void draw_clip_elements_to_mask_helper(GrSWMaskHelper& helper, const ElementList& elements, |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 397 | const SkIRect& scissor, InitialState initialState) { |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 398 | // Set the matrix so that rendered clip elements are transformed to mask space from clip space. |
| joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 399 | SkMatrix translate; |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 400 | translate.setTranslate(SkIntToScalar(-scissor.left()), SkIntToScalar(-scissor.top())); |
| joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 401 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 402 | helper.clear(InitialState::kAllIn == initialState ? 0xFF : 0x00); |
| sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 403 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 404 | for (ElementList::Iter iter(elements); iter.get(); iter.next()) { |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 405 | const Element* element = iter.get(); |
| Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 406 | SkClipOp op = element->getOp(); |
| Chris Dalton | 3b51df1 | 2017-11-27 14:33:06 -0700 | [diff] [blame] | 407 | GrAA aa = GrAA(element->isAA()); |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 408 | |
| Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 409 | if (kIntersect_SkClipOp == op || kReverseDifference_SkClipOp == op) { |
| bsalomon@google.com | 4c2443e | 2012-12-06 20:58:57 +0000 | [diff] [blame] | 410 | // Intersect and reverse difference require modifying pixels outside of the geometry |
| 411 | // that is being "drawn". In both cases we erase all the pixels outside of the geometry |
| 412 | // but leave the pixels inside the geometry alone. For reverse difference we invert all |
| 413 | // the pixels before clearing the ones outside the geometry. |
| Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 414 | if (kReverseDifference_SkClipOp == op) { |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 415 | SkRect temp = SkRect::Make(scissor); |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 416 | // invert the entire scene |
| Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 417 | helper.drawRect(temp, translate, SkRegion::kXOR_Op, GrAA::kNo, 0xFF); |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 418 | } |
| commit-bot@chromium.org | 5c05639 | 2014-02-17 19:50:02 +0000 | [diff] [blame] | 419 | SkPath clipPath; |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 420 | element->asDeviceSpacePath(&clipPath); |
| commit-bot@chromium.org | 5c05639 | 2014-02-17 19:50:02 +0000 | [diff] [blame] | 421 | clipPath.toggleInverseFillType(); |
| bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 422 | GrShape shape(clipPath, GrStyle::SimpleFill()); |
| Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 423 | helper.drawShape(shape, translate, SkRegion::kReplace_Op, aa, 0x00); |
| robertphillips@google.com | fa66294 | 2012-05-17 12:20:22 +0000 | [diff] [blame] | 424 | continue; |
| 425 | } |
| 426 | |
| 427 | // The other ops (union, xor, diff) only affect pixels inside |
| 428 | // the geometry so they can just be drawn normally |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 429 | if (Element::DeviceSpaceType::kRect == element->getDeviceSpaceType()) { |
| Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 430 | helper.drawRect(element->getDeviceSpaceRect(), translate, (SkRegion::Op)op, aa, 0xFF); |
| bsalomon@google.com | 8182fa0 | 2012-12-04 14:06:06 +0000 | [diff] [blame] | 431 | } else { |
| commit-bot@chromium.org | 5c05639 | 2014-02-17 19:50:02 +0000 | [diff] [blame] | 432 | SkPath path; |
| Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 433 | element->asDeviceSpacePath(&path); |
| bsalomon | 8acedde | 2016-06-24 10:42:16 -0700 | [diff] [blame] | 434 | GrShape shape(path, GrStyle::SimpleFill()); |
| Brian Salomon | 7407756 | 2017-08-30 13:55:35 -0400 | [diff] [blame] | 435 | helper.drawShape(shape, translate, (SkRegion::Op)op, aa, 0xFF); |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 438 | } |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 439 | |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 440 | sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask( |
| 441 | GrContext* context, const GrReducedClip& reducedClip, |
| 442 | GrRenderTargetContext* renderTargetContext) const { |
| 443 | GrUniqueKey key; |
| Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 444 | create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(), |
| 445 | reducedClip.numAnalyticFPs(), &key); |
| robertphillips | 391395d | 2016-03-02 09:26:36 -0800 | [diff] [blame] | 446 | |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 447 | GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); |
| 448 | |
| 449 | sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey( |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 450 | key, kTopLeft_GrSurfaceOrigin)); |
| 451 | if (proxy) { |
| 452 | return proxy; |
| 453 | } |
| 454 | |
| 455 | // The mask texture may be larger than necessary. We round out the clip bounds and pin the top |
| 456 | // left corner of the resulting rect to the top left of the texture. |
| 457 | SkIRect maskSpaceIBounds = SkIRect::MakeWH(reducedClip.width(), reducedClip.height()); |
| 458 | |
| 459 | SkTaskGroup* taskGroup = context->contextPriv().getTaskGroup(); |
| 460 | if (taskGroup && renderTargetContext) { |
| 461 | // Create our texture proxy |
| 462 | GrSurfaceDesc desc; |
| 463 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 464 | desc.fWidth = maskSpaceIBounds.width(); |
| 465 | desc.fHeight = maskSpaceIBounds.height(); |
| 466 | desc.fConfig = kAlpha_8_GrPixelConfig; |
| Brian Osman | d140fe9 | 2017-10-03 12:17:26 -0400 | [diff] [blame] | 467 | // MDB TODO: We're going to fill this proxy with an ASAP upload (which is out of order wrt |
| 468 | // to ops), so it can't have any pending IO. |
| Robert Phillips | 0bd24dc | 2018-01-16 08:06:32 -0500 | [diff] [blame] | 469 | proxy = proxyProvider->createProxy(desc, SkBackingFit::kApprox, SkBudgeted::kYes, |
| 470 | GrResourceProvider::kNoPendingIO_Flag); |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 471 | |
| Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 472 | auto uploader = skstd::make_unique<GrTDeferredProxyUploader<ClipMaskData>>(reducedClip); |
| 473 | GrTDeferredProxyUploader<ClipMaskData>* uploaderRaw = uploader.get(); |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 474 | auto drawAndUploadMask = [uploaderRaw, maskSpaceIBounds] { |
| 475 | TRACE_EVENT0("skia", "Threaded SW Clip Mask Render"); |
| 476 | GrSWMaskHelper helper(uploaderRaw->getPixels()); |
| 477 | if (helper.init(maskSpaceIBounds)) { |
| 478 | draw_clip_elements_to_mask_helper(helper, uploaderRaw->data().elements(), |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 479 | uploaderRaw->data().scissor(), |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 480 | uploaderRaw->data().initialState()); |
| 481 | } else { |
| 482 | SkDEBUGFAIL("Unable to allocate SW clip mask."); |
| 483 | } |
| Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 484 | uploaderRaw->signalAndFreeData(); |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | taskGroup->add(std::move(drawAndUploadMask)); |
| Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 488 | proxy->texPriv().setDeferredUploader(std::move(uploader)); |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 489 | } else { |
| 490 | GrSWMaskHelper helper; |
| 491 | if (!helper.init(maskSpaceIBounds)) { |
| 492 | return nullptr; |
| 493 | } |
| 494 | |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 495 | draw_clip_elements_to_mask_helper(helper, reducedClip.maskElements(), reducedClip.scissor(), |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 496 | reducedClip.initialState()); |
| 497 | |
| 498 | proxy = helper.toTextureProxy(context, SkBackingFit::kApprox); |
| 499 | } |
| 500 | |
| 501 | SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); |
| Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 502 | proxyProvider->assignUniqueKeyToProxy(key, proxy.get()); |
| Chris Dalton | 7947193 | 2017-10-27 01:50:57 -0600 | [diff] [blame] | 503 | add_invalidate_on_pop_message(*fStack, reducedClip.maskGenID(), key); |
| Brian Osman | 5d03474 | 2017-09-11 13:38:55 -0400 | [diff] [blame] | 504 | return proxy; |
| robertphillips@google.com | 6b70a7b | 2012-05-11 15:32:48 +0000 | [diff] [blame] | 505 | } |