/src/mozilla-central/layout/painting/nsCSSRenderingGradients.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #ifndef nsCSSRenderingGradients_h__ |
8 | | #define nsCSSRenderingGradients_h__ |
9 | | |
10 | | #include "nsLayoutUtils.h" |
11 | | #include "nsStyleStruct.h" |
12 | | #include "Units.h" |
13 | | #include "mozilla/Maybe.h" |
14 | | #include "mozilla/gfx/2D.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | namespace layers { |
19 | | class StackingContextHelper; |
20 | | } // namespace layers |
21 | | |
22 | | namespace wr { |
23 | | class DisplayListBuilder; |
24 | | } // namespace wr |
25 | | |
26 | | // A resolved color stop, with a specific position along the gradient line and |
27 | | // a color. |
28 | | struct ColorStop |
29 | | { |
30 | | ColorStop() |
31 | | : mPosition(0) |
32 | | , mIsMidpoint(false) |
33 | 0 | { |
34 | 0 | } |
35 | | ColorStop(double aPosition, bool aIsMidPoint, const gfx::Color& aColor) |
36 | | : mPosition(aPosition) |
37 | | , mIsMidpoint(aIsMidPoint) |
38 | | , mColor(aColor) |
39 | 0 | { |
40 | 0 | } |
41 | | double mPosition; // along the gradient line; 0=start, 1=end |
42 | | bool mIsMidpoint; |
43 | | gfx::Color mColor; |
44 | | }; |
45 | | |
46 | | class nsCSSGradientRenderer final |
47 | | { |
48 | | public: |
49 | | /** |
50 | | * Prepare a nsCSSGradientRenderer for a gradient for an element. |
51 | | * aIntrinsicSize - the size of the source gradient. |
52 | | */ |
53 | | static nsCSSGradientRenderer Create(nsPresContext* aPresContext, |
54 | | ComputedStyle* aComputedStyle, |
55 | | nsStyleGradient* aGradient, |
56 | | const nsSize& aIntrinsiceSize); |
57 | | |
58 | | /** |
59 | | * Draw the gradient to aContext |
60 | | * aDest - where the first tile of gradient is |
61 | | * aFill - the area to be filled with tiles of aDest |
62 | | * aSrc - the area of the gradient that will fill aDest |
63 | | * aRepeatSize - the distance from the origin of a tile |
64 | | * to the next origin of a tile |
65 | | * aDirtyRect - pixels outside of this area may be skipped |
66 | | */ |
67 | | void Paint(gfxContext& aContext, |
68 | | const nsRect& aDest, |
69 | | const nsRect& aFill, |
70 | | const nsSize& aRepeatSize, |
71 | | const mozilla::CSSIntRect& aSrc, |
72 | | const nsRect& aDirtyRect, |
73 | | float aOpacity = 1.0); |
74 | | |
75 | | /** |
76 | | * Collect the gradient parameters |
77 | | */ |
78 | | void BuildWebRenderParameters(float aOpacity, |
79 | | wr::ExtendMode& aMode, |
80 | | nsTArray<wr::GradientStop>& aStops, |
81 | | LayoutDevicePoint& aLineStart, |
82 | | LayoutDevicePoint& aLineEnd, |
83 | | LayoutDeviceSize& aGradientRadius); |
84 | | |
85 | | /** |
86 | | * Build display items for the gradient |
87 | | * aLayer - the layer to make this display item relative to |
88 | | * aDest - where the first tile of gradient is |
89 | | * aFill - the area to be filled with tiles of aDest |
90 | | * aRepeatSize - the distance from the origin of a tile |
91 | | * to the next origin of a tile |
92 | | * aSrc - the area of the gradient that will fill aDest |
93 | | */ |
94 | | void BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuilder, |
95 | | const layers::StackingContextHelper& aSc, |
96 | | const nsRect& aDest, |
97 | | const nsRect& aFill, |
98 | | const nsSize& aRepeatSize, |
99 | | const mozilla::CSSIntRect& aSrc, |
100 | | bool aIsBackfaceVisible, |
101 | | float aOpacity = 1.0); |
102 | | |
103 | | private: |
104 | | nsCSSGradientRenderer() |
105 | | : mPresContext(nullptr) |
106 | | , mGradient(nullptr) |
107 | | , mRadiusX(0.0) |
108 | | , mRadiusY(0.0) |
109 | 0 | { |
110 | 0 | } |
111 | | |
112 | | /** |
113 | | * Attempts to paint the tiles for a gradient by painting it once to an |
114 | | * offscreen surface and then painting that offscreen surface with |
115 | | * ExtendMode::Repeat to cover all tiles. |
116 | | * |
117 | | * Returns false if the optimization wasn't able to be used, in which case |
118 | | * a fallback should be used. |
119 | | */ |
120 | | bool TryPaintTilesWithExtendMode(gfxContext& aContext, |
121 | | gfxPattern* aGradientPattern, |
122 | | nscoord aXStart, |
123 | | nscoord aYStart, |
124 | | const gfxRect& aDirtyAreaToFill, |
125 | | const nsRect& aDest, |
126 | | const nsSize& aRepeatSize, |
127 | | bool aForceRepeatToCoverTiles); |
128 | | |
129 | | nsPresContext* mPresContext; |
130 | | nsStyleGradient* mGradient; |
131 | | nsTArray<ColorStop> mStops; |
132 | | gfxPoint mLineStart, mLineEnd; |
133 | | double mRadiusX, mRadiusY; |
134 | | }; |
135 | | |
136 | | } // namespace mozilla |
137 | | |
138 | | #endif /* nsCSSRenderingGradients_h__ */ |