Bug 1288649 - Use mfbt IsPowerOfTwo funcs in gfx/. - r=jrmuizel

While fixing non-unified-build errors in dom/canvas, I started hitting a
static_assert that we were calling IsPowerOfTwo with a signed type. It
turns out we have at least three copies of IsPowerOfTwo() in the tree.
Let's drop the non-mfbt ones.

MozReview-Commit-ID: 1fwQw0CrgiE
This commit is contained in:
Jeff Gilbert 2016-07-22 00:51:18 -07:00
parent 407bc3c38c
commit 017f27acce
2 changed files with 8 additions and 62 deletions

View File

@ -7,6 +7,7 @@
#include "GLContext.h"
#include "mozilla/gfx/2D.h"
#include "gfxUtils.h"
#include "mozilla/gfx/Tools.h" // For BytesPerPixel
#include "nsRegion.h"
#include "GfxTexturesReporter.h"
@ -18,39 +19,6 @@ using namespace gfx;
namespace gl {
/* These two techniques are suggested by "Bit Twiddling Hacks"
*/
/**
* Returns true if |aNumber| is a power of two
* 0 is incorreclty considered a power of two
*/
static bool
IsPowerOfTwo(int aNumber)
{
return (aNumber & (aNumber - 1)) == 0;
}
/**
* Returns the first integer greater than |aNumber| which is a power of two
* Undefined for |aNumber| < 0
*/
static int
NextPowerOfTwo(int aNumber)
{
#if defined(__arm__)
return 1 << (32 - __builtin_clz(aNumber - 1));
#else
--aNumber;
aNumber |= aNumber >> 1;
aNumber |= aNumber >> 2;
aNumber |= aNumber >> 4;
aNumber |= aNumber >> 8;
aNumber |= aNumber >> 16;
return ++aNumber;
#endif
}
static unsigned int
DataOffset(const IntPoint& aPoint, int32_t aStride, SurfaceFormat aFormat)
{
@ -285,10 +253,11 @@ TexImage2DHelper(GLContext* gl,
NS_ASSERTION(format == (GLenum)internalformat,
"format and internalformat not the same for glTexImage2D on GLES2");
MOZ_ASSERT(width >= 0 && height >= 0);
if (!CanUploadNonPowerOfTwo(gl)
&& (stride != width * pixelsize
|| !IsPowerOfTwo(width)
|| !IsPowerOfTwo(height))) {
|| !IsPowerOfTwo((uint32_t)width)
|| !IsPowerOfTwo((uint32_t)height))) {
// Pad out texture width and height to the next power of two
// as we don't support/want non power of two texture uploads

View File

@ -292,37 +292,14 @@ namespace gfx {
Color ToDeviceColor(Color aColor);
Color ToDeviceColor(nscolor aColor);
/* These techniques are suggested by "Bit Twiddling Hacks"
*/
/**
* Returns true if |aNumber| is a power of two
* 0 is incorreclty considered a power of two
* Returns the first integer greater than |aNumber| which is a power of two.
*/
static inline bool
IsPowerOfTwo(int aNumber)
{
return (aNumber & (aNumber - 1)) == 0;
}
/**
* Returns the first integer greater than or equal to |aNumber| which is a
* power of two. Undefined for |aNumber| < 0.
*/
static inline int
static int
NextPowerOfTwo(int aNumber)
{
#if defined(__arm__)
return 1 << (32 - __builtin_clz(aNumber - 1));
#else
--aNumber;
aNumber |= aNumber >> 1;
aNumber |= aNumber >> 2;
aNumber |= aNumber >> 4;
aNumber |= aNumber >> 8;
aNumber |= aNumber >> 16;
return ++aNumber;
#endif
MOZ_ASSERT(aNumber >= 0);
return RoundUpPow2((size_t)aNumber + 1);
}
/**