Setup a experiment to enable background tracing.
[chromium-blink-merge.git] / cc / quads / draw_quad.h
blobfa1959b621e1ca5ab4251608b1209143fa3a0b1a
1 // Copyright 2012 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_QUADS_DRAW_QUAD_H_
6 #define CC_QUADS_DRAW_QUAD_H_
8 #include "base/callback.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/base/resource_id.h"
11 #include "cc/quads/shared_quad_state.h"
13 namespace base {
14 namespace trace_event {
15 class TracedValue;
17 class Value;
18 class DictionaryValue;
21 namespace cc {
23 // DrawQuad is a bag of data used for drawing a quad. Because different
24 // materials need different bits of per-quad data to render, classes that derive
25 // from DrawQuad store additional data in their derived instance. The Material
26 // enum is used to "safely" downcast to the derived class.
27 // Note: quads contain rects and sizes, which live in different spaces. There is
28 // the "content space", which is the arbitrary space in which the quad's
29 // geometry is defined (generally related to the layer that produced the quad,
30 // e.g. the content space for TiledLayerImpls, or the geometry space for
31 // PictureLayerImpls). There is also the "target space", which is the space, in
32 // "physical" pixels, of the render target where the quads is drawn. The quad's
33 // transform maps the content space to the target space.
34 class CC_EXPORT DrawQuad {
35 public:
36 enum Material {
37 INVALID,
38 CHECKERBOARD,
39 DEBUG_BORDER,
40 IO_SURFACE_CONTENT,
41 PICTURE_CONTENT,
42 RENDER_PASS,
43 SOLID_COLOR,
44 STREAM_VIDEO_CONTENT,
45 SURFACE_CONTENT,
46 TEXTURE_CONTENT,
47 TILED_CONTENT,
48 YUV_VIDEO_CONTENT,
49 MATERIAL_LAST = YUV_VIDEO_CONTENT
52 virtual ~DrawQuad();
54 // TODO(danakj): Chromify or remove these SharedQuadState helpers.
55 const gfx::Transform& quadTransform() const {
56 return shared_quad_state->content_to_target_transform;
58 gfx::Rect visibleContentRect() const {
59 return shared_quad_state->visible_content_rect;
61 gfx::Rect clipRect() const { return shared_quad_state->clip_rect; }
62 bool isClipped() const { return shared_quad_state->is_clipped; }
63 float opacity() const { return shared_quad_state->opacity; }
65 Material material;
67 // This rect, after applying the quad_transform(), gives the geometry that
68 // this quad should draw to. This rect lives in content space.
69 gfx::Rect rect;
71 // This specifies the region of the quad that is opaque. This rect lives in
72 // content space.
73 gfx::Rect opaque_rect;
75 // Allows changing the rect that gets drawn to make it smaller. This value
76 // should be clipped to |rect|. This rect lives in content space.
77 gfx::Rect visible_rect;
79 // By default blending is used when some part of the quad is not opaque.
80 // With this setting, it is possible to force blending on regardless of the
81 // opaque area.
82 bool needs_blending;
84 // Stores state common to a large bundle of quads; kept separate for memory
85 // efficiency. There is special treatment to reconstruct these pointers
86 // during serialization.
87 const SharedQuadState* shared_quad_state;
89 bool IsDebugQuad() const { return material == DEBUG_BORDER; }
91 bool ShouldDrawWithBlending() const {
92 if (needs_blending || shared_quad_state->opacity < 1.0f)
93 return true;
94 if (visible_rect.IsEmpty())
95 return false;
96 return !opaque_rect.Contains(visible_rect);
99 // Is the left edge of this tile aligned with the originating layer's
100 // left edge?
101 bool IsLeftEdge() const { return !rect.x(); }
103 // Is the top edge of this tile aligned with the originating layer's
104 // top edge?
105 bool IsTopEdge() const { return !rect.y(); }
107 // Is the right edge of this tile aligned with the originating layer's
108 // right edge?
109 bool IsRightEdge() const {
110 return rect.right() == shared_quad_state->content_bounds.width();
113 // Is the bottom edge of this tile aligned with the originating layer's
114 // bottom edge?
115 bool IsBottomEdge() const {
116 return rect.bottom() == shared_quad_state->content_bounds.height();
119 // Is any edge of this tile aligned with the originating layer's
120 // corresponding edge?
121 bool IsEdge() const {
122 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
125 void AsValueInto(base::trace_event::TracedValue* value) const;
127 struct CC_EXPORT Resources {
128 enum : size_t { kMaxResourceIdCount = 4 };
129 Resources();
131 ResourceId* begin() { return ids; }
132 ResourceId* end() {
133 DCHECK_LE(count, kMaxResourceIdCount);
134 return ids + count;
137 size_t count;
138 ResourceId ids[kMaxResourceIdCount];
141 Resources resources;
143 protected:
144 DrawQuad();
146 void SetAll(const SharedQuadState* shared_quad_state,
147 Material material,
148 const gfx::Rect& rect,
149 const gfx::Rect& opaque_rect,
150 const gfx::Rect& visible_rect,
151 bool needs_blending);
152 virtual void ExtendValue(base::trace_event::TracedValue* value) const = 0;
155 } // namespace cc
157 #endif // CC_QUADS_DRAW_QUAD_H_