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 num_unclipped_descendants(0),
31 layer_or_descendant_has_copy_request(false),
32 layer_or_descendant_has_input_handler(false),
33 has_child_with_a_scroll_parent(false),
34 index_of_first_descendants_addition(0),
35 num_descendants_added(0),
36 index_of_first_render_surface_layer_list_addition(0),
37 num_render_surfaces_added(0),
38 last_drawn_render_surface_layer_list_id(0),
39 ideal_contents_scale(0.f
),
40 maximum_animation_contents_scale(0.f
),
41 starting_animation_contents_scale(0.f
),
42 page_scale_factor(0.f
),
43 device_scale_factor(0.f
) {}
45 // Transforms objects from content space to target surface space, where
46 // this layer would be drawn.
47 gfx::Transform target_space_transform
;
49 // Transforms objects from content space to screen space (viewport space).
50 gfx::Transform screen_space_transform
;
52 // Known occlusion above the layer mapped to the content space of the layer.
53 Occlusion occlusion_in_content_space
;
55 // DrawProperties::opacity may be different than LayerType::opacity,
56 // particularly in the case when a RenderSurface re-parents the layer's
57 // opacity, or when opacity is compounded by the hierarchy.
60 // DrawProperties::blend_mode may be different than LayerType::blend_mode,
61 // when a RenderSurface re-parents the layer's blend_mode.
62 SkXfermode::Mode blend_mode
;
64 // xxx_is_animating flags are used to indicate whether the DrawProperties
65 // are actually meaningful on the main thread. When the properties are
66 // animating, the main thread may not have the same values that are used
68 bool opacity_is_animating
;
69 bool screen_space_opacity_is_animating
;
70 bool target_space_transform_is_animating
;
71 bool screen_space_transform_is_animating
;
73 // True if the layer can use LCD text.
74 bool can_use_lcd_text
;
76 // True if the layer needs to be clipped by clip_rect.
79 // The layer whose coordinate space this layer draws into. This can be
80 // either the same layer (draw_properties_.render_target == this) or an
81 // ancestor of this layer.
82 LayerType
* render_target
;
84 // This rect is a bounding box around what part of the layer is visible, in
85 // the layer's coordinate space.
86 gfx::Rect visible_layer_rect
;
88 // In target surface space, the rect that encloses the clipped, drawable
89 // content of the layer.
90 gfx::Rect drawable_content_rect
;
92 // In target surface space, the original rect that clipped this layer. This
93 // value is used to avoid unnecessarily changing GL scissor state.
96 // Number of descendants with a clip parent that is our ancestor. NB - this
97 // does not include our clip children because they are clipped by us.
98 size_t num_unclipped_descendants
;
100 // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
102 bool layer_or_descendant_has_copy_request
;
104 // If true, the layer or one of its descendants has a wheel or touch handler.
105 bool layer_or_descendant_has_input_handler
;
107 // This is true if the layer has any direct child that has a scroll parent.
108 // This layer will not be the scroll parent in this case. This information
109 // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
110 // children have scroll parents, we will not need to recur out of order.
111 bool has_child_with_a_scroll_parent
;
113 // If this layer is visited out of order, its contribution to the descendant
114 // and render surface layer lists will be put aside in a temporary list.
115 // These values will allow for an efficient reordering of these additions.
116 size_t index_of_first_descendants_addition
;
117 size_t num_descendants_added
;
118 size_t index_of_first_render_surface_layer_list_addition
;
119 size_t num_render_surfaces_added
;
121 // Each time we generate a new render surface layer list, an ID is used to
122 // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
123 // that marked the render surface layer list generation which last updated
124 // these draw properties and determined that this layer will draw itself.
125 // If these draw properties are not a part of the render surface layer list,
126 // or the layer doesn't contribute anything, then this ID will be either out
128 int last_drawn_render_surface_layer_list_id
;
130 // The scale at which content for the layer should be rastered in order to be
132 float ideal_contents_scale
;
134 // The maximum scale during the layers current animation at which content
135 // should be rastered at to be crisp.
136 float maximum_animation_contents_scale
;
138 // The scale during the layer animation start at which content should be
139 // rastered at to be crisp.
140 float starting_animation_contents_scale
;
142 // The page scale factor that is applied to the layer. Since some layers may
143 // have page scale applied and others not, this may differ between layers.
144 float page_scale_factor
;
146 // The device scale factor that is applied to the layer.
147 float device_scale_factor
;
152 #endif // CC_LAYERS_DRAW_PROPERTIES_H_