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 | |
| 13 | namespace cc { |
| 14 | |
| 15 | // DrawQuad is a bag of data used for drawing a quad. Because different |
| 16 | // materials need different bits of per-quad data to render, classes that derive |
| 17 | // from DrawQuad store additional data in their derived instance. The Material |
| 18 | // enum is used to "safely" downcast to the derived class. |
| 19 | class CC_EXPORT DrawQuad { |
| 20 | public: |
| 21 | enum Material { |
| 22 | INVALID, |
| 23 | CHECKERBOARD, |
| 24 | DEBUG_BORDER, |
| 25 | IO_SURFACE_CONTENT, |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame^] | 26 | PICTURE_CONTENT, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 27 | RENDER_PASS, |
| 28 | TEXTURE_CONTENT, |
| 29 | SOLID_COLOR, |
| 30 | TILED_CONTENT, |
| 31 | YUV_VIDEO_CONTENT, |
| 32 | STREAM_VIDEO_CONTENT, |
| 33 | }; |
| 34 | |
| 35 | virtual ~DrawQuad(); |
| 36 | |
| 37 | scoped_ptr<DrawQuad> Copy( |
| 38 | const SharedQuadState* copied_shared_quad_state) const; |
| 39 | |
| 40 | // TODO(danakj): Chromify or remove these SharedQuadState helpers. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame^] | 41 | const gfx::Transform& quadTransform() const { |
| 42 | return shared_quad_state->content_to_target_transform; |
| 43 | } |
| 44 | gfx::Rect visibleContentRect() const { |
| 45 | return shared_quad_state->visible_content_rect; |
| 46 | } |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 47 | gfx::Rect clipRect() const { return shared_quad_state->clip_rect; } |
| 48 | bool isClipped() const { return shared_quad_state->is_clipped; } |
| 49 | float opacity() const { return shared_quad_state->opacity; } |
| 50 | |
| 51 | Material material; |
| 52 | |
| 53 | // This rect, after applying the quad_transform(), gives the geometry that |
| 54 | // this quad should draw to. |
| 55 | gfx::Rect rect; |
| 56 | |
| 57 | // This specifies the region of the quad that is opaque. |
| 58 | gfx::Rect opaque_rect; |
| 59 | |
| 60 | // Allows changing the rect that gets drawn to make it smaller. This value |
| 61 | // should be clipped to |rect|. |
| 62 | gfx::Rect visible_rect; |
| 63 | |
| 64 | // By default blending is used when some part of the quad is not opaque. |
| 65 | // With this setting, it is possible to force blending on regardless of the |
| 66 | // opaque area. |
| 67 | bool needs_blending; |
| 68 | |
| 69 | // Stores state common to a large bundle of quads; kept separate for memory |
| 70 | // efficiency. There is special treatment to reconstruct these pointers |
| 71 | // during serialization. |
| 72 | const SharedQuadState* shared_quad_state; |
| 73 | |
| 74 | bool IsDebugQuad() const { return material == DEBUG_BORDER; } |
| 75 | |
| 76 | bool ShouldDrawWithBlending() const { |
| 77 | return needs_blending || shared_quad_state->opacity < 1.0f || |
| 78 | !opaque_rect.Contains(visible_rect); |
| 79 | } |
| 80 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame^] | 81 | typedef ResourceProvider::ResourceId ResourceId; |
| 82 | typedef base::Callback<ResourceId(ResourceId)> ResourceIteratorCallback; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 83 | virtual void IterateResources(const ResourceIteratorCallback& callback) = 0; |
| 84 | |
| 85 | // Is the left edge of this tile aligned with the originating layer's |
| 86 | // left edge? |
| 87 | bool IsLeftEdge() const { return !rect.x(); } |
| 88 | |
| 89 | // Is the top edge of this tile aligned with the originating layer's |
| 90 | // top edge? |
| 91 | bool IsTopEdge() const { return !rect.y(); } |
| 92 | |
| 93 | // Is the right edge of this tile aligned with the originating layer's |
| 94 | // right edge? |
| 95 | bool IsRightEdge() const { |
| 96 | return rect.right() == shared_quad_state->content_bounds.width(); |
| 97 | } |
| 98 | |
| 99 | // Is the bottom edge of this tile aligned with the originating layer's |
| 100 | // bottom edge? |
| 101 | bool IsBottomEdge() const { |
| 102 | return rect.bottom() == shared_quad_state->content_bounds.height(); |
| 103 | } |
| 104 | |
| 105 | // Is any edge of this tile aligned with the originating layer's |
| 106 | // corresponding edge? |
| 107 | bool IsEdge() const { |
| 108 | return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge(); |
| 109 | } |
| 110 | |
| 111 | protected: |
| 112 | DrawQuad(); |
| 113 | |
| 114 | void SetAll(const SharedQuadState* shared_quad_state, |
| 115 | Material material, |
| 116 | gfx::Rect rect, |
| 117 | gfx::Rect opaque_rect, |
| 118 | gfx::Rect visible_rect, |
| 119 | bool needs_blending); |
| 120 | }; |
| 121 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame^] | 122 | } // namespace cc |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 123 | |
| 124 | #endif // CC_QUADS_DRAW_QUAD_H_ |