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/private/SkColorData.h"
|
2020-12-23 14:16:59 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkClipStack.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a clip that will exercise window rectangles if they are supported.
|
|
|
|
*/
|
2021-08-09 16:21:52 +00:00
|
|
|
class WindowRectanglesGM : public GM {
|
2016-09-06 17:01:06 +00:00
|
|
|
private:
|
2021-08-09 16:21:52 +00:00
|
|
|
DrawResult coverClipStack(const SkClipStack&, SkCanvas*, SkString* errorMsg);
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(kDeviceRect.width(), kDeviceRect.height()); }
|
|
|
|
SkString onShortName() override { return SkString("windowrectangles"); }
|
|
|
|
DrawResult onDraw(SkCanvas*, SkString* errorMsg) override;
|
2016-09-06 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
DrawResult WindowRectanglesGM::coverClipStack(const SkClipStack& stack, SkCanvas* canvas,
|
2019-02-07 23:20:09 +00:00
|
|
|
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()) {
|
2021-08-09 16:21:52 +00:00
|
|
|
SkASSERT(!element->isReplaceOp());
|
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:
|
2021-08-03 17:08:50 +00:00
|
|
|
canvas->clipRect({ 0, 0, 0, 0 }, SkClipOp::kIntersect, false);
|
2017-03-08 18:13:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
DrawResult WindowRectanglesGM::onDraw(SkCanvas* canvas, SkString* errorMsg) {
|
|
|
|
ToolUtils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6, 25);
|
|
|
|
SkClipStack stack;
|
|
|
|
stack.clipRect(SkRect::MakeXYWH(370.75, 80.25, 149, 100), SkMatrix::I(),
|
|
|
|
SkClipOp::kDifference, false);
|
|
|
|
stack.clipRect(SkRect::MakeXYWH(80.25, 420.75, 150, 100), SkMatrix::I(),
|
|
|
|
SkClipOp::kDifference, true);
|
|
|
|
stack.clipRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(200, 200, 200, 200), 60, 45),
|
|
|
|
SkMatrix::I(), SkClipOp::kDifference, true);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
SkRRect nine;
|
|
|
|
nine.setNinePatch(SkRect::MakeXYWH(550 - 30.25 - 100, 370.75, 100, 150), 12, 35, 23, 20);
|
|
|
|
stack.clipRRect(nine, SkMatrix::I(), SkClipOp::kDifference, true);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2021-08-09 16:21:52 +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);
|
|
|
|
stack.clipRRect(complx, SkMatrix::I(), SkClipOp::kDifference, false);
|
2016-09-06 17:01:06 +00:00
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
return this->coverClipStack(stack, canvas, errorMsg);
|
2016-09-06 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 16:21:52 +00:00
|
|
|
DEF_GM( return new WindowRectanglesGM(); )
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|