Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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. |
| 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 Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 13 | namespace base { |
| 14 | class Value; |
| 15 | class DictionaryValue; |
| 16 | } |
| 17 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 18 | namespace 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 Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 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. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 31 | class CC_EXPORT DrawQuad { |
| 32 | public: |
| 33 | enum Material { |
| 34 | INVALID, |
| 35 | CHECKERBOARD, |
| 36 | DEBUG_BORDER, |
| 37 | IO_SURFACE_CONTENT, |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 38 | PICTURE_CONTENT, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 39 | 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) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 53 | 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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; } |
| 62 | |
| 63 | Material material; |
| 64 | |
| 65 | // This rect, after applying the quad_transform(), gives the geometry that |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 66 | // this quad should draw to. This rect lives in content space. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 67 | gfx::Rect rect; |
| 68 | |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 69 | // This specifies the region of the quad that is opaque. This rect lives in |
| 70 | // content space. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 71 | gfx::Rect opaque_rect; |
| 72 | |
| 73 | // Allows changing the rect that gets drawn to make it smaller. This value |
Ben Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 74 | // should be clipped to |rect|. This rect lives in content space. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 75 | 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 90 | 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 97 | typedef ResourceProvider::ResourceId ResourceId; |
| 98 | typedef base::Callback<ResourceId(ResourceId)> ResourceIteratorCallback; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 99 | 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 Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 127 | scoped_ptr<base::Value> AsValue() const; |
| 128 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 129 | 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 Murdoch | ba5b9a6 | 2013-08-12 14:20:17 +0100 | [diff] [blame] | 138 | virtual void ExtendValue(base::DictionaryValue* value) const = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 141 | } // namespace cc |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 142 | |
| 143 | #endif // CC_QUADS_DRAW_QUAD_H_ |