Bug 1263829 - Part 1: Allow static checking of whether we want an active opacity layer. r=mstange

This commit is contained in:
Matt Woodrow 2016-06-08 17:12:20 +12:00
parent 49c7837186
commit 2cdd2a5840
2 changed files with 18 additions and 18 deletions

View File

@ -4378,23 +4378,23 @@ nsDisplayOpacity::BuildLayer(nsDisplayListBuilder* aBuilder,
* size --- but this should be good enough.
*/
static bool
IsItemTooSmallForActiveLayer(nsDisplayItem* aItem)
IsItemTooSmallForActiveLayer(nsIFrame* aFrame)
{
nsIntRect visibleDevPixels = aItem->Frame()->GetVisualOverflowRectRelativeToSelf().ToOutsidePixels(
aItem->Frame()->PresContext()->AppUnitsPerDevPixel());
nsIntRect visibleDevPixels = aFrame->GetVisualOverflowRectRelativeToSelf().ToOutsidePixels(
aFrame->PresContext()->AppUnitsPerDevPixel());
static const int MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS = 16;
return visibleDevPixels.Size() <
nsIntSize(MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS, MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS);
}
static void
SetAnimationPerformanceWarningForTooSmallItem(nsDisplayItem* aItem,
SetAnimationPerformanceWarningForTooSmallItem(nsIFrame* aFrame,
nsCSSProperty aProperty)
{
// We use ToNearestPixels() here since ToOutsidePixels causes some sort of
// errors. See https://bugzilla.mozilla.org/show_bug.cgi?id=1258904#c19
nsIntRect visibleDevPixels = aItem->Frame()->GetVisualOverflowRectRelativeToSelf().ToNearestPixels(
aItem->Frame()->PresContext()->AppUnitsPerDevPixel());
nsIntRect visibleDevPixels = aFrame->GetVisualOverflowRectRelativeToSelf().ToNearestPixels(
aFrame->PresContext()->AppUnitsPerDevPixel());
// Set performance warning only if the visible dev pixels is not empty
// because dev pixels is empty if the frame has 'preserve-3d' style.
@ -4402,23 +4402,23 @@ SetAnimationPerformanceWarningForTooSmallItem(nsDisplayItem* aItem,
return;
}
EffectCompositor::SetPerformanceWarning(aItem->Frame(), aProperty,
EffectCompositor::SetPerformanceWarning(aFrame, aProperty,
AnimationPerformanceWarning(
AnimationPerformanceWarning::Type::ContentTooSmall,
{ visibleDevPixels.Width(), visibleDevPixels.Height() }));
}
bool
nsDisplayOpacity::NeedsActiveLayer(nsDisplayListBuilder* aBuilder)
/* static */ bool
nsDisplayOpacity::NeedsActiveLayer(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
{
if (ActiveLayerTracker::IsStyleAnimated(aBuilder, mFrame,
if (ActiveLayerTracker::IsStyleAnimated(aBuilder, aFrame,
eCSSProperty_opacity) ||
EffectCompositor::HasAnimationsForCompositor(mFrame,
EffectCompositor::HasAnimationsForCompositor(aFrame,
eCSSProperty_opacity)) {
if (!IsItemTooSmallForActiveLayer(this)) {
if (!IsItemTooSmallForActiveLayer(aFrame)) {
return true;
}
SetAnimationPerformanceWarningForTooSmallItem(this, eCSSProperty_opacity);
SetAnimationPerformanceWarningForTooSmallItem(aFrame, eCSSProperty_opacity);
}
return false;
}
@ -4444,7 +4444,7 @@ nsDisplayOpacity::CanApplyOpacity() const
bool
nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
{
if (NeedsActiveLayer(aBuilder) || mOpacity == 0.0) {
if (NeedsActiveLayer(aBuilder, mFrame) || mOpacity == 0.0) {
// If our opacity is zero then we'll discard all descendant display items
// except for layer event regions, so there's no point in doing this
// optimization (and if we do do it, then invalidations of those descendants
@ -4506,7 +4506,7 @@ nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
return LAYER_INACTIVE;
}
if (NeedsActiveLayer(aBuilder)) {
if (NeedsActiveLayer(aBuilder, mFrame)) {
// Returns LAYER_ACTIVE_FORCE to avoid flatterning the layer for async
// animations.
return LAYER_ACTIVE_FORCE;
@ -6021,10 +6021,10 @@ nsDisplayTransform::MayBeAnimated(nsDisplayListBuilder* aBuilder)
eCSSProperty_transform) ||
EffectCompositor::HasAnimationsForCompositor(mFrame,
eCSSProperty_transform)) {
if (!IsItemTooSmallForActiveLayer(this)) {
if (!IsItemTooSmallForActiveLayer(mFrame)) {
return true;
}
SetAnimationPerformanceWarningForTooSmallItem(this, eCSSProperty_transform);
SetAnimationPerformanceWarningForTooSmallItem(mFrame, eCSSProperty_transform);
}
return false;
}

View File

@ -3391,7 +3391,7 @@ public:
const DisplayItemClip* aClip) override;
virtual bool CanApplyOpacity() const override;
virtual bool ShouldFlattenAway(nsDisplayListBuilder* aBuilder) override;
bool NeedsActiveLayer(nsDisplayListBuilder* aBuilder);
static bool NeedsActiveLayer(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame);
NS_DISPLAY_DECL_NAME("Opacity", TYPE_OPACITY)
virtual void WriteDebugInfo(std::stringstream& aStream) override;