gfx/thebes/gfxPattern.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef GFX_PATTERN_H
     7 #define GFX_PATTERN_H
     9 #include "gfxTypes.h"
    11 #include "gfxMatrix.h"
    12 #include "mozilla/Alignment.h"
    13 #include "mozilla/gfx/2D.h"
    14 #include "GraphicsFilter.h"
    15 #include "nsISupportsImpl.h"
    16 #include "nsAutoPtr.h"
    17 #include "nsTArray.h"
    19 class gfxContext;
    20 class gfxASurface;
    21 struct gfxRGBA;
    22 typedef struct _cairo_pattern cairo_pattern_t;
    25 class gfxPattern MOZ_FINAL{
    26     NS_INLINE_DECL_REFCOUNTING(gfxPattern)
    28 public:
    29     gfxPattern(cairo_pattern_t *aPattern);
    30     gfxPattern(const gfxRGBA& aColor);
    31     gfxPattern(gfxASurface *surface); // from another surface
    32     // linear
    33     gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
    34     gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
    35                gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
    36     gfxPattern(mozilla::gfx::SourceSurface *aSurface,
    37                const mozilla::gfx::Matrix &aTransform); // Azure
    39     cairo_pattern_t *CairoPattern();
    40     void AddColorStop(gfxFloat offset, const gfxRGBA& c);
    41     void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops);
    43     // This should only be called on a cairo pattern that we want to use with
    44     // Azure. We will read back the color stops from cairo and try to look
    45     // them up in the cache.
    46     void CacheColorStops(mozilla::gfx::DrawTarget *aDT);
    48     void SetMatrix(const gfxMatrix& matrix);
    49     gfxMatrix GetMatrix() const;
    50     gfxMatrix GetInverseMatrix() const;
    52     /* Get an Azure Pattern for the current Cairo pattern. aPattern transform
    53      * specifies the transform that was set on the DrawTarget when the pattern
    54      * was set. When this is nullptr it is assumed the transform is identical
    55      * to the current transform.
    56      */
    57     mozilla::gfx::Pattern *GetPattern(mozilla::gfx::DrawTarget *aTarget,
    58                                       mozilla::gfx::Matrix *aPatternTransform = nullptr);
    59     bool IsOpaque();
    61     enum GraphicsExtend {
    62         EXTEND_NONE,
    63         EXTEND_REPEAT,
    64         EXTEND_REFLECT,
    65         EXTEND_PAD,
    67         // Our own private flag for setting either NONE or PAD,
    68         // depending on what the platform does for NONE.  This is only
    69         // relevant for surface patterns; for all other patterns, it
    70         // behaves identical to PAD.  On MacOS X, this becomes "NONE",
    71         // because Quartz does the thing that we want at image edges;
    72         // similarily on the win32 printing surface, since
    73         // everything's done with GDI there.  On other platforms, it
    74         // usually becomes PAD.
    75         EXTEND_PAD_EDGE = 1000
    76     };
    78     // none, repeat, reflect
    79     void SetExtend(GraphicsExtend extend);
    80     GraphicsExtend Extend() const;
    82     enum GraphicsPatternType {
    83         PATTERN_SOLID,
    84         PATTERN_SURFACE,
    85         PATTERN_LINEAR,
    86         PATTERN_RADIAL
    87     };
    89     GraphicsPatternType GetType() const;
    91     int CairoStatus();
    93     void SetFilter(GraphicsFilter filter);
    94     GraphicsFilter Filter() const;
    96     /* returns TRUE if it succeeded */
    97     bool GetSolidColor(gfxRGBA& aColor);
    99     already_AddRefed<gfxASurface> GetSurface();
   101     bool IsAzure() { return !mPattern; }
   103     mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetAzureSurface() { return mSourceSurface; }
   105 private:
   106     // Private destructor, to discourage deletion outside of Release():
   107     ~gfxPattern();
   109     cairo_pattern_t *mPattern;
   111     /**
   112      * aPatternTransform is the cairo pattern transform --- from user space at
   113      * the time the pattern was set, to pattern space.
   114      * aCurrentTransform is the DrawTarget's CTM --- from user space to device
   115      * space.
   116      * aOriginalTransform, if non-null, is the DrawTarget's TM when
   117      * aPatternTransform was set --- user space to device space. If null, then
   118      * the DrawTarget's CTM is the same as the TM when aPatternTransfrom was set.
   119      * This function sets aPatternTransform to the Azure pattern transform ---
   120      * from pattern space to current DrawTarget user space.
   121      */
   122     void AdjustTransformForPattern(mozilla::gfx::Matrix &aPatternTransform,
   123                                    const mozilla::gfx::Matrix &aCurrentTransform,
   124                                    const mozilla::gfx::Matrix *aOriginalTransform);
   126     union {
   127       mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
   128       mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern;
   129       mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern;
   130       mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
   131     };
   133     mozilla::gfx::Pattern *mGfxPattern;
   135     mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
   136     mozilla::gfx::Matrix mTransform;
   137     mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
   138     GraphicsExtend mExtend;
   139     mozilla::gfx::Filter mFilter;
   140 };
   142 #endif /* GFX_PATTERN_H */

mercurial