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_
15 class AutoRestoreTransform final
{
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
);
25 mDrawTarget
= aTarget
;
26 mOldTransform
= aTarget
->GetTransform();
30 ~AutoRestoreTransform() {
32 mDrawTarget
->SetTransform(mOldTransform
);
37 RefPtr
<DrawTarget
> mDrawTarget
;
41 class AutoPopClips final
{
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
);
55 void PushClipRect(const Rect
& aRect
) {
56 mDrawTarget
->PushClipRect(aRect
);
61 MOZ_ASSERT(mPushCount
> 0);
62 mDrawTarget
->PopClip();
67 while (mPushCount
-- > 0) {
68 mDrawTarget
->PopClip();
73 RefPtr
<DrawTarget
> mDrawTarget
;
78 } // namespace mozilla
80 #endif // MOZILLA_GFX_2D_HELPERS_H_