• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/rect.h"
19 #include "ui/gfx/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 
BackToFrontBegin()44   inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
BackToFrontEnd()45   inline BackToFrontIterator BackToFrontEnd() { return rend(); }
BackToFrontBegin()46   inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
BackToFrontEnd()47   inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
48 };
49 
50 typedef ScopedPtrVector<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 
59   // A shallow copy of the render pass, which does not include its quads or copy
60   // requests.
61   scoped_ptr<RenderPass> Copy(RenderPassId new_id) const;
62 
63   // A deep copy of the render passes in the list including the quads.
64   static void CopyAll(const ScopedPtrVector<RenderPass>& in,
65                       ScopedPtrVector<RenderPass>* out);
66 
67   void SetNew(RenderPassId id,
68               const gfx::Rect& output_rect,
69               const gfx::Rect& damage_rect,
70               const gfx::Transform& transform_to_root_target);
71 
72   void SetAll(RenderPassId id,
73               const gfx::Rect& output_rect,
74               const gfx::Rect& damage_rect,
75               const gfx::Transform& transform_to_root_target,
76               bool has_transparent_background);
77 
78   void AsValueInto(base::debug::TracedValue* dict) const;
79 
80   SharedQuadState* CreateAndAppendSharedQuadState();
81 
82   template <typename DrawQuadType>
CreateAndAppendDrawQuad()83   DrawQuadType* CreateAndAppendDrawQuad() {
84     return quad_list.AllocateAndConstruct<DrawQuadType>();
85   }
86 
87   RenderPassDrawQuad* CopyFromAndAppendRenderPassDrawQuad(
88       const RenderPassDrawQuad* quad,
89       const SharedQuadState* shared_quad_state,
90       RenderPassId render_pass_id);
91   DrawQuad* CopyFromAndAppendDrawQuad(const DrawQuad* quad,
92                                       const SharedQuadState* shared_quad_state);
93 
94   // Uniquely identifies the render pass in the compositor's current frame.
95   RenderPassId id;
96 
97   // These are in the space of the render pass' physical pixels.
98   gfx::Rect output_rect;
99   gfx::Rect damage_rect;
100 
101   // Transforms from the origin of the |output_rect| to the origin of the root
102   // render pass' |output_rect|.
103   gfx::Transform transform_to_root_target;
104 
105   // If false, the pixels in the render pass' texture are all opaque.
106   bool has_transparent_background;
107 
108   // If non-empty, the renderer should produce a copy of the render pass'
109   // contents as a bitmap, and give a copy of the bitmap to each callback in
110   // this list. This property should not be serialized between compositors, as
111   // it only makes sense in the root compositor.
112   ScopedPtrVector<CopyOutputRequest> copy_requests;
113 
114   QuadList quad_list;
115   SharedQuadStateList shared_quad_state_list;
116 
117  protected:
118   explicit RenderPass(size_t num_layers);
119   RenderPass();
120 
121  private:
122   template <typename DrawQuadType>
CopyFromAndAppendTypedDrawQuad(const DrawQuad * quad)123   DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) {
124     return quad_list.AllocateAndCopyFrom(DrawQuadType::MaterialCast(quad));
125   }
126 
127   DISALLOW_COPY_AND_ASSIGN(RenderPass);
128 };
129 
130 }  // namespace cc
131 
132 namespace BASE_HASH_NAMESPACE {
133 #if defined(COMPILER_MSVC)
hash_value(const cc::RenderPassId & key)134 inline size_t hash_value(const cc::RenderPassId& key) {
135   return base::HashPair(key.layer_id, key.index);
136 }
137 #elif defined(COMPILER_GCC)
138 template <>
139 struct hash<cc::RenderPassId> {
140   size_t operator()(cc::RenderPassId key) const {
141     return base::HashPair(key.layer_id, key.index);
142   }
143 };
144 #else
145 #error define a hash function for your compiler
146 #endif  // COMPILER
147 }  // namespace BASE_HASH_NAMESPACE
148 
149 namespace cc {
150 typedef ScopedPtrVector<RenderPass> RenderPassList;
151 typedef base::hash_map<RenderPassId, RenderPass*> RenderPassIdHashMap;
152 }  // namespace cc
153 
154 #endif  // CC_QUADS_RENDER_PASS_H_
155