Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / quads / draw_quad.h
blob2de24974a5adb781b898375e8c3281725caf4550
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"
13 namespace base {
14 class Value;
15 class DictionaryValue;
18 namespace cc {
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 {
32 public:
33 enum Material {
34 INVALID,
35 CHECKERBOARD,
36 DEBUG_BORDER,
37 IO_SURFACE_CONTENT,
38 PICTURE_CONTENT,
39 RENDER_PASS,
40 SOLID_COLOR,
41 STREAM_VIDEO_CONTENT,
42 SURFACE_CONTENT,
43 TEXTURE_CONTENT,
44 TILED_CONTENT,
45 YUV_VIDEO_CONTENT,
46 MATERIAL_LAST = YUV_VIDEO_CONTENT
49 virtual ~DrawQuad();
51 // TODO(weiliangc): DrawQuad need to be allocated on RenderPass. This function
52 // need to be moved to RenderPass.
53 scoped_ptr<DrawQuad> Copy(
54 const SharedQuadState* copied_shared_quad_state) const;
56 // TODO(danakj): Chromify or remove these SharedQuadState helpers.
57 const gfx::Transform& quadTransform() const {
58 return shared_quad_state->content_to_target_transform;
60 gfx::Rect visibleContentRect() const {
61 return shared_quad_state->visible_content_rect;
63 gfx::Rect clipRect() const { return shared_quad_state->clip_rect; }
64 bool isClipped() const { return shared_quad_state->is_clipped; }
65 float opacity() const { return shared_quad_state->opacity; }
67 Material material;
69 // This rect, after applying the quad_transform(), gives the geometry that
70 // this quad should draw to. This rect lives in content space.
71 gfx::Rect rect;
73 // This specifies the region of the quad that is opaque. This rect lives in
74 // content space.
75 gfx::Rect opaque_rect;
77 // Allows changing the rect that gets drawn to make it smaller. This value
78 // should be clipped to |rect|. This rect lives in content space.
79 gfx::Rect visible_rect;
81 // By default blending is used when some part of the quad is not opaque.
82 // With this setting, it is possible to force blending on regardless of the
83 // opaque area.
84 bool needs_blending;
86 // Stores state common to a large bundle of quads; kept separate for memory
87 // efficiency. There is special treatment to reconstruct these pointers
88 // during serialization.
89 const SharedQuadState* shared_quad_state;
91 bool IsDebugQuad() const { return material == DEBUG_BORDER; }
93 bool ShouldDrawWithBlending() const {
94 if (needs_blending || shared_quad_state->opacity < 1.0f)
95 return true;
96 if (visible_rect.IsEmpty())
97 return false;
98 return !opaque_rect.Contains(visible_rect);
101 typedef ResourceProvider::ResourceId ResourceId;
102 typedef base::Callback<ResourceId(ResourceId)> ResourceIteratorCallback;
103 virtual void IterateResources(const ResourceIteratorCallback& callback) = 0;
105 // Is the left edge of this tile aligned with the originating layer's
106 // left edge?
107 bool IsLeftEdge() const { return !rect.x(); }
109 // Is the top edge of this tile aligned with the originating layer's
110 // top edge?
111 bool IsTopEdge() const { return !rect.y(); }
113 // Is the right edge of this tile aligned with the originating layer's
114 // right edge?
115 bool IsRightEdge() const {
116 return rect.right() == shared_quad_state->content_bounds.width();
119 // Is the bottom edge of this tile aligned with the originating layer's
120 // bottom edge?
121 bool IsBottomEdge() const {
122 return rect.bottom() == shared_quad_state->content_bounds.height();
125 // Is any edge of this tile aligned with the originating layer's
126 // corresponding edge?
127 bool IsEdge() const {
128 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge();
131 scoped_ptr<base::Value> AsValue() const;
133 protected:
134 DrawQuad();
136 void SetAll(const SharedQuadState* shared_quad_state,
137 Material material,
138 const gfx::Rect& rect,
139 const gfx::Rect& opaque_rect,
140 const gfx::Rect& visible_rect,
141 bool needs_blending);
142 virtual void ExtendValue(base::DictionaryValue* value) const = 0;
145 } // namespace cc
147 #endif // CC_QUADS_DRAW_QUAD_H_