blob: de0f6297d4304f6c5c8756804fdd89ecdf7e4fe7 [file] [log] [blame]
Mike Reedc5e641c2017-02-17 14:38:11 -05001/*
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 "SkClipStack.h"
12#include "SkDevice.h"
13
14class SK_API SkClipStackDevice : public SkBaseDevice {
15public:
16 SkClipStackDevice(const SkImageInfo& info, const SkSurfaceProps& props)
17 : SkBaseDevice(info, props)
Mike Reedd37f22b2017-03-09 23:56:25 -050018 , fClipStack(fStorage, sizeof(fStorage))
Mike Reedc5e641c2017-02-17 14:38:11 -050019 {}
20
Mike Reedf880b682017-03-10 11:30:44 -050021 SkClipStack& cs() { return fClipStack; }
Brian Salomon0166cfd2017-03-13 17:58:25 -040022 const SkClipStack& cs() const { return fClipStack; }
Mike Reedc5e641c2017-02-17 14:38:11 -050023
Mike Reeda1361362017-03-07 09:37:29 -050024 SkIRect devClipBounds() const;
Mike Reedfa24d342017-02-22 15:21:35 -050025
Mike Reedc5e641c2017-02-17 14:38:11 -050026protected:
27 void onSave() override;
28 void onRestore() override;
29 void onClipRect(const SkRect& rect, SkClipOp, bool aa) override;
30 void onClipRRect(const SkRRect& rrect, SkClipOp, bool aa) override;
31 void onClipPath(const SkPath& path, SkClipOp, bool aa) override;
32 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
33 void onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) override;
Mike Reeda1361362017-03-07 09:37:29 -050034 bool onClipIsAA() const override;
35 void onAsRgnClip(SkRegion*) const override;
36 ClipType onGetClipType() const override;
Mike Reedc5e641c2017-02-17 14:38:11 -050037
38private:
Mike Reedd37f22b2017-03-09 23:56:25 -050039 enum {
40 kPreallocCount = 16 // empirically determined, adjust as needed to reduce mallocs
41 };
42 intptr_t fStorage[kPreallocCount * sizeof(SkClipStack::Element) / sizeof(intptr_t)];
Mike Reedc5e641c2017-02-17 14:38:11 -050043 SkClipStack fClipStack;
44
45 typedef SkBaseDevice INHERITED;
46};
47
48#endif