Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: cc/trees/draw_property_utils.cc

Issue 1310283002: cc: Avoid duplicate work when computing draw properties using property trees (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move RenderSurfaceDrawProperties to its own file Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/draw_property_utils.h ('k') | cc/trees/layer_tree_host_common.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/draw_property_utils.cc
diff --git a/cc/trees/draw_property_utils.cc b/cc/trees/draw_property_utils.cc
index a000ec6a8e218b46c02651668eaffaf9fd891dfc..a3fa4b5b0e8ef3a87199dc75e4db29d28449cb37 100644
--- a/cc/trees/draw_property_utils.cc
+++ b/cc/trees/draw_property_utils.cc
@@ -7,8 +7,10 @@
#include <vector>
#include "cc/base/math_util.h"
+#include "cc/layers/draw_properties.h"
#include "cc/layers/layer.h"
#include "cc/layers/layer_impl.h"
+#include "cc/layers/render_surface_draw_properties.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/property_tree.h"
#include "cc/trees/property_tree_builder.h"
@@ -630,9 +632,7 @@ void ComputeVisibleRectsUsingPropertyTrees(LayerImpl* root_layer,
template <typename LayerType>
gfx::Transform DrawTransformFromPropertyTreesInternal(
const LayerType* layer,
- const TransformTree& tree) {
- const TransformNode* node = tree.Node(layer->transform_tree_index());
-
+ const TransformNode* node) {
gfx::Transform xform;
const bool owns_non_root_surface =
layer->parent() && layer->has_render_surface();
@@ -653,17 +653,18 @@ gfx::Transform DrawTransformFromPropertyTreesInternal(
gfx::Transform DrawTransformFromPropertyTrees(const Layer* layer,
const TransformTree& tree) {
- return DrawTransformFromPropertyTreesInternal(layer, tree);
+ return DrawTransformFromPropertyTreesInternal(
+ layer, tree.Node(layer->transform_tree_index()));
}
gfx::Transform DrawTransformFromPropertyTrees(const LayerImpl* layer,
const TransformTree& tree) {
- return DrawTransformFromPropertyTreesInternal(layer, tree);
+ return DrawTransformFromPropertyTreesInternal(
+ layer, tree.Node(layer->transform_tree_index()));
}
-gfx::Transform DrawTransformOfRenderSurfaceFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const TransformTree& tree) {
+gfx::Transform SurfaceDrawTransform(const RenderSurfaceImpl* render_surface,
+ const TransformTree& tree) {
const TransformNode* node = tree.Node(render_surface->TransformTreeIndex());
gfx::Transform render_surface_transform;
// The draw transform of root render surface is identity tranform.
@@ -681,28 +682,24 @@ gfx::Transform DrawTransformOfRenderSurfaceFromPropertyTrees(
return render_surface_transform;
}
-bool RenderSurfaceIsClippedFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const ClipTree& tree) {
- const ClipNode* node = tree.Node(render_surface->ClipTreeIndex());
+bool SurfaceIsClipped(const RenderSurfaceImpl* render_surface,
+ const ClipNode* clip_node) {
// If the render surface's owning layer doesn't form a clip node, it is not
// clipped.
- if (render_surface->OwningLayerId() != node->owner_id)
+ if (render_surface->OwningLayerId() != clip_node->owner_id)
return false;
- return node->data.render_surface_is_clipped;
+ return clip_node->data.render_surface_is_clipped;
}
-gfx::Rect ClipRectOfRenderSurfaceFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const ClipTree& clip_tree) {
- if (!RenderSurfaceIsClippedFromPropertyTrees(render_surface, clip_tree))
+gfx::Rect SurfaceClipRect(const RenderSurfaceImpl* render_surface,
+ const ClipNode* parent_clip_node,
+ bool is_clipped) {
+ if (!is_clipped)
return gfx::Rect();
- const ClipNode* clip_node = clip_tree.Node(render_surface->ClipTreeIndex());
- const ClipNode* parent_clip_node = clip_tree.parent(clip_node);
return gfx::ToEnclosingRect(parent_clip_node->data.clip_in_target_space);
}
-gfx::Transform ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees(
+gfx::Transform SurfaceScreenSpaceTransform(
const RenderSurfaceImpl* render_surface,
const TransformTree& tree) {
const TransformNode* node = tree.Node(render_surface->TransformTreeIndex());
@@ -721,74 +718,31 @@ gfx::Transform ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees(
template <typename LayerType>
gfx::Transform ScreenSpaceTransformFromPropertyTreesInternal(
LayerType* layer,
- const TransformTree& tree) {
+ const TransformNode* node) {
gfx::Transform xform(1, 0, 0, 1, layer->offset_to_transform_parent().x(),
layer->offset_to_transform_parent().y());
- if (layer->transform_tree_index() >= 0) {
- gfx::Transform ssxform =
- tree.Node(layer->transform_tree_index())->data.to_screen;
- xform.ConcatTransform(ssxform);
- if (layer->should_flatten_transform_from_property_tree())
- xform.FlattenTo2d();
- }
+ gfx::Transform ssxform = node->data.to_screen;
+ xform.ConcatTransform(ssxform);
+ if (layer->should_flatten_transform_from_property_tree())
+ xform.FlattenTo2d();
return xform;
}
gfx::Transform ScreenSpaceTransformFromPropertyTrees(
const Layer* layer,
const TransformTree& tree) {
- return ScreenSpaceTransformFromPropertyTreesInternal(layer, tree);
+ return ScreenSpaceTransformFromPropertyTreesInternal(
+ layer, tree.Node(layer->transform_tree_index()));
}
gfx::Transform ScreenSpaceTransformFromPropertyTrees(
const LayerImpl* layer,
const TransformTree& tree) {
- return ScreenSpaceTransformFromPropertyTreesInternal(layer, tree);
+ return ScreenSpaceTransformFromPropertyTreesInternal(
+ layer, tree.Node(layer->transform_tree_index()));
}
-template <typename LayerType>
-bool ScreenSpaceTransformIsAnimatingFromPropertyTreesInternal(
- LayerType* layer,
- const TransformTree& tree) {
- return tree.Node(layer->transform_tree_index())->data.to_screen_is_animated;
-}
-
-bool ScreenSpaceTransformIsAnimatingFromPropertyTrees(
- const Layer* layer,
- const TransformTree& tree) {
- return ScreenSpaceTransformIsAnimatingFromPropertyTreesInternal(layer, tree);
-}
-
-bool ScreenSpaceTransformIsAnimatingFromPropertyTrees(
- const LayerImpl* layer,
- const TransformTree& tree) {
- return ScreenSpaceTransformIsAnimatingFromPropertyTreesInternal(layer, tree);
-}
-
-float MaximumAnimationTargetScaleFromPropertyTrees(const LayerImpl* layer,
- const TransformTree& tree) {
- if (!layer->layer_tree_impl()
- ->settings()
- .layer_transforms_should_scale_layer_contents)
- return 0.f;
-
- return tree.Node(layer->transform_tree_index())
- ->data.combined_maximum_animation_target_scale;
-}
-
-float StartingAnimationScaleFromPropertyTrees(const LayerImpl* layer,
- const TransformTree& tree) {
- if (!layer->layer_tree_impl()
- ->settings()
- .layer_transforms_should_scale_layer_contents)
- return 0.f;
-
- return tree.Node(layer->transform_tree_index())
- ->data.combined_starting_animation_scale;
-}
-
-float DrawOpacityFromPropertyTrees(const LayerImpl* layer,
- const EffectTree& tree) {
+float LayerDrawOpacity(const LayerImpl* layer, const EffectTree& tree) {
if (!layer->render_target())
return 0.f;
@@ -806,9 +760,8 @@ float DrawOpacityFromPropertyTrees(const LayerImpl* layer,
return draw_opacity;
}
-float DrawOpacityOfRenderSurfaceFromPropertyTrees(
- RenderSurfaceImpl* render_surface,
- const EffectTree& tree) {
+float SurfaceDrawOpacity(RenderSurfaceImpl* render_surface,
+ const EffectTree& tree) {
const EffectNode* node = tree.Node(render_surface->EffectTreeIndex());
float target_opacity_tree_index = render_surface->TargetEffectTreeIndex();
if (target_opacity_tree_index < 0)
@@ -822,25 +775,20 @@ float DrawOpacityOfRenderSurfaceFromPropertyTrees(
return draw_opacity;
}
-bool CanUseLcdTextFromPropertyTrees(const LayerImpl* layer,
- bool layers_always_allowed_lcd_text,
- bool can_use_lcd_text,
- PropertyTrees* property_trees) {
+bool LayerCanUseLcdText(const LayerImpl* layer,
+ bool layers_always_allowed_lcd_text,
+ bool can_use_lcd_text,
+ const TransformNode* transform_node,
+ const EffectNode* effect_node) {
if (layers_always_allowed_lcd_text)
return true;
if (!can_use_lcd_text)
return false;
if (!layer->contents_opaque())
return false;
- DCHECK(!property_trees->transform_tree.needs_update());
- DCHECK(!property_trees->effect_tree.needs_update());
- const EffectNode* opacity_node =
- property_trees->effect_tree.Node(layer->effect_tree_index());
- if (opacity_node->data.screen_space_opacity != 1.f)
+ if (effect_node->data.screen_space_opacity != 1.f)
return false;
- const TransformNode* transform_node =
- property_trees->transform_tree.Node(layer->transform_tree_index());
if (!transform_node->data.node_and_ancestors_have_only_integer_translation)
return false;
if (static_cast<int>(layer->offset_to_transform_parent().x()) !=
@@ -852,43 +800,14 @@ bool CanUseLcdTextFromPropertyTrees(const LayerImpl* layer,
return true;
}
-gfx::Rect DrawableContentRectOfSurfaceFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const TransformTree& transform_tree) {
- gfx::Rect drawable_content_rect =
- gfx::ToEnclosingRect(MathUtil::MapClippedRect(
- DrawTransformOfRenderSurfaceFromPropertyTrees(render_surface,
- transform_tree),
- render_surface->content_rect_from_property_trees()));
- if (render_surface->HasReplica()) {
- drawable_content_rect.Union(gfx::ToEnclosingRect(MathUtil::MapClippedRect(
- DrawTransformOfRenderSurfaceReplicaFromPropertyTrees(render_surface,
- transform_tree),
- render_surface->content_rect_from_property_trees())));
- }
- return drawable_content_rect;
-}
-
-gfx::Rect DrawableContentRectFromPropertyTrees(
+gfx::Rect LayerDrawableContentRect(
const LayerImpl* layer,
- const TransformTree& transform_tree) {
- gfx::Rect drawable_content_rect = MathUtil::MapEnclosingClippedRect(
- DrawTransformFromPropertyTrees(layer, transform_tree),
- gfx::Rect(layer->bounds()));
- if (layer->is_clipped()) {
- drawable_content_rect.Intersect(
- layer->clip_rect_in_target_space_from_property_trees());
- }
- return drawable_content_rect;
-}
-
-gfx::Rect ClipRectFromPropertyTrees(const LayerImpl* layer,
- const TransformTree& transform_tree) {
+ const gfx::Rect& layer_bounds_in_target_space,
+ const gfx::Rect& clip_rect) {
if (layer->is_clipped())
- return layer->clip_rect_in_target_space_from_property_trees();
- return MathUtil::MapEnclosingClippedRect(
- DrawTransformFromPropertyTrees(layer, transform_tree),
- gfx::Rect(layer->bounds()));
+ return IntersectRects(layer_bounds_in_target_space, clip_rect);
+
+ return layer_bounds_in_target_space;
}
gfx::Transform ReplicaToSurfaceTransform(
@@ -918,23 +837,89 @@ gfx::Transform ReplicaToSurfaceTransform(
return replica_to_surface;
}
-gfx::Transform DrawTransformOfRenderSurfaceReplicaFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const TransformTree& tree) {
- if (!render_surface->HasReplica())
- return gfx::Transform();
- return DrawTransformOfRenderSurfaceFromPropertyTrees(render_surface, tree) *
- ReplicaToSurfaceTransform(render_surface, tree);
+gfx::Rect LayerClipRect(const LayerImpl* layer,
+ const gfx::Rect& layer_bounds_in_target_space) {
+ if (layer->is_clipped())
+ return layer->clip_rect_in_target_space_from_property_trees();
+
+ return layer_bounds_in_target_space;
}
-gfx::Transform ScreenSpaceTransformOfRenderSurfaceReplicaFromPropertyTrees(
- const RenderSurfaceImpl* render_surface,
- const TransformTree& tree) {
- if (!render_surface->HasReplica())
- return gfx::Transform();
- return ScreenSpaceTransformOfRenderSurfaceFromPropertyTrees(render_surface,
- tree) *
- ReplicaToSurfaceTransform(render_surface, tree);
+void ComputeLayerDrawPropertiesUsingPropertyTrees(
+ const LayerImpl* layer,
+ const PropertyTrees* property_trees,
+ bool layers_always_allowed_lcd_text,
+ bool can_use_lcd_text,
+ DrawProperties* draw_properties) {
+ draw_properties->visible_layer_rect =
+ layer->visible_rect_from_property_trees();
+
+ const TransformNode* transform_node =
+ property_trees->transform_tree.Node(layer->transform_tree_index());
+ const EffectNode* effect_node =
+ property_trees->effect_tree.Node(layer->effect_tree_index());
+
+ draw_properties->target_space_transform =
+ DrawTransformFromPropertyTreesInternal(layer, transform_node);
+ draw_properties->screen_space_transform =
+ ScreenSpaceTransformFromPropertyTreesInternal(layer, transform_node);
+ draw_properties->screen_space_transform_is_animating =
+ transform_node->data.to_screen_is_animated;
+ if (layer->layer_tree_impl()
+ ->settings()
+ .layer_transforms_should_scale_layer_contents) {
+ draw_properties->maximum_animation_contents_scale =
+ transform_node->data.combined_maximum_animation_target_scale;
+ draw_properties->starting_animation_contents_scale =
+ transform_node->data.combined_starting_animation_scale;
+ } else {
+ draw_properties->maximum_animation_contents_scale = 0.f;
+ draw_properties->starting_animation_contents_scale = 0.f;
+ }
+
+ draw_properties->opacity =
+ LayerDrawOpacity(layer, property_trees->effect_tree);
+ draw_properties->can_use_lcd_text =
+ LayerCanUseLcdText(layer, layers_always_allowed_lcd_text,
+ can_use_lcd_text, transform_node, effect_node);
+
+ gfx::Rect bounds_in_target_space = MathUtil::MapEnclosingClippedRect(
+ draw_properties->target_space_transform, gfx::Rect(layer->bounds()));
+ draw_properties->clip_rect = LayerClipRect(layer, bounds_in_target_space);
+ draw_properties->drawable_content_rect = LayerDrawableContentRect(
+ layer, bounds_in_target_space, draw_properties->clip_rect);
+}
+
+void ComputeSurfaceDrawPropertiesUsingPropertyTrees(
+ RenderSurfaceImpl* render_surface,
+ const PropertyTrees* property_trees,
+ RenderSurfaceDrawProperties* draw_properties) {
+ const ClipNode* clip_node =
+ property_trees->clip_tree.Node(render_surface->ClipTreeIndex());
+
+ draw_properties->is_clipped = SurfaceIsClipped(render_surface, clip_node);
+ draw_properties->draw_opacity =
+ SurfaceDrawOpacity(render_surface, property_trees->effect_tree);
+ draw_properties->draw_transform =
+ SurfaceDrawTransform(render_surface, property_trees->transform_tree);
+ draw_properties->screen_space_transform = SurfaceScreenSpaceTransform(
+ render_surface, property_trees->transform_tree);
+
+ if (render_surface->HasReplica()) {
+ gfx::Transform replica_to_surface = ReplicaToSurfaceTransform(
+ render_surface, property_trees->transform_tree);
+ draw_properties->replica_draw_transform =
+ draw_properties->draw_transform * replica_to_surface;
+ draw_properties->replica_screen_space_transform =
+ draw_properties->screen_space_transform * replica_to_surface;
+ } else {
+ draw_properties->replica_draw_transform.MakeIdentity();
+ draw_properties->replica_screen_space_transform.MakeIdentity();
+ }
+
+ draw_properties->clip_rect = SurfaceClipRect(
+ render_surface, property_trees->clip_tree.parent(clip_node),
+ draw_properties->is_clipped);
}
} // namespace cc
« no previous file with comments | « cc/trees/draw_property_utils.h ('k') | cc/trees/layer_tree_host_common.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698