Roll src/third_party/skia 7b05ff1:dab1f60
[chromium-blink-merge.git] / cc / quads / draw_quad.h
blobdf3bc1213f52b28bc85f8462f7fcc1ffc4bcff90
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 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 Material material;
56 // This rect, after applying the quad_transform(), gives the geometry that
57 // this quad should draw to. This rect lives in content space.
58 gfx::Rect rect;
60 // This specifies the region of the quad that is opaque. This rect lives in
61 // content space.
62 gfx::Rect opaque_rect;
64 // Allows changing the rect that gets drawn to make it smaller. This value
65 // should be clipped to |rect|. This rect lives in content space.
66 gfx::Rect visible_rect;
68 // By default blending is used when some part of the quad is not opaque.
69 // With this setting, it is possible to force blending on regardless of the
70 // opaque area.
71 bool needs_blending;
73 // Stores state common to a large bundle of quads; kept separate for memory
74 // efficiency. There is special treatment to reconstruct these pointers
75 // during serialization.
76 const SharedQuadState* shared_quad_state;
78 bool IsDebugQuad() const { return material == DEBUG_BORDER; }
80 bool ShouldDrawWithBlending() const {
81 if (needs_blending || shared_quad_state->opacity < 1.0f)
82 return true;
83 if (visible_rect.IsEmpty())
84 return false;
85 return !opaque_rect.Contains(visible_rect);
88 // Is the left edge of this tile aligned with the originating layer's
89 // left edge?
90 bool IsLeftEdge() const { return !rect.x(); }
92 // Is the top edge of this tile aligned with the originating layer's
93 // top edge?
94 bool IsTopEdge() const { return !rect.y(); }
96 // Is the right edge of this tile aligned with the originating layer's
97 // right edge?
98 bool IsRightEdge() const {
99 return rect.right() == shared_quad_state->quad_layer_bounds.width();
102 // Is the bottom edge of this tile aligned with the originating layer's
103 // bottom edge?
104 bool IsBottomEdge() const {
105 return rect.bottom() == shared_quad_state->quad_layer_bounds.height();
108 // Is any edge of this tile aligned with the originating layer's
109 // corresponding edge?
110 bool IsEdge() const {
111 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
114 void AsValueInto(base::trace_event::TracedValue* value) const;
116 struct CC_EXPORT Resources {
117 enum : size_t { kMaxResourceIdCount = 4 };
118 Resources();
120 ResourceId* begin() { return ids; }
121 ResourceId* end() {
122 DCHECK_LE(count, kMaxResourceIdCount);
123 return ids + count;
126 size_t count;
127 ResourceId ids[kMaxResourceIdCount];
130 Resources resources;
132 protected:
133 DrawQuad();
135 void SetAll(const SharedQuadState* shared_quad_state,
136 Material material,
137 const gfx::Rect& rect,
138 const gfx::Rect& opaque_rect,
139 const gfx::Rect& visible_rect,
140 bool needs_blending);
141 virtual void ExtendValue(base::trace_event::TracedValue* value) const = 0;
144 } // namespace cc
146 #endif // CC_QUADS_DRAW_QUAD_H_