Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4350)

Unified Diff: cc/draw_quad.cc

Issue 11344050: Fix DrawQuad copy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/draw_quad.h ('k') | cc/draw_quad_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « cc/draw_quad.h ('k') | cc/draw_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698