1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_LAYERS_DRAW_PROPERTIES_H_
6 #define CC_LAYERS_DRAW_PROPERTIES_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/trees/occlusion.h"
10 #include "third_party/skia/include/core/SkXfermode.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/transform.h"
16 // Container for properties that layers need to compute before they can be
18 template <typename LayerType
>
19 struct CC_EXPORT DrawProperties
{
22 blend_mode(SkXfermode::kSrcOver_Mode
),
23 opacity_is_animating(false),
24 screen_space_opacity_is_animating(false),
25 target_space_transform_is_animating(false),
26 screen_space_transform_is_animating(false),
27 can_use_lcd_text(false),
29 render_target(nullptr),
30 contents_scale_x(1.f
),
31 contents_scale_y(1.f
),
32 num_unclipped_descendants(0),
33 layer_or_descendant_has_copy_request(false),
34 layer_or_descendant_has_input_handler(false),
35 has_child_with_a_scroll_parent(false),
36 sorted_for_recursion(false),
38 index_of_first_descendants_addition(0),
39 num_descendants_added(0),
40 index_of_first_render_surface_layer_list_addition(0),
41 num_render_surfaces_added(0),
42 last_drawn_render_surface_layer_list_id(0),
43 ideal_contents_scale(0.f
),
44 maximum_animation_contents_scale(0.f
),
45 page_scale_factor(0.f
),
46 device_scale_factor(0.f
) {}
48 // Transforms objects from content space to target surface space, where
49 // this layer would be drawn.
50 gfx::Transform target_space_transform
;
52 // Transforms objects from content space to screen space (viewport space).
53 gfx::Transform screen_space_transform
;
55 // Known occlusion above the layer mapped to the content space of the layer.
56 Occlusion occlusion_in_content_space
;
58 // DrawProperties::opacity may be different than LayerType::opacity,
59 // particularly in the case when a RenderSurface re-parents the layer's
60 // opacity, or when opacity is compounded by the hierarchy.
63 // DrawProperties::blend_mode may be different than LayerType::blend_mode,
64 // when a RenderSurface re-parents the layer's blend_mode.
65 SkXfermode::Mode blend_mode
;
67 // xxx_is_animating flags are used to indicate whether the DrawProperties
68 // are actually meaningful on the main thread. When the properties are
69 // animating, the main thread may not have the same values that are used
71 bool opacity_is_animating
;
72 bool screen_space_opacity_is_animating
;
73 bool target_space_transform_is_animating
;
74 bool screen_space_transform_is_animating
;
76 // True if the layer can use LCD text.
77 bool can_use_lcd_text
;
79 // True if the layer needs to be clipped by clip_rect.
82 // The layer whose coordinate space this layer draws into. This can be
83 // either the same layer (draw_properties_.render_target == this) or an
84 // ancestor of this layer.
85 LayerType
* render_target
;
87 // This rect is in the layer's content space.
88 gfx::Rect visible_content_rect
;
90 // In target surface space, the rect that encloses the clipped, drawable
91 // content of the layer.
92 gfx::Rect drawable_content_rect
;
94 // In target surface space, the original rect that clipped this layer. This
95 // value is used to avoid unnecessarily changing GL scissor state.
98 // The scale used to move between layer space and content space, and bounds
99 // of the space. One is always a function of the other, but which one
100 // depends on the layer type. For picture layers, this is an ideal scale,
101 // and not always the one used.
102 float contents_scale_x
;
103 float contents_scale_y
;
104 gfx::Size content_bounds
;
106 // Number of descendants with a clip parent that is our ancestor. NB - this
107 // does not include our clip children because they are clipped by us.
108 int num_unclipped_descendants
;
110 // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
112 bool layer_or_descendant_has_copy_request
;
114 // If true, the layer or one of its descendants has a wheel or touch handler.
115 bool layer_or_descendant_has_input_handler
;
117 // This is true if the layer has any direct child that has a scroll parent.
118 // This layer will not be the scroll parent in this case. This information
119 // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
120 // children have scroll parents, we will not need to recur out of order.
121 bool has_child_with_a_scroll_parent
;
123 // This is true if the order (wrt to its siblings in the tree) in which the
124 // layer will be visited while computing draw properties has been determined.
125 bool sorted_for_recursion
;
127 // This is used to sanity-check CDP and ensure that we don't revisit a layer.
130 // If this layer is visited out of order, its contribution to the descendant
131 // and render surface layer lists will be put aside in a temporary list.
132 // These values will allow for an efficient reordering of these additions.
133 size_t index_of_first_descendants_addition
;
134 size_t num_descendants_added
;
135 size_t index_of_first_render_surface_layer_list_addition
;
136 size_t num_render_surfaces_added
;
138 // Each time we generate a new render surface layer list, an ID is used to
139 // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
140 // that marked the render surface layer list generation which last updated
141 // these draw properties and determined that this layer will draw itself.
142 // If these draw properties are not a part of the render surface layer list,
143 // or the layer doesn't contribute anything, then this ID will be either out
145 int last_drawn_render_surface_layer_list_id
;
147 // The scale at which content for the layer should be rastered in order to be
149 float ideal_contents_scale
;
151 // The maximum scale during the layers current animation at which content
152 // should be rastered at to be crisp.
153 float maximum_animation_contents_scale
;
155 // The page scale factor that is applied to the layer. Since some layers may
156 // have page scale applied and others not, this may differ between layers.
157 float page_scale_factor
;
159 // The device scale factor that is applied to the layer.
160 float device_scale_factor
;
165 #endif // CC_LAYERS_DRAW_PROPERTIES_H_