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_QUADS_RENDER_PASS_H_
6 #define CC_QUADS_RENDER_PASS_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/containers/hash_tables.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/base/scoped_ptr_vector.h"
15 #include "cc/quads/list_container.h"
16 #include "cc/quads/render_pass_id.h"
17 #include "skia/ext/refptr.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/transform.h"
23 namespace trace_event
{
32 class CopyOutputRequest
;
33 class RenderPassDrawQuad
;
34 class SharedQuadState
;
36 // A list of DrawQuad objects, sorted internally in front-to-back order.
37 class QuadList
: public ListContainer
<DrawQuad
> {
39 explicit QuadList(size_t default_size_to_reserve
);
41 typedef QuadList::ReverseIterator BackToFrontIterator
;
42 typedef QuadList::ConstReverseIterator ConstBackToFrontIterator
;
44 inline BackToFrontIterator
BackToFrontBegin() { return rbegin(); }
45 inline BackToFrontIterator
BackToFrontEnd() { return rend(); }
46 inline ConstBackToFrontIterator
BackToFrontBegin() const { return rbegin(); }
47 inline ConstBackToFrontIterator
BackToFrontEnd() const { return rend(); }
50 typedef ListContainer
<SharedQuadState
> SharedQuadStateList
;
52 class CC_EXPORT RenderPass
{
56 static scoped_ptr
<RenderPass
> Create();
57 static scoped_ptr
<RenderPass
> Create(size_t num_layers
);
58 static scoped_ptr
<RenderPass
> Create(size_t shared_quad_state_list_size
,
59 size_t quad_list_size
);
61 // A shallow copy of the render pass, which does not include its quads or copy
63 scoped_ptr
<RenderPass
> Copy(RenderPassId new_id
) const;
65 // A deep copy of the render passes in the list including the quads.
66 static void CopyAll(const ScopedPtrVector
<RenderPass
>& in
,
67 ScopedPtrVector
<RenderPass
>* out
);
69 void SetNew(RenderPassId id
,
70 const gfx::Rect
& output_rect
,
71 const gfx::Rect
& damage_rect
,
72 const gfx::Transform
& transform_to_root_target
);
74 void SetAll(RenderPassId id
,
75 const gfx::Rect
& output_rect
,
76 const gfx::Rect
& damage_rect
,
77 const gfx::Transform
& transform_to_root_target
,
78 bool has_transparent_background
);
80 void AsValueInto(base::trace_event::TracedValue
* dict
) const;
82 SharedQuadState
* CreateAndAppendSharedQuadState();
84 template <typename DrawQuadType
>
85 DrawQuadType
* CreateAndAppendDrawQuad() {
86 return quad_list
.AllocateAndConstruct
<DrawQuadType
>();
89 RenderPassDrawQuad
* CopyFromAndAppendRenderPassDrawQuad(
90 const RenderPassDrawQuad
* quad
,
91 const SharedQuadState
* shared_quad_state
,
92 RenderPassId render_pass_id
);
93 DrawQuad
* CopyFromAndAppendDrawQuad(const DrawQuad
* quad
,
94 const SharedQuadState
* shared_quad_state
);
96 // Uniquely identifies the render pass in the compositor's current frame.
99 // These are in the space of the render pass' physical pixels.
100 gfx::Rect output_rect
;
101 gfx::Rect damage_rect
;
103 // Transforms from the origin of the |output_rect| to the origin of the root
104 // render pass' |output_rect|.
105 gfx::Transform transform_to_root_target
;
107 // If false, the pixels in the render pass' texture are all opaque.
108 bool has_transparent_background
;
110 // If non-empty, the renderer should produce a copy of the render pass'
111 // contents as a bitmap, and give a copy of the bitmap to each callback in
112 // this list. This property should not be serialized between compositors, as
113 // it only makes sense in the root compositor.
114 ScopedPtrVector
<CopyOutputRequest
> copy_requests
;
117 SharedQuadStateList shared_quad_state_list
;
120 explicit RenderPass(size_t num_layers
);
122 RenderPass(size_t shared_quad_state_list_size
, size_t quad_list_size
);
125 template <typename DrawQuadType
>
126 DrawQuadType
* CopyFromAndAppendTypedDrawQuad(const DrawQuad
* quad
) {
127 return quad_list
.AllocateAndCopyFrom(DrawQuadType::MaterialCast(quad
));
130 DISALLOW_COPY_AND_ASSIGN(RenderPass
);
135 namespace BASE_HASH_NAMESPACE
{
137 struct hash
<cc::RenderPassId
> {
138 size_t operator()(cc::RenderPassId key
) const {
139 return base::HashPair(key
.layer_id
, key
.index
);
142 } // namespace BASE_HASH_NAMESPACE
145 typedef ScopedPtrVector
<RenderPass
> RenderPassList
;
146 typedef base::hash_map
<RenderPassId
, RenderPass
*> RenderPassIdHashMap
;
149 #endif // CC_QUADS_RENDER_PASS_H_