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_PATTERN_H
7 #define GFX_PATTERN_H
8 
9 #include "gfxTypes.h"
10 
11 #include "gfxMatrix.h"
12 #include "mozilla/Alignment.h"
13 #include "mozilla/gfx/2D.h"
14 #include "mozilla/gfx/PatternHelpers.h"
15 #include "nsISupportsImpl.h"
16 #include "nsTArray.h"
17 
18 typedef struct _cairo_pattern cairo_pattern_t;
19 
20 
21 class gfxPattern final{
22     NS_INLINE_DECL_REFCOUNTING(gfxPattern)
23 
24 public:
25     explicit gfxPattern(const mozilla::gfx::Color& aColor);
26     // linear
27     gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
28     gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
29                gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
30     gfxPattern(mozilla::gfx::SourceSurface *aSurface,
31                const mozilla::gfx::Matrix &aPatternToUserSpace);
32 
33     void AddColorStop(gfxFloat offset, const mozilla::gfx::Color& c);
34     void SetColorStops(mozilla::gfx::GradientStops* aStops);
35 
36     // This should only be called on a cairo pattern that we want to use with
37     // Azure. We will read back the color stops from cairo and try to look
38     // them up in the cache.
39     void CacheColorStops(const mozilla::gfx::DrawTarget *aDT);
40 
41     void SetMatrix(const gfxMatrix& matrix);
42     gfxMatrix GetMatrix() const;
43     gfxMatrix GetInverseMatrix() const;
44 
45     /* Get an Azure Pattern for the current Cairo pattern. aPattern transform
46      * specifies the transform that was set on the DrawTarget when the pattern
47      * was set. When this is nullptr it is assumed the transform is identical
48      * to the current transform.
49      */
50     mozilla::gfx::Pattern *GetPattern(const mozilla::gfx::DrawTarget *aTarget,
51                                       mozilla::gfx::Matrix *aOriginalUserToDevice = nullptr);
52     bool IsOpaque();
53 
54     // clamp, repeat, reflect
55     void SetExtend(mozilla::gfx::ExtendMode aExtend);
56 
57     int CairoStatus();
58 
59     void SetSamplingFilter(mozilla::gfx::SamplingFilter aSamplingFilter);
60     mozilla::gfx::SamplingFilter SamplingFilter() const;
61 
62     /* returns TRUE if it succeeded */
63     bool GetSolidColor(mozilla::gfx::Color& aColorOut);
64 
65 private:
66     // Private destructor, to discourage deletion outside of Release():
~gfxPattern()67     ~gfxPattern() {}
68 
69     mozilla::gfx::GeneralPattern mGfxPattern;
70     RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
71     mozilla::gfx::Matrix mPatternToUserSpace;
72     RefPtr<mozilla::gfx::GradientStops> mStops;
73     nsTArray<mozilla::gfx::GradientStop> mStopsList;
74     mozilla::gfx::ExtendMode mExtend;
75 };
76 
77 #endif /* GFX_PATTERN_H */
78