csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 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 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 10 | #include "SkClipStack.h" |
| 11 | #include "SkRRect.h" |
| 12 | |
| 13 | #if SK_SUPPORT_GPU |
| 14 | # include "GrAppliedClip.h" |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 15 | # include "GrStencilClip.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 16 | # include "GrReducedClip.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 17 | # include "GrRenderTargetContext.h" |
| 18 | # include "GrRenderTargetContextPriv.h" |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 19 | # include "GrResourceProvider.h" |
| 20 | # include "effects/GrTextureDomain.h" |
| 21 | #endif |
| 22 | |
| 23 | constexpr static SkIRect kDeviceRect = {0, 0, 600, 600}; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 24 | constexpr static SkIRect kCoverRect = {50, 50, 550, 550}; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 25 | |
| 26 | namespace skiagm { |
| 27 | |
| 28 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | class WindowRectanglesBaseGM : public GM { |
| 31 | protected: |
| 32 | virtual void onCoverClipStack(const SkClipStack&, SkCanvas*) = 0; |
| 33 | |
| 34 | private: |
| 35 | SkISize onISize() override { return SkISize::Make(kDeviceRect.width(), kDeviceRect.height()); } |
| 36 | void onDraw(SkCanvas*) final; |
| 37 | }; |
| 38 | |
| 39 | void WindowRectanglesBaseGM::onDraw(SkCanvas* canvas) { |
| 40 | sk_tool_utils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6, 25); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 41 | |
| 42 | SkClipStack stack; |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 43 | stack.clipRect(SkRect::MakeXYWH(370.75, 80.25, 149, 100), SkMatrix::I(), |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 44 | kDifference_SkClipOp, false); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 45 | stack.clipRect(SkRect::MakeXYWH(80.25, 420.75, 150, 100), SkMatrix::I(), |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 46 | kDifference_SkClipOp, true); |
Brian Salomon | a3b45d4 | 2016-10-03 11:36:16 -0400 | [diff] [blame] | 47 | stack.clipRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(200, 200, 200, 200), 60, 45), |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 48 | SkMatrix::I(), kDifference_SkClipOp, true); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 49 | |
| 50 | SkRRect nine; |
| 51 | nine.setNinePatch(SkRect::MakeXYWH(550 - 30.25 - 100, 370.75, 100, 150), 12, 35, 23, 20); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 52 | stack.clipRRect(nine, SkMatrix::I(), kDifference_SkClipOp, true); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 53 | |
| 54 | SkRRect complx; |
| 55 | SkVector complxRadii[4] = {{6, 4}, {8, 12}, {16, 24}, {48, 32}}; |
| 56 | complx.setRectRadii(SkRect::MakeXYWH(80.25, 80.75, 100, 149), complxRadii); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 57 | stack.clipRRect(complx, SkMatrix::I(), kDifference_SkClipOp, false); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 58 | |
| 59 | this->onCoverClipStack(stack, canvas); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 63 | |
| 64 | /** |
| 65 | * Draws a clip that will exercise window rectangles if they are supported. |
| 66 | */ |
| 67 | class WindowRectanglesGM : public WindowRectanglesBaseGM { |
| 68 | private: |
| 69 | SkString onShortName() final { return SkString("windowrectangles"); } |
| 70 | void onCoverClipStack(const SkClipStack&, SkCanvas*) final; |
| 71 | }; |
| 72 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 73 | void WindowRectanglesGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) { |
| 74 | SkPaint paint; |
| 75 | paint.setColor(0xff00aa80); |
| 76 | |
| 77 | // Set up the canvas's clip to match our SkClipStack. |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 78 | SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
| 79 | for (const SkClipStack::Element* element = iter.next(); element; element = iter.next()) { |
Mike Reed | 598524d | 2017-03-08 13:13:44 -0500 | [diff] [blame] | 80 | SkClipOp op = element->getOp(); |
| 81 | bool isAA = element->isAA(); |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 82 | switch (element->getDeviceSpaceType()) { |
| 83 | case SkClipStack::Element::DeviceSpaceType::kPath: |
| 84 | canvas->clipPath(element->getDeviceSpacePath(), op, isAA); |
Mike Reed | 598524d | 2017-03-08 13:13:44 -0500 | [diff] [blame] | 85 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 86 | case SkClipStack::Element::DeviceSpaceType::kRRect: |
| 87 | canvas->clipRRect(element->getDeviceSpaceRRect(), op, isAA); |
Mike Reed | 598524d | 2017-03-08 13:13:44 -0500 | [diff] [blame] | 88 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 89 | case SkClipStack::Element::DeviceSpaceType::kRect: |
| 90 | canvas->clipRect(element->getDeviceSpaceRect(), op, isAA); |
Mike Reed | 598524d | 2017-03-08 13:13:44 -0500 | [diff] [blame] | 91 | break; |
Brian Salomon | f3b46e5 | 2017-08-30 11:37:57 -0400 | [diff] [blame] | 92 | case SkClipStack::Element::DeviceSpaceType::kEmpty: |
Mike Reed | 598524d | 2017-03-08 13:13:44 -0500 | [diff] [blame] | 93 | canvas->clipRect({ 0, 0, 0, 0 }, kIntersect_SkClipOp, false); |
| 94 | break; |
| 95 | } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | canvas->drawRect(SkRect::Make(kCoverRect), paint); |
| 99 | } |
| 100 | |
| 101 | DEF_GM( return new WindowRectanglesGM(); ) |
| 102 | |
| 103 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 104 | |
| 105 | #if SK_SUPPORT_GPU |
| 106 | |
mtklein | 0a44107 | 2016-09-06 11:45:31 -0700 | [diff] [blame] | 107 | constexpr static int kNumWindows = 8; |
| 108 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 109 | /** |
| 110 | * Visualizes the mask (alpha or stencil) for a clip with several window rectangles. The purpose of |
| 111 | * this test is to verify that window rectangles are being used during clip mask generation, and to |
| 112 | * visualize where the window rectangles are placed. |
| 113 | * |
| 114 | * We use window rectangles when generating the clip mask because there is no need to invest time |
| 115 | * defining those regions where window rectangles will be in effect during the actual draw anyway. |
| 116 | * |
| 117 | * This test works by filling the entire clip mask with a small checkerboard pattern before drawing |
| 118 | * it, and then covering the mask with a solid color once it has been generated. The regions inside |
| 119 | * window rectangles or outside the scissor should still have the initial checkerboard intact. |
| 120 | */ |
| 121 | class WindowRectanglesMaskGM : public WindowRectanglesBaseGM { |
| 122 | private: |
| 123 | constexpr static int kMaskCheckerSize = 5; |
| 124 | SkString onShortName() final { return SkString("windowrectangles_mask"); } |
| 125 | void onCoverClipStack(const SkClipStack&, SkCanvas*) final; |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 126 | void visualizeAlphaMask(GrContext*, GrRenderTargetContext*, const GrReducedClip&, GrPaint&&); |
| 127 | void visualizeStencilMask(GrContext*, GrRenderTargetContext*, const GrReducedClip&, GrPaint&&); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 128 | void stencilCheckerboard(GrRenderTargetContext*, bool flip); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 129 | void fail(SkCanvas*); |
| 130 | }; |
| 131 | |
| 132 | /** |
| 133 | * Base class for GrClips that visualize a clip mask. |
| 134 | */ |
| 135 | class MaskOnlyClipBase : public GrClip { |
| 136 | private: |
| 137 | bool quickContains(const SkRect&) const final { return false; } |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 138 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; } |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 139 | void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final { |
| 140 | rect->set(0, 0, width, height); |
| 141 | if (iior) { |
| 142 | *iior = false; |
| 143 | } |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | /** |
| 148 | * This class clips a cover by an alpha mask. We use it to visualize the alpha clip mask. |
| 149 | */ |
| 150 | class AlphaOnlyClip final : public MaskOnlyClipBase { |
| 151 | public: |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 152 | AlphaOnlyClip(sk_sp<GrTextureProxy> mask, int x, int y) : fMask(mask), fX(x), fY(y) {} |
| 153 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 154 | private: |
Brian Salomon | 97180af | 2017-03-14 13:42:58 -0400 | [diff] [blame] | 155 | bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out, |
| 156 | SkRect* bounds) const override { |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 157 | int w = fMask->width(); |
| 158 | int h = fMask->height(); |
| 159 | out->addCoverageFP(GrDeviceSpaceTextureDecalFragmentProcessor::Make( |
| 160 | fMask, SkIRect::MakeWH(w, h), {fX, fY})); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 161 | return true; |
| 162 | } |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 163 | sk_sp<GrTextureProxy> fMask; |
| 164 | int fX; |
| 165 | int fY; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | /** |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 169 | * Makes a clip object that enforces the stencil clip bit. Used to visualize the stencil mask. |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 170 | */ |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 171 | static GrStencilClip make_stencil_only_clip() { |
| 172 | return GrStencilClip(SkClipStack::kEmptyGenID); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | void WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) { |
| 176 | GrContext* ctx = canvas->getGrContext(); |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 177 | GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext(); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 178 | |
Robert Phillips | ec2249f | 2016-11-09 08:54:35 -0500 | [diff] [blame] | 179 | if (!ctx || !rtc || rtc->priv().maxWindowRectangles() < kNumWindows) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 180 | this->fail(canvas); |
| 181 | return; |
| 182 | } |
| 183 | |
Brian Salomon | 1447177 | 2017-12-05 10:35:15 -0500 | [diff] [blame] | 184 | const GrReducedClip reducedClip(stack, SkRect::Make(kCoverRect), rtc->caps()->shaderCaps(), |
| 185 | kNumWindows); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 186 | |
| 187 | GrPaint paint; |
Brian Salomon | 7c8460e | 2017-05-12 11:36:10 -0400 | [diff] [blame] | 188 | if (GrFSAAType::kNone == rtc->fsaaType()) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 189 | paint.setColor4f(GrColor4f(0, 0.25f, 1, 1)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 190 | this->visualizeAlphaMask(ctx, rtc, reducedClip, std::move(paint)); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 191 | } else { |
| 192 | paint.setColor4f(GrColor4f(1, 0.25f, 0.25f, 1)); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 193 | this->visualizeStencilMask(ctx, rtc, reducedClip, std::move(paint)); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 197 | void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrRenderTargetContext* rtc, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 198 | const GrReducedClip& reducedClip, GrPaint&& paint) { |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 199 | const int padRight = (kDeviceRect.right() - kCoverRect.right()) / 2; |
| 200 | const int padBottom = (kDeviceRect.bottom() - kCoverRect.bottom()) / 2; |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 201 | sk_sp<GrRenderTargetContext> maskRTC( |
Robert Phillips | dd3b3f4 | 2017-04-24 10:57:28 -0400 | [diff] [blame] | 202 | ctx->makeDeferredRenderTargetContextWithFallback(SkBackingFit::kExact, |
| 203 | kCoverRect.width() + padRight, |
| 204 | kCoverRect.height() + padBottom, |
| 205 | kAlpha_8_GrPixelConfig, nullptr)); |
Robert Phillips | c0192e3 | 2017-09-21 12:00:26 -0400 | [diff] [blame] | 206 | if (!maskRTC) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | |
| 210 | // Draw a checker pattern into the alpha mask so we can visualize the regions left untouched by |
| 211 | // the clip mask generation. |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 212 | this->stencilCheckerboard(maskRTC.get(), true); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 213 | maskRTC->clear(nullptr, GrColorPackA4(0xff), GrRenderTargetContext::CanClearFullscreen::kYes); |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 214 | maskRTC->priv().drawAndStencilRect(make_stencil_only_clip(), &GrUserStencilSettings::kUnused, |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 215 | SkRegion::kDifference_Op, false, GrAA::kNo, SkMatrix::I(), |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 216 | SkRect::MakeIWH(maskRTC->width(), maskRTC->height())); |
| 217 | reducedClip.drawAlphaClipMask(maskRTC.get()); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 218 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 219 | int x = kCoverRect.x() - kDeviceRect.x(), |
| 220 | y = kCoverRect.y() - kDeviceRect.y(); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 221 | |
| 222 | // Now visualize the alpha mask by drawing a rect over the area where it is defined. The regions |
| 223 | // inside window rectangles or outside the scissor should still have the initial checkerboard |
| 224 | // intact. (This verifies we didn't spend any time modifying those pixels in the mask.) |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 225 | AlphaOnlyClip clip(maskRTC->asTextureProxyRef(), x, y); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 226 | rtc->drawRect(clip, std::move(paint), GrAA::kYes, SkMatrix::I(), |
Robert Phillips | 40fd7c9 | 2017-01-30 08:06:27 -0500 | [diff] [blame] | 227 | SkRect::Make(SkIRect::MakeXYWH(x, y, maskRTC->width(), maskRTC->height()))); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 230 | void WindowRectanglesMaskGM::visualizeStencilMask(GrContext* ctx, GrRenderTargetContext* rtc, |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 231 | const GrReducedClip& reducedClip, |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 232 | GrPaint&& paint) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 233 | // Draw a checker pattern into the stencil buffer so we can visualize the regions left untouched |
| 234 | // by the clip mask generation. |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 235 | this->stencilCheckerboard(rtc, false); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 236 | reducedClip.drawStencilClipMask(ctx, rtc); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 237 | |
| 238 | // Now visualize the stencil mask by covering the entire render target. The regions inside |
Robert Phillips | 806be2d | 2017-06-28 15:23:59 -0400 | [diff] [blame] | 239 | // window rectangles or outside the scissor should still have the initial checkerboard intact. |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 240 | // (This verifies we didn't spend any time modifying those pixels in the mask.) |
Chris Dalton | bbfd516 | 2017-11-07 13:35:22 -0700 | [diff] [blame] | 241 | rtc->drawPaint(make_stencil_only_clip(), std::move(paint), SkMatrix::I()); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 244 | void WindowRectanglesMaskGM::stencilCheckerboard(GrRenderTargetContext* rtc, bool flip) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 245 | constexpr static GrUserStencilSettings kSetClip( |
| 246 | GrUserStencilSettings::StaticInit< |
| 247 | 0, |
| 248 | GrUserStencilTest::kAlways, |
| 249 | 0, |
| 250 | GrUserStencilOp::kSetClipBit, |
| 251 | GrUserStencilOp::kKeep, |
| 252 | 0>() |
| 253 | ); |
| 254 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 255 | rtc->priv().clearStencilClip(GrFixedClip::Disabled(), false); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 256 | |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 257 | for (int y = 0; y < kDeviceRect.height(); y += kMaskCheckerSize) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 258 | for (int x = (y & 1) == flip ? 0 : kMaskCheckerSize; |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 259 | x < kDeviceRect.width(); x += 2 * kMaskCheckerSize) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 260 | SkIRect checker = SkIRect::MakeXYWH(x, y, kMaskCheckerSize, kMaskCheckerSize); |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 261 | rtc->priv().stencilRect(GrNoClip(), &kSetClip, GrAAType::kNone, SkMatrix::I(), |
Brian Osman | 693a540 | 2016-10-27 15:13:22 -0400 | [diff] [blame] | 262 | SkRect::Make(checker)); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | void WindowRectanglesMaskGM::fail(SkCanvas* canvas) { |
| 268 | SkPaint paint; |
| 269 | paint.setAntiAlias(true); |
| 270 | paint.setTextAlign(SkPaint::kCenter_Align); |
| 271 | paint.setTextSize(20); |
| 272 | sk_tool_utils::set_portable_typeface(&paint); |
| 273 | |
| 274 | SkString errorMsg; |
| 275 | errorMsg.printf("Requires GPU with %i window rectangles", kNumWindows); |
| 276 | |
| 277 | canvas->clipRect(SkRect::Make(kCoverRect)); |
| 278 | canvas->clear(SK_ColorWHITE); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 279 | canvas->drawString(errorMsg, SkIntToScalar(kCoverRect.centerX()), |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 280 | SkIntToScalar(kCoverRect.centerY() - 10), paint); |
| 281 | } |
| 282 | |
| 283 | DEF_GM( return new WindowRectanglesMaskGM(); ) |
| 284 | |
| 285 | #endif |
| 286 | |
| 287 | } |