| 1 | /* |
| 2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 3 | * Copyright (C) 2012 Adobe Systems Incorporated |
| 4 | * Copyright (C) 2012, 2016 Igalia S.L. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "ClipStack.h" |
| 24 | |
| 25 | #include "TextureMapperGLHeaders.h" |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | void ClipStack::push() |
| 30 | { |
| 31 | clipStack.append(clipState); |
| 32 | clipStateDirty = true; |
| 33 | } |
| 34 | |
| 35 | void ClipStack::pop() |
| 36 | { |
| 37 | if (clipStack.isEmpty()) |
| 38 | return; |
| 39 | clipState = clipStack.last(); |
| 40 | clipStack.removeLast(); |
| 41 | clipStateDirty = true; |
| 42 | } |
| 43 | |
| 44 | void ClipStack::reset(const IntRect& rect, ClipStack::YAxisMode mode) |
| 45 | { |
| 46 | clipStack.clear(); |
| 47 | size = rect.size(); |
| 48 | yAxisMode = mode; |
| 49 | clipState = State(rect); |
| 50 | clipStateDirty = true; |
| 51 | } |
| 52 | |
| 53 | void ClipStack::intersect(const IntRect& rect) |
| 54 | { |
| 55 | clipState.scissorBox.intersect(rect); |
| 56 | clipStateDirty = true; |
| 57 | } |
| 58 | |
| 59 | void ClipStack::setStencilIndex(int stencilIndex) |
| 60 | { |
| 61 | clipState.stencilIndex = stencilIndex; |
| 62 | clipStateDirty = true; |
| 63 | } |
| 64 | |
| 65 | void ClipStack::apply() |
| 66 | { |
| 67 | if (clipState.scissorBox.isEmpty()) |
| 68 | return; |
| 69 | |
| 70 | glScissor(clipState.scissorBox.x(), |
| 71 | (yAxisMode == YAxisMode::Inverted) ? size.height() - clipState.scissorBox.maxY() : clipState.scissorBox.y(), |
| 72 | clipState.scissorBox.width(), clipState.scissorBox.height()); |
| 73 | glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); |
| 74 | glStencilFunc(GL_EQUAL, clipState.stencilIndex - 1, clipState.stencilIndex - 1); |
| 75 | if (clipState.stencilIndex == 1) |
| 76 | glDisable(GL_STENCIL_TEST); |
| 77 | else |
| 78 | glEnable(GL_STENCIL_TEST); |
| 79 | } |
| 80 | |
| 81 | void ClipStack::applyIfNeeded() |
| 82 | { |
| 83 | if (!clipStateDirty) |
| 84 | return; |
| 85 | |
| 86 | clipStateDirty = false; |
| 87 | apply(); |
| 88 | } |
| 89 | |
| 90 | } // namespace WebCore |
| 91 | |