2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-03-14 09:05:41 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsCSSRenderingGradients_h__
|
|
|
|
#define nsCSSRenderingGradients_h__
|
|
|
|
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "Units.h"
|
2017-03-15 10:14:17 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-03-14 09:05:41 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-03-15 10:20:02 +03:00
|
|
|
namespace layers {
|
2017-05-03 15:48:08 +03:00
|
|
|
class StackingContextHelper;
|
2017-03-15 10:20:02 +03:00
|
|
|
} // namespace layers
|
|
|
|
|
|
|
|
namespace wr {
|
2017-03-15 07:25:09 +03:00
|
|
|
class DisplayListBuilder;
|
|
|
|
} // namespace wr
|
2017-03-15 10:20:02 +03:00
|
|
|
|
2017-03-15 10:14:17 +03:00
|
|
|
// A resolved color stop, with a specific position along the gradient line and
|
|
|
|
// a color.
|
2018-09-04 23:46:21 +03:00
|
|
|
struct ColorStop {
|
|
|
|
ColorStop() : mPosition(0), mIsMidpoint(false) {}
|
2020-03-09 17:16:17 +03:00
|
|
|
ColorStop(double aPosition, bool aIsMidPoint, const gfx::sRGBColor& aColor)
|
2018-09-04 23:46:21 +03:00
|
|
|
: mPosition(aPosition), mIsMidpoint(aIsMidPoint), mColor(aColor) {}
|
2017-03-15 10:14:17 +03:00
|
|
|
double mPosition; // along the gradient line; 0=start, 1=end
|
|
|
|
bool mIsMidpoint;
|
2020-03-09 17:16:17 +03:00
|
|
|
gfx::sRGBColor mColor;
|
2017-03-15 10:14:17 +03:00
|
|
|
};
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
class nsCSSGradientRenderer final {
|
2017-03-14 09:05:41 +03:00
|
|
|
public:
|
|
|
|
/**
|
2017-04-11 21:30:13 +03:00
|
|
|
* Prepare a nsCSSGradientRenderer for a gradient for an element.
|
|
|
|
* aIntrinsicSize - the size of the source gradient.
|
2017-03-14 09:05:41 +03:00
|
|
|
*/
|
2017-04-11 21:30:13 +03:00
|
|
|
static nsCSSGradientRenderer Create(nsPresContext* aPresContext,
|
2018-06-07 08:55:26 +03:00
|
|
|
ComputedStyle* aComputedStyle,
|
2019-06-07 17:13:17 +03:00
|
|
|
const StyleGradient& aGradient,
|
2017-04-11 21:30:13 +03:00
|
|
|
const nsSize& aIntrinsiceSize);
|
2017-03-15 10:14:17 +03:00
|
|
|
|
2017-04-11 21:30:13 +03:00
|
|
|
/**
|
|
|
|
* Draw the gradient to aContext
|
|
|
|
* aDest - where the first tile of gradient is
|
|
|
|
* aFill - the area to be filled with tiles of aDest
|
|
|
|
* aSrc - the area of the gradient that will fill aDest
|
|
|
|
* aRepeatSize - the distance from the origin of a tile
|
|
|
|
* to the next origin of a tile
|
|
|
|
* aDirtyRect - pixels outside of this area may be skipped
|
|
|
|
*/
|
2017-03-15 10:14:17 +03:00
|
|
|
void Paint(gfxContext& aContext, const nsRect& aDest, const nsRect& aFill,
|
2017-04-11 21:30:13 +03:00
|
|
|
const nsSize& aRepeatSize, const mozilla::CSSIntRect& aSrc,
|
2017-03-15 10:14:17 +03:00
|
|
|
const nsRect& aDirtyRect, float aOpacity = 1.0);
|
|
|
|
|
2017-04-11 21:30:13 +03:00
|
|
|
/**
|
|
|
|
* Collect the gradient parameters
|
|
|
|
*/
|
2017-04-10 12:27:30 +03:00
|
|
|
void BuildWebRenderParameters(float aOpacity, wr::ExtendMode& aMode,
|
2017-07-19 08:47:07 +03:00
|
|
|
nsTArray<wr::GradientStop>& aStops,
|
2017-04-10 12:27:30 +03:00
|
|
|
LayoutDevicePoint& aLineStart,
|
|
|
|
LayoutDevicePoint& aLineEnd,
|
2020-02-21 01:07:32 +03:00
|
|
|
LayoutDeviceSize& aGradientRadius,
|
|
|
|
LayoutDevicePoint& aGradientCenter,
|
|
|
|
float& aGradientAngle);
|
2017-04-10 12:27:30 +03:00
|
|
|
|
2017-04-11 21:30:13 +03:00
|
|
|
/**
|
|
|
|
* Build display items for the gradient
|
|
|
|
* aLayer - the layer to make this display item relative to
|
|
|
|
* aDest - where the first tile of gradient is
|
|
|
|
* aFill - the area to be filled with tiles of aDest
|
|
|
|
* aRepeatSize - the distance from the origin of a tile
|
|
|
|
* to the next origin of a tile
|
|
|
|
* aSrc - the area of the gradient that will fill aDest
|
|
|
|
*/
|
2017-03-15 10:20:02 +03:00
|
|
|
void BuildWebRenderDisplayItems(wr::DisplayListBuilder& aBuilder,
|
2017-05-03 15:48:08 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-04-11 21:30:13 +03:00
|
|
|
const nsRect& aDest, const nsRect& aFill,
|
|
|
|
const nsSize& aRepeatSize,
|
|
|
|
const mozilla::CSSIntRect& aSrc,
|
2017-09-21 09:41:38 +03:00
|
|
|
bool aIsBackfaceVisible,
|
2017-03-15 10:20:02 +03:00
|
|
|
float aOpacity = 1.0);
|
|
|
|
|
2017-03-15 10:14:17 +03:00
|
|
|
private:
|
2018-06-15 19:13:05 +03:00
|
|
|
nsCSSGradientRenderer()
|
|
|
|
: mPresContext(nullptr),
|
|
|
|
mGradient(nullptr),
|
|
|
|
mRadiusX(0.0),
|
2020-02-21 01:07:32 +03:00
|
|
|
mRadiusY(0.0),
|
|
|
|
mAngle(0.0) {}
|
2017-03-15 10:14:17 +03:00
|
|
|
|
2018-03-19 21:31:41 +03:00
|
|
|
/**
|
|
|
|
* Attempts to paint the tiles for a gradient by painting it once to an
|
|
|
|
* offscreen surface and then painting that offscreen surface with
|
|
|
|
* ExtendMode::Repeat to cover all tiles.
|
|
|
|
*
|
|
|
|
* Returns false if the optimization wasn't able to be used, in which case
|
|
|
|
* a fallback should be used.
|
|
|
|
*/
|
|
|
|
bool TryPaintTilesWithExtendMode(
|
|
|
|
gfxContext& aContext, gfxPattern* aGradientPattern, nscoord aXStart,
|
|
|
|
nscoord aYStart, const gfxRect& aDirtyAreaToFill, const nsRect& aDest,
|
|
|
|
const nsSize& aRepeatSize, bool aForceRepeatToCoverTiles);
|
|
|
|
|
2017-03-15 10:14:17 +03:00
|
|
|
nsPresContext* mPresContext;
|
2019-06-07 17:13:17 +03:00
|
|
|
const StyleGradient* mGradient;
|
2017-03-15 10:14:17 +03:00
|
|
|
nsTArray<ColorStop> mStops;
|
2020-02-21 01:07:32 +03:00
|
|
|
gfxPoint mLineStart, mLineEnd; // only for linear/radial gradients
|
|
|
|
double mRadiusX, mRadiusY; // only for radial gradients
|
|
|
|
gfxPoint mCenter; // only for conic gradients
|
|
|
|
float mAngle; // only for conic gradients
|
2017-03-14 09:05:41 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* nsCSSRenderingGradients_h__ */
|