draw_properties.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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_descendants_that_draw_content(0),
30        num_unclipped_descendants(0),
31        layer_or_descendant_has_copy_request(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
39  // Transforms objects from content space to target surface space, where
40  // this layer would be drawn.
41  gfx::Transform target_space_transform;
42
43  // Transforms objects from content space to screen space (viewport space).
44  gfx::Transform screen_space_transform;
45
46  // DrawProperties::opacity may be different than LayerType::opacity,
47  // particularly in the case when a RenderSurface re-parents the layer's
48  // opacity, or when opacity is compounded by the hierarchy.
49  float opacity;
50
51  // xxx_is_animating flags are used to indicate whether the DrawProperties
52  // are actually meaningful on the main thread. When the properties are
53  // animating, the main thread may not have the same values that are used
54  // to draw.
55  bool opacity_is_animating;
56  bool screen_space_opacity_is_animating;
57  bool target_space_transform_is_animating;
58  bool screen_space_transform_is_animating;
59
60  // True if the layer can use LCD text.
61  bool can_use_lcd_text;
62
63  // True if the layer needs to be clipped by clip_rect.
64  bool is_clipped;
65
66  // The layer whose coordinate space this layer draws into. This can be
67  // either the same layer (draw_properties_.render_target == this) or an
68  // ancestor of this layer.
69  LayerType* render_target;
70
71  // The surface that this layer and its subtree would contribute to.
72  scoped_ptr<typename LayerType::RenderSurfaceType> render_surface;
73
74  // This rect is in the layer's content space.
75  gfx::Rect visible_content_rect;
76
77  // In target surface space, the rect that encloses the clipped, drawable
78  // content of the layer.
79  gfx::Rect drawable_content_rect;
80
81  // In target surface space, the original rect that clipped this layer. This
82  // value is used to avoid unnecessarily changing GL scissor state.
83  gfx::Rect clip_rect;
84
85  // The scale used to move between layer space and content space, and bounds
86  // of the space. One is always a function of the other, but which one
87  // depends on the layer type. For picture layers, this is an ideal scale,
88  // and not always the one used.
89  float contents_scale_x;
90  float contents_scale_y;
91  gfx::Size content_bounds;
92
93  // Does not include this layer itself, only its children and descendants.
94  int num_descendants_that_draw_content;
95
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  int num_unclipped_descendants;
99
100  // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
101  // present on it.
102  bool layer_or_descendant_has_copy_request;
103
104  // This is true if the layer has any direct child that has a scroll parent.
105  // This layer will not be the scroll parent in this case. This information
106  // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
107  // children have scroll parents, we will not need to recur out of order.
108  bool has_child_with_a_scroll_parent;
109
110  // This is true if the order (wrt to its siblings in the tree) in which the
111  // layer will be visited while computing draw properties has been determined.
112  bool sorted_for_recursion;
113
114  // If this layer is visited out of order, its contribution to the descendant
115  // and render surface layer lists will be put aside in a temporary list.
116  // These values will allow for an efficient reordering of these additions.
117  size_t index_of_first_descendants_addition;
118  size_t num_descendants_added;
119  size_t index_of_first_render_surface_layer_list_addition;
120  size_t num_render_surfaces_added;
121};
122
123}  // namespace cc
124
125#endif  // CC_LAYERS_DRAW_PROPERTIES_H_
126