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/quads/shared_quad_state.h"
11 #include "cc/resources/resource_provider.h"
15 class DictionaryValue
;
20 // DrawQuad is a bag of data used for drawing a quad. Because different
21 // materials need different bits of per-quad data to render, classes that derive
22 // from DrawQuad store additional data in their derived instance. The Material
23 // enum is used to "safely" downcast to the derived class.
24 // Note: quads contain rects and sizes, which live in different spaces. There is
25 // the "content space", which is the arbitrary space in which the quad's
26 // geometry is defined (generally related to the layer that produced the quad,
27 // e.g. the content space for TiledLayerImpls, or the geometry space for
28 // PictureLayerImpls). There is also the "target space", which is the space, in
29 // "physical" pixels, of the render target where the quads is drawn. The quad's
30 // transform maps the content space to the target space.
31 class CC_EXPORT DrawQuad
{
49 scoped_ptr
<DrawQuad
> Copy(
50 const SharedQuadState
* copied_shared_quad_state
) const;
52 // TODO(danakj): Chromify or remove these SharedQuadState helpers.
53 const gfx::Transform
& quadTransform() const {
54 return shared_quad_state
->content_to_target_transform
;
56 gfx::Rect
visibleContentRect() const {
57 return shared_quad_state
->visible_content_rect
;
59 gfx::Rect
clipRect() const { return shared_quad_state
->clip_rect
; }
60 bool isClipped() const { return shared_quad_state
->is_clipped
; }
61 float opacity() const { return shared_quad_state
->opacity
; }
65 // This rect, after applying the quad_transform(), gives the geometry that
66 // this quad should draw to. This rect lives in content space.
69 // This specifies the region of the quad that is opaque. This rect lives in
71 gfx::Rect opaque_rect
;
73 // Allows changing the rect that gets drawn to make it smaller. This value
74 // should be clipped to |rect|. This rect lives in content space.
75 gfx::Rect visible_rect
;
77 // By default blending is used when some part of the quad is not opaque.
78 // With this setting, it is possible to force blending on regardless of the
82 // Stores state common to a large bundle of quads; kept separate for memory
83 // efficiency. There is special treatment to reconstruct these pointers
84 // during serialization.
85 const SharedQuadState
* shared_quad_state
;
87 bool IsDebugQuad() const { return material
== DEBUG_BORDER
; }
89 bool ShouldDrawWithBlending() const {
90 if (needs_blending
|| shared_quad_state
->opacity
< 1.0f
)
92 if (visible_rect
.IsEmpty())
94 return !opaque_rect
.Contains(visible_rect
);
97 typedef ResourceProvider::ResourceId ResourceId
;
98 typedef base::Callback
<ResourceId(ResourceId
)> ResourceIteratorCallback
;
99 virtual void IterateResources(const ResourceIteratorCallback
& callback
) = 0;
101 // Is the left edge of this tile aligned with the originating layer's
103 bool IsLeftEdge() const { return !rect
.x(); }
105 // Is the top edge of this tile aligned with the originating layer's
107 bool IsTopEdge() const { return !rect
.y(); }
109 // Is the right edge of this tile aligned with the originating layer's
111 bool IsRightEdge() const {
112 return rect
.right() == shared_quad_state
->content_bounds
.width();
115 // Is the bottom edge of this tile aligned with the originating layer's
117 bool IsBottomEdge() const {
118 return rect
.bottom() == shared_quad_state
->content_bounds
.height();
121 // Is any edge of this tile aligned with the originating layer's
122 // corresponding edge?
123 bool IsEdge() const {
124 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
127 scoped_ptr
<base::Value
> AsValue() const;
132 void SetAll(const SharedQuadState
* shared_quad_state
,
135 gfx::Rect opaque_rect
,
136 gfx::Rect visible_rect
,
137 bool needs_blending
);
138 virtual void ExtendValue(base::DictionaryValue
* value
) const = 0;
143 #endif // CC_QUADS_DRAW_QUAD_H_