Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef GFX_PATTERN_H |
michael@0 | 7 | #define GFX_PATTERN_H |
michael@0 | 8 | |
michael@0 | 9 | #include "gfxTypes.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "gfxMatrix.h" |
michael@0 | 12 | #include "mozilla/Alignment.h" |
michael@0 | 13 | #include "mozilla/gfx/2D.h" |
michael@0 | 14 | #include "GraphicsFilter.h" |
michael@0 | 15 | #include "nsISupportsImpl.h" |
michael@0 | 16 | #include "nsAutoPtr.h" |
michael@0 | 17 | #include "nsTArray.h" |
michael@0 | 18 | |
michael@0 | 19 | class gfxContext; |
michael@0 | 20 | class gfxASurface; |
michael@0 | 21 | struct gfxRGBA; |
michael@0 | 22 | typedef struct _cairo_pattern cairo_pattern_t; |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | class gfxPattern MOZ_FINAL{ |
michael@0 | 26 | NS_INLINE_DECL_REFCOUNTING(gfxPattern) |
michael@0 | 27 | |
michael@0 | 28 | public: |
michael@0 | 29 | gfxPattern(cairo_pattern_t *aPattern); |
michael@0 | 30 | gfxPattern(const gfxRGBA& aColor); |
michael@0 | 31 | gfxPattern(gfxASurface *surface); // from another surface |
michael@0 | 32 | // linear |
michael@0 | 33 | gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear |
michael@0 | 34 | gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0, |
michael@0 | 35 | gfxFloat cx1, gfxFloat cy1, gfxFloat radius1); // radial |
michael@0 | 36 | gfxPattern(mozilla::gfx::SourceSurface *aSurface, |
michael@0 | 37 | const mozilla::gfx::Matrix &aTransform); // Azure |
michael@0 | 38 | |
michael@0 | 39 | cairo_pattern_t *CairoPattern(); |
michael@0 | 40 | void AddColorStop(gfxFloat offset, const gfxRGBA& c); |
michael@0 | 41 | void SetColorStops(mozilla::RefPtr<mozilla::gfx::GradientStops> aStops); |
michael@0 | 42 | |
michael@0 | 43 | // This should only be called on a cairo pattern that we want to use with |
michael@0 | 44 | // Azure. We will read back the color stops from cairo and try to look |
michael@0 | 45 | // them up in the cache. |
michael@0 | 46 | void CacheColorStops(mozilla::gfx::DrawTarget *aDT); |
michael@0 | 47 | |
michael@0 | 48 | void SetMatrix(const gfxMatrix& matrix); |
michael@0 | 49 | gfxMatrix GetMatrix() const; |
michael@0 | 50 | gfxMatrix GetInverseMatrix() const; |
michael@0 | 51 | |
michael@0 | 52 | /* Get an Azure Pattern for the current Cairo pattern. aPattern transform |
michael@0 | 53 | * specifies the transform that was set on the DrawTarget when the pattern |
michael@0 | 54 | * was set. When this is nullptr it is assumed the transform is identical |
michael@0 | 55 | * to the current transform. |
michael@0 | 56 | */ |
michael@0 | 57 | mozilla::gfx::Pattern *GetPattern(mozilla::gfx::DrawTarget *aTarget, |
michael@0 | 58 | mozilla::gfx::Matrix *aPatternTransform = nullptr); |
michael@0 | 59 | bool IsOpaque(); |
michael@0 | 60 | |
michael@0 | 61 | enum GraphicsExtend { |
michael@0 | 62 | EXTEND_NONE, |
michael@0 | 63 | EXTEND_REPEAT, |
michael@0 | 64 | EXTEND_REFLECT, |
michael@0 | 65 | EXTEND_PAD, |
michael@0 | 66 | |
michael@0 | 67 | // Our own private flag for setting either NONE or PAD, |
michael@0 | 68 | // depending on what the platform does for NONE. This is only |
michael@0 | 69 | // relevant for surface patterns; for all other patterns, it |
michael@0 | 70 | // behaves identical to PAD. On MacOS X, this becomes "NONE", |
michael@0 | 71 | // because Quartz does the thing that we want at image edges; |
michael@0 | 72 | // similarily on the win32 printing surface, since |
michael@0 | 73 | // everything's done with GDI there. On other platforms, it |
michael@0 | 74 | // usually becomes PAD. |
michael@0 | 75 | EXTEND_PAD_EDGE = 1000 |
michael@0 | 76 | }; |
michael@0 | 77 | |
michael@0 | 78 | // none, repeat, reflect |
michael@0 | 79 | void SetExtend(GraphicsExtend extend); |
michael@0 | 80 | GraphicsExtend Extend() const; |
michael@0 | 81 | |
michael@0 | 82 | enum GraphicsPatternType { |
michael@0 | 83 | PATTERN_SOLID, |
michael@0 | 84 | PATTERN_SURFACE, |
michael@0 | 85 | PATTERN_LINEAR, |
michael@0 | 86 | PATTERN_RADIAL |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | GraphicsPatternType GetType() const; |
michael@0 | 90 | |
michael@0 | 91 | int CairoStatus(); |
michael@0 | 92 | |
michael@0 | 93 | void SetFilter(GraphicsFilter filter); |
michael@0 | 94 | GraphicsFilter Filter() const; |
michael@0 | 95 | |
michael@0 | 96 | /* returns TRUE if it succeeded */ |
michael@0 | 97 | bool GetSolidColor(gfxRGBA& aColor); |
michael@0 | 98 | |
michael@0 | 99 | already_AddRefed<gfxASurface> GetSurface(); |
michael@0 | 100 | |
michael@0 | 101 | bool IsAzure() { return !mPattern; } |
michael@0 | 102 | |
michael@0 | 103 | mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetAzureSurface() { return mSourceSurface; } |
michael@0 | 104 | |
michael@0 | 105 | private: |
michael@0 | 106 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 107 | ~gfxPattern(); |
michael@0 | 108 | |
michael@0 | 109 | cairo_pattern_t *mPattern; |
michael@0 | 110 | |
michael@0 | 111 | /** |
michael@0 | 112 | * aPatternTransform is the cairo pattern transform --- from user space at |
michael@0 | 113 | * the time the pattern was set, to pattern space. |
michael@0 | 114 | * aCurrentTransform is the DrawTarget's CTM --- from user space to device |
michael@0 | 115 | * space. |
michael@0 | 116 | * aOriginalTransform, if non-null, is the DrawTarget's TM when |
michael@0 | 117 | * aPatternTransform was set --- user space to device space. If null, then |
michael@0 | 118 | * the DrawTarget's CTM is the same as the TM when aPatternTransfrom was set. |
michael@0 | 119 | * This function sets aPatternTransform to the Azure pattern transform --- |
michael@0 | 120 | * from pattern space to current DrawTarget user space. |
michael@0 | 121 | */ |
michael@0 | 122 | void AdjustTransformForPattern(mozilla::gfx::Matrix &aPatternTransform, |
michael@0 | 123 | const mozilla::gfx::Matrix &aCurrentTransform, |
michael@0 | 124 | const mozilla::gfx::Matrix *aOriginalTransform); |
michael@0 | 125 | |
michael@0 | 126 | union { |
michael@0 | 127 | mozilla::AlignedStorage2<mozilla::gfx::ColorPattern> mColorPattern; |
michael@0 | 128 | mozilla::AlignedStorage2<mozilla::gfx::LinearGradientPattern> mLinearGradientPattern; |
michael@0 | 129 | mozilla::AlignedStorage2<mozilla::gfx::RadialGradientPattern> mRadialGradientPattern; |
michael@0 | 130 | mozilla::AlignedStorage2<mozilla::gfx::SurfacePattern> mSurfacePattern; |
michael@0 | 131 | }; |
michael@0 | 132 | |
michael@0 | 133 | mozilla::gfx::Pattern *mGfxPattern; |
michael@0 | 134 | |
michael@0 | 135 | mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface; |
michael@0 | 136 | mozilla::gfx::Matrix mTransform; |
michael@0 | 137 | mozilla::RefPtr<mozilla::gfx::GradientStops> mStops; |
michael@0 | 138 | GraphicsExtend mExtend; |
michael@0 | 139 | mozilla::gfx::Filter mFilter; |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | #endif /* GFX_PATTERN_H */ |