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.
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.
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.
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.
23 #include "ClipStack.h"
25 #include "GraphicsContext3D.h"
29 void ClipStack::push()
31 clipStack.append(clipState);
32 clipStateDirty = true;
37 if (clipStack.isEmpty())
39 clipState = clipStack.last();
40 clipStack.removeLast();
41 clipStateDirty = true;
44 void ClipStack::reset(const IntRect& rect, ClipStack::YAxisMode mode)
49 clipState = State(rect);
50 clipStateDirty = true;
53 void ClipStack::intersect(const IntRect& rect)
55 clipState.scissorBox.intersect(rect);
56 clipStateDirty = true;
59 void ClipStack::setStencilIndex(int stencilIndex)
61 clipState.stencilIndex = stencilIndex;
62 clipStateDirty = true;
65 void ClipStack::apply(GraphicsContext3D& context)
67 if (clipState.scissorBox.isEmpty())
70 context.scissor(clipState.scissorBox.x(),
71 (yAxisMode == YAxisMode::Inverted) ? size.height() - clipState.scissorBox.maxY() : clipState.scissorBox.y(),
72 clipState.scissorBox.width(), clipState.scissorBox.height());
73 context.stencilOp(GraphicsContext3D::KEEP, GraphicsContext3D::KEEP, GraphicsContext3D::KEEP);
74 context.stencilFunc(GraphicsContext3D::EQUAL, clipState.stencilIndex - 1, clipState.stencilIndex - 1);
75 if (clipState.stencilIndex == 1)
76 context.disable(GraphicsContext3D::STENCIL_TEST);
78 context.enable(GraphicsContext3D::STENCIL_TEST);
81 void ClipStack::applyIfNeeded(GraphicsContext3D& context)
86 clipStateDirty = false;
90 } // namespace WebCore