Remove the treewalk in ResetDrawProperties()
[chromium-blink-merge.git] / cc / layers / draw_properties.h
blob6126489ee3a2d209f41c0d6783a0216fff98918d
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"
14 namespace cc {
16 // Container for properties that layers need to compute before they can be
17 // drawn.
18 template <typename LayerType>
19 struct CC_EXPORT DrawProperties {
20 DrawProperties()
21 : opacity(0.f),
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),
28 is_clipped(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 index_of_first_descendants_addition(0),
37 num_descendants_added(0),
38 index_of_first_render_surface_layer_list_addition(0),
39 num_render_surfaces_added(0),
40 last_drawn_render_surface_layer_list_id(0),
41 ideal_contents_scale(0.f),
42 maximum_animation_contents_scale(0.f),
43 starting_animation_contents_scale(0.f),
44 page_scale_factor(0.f),
45 device_scale_factor(0.f) {}
47 // Transforms objects from content space to target surface space, where
48 // this layer would be drawn.
49 gfx::Transform target_space_transform;
51 // Transforms objects from content space to screen space (viewport space).
52 gfx::Transform screen_space_transform;
54 // Known occlusion above the layer mapped to the content space of the layer.
55 Occlusion occlusion_in_content_space;
57 // DrawProperties::opacity may be different than LayerType::opacity,
58 // particularly in the case when a RenderSurface re-parents the layer's
59 // opacity, or when opacity is compounded by the hierarchy.
60 float opacity;
62 // DrawProperties::blend_mode may be different than LayerType::blend_mode,
63 // when a RenderSurface re-parents the layer's blend_mode.
64 SkXfermode::Mode blend_mode;
66 // xxx_is_animating flags are used to indicate whether the DrawProperties
67 // are actually meaningful on the main thread. When the properties are
68 // animating, the main thread may not have the same values that are used
69 // to draw.
70 bool opacity_is_animating;
71 bool screen_space_opacity_is_animating;
72 bool target_space_transform_is_animating;
73 bool screen_space_transform_is_animating;
75 // True if the layer can use LCD text.
76 bool can_use_lcd_text;
78 // True if the layer needs to be clipped by clip_rect.
79 bool is_clipped;
81 // The layer whose coordinate space this layer draws into. This can be
82 // either the same layer (draw_properties_.render_target == this) or an
83 // ancestor of this layer.
84 LayerType* render_target;
86 // This rect is in the layer's content space.
87 gfx::Rect visible_content_rect;
89 // In target surface space, the rect that encloses the clipped, drawable
90 // content of the layer.
91 gfx::Rect drawable_content_rect;
93 // In target surface space, the original rect that clipped this layer. This
94 // value is used to avoid unnecessarily changing GL scissor state.
95 gfx::Rect clip_rect;
97 // The scale used to move between layer space and content space, and bounds
98 // of the space. One is always a function of the other, but which one
99 // depends on the layer type. For picture layers, this is an ideal scale,
100 // and not always the one used.
101 float contents_scale_x;
102 float contents_scale_y;
103 gfx::Size content_bounds;
105 // Number of descendants with a clip parent that is our ancestor. NB - this
106 // does not include our clip children because they are clipped by us.
107 int num_unclipped_descendants;
109 // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
110 // present on it.
111 bool layer_or_descendant_has_copy_request;
113 // If true, the layer or one of its descendants has a wheel or touch handler.
114 bool layer_or_descendant_has_input_handler;
116 // This is true if the layer has any direct child that has a scroll parent.
117 // This layer will not be the scroll parent in this case. This information
118 // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
119 // children have scroll parents, we will not need to recur out of order.
120 bool has_child_with_a_scroll_parent;
122 // If this layer is visited out of order, its contribution to the descendant
123 // and render surface layer lists will be put aside in a temporary list.
124 // These values will allow for an efficient reordering of these additions.
125 size_t index_of_first_descendants_addition;
126 size_t num_descendants_added;
127 size_t index_of_first_render_surface_layer_list_addition;
128 size_t num_render_surfaces_added;
130 // Each time we generate a new render surface layer list, an ID is used to
131 // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
132 // that marked the render surface layer list generation which last updated
133 // these draw properties and determined that this layer will draw itself.
134 // If these draw properties are not a part of the render surface layer list,
135 // or the layer doesn't contribute anything, then this ID will be either out
136 // of date or 0.
137 int last_drawn_render_surface_layer_list_id;
139 // The scale at which content for the layer should be rastered in order to be
140 // perfectly crisp.
141 float ideal_contents_scale;
143 // The maximum scale during the layers current animation at which content
144 // should be rastered at to be crisp.
145 float maximum_animation_contents_scale;
147 // The scale during the layer animation start at which content should be
148 // rastered at to be crisp.
149 float starting_animation_contents_scale;
151 // The page scale factor that is applied to the layer. Since some layers may
152 // have page scale applied and others not, this may differ between layers.
153 float page_scale_factor;
155 // The device scale factor that is applied to the layer.
156 float device_scale_factor;
159 } // namespace cc
161 #endif // CC_LAYERS_DRAW_PROPERTIES_H_