/work/obj-fuzz/dist/include/mozilla/gfx/Helpers.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_GFX_2D_HELPERS_H_ |
8 | | #define MOZILLA_GFX_2D_HELPERS_H_ |
9 | | |
10 | | #include "2D.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace gfx { |
14 | | |
15 | | class AutoRestoreTransform |
16 | | { |
17 | | public: |
18 | | AutoRestoreTransform() |
19 | 0 | { |
20 | 0 | } |
21 | | |
22 | | explicit AutoRestoreTransform(DrawTarget *aTarget) |
23 | | : mDrawTarget(aTarget), |
24 | | mOldTransform(aTarget->GetTransform()) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | void Init(DrawTarget *aTarget) |
29 | 0 | { |
30 | 0 | MOZ_ASSERT(!mDrawTarget || aTarget == mDrawTarget); |
31 | 0 | if (!mDrawTarget) { |
32 | 0 | mDrawTarget = aTarget; |
33 | 0 | mOldTransform = aTarget->GetTransform(); |
34 | 0 | } |
35 | 0 | } |
36 | | |
37 | | ~AutoRestoreTransform() |
38 | 0 | { |
39 | 0 | if (mDrawTarget) { |
40 | 0 | mDrawTarget->SetTransform(mOldTransform); |
41 | 0 | } |
42 | 0 | } |
43 | | |
44 | | private: |
45 | | RefPtr<DrawTarget> mDrawTarget; |
46 | | Matrix mOldTransform; |
47 | | }; |
48 | | |
49 | | class AutoPopClips |
50 | | { |
51 | | public: |
52 | | explicit AutoPopClips(DrawTarget *aTarget) |
53 | | : mDrawTarget(aTarget) |
54 | | , mPushCount(0) |
55 | 0 | { |
56 | 0 | MOZ_ASSERT(mDrawTarget); |
57 | 0 | } |
58 | | |
59 | | ~AutoPopClips() |
60 | 0 | { |
61 | 0 | PopAll(); |
62 | 0 | } |
63 | | |
64 | | void PushClip(const Path *aPath) |
65 | 0 | { |
66 | 0 | mDrawTarget->PushClip(aPath); |
67 | 0 | ++mPushCount; |
68 | 0 | } |
69 | | |
70 | | void PushClipRect(const Rect &aRect) |
71 | 0 | { |
72 | 0 | mDrawTarget->PushClipRect(aRect); |
73 | 0 | ++mPushCount; |
74 | 0 | } |
75 | | |
76 | | void PopClip() |
77 | 0 | { |
78 | 0 | MOZ_ASSERT(mPushCount > 0); |
79 | 0 | mDrawTarget->PopClip(); |
80 | 0 | --mPushCount; |
81 | 0 | } |
82 | | |
83 | | void PopAll() |
84 | 0 | { |
85 | 0 | while (mPushCount-- > 0) { |
86 | 0 | mDrawTarget->PopClip(); |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | | private: |
91 | | RefPtr<DrawTarget> mDrawTarget; |
92 | | int32_t mPushCount; |
93 | | }; |
94 | | |
95 | | } // namespace gfx |
96 | | } // namespace mozilla |
97 | | |
98 | | #endif // MOZILLA_GFX_2D_HELPERS_H_ |