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