1 // Copyright 2011 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_RENDER_SURFACE_IMPL_H_
6 #define CC_LAYERS_RENDER_SURFACE_IMPL_H_
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/layers/layer_lists.h"
15 #include "cc/quads/render_pass.h"
16 #include "cc/quads/shared_quad_state.h"
17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/rect_f.h"
19 #include "ui/gfx/transform.h"
24 class DelegatedRendererLayerImpl
;
25 template <typename LayerType
>
26 class OcclusionTracker
;
29 template <typename LayerType
>
32 struct AppendQuadsData
;
34 class CC_EXPORT RenderSurfaceImpl
{
36 explicit RenderSurfaceImpl(LayerImpl
* owning_layer
);
37 virtual ~RenderSurfaceImpl();
39 gfx::PointF
ContentRectCenter() const {
40 return gfx::RectF(content_rect_
).CenterPoint();
43 // Returns the rect that encloses the RenderSurfaceImpl including any
45 gfx::RectF
DrawableContentRect() const;
47 void SetDrawOpacity(float opacity
) { draw_opacity_
= opacity
; }
48 float draw_opacity() const { return draw_opacity_
; }
50 void SetNearestOcclusionImmuneAncestor(RenderSurfaceImpl
* surface
) {
51 nearest_occlusion_immune_ancestor_
= surface
;
53 const RenderSurfaceImpl
* nearest_occlusion_immune_ancestor() const {
54 return nearest_occlusion_immune_ancestor_
;
57 void SetDrawOpacityIsAnimating(bool draw_opacity_is_animating
) {
58 draw_opacity_is_animating_
= draw_opacity_is_animating
;
60 bool draw_opacity_is_animating() const { return draw_opacity_is_animating_
; }
62 void SetDrawTransform(const gfx::Transform
& draw_transform
) {
63 draw_transform_
= draw_transform
;
65 const gfx::Transform
& draw_transform() const { return draw_transform_
; }
67 void SetScreenSpaceTransform(const gfx::Transform
& screen_space_transform
) {
68 screen_space_transform_
= screen_space_transform
;
70 const gfx::Transform
& screen_space_transform() const {
71 return screen_space_transform_
;
74 void SetReplicaDrawTransform(const gfx::Transform
& replica_draw_transform
) {
75 replica_draw_transform_
= replica_draw_transform
;
77 const gfx::Transform
& replica_draw_transform() const {
78 return replica_draw_transform_
;
81 void SetReplicaScreenSpaceTransform(
82 const gfx::Transform
& replica_screen_space_transform
) {
83 replica_screen_space_transform_
= replica_screen_space_transform
;
85 const gfx::Transform
& replica_screen_space_transform() const {
86 return replica_screen_space_transform_
;
89 void SetTargetSurfaceTransformsAreAnimating(bool animating
) {
90 target_surface_transforms_are_animating_
= animating
;
92 bool target_surface_transforms_are_animating() const {
93 return target_surface_transforms_are_animating_
;
95 void SetScreenSpaceTransformsAreAnimating(bool animating
) {
96 screen_space_transforms_are_animating_
= animating
;
98 bool screen_space_transforms_are_animating() const {
99 return screen_space_transforms_are_animating_
;
102 void SetIsClipped(bool is_clipped
) { is_clipped_
= is_clipped
; }
103 bool is_clipped() const { return is_clipped_
; }
105 void SetClipRect(const gfx::Rect
& clip_rect
);
106 gfx::Rect
clip_rect() const { return clip_rect_
; }
108 // When false, the RenderSurface does not contribute to another target
109 // RenderSurface that is being drawn for the current frame. It could still be
110 // drawn to as a target, but its output will not be a part of any other
112 bool contributes_to_drawn_surface() const {
113 return contributes_to_drawn_surface_
;
115 void set_contributes_to_drawn_surface(bool contributes_to_drawn_surface
) {
116 contributes_to_drawn_surface_
= contributes_to_drawn_surface
;
119 bool ContentsChanged() const;
121 void SetContentRect(const gfx::Rect
& content_rect
);
122 gfx::Rect
content_rect() const { return content_rect_
; }
124 LayerImplList
& layer_list() { return layer_list_
; }
125 void AddContributingDelegatedRenderPassLayer(LayerImpl
* layer
);
126 void ClearLayerLists();
128 int OwningLayerId() const;
130 void ResetPropertyChangedFlag() { surface_property_changed_
= false; }
131 bool SurfacePropertyChanged() const;
132 bool SurfacePropertyChangedOnlyFromDescendant() const;
134 DamageTracker
* damage_tracker() const { return damage_tracker_
.get(); }
136 RenderPass::Id
RenderPassId();
138 void AppendRenderPasses(RenderPassSink
* pass_sink
);
139 void AppendQuads(RenderPass
* render_pass
,
140 const OcclusionTracker
<LayerImpl
>& occlusion_tracker
,
141 AppendQuadsData
* append_quads_data
,
143 RenderPass::Id render_pass_id
);
146 LayerImpl
* owning_layer_
;
148 // Uses this surface's space.
149 gfx::Rect content_rect_
;
150 bool surface_property_changed_
: 1;
151 bool draw_opacity_is_animating_
: 1;
152 bool target_surface_transforms_are_animating_
: 1;
153 bool screen_space_transforms_are_animating_
: 1;
155 bool is_clipped_
: 1;
156 bool contributes_to_drawn_surface_
: 1;
159 gfx::Transform draw_transform_
;
160 gfx::Transform screen_space_transform_
;
161 gfx::Transform replica_draw_transform_
;
162 gfx::Transform replica_screen_space_transform_
;
164 // Uses the space of the surface's target surface.
165 gfx::Rect clip_rect_
;
167 LayerImplList layer_list_
;
168 std::vector
<DelegatedRendererLayerImpl
*>
169 contributing_delegated_render_pass_layer_list_
;
171 // The nearest ancestor target surface that will contain the contents of this
172 // surface, and that ignores outside occlusion. This can point to itself.
173 RenderSurfaceImpl
* nearest_occlusion_immune_ancestor_
;
175 scoped_ptr
<DamageTracker
> damage_tracker_
;
177 // For LayerIteratorActions
178 int target_render_surface_layer_index_history_
;
179 int current_layer_index_history_
;
181 friend class LayerIterator
<LayerImpl
>;
183 DISALLOW_COPY_AND_ASSIGN(RenderSurfaceImpl
);
187 #endif // CC_LAYERS_RENDER_SURFACE_IMPL_H_