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 SkClipStackDevice_DEFINED |
9 | #define SkClipStackDevice_DEFINED |
10 | |
11 | #include "src/core/SkClipStack.h" |
12 | #include "src/core/SkDevice.h" |
13 | |
14 | class SkClipStackDevice : public SkBaseDevice { |
15 | public: |
16 | SkClipStackDevice(const SkImageInfo& info, const SkSurfaceProps& props) |
17 | : SkBaseDevice(info, props) |
18 | , fClipStack(fStorage, sizeof(fStorage)) |
19 | {} |
20 | |
21 | SkClipStack& cs() { return fClipStack; } |
22 | const SkClipStack& cs() const { return fClipStack; } |
23 | |
24 | protected: |
25 | void onSave() override; |
26 | void onRestore() override; |
27 | void onClipRect(const SkRect& rect, SkClipOp, bool aa) override; |
28 | void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override; |
29 | void onClipPath(const SkPath& path, SkClipOp, bool aa) override; |
30 | void onClipShader(sk_sp<SkShader>) override; |
31 | void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override; |
32 | void onReplaceClip(const SkIRect& rect) override; |
33 | void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) override; |
34 | bool onClipIsAA() const override; |
35 | bool onClipIsWideOpen() const override; |
36 | void onAsRgnClip(SkRegion*) const override; |
37 | ClipType onGetClipType() const override; |
38 | SkIRect onDevClipBounds() const override; |
39 | |
40 | private: |
41 | enum { |
42 | kPreallocCount = 16 // empirically determined, adjust as needed to reduce mallocs |
43 | }; |
44 | intptr_t fStorage[kPreallocCount * sizeof(SkClipStack::Element) / sizeof(intptr_t)]; |
45 | SkClipStack fClipStack; |
46 | |
47 | typedef SkBaseDevice INHERITED; |
48 | }; |
49 | |
50 | #endif |
51 | |