Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / quads / draw_quad.h
blob10b0e40d0f03e69cde61f2938b6cd1d6c9d237b6
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 geometry space for PictureLayerImpls or the layer's coordinate space
31 // for most other layers). There is also the "target space", which is the space,
32 // in "physical" pixels, of the render target where the quads is drawn. The
33 // quad's transform maps the content space to the target space.
34 class CC_EXPORT DrawQuad {
35 public:
36 enum Material {
37 INVALID,
38 DEBUG_BORDER,
39 IO_SURFACE_CONTENT,
40 PICTURE_CONTENT,
41 RENDER_PASS,
42 SOLID_COLOR,
43 STREAM_VIDEO_CONTENT,
44 SURFACE_CONTENT,
45 TEXTURE_CONTENT,
46 TILED_CONTENT,
47 YUV_VIDEO_CONTENT,
48 MATERIAL_LAST = YUV_VIDEO_CONTENT
51 virtual ~DrawQuad();
53 Material material;
55 // This rect, after applying the quad_transform(), gives the geometry that
56 // this quad should draw to. This rect lives in content space.
57 gfx::Rect rect;
59 // This specifies the region of the quad that is opaque. This rect lives in
60 // content space.
61 gfx::Rect opaque_rect;
63 // Allows changing the rect that gets drawn to make it smaller. This value
64 // should be clipped to |rect|. This rect lives in content space.
65 gfx::Rect visible_rect;
67 // By default blending is used when some part of the quad is not opaque.
68 // With this setting, it is possible to force blending on regardless of the
69 // opaque area.
70 bool needs_blending;
72 // Stores state common to a large bundle of quads; kept separate for memory
73 // efficiency. There is special treatment to reconstruct these pointers
74 // during serialization.
75 const SharedQuadState* shared_quad_state;
77 bool IsDebugQuad() const { return material == DEBUG_BORDER; }
79 bool ShouldDrawWithBlending() const {
80 if (needs_blending || shared_quad_state->opacity < 1.0f)
81 return true;
82 if (visible_rect.IsEmpty())
83 return false;
84 return !opaque_rect.Contains(visible_rect);
87 // Is the left edge of this tile aligned with the originating layer's
88 // left edge?
89 bool IsLeftEdge() const { return !rect.x(); }
91 // Is the top edge of this tile aligned with the originating layer's
92 // top edge?
93 bool IsTopEdge() const { return !rect.y(); }
95 // Is the right edge of this tile aligned with the originating layer's
96 // right edge?
97 bool IsRightEdge() const {
98 return rect.right() == shared_quad_state->quad_layer_bounds.width();
101 // Is the bottom edge of this tile aligned with the originating layer's
102 // bottom edge?
103 bool IsBottomEdge() const {
104 return rect.bottom() == shared_quad_state->quad_layer_bounds.height();
107 // Is any edge of this tile aligned with the originating layer's
108 // corresponding edge?
109 bool IsEdge() const {
110 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
113 void AsValueInto(base::trace_event::TracedValue* value) const;
115 struct CC_EXPORT Resources {
116 enum : size_t { kMaxResourceIdCount = 4 };
117 Resources();
119 ResourceId* begin() { return ids; }
120 ResourceId* end() {
121 DCHECK_LE(count, kMaxResourceIdCount);
122 return ids + count;
125 size_t count;
126 ResourceId ids[kMaxResourceIdCount];
129 Resources resources;
131 protected:
132 DrawQuad();
134 void SetAll(const SharedQuadState* shared_quad_state,
135 Material material,
136 const gfx::Rect& rect,
137 const gfx::Rect& opaque_rect,
138 const gfx::Rect& visible_rect,
139 bool needs_blending);
140 virtual void ExtendValue(base::trace_event::TracedValue* value) const = 0;
143 } // namespace cc
145 #endif // CC_QUADS_DRAW_QUAD_H_