1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_TOOLS_CLIPSTATE_HXX
25 #define _BGFX_TOOLS_CLIPSTATE_HXX
26 
27 #include <sal/types.h>
28 #include <o3tl/cow_wrapper.hxx>
29 #include <basegfx/basegfxdllapi.h>
30 
31 //////////////////////////////////////////////////////////////////////////////
32 
33 namespace basegfx
34 {
35     class B2DRange;
36     class B2DPolyRange;
37     class B2DPolygon;
38     class B2DPolyPolygon;
39 
40     namespace tools
41     {
42         struct ImplB2DClipState;
43 
44         /** This class provides an optimized, symbolic clip state for graphical output
45 
46             Having a current 'clip' state is a common attribute of
47             almost all graphic output APIs, most of which internally
48             represent it via a list of rectangular bands. In contrast,
49             this implementation purely uses symbolic clips, but in a
50             quite efficient manner, deferring actual evaluation until
51             a clip representation is requested, and using faster code
52             paths for common special cases (like all-rectangle clips)
53          */
54         class BASEGFX_DLLPUBLIC B2DClipState
55         {
56         public:
57             typedef o3tl::cow_wrapper< ImplB2DClipState > ImplType;
58 
59         private:
60             ImplType mpImpl;
61 
62         public:
63             /// Init clip, in 'cleared' state - everything is visible
64             B2DClipState();
65             ~B2DClipState();
66             B2DClipState( const B2DClipState& );
67             explicit B2DClipState( const B2DRange& );
68             explicit B2DClipState( const B2DPolygon& );
69             explicit B2DClipState( const B2DPolyPolygon& );
70             B2DClipState& operator=( const B2DClipState& );
71 
72             /// unshare this poly-range with all internally shared instances
73             void makeUnique();
74 
75             /// Set clip to 'null' - nothing is visible
76             void makeNull();
77             /// returns true when clip is 'null' - nothing is visible
78             bool isNull() const;
79 
80             /// Set clip 'cleared' - everything is visible
81             void makeClear();
82             /// returns true when clip is 'cleared' - everything is visible
83             bool isCleared() const;
84 
85             bool operator==(const B2DClipState&) const;
86             bool operator!=(const B2DClipState&) const;
87 
88             void unionRange(const B2DRange& );
89             void unionPolygon(const B2DPolygon& );
90             void unionPolyPolygon(const B2DPolyPolygon& );
91             void unionClipState(const B2DClipState& );
92 
93             void intersectRange(const B2DRange& );
94             void intersectPolygon(const B2DPolygon& );
95             void intersectPolyPolygon(const B2DPolyPolygon& );
96             void intersectClipState(const B2DClipState& );
97 
98             void subtractRange(const B2DRange& );
99             void subtractPolygon(const B2DPolygon& );
100             void subtractPolyPolygon(const B2DPolyPolygon& );
101             void subtractClipState(const B2DClipState& );
102 
103             void xorRange(const B2DRange& );
104             void xorPolygon(const B2DPolygon& );
105             void xorPolyPolygon(const B2DPolyPolygon& );
106             void xorClipState(const B2DClipState& );
107 
108             B2DPolyPolygon getClipPoly() const;
109         };
110     }
111 }
112 
113 #endif // _BGFX_TOOLS_CLIPSTATE_HXX
114