Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 8 | #include <utility> |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 9 | |
| 10 | #include "base/basictypes.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 11 | #include "base/callback.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 12 | #include "base/containers/hash_tables.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | #include "cc/base/cc_export.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 14 | #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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #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 | |
| 23 | namespace cc { |
| 24 | |
| 25 | class DrawQuad; |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 26 | class CopyOutputRequest; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 27 | class SharedQuadState; |
| 28 | |
| 29 | // A list of DrawQuad objects, sorted internally in front-to-back order. |
| 30 | class 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 | |
| 41 | typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList; |
| 42 | |
| 43 | class CC_EXPORT RenderPass { |
| 44 | public: |
| 45 | struct Id { |
| 46 | int layer_id; |
| 47 | int index; |
| 48 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 49 | Id(int layer_id, int index) : layer_id(layer_id), index(index) {} |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 50 | |
| 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) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 100 | // 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) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 104 | ScopedPtrVector<CopyOutputRequest> copy_requests; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 105 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 106 | QuadList quad_list; |
| 107 | SharedQuadStateList shared_quad_state_list; |
| 108 | |
| 109 | protected: |
| 110 | RenderPass(); |
| 111 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 112 | private: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 113 | DISALLOW_COPY_AND_ASSIGN(RenderPass); |
| 114 | }; |
| 115 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 116 | } // namespace cc |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 117 | |
| 118 | namespace BASE_HASH_NAMESPACE { |
| 119 | #if defined(COMPILER_MSVC) |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 120 | inline size_t hash_value(const cc::RenderPass::Id& key) { |
| 121 | return base::HashPair(key.layer_id, key.index); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 122 | } |
| 123 | #elif defined(COMPILER_GCC) |
| 124 | template<> |
| 125 | struct hash<cc::RenderPass::Id> { |
| 126 | size_t operator()(cc::RenderPass::Id key) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 127 | return base::HashPair(key.layer_id, key.index); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 128 | } |
| 129 | }; |
| 130 | #else |
| 131 | #error define a hash function for your compiler |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 132 | #endif // COMPILER |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 133 | } // namespace BASE_HASH_NAMESPACE |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 134 | |
| 135 | namespace cc { |
| 136 | typedef ScopedPtrVector<RenderPass> RenderPassList; |
| 137 | typedef base::hash_map<RenderPass::Id, RenderPass*> RenderPassIdHashMap; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 138 | } // namespace cc |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 139 | |
| 140 | #endif // CC_QUADS_RENDER_PASS_H_ |