Index: cc/draw_quad.cc |
diff --git a/cc/draw_quad.cc b/cc/draw_quad.cc |
index 13a1c45fe00ac53305bcce1053c647a8aa77fdec..ecd221ce3121df4194a28ad31d9d34bcbbee5309 100644 |
--- a/cc/draw_quad.cc |
+++ b/cc/draw_quad.cc |
@@ -17,6 +17,14 @@ |
#include "cc/tile_draw_quad.h" |
#include "cc/yuv_video_draw_quad.h" |
+namespace { |
+ |
+template<typename T> T* TypedCopy(const cc::DrawQuad* other) { |
+ return new T(*T::materialCast(other)); |
+} |
+ |
+} |
+ |
namespace cc { |
DrawQuad::DrawQuad(const SharedQuadState* sharedQuadState, Material material, const gfx::Rect& quadRect) |
@@ -46,47 +54,40 @@ void DrawQuad::setQuadVisibleRect(gfx::Rect quadVisibleRect) |
m_quadVisibleRect = gfx::IntersectRects(quadVisibleRect, m_quadRect); |
} |
-unsigned DrawQuad::size() const |
+scoped_ptr<DrawQuad> DrawQuad::copy(const SharedQuadState* copiedSharedQuadState) const |
{ |
+ scoped_ptr<DrawQuad> copyQuad; |
switch (material()) { |
case Checkerboard: |
- return sizeof(CheckerboardDrawQuad); |
+ copyQuad.reset(TypedCopy<CheckerboardDrawQuad>(this)); |
+ break; |
case DebugBorder: |
- return sizeof(DebugBorderDrawQuad); |
+ copyQuad.reset(TypedCopy<DebugBorderDrawQuad>(this)); |
+ break; |
case IOSurfaceContent: |
- return sizeof(IOSurfaceDrawQuad); |
+ copyQuad.reset(TypedCopy<IOSurfaceDrawQuad>(this)); |
+ break; |
case TextureContent: |
- return sizeof(TextureDrawQuad); |
+ copyQuad.reset(TypedCopy<TextureDrawQuad>(this)); |
+ break; |
case SolidColor: |
- return sizeof(SolidColorDrawQuad); |
+ copyQuad.reset(TypedCopy<SolidColorDrawQuad>(this)); |
+ break; |
case TiledContent: |
- return sizeof(TileDrawQuad); |
+ copyQuad.reset(TypedCopy<TileDrawQuad>(this)); |
+ break; |
case StreamVideoContent: |
- return sizeof(StreamVideoDrawQuad); |
- case RenderPass: |
- return sizeof(RenderPassDrawQuad); |
+ copyQuad.reset(TypedCopy<StreamVideoDrawQuad>(this)); |
+ break; |
case YUVVideoContent: |
- return sizeof(YUVVideoDrawQuad); |
+ copyQuad.reset(TypedCopy<YUVVideoDrawQuad>(this)); |
+ break; |
+ case RenderPass: // RenderPass quads have their own copy() method. |
case Invalid: |
+ CRASH(); |
break; |
} |
- |
- CRASH(); |
- return sizeof(DrawQuad); |
-} |
- |
-scoped_ptr<DrawQuad> DrawQuad::copy(const SharedQuadState* copiedSharedQuadState) const |
-{ |
- // RenderPass quads have their own copy() method. |
- DCHECK(material() != RenderPass); |
- |
- unsigned bytes = size(); |
- DCHECK(bytes > 0); |
- |
- scoped_ptr<DrawQuad> copyQuad(reinterpret_cast<DrawQuad*>(new char[bytes])); |
- memcpy(copyQuad.get(), this, bytes); |
copyQuad->setSharedQuadState(copiedSharedQuadState); |
- |
return copyQuad.Pass(); |
} |