mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-09 04:25:38 +00:00
Compute minimal intermediate surface sizes in Advanced Layers. (bug 1375785, r=mattwoodrow)
--HG-- extra : rebase_source : 60b7a69865a0e9083a61201b8ce1bea2e3c82fd1
This commit is contained in:
parent
9c64aee8c8
commit
af47af94ef
@ -8,11 +8,16 @@
|
||||
#include "LayersLogging.h"
|
||||
#include "LayerManagerMLGPU.h"
|
||||
#include "MLGDevice.h"
|
||||
#include "mozilla/gfx/Rect.h"
|
||||
#include "mozilla/gfx/Types.h"
|
||||
#include "UnitTransforms.h"
|
||||
#include "UtilityMLGPU.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
using namespace gfx;
|
||||
|
||||
ContainerLayerMLGPU::ContainerLayerMLGPU(LayerManagerMLGPU* aManager)
|
||||
: ContainerLayer(aManager, nullptr)
|
||||
, LayerMLGPU(aManager)
|
||||
@ -33,6 +38,24 @@ ContainerLayerMLGPU::OnPrepareToRender(FrameBuilder* aBuilder)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((!mRenderTarget || mChildrenChanged) &&
|
||||
gfxPrefs::AdvancedLayersEnableContainerResizing())
|
||||
{
|
||||
// Try to compute a more accurate visible region.
|
||||
AL_LOG("Computing new surface size for container %p:\n", GetLayer());
|
||||
|
||||
Maybe<IntRect> bounds = ComputeIntermediateSurfaceBounds();
|
||||
if (bounds) {
|
||||
LayerIntRegion region = Move(GetShadowVisibleRegion());
|
||||
region.AndWith(LayerIntRect::FromUnknownRect(bounds.value()));
|
||||
AL_LOG(" computed bounds: %s\n", Stringify(bounds.value()).c_str());
|
||||
AL_LOG(" new visible: %s\n", Stringify(region).c_str());
|
||||
|
||||
SetShadowVisibleRegion(Move(region));
|
||||
}
|
||||
}
|
||||
mChildrenChanged = false;
|
||||
|
||||
mTargetOffset = GetIntermediateSurfaceRect().TopLeft().ToUnknownPoint();
|
||||
mTargetSize = GetIntermediateSurfaceRect().Size().ToUnknownSize();
|
||||
|
||||
@ -51,6 +74,89 @@ ContainerLayerMLGPU::OnPrepareToRender(FrameBuilder* aBuilder)
|
||||
return true;
|
||||
}
|
||||
|
||||
static IntRect
|
||||
GetTransformedBounds(Layer* aLayer)
|
||||
{
|
||||
IntRect bounds = aLayer->GetLocalVisibleRegion().GetBounds().ToUnknownRect();
|
||||
if (bounds.IsEmpty()) {
|
||||
return bounds;
|
||||
}
|
||||
|
||||
const Matrix4x4& transform = aLayer->GetEffectiveTransform();
|
||||
Rect rect = transform.TransformAndClipBounds(Rect(bounds), Rect::MaxIntRect());
|
||||
rect.RoundOut();
|
||||
rect.ToIntRect(&bounds);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
static Maybe<IntRect>
|
||||
FindVisibleBounds(Layer* aLayer, const Maybe<RenderTargetIntRect>& aClip)
|
||||
{
|
||||
AL_LOG(" visiting child %p\n", aLayer);
|
||||
AL_LOG_IF(aClip, " parent clip: %s\n", Stringify(aClip.value()).c_str());
|
||||
|
||||
ContainerLayer* container = aLayer->AsContainerLayer();
|
||||
if (container && !container->UseIntermediateSurface()) {
|
||||
Maybe<IntRect> accumulated = Some(IntRect());
|
||||
|
||||
// Traverse children.
|
||||
for (Layer* child = container->GetFirstChild(); child; child = child->GetNextSibling()) {
|
||||
Maybe<RenderTargetIntRect> clip = aClip;
|
||||
if (const Maybe<ParentLayerIntRect>& childClip = child->AsHostLayer()->GetShadowClipRect()) {
|
||||
RenderTargetIntRect rtChildClip =
|
||||
TransformBy(ViewAs<ParentLayerToRenderTargetMatrix4x4>(
|
||||
aLayer->GetEffectiveTransform(),
|
||||
PixelCastJustification::RenderTargetIsParentLayerForRoot),
|
||||
childClip.value());
|
||||
clip = IntersectMaybeRects(clip, Some(rtChildClip));
|
||||
AL_LOG(" target clip: %s\n", Stringify(rtChildClip).c_str());
|
||||
AL_LOG_IF(clip, " full clip: %s\n", Stringify(clip.value()).c_str());
|
||||
}
|
||||
|
||||
Maybe<IntRect> childBounds = FindVisibleBounds(child, clip);
|
||||
if (!childBounds) {
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
accumulated = accumulated->SafeUnion(childBounds.value());
|
||||
if (!accumulated) {
|
||||
return Nothing();
|
||||
}
|
||||
}
|
||||
return accumulated;
|
||||
}
|
||||
|
||||
IntRect bounds = GetTransformedBounds(aLayer);
|
||||
AL_LOG(" layer bounds: %s\n", Stringify(bounds).c_str());
|
||||
|
||||
if (aClip) {
|
||||
bounds = bounds.Intersect(aClip.value().ToUnknownRect());
|
||||
AL_LOG(" clipped bounds: %s\n", Stringify(bounds).c_str());
|
||||
}
|
||||
return Some(bounds);
|
||||
}
|
||||
|
||||
Maybe<IntRect>
|
||||
ContainerLayerMLGPU::ComputeIntermediateSurfaceBounds()
|
||||
{
|
||||
Maybe<IntRect> bounds = Some(IntRect());
|
||||
for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
|
||||
Maybe<RenderTargetIntRect> clip =
|
||||
ViewAs<RenderTargetPixel>(child->AsHostLayer()->GetShadowClipRect(),
|
||||
PixelCastJustification::RenderTargetIsParentLayerForRoot);
|
||||
Maybe<IntRect> childBounds = FindVisibleBounds(child, clip);
|
||||
if (!childBounds) {
|
||||
return Nothing();
|
||||
}
|
||||
|
||||
bounds = bounds->SafeUnion(childBounds.value());
|
||||
if (!bounds) {
|
||||
return Nothing();
|
||||
}
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
void
|
||||
ContainerLayerMLGPU::OnLayerManagerChange(LayerManagerMLGPU* aManager)
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
protected:
|
||||
bool OnPrepareToRender(FrameBuilder* aBuilder) override;
|
||||
void OnLayerManagerChange(LayerManagerMLGPU* aManager) override;
|
||||
Maybe<gfx::IntRect> ComputeIntermediateSurfaceBounds();
|
||||
|
||||
private:
|
||||
RefPtr<MLGRenderTarget> mRenderTarget;
|
||||
|
@ -32,8 +32,10 @@ template <> struct AlignUp<0>
|
||||
|
||||
#ifdef ENABLE_AL_LOGGING
|
||||
# define AL_LOG(...) printf_stderr("AL: " __VA_ARGS__)
|
||||
# define AL_LOG_IF(cond, ...) do { if (cond) { printf_stderr("AL: " __VA_ARGS__); } } while(0)
|
||||
#else
|
||||
# define AL_LOG(...)
|
||||
# define AL_LOG_IF(...)
|
||||
#endif
|
||||
|
||||
#endif // mozilla_gfx_layers_mlgpu_UtilityMLGPU_h
|
||||
|
@ -581,6 +581,7 @@ private:
|
||||
DECL_GFX_PREF(Once, "layers.mlgpu.enable-depth-buffer", AdvancedLayersEnableDepthBuffer, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.mlgpu.enable-invalidation", AdvancedLayersUseInvalidation, bool, true);
|
||||
DECL_GFX_PREF(Once, "layers.mlgpu.enable-on-windows7", AdvancedLayersEnableOnWindows7, bool, false);
|
||||
DECL_GFX_PREF(Once, "layers.mlgpu.enable-container-resizing", AdvancedLayersEnableContainerResizing, bool, true);
|
||||
DECL_GFX_PREF(Once, "layers.offmainthreadcomposition.force-disabled", LayersOffMainThreadCompositionForceDisabled, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.offmainthreadcomposition.frame-rate", LayersCompositionFrameRate, int32_t,-1);
|
||||
DECL_GFX_PREF(Live, "layers.orientation.sync.timeout", OrientationSyncMillis, uint32_t, (uint32_t)0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user