OLD | NEW |
(Empty) | |
| 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/quads/shared_quad_state.h" |
| 10 #include "cc/resources/resource_provider.h" |
| 11 |
| 12 namespace base { |
| 13 namespace trace_event { |
| 14 class TracedValue; |
| 15 } |
| 16 class Value; |
| 17 class DictionaryValue; |
| 18 } |
| 19 |
| 20 namespace cc { |
| 21 |
| 22 // DrawQuad is a bag of data used for drawing a quad. Because different |
| 23 // materials need different bits of per-quad data to render, classes that derive |
| 24 // from DrawQuad store additional data in their derived instance. The Material |
| 25 // enum is used to "safely" downcast to the derived class. |
| 26 // Note: quads contain rects and sizes, which live in different spaces. There is |
| 27 // the "content space", which is the arbitrary space in which the quad's |
| 28 // geometry is defined (generally related to the layer that produced the quad, |
| 29 // e.g. the content space for TiledLayerImpls, or the geometry space for |
| 30 // PictureLayerImpls). There is also the "target space", which is the space, in |
| 31 // "physical" pixels, of the render target where the quads is drawn. The quad's |
| 32 // transform maps the content space to the target space. |
| 33 class DrawQuad { |
| 34 public: |
| 35 enum Material { |
| 36 INVALID, |
| 37 CHECKERBOARD, |
| 38 DEBUG_BORDER, |
| 39 IO_SURFACE_CONTENT, |
| 40 UNUSED_SPACE_FOR_PICTURE_CONTENT, |
| 41 RENDER_PASS, |
| 42 SOLID_COLOR, |
| 43 STREAM_VIDEO_CONTENT, |
| 44 SURFACE_CONTENT, |
| 45 TEXTURE_CONTENT, |
| 46 TILED_CONTENT, |
| 47 YUV_VIDEO_CONTENT, |
| 48 MATERIAL_LAST = YUV_VIDEO_CONTENT |
| 49 }; |
| 50 |
| 51 virtual ~DrawQuad(); |
| 52 |
| 53 // TODO(danakj): Chromify or remove these SharedQuadState helpers. |
| 54 const gfx::Transform& quadTransform() const { |
| 55 return shared_quad_state->content_to_target_transform; |
| 56 } |
| 57 gfx::Rect visibleContentRect() const { |
| 58 return shared_quad_state->visible_content_rect; |
| 59 } |
| 60 gfx::Rect clipRect() const { return shared_quad_state->clip_rect; } |
| 61 bool isClipped() const { return shared_quad_state->is_clipped; } |
| 62 float opacity() const { return shared_quad_state->opacity; } |
| 63 |
| 64 Material material; |
| 65 |
| 66 // This rect, after applying the quad_transform(), gives the geometry that |
| 67 // this quad should draw to. This rect lives in content space. |
| 68 gfx::Rect rect; |
| 69 |
| 70 // This specifies the region of the quad that is opaque. This rect lives in |
| 71 // content space. |
| 72 gfx::Rect opaque_rect; |
| 73 |
| 74 // Allows changing the rect that gets drawn to make it smaller. This value |
| 75 // should be clipped to |rect|. This rect lives in content space. |
| 76 gfx::Rect visible_rect; |
| 77 |
| 78 // By default blending is used when some part of the quad is not opaque. |
| 79 // With this setting, it is possible to force blending on regardless of the |
| 80 // opaque area. |
| 81 bool needs_blending; |
| 82 |
| 83 // Stores state common to a large bundle of quads; kept separate for memory |
| 84 // efficiency. There is special treatment to reconstruct these pointers |
| 85 // during serialization. |
| 86 const SharedQuadState* shared_quad_state; |
| 87 |
| 88 bool IsDebugQuad() const { return material == DEBUG_BORDER; } |
| 89 |
| 90 bool ShouldDrawWithBlending() const { |
| 91 if (needs_blending || shared_quad_state->opacity < 1.0f) |
| 92 return true; |
| 93 if (visible_rect.IsEmpty()) |
| 94 return false; |
| 95 return !opaque_rect.Contains(visible_rect); |
| 96 } |
| 97 |
| 98 typedef ResourceProvider::ResourceId ResourceId; |
| 99 typedef base::Callback<ResourceId(ResourceId)> ResourceIteratorCallback; |
| 100 virtual void IterateResources(const ResourceIteratorCallback& callback) = 0; |
| 101 |
| 102 // Is the left edge of this tile aligned with the originating layer's |
| 103 // left edge? |
| 104 bool IsLeftEdge() const { return !rect.x(); } |
| 105 |
| 106 // Is the top edge of this tile aligned with the originating layer's |
| 107 // top edge? |
| 108 bool IsTopEdge() const { return !rect.y(); } |
| 109 |
| 110 // Is the right edge of this tile aligned with the originating layer's |
| 111 // right edge? |
| 112 bool IsRightEdge() const { |
| 113 return rect.right() == shared_quad_state->content_bounds.width(); |
| 114 } |
| 115 |
| 116 // Is the bottom edge of this tile aligned with the originating layer's |
| 117 // bottom edge? |
| 118 bool IsBottomEdge() const { |
| 119 return rect.bottom() == shared_quad_state->content_bounds.height(); |
| 120 } |
| 121 |
| 122 // Is any edge of this tile aligned with the originating layer's |
| 123 // corresponding edge? |
| 124 bool IsEdge() const { |
| 125 return IsLeftEdge() || IsTopEdge() || IsRightEdge() || IsBottomEdge(); |
| 126 } |
| 127 |
| 128 void AsValueInto(base::trace_event::TracedValue* value) const; |
| 129 |
| 130 protected: |
| 131 DrawQuad(); |
| 132 |
| 133 void SetAll(const SharedQuadState* shared_quad_state, |
| 134 Material material, |
| 135 const gfx::Rect& rect, |
| 136 const gfx::Rect& opaque_rect, |
| 137 const gfx::Rect& visible_rect, |
| 138 bool needs_blending); |
| 139 virtual void ExtendValue(base::trace_event::TracedValue* value) const = 0; |
| 140 }; |
| 141 |
| 142 } // namespace cc |
| 143 |
| 144 #endif // CC_QUADS_DRAW_QUAD_H_ |
OLD | NEW |