Bug 1568157 - Part 5: Move the NodePicker initialization into a getter. r=yulia
[gecko.git] / layout / painting / nsCSSRenderingGradients.h
blob5452ed3a95f2650a41dd69525c3c18d7ec1eda56
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsCSSRenderingGradients_h__
8 #define nsCSSRenderingGradients_h__
10 #include "nsLayoutUtils.h"
11 #include "nsStyleStruct.h"
12 #include "Units.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/gfx/2D.h"
16 namespace mozilla {
18 namespace layers {
19 class StackingContextHelper;
20 } // namespace layers
22 namespace wr {
23 class DisplayListBuilder;
24 } // namespace wr
26 // A resolved color stop, with a specific position along the gradient line and
27 // a color.
28 struct ColorStop {
29 ColorStop() : mPosition(0), mIsMidpoint(false) {}
30 ColorStop(double aPosition, bool aIsMidPoint, const gfx::Color& aColor)
31 : mPosition(aPosition), mIsMidpoint(aIsMidPoint), mColor(aColor) {}
32 double mPosition; // along the gradient line; 0=start, 1=end
33 bool mIsMidpoint;
34 gfx::Color mColor;
37 class nsCSSGradientRenderer final {
38 public:
39 /**
40 * Prepare a nsCSSGradientRenderer for a gradient for an element.
41 * aIntrinsicSize - the size of the source gradient.
43 static nsCSSGradientRenderer Create(nsPresContext* aPresContext,
44 ComputedStyle* aComputedStyle,
45 const StyleGradient& aGradient,
46 const nsSize& aIntrinsiceSize);
48 /**
49 * Draw the gradient to aContext
50 * aDest - where the first tile of gradient is
51 * aFill - the area to be filled with tiles of aDest
52 * aSrc - the area of the gradient that will fill aDest
53 * aRepeatSize - the distance from the origin of a tile
54 * to the next origin of a tile
55 * aDirtyRect - pixels outside of this area may be skipped
57 void Paint(gfxContext& aContext, const nsRect& aDest, const nsRect& aFill,
58 const nsSize& aRepeatSize, const mozilla::CSSIntRect& aSrc,
59 const nsRect& aDirtyRect, float aOpacity = 1.0);
61 /**
62 * Collect the gradient parameters
64 void BuildWebRenderParameters(float aOpacity, wr::ExtendMode& aMode,
65 nsTArray<wr::GradientStop>& aStops,
66 LayoutDevicePoint& aLineStart,
67 LayoutDevicePoint& aLineEnd,
68 LayoutDeviceSize& aGradientRadius);
70 /**
71 * Build display items for the gradient
72 * aLayer - the layer to make this display item relative to
73 * aDest - where the first tile of gradient is
74 * aFill - the area to be filled with tiles of aDest
75 * aRepeatSize - the distance from the origin of a tile
76 * to the next origin of a tile
77 * aSrc - the area of the gradient that will fill aDest
79 void BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuilder,
80 const layers::StackingContextHelper& aSc,
81 const nsRect& aDest, const nsRect& aFill,
82 const nsSize& aRepeatSize,
83 const mozilla::CSSIntRect& aSrc,
84 bool aIsBackfaceVisible,
85 float aOpacity = 1.0);
87 private:
88 nsCSSGradientRenderer()
89 : mPresContext(nullptr),
90 mGradient(nullptr),
91 mRadiusX(0.0),
92 mRadiusY(0.0) {}
94 /**
95 * Attempts to paint the tiles for a gradient by painting it once to an
96 * offscreen surface and then painting that offscreen surface with
97 * ExtendMode::Repeat to cover all tiles.
99 * Returns false if the optimization wasn't able to be used, in which case
100 * a fallback should be used.
102 bool TryPaintTilesWithExtendMode(
103 gfxContext& aContext, gfxPattern* aGradientPattern, nscoord aXStart,
104 nscoord aYStart, const gfxRect& aDirtyAreaToFill, const nsRect& aDest,
105 const nsSize& aRepeatSize, bool aForceRepeatToCoverTiles);
107 nsPresContext* mPresContext;
108 const StyleGradient* mGradient;
109 nsTArray<ColorStop> mStops;
110 gfxPoint mLineStart, mLineEnd;
111 double mRadiusX, mRadiusY;
114 } // namespace mozilla
116 #endif /* nsCSSRenderingGradients_h__ */