Revert 284234 "Pass signin_scoped_device_id to DeviceInfoSpecifics."
[chromium-blink-merge.git] / cc / quads / render_pass.h
blob3032f050d4c2396e3898e48f3fcae410e217c36e
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_
8 #include <utility>
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"
20 namespace base {
21 class Value;
24 namespace cc {
26 class DrawQuad;
27 class RenderPassDrawQuad;
28 class CopyOutputRequest;
29 class SharedQuadState;
31 // A list of DrawQuad objects, sorted internally in front-to-back order.
32 class QuadList : public ScopedPtrVector<DrawQuad> {
33 public:
34 typedef reverse_iterator BackToFrontIterator;
35 typedef const_reverse_iterator ConstBackToFrontIterator;
37 inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
38 inline BackToFrontIterator BackToFrontEnd() { return rend(); }
39 inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
40 inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
43 typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList;
45 class CC_EXPORT RenderPass {
46 public:
47 struct Id {
48 int layer_id;
49 int index;
51 Id(int layer_id, int index) : layer_id(layer_id), index(index) {}
52 void* AsTracingId() const;
54 bool operator==(const Id& other) const {
55 return layer_id == other.layer_id && index == other.index;
57 bool operator!=(const Id& other) const {
58 return !(*this == other);
60 bool operator<(const Id& other) const {
61 return layer_id < other.layer_id ||
62 (layer_id == other.layer_id && index < other.index);
66 ~RenderPass();
68 static scoped_ptr<RenderPass> Create();
69 static scoped_ptr<RenderPass> Create(size_t num_layers);
71 // A shallow copy of the render pass, which does not include its quads or copy
72 // requests.
73 scoped_ptr<RenderPass> Copy(Id new_id) const;
75 // A deep copy of the render passes in the list including the quads.
76 static void CopyAll(const ScopedPtrVector<RenderPass>& in,
77 ScopedPtrVector<RenderPass>* out);
79 void SetNew(Id id,
80 const gfx::Rect& output_rect,
81 const gfx::Rect& damage_rect,
82 const gfx::Transform& transform_to_root_target);
84 void SetAll(Id id,
85 const gfx::Rect& output_rect,
86 const gfx::Rect& damage_rect,
87 const gfx::Transform& transform_to_root_target,
88 bool has_transparent_background);
90 scoped_ptr<base::Value> AsValue() const;
92 SharedQuadState* CreateAndAppendSharedQuadState();
93 template <typename DrawQuadType>
94 DrawQuadType* CreateAndAppendDrawQuad() {
95 scoped_ptr<DrawQuadType> draw_quad = make_scoped_ptr(new DrawQuadType);
96 quad_list.push_back(draw_quad.template PassAs<DrawQuad>());
97 return static_cast<DrawQuadType*>(quad_list.back());
100 RenderPassDrawQuad* CopyFromAndAppendRenderPassDrawQuad(
101 const RenderPassDrawQuad* quad,
102 const SharedQuadState* shared_quad_state,
103 RenderPass::Id render_pass_id);
104 DrawQuad* CopyFromAndAppendDrawQuad(const DrawQuad* quad,
105 const SharedQuadState* shared_quad_state);
107 // Uniquely identifies the render pass in the compositor's current frame.
108 Id id;
110 // These are in the space of the render pass' physical pixels.
111 gfx::Rect output_rect;
112 gfx::Rect damage_rect;
114 // Transforms from the origin of the |output_rect| to the origin of the root
115 // render pass' |output_rect|.
116 gfx::Transform transform_to_root_target;
118 // If false, the pixels in the render pass' texture are all opaque.
119 bool has_transparent_background;
121 // If non-empty, the renderer should produce a copy of the render pass'
122 // contents as a bitmap, and give a copy of the bitmap to each callback in
123 // this list. This property should not be serialized between compositors, as
124 // it only makes sense in the root compositor.
125 ScopedPtrVector<CopyOutputRequest> copy_requests;
127 QuadList quad_list;
128 SharedQuadStateList shared_quad_state_list;
130 protected:
131 explicit RenderPass(size_t num_layers);
132 RenderPass();
134 private:
135 template <typename DrawQuadType>
136 DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) {
137 scoped_ptr<DrawQuadType> draw_quad =
138 make_scoped_ptr(new DrawQuadType(*DrawQuadType::MaterialCast(quad)));
139 quad_list.push_back(draw_quad.template PassAs<DrawQuad>());
140 return static_cast<DrawQuadType*>(quad_list.back());
143 DISALLOW_COPY_AND_ASSIGN(RenderPass);
146 } // namespace cc
148 namespace BASE_HASH_NAMESPACE {
149 #if defined(COMPILER_MSVC)
150 inline size_t hash_value(const cc::RenderPass::Id& key) {
151 return base::HashPair(key.layer_id, key.index);
153 #elif defined(COMPILER_GCC)
154 template<>
155 struct hash<cc::RenderPass::Id> {
156 size_t operator()(cc::RenderPass::Id key) const {
157 return base::HashPair(key.layer_id, key.index);
160 #else
161 #error define a hash function for your compiler
162 #endif // COMPILER
163 } // namespace BASE_HASH_NAMESPACE
165 namespace cc {
166 typedef ScopedPtrVector<RenderPass> RenderPassList;
167 typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap;
168 } // namespace cc
170 #endif // CC_QUADS_RENDER_PASS_H_