• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CC_LAYERS_DRAW_PROPERTIES_H_
6 #define CC_LAYERS_DRAW_PROPERTIES_H_
7 
8 #include "base/memory/scoped_ptr.h"
9 #include "ui/gfx/rect.h"
10 #include "ui/gfx/transform.h"
11 
12 namespace cc {
13 
14 // Container for properties that layers need to compute before they can be
15 // drawn.
16 template <typename LayerType>
17 struct CC_EXPORT DrawProperties {
DrawPropertiesDrawProperties18   DrawProperties()
19       : opacity(0.f),
20         opacity_is_animating(false),
21         screen_space_opacity_is_animating(false),
22         target_space_transform_is_animating(false),
23         screen_space_transform_is_animating(false),
24         can_use_lcd_text(false),
25         is_clipped(false),
26         render_target(NULL),
27         contents_scale_x(1.f),
28         contents_scale_y(1.f),
29         num_descendants_that_draw_content(0),
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         sorted_for_recursion(false),
35         index_of_first_descendants_addition(0),
36         num_descendants_added(0),
37         index_of_first_render_surface_layer_list_addition(0),
38         num_render_surfaces_added(0),
39         last_drawn_render_surface_layer_list_id(0),
40         ideal_contents_scale(0.f),
41         maximum_animation_contents_scale(0.f),
42         page_scale_factor(0.f),
43         device_scale_factor(0.f) {}
44 
45   // Transforms objects from content space to target surface space, where
46   // this layer would be drawn.
47   gfx::Transform target_space_transform;
48 
49   // Transforms objects from content space to screen space (viewport space).
50   gfx::Transform screen_space_transform;
51 
52   // DrawProperties::opacity may be different than LayerType::opacity,
53   // particularly in the case when a RenderSurface re-parents the layer's
54   // opacity, or when opacity is compounded by the hierarchy.
55   float opacity;
56 
57   // xxx_is_animating flags are used to indicate whether the DrawProperties
58   // are actually meaningful on the main thread. When the properties are
59   // animating, the main thread may not have the same values that are used
60   // to draw.
61   bool opacity_is_animating;
62   bool screen_space_opacity_is_animating;
63   bool target_space_transform_is_animating;
64   bool screen_space_transform_is_animating;
65 
66   // True if the layer can use LCD text.
67   bool can_use_lcd_text;
68 
69   // True if the layer needs to be clipped by clip_rect.
70   bool is_clipped;
71 
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;
76 
77   // The surface that this layer and its subtree would contribute to.
78   scoped_ptr<typename LayerType::RenderSurfaceType> render_surface;
79 
80   // This rect is in the layer's content space.
81   gfx::Rect visible_content_rect;
82 
83   // In target surface space, the rect that encloses the clipped, drawable
84   // content of the layer.
85   gfx::Rect drawable_content_rect;
86 
87   // In target surface space, the original rect that clipped this layer. This
88   // value is used to avoid unnecessarily changing GL scissor state.
89   gfx::Rect clip_rect;
90 
91   // The scale used to move between layer space and content space, and bounds
92   // of the space. One is always a function of the other, but which one
93   // depends on the layer type. For picture layers, this is an ideal scale,
94   // and not always the one used.
95   float contents_scale_x;
96   float contents_scale_y;
97   gfx::Size content_bounds;
98 
99   // Does not include this layer itself, only its children and descendants.
100   int num_descendants_that_draw_content;
101 
102   // Number of descendants with a clip parent that is our ancestor. NB - this
103   // does not include our clip children because they are clipped by us.
104   int num_unclipped_descendants;
105 
106   // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
107   // present on it.
108   bool layer_or_descendant_has_copy_request;
109 
110   // If true, the layer or one of its descendants has a wheel or touch handler.
111   bool layer_or_descendant_has_input_handler;
112 
113   // This is true if the layer has any direct child that has a scroll parent.
114   // This layer will not be the scroll parent in this case. This information
115   // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
116   // children have scroll parents, we will not need to recur out of order.
117   bool has_child_with_a_scroll_parent;
118 
119   // This is true if the order (wrt to its siblings in the tree) in which the
120   // layer will be visited while computing draw properties has been determined.
121   bool sorted_for_recursion;
122 
123   // If this layer is visited out of order, its contribution to the descendant
124   // and render surface layer lists will be put aside in a temporary list.
125   // These values will allow for an efficient reordering of these additions.
126   size_t index_of_first_descendants_addition;
127   size_t num_descendants_added;
128   size_t index_of_first_render_surface_layer_list_addition;
129   size_t num_render_surfaces_added;
130 
131   // Each time we generate a new render surface layer list, an ID is used to
132   // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
133   // that marked the render surface layer list generation which last updated
134   // these draw properties and determined that this layer will draw itself.
135   // If these draw properties are not a part of the render surface layer list,
136   // or the layer doesn't contribute anything, then this ID will be either out
137   // of date or 0.
138   int last_drawn_render_surface_layer_list_id;
139 
140   // The scale at which content for the layer should be rastered in order to be
141   // perfectly crisp.
142   float ideal_contents_scale;
143 
144   // The maximum scale during the layers current animation at which content
145   // should be rastered at to be crisp.
146   float maximum_animation_contents_scale;
147 
148   // The page scale factor that is applied to the layer. Since some layers may
149   // have page scale applied and others not, this may differ between layers.
150   float page_scale_factor;
151 
152   // The device scale factor that is applied to the layer.
153   float device_scale_factor;
154 };
155 
156 }  // namespace cc
157 
158 #endif  // CC_LAYERS_DRAW_PROPERTIES_H_
159