gfxPattern.h (2786B)
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/. */ 5 6 #ifndef GFX_PATTERN_H 7 #define GFX_PATTERN_H 8 9 #include "gfxTypes.h" 10 11 #include "gfxMatrix.h" 12 #include "mozilla/gfx/2D.h" 13 #include "mozilla/gfx/PatternHelpers.h" 14 #include "nsISupportsImpl.h" 15 #include "nsTArray.h" 16 17 typedef struct _cairo_pattern cairo_pattern_t; 18 19 class gfxPattern final { 20 NS_INLINE_DECL_REFCOUNTING(gfxPattern) 21 22 public: 23 explicit gfxPattern(const mozilla::gfx::DeviceColor& aColor); 24 // gradients 25 gfxPattern(gfxFloat x0, gfxFloat y0, gfxFloat x1, gfxFloat y1); // linear 26 gfxPattern(gfxFloat cx0, gfxFloat cy0, gfxFloat radius0, gfxFloat cx1, 27 gfxFloat cy1, gfxFloat radius1); // radial 28 gfxPattern(gfxFloat cx, gfxFloat cy, gfxFloat angle, gfxFloat startOffset, 29 gfxFloat endOffset); // conic 30 gfxPattern(mozilla::gfx::SourceSurface* aSurface, 31 const mozilla::gfx::Matrix& aPatternToUserSpace); 32 33 void AddColorStop(gfxFloat offset, const mozilla::gfx::DeviceColor& c); 34 void SetColorStops(mozilla::gfx::GradientStops* aStops); 35 36 // This should only be called on a cairo pattern that we want to use with 37 // Azure. We will read back the color stops from cairo and try to look 38 // them up in the cache. 39 void CacheColorStops(const mozilla::gfx::DrawTarget* aDT); 40 41 void SetMatrix(const gfxMatrix& matrix); 42 gfxMatrix GetMatrix() const; 43 gfxMatrix GetInverseMatrix() const; 44 45 /* Get an Azure Pattern for the current Cairo pattern. aPattern transform 46 * specifies the transform that was set on the DrawTarget when the pattern 47 * was set. When this is nullptr it is assumed the transform is identical 48 * to the current transform. 49 */ 50 mozilla::gfx::Pattern* GetPattern( 51 const mozilla::gfx::DrawTarget* aTarget, 52 const mozilla::gfx::Matrix* aOriginalUserToDevice = nullptr); 53 bool IsOpaque(); 54 55 // clamp, repeat, reflect 56 void SetExtend(mozilla::gfx::ExtendMode aExtend); 57 58 void SetSamplingFilter(mozilla::gfx::SamplingFilter aSamplingFilter); 59 mozilla::gfx::SamplingFilter SamplingFilter() const; 60 61 /* returns TRUE if it succeeded */ 62 bool GetSolidColor(mozilla::gfx::DeviceColor& aColorOut); 63 64 private: 65 // Private destructor, to discourage deletion outside of Release(): 66 ~gfxPattern() = default; 67 68 mozilla::gfx::GeneralPattern mGfxPattern; 69 RefPtr<mozilla::gfx::SourceSurface> mSourceSurface; 70 mozilla::gfx::Matrix mPatternToUserSpace; 71 RefPtr<mozilla::gfx::GradientStops> mStops; 72 nsTArray<mozilla::gfx::GradientStop> mStopsList; 73 mozilla::gfx::ExtendMode mExtend; 74 }; 75 76 #endif /* GFX_PATTERN_H */