GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / layers / draw_properties.h
blob930f7bf0e95a29119937d0ad85adff2193f2959e
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"
14 namespace cc {
16 // Container for properties that layers need to compute before they can be
17 // drawn.
18 template <typename LayerType>
19 struct CC_EXPORT DrawProperties {
20 DrawProperties()
21 : opacity(0.f),
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 is_clipped(false),
29 render_target(nullptr),
30 contents_scale_x(1.f),
31 contents_scale_y(1.f),
32 num_unclipped_descendants(0),
33 layer_or_descendant_has_copy_request(false),
34 layer_or_descendant_has_input_handler(false),
35 layer_or_descendant_is_drawn(false),
36 has_child_with_a_scroll_parent(false),
37 sorted_for_recursion(false),
38 visited(false),
39 index_of_first_descendants_addition(0),
40 num_descendants_added(0),
41 index_of_first_render_surface_layer_list_addition(0),
42 num_render_surfaces_added(0),
43 last_drawn_render_surface_layer_list_id(0),
44 ideal_contents_scale(0.f),
45 maximum_animation_contents_scale(0.f),
46 page_scale_factor(0.f),
47 device_scale_factor(0.f) {}
49 // Transforms objects from content space to target surface space, where
50 // this layer would be drawn.
51 gfx::Transform target_space_transform;
53 // Transforms objects from content space to screen space (viewport space).
54 gfx::Transform screen_space_transform;
56 // Known occlusion above the layer mapped to the content space of the layer.
57 Occlusion occlusion_in_content_space;
59 // DrawProperties::opacity may be different than LayerType::opacity,
60 // particularly in the case when a RenderSurface re-parents the layer's
61 // opacity, or when opacity is compounded by the hierarchy.
62 float opacity;
64 // DrawProperties::blend_mode may be different than LayerType::blend_mode,
65 // when a RenderSurface re-parents the layer's blend_mode.
66 SkXfermode::Mode blend_mode;
68 // xxx_is_animating flags are used to indicate whether the DrawProperties
69 // are actually meaningful on the main thread. When the properties are
70 // animating, the main thread may not have the same values that are used
71 // to draw.
72 bool opacity_is_animating;
73 bool screen_space_opacity_is_animating;
74 bool target_space_transform_is_animating;
75 bool screen_space_transform_is_animating;
77 // True if the layer can use LCD text.
78 bool can_use_lcd_text;
80 // True if the layer needs to be clipped by clip_rect.
81 bool is_clipped;
83 // The layer whose coordinate space this layer draws into. This can be
84 // either the same layer (draw_properties_.render_target == this) or an
85 // ancestor of this layer.
86 LayerType* render_target;
88 // This rect is in the layer's content space.
89 gfx::Rect visible_content_rect;
91 // In target surface space, the rect that encloses the clipped, drawable
92 // content of the layer.
93 gfx::Rect drawable_content_rect;
95 // In target surface space, the original rect that clipped this layer. This
96 // value is used to avoid unnecessarily changing GL scissor state.
97 gfx::Rect clip_rect;
99 // The scale used to move between layer space and content space, and bounds
100 // of the space. One is always a function of the other, but which one
101 // depends on the layer type. For picture layers, this is an ideal scale,
102 // and not always the one used.
103 float contents_scale_x;
104 float contents_scale_y;
105 gfx::Size content_bounds;
107 // Number of descendants with a clip parent that is our ancestor. NB - this
108 // does not include our clip children because they are clipped by us.
109 int num_unclipped_descendants;
111 // If true, the layer or some layer in its sub-tree has a CopyOutputRequest
112 // present on it.
113 bool layer_or_descendant_has_copy_request;
115 // If true, the layer or one of its descendants has a wheel or touch handler.
116 bool layer_or_descendant_has_input_handler;
118 // If true, the layer or one of its descendants is drawn
119 bool layer_or_descendant_is_drawn;
121 // This is true if the layer has any direct child that has a scroll parent.
122 // This layer will not be the scroll parent in this case. This information
123 // lets us avoid work in CalculateDrawPropertiesInternal -- if none of our
124 // children have scroll parents, we will not need to recur out of order.
125 bool has_child_with_a_scroll_parent;
127 // This is true if the order (wrt to its siblings in the tree) in which the
128 // layer will be visited while computing draw properties has been determined.
129 bool sorted_for_recursion;
131 // This is used to sanity-check CDP and ensure that we don't revisit a layer.
132 bool visited;
134 // If this layer is visited out of order, its contribution to the descendant
135 // and render surface layer lists will be put aside in a temporary list.
136 // These values will allow for an efficient reordering of these additions.
137 size_t index_of_first_descendants_addition;
138 size_t num_descendants_added;
139 size_t index_of_first_render_surface_layer_list_addition;
140 size_t num_render_surfaces_added;
142 // Each time we generate a new render surface layer list, an ID is used to
143 // identify it. |last_drawn_render_surface_layer_list_id| is set to the ID
144 // that marked the render surface layer list generation which last updated
145 // these draw properties and determined that this layer will draw itself.
146 // If these draw properties are not a part of the render surface layer list,
147 // or the layer doesn't contribute anything, then this ID will be either out
148 // of date or 0.
149 int last_drawn_render_surface_layer_list_id;
151 // The scale at which content for the layer should be rastered in order to be
152 // perfectly crisp.
153 float ideal_contents_scale;
155 // The maximum scale during the layers current animation at which content
156 // should be rastered at to be crisp.
157 float maximum_animation_contents_scale;
159 // The page scale factor that is applied to the layer. Since some layers may
160 // have page scale applied and others not, this may differ between layers.
161 float page_scale_factor;
163 // The device scale factor that is applied to the layer.
164 float device_scale_factor;
167 } // namespace cc
169 #endif // CC_LAYERS_DRAW_PROPERTIES_H_