Bug 959154 - Part 8: Moz2Dify GLUploadHelpers. r=nical

This commit is contained in:
Andreas Pehrson 2014-02-13 17:28:48 +01:00
parent 3b57ddea97
commit 1cdf85e70e
2 changed files with 37 additions and 78 deletions

View File

@ -8,9 +8,6 @@
#include "GLContext.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Tools.h" // For BytesPerPixel
#include "gfxASurface.h"
#include "gfxUtils.h"
#include "gfxContext.h"
#include "nsRegion.h"
namespace mozilla {
@ -19,6 +16,39 @@ 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 nsIntPoint &aPoint, int32_t aStride, SurfaceFormat aFormat)
{
@ -255,13 +285,13 @@ TexImage2DHelper(GLContext *gl,
if (!CanUploadNonPowerOfTwo(gl)
&& (stride != width * pixelsize
|| !gfx::IsPowerOfTwo(width)
|| !gfx::IsPowerOfTwo(height))) {
|| !IsPowerOfTwo(width)
|| !IsPowerOfTwo(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
GLsizei paddedWidth = gfx::NextPowerOfTwo(width);
GLsizei paddedHeight = gfx::NextPowerOfTwo(height);
GLsizei paddedWidth = NextPowerOfTwo(width);
GLsizei paddedHeight = NextPowerOfTwo(height);
GLvoid* paddedPixels = new unsigned char[paddedWidth * paddedHeight * pixelsize];
@ -494,61 +524,6 @@ UploadImageDataToTexture(GLContext* gl,
return surfaceFormat;
}
SurfaceFormat
DeprecatedUploadSurfaceToTexture(GLContext* gl,
gfxASurface *aSurface,
const nsIntRegion& aDstRegion,
GLuint& aTexture,
bool aOverwrite,
const nsIntPoint& aSrcPoint,
bool aPixelBuffer,
GLenum aTextureUnit,
GLenum aTextureTarget)
{
nsRefPtr<gfxImageSurface> imageSurface = aSurface->GetAsImageSurface();
unsigned char* data = nullptr;
if (!imageSurface ||
(imageSurface->Format() != gfxImageFormat::ARGB32 &&
imageSurface->Format() != gfxImageFormat::RGB24 &&
imageSurface->Format() != gfxImageFormat::RGB16_565 &&
imageSurface->Format() != gfxImageFormat::A8)) {
// We can't get suitable pixel data for the surface, make a copy
nsIntRect bounds = aDstRegion.GetBounds();
imageSurface =
new gfxImageSurface(gfxIntSize(bounds.width, bounds.height),
gfxImageFormat::ARGB32);
nsRefPtr<gfxContext> context = new gfxContext(imageSurface);
context->Translate(-gfxPoint(aSrcPoint.x, aSrcPoint.y));
context->SetSource(aSurface);
context->Paint();
data = imageSurface->Data();
NS_ASSERTION(!aPixelBuffer,
"Must be using an image compatible surface with pixel buffers!");
} else {
// If a pixel buffer is bound the data pointer parameter is relative
// to the start of the data block.
if (!aPixelBuffer) {
data = imageSurface->Data();
}
data += DataOffset(aSrcPoint, imageSurface->Stride(),
ImageFormatToSurfaceFormat(imageSurface->Format()));
}
MOZ_ASSERT(imageSurface);
imageSurface->Flush();
return UploadImageDataToTexture(gl,
data,
imageSurface->Stride(),
ImageFormatToSurfaceFormat(imageSurface->Format()),
aDstRegion, aTexture, aOverwrite,
aPixelBuffer, aTextureUnit, aTextureTarget);
}
SurfaceFormat
UploadSurfaceToTexture(GLContext* gl,
DataSourceSurface *aSurface,

View File

@ -7,11 +7,9 @@
#define GLUploadHelpers_h_
#include "GLDefs.h"
#include "gfxTypes.h"
#include "mozilla/gfx/Types.h"
#include "nsPoint.h"
class gfxASurface;
class nsIntRegion;
namespace mozilla {
@ -67,20 +65,6 @@ UploadImageDataToTexture(GLContext* gl,
GLenum aTextureUnit = LOCAL_GL_TEXTURE0,
GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D);
/**
* Convenience wrapper around UploadImageDataToTexture for gfxASurfaces.
*/
gfx::SurfaceFormat
DeprecatedUploadSurfaceToTexture(GLContext* gl,
gfxASurface *aSurface,
const nsIntRegion& aDstRegion,
GLuint& aTexture,
bool aOverwrite = false,
const nsIntPoint& aSrcPoint = nsIntPoint(0, 0),
bool aPixelBuffer = false,
GLenum aTextureUnit = LOCAL_GL_TEXTURE0,
GLenum aTextureTarget = LOCAL_GL_TEXTURE_2D);
/**
* Convenience wrapper around UploadImageDataToTexture for gfx::DataSourceSurface's.
*/