• 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 "skia/ext/refptr.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/rect_f.h"
18 #include "ui/gfx/transform.h"
19 
20 namespace base {
21 class Value;
22 };
23 
24 namespace cc {
25 
26 class DrawQuad;
27 class CopyOutputRequest;
28 class SharedQuadState;
29 
30 // A list of DrawQuad objects, sorted internally in front-to-back order.
31 class QuadList : public ScopedPtrVector<DrawQuad> {
32  public:
33   typedef reverse_iterator BackToFrontIterator;
34   typedef const_reverse_iterator ConstBackToFrontIterator;
35 
BackToFrontBegin()36   inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
BackToFrontEnd()37   inline BackToFrontIterator BackToFrontEnd() { return rend(); }
BackToFrontBegin()38   inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
BackToFrontEnd()39   inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
40 };
41 
42 typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList;
43 
44 class CC_EXPORT RenderPass {
45  public:
46   struct Id {
47     int layer_id;
48     int index;
49 
IdId50     Id(int layer_id, int index) : layer_id(layer_id), index(index) {}
51     void* AsTracingId() const;
52 
53     bool operator==(const Id& other) const {
54       return layer_id == other.layer_id && index == other.index;
55     }
56     bool operator!=(const Id& other) const {
57       return !(*this == other);
58     }
59     bool operator<(const Id& other) const {
60       return layer_id < other.layer_id ||
61           (layer_id == other.layer_id && index < other.index);
62     }
63   };
64 
65   ~RenderPass();
66 
67   static scoped_ptr<RenderPass> Create();
68   static scoped_ptr<RenderPass> Create(size_t num_layers);
69 
70   // A shallow copy of the render pass, which does not include its quads or copy
71   // requests.
72   scoped_ptr<RenderPass> Copy(Id new_id) const;
73 
74   // A deep copy of the render passes in the list including the quads.
75   static void CopyAll(const ScopedPtrVector<RenderPass>& in,
76                       ScopedPtrVector<RenderPass>* out);
77 
78   void SetNew(Id id,
79               gfx::Rect output_rect,
80               gfx::RectF damage_rect,
81               const gfx::Transform& transform_to_root_target);
82 
83   void SetAll(Id id,
84               gfx::Rect output_rect,
85               gfx::RectF damage_rect,
86               const gfx::Transform& transform_to_root_target,
87               bool has_transparent_background);
88 
89   scoped_ptr<base::Value> AsValue() const;
90 
91   // Uniquely identifies the render pass in the compositor's current frame.
92   Id id;
93 
94   // These are in the space of the render pass' physical pixels.
95   gfx::Rect output_rect;
96   gfx::RectF damage_rect;
97 
98   // Transforms from the origin of the |output_rect| to the origin of the root
99   // render pass' |output_rect|.
100   gfx::Transform transform_to_root_target;
101 
102   // If false, the pixels in the render pass' texture are all opaque.
103   bool has_transparent_background;
104 
105   // If non-empty, the renderer should produce a copy of the render pass'
106   // contents as a bitmap, and give a copy of the bitmap to each callback in
107   // this list. This property should not be serialized between compositors, as
108   // it only makes sense in the root compositor.
109   ScopedPtrVector<CopyOutputRequest> copy_requests;
110 
111   QuadList quad_list;
112   SharedQuadStateList shared_quad_state_list;
113 
114  protected:
115   explicit RenderPass(size_t num_layers);
116   RenderPass();
117 
118  private:
119   DISALLOW_COPY_AND_ASSIGN(RenderPass);
120 };
121 
122 }  // namespace cc
123 
124 namespace BASE_HASH_NAMESPACE {
125 #if defined(COMPILER_MSVC)
hash_value(const cc::RenderPass::Id & key)126 inline size_t hash_value(const cc::RenderPass::Id& key) {
127   return base::HashPair(key.layer_id, key.index);
128 }
129 #elif defined(COMPILER_GCC)
130 template<>
131 struct hash<cc::RenderPass::Id> {
132   size_t operator()(cc::RenderPass::Id key) const {
133     return base::HashPair(key.layer_id, key.index);
134   }
135 };
136 #else
137 #error define a hash function for your compiler
138 #endif  // COMPILER
139 }  // namespace BASE_HASH_NAMESPACE
140 
141 namespace cc {
142 typedef ScopedPtrVector<RenderPass> RenderPassList;
143 typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap;
144 }  // namespace cc
145 
146 #endif  // CC_QUADS_RENDER_PASS_H_
147