Provide core API permissions to extensions_unittests
[chromium-blink-merge.git] / cc / quads / render_pass.h
blob8d4114206351f01d6933e4e35650f93334c16d97
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 namespace debug {
22 class TracedValue;
24 class Value;
27 namespace cc {
29 class DrawQuad;
30 class RenderPassDrawQuad;
31 class CopyOutputRequest;
32 class SharedQuadState;
34 // A list of DrawQuad objects, sorted internally in front-to-back order.
35 class QuadList : public ScopedPtrVector<DrawQuad> {
36 public:
37 typedef reverse_iterator BackToFrontIterator;
38 typedef const_reverse_iterator ConstBackToFrontIterator;
40 inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
41 inline BackToFrontIterator BackToFrontEnd() { return rend(); }
42 inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
43 inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
46 typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList;
48 class CC_EXPORT RenderPass {
49 public:
50 struct Id {
51 int layer_id;
52 int index;
54 Id(int layer_id, int index) : layer_id(layer_id), index(index) {}
55 void* AsTracingId() const;
57 bool operator==(const Id& other) const {
58 return layer_id == other.layer_id && index == other.index;
60 bool operator!=(const Id& other) const {
61 return !(*this == other);
63 bool operator<(const Id& other) const {
64 return layer_id < other.layer_id ||
65 (layer_id == other.layer_id && index < other.index);
69 ~RenderPass();
71 static scoped_ptr<RenderPass> Create();
72 static scoped_ptr<RenderPass> Create(size_t num_layers);
74 // A shallow copy of the render pass, which does not include its quads or copy
75 // requests.
76 scoped_ptr<RenderPass> Copy(Id new_id) const;
78 // A deep copy of the render passes in the list including the quads.
79 static void CopyAll(const ScopedPtrVector<RenderPass>& in,
80 ScopedPtrVector<RenderPass>* out);
82 void SetNew(Id id,
83 const gfx::Rect& output_rect,
84 const gfx::Rect& damage_rect,
85 const gfx::Transform& transform_to_root_target);
87 void SetAll(Id id,
88 const gfx::Rect& output_rect,
89 const gfx::Rect& damage_rect,
90 const gfx::Transform& transform_to_root_target,
91 bool has_transparent_background);
93 void AsValueInto(base::debug::TracedValue* dict) const;
95 SharedQuadState* CreateAndAppendSharedQuadState();
96 template <typename DrawQuadType>
97 DrawQuadType* CreateAndAppendDrawQuad() {
98 scoped_ptr<DrawQuadType> draw_quad = make_scoped_ptr(new DrawQuadType);
99 quad_list.push_back(draw_quad.template PassAs<DrawQuad>());
100 return static_cast<DrawQuadType*>(quad_list.back());
103 RenderPassDrawQuad* CopyFromAndAppendRenderPassDrawQuad(
104 const RenderPassDrawQuad* quad,
105 const SharedQuadState* shared_quad_state,
106 RenderPass::Id render_pass_id);
107 DrawQuad* CopyFromAndAppendDrawQuad(const DrawQuad* quad,
108 const SharedQuadState* shared_quad_state);
110 // Uniquely identifies the render pass in the compositor's current frame.
111 Id id;
113 // These are in the space of the render pass' physical pixels.
114 gfx::Rect output_rect;
115 gfx::Rect damage_rect;
117 // Transforms from the origin of the |output_rect| to the origin of the root
118 // render pass' |output_rect|.
119 gfx::Transform transform_to_root_target;
121 // If false, the pixels in the render pass' texture are all opaque.
122 bool has_transparent_background;
124 // If non-empty, the renderer should produce a copy of the render pass'
125 // contents as a bitmap, and give a copy of the bitmap to each callback in
126 // this list. This property should not be serialized between compositors, as
127 // it only makes sense in the root compositor.
128 ScopedPtrVector<CopyOutputRequest> copy_requests;
130 QuadList quad_list;
131 SharedQuadStateList shared_quad_state_list;
133 protected:
134 explicit RenderPass(size_t num_layers);
135 RenderPass();
137 private:
138 template <typename DrawQuadType>
139 DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) {
140 scoped_ptr<DrawQuadType> draw_quad =
141 make_scoped_ptr(new DrawQuadType(*DrawQuadType::MaterialCast(quad)));
142 quad_list.push_back(draw_quad.template PassAs<DrawQuad>());
143 return static_cast<DrawQuadType*>(quad_list.back());
146 DISALLOW_COPY_AND_ASSIGN(RenderPass);
149 } // namespace cc
151 namespace BASE_HASH_NAMESPACE {
152 #if defined(COMPILER_MSVC)
153 inline size_t hash_value(const cc::RenderPass::Id& key) {
154 return base::HashPair(key.layer_id, key.index);
156 #elif defined(COMPILER_GCC)
157 template<>
158 struct hash<cc::RenderPass::Id> {
159 size_t operator()(cc::RenderPass::Id key) const {
160 return base::HashPair(key.layer_id, key.index);
163 #else
164 #error define a hash function for your compiler
165 #endif // COMPILER
166 } // namespace BASE_HASH_NAMESPACE
168 namespace cc {
169 typedef ScopedPtrVector<RenderPass> RenderPassList;
170 typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap;
171 } // namespace cc
173 #endif // CC_QUADS_RENDER_PASS_H_