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 "cc/trees/occlusion.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/transform.h"
25 class DelegatedRendererLayerImpl
;
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 SkColor
GetDebugBorderColor() const;
58 SkColor
GetReplicaDebugBorderColor() const;
60 float GetDebugBorderWidth() const;
61 float GetReplicaDebugBorderWidth() const;
63 void SetDrawTransform(const gfx::Transform
& draw_transform
) {
64 draw_transform_
= draw_transform
;
66 const gfx::Transform
& draw_transform() const { return draw_transform_
; }
68 void SetScreenSpaceTransform(const gfx::Transform
& screen_space_transform
) {
69 screen_space_transform_
= screen_space_transform
;
71 const gfx::Transform
& screen_space_transform() const {
72 return screen_space_transform_
;
75 void SetReplicaDrawTransform(const gfx::Transform
& replica_draw_transform
) {
76 replica_draw_transform_
= replica_draw_transform
;
78 const gfx::Transform
& replica_draw_transform() const {
79 return replica_draw_transform_
;
82 void SetReplicaScreenSpaceTransform(
83 const gfx::Transform
& replica_screen_space_transform
) {
84 replica_screen_space_transform_
= replica_screen_space_transform
;
86 const gfx::Transform
& replica_screen_space_transform() const {
87 return replica_screen_space_transform_
;
90 void SetIsClipped(bool is_clipped
) { is_clipped_
= is_clipped
; }
91 bool is_clipped() const { return is_clipped_
; }
93 void SetClipRect(const gfx::Rect
& clip_rect
);
94 gfx::Rect
clip_rect() const { return clip_rect_
; }
96 // When false, the RenderSurface does not contribute to another target
97 // RenderSurface that is being drawn for the current frame. It could still be
98 // drawn to as a target, but its output will not be a part of any other
100 bool contributes_to_drawn_surface() const {
101 return contributes_to_drawn_surface_
;
103 void set_contributes_to_drawn_surface(bool contributes_to_drawn_surface
) {
104 contributes_to_drawn_surface_
= contributes_to_drawn_surface
;
107 void SetContentRect(const gfx::Rect
& content_rect
);
108 gfx::Rect
content_rect() const { return content_rect_
; }
110 const Occlusion
& occlusion_in_content_space() const {
111 return occlusion_in_content_space_
;
113 void set_occlusion_in_content_space(const Occlusion
& occlusion
) {
114 occlusion_in_content_space_
= occlusion
;
117 LayerImplList
& layer_list() { return layer_list_
; }
118 void AddContributingDelegatedRenderPassLayer(LayerImpl
* layer
);
119 void ClearLayerLists();
121 int OwningLayerId() const;
123 void ResetPropertyChangedFlag() { surface_property_changed_
= false; }
124 bool SurfacePropertyChanged() const;
125 bool SurfacePropertyChangedOnlyFromDescendant() const;
127 DamageTracker
* damage_tracker() const { return damage_tracker_
.get(); }
129 RenderPassId
GetRenderPassId();
131 void AppendRenderPasses(RenderPassSink
* pass_sink
);
132 void AppendQuads(RenderPass
* render_pass
,
133 const gfx::Transform
& draw_transform
,
134 const Occlusion
& occlusion_in_content_space
,
135 SkColor debug_border_color
,
136 float debug_border_width
,
137 LayerImpl
* mask_layer
,
138 AppendQuadsData
* append_quads_data
,
139 RenderPassId render_pass_id
);
141 int TransformTreeIndex() const;
144 LayerImpl
* owning_layer_
;
146 // Uses this surface's space.
147 gfx::Rect content_rect_
;
148 bool surface_property_changed_
: 1;
149 bool target_surface_transforms_are_animating_
: 1;
150 bool screen_space_transforms_are_animating_
: 1;
152 bool is_clipped_
: 1;
153 bool contributes_to_drawn_surface_
: 1;
156 gfx::Transform draw_transform_
;
157 gfx::Transform screen_space_transform_
;
158 gfx::Transform replica_draw_transform_
;
159 gfx::Transform replica_screen_space_transform_
;
161 // Uses the space of the surface's target surface.
162 gfx::Rect clip_rect_
;
164 LayerImplList layer_list_
;
165 std::vector
<DelegatedRendererLayerImpl
*>
166 contributing_delegated_render_pass_layer_list_
;
167 Occlusion occlusion_in_content_space_
;
169 // The nearest ancestor target surface that will contain the contents of this
170 // surface, and that ignores outside occlusion. This can point to itself.
171 RenderSurfaceImpl
* nearest_occlusion_immune_ancestor_
;
173 scoped_ptr
<DamageTracker
> damage_tracker_
;
175 // For LayerIteratorActions
176 int target_render_surface_layer_index_history_
;
177 size_t current_layer_index_history_
;
179 friend class LayerIterator
;
181 DISALLOW_COPY_AND_ASSIGN(RenderSurfaceImpl
);
185 #endif // CC_LAYERS_RENDER_SURFACE_IMPL_H_