Telemetry: More elegant histogram printing.
[chromium-blink-merge.git] / cc / render_pass.h
bloba7e685f72d307b0fd721cfa2d89feaaddd894b8f
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_RENDER_PASS_H_
6 #define CC_RENDER_PASS_H_
8 #include <public/WebFilterOperations.h>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "cc/cc_export.h"
13 #include "cc/draw_quad.h"
14 #include "cc/hash_pair.h"
15 #include "cc/scoped_ptr_hash_map.h"
16 #include "cc/scoped_ptr_vector.h"
17 #include "cc/shared_quad_state.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkColor.h"
20 #include "third_party/skia/include/core/SkImageFilter.h"
21 #include "ui/gfx/rect_f.h"
22 #include "ui/gfx/transform.h"
24 namespace cc {
26 // A list of DrawQuad objects, sorted internally in front-to-back order.
27 class QuadList : public ScopedPtrVector<DrawQuad> {
28 public:
29 typedef reverse_iterator backToFrontIterator;
30 typedef const_reverse_iterator constBackToFrontIterator;
32 inline backToFrontIterator backToFrontBegin() { return rbegin(); }
33 inline backToFrontIterator backToFrontEnd() { return rend(); }
34 inline constBackToFrontIterator backToFrontBegin() const { return rbegin(); }
35 inline constBackToFrontIterator backToFrontEnd() const { return rend(); }
38 typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList;
40 class CC_EXPORT RenderPass {
41 public:
42 struct Id {
43 int layer_id;
44 int index;
46 Id(int layer_id, int index) : layer_id(layer_id), index(index) {}
48 bool operator==(const Id& other) const {
49 return layer_id == other.layer_id && index == other.index;
51 bool operator!=(const Id& other) const {
52 return !(*this == other);
54 bool operator<(const Id& other) const {
55 return layer_id < other.layer_id ||
56 (layer_id == other.layer_id && index < other.index);
60 ~RenderPass();
62 static scoped_ptr<RenderPass> Create();
64 // A shallow copy of the render pass, which does not include its quads.
65 scoped_ptr<RenderPass> Copy(Id newId) const;
67 void SetNew(Id id,
68 gfx::Rect output_rect,
69 gfx::RectF damage_rect,
70 const gfx::Transform& transform_to_root_target);
72 void SetAll(Id id,
73 gfx::Rect output_rect,
74 gfx::RectF damage_rect,
75 const gfx::Transform& transform_to_root_target,
76 bool has_transparent_background,
77 bool has_occlusion_from_outside_target_surface,
78 const WebKit::WebFilterOperations& filters,
79 const skia::RefPtr<SkImageFilter>& filter,
80 const WebKit::WebFilterOperations& background_filters);
82 // Uniquely identifies the render pass in the compositor's current frame.
83 Id id;
85 // These are in the space of the render pass' physical pixels.
86 gfx::Rect output_rect;
87 gfx::RectF damage_rect;
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;
93 // If false, the pixels in the render pass' texture are all opaque.
94 bool has_transparent_background;
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;
100 // Deprecated post-processing filters, applied to the pixels in the render
101 // pass' texture.
102 WebKit::WebFilterOperations filters;
103 // Post-processing filter applied to the pixels in the render pass' texture.
104 skia::RefPtr<SkImageFilter> filter;
106 // Post-processing filters, applied to the pixels showing through the
107 // background of the render pass, from behind it.
108 WebKit::WebFilterOperations background_filters;
110 QuadList quad_list;
111 SharedQuadStateList shared_quad_state_list;
113 protected:
114 RenderPass();
116 DISALLOW_COPY_AND_ASSIGN(RenderPass);
119 } // namespace cc
121 namespace BASE_HASH_NAMESPACE {
122 #if defined(COMPILER_MSVC)
123 template<>
124 inline size_t hash_value<cc::RenderPass::Id>(const cc::RenderPass::Id& key) {
125 return hash_value<std::pair<int, int> >(
126 std::pair<int, int>(key.layer_id, key.index));
128 #elif defined(COMPILER_GCC)
129 template<>
130 struct hash<cc::RenderPass::Id> {
131 size_t operator()(cc::RenderPass::Id key) const {
132 return hash<std::pair<int, int> >()(
133 std::pair<int, int>(key.layer_id, key.index));
136 #else
137 #error define a hash function for your compiler
138 #endif // COMPILER
141 namespace cc {
142 typedef std::vector<RenderPass*> RenderPassList;
143 typedef ScopedPtrHashMap<RenderPass::Id, RenderPass> RenderPassIdHashMap;
144 } // namespace cc
146 #endif // CC_RENDER_PASS_H_