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