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: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-03-04 13:55:59 +04:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#include "DisplayItemClip.h"
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2014-11-24 03:04:33 +03:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-11-01 13:45:10 +03:00
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2017-08-10 21:00:08 +03:00
|
|
|
#include "mozilla/layers/StackingContextHelper.h"
|
|
|
|
#include "mozilla/webrender/WebRenderTypes.h"
|
2013-03-04 13:55:59 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2013-08-24 02:16:38 +04:00
|
|
|
#include "nsRegion.h"
|
2013-03-04 13:55:59 +04:00
|
|
|
|
2014-11-01 13:45:10 +03:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-03-04 13:55:59 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2013-03-06 15:08:11 +04:00
|
|
|
void
|
|
|
|
DisplayItemClip::SetTo(const nsRect& aRect)
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
2015-02-20 21:55:28 +03:00
|
|
|
SetTo(aRect, nullptr);
|
2013-03-06 15:08:11 +04:00
|
|
|
}
|
2013-03-04 13:55:59 +04:00
|
|
|
|
2013-03-06 15:08:11 +04:00
|
|
|
void
|
|
|
|
DisplayItemClip::SetTo(const nsRect& aRect, const nscoord* aRadii)
|
|
|
|
{
|
|
|
|
mHaveClipRect = true;
|
|
|
|
mClipRect = aRect;
|
2015-02-20 21:55:28 +03:00
|
|
|
if (aRadii) {
|
|
|
|
mRoundedClipRects.SetLength(1);
|
|
|
|
mRoundedClipRects[0].mRect = aRect;
|
|
|
|
memcpy(mRoundedClipRects[0].mRadii, aRadii, sizeof(nscoord)*8);
|
|
|
|
} else {
|
|
|
|
mRoundedClipRects.Clear();
|
|
|
|
}
|
2013-03-06 15:08:11 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:21:06 +04:00
|
|
|
void
|
|
|
|
DisplayItemClip::SetTo(const nsRect& aRect,
|
|
|
|
const nsRect& aRoundedRect,
|
|
|
|
const nscoord* aRadii)
|
|
|
|
{
|
|
|
|
mHaveClipRect = true;
|
|
|
|
mClipRect = aRect;
|
|
|
|
mRoundedClipRects.SetLength(1);
|
|
|
|
mRoundedClipRects[0].mRect = aRoundedRect;
|
|
|
|
memcpy(mRoundedClipRects[0].mRadii, aRadii, sizeof(nscoord)*8);
|
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:11 +04:00
|
|
|
bool
|
|
|
|
DisplayItemClip::MayIntersect(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
if (!mHaveClipRect) {
|
|
|
|
return !aRect.IsEmpty();
|
|
|
|
}
|
|
|
|
nsRect r = aRect.Intersect(mClipRect);
|
|
|
|
if (r.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
|
|
|
|
const RoundedRect& rr = mRoundedClipRects[i];
|
|
|
|
if (!nsLayoutUtils::RoundedRectIntersectsRect(rr.mRect, rr.mRadii, r)) {
|
|
|
|
return false;
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-06 15:08:11 +04:00
|
|
|
return true;
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:00 +04:00
|
|
|
void
|
|
|
|
DisplayItemClip::IntersectWith(const DisplayItemClip& aOther)
|
|
|
|
{
|
|
|
|
if (!aOther.mHaveClipRect) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mHaveClipRect) {
|
|
|
|
*this = aOther;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!mClipRect.IntersectRect(mClipRect, aOther.mClipRect)) {
|
|
|
|
mRoundedClipRects.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRoundedClipRects.AppendElements(aOther.mRoundedClipRects);
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:55:59 +04:00
|
|
|
void
|
|
|
|
DisplayItemClip::ApplyTo(gfxContext* aContext,
|
2018-03-07 05:40:42 +03:00
|
|
|
int32_t A2D)
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
|
|
|
ApplyRectTo(aContext, A2D);
|
2018-03-07 05:40:42 +03:00
|
|
|
ApplyRoundedRectClipsTo(aContext, A2D, 0, mRoundedClipRects.Length());
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisplayItemClip::ApplyRectTo(gfxContext* aContext, int32_t A2D) const
|
|
|
|
{
|
|
|
|
aContext->NewPath();
|
|
|
|
gfxRect clip = nsLayoutUtils::RectToGfxRect(mClipRect, A2D);
|
|
|
|
aContext->Rectangle(clip, true);
|
|
|
|
aContext->Clip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-01 13:45:10 +03:00
|
|
|
DisplayItemClip::ApplyRoundedRectClipsTo(gfxContext* aContext,
|
|
|
|
int32_t A2D,
|
|
|
|
uint32_t aBegin, uint32_t aEnd) const
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
2014-11-01 13:45:10 +03:00
|
|
|
DrawTarget& aDrawTarget = *aContext->GetDrawTarget();
|
|
|
|
|
2013-03-04 13:55:59 +04:00
|
|
|
aEnd = std::min<uint32_t>(aEnd, mRoundedClipRects.Length());
|
|
|
|
|
|
|
|
for (uint32_t i = aBegin; i < aEnd; ++i) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> roundedRect =
|
2014-11-01 13:45:10 +03:00
|
|
|
MakeRoundedRectPath(aDrawTarget, A2D, mRoundedClipRects[i]);
|
|
|
|
aContext->Clip(roundedRect);
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-24 03:04:33 +03:00
|
|
|
DisplayItemClip::FillIntersectionOfRoundedRectClips(gfxContext* aContext,
|
|
|
|
const Color& aColor,
|
2018-03-07 05:40:42 +03:00
|
|
|
int32_t aAppUnitsPerDevPixel) const
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
2014-11-01 13:45:10 +03:00
|
|
|
DrawTarget& aDrawTarget = *aContext->GetDrawTarget();
|
|
|
|
|
2018-03-07 05:40:42 +03:00
|
|
|
uint32_t end = mRoundedClipRects.Length();
|
|
|
|
if (!end) {
|
2013-03-04 13:55:59 +04:00
|
|
|
return;
|
2014-11-24 03:04:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Push clips for any rects that come BEFORE the rect at |aEnd - 1|, if any:
|
2018-03-07 05:40:42 +03:00
|
|
|
ApplyRoundedRectClipsTo(aContext, aAppUnitsPerDevPixel, 0, end - 1);
|
2013-03-04 13:55:59 +04:00
|
|
|
|
2014-11-24 03:04:33 +03:00
|
|
|
// Now fill the rect at |aEnd - 1|:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> roundedRect = MakeRoundedRectPath(aDrawTarget,
|
2014-11-24 03:04:33 +03:00
|
|
|
aAppUnitsPerDevPixel,
|
2018-03-07 05:40:42 +03:00
|
|
|
mRoundedClipRects[end - 1]);
|
2014-11-24 03:04:33 +03:00
|
|
|
ColorPattern color(ToDeviceColor(aColor));
|
|
|
|
aDrawTarget.Fill(roundedRect, color);
|
|
|
|
|
|
|
|
// Finally, pop any clips that we may have pushed:
|
2018-03-07 05:40:42 +03:00
|
|
|
for (uint32_t i = 0; i < end - 1; ++i) {
|
2014-11-24 03:04:33 +03:00
|
|
|
aContext->PopClip();
|
|
|
|
}
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<Path>
|
2014-11-01 13:45:10 +03:00
|
|
|
DisplayItemClip::MakeRoundedRectPath(DrawTarget& aDrawTarget,
|
|
|
|
int32_t A2D,
|
|
|
|
const RoundedRect &aRoundRect) const
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
2014-11-01 13:45:10 +03:00
|
|
|
RectCornerRadii pixelRadii;
|
2013-03-04 13:55:59 +04:00
|
|
|
nsCSSRendering::ComputePixelRadii(aRoundRect.mRadii, A2D, &pixelRadii);
|
|
|
|
|
2014-11-01 13:45:10 +03:00
|
|
|
Rect rect = NSRectToSnappedRect(aRoundRect.mRect, A2D, aDrawTarget);
|
2013-03-04 13:55:59 +04:00
|
|
|
|
2014-11-01 13:45:10 +03:00
|
|
|
return MakePathForRoundedRect(aDrawTarget, rect, pixelRadii);
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2013-03-06 15:08:11 +04:00
|
|
|
DisplayItemClip::ApproximateIntersectInward(const nsRect& aRect) const
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
|
|
|
nsRect r = aRect;
|
|
|
|
if (mHaveClipRect) {
|
|
|
|
r.IntersectRect(r, mClipRect);
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(rr.mRect, rr.mRadii, r);
|
|
|
|
r = rgn.GetLargestRectangle();
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if (aXPoint, aYPoint) is in the ellipse with center (aXCenter, aYCenter)
|
|
|
|
// and radii aXRadius, aYRadius.
|
2018-02-23 08:03:45 +03:00
|
|
|
static bool
|
|
|
|
IsInsideEllipse(nscoord aXRadius, nscoord aXCenter, nscoord aXPoint,
|
|
|
|
nscoord aYRadius, nscoord aYCenter, nscoord aYPoint)
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
|
|
|
float scaledX = float(aXPoint - aXCenter) / float(aXRadius);
|
|
|
|
float scaledY = float(aYPoint - aYCenter) / float(aYRadius);
|
|
|
|
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
DisplayItemClip::IsRectClippedByRoundedCorner(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
if (mRoundedClipRects.IsEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
rect.IntersectRect(aRect, NonRoundedIntersection());
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
// top left
|
2017-01-05 06:31:38 +03:00
|
|
|
if (rect.x < rr.mRect.x + rr.mRadii[eCornerTopLeftX] &&
|
|
|
|
rect.y < rr.mRect.y + rr.mRadii[eCornerTopLeftY]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[eCornerTopLeftX],
|
|
|
|
rr.mRect.x + rr.mRadii[eCornerTopLeftX],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.x,
|
2017-01-05 06:31:38 +03:00
|
|
|
rr.mRadii[eCornerTopLeftY],
|
|
|
|
rr.mRect.y + rr.mRadii[eCornerTopLeftY],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// top right
|
2017-01-05 06:31:38 +03:00
|
|
|
if (rect.XMost() > rr.mRect.XMost() - rr.mRadii[eCornerTopRightX] &&
|
|
|
|
rect.y < rr.mRect.y + rr.mRadii[eCornerTopRightY]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[eCornerTopRightX],
|
|
|
|
rr.mRect.XMost() - rr.mRadii[eCornerTopRightX],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.XMost(),
|
2017-01-05 06:31:38 +03:00
|
|
|
rr.mRadii[eCornerTopRightY],
|
|
|
|
rr.mRect.y + rr.mRadii[eCornerTopRightY],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bottom left
|
2017-01-05 06:31:38 +03:00
|
|
|
if (rect.x < rr.mRect.x + rr.mRadii[eCornerBottomLeftX] &&
|
|
|
|
rect.YMost() > rr.mRect.YMost() - rr.mRadii[eCornerBottomLeftY]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[eCornerBottomLeftX],
|
|
|
|
rr.mRect.x + rr.mRadii[eCornerBottomLeftX],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.x,
|
2017-01-05 06:31:38 +03:00
|
|
|
rr.mRadii[eCornerBottomLeftY],
|
|
|
|
rr.mRect.YMost() - rr.mRadii[eCornerBottomLeftY],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.YMost())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bottom right
|
2017-01-05 06:31:38 +03:00
|
|
|
if (rect.XMost() > rr.mRect.XMost() - rr.mRadii[eCornerBottomRightX] &&
|
|
|
|
rect.YMost() > rr.mRect.YMost() - rr.mRadii[eCornerBottomRightY]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[eCornerBottomRightX],
|
|
|
|
rr.mRect.XMost() - rr.mRadii[eCornerBottomRightX],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.XMost(),
|
2017-01-05 06:31:38 +03:00
|
|
|
rr.mRadii[eCornerBottomRightY],
|
|
|
|
rr.mRect.YMost() - rr.mRadii[eCornerBottomRightY],
|
2013-03-04 13:55:59 +04:00
|
|
|
rect.YMost())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
DisplayItemClip::NonRoundedIntersection() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mHaveClipRect, "Must have a clip rect!");
|
|
|
|
nsRect result = mClipRect;
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
result.IntersectRect(result, mRoundedClipRects[i].mRect);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:00 +04:00
|
|
|
bool
|
|
|
|
DisplayItemClip::IsRectAffectedByClip(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
if (mHaveClipRect && !mClipRect.Contains(aRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(rr.mRect, rr.mRadii, aRect);
|
|
|
|
if (!rgn.Contains(aRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-23 10:12:08 +04:00
|
|
|
bool
|
|
|
|
DisplayItemClip::IsRectAffectedByClip(const nsIntRect& aRect,
|
|
|
|
float aXScale,
|
|
|
|
float aYScale,
|
|
|
|
int32_t A2D) const
|
|
|
|
{
|
|
|
|
if (mHaveClipRect) {
|
|
|
|
nsIntRect pixelClipRect = mClipRect.ScaleToNearestPixels(aXScale, aYScale, A2D);
|
|
|
|
if (!pixelClipRect.Contains(aRect)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rounded rect clipping only snaps to user-space pixels, not device space.
|
|
|
|
nsIntRect unscaled = aRect;
|
|
|
|
unscaled.Scale(1/aXScale, 1/aYScale);
|
|
|
|
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
|
|
|
|
nsIntRect pixelRect = rr.mRect.ToNearestPixels(A2D);
|
|
|
|
|
2014-11-01 13:45:10 +03:00
|
|
|
RectCornerRadii pixelRadii;
|
2014-07-23 10:12:08 +04:00
|
|
|
nsCSSRendering::ComputePixelRadii(rr.mRadii, A2D, &pixelRadii);
|
|
|
|
|
|
|
|
nsIntRegion rgn = nsLayoutUtils::RoundedRectIntersectIntRect(pixelRect, pixelRadii, unscaled);
|
|
|
|
if (!rgn.Contains(unscaled)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:55:59 +04:00
|
|
|
nsRect
|
|
|
|
DisplayItemClip::ApplyNonRoundedIntersection(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
if (!mHaveClipRect) {
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect result = aRect.Intersect(mClipRect);
|
|
|
|
for (uint32_t i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
2015-03-27 01:39:52 +03:00
|
|
|
result = result.Intersect(mRoundedClipRects[i].mRect);
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisplayItemClip::RemoveRoundedCorners()
|
|
|
|
{
|
|
|
|
if (mRoundedClipRects.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mClipRect = NonRoundedIntersection();
|
|
|
|
mRoundedClipRects.Clear();
|
|
|
|
}
|
|
|
|
|
2014-05-12 23:37:21 +04:00
|
|
|
// Computes the difference between aR1 and aR2, limited to aBounds.
|
2013-03-04 13:55:59 +04:00
|
|
|
static void
|
2014-05-12 23:37:21 +04:00
|
|
|
AccumulateRectDifference(const nsRect& aR1, const nsRect& aR2, const nsRect& aBounds, nsRegion* aOut)
|
2013-03-04 13:55:59 +04:00
|
|
|
{
|
|
|
|
if (aR1.IsEqualInterior(aR2))
|
|
|
|
return;
|
|
|
|
nsRegion r;
|
|
|
|
r.Xor(aR1, aR2);
|
2014-05-12 23:37:21 +04:00
|
|
|
r.And(r, aBounds);
|
2013-03-04 13:55:59 +04:00
|
|
|
aOut->Or(*aOut, r);
|
|
|
|
}
|
|
|
|
|
2018-07-13 19:11:28 +03:00
|
|
|
static void
|
|
|
|
AccumulateRoundedRectDifference(const DisplayItemClip::RoundedRect& aR1,
|
|
|
|
const DisplayItemClip::RoundedRect& aR2,
|
|
|
|
const nsRect& aBounds,
|
|
|
|
const nsRect& aOtherBounds,
|
|
|
|
nsRegion* aOut)
|
|
|
|
{
|
|
|
|
const nsRect& rect1 = aR1.mRect;
|
|
|
|
const nsRect& rect2 = aR2.mRect;
|
|
|
|
|
|
|
|
// If the two rectangles are totally disjoint, just add them both - otherwise we'd
|
|
|
|
// end up adding one big enclosing rect
|
|
|
|
if (!rect1.Intersects(rect2) || memcmp(aR1.mRadii, aR2.mRadii, sizeof(aR1.mRadii))) {
|
|
|
|
aOut->Or(*aOut, rect1.Intersect(aBounds));
|
|
|
|
aOut->Or(*aOut, rect2.Intersect(aOtherBounds));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord lowestBottom = std::max(rect1.YMost(), rect2.YMost());
|
|
|
|
nscoord highestTop = std::min(rect1.Y(), rect2.Y());
|
|
|
|
nscoord maxRight = std::max(rect1.XMost(), rect2.XMost());
|
|
|
|
nscoord minLeft = std::min(rect1.X(), rect2.X());
|
|
|
|
|
|
|
|
// At this point, we know that the radii haven't changed, and that the bounds
|
|
|
|
// are different in some way. To explain how this works, consider the case
|
|
|
|
// where the rounded rect has just been translated along the X direction.
|
|
|
|
// | ______________________ _ _ _ _ _ _ |
|
|
|
|
// | / / \ \ |
|
|
|
|
// | | | |
|
|
|
|
// | | aR1 | | aR2 | |
|
|
|
|
// | | | |
|
|
|
|
// | \ __________\___________ / _ _ _ _ _ / |
|
|
|
|
// | |
|
|
|
|
// The invalidation region will be as if we lopped off the left rounded part
|
|
|
|
// of aR2, and the right rounded part of aR1, and XOR'd them:
|
|
|
|
// | ______________________ _ _ _ _ _ _ |
|
|
|
|
// | -/-----------/- -\-----------\- |
|
|
|
|
// | |-------------- --|------------ |
|
|
|
|
// | |-----aR1---|-- --|-----aR2---| |
|
|
|
|
// | |-------------- --|------------ |
|
|
|
|
// | -\ __________\-__________-/ _ _ _ _ _ /- |
|
|
|
|
// | |
|
|
|
|
// The logic below just implements this idea, but generalized to both the
|
|
|
|
// X and Y dimensions. The "(...)Adjusted(...)" values represent the lopped
|
|
|
|
// off sides.
|
|
|
|
nscoord highestAdjustedBottom =
|
|
|
|
std::min(rect1.YMost() - aR1.mRadii[eCornerBottomLeftY],
|
|
|
|
std::min(rect1.YMost() - aR1.mRadii[eCornerBottomRightY],
|
|
|
|
std::min(rect2.YMost() - aR2.mRadii[eCornerBottomLeftY],
|
|
|
|
rect2.YMost() - aR2.mRadii[eCornerBottomRightY])));
|
|
|
|
nscoord lowestAdjustedTop =
|
|
|
|
std::max(rect1.Y() + aR1.mRadii[eCornerTopLeftY],
|
|
|
|
std::max(rect1.Y() + aR1.mRadii[eCornerTopRightY],
|
|
|
|
std::max(rect2.Y() + aR2.mRadii[eCornerTopLeftY],
|
|
|
|
rect2.Y() + aR2.mRadii[eCornerTopRightY])));
|
|
|
|
|
|
|
|
nscoord minAdjustedRight =
|
|
|
|
std::min(rect1.XMost() - aR1.mRadii[eCornerTopRightX],
|
|
|
|
std::min(rect1.XMost() - aR1.mRadii[eCornerBottomRightX],
|
|
|
|
std::min(rect2.XMost() - aR2.mRadii[eCornerTopRightX],
|
|
|
|
rect2.XMost() - aR2.mRadii[eCornerBottomRightX])));
|
|
|
|
nscoord maxAdjustedLeft =
|
|
|
|
std::max(rect1.X() + aR1.mRadii[eCornerTopLeftX],
|
|
|
|
std::max(rect1.X() + aR1.mRadii[eCornerBottomLeftX],
|
|
|
|
std::max(rect2.X() + aR2.mRadii[eCornerTopLeftX],
|
|
|
|
rect2.X() + aR2.mRadii[eCornerBottomLeftX])));
|
|
|
|
|
|
|
|
// We only want to add an invalidation rect if the bounds have changed. If we always
|
|
|
|
// added all of the 4 rects below, we would always be invalidating a border around the
|
|
|
|
// rects, even in cases where we just translated along the X or Y axis.
|
|
|
|
nsRegion r;
|
|
|
|
// First, or with the Y delta rects, wide along the X axis
|
|
|
|
if (rect1.Y() != rect2.Y()) {
|
|
|
|
r.Or(r, nsRect(minLeft, highestTop,
|
|
|
|
maxRight - minLeft, lowestAdjustedTop - highestTop));
|
|
|
|
}
|
|
|
|
if (rect1.YMost() != rect2.YMost()) {
|
|
|
|
r.Or(r, nsRect(minLeft, highestAdjustedBottom,
|
|
|
|
maxRight - minLeft, lowestBottom - highestAdjustedBottom));
|
|
|
|
}
|
|
|
|
// Then, or with the X delta rects, narrow along the Y axis
|
|
|
|
if (rect1.X() != rect2.X()) {
|
|
|
|
r.Or(r, nsRect(minLeft, lowestAdjustedTop,
|
|
|
|
maxAdjustedLeft - minLeft, highestAdjustedBottom - lowestAdjustedTop));
|
|
|
|
}
|
|
|
|
if (rect1.XMost() != rect2.XMost()) {
|
|
|
|
r.Or(r, nsRect(minAdjustedRight, lowestAdjustedTop,
|
|
|
|
maxRight - minAdjustedRight, highestAdjustedBottom - lowestAdjustedTop));
|
|
|
|
}
|
|
|
|
|
|
|
|
r.And(r, aBounds.Union(aOtherBounds));
|
|
|
|
aOut->Or(*aOut, r);
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:55:59 +04:00
|
|
|
void
|
2018-03-07 05:40:42 +03:00
|
|
|
DisplayItemClip::AddOffsetAndComputeDifference(const nsPoint& aOffset,
|
2013-03-04 13:55:59 +04:00
|
|
|
const nsRect& aBounds,
|
|
|
|
const DisplayItemClip& aOther,
|
|
|
|
const nsRect& aOtherBounds,
|
|
|
|
nsRegion* aDifference)
|
|
|
|
{
|
|
|
|
if (mHaveClipRect != aOther.mHaveClipRect ||
|
|
|
|
mRoundedClipRects.Length() != aOther.mRoundedClipRects.Length()) {
|
|
|
|
aDifference->Or(*aDifference, aBounds);
|
|
|
|
aDifference->Or(*aDifference, aOtherBounds);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mHaveClipRect) {
|
2014-05-12 23:37:21 +04:00
|
|
|
AccumulateRectDifference(mClipRect + aOffset, aOther.mClipRect,
|
|
|
|
aBounds.Union(aOtherBounds),
|
2013-03-04 13:55:59 +04:00
|
|
|
aDifference);
|
|
|
|
}
|
2018-03-07 05:40:42 +03:00
|
|
|
for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
|
2013-03-04 13:55:59 +04:00
|
|
|
if (mRoundedClipRects[i] + aOffset != aOther.mRoundedClipRects[i]) {
|
2018-07-13 19:11:28 +03:00
|
|
|
AccumulateRoundedRectDifference(mRoundedClipRects[i] + aOffset,
|
|
|
|
aOther.mRoundedClipRects[i],
|
|
|
|
aBounds,
|
|
|
|
aOtherBounds,
|
|
|
|
aDifference);
|
2013-03-04 13:55:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:00 +04:00
|
|
|
void
|
2018-03-07 05:40:42 +03:00
|
|
|
DisplayItemClip::AppendRoundedRects(nsTArray<RoundedRect>* aArray) const
|
2013-03-04 13:56:00 +04:00
|
|
|
{
|
2018-03-07 05:40:42 +03:00
|
|
|
aArray->AppendElements(mRoundedClipRects.Elements(), mRoundedClipRects.Length());
|
2013-03-04 13:56:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-02-19 02:37:01 +03:00
|
|
|
DisplayItemClip::ComputeRegionInClips(const DisplayItemClip* aOldClip,
|
2013-03-04 13:56:00 +04:00
|
|
|
const nsPoint& aShift,
|
|
|
|
nsRegion* aCombined) const
|
|
|
|
{
|
|
|
|
if (!mHaveClipRect || (aOldClip && !aOldClip->mHaveClipRect)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOldClip) {
|
|
|
|
*aCombined = aOldClip->NonRoundedIntersection();
|
|
|
|
aCombined->MoveBy(aShift);
|
|
|
|
aCombined->Or(*aCombined, NonRoundedIntersection());
|
|
|
|
} else {
|
|
|
|
*aCombined = NonRoundedIntersection();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-06 15:08:11 +04:00
|
|
|
void
|
2017-11-15 12:55:36 +03:00
|
|
|
DisplayItemClip::MoveBy(const nsPoint& aPoint)
|
2013-03-06 15:08:11 +04:00
|
|
|
{
|
|
|
|
if (!mHaveClipRect)
|
|
|
|
return;
|
|
|
|
mClipRect += aPoint;
|
|
|
|
for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
|
|
|
|
mRoundedClipRects[i].mRect += aPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static DisplayItemClip* gNoClip;
|
|
|
|
|
|
|
|
const DisplayItemClip&
|
|
|
|
DisplayItemClip::NoClip()
|
|
|
|
{
|
|
|
|
if (!gNoClip) {
|
|
|
|
gNoClip = new DisplayItemClip();
|
|
|
|
}
|
|
|
|
return *gNoClip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisplayItemClip::Shutdown()
|
|
|
|
{
|
|
|
|
delete gNoClip;
|
|
|
|
gNoClip = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString
|
|
|
|
DisplayItemClip::ToString() const
|
|
|
|
{
|
|
|
|
nsAutoCString str;
|
|
|
|
if (mHaveClipRect) {
|
|
|
|
str.AppendPrintf("%d,%d,%d,%d", mClipRect.x, mClipRect.y,
|
|
|
|
mClipRect.width, mClipRect.height);
|
|
|
|
for (uint32_t i = 0; i < mRoundedClipRects.Length(); ++i) {
|
|
|
|
const RoundedRect& r = mRoundedClipRects[i];
|
|
|
|
str.AppendPrintf(" [%d,%d,%d,%d corners %d,%d,%d,%d,%d,%d,%d,%d]",
|
|
|
|
r.mRect.x, r.mRect.y, r.mRect.width, r.mRect.height,
|
|
|
|
r.mRadii[0], r.mRadii[1], r.mRadii[2], r.mRadii[3],
|
|
|
|
r.mRadii[4], r.mRadii[5], r.mRadii[6], r.mRadii[7]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-08-10 21:00:08 +03:00
|
|
|
void
|
2017-10-04 00:51:49 +03:00
|
|
|
DisplayItemClip::ToComplexClipRegions(int32_t aAppUnitsPerDevPixel,
|
|
|
|
const layers::StackingContextHelper& aSc,
|
|
|
|
nsTArray<wr::ComplexClipRegion>& aOutArray) const
|
2017-08-10 21:00:08 +03:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mRoundedClipRects.Length(); i++) {
|
2017-10-04 00:51:49 +03:00
|
|
|
wr::ComplexClipRegion* region = aOutArray.AppendElement();
|
2018-03-30 00:57:43 +03:00
|
|
|
region->rect = wr::ToRoundedLayoutRect(LayoutDeviceRect::FromAppUnits(
|
2017-08-10 21:00:08 +03:00
|
|
|
mRoundedClipRects[i].mRect, aAppUnitsPerDevPixel));
|
|
|
|
const nscoord* radii = mRoundedClipRects[i].mRadii;
|
|
|
|
region->radii = wr::ToBorderRadius(
|
|
|
|
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerTopLeftX], radii[eCornerTopLeftY]), aAppUnitsPerDevPixel),
|
|
|
|
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerTopRightX], radii[eCornerTopRightY]), aAppUnitsPerDevPixel),
|
|
|
|
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerBottomLeftX], radii[eCornerBottomLeftY]), aAppUnitsPerDevPixel),
|
|
|
|
LayoutDeviceSize::FromAppUnits(nsSize(radii[eCornerBottomRightX], radii[eCornerBottomRightY]), aAppUnitsPerDevPixel));
|
2017-10-23 16:48:45 +03:00
|
|
|
region->mode = wr::ClipMode::Clip;
|
2017-08-10 21:00:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|