LCOV - code coverage report
Current view: top level - gfx/thebes - gfxContext.h (source / functions) Hit Total Coverage
Test: output.info Lines: 58 74 78.4 %
Date: 2017-07-14 16:53:18 Functions: 28 32 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       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 GFX_CONTEXT_H
       7             : #define GFX_CONTEXT_H
       8             : 
       9             : #include "gfxTypes.h"
      10             : 
      11             : #include "gfxASurface.h"
      12             : #include "gfxPoint.h"
      13             : #include "gfxRect.h"
      14             : #include "gfxMatrix.h"
      15             : #include "gfxPattern.h"
      16             : #include "nsTArray.h"
      17             : 
      18             : #include "mozilla/gfx/2D.h"
      19             : 
      20             : typedef struct _cairo cairo_t;
      21             : class GlyphBufferAzure;
      22             : 
      23             : namespace mozilla {
      24             : namespace gfx {
      25             : struct RectCornerRadii;
      26             : } // namespace gfx
      27             : } // namespace mozilla
      28             : 
      29             : class ClipExporter;
      30             : 
      31             : /**
      32             :  * This is the main class for doing actual drawing. It is initialized using
      33             :  * a surface and can be drawn on. It manages various state information like
      34             :  * a current transformation matrix (CTM), a current path, current color,
      35             :  * etc.
      36             :  *
      37             :  * All drawing happens by creating a path and then stroking or filling it.
      38             :  * The functions like Rectangle and Arc do not do any drawing themselves.
      39             :  * When a path is drawn (stroked or filled), it is filled/stroked with a
      40             :  * pattern set by SetPattern, SetColor or SetSource.
      41             :  *
      42             :  * Note that the gfxContext takes coordinates in device pixels,
      43             :  * as opposed to app units.
      44             :  */
      45             : class gfxContext final {
      46             :     typedef mozilla::gfx::CapStyle CapStyle;
      47             :     typedef mozilla::gfx::CompositionOp CompositionOp;
      48             :     typedef mozilla::gfx::JoinStyle JoinStyle;
      49             :     typedef mozilla::gfx::FillRule FillRule;
      50             :     typedef mozilla::gfx::Path Path;
      51             :     typedef mozilla::gfx::Pattern Pattern;
      52             :     typedef mozilla::gfx::Rect Rect;
      53             :     typedef mozilla::gfx::RectCornerRadii RectCornerRadii;
      54             :     typedef mozilla::gfx::Size Size;
      55             : 
      56        1119 :     NS_INLINE_DECL_REFCOUNTING(gfxContext)
      57             : 
      58             : public:
      59             :     /**
      60             :      * Initialize this context from a DrawTarget.
      61             :      * Strips any transform from aTarget.
      62             :      * aTarget will be flushed in the gfxContext's destructor.
      63             :      * If aTarget is null or invalid, nullptr is returned.  The caller
      64             :      * is responsible for handling this scenario as appropriate.
      65             :      */
      66             :     static already_AddRefed<gfxContext>
      67             :         CreateOrNull(mozilla::gfx::DrawTarget* aTarget,
      68             :                      const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point());
      69             : 
      70             :     /**
      71             :      * Create a new gfxContext wrapping aTarget and preserving aTarget's
      72             :      * transform. Note that the transform is moved from aTarget to the resulting
      73             :      * gfxContext, aTarget will no longer have its transform.
      74             :      * If aTarget is null or invalid, nullptr is returned.  The caller
      75             :      * is responsible for handling this scenario as appropriate.
      76             :      */
      77             :     static already_AddRefed<gfxContext>
      78             :         CreatePreservingTransformOrNull(mozilla::gfx::DrawTarget* aTarget);
      79             : 
      80        1264 :     mozilla::gfx::DrawTarget *GetDrawTarget() { return mDT; }
      81             : 
      82             :     /**
      83             :      ** State
      84             :      **/
      85             :     // XXX document exactly what bits are saved
      86             :     void Save();
      87             :     void Restore();
      88             : 
      89             :     /**
      90             :      ** Paths & Drawing
      91             :      **/
      92             : 
      93             :     /**
      94             :      * Fill the current path according to the current settings.
      95             :      *
      96             :      * Does not consume the current path.
      97             :      */
      98             :     void Fill();
      99             :     void Fill(const Pattern& aPattern);
     100             : 
     101             :     /**
     102             :      * Forgets the current path.
     103             :      */
     104             :     void NewPath();
     105             : 
     106             :     /**
     107             :      * Closes the path, i.e. connects the last drawn point to the first one.
     108             :      *
     109             :      * Filling a path will implicitly close it.
     110             :      */
     111             :     void ClosePath();
     112             : 
     113             :     /**
     114             :      * Returns the current path.
     115             :      */
     116             :     already_AddRefed<Path> GetPath();
     117             : 
     118             :     /**
     119             :      * Sets the given path as the current path.
     120             :      */
     121             :     void SetPath(Path* path);
     122             : 
     123             :     /**
     124             :      * Moves the pen to a new point without drawing a line.
     125             :      */
     126             :     void MoveTo(const gfxPoint& pt);
     127             : 
     128             :     /**
     129             :      * Returns the current point in the current path.
     130             :      */
     131             :     gfxPoint CurrentPoint();
     132             : 
     133             :     /**
     134             :      * Draws a line from the current point to pt.
     135             :      *
     136             :      * @see MoveTo
     137             :      */
     138             :     void LineTo(const gfxPoint& pt);
     139             : 
     140             :     // path helpers
     141             :     /**
     142             :      * Draws a line from start to end.
     143             :      */
     144             :     void Line(const gfxPoint& start, const gfxPoint& end); // XXX snapToPixels option?
     145             : 
     146             :     /**
     147             :      * Draws the rectangle given by rect.
     148             :      * @param snapToPixels ?
     149             :      */
     150             :     void Rectangle(const gfxRect& rect, bool snapToPixels = false);
     151          22 :     void SnappedRectangle(const gfxRect& rect) { return Rectangle(rect, true); }
     152             : 
     153             :     /**
     154             :      ** Transformation Matrix manipulation
     155             :      **/
     156             : 
     157             :     /**
     158             :      * Post-multiplies 'other' onto the current CTM, i.e. this
     159             :      * matrix's transformation will take place before the previously set
     160             :      * transformations.
     161             :      */
     162             :     void Multiply(const gfxMatrix& other);
     163             : 
     164             :     /**
     165             :      * Replaces the current transformation matrix with matrix.
     166             :      */
     167             :     void SetMatrix(const gfxMatrix& matrix);
     168             : 
     169             :     /**
     170             :      * Returns the current transformation matrix.
     171             :      */
     172             :     gfxMatrix CurrentMatrix() const;
     173             : 
     174             :     /**
     175             :      * Converts a point from device to user coordinates using the inverse
     176             :      * transformation matrix.
     177             :      */
     178             :     gfxPoint DeviceToUser(const gfxPoint& point) const;
     179             : 
     180             :     /**
     181             :      * Converts a size from device to user coordinates. This does not apply
     182             :      * translation components of the matrix.
     183             :      */
     184             :     Size DeviceToUser(const Size& size) const;
     185             : 
     186             :     /**
     187             :      * Converts a rectangle from device to user coordinates; this has the
     188             :      * same effect as using DeviceToUser on both the rectangle's point and
     189             :      * size.
     190             :      */
     191             :     gfxRect DeviceToUser(const gfxRect& rect) const;
     192             : 
     193             :     /**
     194             :      * Converts a point from user to device coordinates using the transformation
     195             :      * matrix.
     196             :      */
     197             :     gfxPoint UserToDevice(const gfxPoint& point) const;
     198             : 
     199             :     /**
     200             :      * Converts a size from user to device coordinates. This does not apply
     201             :      * translation components of the matrix.
     202             :      */
     203             :     Size UserToDevice(const Size& size) const;
     204             : 
     205             :     /**
     206             :      * Converts a rectangle from user to device coordinates.  The
     207             :      * resulting rectangle is the minimum device-space rectangle that
     208             :      * encloses the user-space rectangle given.
     209             :      */
     210             :     gfxRect UserToDevice(const gfxRect& rect) const;
     211             : 
     212             :     /**
     213             :      * Takes the given rect and tries to align it to device pixels.  If
     214             :      * this succeeds, the method will return true, and the rect will
     215             :      * be in device coordinates (already transformed by the CTM).  If it
     216             :      * fails, the method will return false, and the rect will not be
     217             :      * changed.
     218             :      *
     219             :      * If ignoreScale is true, then snapping will take place even if
     220             :      * the CTM has a scale applied.  Snapping never takes place if
     221             :      * there is a rotation in the CTM.
     222             :      */
     223             :     bool UserToDevicePixelSnapped(gfxRect& rect, bool ignoreScale = false) const;
     224             : 
     225             :     /**
     226             :      * Takes the given point and tries to align it to device pixels.  If
     227             :      * this succeeds, the method will return true, and the point will
     228             :      * be in device coordinates (already transformed by the CTM).  If it
     229             :      * fails, the method will return false, and the point will not be
     230             :      * changed.
     231             :      *
     232             :      * If ignoreScale is true, then snapping will take place even if
     233             :      * the CTM has a scale applied.  Snapping never takes place if
     234             :      * there is a rotation in the CTM.
     235             :      */
     236             :     bool UserToDevicePixelSnapped(gfxPoint& pt, bool ignoreScale = false) const;
     237             : 
     238             :     /**
     239             :      ** Painting sources
     240             :      **/
     241             : 
     242             :     /**
     243             :      * Set a solid color to use for drawing.  This color is in the device color space
     244             :      * and is not transformed.
     245             :      */
     246             :     void SetDeviceColor(const mozilla::gfx::Color& aColor);
     247             : 
     248             :     /**
     249             :      * Gets the current color.  It's returned in the device color space.
     250             :      * returns false if there is something other than a color
     251             :      *         set as the current source (pattern, surface, etc)
     252             :      */
     253             :     bool GetDeviceColor(mozilla::gfx::Color& aColorOut);
     254             : 
     255             :     /**
     256             :      * Set a solid color in the sRGB color space to use for drawing.
     257             :      * If CMS is not enabled, the color is treated as a device-space color
     258             :      * and this call is identical to SetDeviceColor().
     259             :      */
     260             :     void SetColor(const mozilla::gfx::Color& aColor);
     261             : 
     262             :     /**
     263             :      * Uses a surface for drawing. This is a shorthand for creating a
     264             :      * pattern and setting it.
     265             :      *
     266             :      * @param offset from the source surface, to use only part of it.
     267             :      *        May need to make it negative.
     268             :      */
     269             :     void SetSource(gfxASurface *surface, const gfxPoint& offset = gfxPoint(0.0, 0.0));
     270             : 
     271             :     /**
     272             :      * Uses a pattern for drawing.
     273             :      */
     274             :     void SetPattern(gfxPattern *pattern);
     275             : 
     276             :     /**
     277             :      * Set the color that text drawn on top of transparent pixels should be
     278             :      * anti-aliased into.
     279             :      */
     280             :     void SetFontSmoothingBackgroundColor(const mozilla::gfx::Color& aColor);
     281             :     mozilla::gfx::Color GetFontSmoothingBackgroundColor();
     282             : 
     283             :     /**
     284             :      * Get the source pattern (solid color, normal pattern, surface, etc)
     285             :      */
     286             :     already_AddRefed<gfxPattern> GetPattern();
     287             : 
     288             :     /**
     289             :      ** Painting
     290             :      **/
     291             :     /**
     292             :      * Paints the current source surface/pattern everywhere in the current
     293             :      * clip region.
     294             :      */
     295             :     void Paint(gfxFloat alpha = 1.0);
     296             : 
     297             :     /**
     298             :      ** Painting with a Mask
     299             :      **/
     300             :     /**
     301             :      * Like Paint, except that it only draws the source where pattern is
     302             :      * non-transparent.
     303             :      */
     304             :     void Mask(mozilla::gfx::SourceSurface *aSurface, mozilla::gfx::Float aAlpha, const mozilla::gfx::Matrix& aTransform);
     305             :     void Mask(mozilla::gfx::SourceSurface *aSurface, const mozilla::gfx::Matrix& aTransform) { Mask(aSurface, 1.0f, aTransform); }
     306             :     void Mask(mozilla::gfx::SourceSurface *surface, float alpha = 1.0f, const mozilla::gfx::Point& offset = mozilla::gfx::Point());
     307             : 
     308             :     /**
     309             :      ** Line Properties
     310             :      **/
     311             : 
     312             :     void SetDash(gfxFloat *dashes, int ndash, gfxFloat offset);
     313             :     // Return true if dashing is set, false if it's not enabled or the
     314             :     // context is in an error state.  |offset| can be nullptr to mean
     315             :     // "don't care".
     316             :     bool CurrentDash(FallibleTArray<gfxFloat>& dashes, gfxFloat* offset) const;
     317             :     // Returns 0.0 if dashing isn't enabled.
     318             :     gfxFloat CurrentDashOffset() const;
     319             : 
     320             :     /**
     321             :      * Sets the line width that's used for line drawing.
     322             :      */
     323             :     void SetLineWidth(gfxFloat width);
     324             : 
     325             :     /**
     326             :      * Returns the currently set line width.
     327             :      *
     328             :      * @see SetLineWidth
     329             :      */
     330             :     gfxFloat CurrentLineWidth() const;
     331             : 
     332             :     /**
     333             :      * Sets the line caps, i.e. how line endings are drawn.
     334             :      */
     335             :     void SetLineCap(CapStyle cap);
     336             :     CapStyle CurrentLineCap() const;
     337             : 
     338             :     /**
     339             :      * Sets the line join, i.e. how the connection between two lines is
     340             :      * drawn.
     341             :      */
     342             :     void SetLineJoin(JoinStyle join);
     343             :     JoinStyle CurrentLineJoin() const;
     344             : 
     345             :     void SetMiterLimit(gfxFloat limit);
     346             :     gfxFloat CurrentMiterLimit() const;
     347             : 
     348             :     /**
     349             :      * Sets the operator used for all further drawing. The operator affects
     350             :      * how drawing something will modify the destination. For example, the
     351             :      * OVER operator will do alpha blending of source and destination, while
     352             :      * SOURCE will replace the destination with the source.
     353             :      */
     354             :     void SetOp(CompositionOp op);
     355             :     CompositionOp CurrentOp() const;
     356             : 
     357             :     void SetAntialiasMode(mozilla::gfx::AntialiasMode mode);
     358             :     mozilla::gfx::AntialiasMode CurrentAntialiasMode() const;
     359             : 
     360             :     /**
     361             :      ** Clipping
     362             :      **/
     363             : 
     364             :     /**
     365             :      * Clips all further drawing to the current path.
     366             :      * This does not consume the current path.
     367             :      */
     368             :     void Clip();
     369             : 
     370             :     /**
     371             :      * Helper functions that will create a rect path and call Clip().
     372             :      * Any current path will be destroyed by these functions!
     373             :      */
     374             :     void Clip(const Rect& rect);
     375             :     void Clip(const gfxRect& rect); // will clip to a rect
     376             :     void Clip(Path* aPath);
     377             : 
     378             :     void PopClip();
     379             : 
     380             :     /**
     381             :      * This will return the current bounds of the clip region in user
     382             :      * space.
     383             :      */
     384             :     gfxRect GetClipExtents();
     385             : 
     386             :     /**
     387             :      * Whether the current clip is not a simple rectangle.
     388             :      */
     389             :     bool HasComplexClip() const;
     390             : 
     391             :     /**
     392             :      * Returns true if the given rectangle is fully contained in the current clip.
     393             :      * This is conservative; it may return false even when the given rectangle is
     394             :      * fully contained by the current clip.
     395             :      */
     396             :     bool ClipContainsRect(const gfxRect& aRect);
     397             : 
     398             :      /**
     399             :       * Exports the current clip using the provided exporter.
     400             :       */
     401             :     bool ExportClip(ClipExporter& aExporter);
     402             : 
     403             :     /**
     404             :      * Groups
     405             :      */
     406             :     void PushGroupForBlendBack(gfxContentType content, mozilla::gfx::Float aOpacity = 1.0f,
     407             :                                mozilla::gfx::SourceSurface* aMask = nullptr,
     408             :                                const mozilla::gfx::Matrix& aMaskTransform = mozilla::gfx::Matrix());
     409             : 
     410             :     /**
     411             :      * Like PushGroupForBlendBack, but if the current surface is gfxContentType::COLOR and
     412             :      * content is gfxContentType::COLOR_ALPHA, makes the pushed surface gfxContentType::COLOR
     413             :      * instead and copies the contents of the current surface to the pushed
     414             :      * surface. This is good for pushing opacity groups, since blending the
     415             :      * group back to the current surface with some alpha applied will give
     416             :      * the correct results and using an opaque pushed surface gives better
     417             :      * quality and performance.
     418             :      */
     419             :     void PushGroupAndCopyBackground(gfxContentType content = gfxContentType::COLOR,
     420             :                                     mozilla::gfx::Float aOpacity = 1.0f,
     421             :                                     mozilla::gfx::SourceSurface* aMask = nullptr,
     422             :                                     const mozilla::gfx::Matrix& aMaskTransform = mozilla::gfx::Matrix());
     423             :     void PopGroupAndBlend();
     424             : 
     425             :     mozilla::gfx::Point GetDeviceOffset() const;
     426             : 
     427             : #ifdef MOZ_DUMP_PAINTING
     428             :     /**
     429             :      * Debug functions to encode the current surface as a PNG and export it.
     430             :      */
     431             : 
     432             :     /**
     433             :      * Writes a binary PNG file.
     434             :      */
     435             :     void WriteAsPNG(const char* aFile);
     436             : 
     437             :     /**
     438             :      * Write as a PNG encoded Data URL to stdout.
     439             :      */
     440             :     void DumpAsDataURI();
     441             : 
     442             :     /**
     443             :      * Copy a PNG encoded Data URL to the clipboard.
     444             :      */
     445             :     void CopyAsDataURI();
     446             : #endif
     447             : 
     448             :     static mozilla::gfx::UserDataKey sDontUseAsSourceKey;
     449             : 
     450             : private:
     451             : 
     452             :     /**
     453             :      * Initialize this context from a DrawTarget.
     454             :      * Strips any transform from aTarget.
     455             :      * aTarget will be flushed in the gfxContext's destructor.  Use the static
     456             :      * ContextForDrawTargetNoTransform() when you want this behavior, as that
     457             :      * version deals with null DrawTarget better.
     458             :      */
     459             :     explicit gfxContext(mozilla::gfx::DrawTarget *aTarget,
     460             :                         const mozilla::gfx::Point& aDeviceOffset = mozilla::gfx::Point());
     461             :     ~gfxContext();
     462             : 
     463             :   friend class PatternFromState;
     464             :   friend class GlyphBufferAzure;
     465             : 
     466             :   typedef mozilla::gfx::Matrix Matrix;
     467             :   typedef mozilla::gfx::DrawTarget DrawTarget;
     468             :   typedef mozilla::gfx::Color Color;
     469             :   typedef mozilla::gfx::StrokeOptions StrokeOptions;
     470             :   typedef mozilla::gfx::Float Float;
     471             :   typedef mozilla::gfx::PathBuilder PathBuilder;
     472             :   typedef mozilla::gfx::SourceSurface SourceSurface;
     473             : 
     474        1647 :   struct AzureState {
     475         151 :     AzureState()
     476         151 :       : op(mozilla::gfx::CompositionOp::OP_OVER)
     477             :       , color(0, 0, 0, 1.0f)
     478             :       , aaMode(mozilla::gfx::AntialiasMode::SUBPIXEL)
     479             :       , patternTransformChanged(false)
     480         151 :       , mBlendOpacity(0.0f)
     481         151 :     {}
     482             : 
     483             :     mozilla::gfx::CompositionOp op;
     484             :     Color color;
     485             :     RefPtr<gfxPattern> pattern;
     486             :     RefPtr<gfxASurface> sourceSurfCairo;
     487             :     RefPtr<SourceSurface> sourceSurface;
     488             :     mozilla::gfx::Point sourceSurfaceDeviceOffset;
     489             :     Matrix surfTransform;
     490             :     Matrix transform;
     491        1839 :     struct PushedClip {
     492             :       RefPtr<Path> path;
     493             :       Rect rect;
     494             :       Matrix transform;
     495             :     };
     496             :     nsTArray<PushedClip> pushedClips;
     497             :     nsTArray<Float> dashPattern;
     498             :     StrokeOptions strokeOptions;
     499             :     RefPtr<DrawTarget> drawTarget;
     500             :     mozilla::gfx::AntialiasMode aaMode;
     501             :     bool patternTransformChanged;
     502             :     Matrix patternTransform;
     503             :     Color fontSmoothingBackgroundColor;
     504             :     // This is used solely for using minimal intermediate surface size.
     505             :     mozilla::gfx::Point deviceOffset;
     506             :     // Support groups
     507             :     mozilla::gfx::Float mBlendOpacity;
     508             :     RefPtr<SourceSurface> mBlendMask;
     509             :     Matrix mBlendMaskTransform;
     510             : #ifdef DEBUG
     511             :     bool mWasPushedForBlendBack;
     512             : #endif
     513             :   };
     514             : 
     515             :   // This ensures mPath contains a valid path (in user space!)
     516             :   void EnsurePath();
     517             :   // This ensures mPathBuilder contains a valid PathBuilder (in user space!)
     518             :   void EnsurePathBuilder();
     519             :   void FillAzure(const Pattern& aPattern, mozilla::gfx::Float aOpacity);
     520             :   CompositionOp GetOp();
     521             :   void ChangeTransform(const mozilla::gfx::Matrix &aNewMatrix, bool aUpdatePatternTransform = true);
     522             :   Rect GetAzureDeviceSpaceClipBounds();
     523             :   Matrix GetDeviceTransform() const;
     524             :   Matrix GetDTTransform() const;
     525             : 
     526             :   bool mPathIsRect;
     527             :   bool mTransformChanged;
     528             :   Matrix mPathTransform;
     529             :   Rect mRect;
     530             :   RefPtr<PathBuilder> mPathBuilder;
     531             :   RefPtr<Path> mPath;
     532             :   Matrix mTransform;
     533             :   nsTArray<AzureState> mStateStack;
     534             : 
     535        6276 :   AzureState &CurrentState() { return mStateStack[mStateStack.Length() - 1]; }
     536        3733 :   const AzureState &CurrentState() const { return mStateStack[mStateStack.Length() - 1]; }
     537             : 
     538             :   RefPtr<DrawTarget> mDT;
     539             : };
     540             : 
     541             : /**
     542             :  * Sentry helper class for functions with multiple return points that need to
     543             :  * call Save() on a gfxContext and have Restore() called automatically on the
     544             :  * gfxContext before they return.
     545             :  */
     546             : class gfxContextAutoSaveRestore
     547             : {
     548             : public:
     549         209 :   gfxContextAutoSaveRestore() : mContext(nullptr) {}
     550             : 
     551          46 :   explicit gfxContextAutoSaveRestore(gfxContext *aContext) : mContext(aContext) {
     552          46 :     mContext->Save();
     553          46 :   }
     554             : 
     555         510 :   ~gfxContextAutoSaveRestore() {
     556         255 :     Restore();
     557         255 :   }
     558             : 
     559          22 :   void SetContext(gfxContext *aContext) {
     560          22 :     NS_ASSERTION(!mContext, "Not going to call Restore() on some context!!!");
     561          22 :     mContext = aContext;
     562          22 :     mContext->Save();
     563          22 :   }
     564             : 
     565           0 :   void EnsureSaved(gfxContext *aContext) {
     566           0 :     MOZ_ASSERT(!mContext || mContext == aContext, "wrong context");
     567           0 :     if (!mContext) {
     568           0 :         mContext = aContext;
     569           0 :         mContext->Save();
     570             :     }
     571           0 :   }
     572             : 
     573         255 :   void Restore() {
     574         255 :     if (mContext) {
     575          68 :       mContext->Restore();
     576          68 :       mContext = nullptr;
     577             :     }
     578         255 :   }
     579             : 
     580             : private:
     581             :   gfxContext *mContext;
     582             : };
     583             : 
     584             : /**
     585             :  * Sentry helper class for functions with multiple return points that need to
     586             :  * back up the current matrix of a context and have it automatically restored
     587             :  * before they return.
     588             :  */
     589             : class gfxContextMatrixAutoSaveRestore
     590             : {
     591             : public:
     592          41 :     gfxContextMatrixAutoSaveRestore() :
     593          41 :       mContext(nullptr)
     594             :     {
     595          41 :     }
     596             : 
     597         458 :     explicit gfxContextMatrixAutoSaveRestore(gfxContext *aContext) :
     598         458 :       mContext(aContext), mMatrix(aContext->CurrentMatrix())
     599             :     {
     600         458 :     }
     601             : 
     602         499 :     ~gfxContextMatrixAutoSaveRestore()
     603         499 :     {
     604         499 :       if (mContext) {
     605         461 :         mContext->SetMatrix(mMatrix);
     606             :       }
     607         499 :     }
     608             : 
     609           3 :     void SetContext(gfxContext *aContext)
     610             :     {
     611           3 :       NS_ASSERTION(!mContext,
     612             :                    "Not going to restore the matrix on some context!");
     613           3 :       mContext = aContext;
     614           3 :       mMatrix = aContext->CurrentMatrix();
     615           3 :     }
     616             : 
     617           0 :     void Restore()
     618             :     {
     619           0 :       if (mContext) {
     620           0 :         mContext->SetMatrix(mMatrix);
     621           0 :         mContext = nullptr;
     622             :       }
     623           0 :     }
     624             : 
     625           5 :     const gfxMatrix& Matrix()
     626             :     {
     627           5 :       MOZ_ASSERT(mContext, "mMatrix doesn't contain a useful matrix");
     628           5 :       return mMatrix;
     629             :     }
     630             : 
     631           0 :     bool HasMatrix() const { return !!mContext; }
     632             : 
     633             : private:
     634             :     gfxContext *mContext;
     635             :     gfxMatrix   mMatrix;
     636             : };
     637             : 
     638             : 
     639             : class DrawTargetAutoDisableSubpixelAntialiasing {
     640             : public:
     641             :     typedef mozilla::gfx::DrawTarget DrawTarget;
     642             : 
     643          20 :     DrawTargetAutoDisableSubpixelAntialiasing(DrawTarget *aDT, bool aDisable)
     644          20 :     {
     645          20 :         if (aDisable) {
     646           0 :             mDT = aDT;
     647           0 :             mSubpixelAntialiasingEnabled = mDT->GetPermitSubpixelAA();
     648           0 :             mDT->SetPermitSubpixelAA(false);
     649             :         }
     650          20 :     }
     651          20 :     ~DrawTargetAutoDisableSubpixelAntialiasing()
     652          20 :     {
     653          20 :         if (mDT) {
     654           0 :             mDT->SetPermitSubpixelAA(mSubpixelAntialiasingEnabled);
     655             :         }
     656          20 :     }
     657             : 
     658             : private:
     659             :     RefPtr<DrawTarget> mDT;
     660             :     bool mSubpixelAntialiasingEnabled;
     661             : };
     662             : 
     663             : /* This class lives on the stack and allows gfxContext users to easily, and
     664             :  * performantly get a gfx::Pattern to use for drawing in their current context.
     665             :  */
     666             : class PatternFromState
     667             : {
     668             : public:
     669          78 :   explicit PatternFromState(gfxContext *aContext) : mContext(aContext), mPattern(nullptr) {}
     670          78 :   ~PatternFromState() { if (mPattern) { mPattern->~Pattern(); } }
     671             : 
     672             :   operator mozilla::gfx::Pattern&();
     673             : 
     674             : private:
     675             :   union {
     676             :     mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
     677             :     mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
     678             :   };
     679             : 
     680             :   gfxContext *mContext;
     681             :   mozilla::gfx::Pattern *mPattern;
     682             : };
     683             : 
     684             : /* This interface should be implemented to handle exporting the clip from a context.
     685             :  */
     686          36 : class ClipExporter : public mozilla::gfx::PathSink {
     687             : public:
     688             :   virtual void BeginClip(const mozilla::gfx::Matrix& aMatrix) = 0;
     689             :   virtual void EndClip() = 0;
     690             : };
     691             : 
     692             : #endif /* GFX_CONTEXT_H */

Generated by: LCOV version 1.13