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