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
;
25 class gfxPattern MOZ_FINAL
{
26 NS_INLINE_DECL_REFCOUNTING(gfxPattern
)
29 explicit gfxPattern(cairo_pattern_t
*aPattern
);
30 explicit gfxPattern(const gfxRGBA
& aColor
);
31 explicit 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
39 cairo_pattern_t
*CairoPattern();
40 void AddColorStop(gfxFloat offset
, const gfxRGBA
& c
);
41 void SetColorStops(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.
57 mozilla::gfx::Pattern
*GetPattern(mozilla::gfx::DrawTarget
*aTarget
,
58 mozilla::gfx::Matrix
*aPatternTransform
= nullptr);
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
78 // none, repeat, reflect
79 void SetExtend(GraphicsExtend extend
);
80 GraphicsExtend
Extend() const;
82 enum GraphicsPatternType
{
89 GraphicsPatternType
GetType() const;
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
; }
106 // Private destructor, to discourage deletion outside of Release():
109 cairo_pattern_t
*mPattern
;
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
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.
122 void AdjustTransformForPattern(mozilla::gfx::Matrix
&aPatternTransform
,
123 const mozilla::gfx::Matrix
&aCurrentTransform
,
124 const mozilla::gfx::Matrix
*aOriginalTransform
);
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
;
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
;
142 #endif /* GFX_PATTERN_H */