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