Flutter Engine
The Flutter Engine
windowrectangles.cpp
Go to the documentation of this file.
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/gm.h"
17#include "include/core/SkRect.h"
20#include "include/core/SkSize.h"
26#include "tools/ToolUtils.h"
27
28#include <utility>
29
30constexpr static SkIRect kDeviceRect = {0, 0, 600, 600};
31constexpr static SkIRect kCoverRect = {50, 50, 550, 550};
32
33namespace skiagm {
34
35////////////////////////////////////////////////////////////////////////////////////////////////////
36
37/**
38 * Draws a clip that will exercise window rectangles if they are supported.
39 */
40class WindowRectanglesGM : public GM {
41private:
42 DrawResult coverClipStack(const SkClipStack&, SkCanvas*, SkString* errorMsg);
43
44 SkISize getISize() override { return SkISize::Make(kDeviceRect.width(), kDeviceRect.height()); }
45 SkString getName() const override { return SkString("windowrectangles"); }
46 DrawResult onDraw(SkCanvas*, SkString* errorMsg) override;
47};
48
49DrawResult WindowRectanglesGM::coverClipStack(const SkClipStack& stack, SkCanvas* canvas,
50 SkString* errorMsg) {
52 paint.setColor(0xff00aa80);
53
54 // Set up the canvas's clip to match our SkClipStack.
56 for (const SkClipStack::Element* element = iter.next(); element; element = iter.next()) {
57 SkASSERT(!element->isReplaceOp());
58 SkClipOp op = element->getOp();
59 bool isAA = element->isAA();
60 switch (element->getDeviceSpaceType()) {
62 canvas->clipShader(element->refShader(), op);
63 break;
65 canvas->clipPath(element->getDeviceSpacePath(), op, isAA);
66 break;
68 canvas->clipRRect(element->getDeviceSpaceRRect(), op, isAA);
69 break;
71 canvas->clipRect(element->getDeviceSpaceRect(), op, isAA);
72 break;
74 canvas->clipRect({ 0, 0, 0, 0 }, SkClipOp::kIntersect, false);
75 break;
76 }
77 }
78
80 return DrawResult::kOk;
81}
82
83DrawResult WindowRectanglesGM::onDraw(SkCanvas* canvas, SkString* errorMsg) {
84 ToolUtils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6, 25);
85 SkClipStack stack;
86 stack.clipRect(SkRect::MakeXYWH(370.75, 80.25, 149, 100), SkMatrix::I(),
88 stack.clipRect(SkRect::MakeXYWH(80.25, 420.75, 150, 100), SkMatrix::I(),
90 stack.clipRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(200, 200, 200, 200), 60, 45),
92
93 SkRRect nine;
94 nine.setNinePatch(SkRect::MakeXYWH(550 - 30.25 - 100, 370.75, 100, 150), 12, 35, 23, 20);
95 stack.clipRRect(nine, SkMatrix::I(), SkClipOp::kDifference, true);
96
97 SkRRect complx;
98 SkVector complxRadii[4] = {{6, 4}, {8, 12}, {16, 24}, {48, 32}};
99 complx.setRectRadii(SkRect::MakeXYWH(80.25, 80.75, 100, 149), complxRadii);
100 stack.clipRRect(complx, SkMatrix::I(), SkClipOp::kDifference, false);
101
102 return this->coverClipStack(stack, canvas, errorMsg);
103}
104
105DEF_GM( return new WindowRectanglesGM(); )
106} // namespace skiagm
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkClipOp
Definition: SkClipOp.h:13
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
void clipShader(sk_sp< SkShader >, SkClipOp=SkClipOp::kIntersect)
Definition: SkCanvas.cpp:1488
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1439
@ kPath
This element does not have geometry, but applies a shader to the clip.
@ kEmpty
This element makes the clip empty (regardless of previous elements).
@ kRect
This element combines a device space round-rect with the current clip.
@ kRRect
This element combines a device space path with the current clip.
void clipRect(const SkRect &, const SkMatrix &matrix, SkClipOp, bool doAA)
void clipRRect(const SkRRect &, const SkMatrix &matrix, SkClipOp, bool doAA)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
void setRectRadii(const SkRect &rect, const SkVector radii[4])
Definition: SkRRect.cpp:189
void setNinePatch(const SkRect &rect, SkScalar leftRad, SkScalar topRad, SkScalar rightRad, SkScalar bottomRad)
Definition: SkRRect.cpp:115
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
void draw_checkerboard(SkCanvas *canvas, SkColor c1, SkColor c2, int size)
Definition: ToolUtils.cpp:174
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
DrawResult
Definition: gm.h:104
Definition: SkRect.h:32
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkIRect kCoverRect
static constexpr SkIRect kDeviceRect