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: */
|
2012-05-21 15:12:37 +04: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/. */
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
#ifndef NSSVGINTEGRATIONUTILS_H_
|
|
|
|
#define NSSVGINTEGRATIONUTILS_H_
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
#include "ImgDrawResult.h"
|
2009-07-23 12:35:59 +04:00
|
|
|
#include "gfxMatrix.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "gfxRect.h"
|
2015-11-04 19:49:49 +03:00
|
|
|
#include "nsRegionFwd.h"
|
2016-10-11 08:12:00 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
class gfxContext;
|
2014-01-31 07:36:42 +04:00
|
|
|
class gfxDrawable;
|
2008-09-11 04:24:16 +04:00
|
|
|
class nsDisplayList;
|
2012-03-20 16:15:55 +04:00
|
|
|
class nsDisplayListBuilder;
|
|
|
|
class nsIFrame;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2013-09-07 06:15:49 +04:00
|
|
|
struct nsRect;
|
|
|
|
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace mozilla {
|
2014-09-29 17:15:19 +04:00
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
2012-07-31 04:42:26 +04:00
|
|
|
namespace layers {
|
|
|
|
class LayerManager;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
2012-07-31 04:42:26 +04:00
|
|
|
|
2012-03-20 16:15:55 +04:00
|
|
|
struct nsPoint;
|
|
|
|
struct nsSize;
|
|
|
|
|
2012-06-19 19:28:04 +04:00
|
|
|
/**
|
|
|
|
* Integration of SVG effects (clipPath clipping, masking and filters) into
|
|
|
|
* regular display list based painting and hit-testing.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsSVGIntegrationUtils final
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2014-09-29 17:15:19 +04:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2016-10-11 08:12:00 +03:00
|
|
|
typedef mozilla::gfx::IntRect IntRect;
|
2017-05-18 23:03:41 +03:00
|
|
|
typedef mozilla::image::imgDrawingParams imgDrawingParams;
|
2014-09-29 17:15:19 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
public:
|
2008-10-20 12:42:03 +04:00
|
|
|
/**
|
2012-07-20 22:12:29 +04:00
|
|
|
* Returns true if SVG effects are currently applied to this frame.
|
2008-10-20 12:42:03 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-09-11 04:24:16 +04:00
|
|
|
UsingEffectsForFrame(const nsIFrame* aFrame);
|
|
|
|
|
2016-08-16 08:56:11 +03:00
|
|
|
/**
|
|
|
|
* Returns true if mask or clippath are currently applied to this frame.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
UsingMaskOrClipPathForFrame(const nsIFrame* aFrame);
|
|
|
|
|
2012-06-19 19:28:04 +04:00
|
|
|
/**
|
|
|
|
* Returns the size of the union of the border-box rects of all of
|
|
|
|
* aNonSVGFrame's continuations.
|
|
|
|
*/
|
|
|
|
static nsSize
|
|
|
|
GetContinuationUnionSize(nsIFrame* aNonSVGFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When SVG effects need to resolve percentage, userSpaceOnUse lengths, they
|
|
|
|
* need a coordinate context to resolve them against. This method provides
|
|
|
|
* that coordinate context for non-SVG frames with SVG effects applied to
|
|
|
|
* them. The gfxSize returned is the size of the union of all of the given
|
|
|
|
* frame's continuations' border boxes, converted to SVG user units (equal to
|
|
|
|
* CSS px units), as required by the SVG code.
|
|
|
|
*/
|
2013-12-30 03:35:52 +04:00
|
|
|
static mozilla::gfx::Size
|
2012-06-19 19:28:04 +04:00
|
|
|
GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame);
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
2012-06-21 04:29:50 +04:00
|
|
|
* SVG effects such as SVG filters, masking and clipPath may require an SVG
|
|
|
|
* "bbox" for the element they're being applied to in order to make decisions
|
|
|
|
* about positioning, and to resolve various lengths against. This method
|
|
|
|
* provides the "bbox" for non-SVG frames. The bbox returned is in CSS px
|
2017-08-17 04:52:17 +03:00
|
|
|
* units, and aUnionContinuations decide whether bbox contains the area of
|
|
|
|
* current frame only or the union of all aNonSVGFrame's continuations'
|
|
|
|
* overflow areas, relative to the top-left of the union of all aNonSVGFrame's
|
2012-06-21 04:29:50 +04:00
|
|
|
* continuations' border box rects.
|
|
|
|
*/
|
|
|
|
static gfxRect
|
2017-08-17 04:52:17 +03:00
|
|
|
GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame, bool aUnionContinuations);
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to adjust a frame's pre-effects visual overflow rect to take account
|
|
|
|
* of SVG effects.
|
|
|
|
*
|
|
|
|
* XXX This method will not do the right thing for frames with continuations.
|
|
|
|
* It really needs all the continuations to have been reflowed before being
|
|
|
|
* called, but we currently call it on each continuation as its overflow
|
|
|
|
* rects are set during the reflow of each particular continuation. Gecko's
|
|
|
|
* current reflow architecture does not allow us to set the overflow rects
|
|
|
|
* for a whole chain of continuations for a given element at the point when
|
|
|
|
* the last continuation is reflowed. See:
|
|
|
|
* http://groups.google.com/group/mozilla.dev.tech.layout/msg/6b179066f3051f65
|
2008-09-11 04:24:16 +04:00
|
|
|
*/
|
|
|
|
static nsRect
|
2012-06-21 04:29:50 +04:00
|
|
|
ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame,
|
|
|
|
const nsRect& aPreEffectsOverflowRect);
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
2012-06-21 04:29:50 +04:00
|
|
|
* Used to adjust the area of a frame that needs to be invalidated to take
|
|
|
|
* account of SVG effects.
|
2012-11-28 08:06:07 +04:00
|
|
|
*
|
|
|
|
* @param aFrame The effects frame.
|
|
|
|
* @param aToReferenceFrame The offset (in app units) from aFrame to its
|
|
|
|
* reference display item.
|
2014-04-24 12:25:17 +04:00
|
|
|
* @param aInvalidRegion The pre-effects invalid region in pixels relative to
|
2012-11-28 08:06:07 +04:00
|
|
|
* the reference display item.
|
|
|
|
* @return The post-effects invalid rect in pixels relative to the reference
|
|
|
|
* display item.
|
2008-09-11 04:24:16 +04:00
|
|
|
*/
|
2014-04-24 12:25:17 +04:00
|
|
|
static nsIntRegion
|
2012-11-28 08:06:07 +04:00
|
|
|
AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
|
2014-04-24 12:25:17 +04:00
|
|
|
const nsIntRegion& aInvalidRegion);
|
2012-06-21 04:29:50 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
|
|
|
* Figure out which area of the source is needed given an area to
|
|
|
|
* repaint
|
|
|
|
*/
|
|
|
|
static nsRect
|
|
|
|
GetRequiredSourceForInvalidArea(nsIFrame* aFrame, const nsRect& aDamageRect);
|
2012-06-21 04:29:50 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
|
|
|
* Returns true if the given point is not clipped out by effects.
|
|
|
|
* @param aPt in appunits relative to aFrame
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2008-09-11 04:24:16 +04:00
|
|
|
HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt);
|
|
|
|
|
2017-05-18 23:03:45 +03:00
|
|
|
struct MOZ_STACK_CLASS PaintFramesParams {
|
2016-05-19 10:43:32 +03:00
|
|
|
gfxContext& ctx;
|
|
|
|
nsIFrame* frame;
|
|
|
|
const nsRect& dirtyRect;
|
|
|
|
const nsRect& borderArea;
|
|
|
|
nsDisplayListBuilder* builder;
|
|
|
|
mozilla::layers::LayerManager* layerManager;
|
2016-09-05 06:47:18 +03:00
|
|
|
bool handleOpacity; // If true, PaintMaskAndClipPath/ PaintFilter should
|
|
|
|
// apply css opacity.
|
2016-10-11 08:12:00 +03:00
|
|
|
IntRect maskRect;
|
2017-05-18 23:03:45 +03:00
|
|
|
imgDrawingParams& imgParams;
|
2016-10-11 08:12:00 +03:00
|
|
|
|
2016-05-19 10:43:32 +03:00
|
|
|
explicit PaintFramesParams(gfxContext& aCtx, nsIFrame* aFrame,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aBorderArea,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2016-06-08 08:12:35 +03:00
|
|
|
mozilla::layers::LayerManager* aLayerManager,
|
2017-05-18 23:03:45 +03:00
|
|
|
bool aHandleOpacity,
|
|
|
|
imgDrawingParams& aImgParams)
|
2016-05-19 10:43:32 +03:00
|
|
|
: ctx(aCtx), frame(aFrame), dirtyRect(aDirtyRect),
|
|
|
|
borderArea(aBorderArea), builder(aBuilder),
|
2017-05-18 23:03:45 +03:00
|
|
|
layerManager(aLayerManager), handleOpacity(aHandleOpacity),
|
|
|
|
imgParams(aImgParams)
|
2016-05-19 10:43:32 +03:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/**
|
2016-09-09 06:24:15 +03:00
|
|
|
* Paint non-SVG frame with mask, clipPath and opacity effect.
|
2008-09-11 04:24:16 +04:00
|
|
|
*/
|
2017-05-18 23:03:45 +03:00
|
|
|
static void
|
2016-08-15 20:07:57 +03:00
|
|
|
PaintMaskAndClipPath(const PaintFramesParams& aParams);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2016-10-19 12:31:36 +03:00
|
|
|
/**
|
|
|
|
* Paint mask of non-SVG frame onto a given context, aParams.ctx.
|
|
|
|
* aParams.ctx must contain an A8 surface.
|
|
|
|
*/
|
2017-05-18 23:03:45 +03:00
|
|
|
static void
|
2016-10-19 12:31:36 +03:00
|
|
|
PaintMask(const PaintFramesParams& aParams);
|
|
|
|
|
2016-10-30 16:41:06 +03:00
|
|
|
/**
|
|
|
|
* Return true if all the mask resource of aFrame are ready.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
IsMaskResourceReady(nsIFrame* aFrame);
|
|
|
|
|
2016-09-09 06:24:15 +03:00
|
|
|
/**
|
|
|
|
* Paint non-SVG frame with filter and opacity effect.
|
|
|
|
*/
|
2017-05-18 23:03:41 +03:00
|
|
|
static void
|
2017-05-18 23:03:45 +03:00
|
|
|
PaintFilter(const PaintFramesParams& aParams);
|
2016-08-15 19:59:35 +03:00
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
/**
|
|
|
|
* @param aRenderingContext the target rendering context in which the paint
|
|
|
|
* server will be rendered
|
|
|
|
* @param aTarget the target frame onto which the paint server will be
|
|
|
|
* rendered
|
|
|
|
* @param aPaintServer a first-continuation frame to use as the source
|
|
|
|
* @param aFilter a filter to be applied when scaling
|
|
|
|
* @param aDest the area the paint server image should be mapped to
|
|
|
|
* @param aFill the area to be filled with copies of the paint server image
|
|
|
|
* @param aAnchor a point in aFill which we will ensure is pixel-aligned in
|
|
|
|
* the output
|
|
|
|
* @param aDirty pixels outside this area may be skipped
|
|
|
|
* @param aPaintServerSize the size that would be filled when using
|
|
|
|
* background-repeat:no-repeat and background-size:auto. For normal background
|
|
|
|
* images, this would be the intrinsic size of the image; for gradients and
|
|
|
|
* patterns this would be the whole target frame fill area.
|
2013-08-02 00:42:34 +04:00
|
|
|
* @param aFlags pass FLAG_SYNC_DECODE_IMAGES and any images in the paint
|
|
|
|
* server will be decoding synchronously if they are not decoded already.
|
2010-08-13 17:32:27 +04:00
|
|
|
*/
|
2013-08-02 00:42:34 +04:00
|
|
|
enum {
|
|
|
|
FLAG_SYNC_DECODE_IMAGES = 0x01,
|
|
|
|
};
|
2014-01-31 07:36:42 +04:00
|
|
|
|
|
|
|
static already_AddRefed<gfxDrawable>
|
2015-09-23 21:49:05 +03:00
|
|
|
DrawableFromPaintServer(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aTarget,
|
|
|
|
const nsSize& aPaintServerSize,
|
|
|
|
const mozilla::gfx::IntSize& aRenderSize,
|
2014-09-29 17:15:19 +04:00
|
|
|
const DrawTarget* aDrawTarget,
|
2015-09-23 21:49:05 +03:00
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
uint32_t aFlags);
|
2016-10-11 08:12:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For non-SVG frames, this gives the offset to the frame's "user space".
|
|
|
|
* For SVG frames, this returns a zero offset.
|
|
|
|
*/
|
|
|
|
static nsPoint
|
|
|
|
GetOffsetToBoundingBox(nsIFrame* aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*NSSVGINTEGRATIONUTILS_H_*/
|