| 1 | /* |
| 2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | * Copyright (C) 2015, 2016 Igalia S.L. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #ifndef ClipStack_h |
| 22 | #define ClipStack_h |
| 23 | |
| 24 | #include "IntRect.h" |
| 25 | #include "IntSize.h" |
| 26 | #include <wtf/Vector.h> |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | class ClipStack { |
| 31 | public: |
| 32 | struct State { |
| 33 | State(const IntRect& scissors = IntRect(), int stencil = 1) |
| 34 | : scissorBox(scissors) |
| 35 | , stencilIndex(stencil) |
| 36 | { } |
| 37 | |
| 38 | IntRect scissorBox; |
| 39 | int stencilIndex; |
| 40 | }; |
| 41 | |
| 42 | // Y-axis should be inverted only when painting into the window. |
| 43 | enum class YAxisMode { |
| 44 | Default, |
| 45 | Inverted, |
| 46 | }; |
| 47 | |
| 48 | void push(); |
| 49 | void pop(); |
| 50 | State& current() { return clipState; } |
| 51 | |
| 52 | void reset(const IntRect&, YAxisMode); |
| 53 | void intersect(const IntRect&); |
| 54 | void setStencilIndex(int); |
| 55 | int getStencilIndex() const { return clipState.stencilIndex; } |
| 56 | |
| 57 | void apply(); |
| 58 | void applyIfNeeded(); |
| 59 | |
| 60 | bool isCurrentScissorBoxEmpty() const { return clipState.scissorBox.isEmpty(); } |
| 61 | |
| 62 | private: |
| 63 | Vector<State> clipStack; |
| 64 | State clipState; |
| 65 | IntSize size; |
| 66 | bool clipStateDirty { false }; |
| 67 | YAxisMode yAxisMode { YAxisMode::Default }; |
| 68 | }; |
| 69 | |
| 70 | } // namespace WebCore |
| 71 | |
| 72 | #endif // ClipStack_h |
| 73 | |