gfx/thebes/gfxPattern.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxPattern.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,142 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_PATTERN_H
    1.10 +#define GFX_PATTERN_H
    1.11 +
    1.12 +#include "gfxTypes.h"
    1.13 +
    1.14 +#include "gfxMatrix.h"
    1.15 +#include "mozilla/Alignment.h"
    1.16 +#include "mozilla/gfx/2D.h"
    1.17 +#include "GraphicsFilter.h"
    1.18 +#include "nsISupportsImpl.h"
    1.19 +#include "nsAutoPtr.h"
    1.20 +#include "nsTArray.h"
    1.21 +
    1.22 +class gfxContext;
    1.23 +class gfxASurface;
    1.24 +struct gfxRGBA;
    1.25 +typedef struct _cairo_pattern cairo_pattern_t;
    1.26 +
    1.27 +
    1.28 +class gfxPattern MOZ_FINAL{
    1.29 +    NS_INLINE_DECL_REFCOUNTING(gfxPattern)
    1.30 +
    1.31 +public:
    1.32 +    gfxPattern(cairo_pattern_t *aPattern);
    1.33 +    gfxPattern(const gfxRGBA& aColor);
    1.34 +    gfxPattern(gfxASurface *surface); // from another surface
    1.35 +    // linear
    1.36 +    gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
    1.37 +    gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
    1.38 +               gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
    1.39 +    gfxPattern(mozilla::gfx::SourceSurface *aSurface,
    1.40 +               const mozilla::gfx::Matrix &aTransform); // Azure
    1.41 +
    1.42 +    cairo_pattern_t *CairoPattern();
    1.43 +    void AddColorStop(gfxFloat offset, const gfxRGBA& c);
    1.44 +    void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops);
    1.45 +
    1.46 +    // This should only be called on a cairo pattern that we want to use with
    1.47 +    // Azure. We will read back the color stops from cairo and try to look
    1.48 +    // them up in the cache.
    1.49 +    void CacheColorStops(mozilla::gfx::DrawTarget *aDT);
    1.50 +
    1.51 +    void SetMatrix(const gfxMatrix& matrix);
    1.52 +    gfxMatrix GetMatrix() const;
    1.53 +    gfxMatrix GetInverseMatrix() const;
    1.54 +
    1.55 +    /* Get an Azure Pattern for the current Cairo pattern. aPattern transform
    1.56 +     * specifies the transform that was set on the DrawTarget when the pattern
    1.57 +     * was set. When this is nullptr it is assumed the transform is identical
    1.58 +     * to the current transform.
    1.59 +     */
    1.60 +    mozilla::gfx::Pattern *GetPattern(mozilla::gfx::DrawTarget *aTarget,
    1.61 +                                      mozilla::gfx::Matrix *aPatternTransform = nullptr);
    1.62 +    bool IsOpaque();
    1.63 +
    1.64 +    enum GraphicsExtend {
    1.65 +        EXTEND_NONE,
    1.66 +        EXTEND_REPEAT,
    1.67 +        EXTEND_REFLECT,
    1.68 +        EXTEND_PAD,
    1.69 +
    1.70 +        // Our own private flag for setting either NONE or PAD,
    1.71 +        // depending on what the platform does for NONE.  This is only
    1.72 +        // relevant for surface patterns; for all other patterns, it
    1.73 +        // behaves identical to PAD.  On MacOS X, this becomes "NONE",
    1.74 +        // because Quartz does the thing that we want at image edges;
    1.75 +        // similarily on the win32 printing surface, since
    1.76 +        // everything's done with GDI there.  On other platforms, it
    1.77 +        // usually becomes PAD.
    1.78 +        EXTEND_PAD_EDGE = 1000
    1.79 +    };
    1.80 +
    1.81 +    // none, repeat, reflect
    1.82 +    void SetExtend(GraphicsExtend extend);
    1.83 +    GraphicsExtend Extend() const;
    1.84 +
    1.85 +    enum GraphicsPatternType {
    1.86 +        PATTERN_SOLID,
    1.87 +        PATTERN_SURFACE,
    1.88 +        PATTERN_LINEAR,
    1.89 +        PATTERN_RADIAL
    1.90 +    };
    1.91 +
    1.92 +    GraphicsPatternType GetType() const;
    1.93 +
    1.94 +    int CairoStatus();
    1.95 +
    1.96 +    void SetFilter(GraphicsFilter filter);
    1.97 +    GraphicsFilter Filter() const;
    1.98 +
    1.99 +    /* returns TRUE if it succeeded */
   1.100 +    bool GetSolidColor(gfxRGBA& aColor);
   1.101 +
   1.102 +    already_AddRefed<gfxASurface> GetSurface();
   1.103 +
   1.104 +    bool IsAzure() { return !mPattern; }
   1.105 +
   1.106 +    mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetAzureSurface() { return mSourceSurface; }
   1.107 +
   1.108 +private:
   1.109 +    // Private destructor, to discourage deletion outside of Release():
   1.110 +    ~gfxPattern();
   1.111 +
   1.112 +    cairo_pattern_t *mPattern;
   1.113 +
   1.114 +    /**
   1.115 +     * aPatternTransform is the cairo pattern transform --- from user space at
   1.116 +     * the time the pattern was set, to pattern space.
   1.117 +     * aCurrentTransform is the DrawTarget's CTM --- from user space to device
   1.118 +     * space.
   1.119 +     * aOriginalTransform, if non-null, is the DrawTarget's TM when
   1.120 +     * aPatternTransform was set --- user space to device space. If null, then
   1.121 +     * the DrawTarget's CTM is the same as the TM when aPatternTransfrom was set.
   1.122 +     * This function sets aPatternTransform to the Azure pattern transform ---
   1.123 +     * from pattern space to current DrawTarget user space.
   1.124 +     */
   1.125 +    void AdjustTransformForPattern(mozilla::gfx::Matrix &aPatternTransform,
   1.126 +                                   const mozilla::gfx::Matrix &aCurrentTransform,
   1.127 +                                   const mozilla::gfx::Matrix *aOriginalTransform);
   1.128 +
   1.129 +    union {
   1.130 +      mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
   1.131 +      mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern;
   1.132 +      mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern;
   1.133 +      mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
   1.134 +    };
   1.135 +
   1.136 +    mozilla::gfx::Pattern *mGfxPattern;
   1.137 +
   1.138 +    mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
   1.139 +    mozilla::gfx::Matrix mTransform;
   1.140 +    mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
   1.141 +    GraphicsExtend mExtend;
   1.142 +    mozilla::gfx::Filter mFilter;
   1.143 +};
   1.144 +
   1.145 +#endif /* GFX_PATTERN_H */

mercurial