Flutter Engine
The Flutter Engine
SkRasterClipStack.h
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
8#ifndef SkRasterClipStack_DEFINED
9#define SkRasterClipStack_DEFINED
10
14#include "src/core/SkScan.h"
15
17public:
19 : fRootBounds(SkIRect::MakeWH(width, height))
20 , fDisableAA(SkScan::PathRequiresTiling(fRootBounds)) {
21 fStack.emplace_back(SkRasterClip(fRootBounds));
22 SkASSERT(fStack.count() == 1);
23 }
24
25 void setNewSize(int w, int h) {
26 fRootBounds.setXYWH(0, 0, w, h);
27
28 SkASSERT(fStack.count() == 1);
29 Rec& rec = fStack.back();
30 SkASSERT(rec.fDeferredCount == 0);
31 rec.fRC.setRect(fRootBounds);
32 }
33
34 const SkRasterClip& rc() const { return fStack.back().fRC; }
35
36 void save() {
37 SkDEBUGCODE(fCounter += 1);
38 SkASSERT(fStack.back().fDeferredCount >= 0);
39 fStack.back().fDeferredCount += 1;
40 }
41
42 void restore() {
43 SkDEBUGCODE(fCounter -= 1);
44 SkASSERT(fCounter >= 0);
45
46 if (--fStack.back().fDeferredCount < 0) {
47 SkASSERT(fStack.back().fDeferredCount == -1);
48 SkASSERT(fStack.count() > 1);
49 fStack.pop_back();
50 }
51 }
52
53 void clipRect(const SkMatrix& ctm, const SkRect& rect, SkClipOp op, bool aa) {
54 this->writable_rc().op(rect, ctm, op, this->finalAA(aa));
55 this->validate();
56 }
57
58 void clipRRect(const SkMatrix& ctm, const SkRRect& rrect, SkClipOp op, bool aa) {
59 this->writable_rc().op(rrect, ctm, op, this->finalAA(aa));
60 this->validate();
61 }
62
63 void clipPath(const SkMatrix& ctm, const SkPath& path, SkClipOp op, bool aa) {
64 this->writable_rc().op(path, ctm, op, this->finalAA(aa));
65 this->validate();
66 }
67
69 this->writable_rc().op(std::move(sh));
70 this->validate();
71 }
72
73 void clipRegion(const SkRegion& rgn, SkClipOp op) {
74 this->writable_rc().op(rgn, op);
75 this->validate();
76 }
77
78 void replaceClip(const SkIRect& rect) {
79 SkIRect devRect = rect;
80 if (!devRect.intersect(fRootBounds)) {
81 this->writable_rc().setEmpty();
82 } else {
83 this->writable_rc().setRect(devRect);
84 }
85 }
86
87 void validate() const {
88#ifdef SK_DEBUG
89 const SkRasterClip& clip = this->rc();
90 if (fRootBounds.isEmpty()) {
92 } else if (!clip.isEmpty()) {
93 SkASSERT(fRootBounds.contains(clip.getBounds()));
94 }
95#endif
96 }
97
98private:
99 struct Rec {
100 SkRasterClip fRC;
101 int fDeferredCount; // 0 for a "normal" entry
102
103 Rec(const SkRasterClip& rc) : fRC(rc), fDeferredCount(0) {}
104 };
105
107 SkIRect fRootBounds;
108 bool fDisableAA;
109 SkDEBUGCODE(int fCounter = 0;)
110
111 SkRasterClip& writable_rc() {
112 SkASSERT(fStack.back().fDeferredCount >= 0);
113 if (fStack.back().fDeferredCount > 0) {
114 fStack.back().fDeferredCount -= 1;
115 fStack.emplace_back(fStack.back().fRC);
116 }
117 return fStack.back().fRC;
118 }
119
120 bool finalAA(bool aa) const { return aa && !fDisableAA; }
121};
122
123#endif
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkClipOp
Definition: SkClipOp.h:13
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
Definition: SkPath.h:59
bool isEmpty() const
Definition: SkPath.cpp:416
const SkRect & getBounds() const
Definition: SkPath.cpp:430
void setNewSize(int w, int h)
void clipShader(sk_sp< SkShader > sh)
void clipPath(const SkMatrix &ctm, const SkPath &path, SkClipOp op, bool aa)
void replaceClip(const SkIRect &rect)
void validate() const
void clipRegion(const SkRegion &rgn, SkClipOp op)
const SkRasterClip & rc() const
SkRasterClipStack(int width, int height)
void clipRect(const SkMatrix &ctm, const SkRect &rect, SkClipOp op, bool aa)
void clipRRect(const SkMatrix &ctm, const SkRRect &rrect, SkClipOp op, bool aa)
Definition: SkScan.h:26
void pop_back()
Definition: SkTBlockList.h:130
int count() const
Definition: SkTBlockList.h:167
T & emplace_back(Args &&... args)
Definition: SkTBlockList.h:101
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
sh
Definition: run_sh.py:10
SkScalar w
SkScalar h
int32_t height
int32_t width
Definition: SkRect.h:32
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
bool isEmpty() const
Definition: SkRect.h:202
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
Definition: SkRect.h:268
bool contains(int32_t x, int32_t y) const
Definition: SkRect.h:463