From c9a470f6fb89909eb075a2282f01db01e30fea3e Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 27 Sep 2013 17:20:28 +0200 Subject: [PATCH] Bug 912945 - Use aligned data storage for DrawTargetCG. r=jrmuizel --- gfx/2d/DrawTargetCG.cpp | 17 ++++------------- gfx/2d/DrawTargetCG.h | 13 ++++++------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/gfx/2d/DrawTargetCG.cpp b/gfx/2d/DrawTargetCG.cpp index 100d0055d3d..65eee44199f 100644 --- a/gfx/2d/DrawTargetCG.cpp +++ b/gfx/2d/DrawTargetCG.cpp @@ -152,7 +152,6 @@ DrawTargetCG::~DrawTargetCG() CGColorSpaceRelease(mColorSpace); if (mCg) CGContextRelease(mCg); - free(mData); } BackendType @@ -1188,7 +1187,6 @@ DrawTargetCG::Init(BackendType aType, aSize.width > 32767 || aSize.height > 32767) { mColorSpace = nullptr; mCg = nullptr; - mData = nullptr; return false; } @@ -1199,12 +1197,9 @@ DrawTargetCG::Init(BackendType aType, if (aData == nullptr && aType != BACKEND_COREGRAPHICS_ACCELERATED) { // XXX: Currently, Init implicitly clears, that can often be a waste of time - mData = calloc(aSize.height * aStride, 1); - aData = static_cast(mData); - } else { - // mData == nullptr means DrawTargetCG doesn't own the image data and will not - // delete it in the destructor - mData = nullptr; + mData.Realloc(aStride * aSize.height); + aData = static_cast(mData); + memset(aData, 0, aStride * aSize.height); } mSize = aSize; @@ -1214,7 +1209,6 @@ DrawTargetCG::Init(BackendType aType, mCg = ioSurface->CreateIOSurfaceContext(); // If we don't have the symbol for 'CreateIOSurfaceContext' mCg will be null // and we will fallback to software below - mData = nullptr; } mFormat = FORMAT_B8G8R8A8; @@ -1287,7 +1281,6 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize) if (aSize.width == 0 || aSize.height == 0) { mColorSpace = nullptr; mCg = nullptr; - mData = nullptr; return false; } @@ -1301,8 +1294,6 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize) mCg = cgContext; CGContextRetain(mCg); - mData = nullptr; - assert(mCg); // CGContext's default to have the origin at the bottom left. @@ -1331,7 +1322,7 @@ DrawTargetCG::Init(CGContextRef cgContext, const IntSize &aSize) bool DrawTargetCG::Init(BackendType aType, const IntSize &aSize, SurfaceFormat &aFormat) { - int stride = aSize.width*4; + int32_t stride = GetAlignedStride<16>(aSize.width * BytesPerPixel(aFormat)); // Calling Init with aData == nullptr will allocate. return Init(aType, nullptr, aSize, stride, aFormat); diff --git a/gfx/2d/DrawTargetCG.h b/gfx/2d/DrawTargetCG.h index d2edc3669fb..7b21930983c 100644 --- a/gfx/2d/DrawTargetCG.h +++ b/gfx/2d/DrawTargetCG.h @@ -10,6 +10,7 @@ #include "PathCG.h" #include "SourceSurfaceCG.h" #include "GLDefs.h" +#include "Tools.h" namespace mozilla { namespace gfx { @@ -157,14 +158,12 @@ private: CGContextRef mCg; /** - * A pointer to the image buffer if the buffer is owned by this class (set to - * nullptr otherwise). - * The data is not considered owned by DrawTargetCG if the DrawTarget was - * created for a pre-existing buffer or if the buffer's lifetime is managed - * by CoreGraphics. - * Data owned by DrawTargetCG will be deallocated in the destructor. + * The image buffer, if the buffer is owned by this class. + * If the DrawTarget was created for a pre-existing buffer or if the buffer's + * lifetime is managed by CoreGraphics, mData will be null. + * Data owned by DrawTargetCG will be deallocated in the destructor. */ - void *mData; + AlignedArray mData; RefPtr mSnapshot; };