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 layer_or_descendant_is_drawn(false),
36 has_child_with_a_scroll_parent(false),
37 sorted_for_recursion(false),
39 index_of_first_descendants_addition(0),
40 num_descendants_added(0),
41 index_of_first_render_surface_layer_list_addition(0),
42 num_render_surfaces_added(0),
43 last_drawn_render_surface_layer_list_id(0),
44 ideal_contents_scale(0.f
),
45 maximum_animation_contents_scale(0.f
),
46 starting_animation_contents_scale(0.f
),
47 page_scale_factor(0.f
),
48 device_scale_factor(0.f
) {}
50 // Transforms objects from content space to target surface space, where
51 // this layer would be drawn.
52 gfx::Transform target_space_transform
;
54 // Transforms objects from content space to screen space (viewport space).
55 gfx::Transform screen_space_transform
;
57 // Known occlusion above the layer mapped to the content space of the layer.
58 Occlusion occlusion_in_content_space
;
60 // DrawProperties::opacity may be different than LayerType::opacity,
61 // particularly in the case when a RenderSurface re-parents the layer's
62 // opacity, or when opacity is compounded by the hierarchy.
65 // DrawProperties::blend_mode may be different than LayerType::blend_mode,
66 // when a RenderSurface re-parents the layer's blend_mode.
67 SkXfermode::Mode blend_mode
;
69 // xxx_is_animating flags are used to indicate whether the DrawProperties
70 // are actually meaningful on the main thread. When the properties are
71 // animating, the main thread may not have the same values that are used
73 bool opacity_is_animating
;
74 bool screen_space_opacity_is_animating
;
75 bool target_space_transform_is_animating
;
76 bool screen_space_transform_is_animating
;
78 // True if the layer can use LCD text.
79 bool can_use_lcd_text
;
81 // True if the layer needs to be clipped by clip_rect.
84 // The layer whose coordinate space this layer draws into. This can be
85 // either the same layer (draw_properties_.render_target == this) or an
86 // ancestor of this layer.
87 LayerType
* render_target
;
89 // This rect is in the layer's content space.
90 gfx::Rect visible_content_rect
;
92 // In target surface space, the rect that encloses the clipped, drawable
93 // content of the layer.
94 gfx::Rect drawable_content_rect
;
96 // In target surface space, the original rect that clipped this layer. This
97 // value is used to avoid unnecessarily changing GL scissor state.
100 // The scale used to move between layer space and content space, and bounds
101 // of the space. One is always a function of the other, but which one
102 // depends on the layer type. For picture layers, this is an ideal scale,
103 // and not always the one used.
104 float contents_scale_x
;
105 float contents_scale_y
;
106 gfx::Size content_bounds
;
108 // Number of descendants with a clip parent that is our ancestor. NB - this
109 // does not include our clip children because they are clipped by us.
110 int num_unclipped_descendants
;
112 // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
114 bool layer_or_descendant_has_copy_request
;
116 // If true, the layer or one of its descendants has a wheel or touch handler.
117 bool layer_or_descendant_has_input_handler
;
119 // If true, the layer or one of its descendants is drawn
120 bool layer_or_descendant_is_drawn
;
122 // This is true if the layer has any direct child that has a scroll parent.
123 // This layer will not be the scroll parent in this case. This information
124 // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
125 // children have scroll parents, we will not need to recur out of order.
126 bool has_child_with_a_scroll_parent
;
128 // This is true if the order (wrt to its siblings in the tree) in which the
129 // layer will be visited while computing draw properties has been determined.
130 bool sorted_for_recursion
;
132 // This is used to sanity-check CDP and ensure that we don't revisit a layer.
135 // If this layer is visited out of order, its contribution to the descendant
136 // and render surface layer lists will be put aside in a temporary list.
137 // These values will allow for an efficient reordering of these additions.
138 size_t index_of_first_descendants_addition
;
139 size_t num_descendants_added
;
140 size_t index_of_first_render_surface_layer_list_addition
;
141 size_t num_render_surfaces_added
;
143 // Each time we generate a new render surface layer list, an ID is used to
144 // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
145 // that marked the render surface layer list generation which last updated
146 // these draw properties and determined that this layer will draw itself.
147 // If these draw properties are not a part of the render surface layer list,
148 // or the layer doesn't contribute anything, then this ID will be either out
150 int last_drawn_render_surface_layer_list_id
;
152 // The scale at which content for the layer should be rastered in order to be
154 float ideal_contents_scale
;
156 // The maximum scale during the layers current animation at which content
157 // should be rastered at to be crisp.
158 float maximum_animation_contents_scale
;
160 // The scale during the layer animation start at which content should be
161 // rastered at to be crisp.
162 float starting_animation_contents_scale
;
164 // The page scale factor that is applied to the layer. Since some layers may
165 // have page scale applied and others not, this may differ between layers.
166 float page_scale_factor
;
168 // The device scale factor that is applied to the layer.
169 float device_scale_factor
;
174 #endif // CC_LAYERS_DRAW_PROPERTIES_H_