/src/mozilla-central/layout/painting/MatrixStack.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_PAINTING_MATRIXSTACK_H |
8 | | #define MOZILLA_PAINTING_MATRIXSTACK_H |
9 | | |
10 | | #include "nsTArray.h" |
11 | | #include "mozilla/gfx/MatrixFwd.h" |
12 | | |
13 | | namespace mozilla { |
14 | | |
15 | | /** |
16 | | * MatrixStack stores a stack of matrices and keeps track of the accumulated |
17 | | * transform matrix. |
18 | | */ |
19 | | template<typename T> |
20 | | class MatrixStack |
21 | | { |
22 | | public: |
23 | 0 | MatrixStack() = default; |
24 | | |
25 | 0 | ~MatrixStack() { MOZ_ASSERT(mMatrices.IsEmpty()); } |
26 | | |
27 | | /** |
28 | | * Returns the current accumulated transform matrix. |
29 | | */ |
30 | 0 | const T& CurrentMatrix() const { return mCurrentMatrix; } |
31 | | |
32 | | /** |
33 | | * Returns true if any matrices are currently pushed to the stack. |
34 | | */ |
35 | 0 | bool HasTransform() const { return mMatrices.Length() > 0; } |
36 | | |
37 | | /** |
38 | | * Pushes the given |aMatrix| to the stack. |
39 | | */ |
40 | | void Push(const T& aMatrix) |
41 | 0 | { |
42 | 0 | mMatrices.AppendElement(mCurrentMatrix); |
43 | 0 | mCurrentMatrix = aMatrix * mCurrentMatrix; |
44 | 0 | } |
45 | | |
46 | | /** |
47 | | * Pops the most recently added matrix from the stack. |
48 | | */ |
49 | | void Pop() |
50 | 0 | { |
51 | 0 | MOZ_ASSERT(mMatrices.Length() > 0); |
52 | 0 | mCurrentMatrix = mMatrices.PopLastElement(); |
53 | 0 | } |
54 | | |
55 | | private: |
56 | | T mCurrentMatrix; |
57 | | AutoTArray<T, 2> mMatrices; |
58 | | }; |
59 | | |
60 | | typedef MatrixStack<gfx::Matrix4x4Flagged> MatrixStack4x4; |
61 | | |
62 | | } // namespace mozilla |
63 | | |
64 | | #endif /* MOZILLA_PAINTING_MATRIXSTACK_H */ |