0

Fix DrawQuad copy

Creating a copy of the quads by allocating a bag of bytes is problematic because
the delete doesn't match the new (new [] vs scalar delete), which is wrong in
general but in particular causes asserts in tcmalloc and ASAN.
Instead, do the proper C++ version, relying on implicit copy constructors.

BUG=None


Review URL: https://chromiumcodereview.appspot.com/11344050

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165248 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
piman@chromium.org
2012-10-31 22:48:14 +00:00
parent dbfe3dc13a
commit f4bc734c62
6 changed files with 40 additions and 53 deletions

@ -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
{
switch (material()) {
case Checkerboard:
return sizeof(CheckerboardDrawQuad);
case DebugBorder:
return sizeof(DebugBorderDrawQuad);
case IOSurfaceContent:
return sizeof(IOSurfaceDrawQuad);
case TextureContent:
return sizeof(TextureDrawQuad);
case SolidColor:
return sizeof(SolidColorDrawQuad);
case TiledContent:
return sizeof(TileDrawQuad);
case StreamVideoContent:
return sizeof(StreamVideoDrawQuad);
case RenderPass:
return sizeof(RenderPassDrawQuad);
case YUVVideoContent:
return sizeof(YUVVideoDrawQuad);
case Invalid:
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);
scoped_ptr<DrawQuad> copyQuad;
switch (material()) {
case Checkerboard:
copyQuad.reset(TypedCopy<CheckerboardDrawQuad>(this));
break;
case DebugBorder:
copyQuad.reset(TypedCopy<DebugBorderDrawQuad>(this));
break;
case IOSurfaceContent:
copyQuad.reset(TypedCopy<IOSurfaceDrawQuad>(this));
break;
case TextureContent:
copyQuad.reset(TypedCopy<TextureDrawQuad>(this));
break;
case SolidColor:
copyQuad.reset(TypedCopy<SolidColorDrawQuad>(this));
break;
case TiledContent:
copyQuad.reset(TypedCopy<TileDrawQuad>(this));
break;
case StreamVideoContent:
copyQuad.reset(TypedCopy<StreamVideoDrawQuad>(this));
break;
case YUVVideoContent:
copyQuad.reset(TypedCopy<YUVVideoDrawQuad>(this));
break;
case RenderPass: // RenderPass quads have their own copy() method.
case Invalid:
CRASH();
break;
}
copyQuad->setSharedQuadState(copiedSharedQuadState);
return copyQuad.Pass();
}

@ -55,10 +55,6 @@ public:
Material material() const { return m_material; }
// Returns transfer size of this object based on the derived class (by
// looking at the material type).
unsigned size() const;
scoped_ptr<DrawQuad> copy(const SharedQuadState* copiedSharedQuadState) const;
const SharedQuadState* sharedQuadState() const { return m_sharedQuadState; }

@ -62,7 +62,6 @@ scoped_ptr<SharedQuadState> createSharedQuadState()
void compareDrawQuad(DrawQuad* quad, DrawQuad* copy, SharedQuadState* copySharedState)
{
EXPECT_EQ(quad->size(), copy->size());
EXPECT_EQ(quad->material(), copy->material());
EXPECT_EQ(quad->isDebugQuad(), copy->isDebugQuad());
EXPECT_RECT_EQ(quad->quadRect(), copy->quadRect());

@ -36,14 +36,9 @@ const RenderPassDrawQuad* RenderPassDrawQuad::materialCast(const DrawQuad* quad)
scoped_ptr<RenderPassDrawQuad> RenderPassDrawQuad::copy(const SharedQuadState* copiedSharedQuadState, RenderPass::Id copiedRenderPassId) const
{
unsigned bytes = size();
DCHECK(bytes > 0);
scoped_ptr<RenderPassDrawQuad> copyQuad(reinterpret_cast<RenderPassDrawQuad*>(new char[bytes]));
memcpy(copyQuad.get(), this, bytes);
scoped_ptr<RenderPassDrawQuad> copyQuad(new RenderPassDrawQuad(*materialCast(this)));
copyQuad->setSharedQuadState(copiedSharedQuadState);
copyQuad->m_renderPassId = copiedRenderPassId;
return copyQuad.Pass();
}

@ -41,8 +41,6 @@ private:
float m_maskTexCoordScaleY;
float m_maskTexCoordOffsetX;
float m_maskTexCoordOffsetY;
DISALLOW_COPY_AND_ASSIGN(RenderPassDrawQuad);
};
}

@ -27,8 +27,6 @@ private:
VideoLayerImpl::FramePlane m_yPlane;
VideoLayerImpl::FramePlane m_uPlane;
VideoLayerImpl::FramePlane m_vPlane;
DISALLOW_COPY_AND_ASSIGN(YUVVideoDrawQuad);
};
}