Bug 539356 - Part 4 - Reinstate the foreignObject registering code so that bug 605265 doesn't slow down SVG in general. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2012-07-17 13:03:51 -04:00
parent 752c70ddaa
commit 4316271e58
4 changed files with 70 additions and 0 deletions

View File

@ -67,9 +67,22 @@ nsSVGForeignObjectFrame::Init(nsIContent* aContent,
(NS_STATE_SVG_NONDISPLAY_CHILD | NS_STATE_SVG_CLIPPATH_CHILD));
AddStateBits(NS_FRAME_FONT_INFLATION_CONTAINER |
NS_FRAME_FONT_INFLATION_FLOW_ROOT);
if (NS_SUCCEEDED(rv) &&
!(mState & NS_STATE_SVG_NONDISPLAY_CHILD)) {
nsSVGUtils::GetOuterSVGFrame(this)->RegisterForeignObject(this);
}
return rv;
}
void nsSVGForeignObjectFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
// Only unregister if we registered in the first place:
if (!(mState & NS_STATE_SVG_NONDISPLAY_CHILD)) {
nsSVGUtils::GetOuterSVGFrame(this)->UnregisterForeignObject(this);
}
nsSVGForeignObjectFrameBase::DestroyFrom(aDestructRoot);
}
nsIAtom *
nsSVGForeignObjectFrame::GetType() const
{

View File

@ -33,6 +33,7 @@ public:
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void DestroyFrom(nsIFrame* aDestructRoot);
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType);

View File

@ -18,6 +18,7 @@
#include "nsRenderingContext.h"
#include "nsStubMutationObserver.h"
#include "nsSVGIntegrationUtils.h"
#include "nsSVGForeignObjectFrame.h"
#include "nsSVGSVGElement.h"
#include "nsSVGTextFrame.h"
@ -79,6 +80,33 @@ nsSVGMutationObserver::AttributeChanged(nsIDocument* aDocument,
//----------------------------------------------------------------------
// Implementation helpers
void
nsSVGOuterSVGFrame::RegisterForeignObject(nsSVGForeignObjectFrame* aFrame)
{
NS_ASSERTION(aFrame, "Who on earth is calling us?!");
if (!mForeignObjectHash.IsInitialized()) {
mForeignObjectHash.Init();
}
NS_ASSERTION(!mForeignObjectHash.GetEntry(aFrame),
"nsSVGForeignObjectFrame already registered!");
mForeignObjectHash.PutEntry(aFrame);
NS_ASSERTION(mForeignObjectHash.GetEntry(aFrame),
"Failed to register nsSVGForeignObjectFrame!");
}
void
nsSVGOuterSVGFrame::UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame)
{
NS_ASSERTION(aFrame, "Who on earth is calling us?!");
NS_ASSERTION(mForeignObjectHash.GetEntry(aFrame),
"nsSVGForeignObjectFrame not in registry!");
return mForeignObjectHash.RemoveEntry(aFrame);
}
void
nsSVGMutationObserver::UpdateTextFragmentTrees(nsIFrame *aFrame)
{

View File

@ -10,6 +10,8 @@
#include "nsISVGSVGFrame.h"
#include "nsSVGContainerFrame.h"
class nsSVGForeignObjectFrame;
////////////////////////////////////////////////////////////////////////
// nsSVGOuterSVGFrame class
@ -27,6 +29,13 @@ public:
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
#ifdef DEBUG
~nsSVGOuterSVGFrame() {
NS_ASSERTION(mForeignObjectHash.Count() == 0,
"foreignObject(s) still registered!");
}
#endif
// nsIFrame:
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
@ -105,6 +114,18 @@ public:
// nsSVGContainerFrame methods:
virtual gfxMatrix GetCanvasTM(PRUint32 aFor);
/* Methods to allow descendant nsSVGForeignObjectFrame frames to register and
* unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This
* is temporary until display list based invalidation is impleented for SVG.
* Maintaining a list of our foreignObject descendants allows us to search
* them for areas that need to be invalidated, without having to also search
* the SVG frame tree for foreignObjects. This is important so that bug 539356
* does not slow down SVG in general (only foreignObjects, until bug 614732 is
* fixed).
*/
void RegisterForeignObject(nsSVGForeignObjectFrame* aFrame);
void UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame);
virtual bool HasChildrenOnlyTransform(gfxMatrix *aTransform) const {
// Our anonymous wrapper child must claim our children-only transforms as
// its own so that our real children (the frames it wraps) are transformed
@ -138,6 +159,13 @@ protected:
*/
bool IsRootOfImage();
// This is temporary until display list based invalidation is implemented for
// SVG.
// A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use
// a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame
// subtree if we were to use a list (see bug 381285 comment 20).
nsTHashtable<nsVoidPtrHashKey> mForeignObjectHash;
nsAutoPtr<gfxMatrix> mCanvasTM;
float mFullZoom;