blob: c3696d6f301fe17fa1f5500212ba160046fc2949 [file] [log] [blame]
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001// 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.
4
5#ifndef CC_QUADS_DRAW_QUAD_H_
6#define CC_QUADS_DRAW_QUAD_H_
7
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"
12
Ben Murdochba5b9a62013-08-12 14:20:17 +010013namespace base {
14class Value;
15class DictionaryValue;
16}
17
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000018namespace cc {
19
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.
Ben Murdochba5b9a62013-08-12 14:20:17 +010024// 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.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000031class CC_EXPORT DrawQuad {
32 public:
33 enum Material {
34 INVALID,
35 CHECKERBOARD,
36 DEBUG_BORDER,
37 IO_SURFACE_CONTENT,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010038 PICTURE_CONTENT,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000039 RENDER_PASS,
40 TEXTURE_CONTENT,
41 SOLID_COLOR,
42 TILED_CONTENT,
43 YUV_VIDEO_CONTENT,
44 STREAM_VIDEO_CONTENT,
45 };
46
47 virtual ~DrawQuad();
48
49 scoped_ptr<DrawQuad> Copy(
50 const SharedQuadState* copied_shared_quad_state) const;
51
52 // TODO(danakj): Chromify or remove these SharedQuadState helpers.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010053 const gfx::Transform& quadTransform() const {
54 return shared_quad_state->content_to_target_transform;
55 }
56 gfx::Rect visibleContentRect() const {
57 return shared_quad_state->visible_content_rect;
58 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059 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; }
62
63 Material material;
64
65 // This rect, after applying the quad_transform(), gives the geometry that
Ben Murdochba5b9a62013-08-12 14:20:17 +010066 // this quad should draw to. This rect lives in content space.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000067 gfx::Rect rect;
68
Ben Murdochba5b9a62013-08-12 14:20:17 +010069 // This specifies the region of the quad that is opaque. This rect lives in
70 // content space.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000071 gfx::Rect opaque_rect;
72
73 // Allows changing the rect that gets drawn to make it smaller. This value
Ben Murdochba5b9a62013-08-12 14:20:17 +010074 // should be clipped to |rect|. This rect lives in content space.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000075 gfx::Rect visible_rect;
76
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
79 // opaque area.
80 bool needs_blending;
81
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;
86
87 bool IsDebugQuad() const { return material == DEBUG_BORDER; }
88
89 bool ShouldDrawWithBlending() const {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010090 if (needs_blending || shared_quad_state->opacity < 1.0f)
91 return true;
92 if (visible_rect.IsEmpty())
93 return false;
94 return !opaque_rect.Contains(visible_rect);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000095 }
96
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010097 typedef ResourceProvider::ResourceId ResourceId;
98 typedef base::Callback<ResourceId(ResourceId)> ResourceIteratorCallback;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000099 virtual void IterateResources(const ResourceIteratorCallback& callback) = 0;
100
101 // Is the left edge of this tile aligned with the originating layer's
102 // left edge?
103 bool IsLeftEdge() const { return !rect.x(); }
104
105 // Is the top edge of this tile aligned with the originating layer's
106 // top edge?
107 bool IsTopEdge() const { return !rect.y(); }
108
109 // Is the right edge of this tile aligned with the originating layer's
110 // right edge?
111 bool IsRightEdge() const {
112 return rect.right() == shared_quad_state->content_bounds.width();
113 }
114
115 // Is the bottom edge of this tile aligned with the originating layer's
116 // bottom edge?
117 bool IsBottomEdge() const {
118 return rect.bottom() == shared_quad_state->content_bounds.height();
119 }
120
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();
125 }
126
Ben Murdochba5b9a62013-08-12 14:20:17 +0100127 scoped_ptr<base::Value> AsValue() const;
128
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000129 protected:
130 DrawQuad();
131
132 void SetAll(const SharedQuadState* shared_quad_state,
133 Material material,
134 gfx::Rect rect,
135 gfx::Rect opaque_rect,
136 gfx::Rect visible_rect,
137 bool needs_blending);
Ben Murdochba5b9a62013-08-12 14:20:17 +0100138 virtual void ExtendValue(base::DictionaryValue* value) const = 0;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000139};
140
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100141} // namespace cc
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000142
143#endif // CC_QUADS_DRAW_QUAD_H_