[go: nahoru, domu]

slim: Implement visible rect (clip in layer space)

Rename variables in recursive LayerTreeImpl::Draw to document the space
they are in. Eg clip -> clip_in_target.

Compute the transform parent to child by applying the layer transforms
in reverse, and in particular try to invert the transform matrix.
Restrict transforms to be 2D so that if the transforms is not
invertible, then it must transform a layer to be not be visible.
Rely on this fact to just skip the entire subtree and not deal with
non-invertible transforms.

Maintain a clip in layer space by using the parent to child transform
at each recursion level. Note only layers that has masks_to_bounds()
will clip the layer at the recursion.

It is then used as the visible rect in AppendQuads. Note viz expects
that the visible rect is a subset of layer bounds, so this will always
intersect with layer bounds regardless of masks_to_bounds().

Use RectF throughout and gfx::ToEnclosingRect at the end to avoid
any potential rounding errors.

Bug: 1408128
Change-Id: Idbd9a00aaaf93f3f1cad4832a22cf0a2f94372ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4295251
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Commit-Queue: Bo Liu <boliu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1112915}
diff --git a/cc/slim/ui_resource_layer.cc b/cc/slim/ui_resource_layer.cc
index fac58b2..52d8b6e 100644
--- a/cc/slim/ui_resource_layer.cc
+++ b/cc/slim/ui_resource_layer.cc
@@ -141,15 +141,16 @@
 void UIResourceLayer::AppendQuads(viz::CompositorRenderPass& render_pass,
                                   FrameData& data,
                                   const gfx::Transform& transform,
-                                  const gfx::Rect* clip) {
+                                  const gfx::Rect* clip_in_target,
+                                  const gfx::Rect& visible_rect) {
   viz::ResourceId viz_resource_id =
       static_cast<LayerTreeImpl*>(layer_tree())->GetVizResourceId(resource_id_);
   if (viz_resource_id == viz::kInvalidResourceId) {
     return;
   }
 
-  viz::SharedQuadState* quad_state =
-      CreateAndAppendSharedQuadState(render_pass, transform, clip);
+  viz::SharedQuadState* quad_state = CreateAndAppendSharedQuadState(
+      render_pass, transform, clip_in_target, visible_rect);
 
   viz::TextureDrawQuad* quad =
       render_pass.CreateAndAppendDrawQuad<viz::TextureDrawQuad>();