Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / painting / nsCSSRenderingGradients.h
blob5cf00fb4f8ccecc42e36de8e4f4823e8629b2293
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 "gfxRect.h"
11 #include "nsStyleStruct.h"
12 #include "Units.h"
13 #include "mozilla/Maybe.h"
14 #include "mozilla/gfx/2D.h"
15 #include "mozilla/webrender/webrender_ffi.h"
17 class gfxPattern;
19 namespace mozilla {
21 namespace layers {
22 class StackingContextHelper;
23 } // namespace layers
25 namespace wr {
26 class DisplayListBuilder;
27 } // namespace wr
29 // A resolved color stop, with a specific position along the gradient line and
30 // a color.
31 struct ColorStop {
32 ColorStop() : mPosition(0), mIsMidpoint(false) {}
33 ColorStop(double aPosition, bool aIsMidPoint,
34 const StyleAbsoluteColor& aColor)
35 : mPosition(aPosition), mIsMidpoint(aIsMidPoint), mColor(aColor) {}
36 double mPosition; // along the gradient line; 0=start, 1=end
37 bool mIsMidpoint;
38 StyleAbsoluteColor mColor;
41 class nsCSSGradientRenderer final {
42 public:
43 /**
44 * Prepare a nsCSSGradientRenderer for a gradient for an element.
45 * aIntrinsicSize - the size of the source gradient.
47 static nsCSSGradientRenderer Create(nsPresContext* aPresContext,
48 ComputedStyle* aComputedStyle,
49 const StyleGradient& aGradient,
50 const nsSize& aIntrinsiceSize);
52 /**
53 * Draw the gradient to aContext
54 * aDest - where the first tile of gradient is
55 * aFill - the area to be filled with tiles of aDest
56 * aSrc - the area of the gradient that will fill aDest
57 * aRepeatSize - the distance from the origin of a tile
58 * to the next origin of a tile
59 * aDirtyRect - pixels outside of this area may be skipped
61 void Paint(gfxContext& aContext, const nsRect& aDest, const nsRect& aFill,
62 const nsSize& aRepeatSize, const mozilla::CSSIntRect& aSrc,
63 const nsRect& aDirtyRect, float aOpacity = 1.0);
65 /**
66 * Collect the gradient parameters
68 void BuildWebRenderParameters(float aOpacity, wr::ExtendMode& aMode,
69 nsTArray<wr::GradientStop>& aStops,
70 LayoutDevicePoint& aLineStart,
71 LayoutDevicePoint& aLineEnd,
72 LayoutDeviceSize& aGradientRadius,
73 LayoutDevicePoint& aGradientCenter,
74 float& aGradientAngle);
76 /**
77 * Build display items for the gradient
78 * aLayer - the layer to make this display item relative to
79 * aDest - where the first tile of gradient is
80 * aFill - the area to be filled with tiles of aDest
81 * aRepeatSize - the distance from the origin of a tile
82 * to the next origin of a tile
83 * aSrc - the area of the gradient that will fill aDest
85 void BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuilder,
86 const layers::StackingContextHelper& aSc,
87 const nsRect& aDest, const nsRect& aFill,
88 const nsSize& aRepeatSize,
89 const mozilla::CSSIntRect& aSrc,
90 bool aIsBackfaceVisible,
91 float aOpacity = 1.0);
93 private:
94 nsCSSGradientRenderer()
95 : mPresContext(nullptr),
96 mGradient(nullptr),
97 mRadiusX(0.0),
98 mRadiusY(0.0),
99 mAngle(0.0) {}
102 * Attempts to paint the tiles for a gradient by painting it once to an
103 * offscreen surface and then painting that offscreen surface with
104 * ExtendMode::Repeat to cover all tiles.
106 * Returns false if the optimization wasn't able to be used, in which case
107 * a fallback should be used.
109 bool TryPaintTilesWithExtendMode(
110 gfxContext& aContext, gfxPattern* aGradientPattern, nscoord aXStart,
111 nscoord aYStart, const gfxRect& aDirtyAreaToFill, const nsRect& aDest,
112 const nsSize& aRepeatSize, bool aForceRepeatToCoverTiles);
114 nsPresContext* mPresContext;
115 const StyleGradient* mGradient;
116 nsTArray<ColorStop> mStops;
117 gfxPoint mLineStart, mLineEnd; // only for linear/radial gradients
118 double mRadiusX, mRadiusY; // only for radial gradients
119 gfxPoint mCenter; // only for conic gradients
120 float mAngle; // only for conic gradients
123 } // namespace mozilla
125 #endif /* nsCSSRenderingGradients_h__ */