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/. */
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"
22 typedef struct _cairo_pattern cairo_pattern_t
;
26 NS_INLINE_DECL_REFCOUNTING(gfxPattern
)
29 gfxPattern(cairo_pattern_t
*aPattern
);
30 gfxPattern(const gfxRGBA
& aColor
);
31 gfxPattern(gfxASurface
*surface
); // from another surface
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
38 virtual ~gfxPattern();
40 cairo_pattern_t
*CairoPattern();
41 void AddColorStop(gfxFloat offset
, const gfxRGBA
& c
);
42 void SetColorStops(mozilla::RefPtr
<mozilla::gfx::GradientStops
> aStops
);
44 // This should only be called on a cairo pattern that we want to use with
45 // Azure. We will read back the color stops from cairo and try to look
46 // them up in the cache.
47 void CacheColorStops(mozilla::gfx::DrawTarget
*aDT
);
49 void SetMatrix(const gfxMatrix
& matrix
);
50 gfxMatrix
GetMatrix() const;
51 gfxMatrix
GetInverseMatrix() const;
53 /* Get an Azure Pattern for the current Cairo pattern. aPattern transform
54 * specifies the transform that was set on the DrawTarget when the pattern
55 * was set. When this is nullptr it is assumed the transform is identical
56 * to the current transform.
58 mozilla::gfx::Pattern
*GetPattern(mozilla::gfx::DrawTarget
*aTarget
,
59 mozilla::gfx::Matrix
*aPatternTransform
= nullptr);
68 // Our own private flag for setting either NONE or PAD,
69 // depending on what the platform does for NONE. This is only
70 // relevant for surface patterns; for all other patterns, it
71 // behaves identical to PAD. On MacOS X, this becomes "NONE",
72 // because Quartz does the thing that we want at image edges;
73 // similarily on the win32 printing surface, since
74 // everything's done with GDI there. On other platforms, it
75 // usually becomes PAD.
76 EXTEND_PAD_EDGE
= 1000
79 // none, repeat, reflect
80 void SetExtend(GraphicsExtend extend
);
81 GraphicsExtend
Extend() const;
83 enum GraphicsPatternType
{
90 GraphicsPatternType
GetType() const;
94 void SetFilter(GraphicsFilter filter
);
95 GraphicsFilter
Filter() const;
97 /* returns TRUE if it succeeded */
98 bool GetSolidColor(gfxRGBA
& aColor
);
100 already_AddRefed
<gfxASurface
> GetSurface();
102 bool IsAzure() { return !mPattern
; }
104 mozilla::TemporaryRef
<mozilla::gfx::SourceSurface
> GetAzureSurface() { return mSourceSurface
; }
107 cairo_pattern_t
*mPattern
;
110 * aPatternTransform is the cairo pattern transform --- from user space at
111 * the time the pattern was set, to pattern space.
112 * aCurrentTransform is the DrawTarget's CTM --- from user space to device
114 * aOriginalTransform, if non-null, is the DrawTarget's TM when
115 * aPatternTransform was set --- user space to device space. If null, then
116 * the DrawTarget's CTM is the same as the TM when aPatternTransfrom was set.
117 * This function sets aPatternTransform to the Azure pattern transform ---
118 * from pattern space to current DrawTarget user space.
120 void AdjustTransformForPattern(mozilla::gfx::Matrix
&aPatternTransform
,
121 const mozilla::gfx::Matrix
&aCurrentTransform
,
122 const mozilla::gfx::Matrix
*aOriginalTransform
);
125 mozilla::AlignedStorage2
<mozilla::gfx::ColorPattern
> mColorPattern
;
126 mozilla::AlignedStorage2
<mozilla::gfx::LinearGradientPattern
> mLinearGradientPattern
;
127 mozilla::AlignedStorage2
<mozilla::gfx::RadialGradientPattern
> mRadialGradientPattern
;
128 mozilla::AlignedStorage2
<mozilla::gfx::SurfacePattern
> mSurfacePattern
;
131 mozilla::gfx::Pattern
*mGfxPattern
;
133 mozilla::RefPtr
<mozilla::gfx::SourceSurface
> mSourceSurface
;
134 mozilla::gfx::Matrix mTransform
;
135 mozilla::RefPtr
<mozilla::gfx::GradientStops
> mStops
;
136 GraphicsExtend mExtend
;
137 mozilla::gfx::Filter mFilter
;
140 #endif /* GFX_PATTERN_H */