зеркало из https://github.com/mozilla/pjs.git
Bug 629799, part 2: Ensure that gfxImageSurfaces are aligned well for alpha recovery. r=roc
This commit is contained in:
Родитель
5396078f80
Коммит
eb88026f02
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
#include "prmem.h"
|
#include "prmem.h"
|
||||||
|
|
||||||
|
#include "gfxAlphaRecovery.h"
|
||||||
#include "gfxImageSurface.h"
|
#include "gfxImageSurface.h"
|
||||||
|
|
||||||
#include "cairo.h"
|
#include "cairo.h"
|
||||||
|
@ -96,6 +97,24 @@ gfxImageSurface::InitWithData(unsigned char *aData, const gfxIntSize& aSize,
|
||||||
Init(surface);
|
Init(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void*
|
||||||
|
TryAllocAlignedBytes(size_t aSize)
|
||||||
|
{
|
||||||
|
// Use fallible allocators here
|
||||||
|
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
|
||||||
|
void* ptr;
|
||||||
|
// Try to align for fast alpha recovery. This should only help
|
||||||
|
// cairo too, can't hurt.
|
||||||
|
return moz_posix_memalign(&ptr,
|
||||||
|
1 << gfxAlphaRecovery::GoodAlignmentLog2(),
|
||||||
|
aSize) ?
|
||||||
|
nsnull : ptr;
|
||||||
|
#else
|
||||||
|
// Oh well, hope that luck is with us in the allocator
|
||||||
|
return moz_malloc(aSize);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format) :
|
gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format) :
|
||||||
mSize(size), mOwnsData(PR_FALSE), mData(nsnull), mFormat(format)
|
mSize(size), mOwnsData(PR_FALSE), mData(nsnull), mFormat(format)
|
||||||
{
|
{
|
||||||
|
@ -107,8 +126,9 @@ gfxImageSurface::gfxImageSurface(const gfxIntSize& size, gfxImageFormat format)
|
||||||
// if we have a zero-sized surface, just leave mData nsnull
|
// if we have a zero-sized surface, just leave mData nsnull
|
||||||
if (mSize.height * mStride > 0) {
|
if (mSize.height * mStride > 0) {
|
||||||
|
|
||||||
// Use the fallible allocator here
|
// This can fail to allocate memory aligned as we requested,
|
||||||
mData = (unsigned char *) moz_malloc(mSize.height * mStride);
|
// or it can fail to allocate any memory at all.
|
||||||
|
mData = (unsigned char *) TryAllocAlignedBytes(mSize.height * mStride);
|
||||||
if (!mData)
|
if (!mData)
|
||||||
return;
|
return;
|
||||||
memset(mData, 0, mSize.height * mStride);
|
memset(mData, 0, mSize.height * mStride);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче