Backed out 2 changesets (bug 903746) for causing non-unified build bustages on nsIPri...
[gecko.git] / layout / painting / MatrixStack.h
blob320d08317b7eba7f9cdfac9740c86fb4d43e44e0
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/. */
7 #ifndef MOZILLA_PAINTING_MATRIXSTACK_H
8 #define MOZILLA_PAINTING_MATRIXSTACK_H
10 #include "nsTArray.h"
11 #include "mozilla/gfx/MatrixFwd.h"
13 namespace mozilla {
15 /**
16 * MatrixStack stores a stack of matrices and keeps track of the accumulated
17 * transform matrix.
19 template <typename T>
20 class MatrixStack {
21 public:
22 MatrixStack() = default;
24 ~MatrixStack() { MOZ_ASSERT(mMatrices.IsEmpty()); }
26 /**
27 * Returns the current accumulated transform matrix.
29 const T& CurrentMatrix() const { return mCurrentMatrix; }
31 /**
32 * Returns true if any matrices are currently pushed to the stack.
34 bool HasTransform() const { return mMatrices.Length() > 0; }
36 /**
37 * Pushes the given |aMatrix| to the stack.
39 void Push(const T& aMatrix) {
40 mMatrices.AppendElement(mCurrentMatrix);
41 mCurrentMatrix = aMatrix * mCurrentMatrix;
44 /**
45 * Pops the most recently added matrix from the stack.
47 void Pop() {
48 MOZ_ASSERT(mMatrices.Length() > 0);
49 mCurrentMatrix = mMatrices.PopLastElement();
52 private:
53 T mCurrentMatrix;
54 AutoTArray<T, 2> mMatrices;
57 typedef MatrixStack<gfx::Matrix4x4Flagged> MatrixStack4x4;
59 } // namespace mozilla
61 #endif /* MOZILLA_PAINTING_MATRIXSTACK_H */