2005-04-06 05:54:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#ifndef GFX_PATTERN_H
|
|
|
|
#define GFX_PATTERN_H
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
#include "gfxTypes.h"
|
2005-04-06 05:54:26 +04:00
|
|
|
|
|
|
|
#include "gfxColor.h"
|
|
|
|
#include "gfxMatrix.h"
|
2010-04-01 22:05:40 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-08-14 11:00:52 +04:00
|
|
|
#include "mozilla/Alignment.h"
|
2012-01-05 11:17:51 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2006-01-19 01:43:42 +03:00
|
|
|
class gfxContext;
|
2007-01-27 04:26:49 +03:00
|
|
|
class gfxASurface;
|
|
|
|
typedef struct _cairo_pattern cairo_pattern_t;
|
2006-01-19 01:43:42 +03:00
|
|
|
|
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxPattern {
|
2010-04-01 22:05:40 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxPattern)
|
2005-06-30 08:58:27 +04:00
|
|
|
|
2005-04-06 05:54:26 +04:00
|
|
|
public:
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern(cairo_pattern_t *aPattern);
|
2007-02-08 23:47:48 +03:00
|
|
|
gfxPattern(const gfxRGBA& aColor);
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern(gfxASurface *surface); // from another surface
|
2005-04-06 05:54:26 +04:00
|
|
|
// linear
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear
|
2005-04-08 09:44:32 +04:00
|
|
|
gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0,
|
2007-01-27 04:26:49 +03:00
|
|
|
gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial
|
2012-01-05 11:17:51 +04:00
|
|
|
gfxPattern(mozilla::gfx::SourceSurface *aSurface,
|
|
|
|
const mozilla::gfx::Matrix &aTransform); // Azure
|
2007-01-27 04:26:49 +03:00
|
|
|
virtual ~gfxPattern();
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
cairo_pattern_t *CairoPattern();
|
|
|
|
void AddColorStop(gfxFloat offset, const gfxRGBA& c);
|
2013-02-15 22:54:49 +04:00
|
|
|
void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops);
|
2007-03-03 03:18:34 +03:00
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
void SetMatrix(const gfxMatrix& matrix);
|
2007-03-03 03:18:34 +03:00
|
|
|
gfxMatrix GetMatrix() const;
|
2013-06-21 22:55:24 +04:00
|
|
|
gfxMatrix GetInverseMatrix() const;
|
2005-06-28 13:18:55 +04:00
|
|
|
|
2012-03-29 22:53:43 +04:00
|
|
|
/* Get an Azure Pattern for the current Cairo pattern. aPattern transform
|
|
|
|
* specifies the transform that was set on the DrawTarget when the pattern
|
2013-07-31 19:44:31 +04:00
|
|
|
* was set. When this is nullptr it is assumed the transform is identical
|
2012-03-29 22:53:43 +04:00
|
|
|
* to the current transform.
|
|
|
|
*/
|
|
|
|
mozilla::gfx::Pattern *GetPattern(mozilla::gfx::DrawTarget *aTarget,
|
2012-07-30 18:20:58 +04:00
|
|
|
mozilla::gfx::Matrix *aPatternTransform = nullptr);
|
2012-01-05 11:17:51 +04:00
|
|
|
bool IsOpaque();
|
|
|
|
|
2007-01-27 04:26:49 +03:00
|
|
|
enum GraphicsExtend {
|
|
|
|
EXTEND_NONE,
|
|
|
|
EXTEND_REPEAT,
|
|
|
|
EXTEND_REFLECT,
|
2008-09-25 23:49:55 +04:00
|
|
|
EXTEND_PAD,
|
|
|
|
|
|
|
|
// Our own private flag for setting either NONE or PAD,
|
|
|
|
// depending on what the platform does for NONE. This is only
|
|
|
|
// relevant for surface patterns; for all other patterns, it
|
|
|
|
// behaves identical to PAD. On MacOS X, this becomes "NONE",
|
|
|
|
// because Quartz does the thing that we want at image edges;
|
|
|
|
// similarily on the win32 printing surface, since
|
|
|
|
// everything's done with GDI there. On other platforms, it
|
|
|
|
// usually becomes PAD.
|
|
|
|
EXTEND_PAD_EDGE = 1000
|
2007-01-27 04:26:49 +03:00
|
|
|
};
|
2005-04-06 05:54:26 +04:00
|
|
|
|
|
|
|
// none, repeat, reflect
|
2007-01-27 04:26:49 +03:00
|
|
|
void SetExtend(GraphicsExtend extend);
|
|
|
|
GraphicsExtend Extend() const;
|
2005-04-06 05:54:26 +04:00
|
|
|
|
2008-03-06 09:51:13 +03:00
|
|
|
enum GraphicsPatternType {
|
|
|
|
PATTERN_SOLID,
|
|
|
|
PATTERN_SURFACE,
|
|
|
|
PATTERN_LINEAR,
|
|
|
|
PATTERN_RADIAL
|
|
|
|
};
|
|
|
|
|
|
|
|
GraphicsPatternType GetType() const;
|
|
|
|
|
|
|
|
int CairoStatus();
|
|
|
|
|
2009-03-21 18:36:38 +03:00
|
|
|
enum GraphicsFilter {
|
|
|
|
FILTER_FAST,
|
|
|
|
FILTER_GOOD,
|
|
|
|
FILTER_BEST,
|
|
|
|
FILTER_NEAREST,
|
|
|
|
FILTER_BILINEAR,
|
2012-07-12 16:51:57 +04:00
|
|
|
FILTER_GAUSSIAN,
|
|
|
|
FILTER_SENTINEL
|
2009-03-21 18:36:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void SetFilter(GraphicsFilter filter);
|
|
|
|
GraphicsFilter Filter() const;
|
2006-08-10 00:25:07 +04:00
|
|
|
|
|
|
|
/* returns TRUE if it succeeded */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetSolidColor(gfxRGBA& aColor);
|
2006-08-10 00:25:07 +04:00
|
|
|
|
2007-03-03 03:18:34 +03:00
|
|
|
already_AddRefed<gfxASurface> GetSurface();
|
|
|
|
|
2013-05-12 18:03:12 +04:00
|
|
|
bool IsAzure() { return !mPattern; }
|
|
|
|
|
|
|
|
mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetAzureSurface() { return mSourceSurface; }
|
|
|
|
|
2005-06-28 13:18:55 +04:00
|
|
|
protected:
|
2005-04-06 05:54:26 +04:00
|
|
|
cairo_pattern_t *mPattern;
|
2012-01-05 11:17:51 +04:00
|
|
|
|
2012-09-12 09:13:12 +04:00
|
|
|
/**
|
|
|
|
* aPatternTransform is the cairo pattern transform --- from user space at
|
|
|
|
* the time the pattern was set, to pattern space.
|
|
|
|
* aCurrentTransform is the DrawTarget's CTM --- from user space to device
|
|
|
|
* space.
|
|
|
|
* aOriginalTransform, if non-null, is the DrawTarget's TM when
|
|
|
|
* aPatternTransform was set --- user space to device space. If null, then
|
|
|
|
* the DrawTarget's CTM is the same as the TM when aPatternTransfrom was set.
|
|
|
|
* This function sets aPatternTransform to the Azure pattern transform ---
|
|
|
|
* from pattern space to current DrawTarget user space.
|
|
|
|
*/
|
2012-03-29 22:53:43 +04:00
|
|
|
void AdjustTransformForPattern(mozilla::gfx::Matrix &aPatternTransform,
|
|
|
|
const mozilla::gfx::Matrix &aCurrentTransform,
|
|
|
|
const mozilla::gfx::Matrix *aOriginalTransform);
|
|
|
|
|
2012-01-05 11:17:51 +04:00
|
|
|
union {
|
|
|
|
mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern;
|
|
|
|
mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern;
|
|
|
|
mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern;
|
|
|
|
mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern;
|
|
|
|
};
|
|
|
|
|
|
|
|
mozilla::gfx::Pattern *mGfxPattern;
|
|
|
|
|
|
|
|
mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
|
|
|
|
mozilla::gfx::Matrix mTransform;
|
|
|
|
mozilla::RefPtr<mozilla::gfx::GradientStops> mStops;
|
2013-06-20 01:06:42 +04:00
|
|
|
GraphicsExtend mExtend;
|
2012-01-05 11:17:51 +04:00
|
|
|
mozilla::gfx::Filter mFilter;
|
2005-04-06 05:54:26 +04:00
|
|
|
};
|
|
|
|
|
2005-04-11 08:36:18 +04:00
|
|
|
#endif /* GFX_PATTERN_H */
|