Store the AL render region separately from the shadow visible region. (bug 1408781 part 1, r=mattwoodrow)

--HG--
extra : rebase_source : 14c97296ca7dbe638179476abbe3c8eada5e159a
This commit is contained in:
David Anderson 2017-10-20 10:31:46 -07:00
parent 7570c7a401
commit e5f304d59f
11 changed files with 50 additions and 46 deletions

View File

@ -95,10 +95,10 @@ CanvasLayerMLGPU::ClearCachedResources()
}
void
CanvasLayerMLGPU::SetRegionToRender(LayerIntRegion&& aRegion)
CanvasLayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion)
{
aRegion.AndWith(LayerIntRect::FromUnknownRect(mPictureRect));
LayerMLGPU::SetRegionToRender(Move(aRegion));
LayerMLGPU::SetRenderRegion(Move(aRegion));
}
} // namespace layers

View File

@ -39,7 +39,7 @@ public:
CanvasLayerMLGPU* AsCanvasLayerMLGPU() override { return this; }
gfx::SamplingFilter GetSamplingFilter() override;
void ClearCachedResources() override;
void SetRegionToRender(LayerIntRegion&& aRegion) override;
void SetRenderRegion(LayerIntRegion&& aRegion) override;
MOZ_LAYER_DECL_NAME("CanvasLayerMLGPU", TYPE_CANVAS)

View File

@ -75,7 +75,7 @@ ImageLayerMLGPU::IsContentOpaque()
}
void
ImageLayerMLGPU::SetRegionToRender(LayerIntRegion&& aRegion)
ImageLayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion)
{
switch (mScaleMode) {
case ScaleMode::STRETCH:
@ -88,7 +88,7 @@ ImageLayerMLGPU::SetRegionToRender(LayerIntRegion&& aRegion)
aRegion.AndWith(LayerIntRect(0, 0, mPictureRect.width, mPictureRect.height));
break;
}
LayerMLGPU::SetRegionToRender(Move(aRegion));
LayerMLGPU::SetRenderRegion(Move(aRegion));
}
void

View File

@ -26,7 +26,7 @@ public:
ImageLayerMLGPU* AsImageLayerMLGPU() override { return this; }
void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override;
void SetRegionToRender(LayerIntRegion&& aRegion) override;
void SetRenderRegion(LayerIntRegion&& aRegion) override;
gfx::SamplingFilter GetSamplingFilter() override;
void ClearCachedResources() override;
bool IsContentOpaque() override;

View File

@ -125,9 +125,9 @@ LayerMLGPU::IsContentOpaque()
}
void
LayerMLGPU::SetRegionToRender(LayerIntRegion&& aRegion)
LayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion)
{
SetShadowVisibleRegion(Move(aRegion));
mRenderRegion = Move(aRegion);
}
void

View File

@ -74,13 +74,19 @@ public:
// blend modes or opacity), false otherwise.
virtual bool IsContentOpaque();
// This is a wrapper around SetShadowVisibleRegion. Some layers have visible
// regions that extend beyond what is actually drawn. When performing CPU-
// based occlusion culling we must clamp the visible region to the actual
// area. Note that if a layer is opaque, it must not expand its visible
// region such that it might include non-opaque pixels, as may be the case
// for PaintedLayers with a restricted visible region.
virtual void SetRegionToRender(LayerIntRegion&& aRegion);
// This is used by RenderPasses for deciding which rects to draw. This
// region factors in occulsion culling and any layer-specific adjustments,
// whereas the local/shadow visible region does not.
const LayerIntRegion& GetRenderRegion() const {
return mRenderRegion;
}
// Some layers have visible regions that extend beyond what is actually drawn.
// When performing CPU-based occlusion culling we must clamp the visible region
// to the actual area. Note that if a layer is opaque, it must not expand its
// visible region such that it might include non-opaque pixels, as may be the
// case for PaintedLayers with a restricted visible region.
virtual void SetRenderRegion(LayerIntRegion&& aRegion);
virtual void AssignToView(FrameBuilder* aBuilder,
RenderViewMLGPU* aView,
@ -124,6 +130,7 @@ protected:
uint64_t mFrameKey;
float mComputedOpacity;
bool mPrepared;
LayerIntRegion mRenderRegion;
};
class RefLayerMLGPU final : public RefLayer

View File

@ -6,6 +6,7 @@
#include "PaintedLayerMLGPU.h"
#include "LayerManagerMLGPU.h"
#include "mozilla/layers/LayersHelpers.h"
#include "UnitTransforms.h"
namespace mozilla {
@ -42,10 +43,10 @@ PaintedLayerMLGPU::OnPrepareToRender(FrameBuilder* aBuilder)
return true;
}
nsIntRegion
PaintedLayerMLGPU::GetRenderRegion()
void
PaintedLayerMLGPU::SetRenderRegion(LayerIntRegion&& aRegion)
{
nsIntRegion region;
mRenderRegion = Move(aRegion);
#ifndef MOZ_IGNORE_PAINT_WILL_RESAMPLE
// Note: we don't set PaintWillResample on our ContentTextureHost. The old
@ -56,15 +57,13 @@ PaintedLayerMLGPU::GetRenderRegion()
// behavior), we might break up the visible region again. If that turns
// out to be a problem, we can factor this into ForEachDrawRect instead.
if (MayResample()) {
region = GetShadowVisibleRegion().GetBounds().ToUnknownRect();
} else
#endif
{
region = GetShadowVisibleRegion().ToUnknownRegion();
mRenderRegion = mRenderRegion.GetBounds();
}
#endif
region.AndWith(gfx::IntRect(region.GetBounds().TopLeft(), mTexture->GetSize()));
return region;
LayerIntRect bounds(mRenderRegion.GetBounds().TopLeft(),
ViewAs<LayerPixel>(mTexture->GetSize()));
mRenderRegion.AndWith(bounds);
}
bool

View File

@ -59,10 +59,7 @@ public:
: SamplerMode::LinearRepeat;
}
// This can return a different region than GetShadowVisibleRegion or
// GetLocalVisibleRegion, since we make sure to clamp it to the
// texture size and account for resampling.
nsIntRegion GetRenderRegion();
void SetRenderRegion(LayerIntRegion&& aRegion);
MOZ_LAYER_DECL_NAME("PaintedLayerMLGPU", TYPE_PAINTED)

View File

@ -381,7 +381,7 @@ ClearViewPass::IsCompatible(const ItemInfo& aItem)
bool
ClearViewPass::AddToPass(LayerMLGPU* aItem, ItemInfo& aInfo)
{
const LayerIntRegion& region = aItem->GetShadowVisibleRegion();
const LayerIntRegion& region = aItem->GetRenderRegion();
for (auto iter = region.RectIter(); !iter.Done(); iter.Next()) {
IntRect rect = iter.Get().ToUnknownRect();
rect += aInfo.translation.value();
@ -414,7 +414,7 @@ SolidColorPass::AddToPass(LayerMLGPU* aLayer, ItemInfo& aInfo)
gfx::Color color = ComputeLayerColor(aLayer, colorLayer->GetColor());
const LayerIntRegion& region = aLayer->GetShadowVisibleRegion();
const LayerIntRegion& region = aLayer->GetRenderRegion();
for (auto iter = region.RectIter(); !iter.Done(); iter.Next()) {
const IntRect rect = iter.Get().ToUnknownRect();
ColorTraits traits(aInfo, Rect(rect), color);
@ -619,6 +619,8 @@ SingleTexturePass::AddToPass(LayerMLGPU* aLayer, ItemInfo& aItem)
Txn txn(this);
// Note: these are two separate cases since no Info constructor takes in a
// base LayerMLGPU class.
if (PaintedLayerMLGPU* layer = aLayer->AsPaintedLayerMLGPU()) {
Info info(aItem, layer);
if (!AddItems(txn, info, layer->GetRenderRegion())) {
@ -626,8 +628,7 @@ SingleTexturePass::AddToPass(LayerMLGPU* aLayer, ItemInfo& aItem)
}
} else if (TexturedLayerMLGPU* layer = aLayer->AsTexturedLayerMLGPU()) {
Info info(aItem, layer);
nsIntRegion visible = layer->GetShadowVisibleRegion().ToUnknownRegion();
if (!AddItems(txn, info, visible)) {
if (!AddItems(txn, info, layer->GetRenderRegion())) {
return false;
}
}
@ -778,8 +779,7 @@ VideoRenderPass::AddToPass(LayerMLGPU* aLayer, ItemInfo& aItem)
Txn txn(this);
Info info(aItem, layer);
nsIntRegion visible = layer->GetShadowVisibleRegion().ToUnknownRegion();
if (!AddItems(txn, info, visible)) {
if (!AddItems(txn, info, layer->GetRenderRegion())) {
return false;
}
return txn.Commit();
@ -881,7 +881,7 @@ RenderViewPass::AddToPass(LayerMLGPU* aLayer, ItemInfo& aItem)
IntSize size = mAssignedLayer->GetTargetSize();
// Clamp the visible region to the texture size.
nsIntRegion visible = mAssignedLayer->GetShadowVisibleRegion().ToUnknownRegion();
nsIntRegion visible = mAssignedLayer->GetRenderRegion().ToUnknownRegion();
visible.AndWith(IntRect(offset, size));
Info info(aItem, mAssignedLayer);
@ -934,7 +934,7 @@ GetShaderForBlendMode(CompositionOp aOp)
bool
RenderViewPass::PrepareBlendState()
{
Rect visibleRect(mAssignedLayer->GetShadowVisibleRegion().GetBounds().ToUnknownRect());
Rect visibleRect(mAssignedLayer->GetRenderRegion().GetBounds().ToUnknownRect());
IntRect clipRect(mAssignedLayer->GetComputedClipRect().ToUnknownRect());
const Matrix4x4& transform = mAssignedLayer->GetLayer()->GetEffectiveTransformForBuffer();
@ -1024,7 +1024,7 @@ RenderViewPass::RenderWithBackdropCopy()
RenderViewMLGPU* childView = mAssignedLayer->GetRenderView();
IntRect visible = mAssignedLayer->GetShadowVisibleRegion().GetBounds().ToUnknownRect();
IntRect visible = mAssignedLayer->GetRenderRegion().GetBounds().ToUnknownRect();
IntRect sourceRect = visible + translation - mParentView->GetTargetOffset();
IntPoint destPoint = visible.TopLeft() - childView->GetTargetOffset();

View File

@ -314,12 +314,13 @@ protected:
// surfaces, on the other hand, are relative to the target offset of the
// layer. In all cases the visible region may be partially occluded, so
// knowing the true origin is important.
template <typename RegionType>
bool AddItems(Txn& aTxn,
const Info& aInfo,
const nsIntRegion& aDrawRegion)
const RegionType& aDrawRegion)
{
for (auto iter = aDrawRegion.RectIter(); !iter.Done(); iter.Next()) {
gfx::Rect drawRect = gfx::Rect(iter.Get());
gfx::Rect drawRect = gfx::Rect(iter.Get().ToUnknownRect());
if (!AddItem(aTxn, aInfo, drawRect)) {
return false;
}

View File

@ -135,7 +135,7 @@ RenderViewMLGPU::RenderAfterBackdropCopy()
// Update the invalid bounds based on the container's visible region. This
// of course won't affect the prepared pipeline, but it will change the
// scissor rect in SetDeviceState.
mInvalidBounds = mContainer->GetShadowVisibleRegion().GetBounds().ToUnknownRect() -
mInvalidBounds = mContainer->GetRenderRegion().GetBounds().ToUnknownRect() -
GetTargetOffset();
ExecuteRendering();
@ -215,8 +215,8 @@ RenderViewMLGPU::UpdateVisibleRegion(ItemInfo& aItem)
// Update the render region even if we won't compute visibility, since some
// layer types (like Canvas and Image) need to have the visible region
// clamped.
LayerIntRegion region = Move(aItem.layer->GetShadowVisibleRegion());
aItem.layer->SetRegionToRender(Move(region));
LayerIntRegion region = aItem.layer->GetShadowVisibleRegion();
aItem.layer->SetRenderRegion(Move(region));
AL_LOG("RenderView %p simple occlusion test, bounds=%s, translation?=%d\n",
this,
@ -238,7 +238,7 @@ RenderViewMLGPU::UpdateVisibleRegion(ItemInfo& aItem)
IntRect clip = aItem.layer->GetComputedClipRect().ToUnknownRect();
AL_LOG(" clip=%s\n", Stringify(translation).c_str());
LayerIntRegion region = Move(aItem.layer->GetShadowVisibleRegion());
LayerIntRegion region = aItem.layer->GetShadowVisibleRegion();
region.MoveBy(translation);
AL_LOG(" effective-visible=%s\n", Stringify(region).c_str());
@ -253,14 +253,14 @@ RenderViewMLGPU::UpdateVisibleRegion(ItemInfo& aItem)
region.MoveBy(-translation);
AL_LOG(" new-local-visible=%s\n", Stringify(region).c_str());
aItem.layer->SetRegionToRender(Move(region));
aItem.layer->SetRenderRegion(Move(region));
// Apply the new occluded area. We do another dance with the translation to
// avoid copying the region. We do this after the SetRegionToRender call to
// accomodate the possiblity of a layer changing its visible region.
if (aItem.opaque) {
mOccludedRegion.MoveBy(-translation);
mOccludedRegion.OrWith(aItem.layer->GetShadowVisibleRegion());
mOccludedRegion.OrWith(aItem.layer->GetRenderRegion());
mOccludedRegion.MoveBy(translation);
AL_LOG(" new-occluded=%s\n", Stringify(mOccludedRegion).c_str());