no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / gfx / 2d / Helpers.h
blob349e99973ac196a319dc534588ddc089826b1eb2
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_GFX_2D_HELPERS_H_
8 #define MOZILLA_GFX_2D_HELPERS_H_
10 #include "2D.h"
12 namespace mozilla {
13 namespace gfx {
15 class AutoRestoreTransform final {
16 public:
17 AutoRestoreTransform() = default;
19 explicit AutoRestoreTransform(DrawTarget* aTarget)
20 : mDrawTarget(aTarget), mOldTransform(aTarget->GetTransform()) {}
22 void Init(DrawTarget* aTarget) {
23 MOZ_ASSERT(!mDrawTarget || aTarget == mDrawTarget);
24 if (!mDrawTarget) {
25 mDrawTarget = aTarget;
26 mOldTransform = aTarget->GetTransform();
30 ~AutoRestoreTransform() {
31 if (mDrawTarget) {
32 mDrawTarget->SetTransform(mOldTransform);
36 private:
37 RefPtr<DrawTarget> mDrawTarget;
38 Matrix mOldTransform;
41 class AutoPopClips final {
42 public:
43 explicit AutoPopClips(DrawTarget* aTarget)
44 : mDrawTarget(aTarget), mPushCount(0) {
45 MOZ_ASSERT(mDrawTarget);
48 ~AutoPopClips() { PopAll(); }
50 void PushClip(const Path* aPath) {
51 mDrawTarget->PushClip(aPath);
52 ++mPushCount;
55 void PushClipRect(const Rect& aRect) {
56 mDrawTarget->PushClipRect(aRect);
57 ++mPushCount;
60 void PopClip() {
61 MOZ_ASSERT(mPushCount > 0);
62 mDrawTarget->PopClip();
63 --mPushCount;
66 void PopAll() {
67 while (mPushCount-- > 0) {
68 mDrawTarget->PopClip();
72 private:
73 RefPtr<DrawTarget> mDrawTarget;
74 int32_t mPushCount;
77 } // namespace gfx
78 } // namespace mozilla
80 #endif // MOZILLA_GFX_2D_HELPERS_H_