Bug 841192. Part 4: Create DisplayListClipState. r=mattwoodrow

--HG--
extra : rebase_source : 90eb025d01cec4d3e52473ebc27ae411f42c0439
This commit is contained in:
Robert O'Callahan 2013-03-04 22:56:00 +13:00
parent ddb47c1cef
commit 2a890de2cb
5 changed files with 135 additions and 2 deletions

View File

@ -41,6 +41,23 @@ DisplayItemClip::DisplayItemClip(const DisplayItemClip& aOther, nsDisplayItem* a
// FIXME: Optimize away excess rounded rectangles due to the new addition.
}
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);
}
void
DisplayItemClip::ApplyTo(gfxContext* aContext,
nsPresContext* aPresContext,

View File

@ -58,6 +58,8 @@ public:
// Construct as the intersection of aOther and aClipItem.
DisplayItemClip(const DisplayItemClip& aOther, nsDisplayItem* aClipItem);
void IntersectWith(const DisplayItemClip& aOther);
// Apply this |DisplayItemClip| to the given gfxContext. Any saving of state
// or clearing of other clips must be done by the caller.
// See aBegin/aEnd note on ApplyRoundedRectsTo.
@ -129,8 +131,8 @@ public:
return !(*this == aOther);
}
bool HasClip() { return mHaveClipRect; }
const nsRect& GetClipRect()
bool HasClip() const { return mHaveClipRect; }
const nsRect& GetClipRect() const
{
NS_ASSERTION(HasClip(), "No clip rect!");
return mClipRect;

View File

@ -0,0 +1,35 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* 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/. */
#include "DisplayListClipState.h"
#include "nsDisplayList.h"
namespace mozilla {
const DisplayItemClip*
DisplayListClipState::GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder)
{
if (mCurrentCombinedClip) {
return mCurrentCombinedClip;
}
if (!mClipContentDescendants && !mClipContainingBlockDescendants) {
return nullptr;
}
void* mem = aBuilder->Allocate(sizeof(DisplayItemClip));
if (mClipContentDescendants) {
mCurrentCombinedClip =
new (mem) DisplayItemClip(*mClipContentDescendants);
if (mClipContainingBlockDescendants) {
mCurrentCombinedClip->IntersectWith(*mClipContainingBlockDescendants);
}
} else {
mCurrentCombinedClip =
new (mem) DisplayItemClip(*mClipContainingBlockDescendants);
}
return mCurrentCombinedClip;
}
}

View File

@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DISPLAYLISTCLIPSTATE_H_
#define DISPLAYLISTCLIPSTATE_H_
#include "DisplayItemClip.h"
class nsIFrame;
class nsDisplayListBuilder;
namespace mozilla {
/**
* All clip coordinates are in appunits relative to the reference frame
* for the display item we're building.
*/
class DisplayListClipState {
public:
DisplayListClipState()
: mClipContentDescendants(nullptr)
, mClipContainingBlockDescendants(nullptr)
, mCurrentCombinedClip(nullptr)
{}
const DisplayItemClip* GetCurrentCombinedClip(nsDisplayListBuilder* aBuilder);
const DisplayItemClip* GetClipForContainingBlockDescendants()
{
return mClipContainingBlockDescendants;
}
const DisplayItemClip* GetClipForContentDescendants()
{
return mClipContentDescendants;
}
void SetClipForContainingBlockDescendants(const DisplayItemClip* aClip)
{
mClipContainingBlockDescendants = aClip;
mCurrentCombinedClip = nullptr;
}
void SetClipForContentDescendants(const DisplayItemClip* aClip)
{
mClipContentDescendants = aClip;
mCurrentCombinedClip = nullptr;
}
private:
/**
* All content descendants (i.e. following placeholder frames to their
* out-of-flows if necessary) should be clipped by mClipContentDescendants.
* Null if no clipping applies.
*/
const DisplayItemClip* mClipContentDescendants;
/**
* All containing-block descendants (i.e. frame descendants) should be
* clipped by mClipContainingBlockDescendants.
* Null if no clipping applies.
*/
const DisplayItemClip* mClipContainingBlockDescendants;
/**
* The intersection of mClipContentDescendants and
* mClipContainingBlockDescendants.
* Allocated in the nsDisplayListBuilder arena. Null if none has been
* allocated or both mClipContentDescendants and mClipContainingBlockDescendants
* are null.
*/
const DisplayItemClip* mCurrentCombinedClip;
};
}
#endif /* DISPLAYLISTCLIPSTATE_H_ */

View File

@ -21,6 +21,8 @@ endif # !_MSC_VER
EXPORTS_NAMESPACES = mozilla
EXPORTS = \
DisplayItemClip.h \
DisplayListClipState.h \
FrameLayerBuilder.h \
FramePropertyTable.h \
nsArenaMemoryStats.h \
@ -59,6 +61,7 @@ EXPORTS_mozilla = \
CPPSRCS = \
DisplayItemClip.cpp \
DisplayListClipState.cpp \
FrameLayerBuilder.cpp \
FramePropertyTable.cpp \
MaskLayerImageCache.cpp \