1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 "mozilla/gfx/PatternHelpers.h"
15 #include "nsISupportsImpl.h"
18 typedef struct _cairo_pattern cairo_pattern_t
;
20 class gfxPattern final
{
21 NS_INLINE_DECL_REFCOUNTING(gfxPattern
)
24 explicit gfxPattern(const mozilla::gfx::DeviceColor
& aColor
);
26 gfxPattern(gfxFloat x0
, gfxFloat y0
, gfxFloat x1
, gfxFloat y1
); // linear
27 gfxPattern(gfxFloat cx0
, gfxFloat cy0
, gfxFloat radius0
, gfxFloat cx1
,
28 gfxFloat cy1
, gfxFloat radius1
); // radial
29 gfxPattern(gfxFloat cx
, gfxFloat cy
, gfxFloat angle
, gfxFloat startOffset
,
30 gfxFloat endOffset
); // conic
31 gfxPattern(mozilla::gfx::SourceSurface
* aSurface
,
32 const mozilla::gfx::Matrix
& aPatternToUserSpace
);
34 void AddColorStop(gfxFloat offset
, const mozilla::gfx::DeviceColor
& c
);
35 void SetColorStops(mozilla::gfx::GradientStops
* aStops
);
37 // This should only be called on a cairo pattern that we want to use with
38 // Azure. We will read back the color stops from cairo and try to look
39 // them up in the cache.
40 void CacheColorStops(const mozilla::gfx::DrawTarget
* aDT
);
42 void SetMatrix(const gfxMatrix
& matrix
);
43 gfxMatrix
GetMatrix() const;
44 gfxMatrix
GetInverseMatrix() const;
46 /* Get an Azure Pattern for the current Cairo pattern. aPattern transform
47 * specifies the transform that was set on the DrawTarget when the pattern
48 * was set. When this is nullptr it is assumed the transform is identical
49 * to the current transform.
51 mozilla::gfx::Pattern
* GetPattern(
52 const mozilla::gfx::DrawTarget
* aTarget
,
53 const mozilla::gfx::Matrix
* aOriginalUserToDevice
= nullptr);
56 // clamp, repeat, reflect
57 void SetExtend(mozilla::gfx::ExtendMode aExtend
);
59 void SetSamplingFilter(mozilla::gfx::SamplingFilter aSamplingFilter
);
60 mozilla::gfx::SamplingFilter
SamplingFilter() const;
62 /* returns TRUE if it succeeded */
63 bool GetSolidColor(mozilla::gfx::DeviceColor
& aColorOut
);
66 // Private destructor, to discourage deletion outside of Release():
67 ~gfxPattern() = default;
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
;
77 #endif /* GFX_PATTERN_H */