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