LCOV - code coverage report
Current view: top level - gfx/2d - Helpers.h (source / functions) Hit Total Coverage
Test: output.info Lines: 18 35 51.4 %
Date: 2017-07-14 16:53:18 Functions: 4 8 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef MOZILLA_GFX_2D_HELPERS_H_
       7             : #define MOZILLA_GFX_2D_HELPERS_H_
       8             : 
       9             : #include "2D.h"
      10             : 
      11             : namespace mozilla {
      12             : namespace gfx {
      13             : 
      14             : class AutoRestoreTransform
      15             : {
      16             :  public:
      17          34 :   AutoRestoreTransform()
      18          34 :   {
      19          34 :   }
      20             : 
      21          61 :   explicit AutoRestoreTransform(DrawTarget *aTarget)
      22          61 :    : mDrawTarget(aTarget),
      23          61 :      mOldTransform(aTarget->GetTransform())
      24             :   {
      25          61 :   }
      26             : 
      27          34 :   void Init(DrawTarget *aTarget)
      28             :   {
      29          34 :     MOZ_ASSERT(!mDrawTarget || aTarget == mDrawTarget);
      30          34 :     if (!mDrawTarget) {
      31          34 :       mDrawTarget = aTarget;
      32          34 :       mOldTransform = aTarget->GetTransform();
      33             :     }
      34          34 :   }
      35             : 
      36          95 :   ~AutoRestoreTransform()
      37          95 :   {
      38          95 :     if (mDrawTarget) {
      39          95 :       mDrawTarget->SetTransform(mOldTransform);
      40             :     }
      41          95 :   }
      42             : 
      43             :  private:
      44             :   RefPtr<DrawTarget> mDrawTarget;
      45             :   Matrix mOldTransform;
      46             : };
      47             : 
      48             : class AutoPopClips
      49             : {
      50             : public:
      51           0 :   explicit AutoPopClips(DrawTarget *aTarget)
      52           0 :     : mDrawTarget(aTarget)
      53           0 :     , mPushCount(0)
      54             :   {
      55           0 :     MOZ_ASSERT(mDrawTarget);
      56           0 :   }
      57             : 
      58           0 :   ~AutoPopClips()
      59           0 :   {
      60           0 :     PopAll();
      61           0 :   }
      62             : 
      63             :   void PushClip(const Path *aPath)
      64             :   {
      65             :     mDrawTarget->PushClip(aPath);
      66             :     ++mPushCount;
      67             :   }
      68             : 
      69           0 :   void PushClipRect(const Rect &aRect)
      70             :   {
      71           0 :     mDrawTarget->PushClipRect(aRect);
      72           0 :     ++mPushCount;
      73           0 :   }
      74             : 
      75             :   void PopClip()
      76             :   {
      77             :     MOZ_ASSERT(mPushCount > 0);
      78             :     mDrawTarget->PopClip();
      79             :     --mPushCount;
      80             :   }
      81             : 
      82           0 :   void PopAll()
      83             :   {
      84           0 :     while (mPushCount-- > 0) {
      85           0 :       mDrawTarget->PopClip();
      86             :     }
      87           0 :   }
      88             : 
      89             : private:
      90             :   RefPtr<DrawTarget> mDrawTarget;
      91             :   int32_t mPushCount;
      92             : };
      93             : 
      94             : } // namespace gfx
      95             : } // namespace mozilla
      96             : 
      97             : #endif // MOZILLA_GFX_2D_HELPERS_H_

Generated by: LCOV version 1.13