Flutter Engine
The Flutter Engine
SkClipStackDevice.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 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
9
12#include "include/core/SkPath.h"
18
19#include <utility>
20
21class SkRRect;
22enum class SkClipOp;
23
25 SkIRect r = fClipStack.bounds(this->imageInfo().bounds()).roundOut();
26 if (!r.isEmpty()) {
27 SkASSERT(this->imageInfo().bounds().contains(r));
28 }
29 return r;
30}
31
32///////////////////////////////////////////////////////////////////////////////////////////////////
33
35 fClipStack.save();
36}
37
39 fClipStack.restore();
40}
41
43 fClipStack.clipRect(rect, this->localToDevice(), op, aa);
44}
45
47 fClipStack.clipRRect(rrect, this->localToDevice(), op, aa);
48}
49
51 fClipStack.clipPath(path, this->localToDevice(), op, aa);
52}
53
54void SkClipStackDevice::onClipShader(sk_sp<SkShader> shader) {
55 fClipStack.clipShader(std::move(shader));
56}
57
59 SkIPoint origin = this->getOrigin();
60 SkRegion tmp;
63 path.transform(SkMatrix::Translate(-origin));
64 fClipStack.clipPath(path, SkMatrix::I(), op, false);
65}
66
68 SkRect deviceRect = SkMatrixPriv::MapRect(this->globalToDevice(), SkRect::Make(rect));
69 fClipStack.replaceClip(deviceRect, /*doAA=*/false);
70}
71
73 SkClipStack::B2TIter iter(fClipStack);
74 const SkClipStack::Element* element;
75
76 while ((element = iter.next()) != nullptr) {
77 if (element->isAA()) {
78 return true;
79 }
80 }
81 return false;
82}
83
85 return fClipStack.quickContains(SkRect::MakeIWH(this->width(), this->height()));
86}
87
89 return fClipStack.isEmpty(SkIRect::MakeWH(this->width(), this->height()));
90}
91
93 if (this->isClipWideOpen()) {
94 return true;
95 } else if (this->isClipEmpty()) {
96 return false;
97 }
98
100 bool isIntersectionOfRects;
102 fClipStack.getBounds(&bounds, &boundType, &isIntersectionOfRects);
103 return isIntersectionOfRects && boundType == SkClipStack::kNormal_BoundsType;
104}
105
107 SkClipStack::BoundsType boundType;
108 bool isIntersectionOfRects;
110 fClipStack.getBounds(&bounds, &boundType, &isIntersectionOfRects);
111 if (isIntersectionOfRects && SkClipStack::kNormal_BoundsType == boundType) {
112 rgn->setRect(bounds.round());
113 } else {
114 SkRegion boundsRgn({0, 0, this->width(), this->height()});
115 SkPath tmpPath;
116
117 *rgn = boundsRgn;
118 SkClipStack::B2TIter iter(fClipStack);
119 while (auto elem = iter.next()) {
120 tmpPath.rewind();
121 elem->asDeviceSpacePath(&tmpPath);
122 SkRegion tmpRgn;
123 tmpRgn.setPath(tmpPath, boundsRgn);
124 if (elem->isReplaceOp()) {
125 // All replace elements are rectangles
126 // TODO: SkClipStack can be simplified to be I,D,R ops now, which means element
127 // iteration can be from top of the stack to the most recent replace element.
128 // When that's done, this loop will be simplifiable.
129 rgn->setRect(elem->getDeviceSpaceRect().round());
130 } else {
131 rgn->op(tmpRgn, static_cast<SkRegion::Op>(elem->getOp()));
132 }
133 }
134 }
135}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkClipOp
Definition: SkClipOp.h:13
bool isClipAntiAliased() const override
bool isClipWideOpen() const override
void clipPath(const SkPath &path, SkClipOp, bool aa) override
bool isClipEmpty() const override
void android_utils_clipAsRgn(SkRegion *) const override
void popClipStack() override
void pushClipStack() override
void replaceClip(const SkIRect &rect) override
void clipRRect(const SkRRect &rrect, SkClipOp, bool aa) override
void clipRect(const SkRect &rect, SkClipOp, bool aa) override
SkIRect devClipBounds() const override
void clipRegion(const SkRegion &deviceRgn, SkClipOp) override
bool isClipRect() const override
const Element * next()
bool isAA() const
Inverts the fill of the clip shape. Note that a kEmpty element remains kEmpty.
Definition: SkClipStack.h:151
@ kNormal_BoundsType
Definition: SkClipStack.h:37
void clipRect(const SkRect &, const SkMatrix &matrix, SkClipOp, bool doAA)
void clipShader(sk_sp< SkShader >)
void clipRRect(const SkRRect &, const SkMatrix &matrix, SkClipOp, bool doAA)
bool quickContains(const SkRect &devRect) const
Definition: SkClipStack.h:336
void getBounds(SkRect *canvFiniteBound, BoundsType *boundType, bool *isIntersectionOfRects=nullptr) const
bool isEmpty(const SkIRect &deviceBounds) const
void restore()
void clipPath(const SkPath &, const SkMatrix &matrix, SkClipOp, bool doAA)
SkRect bounds(const SkIRect &deviceBounds) const
void replaceClip(const SkRect &devRect, bool doAA)
const SkImageInfo & imageInfo() const
Definition: SkDevice.h:117
int height() const
Definition: SkDevice.h:120
SkIPoint getOrigin() const
Definition: SkDevice.cpp:91
const SkM44 & globalToDevice() const
Definition: SkDevice.h:191
const SkMatrix & localToDevice() const
Definition: SkDevice.h:179
int width() const
Definition: SkDevice.h:119
SkIRect bounds() const
Definition: SkDevice.h:125
static SkRect MapRect(const SkM44 &m, const SkRect &r)
Definition: SkM44.cpp:216
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
Definition: SkPath.h:59
bool getBoundaryPath(SkPath *path) const
bool op(const SkIRect &rect, Op op)
Definition: SkRegion.h:384
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
bool setPath(const SkPath &path, const SkRegion &clip)
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
bool isEmpty() const
Definition: SkRect.h:202
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241