Bug 912945 - Use aligned data storage for DrawTargetCG. r=jrmuizel

This commit is contained in:
Markus Stange 2013-09-27 17:20:28 +02:00
parent 737fc61f80
commit c9a470f6fb
2 changed files with 10 additions and 20 deletions

View File

@ -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<unsigned char*>(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<unsigned char*>(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);

View File

@ -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<uint8_t> mData;
RefPtr<SourceSurfaceCGContext> mSnapshot;
};