[go: nahoru, domu]

slim: Implement opacity correctly

Opacity applies to the whole subtree, not just the layer it is set on.
Also directly applying opacity to all quads from the subtree is
incorrect if those quads overlap and has to blend. The correct results
requires an extra render pass where the subtree is drawn without
opacity, but the extra pass is drawn with opacity.

Duplicate the behavior from cc.
* Implement Layer::NumDescendantsThatDrawContent which counts number of
  layers in a subtree (excluding the root) that draws in the structure
  of the tree.
* Pass opacity through each level of recursion of draw, create new
  render pass if there are more than 2 layers that draws.
* Skip subtree where opacity is 0.

Bug: 1408128
Change-Id: I2eb2d825c972201a982b5be12854669b69678d0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4335358
Commit-Queue: Bo Liu <boliu@chromium.org>
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1117038}
diff --git a/cc/slim/ui_resource_layer.cc b/cc/slim/ui_resource_layer.cc
index 309fce1..e1e762a 100644
--- a/cc/slim/ui_resource_layer.cc
+++ b/cc/slim/ui_resource_layer.cc
@@ -143,7 +143,8 @@
                                   const gfx::Transform& transform_to_root,
                                   const gfx::Transform& transform_to_target,
                                   const gfx::Rect* clip_in_target,
-                                  const gfx::Rect& visible_rect) {
+                                  const gfx::Rect& visible_rect,
+                                  float opacity) {
   viz::ResourceId viz_resource_id =
       static_cast<LayerTreeImpl*>(layer_tree())->GetVizResourceId(resource_id_);
   if (viz_resource_id == viz::kInvalidResourceId) {
@@ -151,7 +152,7 @@
   }
 
   viz::SharedQuadState* quad_state = CreateAndAppendSharedQuadState(
-      render_pass, transform_to_target, clip_in_target, visible_rect);
+      render_pass, transform_to_target, clip_in_target, visible_rect, opacity);
 
   viz::TextureDrawQuad* quad =
       render_pass.CreateAndAppendDrawQuad<viz::TextureDrawQuad>();