2016-09-06 17:01:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkClipOp.h"
|
|
|
|
#include "include/core/SkColorSpace.h"
|
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRRect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/private/GrTypesPriv.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
2020-12-23 14:16:59 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/core/SkClipOpPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipStack.h"
|
|
|
|
#include "src/gpu/GrAppliedClip.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrClip.h"
|
|
|
|
#include "src/gpu/GrFragmentProcessor.h"
|
|
|
|
#include "src/gpu/GrPaint.h"
|
2020-02-26 18:28:42 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrReducedClip.h"
|
|
|
|
#include "src/gpu/GrStencilClip.h"
|
2020-12-09 21:37:04 +00:00
|
|
|
#include "src/gpu/GrSurfaceDrawContext.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "src/gpu/GrUserStencilSettings.h"
|
2020-02-26 18:28:42 +00:00
|
|
|
#include "src/gpu/effects/generated/GrDeviceSpaceEffect.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
class GrRecordingContext;
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
constexpr static SkIRect kDeviceRect = {0, 0, 600, 600};
|
|
|
|
constexpr static SkIRect kCoverRect = {50, 50, 550, 550};
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class WindowRectanglesBaseGM : public GM {
|
|
|
|
protected:
|
2019-02-07 23:20:09 +00:00
|
|
|
virtual DrawResult onCoverClipStack(const SkClipStack&, SkCanvas*, SkString* errorMsg) = 0;
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkISize onISize() override { return SkISize::Make(kDeviceRect.width(), kDeviceRect.height()); }
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onDraw(SkCanvas*, SkString* errorMsg) final;
|
2016-09-06 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult WindowRectanglesBaseGM::onDraw(SkCanvas* canvas, SkString* errorMsg) {
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6, 25);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
SkClipStack stack;
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(370.75, 80.25, 149, 100), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kDifference_SkClipOp, false);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRect(SkRect::MakeXYWH(80.25, 420.75, 150, 100), SkMatrix::I(),
|
2016-12-09 14:00:50 +00:00
|
|
|
kDifference_SkClipOp, true);
|
2016-10-03 15:36:16 +00:00
|
|
|
stack.clipRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(200, 200, 200, 200), 60, 45),
|
2016-12-09 14:00:50 +00:00
|
|
|
SkMatrix::I(), kDifference_SkClipOp, true);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
SkRRect nine;
|
|
|
|
nine.setNinePatch(SkRect::MakeXYWH(550 - 30.25 - 100, 370.75, 100, 150), 12, 35, 23, 20);
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRRect(nine, SkMatrix::I(), kDifference_SkClipOp, true);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
SkRRect complx;
|
|
|
|
SkVector complxRadii[4] = {{6, 4}, {8, 12}, {16, 24}, {48, 32}};
|
|
|
|
complx.setRectRadii(SkRect::MakeXYWH(80.25, 80.75, 100, 149), complxRadii);
|
2016-12-09 14:00:50 +00:00
|
|
|
stack.clipRRect(complx, SkMatrix::I(), kDifference_SkClipOp, false);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
return this->onCoverClipStack(stack, canvas, errorMsg);
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a clip that will exercise window rectangles if they are supported.
|
|
|
|
*/
|
|
|
|
class WindowRectanglesGM : public WindowRectanglesBaseGM {
|
|
|
|
private:
|
|
|
|
SkString onShortName() final { return SkString("windowrectangles"); }
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onCoverClipStack(const SkClipStack&, SkCanvas*, SkString* errorMsg) final;
|
2016-09-06 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult WindowRectanglesGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas,
|
|
|
|
SkString* errorMsg) {
|
2016-09-06 17:01:06 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xff00aa80);
|
|
|
|
|
|
|
|
// Set up the canvas's clip to match our SkClipStack.
|
|
|
|
SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
|
|
|
|
for (const SkClipStack::Element* element = iter.next(); element; element = iter.next()) {
|
2017-03-08 18:13:44 +00:00
|
|
|
SkClipOp op = element->getOp();
|
|
|
|
bool isAA = element->isAA();
|
2017-08-30 15:37:57 +00:00
|
|
|
switch (element->getDeviceSpaceType()) {
|
2020-06-05 15:29:36 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kShader:
|
|
|
|
canvas->clipShader(element->refShader(), op);
|
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kPath:
|
|
|
|
canvas->clipPath(element->getDeviceSpacePath(), op, isAA);
|
2017-03-08 18:13:44 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRRect:
|
|
|
|
canvas->clipRRect(element->getDeviceSpaceRRect(), op, isAA);
|
2017-03-08 18:13:44 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kRect:
|
|
|
|
canvas->clipRect(element->getDeviceSpaceRect(), op, isAA);
|
2017-03-08 18:13:44 +00:00
|
|
|
break;
|
2017-08-30 15:37:57 +00:00
|
|
|
case SkClipStack::Element::DeviceSpaceType::kEmpty:
|
2017-03-08 18:13:44 +00:00
|
|
|
canvas->clipRect({ 0, 0, 0, 0 }, kIntersect_SkClipOp, false);
|
|
|
|
break;
|
|
|
|
}
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawRect(SkRect::Make(kCoverRect), paint);
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GM( return new WindowRectanglesGM(); )
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-06 18:45:31 +00:00
|
|
|
constexpr static int kNumWindows = 8;
|
|
|
|
|
2016-09-06 17:01:06 +00:00
|
|
|
/**
|
2018-03-30 15:59:38 +00:00
|
|
|
* Visualizes the mask (alpha or stencil) for a clip with several window rectangles. The purpose of
|
|
|
|
* this test is to verify that window rectangles are being used during clip mask generation, and to
|
2016-09-06 17:01:06 +00:00
|
|
|
* visualize where the window rectangles are placed.
|
|
|
|
*
|
|
|
|
* We use window rectangles when generating the clip mask because there is no need to invest time
|
|
|
|
* defining those regions where window rectangles will be in effect during the actual draw anyway.
|
|
|
|
*
|
|
|
|
* This test works by filling the entire clip mask with a small checkerboard pattern before drawing
|
|
|
|
* it, and then covering the mask with a solid color once it has been generated. The regions inside
|
|
|
|
* window rectangles or outside the scissor should still have the initial checkerboard intact.
|
|
|
|
*/
|
|
|
|
class WindowRectanglesMaskGM : public WindowRectanglesBaseGM {
|
|
|
|
private:
|
|
|
|
constexpr static int kMaskCheckerSize = 5;
|
|
|
|
SkString onShortName() final { return SkString("windowrectangles_mask"); }
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult onCoverClipStack(const SkClipStack&, SkCanvas*, SkString* errorMsg) final;
|
2020-12-09 21:37:04 +00:00
|
|
|
void visualizeAlphaMask(GrRecordingContext*, GrSurfaceDrawContext*,
|
2020-06-29 19:36:12 +00:00
|
|
|
const GrReducedClip&, GrPaint&&);
|
2020-12-09 21:37:04 +00:00
|
|
|
void visualizeStencilMask(GrRecordingContext*, GrSurfaceDrawContext*,
|
2020-06-29 19:36:12 +00:00
|
|
|
const GrReducedClip&, GrPaint&&);
|
2020-12-09 21:37:04 +00:00
|
|
|
void stencilCheckerboard(GrSurfaceDrawContext*, bool flip);
|
2016-09-06 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class clips a cover by an alpha mask. We use it to visualize the alpha clip mask.
|
|
|
|
*/
|
2020-06-30 15:12:46 +00:00
|
|
|
class AlphaOnlyClip final : public GrClip {
|
2016-09-06 17:01:06 +00:00
|
|
|
public:
|
2020-02-10 21:00:54 +00:00
|
|
|
AlphaOnlyClip(GrSurfaceProxyView mask, int x, int y) : fMask(std::move(mask)), fX(x), fY(y) {}
|
2017-08-11 13:40:37 +00:00
|
|
|
|
2016-09-06 17:01:06 +00:00
|
|
|
private:
|
2020-06-11 14:29:00 +00:00
|
|
|
SkIRect getConservativeBounds() const final {
|
|
|
|
return SkIRect::MakeXYWH(fX, fY, fMask.width(), fMask.height());
|
|
|
|
}
|
2020-12-09 21:37:04 +00:00
|
|
|
Effect apply(GrRecordingContext* ctx, GrSurfaceDrawContext*, GrAAType, bool,
|
2021-04-02 15:44:36 +00:00
|
|
|
GrAppliedClip* out, SkRect* bounds) const override {
|
2020-02-26 18:28:42 +00:00
|
|
|
GrSamplerState samplerState(GrSamplerState::WrapMode::kClampToBorder,
|
|
|
|
GrSamplerState::Filter::kNearest);
|
2020-05-21 16:11:27 +00:00
|
|
|
auto m = SkMatrix::Translate(-fX, -fY);
|
2020-02-26 18:28:42 +00:00
|
|
|
auto subset = SkRect::Make(fMask.dimensions());
|
|
|
|
auto domain = bounds->makeOffset(-fX, -fY).makeInset(0.5, 0.5);
|
|
|
|
auto fp = GrTextureEffect::MakeSubset(fMask, kPremul_SkAlphaType, m, samplerState, subset,
|
|
|
|
domain, *ctx->priv().caps());
|
|
|
|
fp = GrDeviceSpaceEffect::Make(std::move(fp));
|
|
|
|
out->addCoverageFP(std::move(fp));
|
2020-06-30 15:12:46 +00:00
|
|
|
return Effect::kClipped;
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
2020-02-10 21:00:54 +00:00
|
|
|
GrSurfaceProxyView fMask;
|
2017-08-11 13:40:37 +00:00
|
|
|
int fX;
|
|
|
|
int fY;
|
2016-09-06 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-11-07 20:35:22 +00:00
|
|
|
* Makes a clip object that enforces the stencil clip bit. Used to visualize the stencil mask.
|
2016-09-06 17:01:06 +00:00
|
|
|
*/
|
2020-12-09 21:37:04 +00:00
|
|
|
static GrStencilClip make_stencil_only_clip(GrSurfaceDrawContext* rtc) {
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
return GrStencilClip(rtc->dimensions(), SkClipStack::kEmptyGenID);
|
|
|
|
};
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DrawResult WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas,
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
SkString* errorMsg) {
|
2020-06-29 19:36:12 +00:00
|
|
|
auto ctx = canvas->recordingContext();
|
2020-12-23 14:16:59 +00:00
|
|
|
GrSurfaceDrawContext* sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
|
|
|
|
|
|
|
if (!ctx || !sdc) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
2020-12-23 14:16:59 +00:00
|
|
|
if (sdc->maxWindowRectangles() < kNumWindows) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Requires at least 8 window rectangles. "
|
|
|
|
"(Are you off FBO 0? Use sRGB to force offscreen rendering.)";
|
|
|
|
return DrawResult::kSkip;
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 14:16:59 +00:00
|
|
|
const GrReducedClip reducedClip(stack, SkRect::Make(kCoverRect), sdc->caps(), kNumWindows);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2018-03-30 15:59:38 +00:00
|
|
|
GrPaint paint;
|
2020-12-23 14:16:59 +00:00
|
|
|
if (sdc->numSamples() <= 1) {
|
2018-10-16 19:19:28 +00:00
|
|
|
paint.setColor4f({ 0, 0.25f, 1, 1 });
|
2020-12-23 14:16:59 +00:00
|
|
|
this->visualizeAlphaMask(ctx, sdc, reducedClip, std::move(paint));
|
2016-09-06 17:01:06 +00:00
|
|
|
} else {
|
2018-10-16 19:19:28 +00:00
|
|
|
paint.setColor4f({ 1, 0.25f, 0.25f, 1 });
|
2020-12-23 14:16:59 +00:00
|
|
|
this->visualizeStencilMask(ctx, sdc, reducedClip, std::move(paint));
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return DrawResult::kOk;
|
2018-03-30 15:59:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
void WindowRectanglesMaskGM::visualizeAlphaMask(GrRecordingContext* ctx, GrSurfaceDrawContext* rtc,
|
2018-03-30 15:59:38 +00:00
|
|
|
const GrReducedClip& reducedClip, GrPaint&& paint) {
|
|
|
|
const int padRight = (kDeviceRect.right() - kCoverRect.right()) / 2;
|
|
|
|
const int padBottom = (kDeviceRect.bottom() - kCoverRect.bottom()) / 2;
|
2020-12-09 21:37:04 +00:00
|
|
|
auto maskRTC = GrSurfaceDrawContext::MakeWithFallback(
|
2020-01-08 16:52:34 +00:00
|
|
|
ctx, GrColorType::kAlpha_8, nullptr, SkBackingFit::kExact,
|
2021-04-19 23:27:09 +00:00
|
|
|
{kCoverRect.width() + padRight, kCoverRect.height() + padBottom}, SkSurfaceProps());
|
2018-03-30 15:59:38 +00:00
|
|
|
if (!maskRTC) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw a checker pattern into the alpha mask so we can visualize the regions left untouched by
|
|
|
|
// the clip mask generation.
|
|
|
|
this->stencilCheckerboard(maskRTC.get(), true);
|
2020-05-26 20:57:38 +00:00
|
|
|
maskRTC->clear(SK_PMColor4fWHITE);
|
2019-05-29 18:43:13 +00:00
|
|
|
GrPaint stencilPaint;
|
|
|
|
stencilPaint.setCoverageSetOpXPFactory(SkRegion::kDifference_Op, false);
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
GrStencilClip stencilClip = make_stencil_only_clip(maskRTC.get());
|
2020-11-30 19:33:58 +00:00
|
|
|
maskRTC->stencilRect(&stencilClip, &GrUserStencilSettings::kUnused, std::move(stencilPaint),
|
|
|
|
GrAA::kNo, SkMatrix::I(), SkRect::Make(maskRTC->dimensions()));
|
2018-03-30 15:59:38 +00:00
|
|
|
reducedClip.drawAlphaClipMask(maskRTC.get());
|
|
|
|
|
|
|
|
int x = kCoverRect.x() - kDeviceRect.x(),
|
|
|
|
y = kCoverRect.y() - kDeviceRect.y();
|
|
|
|
|
|
|
|
// Now visualize the alpha mask by drawing a rect over the area where it is defined. The regions
|
|
|
|
// inside window rectangles or outside the scissor should still have the initial checkerboard
|
|
|
|
// intact. (This verifies we didn't spend any time modifying those pixels in the mask.)
|
2021-01-05 19:37:40 +00:00
|
|
|
AlphaOnlyClip alphaClip(maskRTC->readSurfaceView().makeSwizzle(GrSwizzle("aaaa")), x, y);
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
rtc->drawRect(&alphaClip, std::move(paint), GrAA::kYes, SkMatrix::I(),
|
2018-03-30 15:59:38 +00:00
|
|
|
SkRect::Make(SkIRect::MakeXYWH(x, y, maskRTC->width(), maskRTC->height())));
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 19:36:12 +00:00
|
|
|
void WindowRectanglesMaskGM::visualizeStencilMask(GrRecordingContext* ctx,
|
2020-12-09 21:37:04 +00:00
|
|
|
GrSurfaceDrawContext* rtc,
|
2016-09-06 17:01:06 +00:00
|
|
|
const GrReducedClip& reducedClip,
|
2017-01-11 18:42:54 +00:00
|
|
|
GrPaint&& paint) {
|
2020-06-30 19:30:12 +00:00
|
|
|
if (ctx->abandoned()) {
|
2020-05-12 17:15:35 +00:00
|
|
|
// GrReducedClip assumes the context hasn't been abandoned, which is reasonable since it is
|
|
|
|
// only ever used if a draw op is made. Since this GM calls it directly, it has to be taken
|
|
|
|
// into account.
|
|
|
|
return;
|
|
|
|
}
|
2016-09-06 17:01:06 +00:00
|
|
|
// Draw a checker pattern into the stencil buffer so we can visualize the regions left untouched
|
|
|
|
// by the clip mask generation.
|
2016-10-27 18:47:55 +00:00
|
|
|
this->stencilCheckerboard(rtc, false);
|
2018-10-15 20:09:54 +00:00
|
|
|
reducedClip.drawStencilClipMask(ctx, rtc);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
|
|
|
// Now visualize the stencil mask by covering the entire render target. The regions inside
|
2017-06-28 19:23:59 +00:00
|
|
|
// window rectangles or outside the scissor should still have the initial checkerboard intact.
|
2016-09-06 17:01:06 +00:00
|
|
|
// (This verifies we didn't spend any time modifying those pixels in the mask.)
|
Reland "Improve scissor state tracking in GrRTC"
This reverts commit 4926b07217f07e8f5ff1dba15d23bab960ffded3.
Reason for revert: fix wip
Original change's description:
> Revert "Improve scissor state tracking in GrRTC"
>
> This reverts commit 3b923a880bc0855772daffd95b5728795f515d5f.
>
> Reason for revert: GrAppliedHardClip isn't tracking scissor state properly
>
> Original change's description:
> > Improve scissor state tracking in GrRTC
> >
> > At a low level, this changes GrScissorState from a rect+bool to a rect+size.
> > The scissor test is considered enablebd if the rect does not fill the
> > device bounds rect specified by the size. This has a number of benefits:
> >
> > 1. We can always access the scissor rect and know that it will be
> > restricted to the render target dimensions.
> > 2. It helps consolidate code that previously had to test the scissor rect
> > and render target bounds separately.
> > 3. The clear operations can now match the proper backing store dimensions
> > of the render target.
> > 4. It makes it easier to reason about scissors applying to the logical
> > dimensions of the render target vs. its backing store dimensions.
> >
> > Originally, I was going to have the extra scissor guards for the logical
> > dimensions be added in a separate CL (with the cleanup for
> > attemptQuadOptimization). However, it became difficult to ensure correct
> > behavior respecting the vulkan render pass bounds without applying this
> > new logic at the same time.
> >
> > So now, with this CL, GrAppliedClips are sized to the backing store
> > dimensions of the render target. GrOpsTasks also clip bounds to the
> > backing store dimensions instead of the logical dimensions (which seems
> > more correct since that's where the auto-clipping happens). Then when
> > we convert a GrClip to a GrAppliedClip, the GrRTC automatically enforces
> > the logical dimensions scissor if we have stencil settings (to ensure
> > the padded pixels don't get corrupted). It also may remove the scissor
> > if the draw was just a color buffer update.
> >
> > Change-Id: I75671c9cc921f4696b1dd5231e02486090aa4282
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290654
> > Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> > Reviewed-by: Brian Salomon <bsalomon@google.com>
>
> TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
>
> Change-Id: Ie98d084158e3a537604ab0fecee69bde3e744d1b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294340
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,michaelludwig@google.com
# Not skipping CQ checks because this is a reland.
Change-Id: I2116e52146890ee4b7ea007f3c3d5c3e532e4bdd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/294257
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-04 19:52:44 +00:00
|
|
|
GrStencilClip clip = make_stencil_only_clip(rtc);
|
|
|
|
rtc->drawPaint(&clip, std::move(paint), SkMatrix::I());
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 21:37:04 +00:00
|
|
|
void WindowRectanglesMaskGM::stencilCheckerboard(GrSurfaceDrawContext* rtc, bool flip) {
|
2016-09-06 17:01:06 +00:00
|
|
|
constexpr static GrUserStencilSettings kSetClip(
|
|
|
|
GrUserStencilSettings::StaticInit<
|
|
|
|
0,
|
|
|
|
GrUserStencilTest::kAlways,
|
|
|
|
0,
|
|
|
|
GrUserStencilOp::kSetClipBit,
|
|
|
|
GrUserStencilOp::kKeep,
|
|
|
|
0>()
|
|
|
|
);
|
|
|
|
|
2020-11-30 19:33:58 +00:00
|
|
|
rtc->clearStencilClip(SkIRect::MakeSize(rtc->dimensions()), false);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2017-03-13 21:57:28 +00:00
|
|
|
for (int y = 0; y < kDeviceRect.height(); y += kMaskCheckerSize) {
|
2016-09-06 17:01:06 +00:00
|
|
|
for (int x = (y & 1) == flip ? 0 : kMaskCheckerSize;
|
2017-03-13 21:57:28 +00:00
|
|
|
x < kDeviceRect.width(); x += 2 * kMaskCheckerSize) {
|
2016-09-06 17:01:06 +00:00
|
|
|
SkIRect checker = SkIRect::MakeXYWH(x, y, kMaskCheckerSize, kMaskCheckerSize);
|
2019-05-29 18:43:13 +00:00
|
|
|
GrPaint paint;
|
|
|
|
paint.setXPFactory(GrDisableColorXPFactory::Get());
|
2020-11-30 19:33:58 +00:00
|
|
|
rtc->stencilRect(nullptr, &kSetClip, std::move(paint), GrAA::kNo, SkMatrix::I(),
|
|
|
|
SkRect::Make(checker));
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GM( return new WindowRectanglesMaskGM(); )
|
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|