Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / cc / quads / render_pass.h
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.
4
5 #ifndef CC_QUADS_RENDER_PASS_H_
6 #define CC_QUADS_RENDER_PASS_H_
7
8 #include <utility>
9
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"
21
22 namespace base {
23 namespace debug {
24 class TracedValue;
25 }
26 class Value;
27 };
28
29 namespace cc {
30
31 class DrawQuad;
32 class CopyOutputRequest;
33 class RenderPassDrawQuad;
34 class SharedQuadState;
35
36 // A list of DrawQuad objects, sorted internally in front-to-back order.
37 class QuadList : public ListContainer<DrawQuad> {
38  public:
39   explicit QuadList(size_t default_size_to_reserve);
40
41   typedef QuadList::ReverseIterator BackToFrontIterator;
42   typedef QuadList::ConstReverseIterator ConstBackToFrontIterator;
43
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(); }
48 };
49
50 typedef ListContainer<SharedQuadState> SharedQuadStateList;
51
52 class CC_EXPORT RenderPass {
53  public:
54   ~RenderPass();
55
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);
60
61   // A shallow copy of the render pass, which does not include its quads or copy
62   // requests.
63   scoped_ptr<RenderPass> Copy(RenderPassId new_id) const;
64
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);
68
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);
73
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);
79
80   void AsValueInto(base::debug::TracedValue* dict) const;
81
82   SharedQuadState* CreateAndAppendSharedQuadState();
83
84   template <typename DrawQuadType>
85   DrawQuadType* CreateAndAppendDrawQuad() {
86     return quad_list.AllocateAndConstruct<DrawQuadType>();
87   }
88
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);
95
96   // Uniquely identifies the render pass in the compositor's current frame.
97   RenderPassId id;
98
99   // These are in the space of the render pass' physical pixels.
100   gfx::Rect output_rect;
101   gfx::Rect damage_rect;
102
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;
106
107   // If false, the pixels in the render pass' texture are all opaque.
108   bool has_transparent_background;
109
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;
115
116   QuadList quad_list;
117   SharedQuadStateList shared_quad_state_list;
118
119  protected:
120   explicit RenderPass(size_t num_layers);
121   RenderPass();
122   RenderPass(size_t shared_quad_state_list_size, size_t quad_list_size);
123
124  private:
125   template <typename DrawQuadType>
126   DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) {
127     return quad_list.AllocateAndCopyFrom(DrawQuadType::MaterialCast(quad));
128   }
129
130   DISALLOW_COPY_AND_ASSIGN(RenderPass);
131 };
132
133 }  // namespace cc
134
135 namespace BASE_HASH_NAMESPACE {
136 template <>
137 struct hash<cc::RenderPassId> {
138   size_t operator()(cc::RenderPassId key) const {
139     return base::HashPair(key.layer_id, key.index);
140   }
141 };
142 }  // namespace BASE_HASH_NAMESPACE
143
144 namespace cc {
145 typedef ScopedPtrVector<RenderPass> RenderPassList;
146 typedef base::hash_map<RenderPassId, RenderPass*> RenderPassIdHashMap;
147 }  // namespace cc
148
149 #endif  // CC_QUADS_RENDER_PASS_H_