Skip to content

Commit

Permalink
Bug 1131840 - Replace the shouldForceDispatchToContent flag with a bi…
Browse files Browse the repository at this point in the history
…tset enum. r=roc,botond
  • Loading branch information
staktrace committed Feb 17, 2015
1 parent e3547aa commit 7fd26da
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 48 deletions.
7 changes: 7 additions & 0 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,13 @@ struct ParamTraits<APZStateChange>
APZStateChange::APZStateChangeSentinel>
{};

template<>
struct ParamTraits<mozilla::layers::EventRegionsOverride>
: public BitFlagsEnumSerializer<
mozilla::layers::EventRegionsOverride,
mozilla::layers::EventRegionsOverride::ALL_BITS>
{};

} /* namespace IPC */

#endif /* __GFXMESSAGEUTILS_H__ */
7 changes: 4 additions & 3 deletions gfx/layers/LayerMetricsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,14 @@ class MOZ_STACK_CLASS LayerMetricsWrapper {
return mLayer->GetClipRect();
}

bool GetForceDispatchToContentRegion() const {
EventRegionsOverride GetEventRegionsOverride() const
{
MOZ_ASSERT(IsValid());

if (mLayer->AsContainerLayer()) {
return mLayer->AsContainerLayer()->GetForceDispatchToContentRegion();
return mLayer->AsContainerLayer()->GetEventRegionsOverride();
}
return false;
return EventRegionsOverride::NoOverride;
}

// Expose an opaque pointer to the layer. Mostly used for printf
Expand Down
6 changes: 3 additions & 3 deletions gfx/layers/Layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ ContainerLayer::ContainerLayer(LayerManager* aManager, void* aImplData)
mSupportsComponentAlphaChildren(false),
mMayHaveReadbackChild(false),
mChildrenChanged(false),
mForceDispatchToContentRegion(false)
mEventRegionsOverride(EventRegionsOverride::NoOverride)
{
mContentFlags = 0; // Clear NO_TEXT, NO_TEXT_OVER_TRANSPARENT
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ ContainerLayer::FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
aAttrs = ContainerLayerAttributes(mPreXScale, mPreYScale,
mInheritedXScale, mInheritedYScale,
mPresShellResolution, mScaleToResolution,
mForceDispatchToContentRegion,
mEventRegionsOverride,
reinterpret_cast<uint64_t>(mHMDInfo.get()));
}

Expand Down Expand Up @@ -1750,7 +1750,7 @@ ContainerLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
if (mScaleToResolution) {
aStream << nsPrintfCString(" [presShellResolution=%g]", mPresShellResolution).get();
}
if (mForceDispatchToContentRegion) {
if (mEventRegionsOverride & EventRegionsOverride::ForceDispatchToContent) {
aStream << " [force-dtc]";
}
if (mHMDInfo) {
Expand Down
14 changes: 7 additions & 7 deletions gfx/layers/Layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1971,18 +1971,18 @@ class ContainerLayer : public Layer {
mChildrenChanged = aVal;
}

void SetForceDispatchToContentRegion(bool aVal) {
if (mForceDispatchToContentRegion == aVal) {
void SetEventRegionsOverride(EventRegionsOverride aVal) {
if (mEventRegionsOverride == aVal) {
return;
}

MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ForceDispatchToContentRegion", this));
mForceDispatchToContentRegion = aVal;
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) EventRegionsOverride", this));
mEventRegionsOverride = aVal;
Mutated();
}

bool GetForceDispatchToContentRegion() const {
return mForceDispatchToContentRegion;
EventRegionsOverride GetEventRegionsOverride() const {
return mEventRegionsOverride;
}

/**
Expand Down Expand Up @@ -2041,7 +2041,7 @@ class ContainerLayer : public Layer {
// This is updated by ComputeDifferences. This will be true if we need to invalidate
// the intermediate surface.
bool mChildrenChanged;
bool mForceDispatchToContentRegion;
EventRegionsOverride mEventRegionsOverride;
nsRefPtr<gfx::VRHMDInfo> mHMDInfo;
};

Expand Down
26 changes: 26 additions & 0 deletions gfx/layers/LayersTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,32 @@ struct EventRegions {
}
};

// Bit flags that go on a ContainerLayer (or RefLayer) and override the
// event regions in the entire subtree below. This is needed for propagating
// various flags across processes since the child-process layout code doesn't
// know about parent-process listeners or CSS rules.
enum EventRegionsOverride {
// The default, no flags set
NoOverride = 0,
// Treat all hit regions in the subtree as dispatch-to-content
ForceDispatchToContent = (1 << 0),
// OR union of all valid bit flags, for use in BitFlagsEnumSerializer
ALL_BITS = (1 << 1) - 1
};

MOZ_ALWAYS_INLINE EventRegionsOverride
operator|(EventRegionsOverride a, EventRegionsOverride b)
{
return (EventRegionsOverride)((int)a | (int)b);
}

MOZ_ALWAYS_INLINE EventRegionsOverride&
operator|=(EventRegionsOverride& a, EventRegionsOverride b)
{
a = a | b;
return a;
}

} // namespace
} // namespace

Expand Down
19 changes: 10 additions & 9 deletions gfx/layers/apz/src/APZCTreeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,19 @@ APZCTreeManager::RecycleOrCreateNode(TreeBuildingState& aState,
return node.forget();
}

static bool
ShouldForceDispatchToContent(HitTestingTreeNode* aParent,
const LayerMetricsWrapper& aLayer)
static EventRegionsOverride
GetEventRegionsOverride(HitTestingTreeNode* aParent,
const LayerMetricsWrapper& aLayer)
{
// Make it so that if the flag is set on the layer tree, it automatically
// propagates to all the nodes in the corresponding subtree rooted at that
// layer in the hit-test tree. This saves having to walk up the tree every
// we want to see if a hit-test node is affected by this flag.
if (aParent && aParent->GetForceDispatchToContent()) {
return true;
EventRegionsOverride result = aLayer.GetEventRegionsOverride();
if (aParent) {
result |= aParent->GetEventRegionsOverride();
}
return aLayer.GetForceDispatchToContentRegion();
return result;
}

HitTestingTreeNode*
Expand Down Expand Up @@ -359,7 +360,7 @@ APZCTreeManager::PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,
AttachNodeToTree(node, aParent, aNextSibling);
node->SetHitTestData(GetEventRegions(aLayer), aLayer.GetTransform(),
aLayer.GetClipRect() ? Some(nsIntRegion(*aLayer.GetClipRect())) : Nothing(),
ShouldForceDispatchToContent(aParent, aLayer));
GetEventRegionsOverride(aParent, aLayer));
return node;
}

Expand Down Expand Up @@ -456,7 +457,7 @@ APZCTreeManager::PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,

nsIntRegion clipRegion = ComputeClipRegion(state->mController, aLayer);
node->SetHitTestData(GetEventRegions(aLayer), aLayer.GetTransform(), Some(clipRegion),
ShouldForceDispatchToContent(aParent, aLayer));
GetEventRegionsOverride(aParent, aLayer));
apzc->SetAncestorTransform(aAncestorTransform);

PrintAPZCInfo(aLayer, apzc);
Expand Down Expand Up @@ -511,7 +512,7 @@ APZCTreeManager::PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,

nsIntRegion clipRegion = ComputeClipRegion(state->mController, aLayer);
node->SetHitTestData(GetEventRegions(aLayer), aLayer.GetTransform(), Some(clipRegion),
ShouldForceDispatchToContent(aParent, aLayer));
GetEventRegionsOverride(aParent, aLayer));
}

return node;
Expand Down
16 changes: 8 additions & 8 deletions gfx/layers/apz/src/HitTestingTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ HitTestingTreeNode::HitTestingTreeNode(AsyncPanZoomController* aApzc,
bool aIsPrimaryHolder)
: mApzc(aApzc)
, mIsPrimaryApzcHolder(aIsPrimaryHolder)
, mForceDispatchToContent(false)
, mOverride(EventRegionsOverride::NoOverride)
{
if (mIsPrimaryApzcHolder) {
MOZ_ASSERT(mApzc);
Expand Down Expand Up @@ -157,12 +157,12 @@ void
HitTestingTreeNode::SetHitTestData(const EventRegions& aRegions,
const gfx::Matrix4x4& aTransform,
const Maybe<nsIntRegion>& aClipRegion,
bool aForceDispatchToContent)
const EventRegionsOverride& aOverride)
{
mEventRegions = aRegions;
mTransform = aTransform;
mClipRegion = aClipRegion;
mForceDispatchToContent = aForceDispatchToContent;
mOverride = aOverride;
}

bool
Expand Down Expand Up @@ -213,18 +213,18 @@ HitTestingTreeNode::HitTest(const ParentLayerPoint& aPoint) const
if (!mEventRegions.mHitRegion.Contains(point.x, point.y)) {
return HitTestResult::HitNothing;
}
if (mForceDispatchToContent ||
if ((mOverride & EventRegionsOverride::ForceDispatchToContent) ||
mEventRegions.mDispatchToContentHitRegion.Contains(point.x, point.y))
{
return HitTestResult::HitDispatchToContentRegion;
}
return HitTestResult::HitLayer;
}

bool
HitTestingTreeNode::GetForceDispatchToContent() const
EventRegionsOverride
HitTestingTreeNode::GetEventRegionsOverride() const
{
return mForceDispatchToContent;
return mOverride;
}

void
Expand All @@ -235,7 +235,7 @@ HitTestingTreeNode::Dump(const char* aPrefix) const
}
printf_stderr("%sHitTestingTreeNode (%p) APZC (%p) g=(%s) %sr=(%s) t=(%s) c=(%s)\n",
aPrefix, this, mApzc.get(), mApzc ? Stringify(mApzc->GetGuid()).c_str() : "",
mForceDispatchToContent ? "fdtc " : "",
(mOverride & EventRegionsOverride::ForceDispatchToContent) ? "fdtc " : "",
Stringify(mEventRegions).c_str(), Stringify(mTransform).c_str(),
mClipRegion ? Stringify(mClipRegion.ref()).c_str() : "none");
if (mLastChild) {
Expand Down
13 changes: 6 additions & 7 deletions gfx/layers/apz/src/HitTestingTreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ class HitTestingTreeNode {
void SetHitTestData(const EventRegions& aRegions,
const gfx::Matrix4x4& aTransform,
const Maybe<nsIntRegion>& aClipRegion,
bool aForceDispatchToContent);
const EventRegionsOverride& aOverride);
bool IsOutsideClip(const ParentLayerPoint& aPoint) const;
/* Convert aPoint into the LayerPixel space for the layer corresponding to
* this node. */
Maybe<LayerPoint> Untransform(const ParentLayerPoint& aPoint) const;
/* Assuming aPoint is inside the clip region for this node, check which of the
* event region spaces it falls inside. */
HitTestResult HitTest(const ParentLayerPoint& aPoint) const;
/* Returns the mForceDispatchToContent flag. */
bool GetForceDispatchToContent() const;
/* Returns the mOverride flag. */
EventRegionsOverride GetEventRegionsOverride() const;

/* Debug helpers */
void Dump(const char* aPrefix = "") const;
Expand Down Expand Up @@ -126,10 +126,9 @@ class HitTestingTreeNode {
* present. This value is in L's ParentLayerPixels. */
Maybe<nsIntRegion> mClipRegion;

/* If this flag is set, then events to this node and the entire subtree under
* should always be treated as dispatch-to-content.
*/
bool mForceDispatchToContent;
/* Indicates whether or not the event regions on this node need to be
* overridden in a certain way. */
EventRegionsOverride mOverride;
};

}
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/ipc/LayerTransactionParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ LayerTransactionParent::RecvUpdate(InfallibleTArray<Edit>&& cset,
containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale());
containerLayer->SetScaleToResolution(attrs.scaleToResolution(),
attrs.presShellResolution());
containerLayer->SetForceDispatchToContentRegion(attrs.forceDispatchToContentRegion());
containerLayer->SetEventRegionsOverride(attrs.eventRegionsOverride());

if (attrs.hmdInfo()) {
if (!IsSameProcess()) {
Expand Down
3 changes: 2 additions & 1 deletion gfx/layers/ipc/LayersMessages.ipdlh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using mozilla::LayerPoint from "Units.h";
using mozilla::LayerRect from "Units.h";
using mozilla::layers::ScaleMode from "mozilla/layers/LayersTypes.h";
using mozilla::layers::EventRegions from "mozilla/layers/LayersTypes.h";
using mozilla::layers::EventRegionsOverride from "mozilla/layers/LayersTypes.h";
using mozilla::layers::DiagnosticTypes from "mozilla/layers/CompositorTypes.h";
using struct mozilla::layers::FrameMetrics from "FrameMetrics.h";
using mozilla::layers::FrameMetrics::ViewID from "FrameMetrics.h";
Expand Down Expand Up @@ -234,7 +235,7 @@ struct ContainerLayerAttributes {
float inheritedYScale;
float presShellResolution;
bool scaleToResolution;
bool forceDispatchToContentRegion;
EventRegionsOverride eventRegionsOverride;
// This is a bare pointer; LayerTransactionParent::RecvUpdate prevents this
// from being used when !IsSameProcess(), but we should make this truly
// cross process at some point by passing the HMDConfig
Expand Down
11 changes: 7 additions & 4 deletions layout/base/nsDisplayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,9 +1629,10 @@ already_AddRefed<LayerManager> nsDisplayList::PaintRoot(nsDisplayListBuilder* aB
1.0f/containerParameters.mYScale);
root->SetScaleToResolution(presShell->ScaleToResolution(),
containerParameters.mXScale);
root->SetForceDispatchToContentRegion(
aBuilder->IsBuildingLayerEventRegions() &&
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(presShell));
if (aBuilder->IsBuildingLayerEventRegions() &&
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(presShell)) {
root->SetEventRegionsOverride(EventRegionsOverride::ForceDispatchToContent);
}

if (gfxPrefs::LayoutUseContainersForRootFrames()) {
bool isRoot = presContext->IsRootContentDocument();
Expand Down Expand Up @@ -4089,7 +4090,9 @@ nsDisplaySubDocument::BuildLayer(nsDisplayListBuilder* aBuilder,
}

nsRefPtr<Layer> layer = nsDisplayOwnLayer::BuildLayer(aBuilder, aManager, params);
layer->AsContainerLayer()->SetForceDispatchToContentRegion(mForceDispatchToContentRegion);
if (mForceDispatchToContentRegion) {
layer->AsContainerLayer()->SetEventRegionsOverride(EventRegionsOverride::ForceDispatchToContent);
}
return layer.forget();
}

Expand Down
10 changes: 6 additions & 4 deletions layout/ipc/RenderFrameParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,12 @@ nsDisplayRemote::nsDisplayRemote(nsDisplayListBuilder* aBuilder,
RenderFrameParent* aRemoteFrame)
: nsDisplayItem(aBuilder, aFrame)
, mRemoteFrame(aRemoteFrame)
, mEventRegionsOverride(EventRegionsOverride::NoOverride)
{
mForceDispatchToContentRegion =
aBuilder->IsBuildingLayerEventRegions() &&
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(aFrame->PresContext()->PresShell());
if (aBuilder->IsBuildingLayerEventRegions() &&
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(aFrame->PresContext()->PresShell())) {
mEventRegionsOverride = EventRegionsOverride::ForceDispatchToContent;
}
}

already_AddRefed<Layer>
Expand All @@ -636,7 +638,7 @@ nsDisplayRemote::BuildLayer(nsDisplayListBuilder* aBuilder,
visibleRect += aContainerParameters.mOffset;
nsRefPtr<Layer> layer = mRemoteFrame->BuildLayer(aBuilder, mFrame, aManager, visibleRect, this, aContainerParameters);
if (layer && layer->AsContainerLayer()) {
layer->AsContainerLayer()->SetForceDispatchToContentRegion(mForceDispatchToContentRegion);
layer->AsContainerLayer()->SetEventRegionsOverride(mEventRegionsOverride);
}
return layer.forget();
}
Expand Down
3 changes: 2 additions & 1 deletion layout/ipc/RenderFrameParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mozilla/Attributes.h"
#include <map>

#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layout/PRenderFrameParent.h"
#include "nsDisplayList.h"
#include "RenderFrameUtils.h"
Expand Down Expand Up @@ -184,7 +185,7 @@ class nsDisplayRemote : public nsDisplayItem

private:
RenderFrameParent* mRemoteFrame;
bool mForceDispatchToContentRegion;
mozilla::layers::EventRegionsOverride mEventRegionsOverride;
};


Expand Down

0 comments on commit 7fd26da

Please sign in to comment.