blob: 3d5a37cb78d9c1e4fbf1ee6c8785ae71e0e64b13 [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01008#include <utility>
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00009
10#include "base/basictypes.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010011#include "base/callback.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010012#include "base/containers/hash_tables.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013#include "cc/base/cc_export.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "cc/base/scoped_ptr_hash_map.h"
15#include "cc/base/scoped_ptr_vector.h"
16#include "skia/ext/refptr.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000017#include "third_party/skia/include/core/SkColor.h"
18#include "third_party/skia/include/core/SkImageFilter.h"
19#include "ui/gfx/rect.h"
20#include "ui/gfx/rect_f.h"
21#include "ui/gfx/transform.h"
22
23namespace cc {
24
25class DrawQuad;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010026class CopyOutputRequest;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000027class SharedQuadState;
28
29// A list of DrawQuad objects, sorted internally in front-to-back order.
30class QuadList : public ScopedPtrVector<DrawQuad> {
31 public:
32 typedef reverse_iterator BackToFrontIterator;
33 typedef const_reverse_iterator ConstBackToFrontIterator;
34
35 inline BackToFrontIterator BackToFrontBegin() { return rbegin(); }
36 inline BackToFrontIterator BackToFrontEnd() { return rend(); }
37 inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); }
38 inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); }
39};
40
41typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList;
42
43class CC_EXPORT RenderPass {
44 public:
45 struct Id {
46 int layer_id;
47 int index;
48
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010049 Id(int layer_id, int index) : layer_id(layer_id), index(index) {}
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000050
51 bool operator==(const Id& other) const {
52 return layer_id == other.layer_id && index == other.index;
53 }
54 bool operator!=(const Id& other) const {
55 return !(*this == other);
56 }
57 bool operator<(const Id& other) const {
58 return layer_id < other.layer_id ||
59 (layer_id == other.layer_id && index < other.index);
60 }
61 };
62
63 ~RenderPass();
64
65 static scoped_ptr<RenderPass> Create();
66
67 // A shallow copy of the render pass, which does not include its quads.
68 scoped_ptr<RenderPass> Copy(Id new_id) const;
69
70 void SetNew(Id id,
71 gfx::Rect output_rect,
72 gfx::RectF damage_rect,
73 const gfx::Transform& transform_to_root_target);
74
75 void SetAll(Id id,
76 gfx::Rect output_rect,
77 gfx::RectF damage_rect,
78 const gfx::Transform& transform_to_root_target,
79 bool has_transparent_background,
80 bool has_occlusion_from_outside_target_surface);
81
82 // Uniquely identifies the render pass in the compositor's current frame.
83 Id id;
84
85 // These are in the space of the render pass' physical pixels.
86 gfx::Rect output_rect;
87 gfx::RectF damage_rect;
88
89 // Transforms from the origin of the |output_rect| to the origin of the root
90 // render pass' |output_rect|.
91 gfx::Transform transform_to_root_target;
92
93 // If false, the pixels in the render pass' texture are all opaque.
94 bool has_transparent_background;
95
96 // If true, then there may be pixels in the render pass' texture that are not
97 // complete, since they are occluded.
98 bool has_occlusion_from_outside_target_surface;
99
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100100 // If non-empty, the renderer should produce a copy of the render pass'
101 // contents as a bitmap, and give a copy of the bitmap to each callback in
102 // this list. This property should not be serialized between compositors, as
103 // it only makes sense in the root compositor.
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100104 ScopedPtrVector<CopyOutputRequest> copy_requests;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100105
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000106 QuadList quad_list;
107 SharedQuadStateList shared_quad_state_list;
108
109 protected:
110 RenderPass();
111
Ben Murdocheb525c52013-07-10 11:40:50 +0100112 private:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000113 DISALLOW_COPY_AND_ASSIGN(RenderPass);
114};
115
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100116} // namespace cc
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000117
118namespace BASE_HASH_NAMESPACE {
119#if defined(COMPILER_MSVC)
Ben Murdochbb1529c2013-08-08 10:24:53 +0100120inline size_t hash_value(const cc::RenderPass::Id& key) {
121 return base::HashPair(key.layer_id, key.index);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000122}
123#elif defined(COMPILER_GCC)
124template<>
125struct hash<cc::RenderPass::Id> {
126 size_t operator()(cc::RenderPass::Id key) const {
Ben Murdochbb1529c2013-08-08 10:24:53 +0100127 return base::HashPair(key.layer_id, key.index);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000128 }
129};
130#else
131#error define a hash function for your compiler
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100132#endif // COMPILER
Ben Murdocheb525c52013-07-10 11:40:50 +0100133} // namespace BASE_HASH_NAMESPACE
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000134
135namespace cc {
136typedef ScopedPtrVector<RenderPass> RenderPassList;
137typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100138} // namespace cc
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000139
140#endif // CC_QUADS_RENDER_PASS_H_