2008-09-11 04:24:16 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxDrawable.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2016-02-09 01:08:09 +03:00
|
|
|
#include "nsCSSClipPathInstance.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsDisplayList.h"
|
2014-02-24 19:22:58 +04:00
|
|
|
#include "nsFilterInstance.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-07-20 22:12:29 +04:00
|
|
|
#include "nsSVGElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGFilterPaintCallback.h"
|
2008-10-01 04:51:05 +04:00
|
|
|
#include "nsSVGMaskFrame.h"
|
2010-08-13 17:32:27 +04:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2012-07-17 21:03:51 +04:00
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "BasicLayers.h"
|
2013-12-30 03:35:52 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2016-01-28 08:29:00 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-01-12 11:38:48 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
2014-09-12 11:20:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2016-07-11 20:22:54 +03:00
|
|
|
using namespace mozilla::image;
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2012-06-21 04:29:50 +04:00
|
|
|
/**
|
|
|
|
* This class is used to get the pre-effects visual overflow rect of a frame,
|
|
|
|
* or, in the case of a frame with continuations, to collect the union of the
|
|
|
|
* pre-effects visual overflow rects of all the continuations. The result is
|
|
|
|
* relative to the origin (top left corner of the border box) of the frame, or,
|
|
|
|
* if the frame has continuations, the origin of the _first_ continuation.
|
|
|
|
*/
|
|
|
|
class PreEffectsVisualOverflowCollector : public nsLayoutUtils::BoxCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* If the pre-effects visual overflow rect of the frame being examined
|
|
|
|
* happens to be known, it can be passed in as aCurrentFrame and its
|
|
|
|
* pre-effects visual overflow rect can be passed in as
|
|
|
|
* aCurrentFrameOverflowArea. This is just an optimization to save a
|
|
|
|
* frame property lookup - these arguments are optional.
|
|
|
|
*/
|
|
|
|
PreEffectsVisualOverflowCollector(nsIFrame* aFirstContinuation,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
const nsRect& aCurrentFrameOverflowArea)
|
|
|
|
: mFirstContinuation(aFirstContinuation)
|
|
|
|
, mCurrentFrame(aCurrentFrame)
|
|
|
|
, mCurrentFrameOverflowArea(aCurrentFrameOverflowArea)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mFirstContinuation->GetPrevContinuation(),
|
|
|
|
"We want the first continuation here");
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void AddBox(nsIFrame* aFrame) override {
|
2012-06-21 04:29:50 +04:00
|
|
|
nsRect overflow = (aFrame == mCurrentFrame) ?
|
|
|
|
mCurrentFrameOverflowArea : GetPreEffectsVisualOverflowRect(aFrame);
|
|
|
|
mResult.UnionRect(mResult, overflow + aFrame->GetOffsetTo(mFirstContinuation));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect GetResult() const {
|
|
|
|
return mResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static nsRect GetPreEffectsVisualOverflowRect(nsIFrame* aFrame) {
|
2016-06-21 23:17:11 +03:00
|
|
|
nsRect* r = aFrame->Properties().Get(nsIFrame::PreEffectsBBoxProperty());
|
2012-06-21 04:29:50 +04:00
|
|
|
if (r) {
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
// Despite the fact that we're invoked for frames with SVG effects applied,
|
2014-02-07 05:45:33 +04:00
|
|
|
// we can actually get here. All continuations and IB split siblings of a
|
2012-06-21 04:29:50 +04:00
|
|
|
// frame with SVG effects applied will have the PreEffectsBBoxProperty
|
|
|
|
// property set on them. Therefore, the frames that are passed to us will
|
|
|
|
// always have that property set...well, with one exception. If the frames
|
|
|
|
// for an element with SVG effects applied have been subject to an "IB
|
|
|
|
// split", then the block frame(s) that caused the split will have been
|
|
|
|
// wrapped in anonymous, inline-block, nsBlockFrames of pseudo-type
|
2014-02-07 05:45:33 +04:00
|
|
|
// nsCSSAnonBoxes::mozAnonymousBlock. These "IB split sibling" anonymous
|
2012-06-21 04:29:50 +04:00
|
|
|
// blocks will have the PreEffectsBBoxProperty property set on them, but
|
|
|
|
// they will never be passed to us. Instead, we'll be passed the block
|
|
|
|
// children that they wrap, which don't have the PreEffectsBBoxProperty
|
|
|
|
// property set on them. This is actually okay. What we care about is
|
|
|
|
// collecting the _pre_ effects visual overflow rects of the frames to
|
|
|
|
// which the SVG effects have been applied. Since the IB split results in
|
|
|
|
// any overflow rect adjustments for transforms, effects, etc. taking
|
|
|
|
// place on the anonymous block wrappers, the wrapped children are left
|
|
|
|
// with their overflow rects unaffected. In other words, calling
|
|
|
|
// GetVisualOverflowRect() on the children will return their pre-effects
|
|
|
|
// visual overflow rects, just as we need.
|
|
|
|
//
|
|
|
|
// A couple of tests that demonstrate the IB split and cause us to get here
|
|
|
|
// are:
|
|
|
|
//
|
|
|
|
// * reftests/svg/svg-integration/clipPath-html-06.xhtml
|
|
|
|
// * reftests/svg/svg-integration/clipPath-html-06-extref.xhtml
|
|
|
|
//
|
|
|
|
// If we ever got passed a frame with the PreTransformOverflowAreasProperty
|
|
|
|
// property set, that would be bad, since then our GetVisualOverflowRect()
|
|
|
|
// call would give us the post-effects, and post-transform, overflow rect.
|
|
|
|
//
|
2017-01-12 11:38:48 +03:00
|
|
|
// There are two more exceptions:
|
|
|
|
// 1. In nsStyleImageLayers::Layer::CalcDifference, we do not add
|
|
|
|
// nsChangeHint_UpdateOverflow hint when image mask(not SVG mask)
|
|
|
|
// property value changed, since replace image mask does not cause
|
|
|
|
// layout change. So even if we apply a new mask image to this frame,
|
|
|
|
// PreEffectsBBoxProperty might still left empty.
|
|
|
|
// 2. During restyling: before the last continuation is restyled, there
|
|
|
|
// is no guarantee that every continuation carries a
|
|
|
|
// PreEffectsBBoxProperty property.
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
|
|
|
bool mightHaveNoneSVGMask =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame).MightHaveNoneSVGMask();
|
|
|
|
bool inRestyle =
|
|
|
|
aFrame->PresContext()->RestyleManager()->AsGecko()->IsInStyleRefresh();
|
|
|
|
|
|
|
|
NS_ASSERTION(mightHaveNoneSVGMask || inRestyle ||
|
2016-11-28 11:26:34 +03:00
|
|
|
aFrame->GetParent()->StyleContext()->GetPseudo() ==
|
2017-01-12 06:21:14 +03:00
|
|
|
nsCSSAnonBoxes::mozAnonymousBlock,
|
2012-06-21 04:29:50 +04:00
|
|
|
"How did we getting here, then?");
|
2017-01-12 11:38:48 +03:00
|
|
|
#endif
|
2012-06-21 04:29:50 +04:00
|
|
|
NS_ASSERTION(!aFrame->Properties().Get(
|
|
|
|
aFrame->PreTransformOverflowAreasProperty()),
|
|
|
|
"GetVisualOverflowRect() won't return the pre-effects rect!");
|
|
|
|
return aFrame->GetVisualOverflowRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* mFirstContinuation;
|
|
|
|
nsIFrame* mCurrentFrame;
|
|
|
|
const nsRect& mCurrentFrameOverflowArea;
|
|
|
|
nsRect mResult;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the union of the pre-effects visual overflow rects of all of a frame's
|
|
|
|
* continuations, in "user space".
|
|
|
|
*/
|
|
|
|
static nsRect
|
|
|
|
GetPreEffectsVisualOverflowUnion(nsIFrame* aFirstContinuation,
|
|
|
|
nsIFrame* aCurrentFrame,
|
|
|
|
const nsRect& aCurrentFramePreEffectsOverflow,
|
|
|
|
const nsPoint& aFirstContinuationToUserSpace)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aFirstContinuation->GetPrevContinuation(),
|
|
|
|
"Need first continuation here");
|
|
|
|
PreEffectsVisualOverflowCollector collector(aFirstContinuation,
|
|
|
|
aCurrentFrame,
|
|
|
|
aCurrentFramePreEffectsOverflow);
|
|
|
|
// Compute union of all overflow areas relative to aFirstContinuation:
|
|
|
|
nsLayoutUtils::GetAllInFlowBoxes(aFirstContinuation, &collector);
|
|
|
|
// Return the result in user space:
|
|
|
|
return collector.GetResult() + aFirstContinuationToUserSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGIntegrationUtils::UsingEffectsForFrame(const nsIFrame* aFrame)
|
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
// Even when SVG display lists are disabled, returning true for SVG frames
|
|
|
|
// does not adversely affect any of our callers. Therefore we don't bother
|
|
|
|
// checking the SDL prefs here, since we don't know if we're being called for
|
|
|
|
// painting or hit-testing anyway.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
|
2016-04-12 08:52:43 +03:00
|
|
|
return aFrame->StyleEffects()->HasFilters() ||
|
|
|
|
style->HasClipPath() ||
|
|
|
|
style->mMask.HasLayerWithImage();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-16 08:56:11 +03:00
|
|
|
bool
|
|
|
|
nsSVGIntegrationUtils::UsingMaskOrClipPathForFrame(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
|
|
|
|
return style->HasClipPath() ||
|
2016-09-05 06:47:18 +03:00
|
|
|
style->mMask.HasLayerWithImage();
|
2016-08-16 08:56:11 +03:00
|
|
|
}
|
|
|
|
|
2016-10-11 08:12:00 +03:00
|
|
|
nsPoint
|
|
|
|
nsSVGIntegrationUtils::GetOffsetToBoundingBox(nsIFrame* aFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04:00
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
// Do NOT call GetAllInFlowRectsUnion for SVG - it will get the
|
|
|
|
// covered region relative to the nsSVGOuterSVGFrame, which is absolutely
|
|
|
|
// not what we want. SVG frames are always in user space, so they have
|
|
|
|
// no offset adjustment to make.
|
|
|
|
return nsPoint();
|
|
|
|
}
|
2012-06-19 19:28:04 +04:00
|
|
|
|
|
|
|
// The GetAllInFlowRectsUnion() call gets the union of the frame border-box
|
|
|
|
// rects over all continuations, relative to the origin (top-left of the
|
|
|
|
// border box) of its second argument (here, aFrame, the first continuation).
|
|
|
|
return -nsLayoutUtils::GetAllInFlowRectsUnion(aFrame, aFrame).TopLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsSize
|
|
|
|
nsSVGIntegrationUtils::GetContinuationUnionSize(nsIFrame* aNonSVGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
return nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame).Size();
|
|
|
|
}
|
|
|
|
|
2013-12-30 03:35:52 +04:00
|
|
|
/* static */ gfx::Size
|
2012-06-19 19:28:04 +04:00
|
|
|
nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
nsRect r = nsLayoutUtils::GetAllInFlowRectsUnion(firstFrame, firstFrame);
|
|
|
|
nsPresContext* presContext = firstFrame->PresContext();
|
2013-12-30 03:35:52 +04:00
|
|
|
return gfx::Size(presContext->AppUnitsToFloatCSSPixels(r.width),
|
|
|
|
presContext->AppUnitsToFloatCSSPixels(r.height));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-21 04:29:50 +04:00
|
|
|
gfxRect
|
|
|
|
nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-06-21 04:29:50 +04:00
|
|
|
NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG),
|
|
|
|
"SVG frames should not get here");
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame);
|
2012-06-21 04:29:50 +04:00
|
|
|
// 'r' is in "user space":
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRect r = GetPreEffectsVisualOverflowUnion(firstFrame, nullptr, nsRect(),
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
GetOffsetToBoundingBox(firstFrame));
|
2012-06-21 04:29:50 +04:00
|
|
|
return nsLayoutUtils::RectToGfxRect(r,
|
|
|
|
aNonSVGFrame->PresContext()->AppUnitsPerCSSPixel());
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-22 14:42:05 +04:00
|
|
|
// XXX Since we're called during reflow, this method is broken for frames with
|
|
|
|
// continuations. When we're called for a frame with continuations, we're
|
|
|
|
// called for each continuation in turn as it's reflowed. However, it isn't
|
|
|
|
// until the last continuation is reflowed that this method's
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
// GetOffsetToBoundingBox() and GetPreEffectsVisualOverflowUnion() calls will
|
2012-06-22 14:42:05 +04:00
|
|
|
// obtain valid border boxes for all the continuations. As a result, we'll
|
|
|
|
// end up returning bogus post-filter visual overflow rects for all the prior
|
|
|
|
// continuations. Unfortunately, by the time the last continuation is
|
|
|
|
// reflowed, it's too late to go back and set and propagate the overflow
|
|
|
|
// rects on the previous continuations.
|
|
|
|
//
|
|
|
|
// The reason that we need to pass an override bbox to
|
|
|
|
// GetPreEffectsVisualOverflowUnion rather than just letting it call into our
|
|
|
|
// GetSVGBBoxForNonSVGFrame method is because we get called by
|
2014-02-15 09:29:12 +04:00
|
|
|
// ComputeEffectsRect when it has been called with
|
2012-06-22 14:42:05 +04:00
|
|
|
// aStoreRectProperties set to false. In this case the pre-effects visual
|
|
|
|
// overflow rect that it has been passed may be different to that stored on
|
|
|
|
// aFrame, resulting in a different bbox.
|
|
|
|
//
|
|
|
|
// XXXjwatt The pre-effects visual overflow rect passed to
|
2014-02-15 09:29:12 +04:00
|
|
|
// ComputeEffectsRect won't include continuation overflows, so
|
2012-06-22 14:42:05 +04:00
|
|
|
// for frames with continuation the following filter analysis will likely end
|
|
|
|
// up being carried out with a bbox created as if the frame didn't have
|
|
|
|
// continuations.
|
|
|
|
//
|
|
|
|
// XXXjwatt Using aPreEffectsOverflowRect to create the bbox isn't really right
|
|
|
|
// for SVG frames, since for SVG frames the SVG spec defines the bbox to be
|
|
|
|
// something quite different to the pre-effects visual overflow rect. However,
|
|
|
|
// we're essentially calculating an invalidation area here, and using the
|
|
|
|
// pre-effects overflow rect will actually overestimate that area which, while
|
|
|
|
// being a bit wasteful, isn't otherwise a problem.
|
|
|
|
//
|
2008-09-11 04:24:16 +04:00
|
|
|
nsRect
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::
|
|
|
|
ComputePostEffectsVisualOverflowRect(nsIFrame* aFrame,
|
|
|
|
const nsRect& aPreEffectsOverflowRect)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-06-21 04:29:50 +04:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT),
|
|
|
|
"Don't call this on SVG child frames");
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
2014-02-24 19:22:58 +04:00
|
|
|
if (!effectProperties.HasValidFilter()) {
|
2012-06-21 04:29:50 +04:00
|
|
|
return aPreEffectsOverflowRect;
|
2014-02-24 19:22:58 +04:00
|
|
|
}
|
2012-06-21 04:29:50 +04:00
|
|
|
|
2012-06-22 14:42:05 +04:00
|
|
|
// Create an override bbox - see comment above:
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint firstFrameToBoundingBox = GetOffsetToBoundingBox(firstFrame);
|
2012-06-23 07:01:36 +04:00
|
|
|
// overrideBBox is in "user space", in _CSS_ pixels:
|
2012-06-22 14:42:05 +04:00
|
|
|
// XXX Why are we rounding out to pixel boundaries? We don't do that in
|
|
|
|
// GetSVGBBoxForNonSVGFrame, and it doesn't appear to be necessary.
|
2012-06-23 07:01:36 +04:00
|
|
|
gfxRect overrideBBox =
|
|
|
|
nsLayoutUtils::RectToGfxRect(
|
|
|
|
GetPreEffectsVisualOverflowUnion(firstFrame, aFrame,
|
|
|
|
aPreEffectsOverflowRect,
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
firstFrameToBoundingBox),
|
2012-06-23 07:01:36 +04:00
|
|
|
aFrame->PresContext()->AppUnitsPerCSSPixel());
|
|
|
|
overrideBBox.RoundOut();
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
nsRect overflowRect =
|
2014-02-24 19:22:58 +04:00
|
|
|
nsFilterInstance::GetPostFilterBounds(firstFrame, &overrideBBox);
|
2012-06-21 04:29:50 +04:00
|
|
|
|
|
|
|
// Return overflowRect relative to aFrame, rather than "user space":
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
return overflowRect - (aFrame->GetOffsetTo(firstFrame) + firstFrameToBoundingBox);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2014-04-24 12:25:17 +04:00
|
|
|
nsIntRegion
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::AdjustInvalidAreaForSVGEffects(nsIFrame* aFrame,
|
2012-11-28 08:06:07 +04:00
|
|
|
const nsPoint& aToReferenceFrame,
|
2014-04-24 12:25:17 +04:00
|
|
|
const nsIntRegion& aInvalidRegion)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2014-04-24 12:25:17 +04:00
|
|
|
if (aInvalidRegion.IsEmpty()) {
|
2013-09-06 13:30:27 +04:00
|
|
|
return nsIntRect();
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2010-11-11 00:18:11 +03:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
2014-02-10 08:31:03 +04:00
|
|
|
if (!prop || !prop->IsInObserverLists()) {
|
2014-04-24 12:25:17 +04:00
|
|
|
return aInvalidRegion;
|
2010-11-10 08:50:29 +03:00
|
|
|
}
|
|
|
|
|
2012-08-29 09:39:33 +04:00
|
|
|
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2008-12-12 11:25:16 +03:00
|
|
|
// The frame is either not there or not currently available,
|
|
|
|
// perhaps because we're in the middle of tearing stuff down.
|
2012-11-28 08:06:07 +04:00
|
|
|
// Be conservative, return our visual overflow rect relative
|
|
|
|
// to the reference frame.
|
|
|
|
nsRect overflow = aFrame->GetVisualOverflowRect() + aToReferenceFrame;
|
2012-08-29 09:39:33 +04:00
|
|
|
return overflow.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-12-12 11:25:16 +03:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-04-24 12:25:17 +04:00
|
|
|
// Convert aInvalidRegion into bounding box frame space in app units:
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
nsPoint toBoundingBox =
|
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-11-28 08:06:07 +04:00
|
|
|
// The initial rect was relative to the reference frame, so we need to
|
|
|
|
// remove that offset to get a rect relative to the current frame.
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
toBoundingBox -= aToReferenceFrame;
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion preEffectsRegion = aInvalidRegion.ToAppUnits(appUnitsPerDevPixel).MovedBy(toBoundingBox);
|
2012-06-19 19:28:04 +04:00
|
|
|
|
2012-11-28 08:06:07 +04:00
|
|
|
// Adjust the dirty area for effects, and shift it back to being relative to
|
|
|
|
// the reference frame.
|
2014-04-24 12:25:17 +04:00
|
|
|
nsRegion result = nsFilterInstance::GetPostFilterDirtyArea(firstFrame,
|
|
|
|
preEffectsRegion).MovedBy(-toBoundingBox);
|
2012-11-28 08:06:07 +04:00
|
|
|
// Return the result, in pixels relative to the reference frame.
|
2012-08-29 09:39:33 +04:00
|
|
|
return result.ToOutsidePixels(appUnitsPerDevPixel);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame* aFrame,
|
2012-06-19 19:28:04 +04:00
|
|
|
const nsRect& aDirtyRect)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
// Don't bother calling GetEffectProperties; the filter property should
|
|
|
|
// already have been set up during reflow/ComputeFrameEffectsRect
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2014-02-24 19:22:58 +04:00
|
|
|
nsSVGFilterProperty *prop = nsSVGEffects::GetFilterProperty(firstFrame);
|
|
|
|
if (!prop || !prop->ReferencesValidResources()) {
|
2012-06-19 19:28:04 +04:00
|
|
|
return aDirtyRect;
|
2014-02-24 19:22:58 +04:00
|
|
|
}
|
2014-08-01 04:37:35 +04:00
|
|
|
|
2012-06-26 14:49:23 +04:00
|
|
|
// Convert aDirtyRect into "user space" in app units:
|
2012-06-19 19:28:04 +04:00
|
|
|
nsPoint toUserSpace =
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2012-06-26 14:49:23 +04:00
|
|
|
nsRect postEffectsRect = aDirtyRect + toUserSpace;
|
2012-06-19 19:28:04 +04:00
|
|
|
|
2012-06-26 14:49:23 +04:00
|
|
|
// Return ther result, relative to aFrame, not in user space:
|
2014-04-24 12:25:17 +04:00
|
|
|
return nsFilterInstance::GetPreFilterNeededArea(firstFrame, postEffectsRect).GetBounds()
|
2014-02-24 19:22:58 +04:00
|
|
|
- toUserSpace;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-11 04:24:16 +04:00
|
|
|
nsSVGIntegrationUtils::HitTestFrameForEffects(nsIFrame* aFrame, const nsPoint& aPt)
|
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
// Convert aPt to user space:
|
2013-01-04 15:48:12 +04:00
|
|
|
nsPoint toUserSpace;
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
// XXXmstange Isn't this wrong for svg:use and innerSVG frames?
|
2013-01-04 15:48:12 +04:00
|
|
|
toUserSpace = aFrame->GetPosition();
|
|
|
|
} else {
|
|
|
|
toUserSpace =
|
Bug 997735 - Rename nsSVGIntegrationUtils::GetOffsetToUserSpace to GetOffsetToBoundingBox. r=roc
There are three spaces that nsSVGIntegrationUtils needs to convert between. I'll call them "frame space", "bounding box frame space" and "user space".
"Bounding box frame space" has its origin at the top left of the union of a frame's border boxes over all continuations.
For SVG frames, "frame space" and "bounding box frame space" are the same because SVG frames don't have multiple continuations.
For non-SVG frames, "bounding box frame space" and "user space" are the same.
However, for SVG frames, "bounding box frame space" and "user space" are different! For example, for a <rect x="100" y="100">, the point 0,0 in frame space is at the rect's top left corner, but the point 0,0 in user space is 100,100 pixels away from the rect's corner.
nsSVGIntegrationUtils::GetOffsetToUserSpace took the non-SVG viewpoint, but it's misleading for SVG frames.
2014-04-23 13:47:31 +04:00
|
|
|
aFrame->GetOffsetTo(firstFrame) + GetOffsetToBoundingBox(firstFrame);
|
2013-01-04 15:48:12 +04:00
|
|
|
}
|
2012-06-19 19:28:04 +04:00
|
|
|
nsPoint pt = aPt + toUserSpace;
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxPoint userSpacePt =
|
|
|
|
gfxPoint(pt.x, pt.y) / aFrame->PresContext()->AppUnitsPerCSSPixel();
|
|
|
|
return nsSVGUtils::HitTestClip(firstFrame, userSpacePt);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class RegularFramePaintCallback : public nsSVGFilterPaintCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RegularFramePaintCallback(nsDisplayListBuilder* aBuilder,
|
2012-07-17 21:03:51 +04:00
|
|
|
LayerManager* aManager,
|
2008-09-11 04:24:16 +04:00
|
|
|
const nsPoint& aOffset)
|
2012-07-17 21:03:51 +04:00
|
|
|
: mBuilder(aBuilder), mLayerManager(aManager),
|
2010-03-10 23:55:05 +03:00
|
|
|
mOffset(aOffset) {}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2016-07-14 07:47:06 +03:00
|
|
|
virtual DrawResult Paint(gfxContext& aContext, nsIFrame *aTarget,
|
|
|
|
const gfxMatrix& aTransform,
|
|
|
|
const nsIntRect* aDirtyRect) override
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2016-11-07 19:38:45 +03:00
|
|
|
BasicLayerManager* basic = mLayerManager->AsBasicLayerManager();
|
2014-10-31 23:08:54 +03:00
|
|
|
basic->SetTarget(&aContext);
|
2014-09-11 10:48:09 +04:00
|
|
|
|
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(-mOffset,
|
|
|
|
aTarget->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
2014-10-31 23:08:54 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore autoSR(&aContext);
|
|
|
|
aContext.SetMatrix(aContext.CurrentMatrix().Translate(devPixelOffset));
|
2014-09-11 10:48:09 +04:00
|
|
|
|
2014-09-26 21:06:08 +04:00
|
|
|
mLayerManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer, mBuilder);
|
2016-07-14 07:47:06 +03:00
|
|
|
return DrawResult::SUCCESS;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDisplayListBuilder* mBuilder;
|
2012-07-17 21:03:51 +04:00
|
|
|
LayerManager* mLayerManager;
|
2008-09-11 04:24:16 +04:00
|
|
|
nsPoint mOffset;
|
|
|
|
};
|
|
|
|
|
2016-09-22 06:12:54 +03:00
|
|
|
typedef nsSVGIntegrationUtils::PaintFramesParams PaintFramesParams;
|
|
|
|
|
2016-11-02 10:10:46 +03:00
|
|
|
/**
|
|
|
|
* Paint css-positioned-mask onto a given target(aMaskDT).
|
|
|
|
*/
|
2016-07-11 20:22:54 +03:00
|
|
|
static DrawResult
|
2016-11-02 10:10:46 +03:00
|
|
|
PaintMaskSurface(const PaintFramesParams& aParams,
|
|
|
|
DrawTarget* aMaskDT, float aOpacity, nsStyleContext* aSC,
|
|
|
|
const nsTArray<nsSVGMaskFrame*>& aMaskFrames,
|
|
|
|
const gfxMatrix& aMaskSurfaceMatrix,
|
|
|
|
const nsPoint& aOffsetToUserSpace)
|
2016-05-19 10:43:43 +03:00
|
|
|
{
|
2016-05-31 10:45:42 +03:00
|
|
|
MOZ_ASSERT(aMaskFrames.Length() > 0);
|
2016-11-02 10:10:46 +03:00
|
|
|
MOZ_ASSERT(aMaskDT->GetFormat() == SurfaceFormat::A8);
|
2017-01-03 11:35:17 +03:00
|
|
|
MOZ_ASSERT(aOpacity == 1.0 || aMaskFrames.Length() == 1);
|
2016-05-19 10:43:43 +03:00
|
|
|
|
2016-11-02 10:10:46 +03:00
|
|
|
const nsStyleSVGReset *svgReset = aSC->StyleSVGReset();
|
2016-05-19 10:44:07 +03:00
|
|
|
gfxMatrix cssPxToDevPxMatrix =
|
|
|
|
nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aParams.frame);
|
2016-05-19 10:43:43 +03:00
|
|
|
|
2016-06-18 02:24:26 +03:00
|
|
|
nsPresContext* presContext = aParams.frame->PresContext();
|
|
|
|
gfxPoint devPixelOffsetToUserSpace =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(aOffsetToUserSpace,
|
|
|
|
presContext->AppUnitsPerDevPixel());
|
|
|
|
|
2016-11-02 10:10:46 +03:00
|
|
|
RefPtr<gfxContext> maskContext = gfxContext::CreateOrNull(aMaskDT);
|
|
|
|
MOZ_ASSERT(maskContext);
|
|
|
|
maskContext->SetMatrix(aMaskSurfaceMatrix);
|
2016-09-27 21:46:47 +03:00
|
|
|
|
2016-06-18 02:24:26 +03:00
|
|
|
// Multiple SVG masks interleave with image mask. Paint each layer onto
|
2016-11-02 10:10:46 +03:00
|
|
|
// aMaskDT one at a time.
|
2016-05-31 10:45:42 +03:00
|
|
|
for (int i = aMaskFrames.Length() - 1; i >= 0 ; i--) {
|
|
|
|
nsSVGMaskFrame *maskFrame = aMaskFrames[i];
|
2016-11-16 07:59:52 +03:00
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
2016-05-31 10:45:42 +03:00
|
|
|
CompositionOp compositionOp = (i == int(aMaskFrames.Length() - 1))
|
2016-05-26 11:07:43 +03:00
|
|
|
? CompositionOp::OP_OVER
|
|
|
|
: nsCSSRendering::GetGFXCompositeMode(svgReset->mMask.mLayers[i].mComposite);
|
|
|
|
|
2016-05-19 10:44:07 +03:00
|
|
|
// maskFrame != nullptr means we get a SVG mask.
|
|
|
|
// maskFrame == nullptr means we get an image mask.
|
|
|
|
if (maskFrame) {
|
|
|
|
Matrix svgMaskMatrix;
|
2016-11-16 07:59:52 +03:00
|
|
|
nsSVGMaskFrame::MaskParams params(maskContext, aParams.frame,
|
|
|
|
cssPxToDevPxMatrix,
|
|
|
|
aOpacity, &svgMaskMatrix,
|
|
|
|
svgReset->mMask.mLayers[i].mMaskMode);
|
|
|
|
RefPtr<SourceSurface> svgMask;
|
|
|
|
Tie(result, svgMask) = maskFrame->GetMaskForMaskedFrame(params);
|
|
|
|
|
2016-05-19 10:44:07 +03:00
|
|
|
if (svgMask) {
|
2016-11-16 07:59:52 +03:00
|
|
|
MOZ_ASSERT(result == DrawResult::SUCCESS);
|
2016-05-19 10:44:07 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore matRestore(maskContext);
|
|
|
|
|
|
|
|
maskContext->Multiply(ThebesMatrix(svgMaskMatrix));
|
2016-11-02 10:10:46 +03:00
|
|
|
aMaskDT->MaskSurface(ColorPattern(Color(0.0, 0.0, 0.0, 1.0)), svgMask,
|
2016-11-04 09:48:11 +03:00
|
|
|
Point(0, 0),
|
|
|
|
DrawOptions(1.0, compositionOp));
|
2016-05-19 10:44:07 +03:00
|
|
|
}
|
2016-11-16 07:59:52 +03:00
|
|
|
|
|
|
|
if (result != DrawResult::SUCCESS) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-05-19 10:44:07 +03:00
|
|
|
} else {
|
|
|
|
gfxContextMatrixAutoSaveRestore matRestore(maskContext);
|
|
|
|
|
2016-06-18 02:24:26 +03:00
|
|
|
maskContext->Multiply(gfxMatrix::Translation(-devPixelOffsetToUserSpace));
|
2016-05-19 10:44:07 +03:00
|
|
|
nsRenderingContext rc(maskContext);
|
|
|
|
nsCSSRendering::PaintBGParams params =
|
2016-06-18 02:24:26 +03:00
|
|
|
nsCSSRendering::PaintBGParams::ForSingleLayer(*presContext,
|
2016-05-19 10:44:07 +03:00
|
|
|
rc, aParams.dirtyRect,
|
|
|
|
aParams.borderArea,
|
|
|
|
aParams.frame,
|
|
|
|
aParams.builder->GetBackgroundPaintFlags() |
|
|
|
|
nsCSSRendering::PAINTBG_MASK_IMAGE,
|
2017-01-03 11:35:17 +03:00
|
|
|
i, compositionOp,
|
|
|
|
aOpacity);
|
2016-05-19 10:44:07 +03:00
|
|
|
|
2016-11-16 07:59:52 +03:00
|
|
|
result =
|
2017-01-03 06:57:13 +03:00
|
|
|
nsCSSRendering::PaintStyleImageLayerWithSC(params, aSC,
|
2016-07-11 20:22:54 +03:00
|
|
|
*aParams.frame->StyleBorder());
|
|
|
|
if (result != DrawResult::SUCCESS) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-05-19 10:43:43 +03:00
|
|
|
}
|
2016-05-19 10:44:07 +03:00
|
|
|
}
|
2016-05-19 10:43:43 +03:00
|
|
|
|
2016-11-02 10:10:46 +03:00
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
struct MaskPaintResult {
|
|
|
|
RefPtr<SourceSurface> maskSurface;
|
|
|
|
Matrix maskTransform;
|
|
|
|
DrawResult result;
|
|
|
|
bool transparentBlackMask;
|
|
|
|
bool opacityApplied;
|
|
|
|
|
|
|
|
MaskPaintResult()
|
|
|
|
: result(DrawResult::SUCCESS), transparentBlackMask(false),
|
|
|
|
opacityApplied(false)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static MaskPaintResult
|
2016-11-02 10:10:46 +03:00
|
|
|
CreateAndPaintMaskSurface(const PaintFramesParams& aParams,
|
|
|
|
float aOpacity, nsStyleContext* aSC,
|
|
|
|
const nsTArray<nsSVGMaskFrame*>& aMaskFrames,
|
2016-11-23 08:51:36 +03:00
|
|
|
const nsPoint& aOffsetToUserSpace)
|
2016-11-02 10:10:46 +03:00
|
|
|
{
|
|
|
|
const nsStyleSVGReset *svgReset = aSC->StyleSVGReset();
|
|
|
|
MOZ_ASSERT(aMaskFrames.Length() > 0);
|
2016-11-23 08:51:36 +03:00
|
|
|
MaskPaintResult paintResult;
|
2016-11-02 10:10:46 +03:00
|
|
|
|
|
|
|
gfxContext& ctx = aParams.ctx;
|
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
// Optimization for single SVG mask.
|
2016-11-02 10:10:46 +03:00
|
|
|
if (((aMaskFrames.Length() == 1) && aMaskFrames[0])) {
|
|
|
|
gfxMatrix cssPxToDevPxMatrix =
|
|
|
|
nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(aParams.frame);
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.opacityApplied = true;
|
2016-11-16 07:59:52 +03:00
|
|
|
nsSVGMaskFrame::MaskParams params(&ctx, aParams.frame, cssPxToDevPxMatrix,
|
2016-11-23 08:51:36 +03:00
|
|
|
aOpacity, &paintResult.maskTransform,
|
2016-11-16 07:59:52 +03:00
|
|
|
svgReset->mMask.mLayers[0].mMaskMode);
|
2016-11-23 08:51:36 +03:00
|
|
|
Tie(paintResult.result, paintResult.maskSurface) =
|
2016-11-16 07:59:52 +03:00
|
|
|
aMaskFrames[0]->GetMaskForMaskedFrame(params);
|
2016-11-23 08:51:36 +03:00
|
|
|
|
|
|
|
if (!paintResult.maskSurface) {
|
|
|
|
paintResult.transparentBlackMask = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return paintResult;
|
2016-11-02 10:10:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const IntRect& maskSurfaceRect = aParams.maskRect;
|
|
|
|
if (maskSurfaceRect.IsEmpty()) {
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.transparentBlackMask = true;
|
|
|
|
return paintResult;
|
2016-11-02 10:10:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> maskDT =
|
|
|
|
ctx.GetDrawTarget()->CreateSimilarDrawTarget(maskSurfaceRect.Size(),
|
|
|
|
SurfaceFormat::A8);
|
|
|
|
if (!maskDT || !maskDT->IsValid()) {
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.result = DrawResult::TEMPORARY_ERROR;
|
|
|
|
return paintResult;
|
2016-11-02 10:10:46 +03:00
|
|
|
}
|
|
|
|
|
2017-01-03 11:35:17 +03:00
|
|
|
// We can paint mask along with opacity only if
|
|
|
|
// 1. There is only one mask, or
|
|
|
|
// 2. No overlap among masks.
|
|
|
|
// Collision detect in #2 is not that trivial, we only accept #1 here.
|
|
|
|
paintResult.opacityApplied = (aMaskFrames.Length() == 1);
|
2016-11-02 10:10:46 +03:00
|
|
|
|
|
|
|
// Set context's matrix on maskContext, offset by the maskSurfaceRect's
|
|
|
|
// position. This makes sure that we combine the masks in device space.
|
|
|
|
gfxMatrix maskSurfaceMatrix =
|
|
|
|
ctx.CurrentMatrix() * gfxMatrix::Translation(-aParams.maskRect.TopLeft());
|
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.result = PaintMaskSurface(aParams, maskDT,
|
|
|
|
paintResult.opacityApplied
|
|
|
|
? aOpacity : 1.0,
|
|
|
|
aSC, aMaskFrames, maskSurfaceMatrix,
|
|
|
|
aOffsetToUserSpace);
|
|
|
|
if (paintResult.result != DrawResult::SUCCESS) {
|
|
|
|
// Now we know the status of mask resource since we used it while painting.
|
|
|
|
// According to the return value of PaintMaskSurface, we know whether mask
|
|
|
|
// resource is resolvable or not.
|
|
|
|
//
|
|
|
|
// For a HTML doc:
|
|
|
|
// According to css-masking spec, always create a mask surface when
|
|
|
|
// we have any item in maskFrame even if all of those items are
|
|
|
|
// non-resolvable <mask-sources> or <images>.
|
|
|
|
// Set paintResult.transparentBlackMask as true, the caller should stop
|
|
|
|
// painting masked content as if this mask is a transparent black one.
|
|
|
|
// For a SVG doc:
|
|
|
|
// SVG 1.1 say that if we fail to resolve a mask, we should draw the
|
|
|
|
// object unmasked.
|
|
|
|
// Left patinResult.maskSurface empty, the caller should paint all
|
|
|
|
// masked content as if this mask is an opaque white one(no mask).
|
|
|
|
paintResult.transparentBlackMask =
|
|
|
|
!(aParams.frame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
|
|
|
|
|
|
|
MOZ_ASSERT(!paintResult.maskSurface);
|
|
|
|
return paintResult;
|
2016-11-02 10:10:46 +03:00
|
|
|
}
|
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.maskTransform = ToMatrix(maskSurfaceMatrix);
|
|
|
|
if (!paintResult.maskTransform.Invert()) {
|
|
|
|
return paintResult;
|
2016-05-19 10:43:43 +03:00
|
|
|
}
|
2016-05-19 10:44:07 +03:00
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
paintResult.maskSurface = maskDT->Snapshot();
|
|
|
|
return paintResult;
|
2016-05-19 10:43:43 +03:00
|
|
|
}
|
|
|
|
|
2016-08-15 19:05:10 +03:00
|
|
|
static bool
|
2016-10-28 08:04:17 +03:00
|
|
|
ValidateSVGFrame(nsIFrame* aFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-10-28 08:04:17 +03:00
|
|
|
NS_ASSERTION(!(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) ||
|
2012-07-20 22:12:29 +04:00
|
|
|
(NS_SVGDisplayListPaintingEnabled() &&
|
2016-10-28 08:04:17 +03:00
|
|
|
!(aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY)),
|
2012-07-20 22:12:29 +04:00
|
|
|
"Should not use nsSVGIntegrationUtils on this SVG frame");
|
2009-01-12 22:20:59 +03:00
|
|
|
#endif
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2016-10-28 08:04:17 +03:00
|
|
|
bool hasSVGLayout = (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
|
|
|
if (hasSVGLayout) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(aFrame);
|
|
|
|
MOZ_ASSERT(svgChildFrame && aFrame->GetContent()->IsSVGElement(),
|
|
|
|
"A non-SVG frame carries NS_FRAME_SVG_LAYOUT flag?");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const nsIContent* content = aFrame->GetContent();
|
2016-08-15 19:05:10 +03:00
|
|
|
if (!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
|
|
|
// The SVG spec says not to draw _anything_
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
/**
|
|
|
|
* Setup transform matrix of a gfx context by a specific frame. Depend on
|
|
|
|
* aClipCtx, this function may clip that context by the visual overflow area
|
|
|
|
* of aFrame.
|
|
|
|
*
|
|
|
|
* @param aFrame is the target frame.
|
|
|
|
* @param aOffsetToBoundingBox returns the offset between the reference frame
|
|
|
|
* and the bounding box of aFrame.
|
|
|
|
* @oaram aOffsetToUserSpace returns the offset between the reference frame and
|
|
|
|
* the user space coordinate of aFrame.
|
|
|
|
*/
|
2016-08-15 19:33:35 +03:00
|
|
|
static void
|
2016-09-21 11:49:27 +03:00
|
|
|
SetupContextMatrix(nsIFrame* aFrame, const PaintFramesParams& aParams,
|
2016-12-21 11:21:23 +03:00
|
|
|
nsPoint& aOffsetToBoundingBox, nsPoint& aOffsetToUserSpace)
|
2016-08-15 19:33:35 +03:00
|
|
|
{
|
2016-09-21 11:49:27 +03:00
|
|
|
aOffsetToBoundingBox = aParams.builder->ToReferenceFrame(aFrame) -
|
2016-10-11 08:12:00 +03:00
|
|
|
nsSVGIntegrationUtils::GetOffsetToBoundingBox(aFrame);
|
2016-09-21 11:49:27 +03:00
|
|
|
if (!aFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
2016-08-15 19:33:35 +03:00
|
|
|
/* Snap the offset if the reference frame is not a SVG frame,
|
|
|
|
* since other frames will be snapped to pixel when rendering. */
|
|
|
|
aOffsetToBoundingBox = nsPoint(
|
2016-09-21 11:49:27 +03:00
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(aOffsetToBoundingBox.x),
|
|
|
|
aFrame->PresContext()->RoundAppUnitsToNearestDevPixels(aOffsetToBoundingBox.y));
|
2016-08-15 19:33:35 +03:00
|
|
|
}
|
|
|
|
|
2016-09-18 18:16:35 +03:00
|
|
|
// After applying only "aOffsetToBoundingBox", aParams.ctx would have its
|
|
|
|
// origin at the top left corner of frame's bounding box (over all
|
|
|
|
// continuations).
|
2016-08-15 19:33:35 +03:00
|
|
|
// However, SVG painting needs the origin to be located at the origin of the
|
|
|
|
// SVG frame's "user space", i.e. the space in which, for example, the
|
|
|
|
// frame's BBox lives.
|
|
|
|
// SVG geometry frames and foreignObject frames apply their own offsets, so
|
|
|
|
// their position is relative to their user space. So for these frame types,
|
2016-12-21 11:21:23 +03:00
|
|
|
// if we want aParams.ctx to be in user space, we first need to subtract the
|
2016-08-15 19:33:35 +03:00
|
|
|
// frame's position so that SVG painting can later add it again and the
|
|
|
|
// frame is painted in the right place.
|
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
gfxPoint toUserSpaceGfx = nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(aFrame);
|
|
|
|
nsPoint toUserSpace =
|
2016-08-15 19:33:35 +03:00
|
|
|
nsPoint(nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.x)),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(float(toUserSpaceGfx.y)));
|
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
aOffsetToUserSpace = aOffsetToBoundingBox - toUserSpace;
|
2016-08-15 19:33:35 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2016-09-21 11:49:27 +03:00
|
|
|
bool hasSVGLayout = (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
2016-08-15 19:33:35 +03:00
|
|
|
NS_ASSERTION(hasSVGLayout || aOffsetToBoundingBox == aOffsetToUserSpace,
|
|
|
|
"For non-SVG frames there shouldn't be any additional offset");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gfxPoint devPixelOffsetToUserSpace =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(aOffsetToUserSpace,
|
2016-09-21 11:49:27 +03:00
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
gfxContext& context = aParams.ctx;
|
|
|
|
context.SetMatrix(context.CurrentMatrix().Translate(devPixelOffsetToUserSpace));
|
2016-08-15 19:33:35 +03:00
|
|
|
}
|
|
|
|
|
2016-10-30 16:41:06 +03:00
|
|
|
bool
|
|
|
|
nsSVGIntegrationUtils::IsMaskResourceReady(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(aFrame);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
nsTArray<nsSVGMaskFrame*> maskFrames = effectProperties.GetMaskFrames();
|
|
|
|
const nsStyleSVGReset* svgReset = firstFrame->StyleSVGReset();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < maskFrames.Length(); i++) {
|
|
|
|
// Refers to a valid SVG mask.
|
|
|
|
if (maskFrames[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refers to an external resource, which is not ready yet.
|
|
|
|
if (!svgReset->mMask.mLayers[i].mImage.IsComplete()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Either all mask resources are ready, or no mask resource is needed.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-03 12:12:32 +03:00
|
|
|
class AutoPopGroup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoPopGroup() : mContext(nullptr) { }
|
|
|
|
|
|
|
|
~AutoPopGroup() {
|
|
|
|
if (mContext) {
|
|
|
|
mContext->PopGroupAndBlend();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetContext(gfxContext* aContext) {
|
|
|
|
mContext = aContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfxContext* mContext;
|
|
|
|
};
|
|
|
|
|
2016-10-19 12:31:36 +03:00
|
|
|
DrawResult
|
|
|
|
nsSVGIntegrationUtils::PaintMask(const PaintFramesParams& aParams)
|
|
|
|
{
|
2016-11-03 06:16:46 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(aParams.frame, aParams.handleOpacity,
|
|
|
|
maskUsage);
|
2016-10-19 12:31:36 +03:00
|
|
|
|
|
|
|
nsIFrame* frame = aParams.frame;
|
|
|
|
if (!ValidateSVGFrame(frame)) {
|
2016-11-02 10:10:46 +03:00
|
|
|
return DrawResult::SUCCESS;
|
2016-10-19 12:31:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxContext& ctx = aParams.ctx;
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2016-11-04 09:48:11 +03:00
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
2016-12-29 21:07:04 +03:00
|
|
|
RefPtr<DrawTarget> maskTarget = ctx.GetDrawTarget();
|
2016-12-15 09:17:50 +03:00
|
|
|
|
|
|
|
if (maskUsage.shouldGenerateMaskLayer &&
|
|
|
|
maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
// We will paint both mask of positioned mask and clip-path into
|
|
|
|
// maskTarget.
|
|
|
|
//
|
|
|
|
// Create one extra draw target for drawing positioned mask, so that we do
|
|
|
|
// not have to copy the content of maskTarget before painting
|
|
|
|
// clip-path into it.
|
|
|
|
maskTarget = maskTarget->CreateSimilarDrawTarget(maskTarget->GetSize(),
|
|
|
|
SurfaceFormat::A8);
|
|
|
|
}
|
2016-11-04 09:48:11 +03:00
|
|
|
|
2017-01-03 12:12:32 +03:00
|
|
|
nsTArray<nsSVGMaskFrame *> maskFrames = effectProperties.GetMaskFrames();
|
|
|
|
AutoPopGroup autoPop;
|
|
|
|
bool shouldPushOpacity = (maskUsage.opacity != 1.0) &&
|
|
|
|
(maskFrames.Length() != 1);
|
|
|
|
if (shouldPushOpacity) {
|
|
|
|
ctx.PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, maskUsage.opacity);
|
|
|
|
autoPop.SetContext(&ctx);
|
|
|
|
}
|
|
|
|
|
2016-12-29 21:07:04 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore matSR;
|
|
|
|
nsPoint offsetToBoundingBox;
|
|
|
|
nsPoint offsetToUserSpace;
|
|
|
|
|
|
|
|
// Paint clip-path-basic-shape onto ctx
|
|
|
|
gfxContextAutoSaveRestore basicShapeSR;
|
2016-12-16 05:56:07 +03:00
|
|
|
if (maskUsage.shouldApplyBasicShape) {
|
|
|
|
matSR.SetContext(&ctx);
|
|
|
|
|
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
|
|
|
offsetToUserSpace);
|
|
|
|
|
2016-12-29 21:07:04 +03:00
|
|
|
basicShapeSR.SetContext(&ctx);
|
2016-12-16 05:56:07 +03:00
|
|
|
nsCSSClipPathInstance::ApplyBasicShapeClip(ctx, frame);
|
|
|
|
if (!maskUsage.shouldGenerateMaskLayer) {
|
|
|
|
// Only have basic-shape clip-path effect. Fill clipped region by
|
|
|
|
// opaque white.
|
2016-12-29 21:07:04 +03:00
|
|
|
ctx.SetColor(Color(1.0, 1.0, 1.0, 1.0));
|
2016-12-16 05:56:07 +03:00
|
|
|
ctx.Fill();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-04 09:48:11 +03:00
|
|
|
// Paint mask onto ctx.
|
|
|
|
if (maskUsage.shouldGenerateMaskLayer) {
|
2016-12-16 05:56:07 +03:00
|
|
|
matSR.Restore();
|
2016-11-04 09:48:11 +03:00
|
|
|
matSR.SetContext(&ctx);
|
|
|
|
|
|
|
|
SetupContextMatrix(frame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2017-01-03 12:12:32 +03:00
|
|
|
result = PaintMaskSurface(aParams, maskTarget,
|
|
|
|
shouldPushOpacity ? 1.0 : maskUsage.opacity,
|
2016-11-04 09:48:11 +03:00
|
|
|
firstFrame->StyleContext(), maskFrames,
|
|
|
|
ctx.CurrentMatrix(), offsetToUserSpace);
|
|
|
|
if (result != DrawResult::SUCCESS) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paint clip-path onto ctx.
|
2016-11-04 10:33:38 +03:00
|
|
|
if (maskUsage.shouldGenerateClipMaskLayer || maskUsage.shouldApplyClipPath) {
|
2016-11-04 09:48:11 +03:00
|
|
|
matSR.Restore();
|
|
|
|
matSR.SetContext(&ctx);
|
|
|
|
|
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-11-04 09:48:11 +03:00
|
|
|
Matrix clipMaskTransform;
|
|
|
|
gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(frame);
|
|
|
|
|
2016-12-07 10:28:47 +03:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame();
|
2016-11-16 14:04:59 +03:00
|
|
|
RefPtr<SourceSurface> maskSurface =
|
2016-12-15 09:17:50 +03:00
|
|
|
maskUsage.shouldGenerateMaskLayer ? maskTarget->Snapshot() : nullptr;
|
2016-11-16 14:04:59 +03:00
|
|
|
result =
|
|
|
|
clipPathFrame->PaintClipMask(ctx, frame, cssPxToDevPxMatrix,
|
|
|
|
&clipMaskTransform, maskSurface,
|
|
|
|
ToMatrix(ctx.CurrentMatrix()));
|
2016-11-04 09:48:11 +03:00
|
|
|
}
|
2016-10-19 12:31:36 +03:00
|
|
|
|
2016-11-04 09:48:11 +03:00
|
|
|
return result;
|
2016-10-19 12:31:36 +03:00
|
|
|
}
|
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
DrawResult
|
|
|
|
nsSVGIntegrationUtils::PaintMaskAndClipPath(const PaintFramesParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(UsingMaskOrClipPathForFrame(aParams.frame),
|
|
|
|
"Should not use this method when no mask or clipPath effect"
|
|
|
|
"on this frame");
|
|
|
|
|
|
|
|
/* SVG defines the following rendering model:
|
|
|
|
*
|
|
|
|
* 1. Render geometry
|
|
|
|
* 2. Apply filter
|
|
|
|
* 3. Apply clipping, masking, group opacity
|
|
|
|
*
|
|
|
|
* We handle #3 here and perform a couple of optimizations:
|
|
|
|
*
|
|
|
|
* + Use cairo's clipPath when representable natively (single object
|
|
|
|
* clip region).
|
|
|
|
*
|
|
|
|
* + Merge opacity and masking if both used together.
|
|
|
|
*/
|
|
|
|
nsIFrame* frame = aParams.frame;
|
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
if (!ValidateSVGFrame(frame)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-03 06:16:46 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(aParams.frame, aParams.handleOpacity,
|
|
|
|
maskUsage);
|
2016-10-19 08:38:35 +03:00
|
|
|
|
|
|
|
if (maskUsage.opacity == 0.0f) {
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxContext& context = aParams.ctx;
|
|
|
|
gfxContextMatrixAutoSaveRestore matrixAutoSaveRestore(&context);
|
|
|
|
|
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2016-12-07 10:28:47 +03:00
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame();
|
2016-10-19 08:38:35 +03:00
|
|
|
|
|
|
|
gfxMatrix cssPxToDevPxMatrix = GetCSSPxToDevPxMatrix(frame);
|
|
|
|
nsTArray<nsSVGMaskFrame*> maskFrames = effectProperties.GetMaskFrames();
|
2016-08-15 18:04:50 +03:00
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
nsPoint offsetToBoundingBox;
|
|
|
|
nsPoint offsetToUserSpace;
|
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
bool shouldGenerateMask = (maskUsage.opacity != 1.0f ||
|
|
|
|
maskUsage.shouldGenerateClipMaskLayer ||
|
|
|
|
maskUsage.shouldGenerateMaskLayer);
|
2016-11-23 08:51:36 +03:00
|
|
|
bool shouldPushMask = false;
|
2016-08-15 18:04:50 +03:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
/* Check if we need to do additional operations on this child's
|
|
|
|
* rendering, which necessitates rendering into another surface. */
|
2016-08-15 18:04:50 +03:00
|
|
|
if (shouldGenerateMask) {
|
2016-09-22 08:38:55 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore matSR;
|
|
|
|
|
2016-01-28 08:29:00 +03:00
|
|
|
Matrix maskTransform;
|
|
|
|
RefPtr<SourceSurface> maskSurface;
|
2016-09-27 21:46:47 +03:00
|
|
|
bool opacityApplied = false;
|
2016-09-22 08:38:55 +03:00
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
if (maskUsage.shouldGenerateMaskLayer) {
|
2016-09-22 08:38:55 +03:00
|
|
|
matSR.SetContext(&context);
|
|
|
|
|
|
|
|
// For css-mask, we want to generate a mask for each continuation frame,
|
|
|
|
// so we setup context matrix by the position of the current frame,
|
|
|
|
// instead of the first continuation frame.
|
|
|
|
SetupContextMatrix(frame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-11-23 08:51:36 +03:00
|
|
|
MaskPaintResult paintResult =
|
|
|
|
CreateAndPaintMaskSurface(aParams, maskUsage.opacity,
|
|
|
|
firstFrame->StyleContext(),
|
|
|
|
maskFrames, offsetToUserSpace);
|
|
|
|
|
|
|
|
if (paintResult.transparentBlackMask) {
|
|
|
|
return paintResult.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result &= paintResult.result;
|
|
|
|
maskSurface = paintResult.maskSurface;
|
|
|
|
if (maskSurface) {
|
|
|
|
MOZ_ASSERT(paintResult.result == DrawResult::SUCCESS);
|
|
|
|
shouldPushMask = true;
|
|
|
|
maskTransform = paintResult.maskTransform;
|
|
|
|
opacityApplied = paintResult.opacityApplied;
|
2016-09-22 08:38:55 +03:00
|
|
|
}
|
2016-01-28 08:29:00 +03:00
|
|
|
}
|
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
if (maskUsage.shouldGenerateClipMaskLayer) {
|
2016-09-22 08:38:55 +03:00
|
|
|
matSR.Restore();
|
|
|
|
matSR.SetContext(&context);
|
|
|
|
|
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-11-04 09:48:11 +03:00
|
|
|
Matrix clipMaskTransform;
|
2016-11-23 19:08:13 +03:00
|
|
|
DrawResult clipMaskResult;
|
|
|
|
RefPtr<SourceSurface> clipMaskSurface;
|
|
|
|
Tie(clipMaskResult, clipMaskSurface) =
|
2016-07-14 07:47:06 +03:00
|
|
|
clipPathFrame->GetClipMask(context, frame, cssPxToDevPxMatrix,
|
2016-11-04 09:48:11 +03:00
|
|
|
&clipMaskTransform, maskSurface,
|
2016-11-23 19:08:13 +03:00
|
|
|
maskTransform);
|
2015-11-11 18:15:39 +03:00
|
|
|
|
|
|
|
if (clipMaskSurface) {
|
|
|
|
maskSurface = clipMaskSurface;
|
2016-11-04 09:48:11 +03:00
|
|
|
maskTransform = clipMaskTransform;
|
2016-09-22 11:29:03 +03:00
|
|
|
} else {
|
|
|
|
// Either entire surface is clipped out, or gfx buffer allocation
|
|
|
|
// failure in nsSVGClipPathFrame::GetClipMask.
|
2016-11-23 19:08:13 +03:00
|
|
|
return clipMaskResult;
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
2016-11-23 19:08:13 +03:00
|
|
|
result &= clipMaskResult;
|
2016-11-23 08:51:36 +03:00
|
|
|
shouldPushMask = true;
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
2016-09-22 08:38:55 +03:00
|
|
|
|
|
|
|
// opacity != 1.0f.
|
2016-10-19 08:38:35 +03:00
|
|
|
if (!maskUsage.shouldGenerateClipMaskLayer &&
|
|
|
|
!maskUsage.shouldGenerateMaskLayer) {
|
|
|
|
MOZ_ASSERT(maskUsage.opacity != 1.0f);
|
2016-09-22 08:38:55 +03:00
|
|
|
|
|
|
|
matSR.SetContext(&context);
|
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-11-23 08:51:36 +03:00
|
|
|
shouldPushMask = true;
|
2016-09-22 08:38:55 +03:00
|
|
|
}
|
2015-11-11 18:15:39 +03:00
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
if (shouldPushMask) {
|
|
|
|
if (aParams.layerManager->GetRoot()->GetContentFlags() &
|
|
|
|
Layer::CONTENT_COMPONENT_ALPHA) {
|
|
|
|
context.PushGroupAndCopyBackground(gfxContentType::COLOR_ALPHA,
|
|
|
|
opacityApplied
|
|
|
|
? 1.0
|
|
|
|
: maskUsage.opacity,
|
|
|
|
maskSurface, maskTransform);
|
|
|
|
} else {
|
|
|
|
context.PushGroupForBlendBack(gfxContentType::COLOR_ALPHA,
|
|
|
|
opacityApplied ? 1.0 : maskUsage.opacity,
|
|
|
|
maskSurface, maskTransform);
|
|
|
|
}
|
2016-10-01 04:22:30 +03:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If this frame has only a trivial clipPath, set up cairo's clipping now so
|
|
|
|
* we can just do normal painting and get it clipped appropriately.
|
|
|
|
*/
|
2016-10-19 08:38:35 +03:00
|
|
|
if (maskUsage.shouldApplyClipPath || maskUsage.shouldApplyBasicShape) {
|
2016-10-28 13:32:01 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore matSR(&context);
|
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-09-21 11:49:27 +03:00
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
MOZ_ASSERT(!maskUsage.shouldApplyClipPath ||
|
|
|
|
!maskUsage.shouldApplyBasicShape);
|
|
|
|
if (maskUsage.shouldApplyClipPath) {
|
2016-09-21 11:49:27 +03:00
|
|
|
clipPathFrame->ApplyClipPath(context, frame, cssPxToDevPxMatrix);
|
|
|
|
} else {
|
|
|
|
nsCSSClipPathInstance::ApplyBasicShapeClip(context, frame);
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the child */
|
2016-09-29 06:07:51 +03:00
|
|
|
context.SetMatrix(matrixAutoSaveRestore.Matrix());
|
2016-11-07 19:38:45 +03:00
|
|
|
BasicLayerManager* basic = aParams.layerManager->AsBasicLayerManager();
|
2016-08-15 20:07:57 +03:00
|
|
|
RefPtr<gfxContext> oldCtx = basic->GetTarget();
|
2016-09-29 06:07:51 +03:00
|
|
|
basic->SetTarget(&context);
|
2016-08-15 20:07:57 +03:00
|
|
|
aParams.layerManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer,
|
2016-09-18 18:16:35 +03:00
|
|
|
aParams.builder);
|
2016-08-15 20:07:57 +03:00
|
|
|
basic->SetTarget(oldCtx);
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2016-11-04 07:25:33 +03:00
|
|
|
if (gfxPrefs::DrawMaskLayer()) {
|
|
|
|
gfxContextAutoSaveRestore saver(&context);
|
|
|
|
|
|
|
|
context.NewPath();
|
|
|
|
gfxRect drawingRect =
|
|
|
|
nsLayoutUtils::RectToGfxRect(aParams.borderArea,
|
|
|
|
frame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
context.Rectangle(drawingRect, true);
|
2016-12-29 22:35:36 +03:00
|
|
|
Color overlayColor(0.0f, 0.0f, 0.0f, 0.8f);
|
|
|
|
if (maskUsage.shouldGenerateMaskLayer) {
|
|
|
|
overlayColor.r = 1.0f; // red represents css positioned mask.
|
|
|
|
}
|
|
|
|
if (maskUsage.shouldApplyClipPath ||
|
|
|
|
maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
overlayColor.g = 1.0f; // green represents clip-path:<clip-source>.
|
|
|
|
}
|
|
|
|
if (maskUsage.shouldApplyBasicShape) {
|
|
|
|
overlayColor.b = 1.0f; // blue represents
|
|
|
|
// clip-path:<basic-shape>||<geometry-box>.
|
|
|
|
}
|
|
|
|
|
|
|
|
context.SetColor(overlayColor);
|
2016-11-04 07:25:33 +03:00
|
|
|
context.Fill();
|
|
|
|
}
|
|
|
|
|
2016-10-19 08:38:35 +03:00
|
|
|
if (maskUsage.shouldApplyClipPath || maskUsage.shouldApplyBasicShape) {
|
2016-10-28 13:32:01 +03:00
|
|
|
context.PopClip();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2016-11-23 08:51:36 +03:00
|
|
|
if (shouldPushMask) {
|
2016-09-29 06:07:51 +03:00
|
|
|
context.PopGroupAndBlend();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-11 20:22:54 +03:00
|
|
|
return result;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2016-08-15 19:59:35 +03:00
|
|
|
DrawResult
|
|
|
|
nsSVGIntegrationUtils::PaintFilter(const PaintFramesParams& aParams)
|
|
|
|
{
|
2016-09-05 07:46:56 +03:00
|
|
|
MOZ_ASSERT(!aParams.builder->IsForGenerateGlyphMask(),
|
|
|
|
"Filter effect is discarded while generating glyph mask.");
|
|
|
|
MOZ_ASSERT(aParams.frame->StyleEffects()->HasFilters(),
|
|
|
|
"Should not use this method when no filter effect on this frame");
|
2016-09-01 09:54:11 +03:00
|
|
|
|
2016-08-15 19:59:35 +03:00
|
|
|
nsIFrame* frame = aParams.frame;
|
2016-10-28 08:04:17 +03:00
|
|
|
if (!ValidateSVGFrame(frame)) {
|
|
|
|
return DrawResult::SUCCESS;
|
2016-08-15 19:59:35 +03:00
|
|
|
}
|
|
|
|
|
2016-11-03 06:16:46 +03:00
|
|
|
float opacity = nsSVGUtils::ComputeOpacity(frame, aParams.handleOpacity);
|
2016-08-15 19:59:35 +03:00
|
|
|
if (opacity == 0.0f) {
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Properties are added lazily and may have been removed by a restyle,
|
|
|
|
so make sure all applicable ones are set again. */
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(frame);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2016-12-13 14:40:27 +03:00
|
|
|
if (effectProperties.HasInvalidFilter()) {
|
2016-08-15 19:59:35 +03:00
|
|
|
return DrawResult::NOT_READY;
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:49:27 +03:00
|
|
|
gfxContext& context = aParams.ctx;
|
|
|
|
nsPoint offsetToBoundingBox;
|
|
|
|
nsPoint offsetToUserSpace;
|
|
|
|
|
2016-09-22 08:38:55 +03:00
|
|
|
gfxContextAutoSaveRestore autoSR(&context);
|
2016-09-21 11:49:27 +03:00
|
|
|
SetupContextMatrix(firstFrame, aParams, offsetToBoundingBox,
|
2016-12-21 11:21:23 +03:00
|
|
|
offsetToUserSpace);
|
2016-08-15 19:59:35 +03:00
|
|
|
|
2016-09-05 06:47:18 +03:00
|
|
|
if (opacity != 1.0f) {
|
2016-09-29 06:07:51 +03:00
|
|
|
context.PushGroupForBlendBack(gfxContentType::COLOR_ALPHA, opacity,
|
2016-09-05 06:47:18 +03:00
|
|
|
nullptr, Matrix());
|
|
|
|
}
|
|
|
|
|
2016-08-15 19:59:35 +03:00
|
|
|
/* Paint the child and apply filters */
|
2016-09-01 09:54:11 +03:00
|
|
|
RegularFramePaintCallback callback(aParams.builder, aParams.layerManager,
|
|
|
|
offsetToUserSpace);
|
|
|
|
nsRegion dirtyRegion = aParams.dirtyRect - offsetToBoundingBox;
|
|
|
|
gfxMatrix tm = nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(frame);
|
2016-09-29 06:07:51 +03:00
|
|
|
nsFilterInstance::PaintFilteredFrame(frame, context.GetDrawTarget(),
|
2016-09-01 09:54:11 +03:00
|
|
|
tm, &callback, &dirtyRegion);
|
2016-08-15 19:59:35 +03:00
|
|
|
|
2016-09-05 06:47:18 +03:00
|
|
|
if (opacity != 1.0f) {
|
2016-09-29 06:07:51 +03:00
|
|
|
context.PopGroupAndBlend();
|
2016-08-15 19:59:35 +03:00
|
|
|
}
|
|
|
|
|
2016-10-28 08:04:17 +03:00
|
|
|
return DrawResult::SUCCESS;
|
2016-08-15 19:59:35 +03:00
|
|
|
}
|
|
|
|
|
2009-07-23 12:35:59 +04:00
|
|
|
gfxMatrix
|
2012-06-21 04:29:50 +04:00
|
|
|
nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(nsIFrame* aNonSVGFrame)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = aNonSVGFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-09-11 04:24:16 +04:00
|
|
|
float devPxPerCSSPx =
|
|
|
|
1 / nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPixel);
|
2009-07-23 12:35:59 +04:00
|
|
|
|
|
|
|
return gfxMatrix(devPxPerCSSPx, 0.0,
|
|
|
|
0.0, devPxPerCSSPx,
|
|
|
|
0.0, 0.0);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
class PaintFrameCallback : public gfxDrawingCallback {
|
|
|
|
public:
|
|
|
|
PaintFrameCallback(nsIFrame* aFrame,
|
|
|
|
const nsSize aPaintServerSize,
|
2015-09-23 21:49:05 +03:00
|
|
|
const IntSize aRenderSize,
|
2013-08-02 00:42:34 +04:00
|
|
|
uint32_t aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
: mFrame(aFrame)
|
|
|
|
, mPaintServerSize(aPaintServerSize)
|
|
|
|
, mRenderSize(aRenderSize)
|
2013-08-02 00:42:34 +04:00
|
|
|
, mFlags (aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
{}
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxRect& aFillRect,
|
2016-05-25 19:01:18 +03:00
|
|
|
const SamplingFilter aSamplingFilter,
|
2015-10-06 03:18:10 +03:00
|
|
|
const gfxMatrix& aTransform) override;
|
2010-08-13 17:32:27 +04:00
|
|
|
private:
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nsSize mPaintServerSize;
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize mRenderSize;
|
2013-08-02 00:42:34 +04:00
|
|
|
uint32_t mFlags;
|
2010-08-13 17:32:27 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-13 17:32:27 +04:00
|
|
|
PaintFrameCallback::operator()(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
2016-05-25 19:01:18 +03:00
|
|
|
const SamplingFilter aSamplingFilter,
|
2010-08-13 17:32:27 +04:00
|
|
|
const gfxMatrix& aTransform)
|
|
|
|
{
|
|
|
|
if (mFrame->GetStateBits() & NS_FRAME_DRAWING_AS_PAINTSERVER)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
mFrame->AddStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
|
|
|
aContext->Save();
|
|
|
|
|
|
|
|
// Clip to aFillRect so that we don't paint outside.
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(aFillRect);
|
|
|
|
aContext->Clip();
|
|
|
|
|
2014-07-11 11:06:39 +04:00
|
|
|
gfxMatrix invmatrix = aTransform;
|
|
|
|
if (!invmatrix.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aContext->Multiply(invmatrix);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
// nsLayoutUtils::PaintFrame will anchor its painting at mFrame. But we want
|
|
|
|
// to have it anchored at the top left corner of the bounding box of all of
|
|
|
|
// mFrame's continuations. So we add a translation transform.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2016-10-11 08:12:00 +03:00
|
|
|
nsPoint offset = nsSVGIntegrationUtils::GetOffsetToBoundingBox(mFrame);
|
2012-06-19 19:28:04 +04:00
|
|
|
gfxPoint devPxOffset = gfxPoint(offset.x, offset.y) / appUnitsPerDevPixel;
|
2014-09-10 17:26:12 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Translation(devPxOffset));
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
gfxSize paintServerSize =
|
|
|
|
gfxSize(mPaintServerSize.width, mPaintServerSize.height) /
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
// nsLayoutUtils::PaintFrame wants to render with paintServerSize, but we
|
|
|
|
// want it to render with mRenderSize, so we need to set up a scale transform.
|
|
|
|
gfxFloat scaleX = mRenderSize.width / paintServerSize.width;
|
|
|
|
gfxFloat scaleY = mRenderSize.height / paintServerSize.height;
|
2014-09-10 17:26:12 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scaleX, scaleY));
|
2010-08-13 17:32:27 +04:00
|
|
|
|
|
|
|
// Draw.
|
2012-06-19 19:28:04 +04:00
|
|
|
nsRect dirty(-offset.x, -offset.y,
|
|
|
|
mPaintServerSize.width, mPaintServerSize.height);
|
2013-08-02 00:42:34 +04:00
|
|
|
|
2016-04-27 07:01:54 +03:00
|
|
|
using PaintFrameFlags = nsLayoutUtils::PaintFrameFlags;
|
|
|
|
PaintFrameFlags flags = PaintFrameFlags::PAINT_IN_TRANSFORM;
|
2013-08-02 00:42:34 +04:00
|
|
|
if (mFlags & nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES) {
|
2016-04-27 07:01:54 +03:00
|
|
|
flags |= PaintFrameFlags::PAINT_SYNC_DECODE_IMAGES;
|
2013-08-02 00:42:34 +04:00
|
|
|
}
|
2014-10-31 23:08:49 +03:00
|
|
|
nsRenderingContext context(aContext);
|
|
|
|
nsLayoutUtils::PaintFrame(&context, mFrame,
|
2010-08-13 17:32:27 +04:00
|
|
|
dirty, NS_RGBA(0, 0, 0, 0),
|
2016-04-25 19:26:40 +03:00
|
|
|
nsDisplayListBuilderMode::PAINTING,
|
2013-08-02 00:42:34 +04:00
|
|
|
flags);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
2015-09-25 01:26:34 +03:00
|
|
|
nsIFrame* currentFrame = mFrame;
|
|
|
|
while ((currentFrame = currentFrame->GetNextContinuation()) != nullptr) {
|
|
|
|
offset = currentFrame->GetOffsetToCrossDoc(mFrame);
|
|
|
|
devPxOffset = gfxPoint(offset.x, offset.y) / appUnitsPerDevPixel;
|
|
|
|
|
|
|
|
aContext->Save();
|
|
|
|
aContext->Multiply(gfxMatrix::Scaling(1/scaleX, 1/scaleY));
|
|
|
|
aContext->Multiply(gfxMatrix::Translation(devPxOffset));
|
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scaleX, scaleY));
|
|
|
|
|
|
|
|
nsLayoutUtils::PaintFrame(&context, currentFrame,
|
|
|
|
dirty - offset, NS_RGBA(0, 0, 0, 0),
|
2016-04-25 19:26:40 +03:00
|
|
|
nsDisplayListBuilderMode::PAINTING,
|
2015-09-25 01:26:34 +03:00
|
|
|
flags);
|
|
|
|
|
|
|
|
aContext->Restore();
|
|
|
|
}
|
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
aContext->Restore();
|
|
|
|
|
|
|
|
mFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-08-13 17:32:27 +04:00
|
|
|
}
|
|
|
|
|
2014-01-31 07:36:42 +04:00
|
|
|
/* static */ already_AddRefed<gfxDrawable>
|
|
|
|
nsSVGIntegrationUtils::DrawableFromPaintServer(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aTarget,
|
|
|
|
const nsSize& aPaintServerSize,
|
2015-09-23 21:49:05 +03:00
|
|
|
const IntSize& aRenderSize,
|
2014-09-29 17:15:19 +04:00
|
|
|
const DrawTarget* aDrawTarget,
|
2014-01-31 07:36:42 +04:00
|
|
|
const gfxMatrix& aContextMatrix,
|
|
|
|
uint32_t aFlags)
|
2010-08-13 17:32:27 +04:00
|
|
|
{
|
|
|
|
// aPaintServerSize is 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.
|
|
|
|
// aRenderSize is what we will be actually filling after accounting for
|
|
|
|
// background-size.
|
|
|
|
if (aFrame->IsFrameOfType(nsIFrame::eSVGPaintServer)) {
|
|
|
|
// aFrame is either a pattern or a gradient. These fill the whole target
|
|
|
|
// frame by default, so aPaintServerSize is the whole target background fill
|
|
|
|
// area.
|
|
|
|
nsSVGPaintServerFrame* server =
|
|
|
|
static_cast<nsSVGPaintServerFrame*>(aFrame);
|
|
|
|
|
|
|
|
gfxRect overrideBounds(0, 0,
|
|
|
|
aPaintServerSize.width, aPaintServerSize.height);
|
|
|
|
overrideBounds.ScaleInverse(aFrame->PresContext()->AppUnitsPerDevPixel());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxPattern> pattern =
|
2014-09-29 17:15:19 +04:00
|
|
|
server->GetPaintServerPattern(aTarget, aDrawTarget,
|
|
|
|
aContextMatrix, &nsStyleSVG::mFill, 1.0,
|
|
|
|
&overrideBounds);
|
2010-08-13 17:32:27 +04:00
|
|
|
|
2010-09-06 07:12:46 +04:00
|
|
|
if (!pattern)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-06 07:12:46 +04:00
|
|
|
|
2010-08-13 17:32:27 +04:00
|
|
|
// pattern is now set up to fill aPaintServerSize. But we want it to
|
|
|
|
// fill aRenderSize, so we need to add a scaling transform.
|
|
|
|
// We couldn't just have set overrideBounds to aRenderSize - it would have
|
|
|
|
// worked for gradients, but for patterns it would result in a different
|
|
|
|
// pattern size.
|
|
|
|
gfxFloat scaleX = overrideBounds.Width() / aRenderSize.width;
|
|
|
|
gfxFloat scaleY = overrideBounds.Height() / aRenderSize.height;
|
2014-07-11 11:07:07 +04:00
|
|
|
gfxMatrix scaleMatrix = gfxMatrix::Scaling(scaleX, scaleY);
|
|
|
|
pattern->SetMatrix(scaleMatrix * pattern->GetMatrix());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawable> drawable =
|
2010-08-13 17:32:27 +04:00
|
|
|
new gfxPatternDrawable(pattern, aRenderSize);
|
|
|
|
return drawable.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to paint into a surface as long as we don't need to, so we
|
|
|
|
// set up a drawing callback.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawingCallback> cb =
|
2013-08-02 00:42:34 +04:00
|
|
|
new PaintFrameCallback(aFrame, aPaintServerSize, aRenderSize, aFlags);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawable> drawable = new gfxCallbackDrawable(cb, aRenderSize);
|
2010-08-13 17:32:27 +04:00
|
|
|
return drawable.forget();
|
|
|
|
}
|