Bug 843666 - Implement color-buffer-(half-)float for WebGL. - r=kamidphish

This commit is contained in:
Jeff Gilbert 2014-03-07 13:26:17 -08:00
parent d13d414bf0
commit bdd584a1f9
17 changed files with 376 additions and 27 deletions

View File

@ -896,6 +896,7 @@ protected:
// -------------------------------------------------------------------------
// WebGL extensions (implemented in WebGLContextExtensions.cpp)
enum WebGLExtensionID {
EXT_color_buffer_half_float,
EXT_frag_depth,
EXT_sRGB,
EXT_texture_filter_anisotropic,
@ -906,6 +907,7 @@ protected:
OES_texture_half_float,
OES_texture_half_float_linear,
OES_vertex_array_object,
WEBGL_color_buffer_float,
WEBGL_compressed_texture_atc,
WEBGL_compressed_texture_pvrtc,
WEBGL_compressed_texture_s3tc,
@ -934,7 +936,6 @@ protected:
nsTArray<GLenum> mCompressedTextureFormats;
// -------------------------------------------------------------------------
// WebGL 2 specifics (implemented in WebGL2Context.cpp)

View File

@ -17,6 +17,7 @@ using namespace mozilla::gl;
// must match WebGLContext::WebGLExtensionID
static const char *sExtensionNames[] = {
"EXT_color_buffer_half_float",
"EXT_frag_depth",
"EXT_sRGB",
"EXT_texture_filter_anisotropic",
@ -27,6 +28,7 @@ static const char *sExtensionNames[] = {
"OES_texture_half_float",
"OES_texture_half_float_linear",
"OES_vertex_array_object",
"WEBGL_color_buffer_float",
"WEBGL_compressed_texture_atc",
"WEBGL_compressed_texture_pvrtc",
"WEBGL_compressed_texture_s3tc",
@ -108,6 +110,10 @@ bool WebGLContext::IsExtensionSupported(WebGLExtensionID ext) const
gl->IsSupported(GLFeature::texture_half_float);
case OES_texture_half_float_linear:
return gl->IsSupported(GLFeature::texture_half_float_linear);
case WEBGL_color_buffer_float:
return WebGLExtensionColorBufferFloat::IsSupported(this);
case EXT_color_buffer_half_float:
return WebGLExtensionColorBufferHalfFloat::IsSupported(this);
case OES_vertex_array_object:
return WebGLExtensionVertexArray::IsSupported(this);
case EXT_texture_filter_anisotropic:
@ -286,6 +292,12 @@ WebGLContext::EnableExtension(WebGLExtensionID ext)
case OES_texture_half_float_linear:
obj = new WebGLExtensionTextureHalfFloatLinear(this);
break;
case WEBGL_color_buffer_float:
obj = new WebGLExtensionColorBufferFloat(this);
break;
case EXT_color_buffer_half_float:
obj = new WebGLExtensionColorBufferHalfFloat(this);
break;
case WEBGL_draw_buffers:
obj = new WebGLExtensionDrawBuffers(this);
break;

View File

@ -1389,8 +1389,47 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
return JS::NumberValue(uint32_t(LOCAL_GL_RENDERBUFFER));
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
{
return WebGLObjectAsJSValue(cx, fba.Renderbuffer(), rv);
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: {
if (!IsExtensionEnabled(EXT_color_buffer_half_float) &&
!IsExtensionEnabled(WEBGL_color_buffer_float))
{
break;
}
if (attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
ErrorInvalidOperation("getFramebufferAttachmentParameter: Cannot get component"
" type of a depth-stencil attachment.");
return JS::NullValue();
}
if (!fba.IsComplete())
return JS::NumberValue(uint32_t(LOCAL_GL_NONE));
uint32_t ret = LOCAL_GL_NONE;
switch (fba.Renderbuffer()->InternalFormat()) {
case LOCAL_GL_RGBA4:
case LOCAL_GL_RGB5_A1:
case LOCAL_GL_RGB565:
case LOCAL_GL_SRGB8_ALPHA8:
ret = LOCAL_GL_UNSIGNED_NORMALIZED;
break;
case LOCAL_GL_RGB16F:
case LOCAL_GL_RGBA16F:
case LOCAL_GL_RGB32F:
case LOCAL_GL_RGBA32F:
ret = LOCAL_GL_FLOAT;
break;
case LOCAL_GL_DEPTH_COMPONENT16:
case LOCAL_GL_STENCIL_INDEX8:
ret = LOCAL_GL_UNSIGNED_INT;
break;
default:
MOZ_ASSERT(false, "Unhandled RB component type.");
break;
}
return JS::NumberValue(uint32_t(ret));
}
}
@ -1413,20 +1452,58 @@ WebGLContext::GetFramebufferAttachmentParameter(JSContext* cx,
return JS::NumberValue(uint32_t(LOCAL_GL_TEXTURE));
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
{
return WebGLObjectAsJSValue(cx, fba.Texture(), rv);
}
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
return JS::Int32Value(fba.TexImageLevel());
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
{
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: {
GLenum face = fba.TexImageTarget();
if (face == LOCAL_GL_TEXTURE_2D)
face = 0;
return JS::Int32Value(face);
}
case LOCAL_GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: {
if (!IsExtensionEnabled(EXT_color_buffer_half_float) &&
!IsExtensionEnabled(WEBGL_color_buffer_float))
{
break;
}
if (attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
ErrorInvalidOperation("getFramebufferAttachmentParameter: cannot component"
" type of depth-stencil attachments.");
return JS::NullValue();
}
if (!fba.IsComplete())
return JS::NumberValue(uint32_t(LOCAL_GL_NONE));
uint32_t ret = LOCAL_GL_NONE;
GLenum type = fba.Texture()->ImageInfoAt(fba.TexImageTarget(),
fba.TexImageLevel()).Type();
switch (type) {
case LOCAL_GL_UNSIGNED_BYTE:
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
ret = LOCAL_GL_UNSIGNED_NORMALIZED;
break;
case LOCAL_GL_FLOAT:
case LOCAL_GL_HALF_FLOAT_OES:
ret = LOCAL_GL_FLOAT;
break;
case LOCAL_GL_UNSIGNED_SHORT:
case LOCAL_GL_UNSIGNED_INT:
ret = LOCAL_GL_UNSIGNED_INT;
break;
default:
MOZ_ASSERT(false, "Unhandled RB component type.");
break;
}
return JS::NumberValue(uint32_t(ret));
}
}
ErrorInvalidEnumInfo("getFramebufferAttachmentParameter: pname", pname);
@ -2247,9 +2324,8 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
GLenum type, const Nullable<ArrayBufferView> &pixels,
ErrorResult& rv)
{
if (IsContextLost()) {
if (IsContextLost())
return;
}
if (mCanvasElement->IsWriteOnly() && !nsContentUtils::IsCallerChrome()) {
GenerateWarning("readPixels: Not allowed");
@ -2287,20 +2363,34 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
int requiredDataType = 0;
// Check the type param
bool isReadTypeValid = false;
bool isReadTypeFloat = false;
switch (type) {
case LOCAL_GL_UNSIGNED_BYTE:
bytesPerPixel = 1 * channels;
isReadTypeValid = true;
bytesPerPixel = 1*channels;
requiredDataType = js::ArrayBufferView::TYPE_UINT8;
break;
case LOCAL_GL_UNSIGNED_SHORT_4_4_4_4:
case LOCAL_GL_UNSIGNED_SHORT_5_5_5_1:
case LOCAL_GL_UNSIGNED_SHORT_5_6_5:
isReadTypeValid = true;
bytesPerPixel = 2;
requiredDataType = js::ArrayBufferView::TYPE_UINT16;
break;
default:
return ErrorInvalidEnum("readPixels: Bad type");
case LOCAL_GL_FLOAT:
if (IsExtensionEnabled(WEBGL_color_buffer_float) ||
IsExtensionEnabled(EXT_color_buffer_half_float))
{
isReadTypeValid = true;
isReadTypeFloat = true;
bytesPerPixel = 4*channels;
requiredDataType = js::ArrayBufferView::TYPE_FLOAT32;
}
break;
}
if (!isReadTypeValid)
return ErrorInvalidEnum("readPixels: Bad type", type);
int dataType = JS_GetArrayBufferViewType(pixels.Value().Obj());
@ -2330,12 +2420,25 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
return rv.Throw(NS_ERROR_OUT_OF_MEMORY);
}
bool isSourceTypeFloat = false;
if (mBoundFramebuffer &&
mBoundFramebuffer->ColorAttachmentCount() &&
mBoundFramebuffer->ColorAttachment(0).IsDefined())
{
isSourceTypeFloat = mBoundFramebuffer->ColorAttachment(0).IsReadableFloat();
}
if (isReadTypeFloat != isSourceTypeFloat)
return ErrorInvalidOperation("readPixels: Invalid type floatness");
// Check the format and type params to assure they are an acceptable pair (as per spec)
switch (format) {
case LOCAL_GL_RGBA: {
switch (type) {
case LOCAL_GL_UNSIGNED_BYTE:
break;
case LOCAL_GL_FLOAT:
break;
default:
return ErrorInvalidOperation("readPixels: Invalid format/type pair");
}
@ -2463,6 +2566,20 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width,
rowp += 4;
}
row += checked_alignedRowSize.value();
}
} else if (format == LOCAL_GL_RGBA && type == LOCAL_GL_FLOAT) {
float* row = static_cast<float*>(data);
for (GLint j = 0; j < height; ++j) {
float* pAlpha = row + 3;
float* pAlphaEnd = pAlpha + 4*width;
while (pAlpha != pAlphaEnd) {
*pAlpha = 1.0f;
pAlpha += 4;
}
row += checked_alignedRowSize.value();
}
} else {
@ -2518,6 +2635,22 @@ WebGLContext::RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei
break;
case LOCAL_GL_SRGB8_ALPHA8_EXT:
break;
case LOCAL_GL_RGB16F:
case LOCAL_GL_RGBA16F: {
bool hasExtensions = IsExtensionEnabled(OES_texture_half_float) &&
IsExtensionEnabled(EXT_color_buffer_half_float);
if (!hasExtensions)
return ErrorInvalidEnumInfo("renderbufferStorage: internalformat", target);
break;
}
case LOCAL_GL_RGB32F:
case LOCAL_GL_RGBA32F: {
bool hasExtensions = IsExtensionEnabled(OES_texture_float) &&
IsExtensionEnabled(WEBGL_color_buffer_float);
if (!hasExtensions)
return ErrorInvalidEnumInfo("renderbufferStorage: internalformat", target);
break;
}
default:
return ErrorInvalidEnumInfo("renderbufferStorage: internalformat", internalformat);
}
@ -3911,8 +4044,13 @@ WebGLContext::TexSubImage2D_base(GLenum target, GLint level,
// convert type for half float if not on GLES2
GLenum realType = type;
if (realType == LOCAL_GL_HALF_FLOAT_OES && !gl->IsGLES2())
realType = LOCAL_GL_HALF_FLOAT;
if (realType == LOCAL_GL_HALF_FLOAT_OES) {
if (gl->IsSupported(gl::GLFeature::texture_half_float)) {
realType = LOCAL_GL_HALF_FLOAT;
} else {
MOZ_ASSERT(gl->IsExtensionSupported(gl::GLContext::OES_texture_half_float));
}
}
if (actualSrcFormat == dstFormat &&
srcPremultiplied == mPixelStorePremultiplyAlpha &&

View File

@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLExtensions.h"
#include "GLContext.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "WebGLContext.h"
using namespace mozilla;
WebGLExtensionColorBufferFloat::WebGLExtensionColorBufferFloat(WebGLContext* context)
: WebGLExtensionBase(context)
{
MOZ_ASSERT(IsSupported(context));
}
WebGLExtensionColorBufferFloat::~WebGLExtensionColorBufferFloat()
{
}
bool
WebGLExtensionColorBufferFloat::IsSupported(const WebGLContext* context)
{
return context->GL()->IsSupported(gl::GLFeature::renderbuffer_color_float) &&
context->GL()->IsSupported(gl::GLFeature::frag_color_float);
}
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionColorBufferFloat)

View File

@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLExtensions.h"
#include "GLContext.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "WebGLContext.h"
using namespace mozilla;
WebGLExtensionColorBufferHalfFloat::WebGLExtensionColorBufferHalfFloat(WebGLContext* context)
: WebGLExtensionBase(context)
{
MOZ_ASSERT(IsSupported(context));
}
WebGLExtensionColorBufferHalfFloat::~WebGLExtensionColorBufferHalfFloat()
{
}
bool
WebGLExtensionColorBufferHalfFloat::IsSupported(const WebGLContext* context)
{
return context->GL()->IsSupported(gl::GLFeature::renderbuffer_color_half_float) &&
context->GL()->IsSupported(gl::GLFeature::frag_color_float);
}
IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionColorBufferHalfFloat)

View File

@ -213,6 +213,30 @@ public:
DECL_WEBGL_EXTENSION_GOOP
};
class WebGLExtensionColorBufferFloat
: public WebGLExtensionBase
{
public:
WebGLExtensionColorBufferFloat(WebGLContext*);
virtual ~WebGLExtensionColorBufferFloat();
static bool IsSupported(const WebGLContext*);
DECL_WEBGL_EXTENSION_GOOP
};
class WebGLExtensionColorBufferHalfFloat
: public WebGLExtensionBase
{
public:
WebGLExtensionColorBufferHalfFloat(WebGLContext*);
virtual ~WebGLExtensionColorBufferHalfFloat();
static bool IsSupported(const WebGLContext*);
DECL_WEBGL_EXTENSION_GOOP
};
class WebGLExtensionDrawBuffers
: public WebGLExtensionBase
{

View File

@ -60,6 +60,35 @@ WebGLFramebuffer::Attachment::HasAlpha() const
return FormatHasAlpha(format);
}
bool
WebGLFramebuffer::Attachment::IsReadableFloat() const
{
if (Texture() && Texture()->HasImageInfoAt(mTexImageTarget, mTexImageLevel)) {
GLenum type = Texture()->ImageInfoAt(mTexImageTarget, mTexImageLevel).Type();
switch (type) {
case LOCAL_GL_FLOAT:
case LOCAL_GL_HALF_FLOAT_OES:
return true;
}
return false;
}
if (Renderbuffer()) {
GLenum format = Renderbuffer()->InternalFormat();
switch (format) {
case LOCAL_GL_RGB16F:
case LOCAL_GL_RGBA16F:
case LOCAL_GL_RGB32F:
case LOCAL_GL_RGBA32F:
return true;
}
return false;
}
MOZ_ASSERT(false, "Should not get here.");
return false;
}
void
WebGLFramebuffer::Attachment::SetTexImage(WebGLTexture* tex, GLenum target, GLint level)
{

View File

@ -53,6 +53,7 @@ public:
bool IsDeleteRequested() const;
bool HasAlpha() const;
bool IsReadableFloat() const;
void SetTexImage(WebGLTexture* tex, GLenum target, GLint level);
void SetRenderbuffer(WebGLRenderbuffer* rb) {

View File

@ -95,13 +95,13 @@ WebGLRenderbuffer::MemoryUsage() const {
int64_t primarySize = 0;
switch (primaryFormat) {
case LOCAL_GL_STENCIL_INDEX8:
primarySize = 1 * pixels;
primarySize = 1*pixels;
break;
case LOCAL_GL_RGBA4:
case LOCAL_GL_RGB5_A1:
case LOCAL_GL_RGB565:
case LOCAL_GL_DEPTH_COMPONENT16:
primarySize = 2 * pixels;
primarySize = 2*pixels;
break;
case LOCAL_GL_RGB8:
case LOCAL_GL_DEPTH_COMPONENT24:
@ -113,6 +113,18 @@ WebGLRenderbuffer::MemoryUsage() const {
case LOCAL_GL_DEPTH_COMPONENT32:
primarySize = 4*pixels;
break;
case LOCAL_GL_RGB16F:
primarySize = 2*3*pixels;
break;
case LOCAL_GL_RGBA16F:
primarySize = 2*4*pixels;
break;
case LOCAL_GL_RGB32F:
primarySize = 4*3*pixels;
break;
case LOCAL_GL_RGBA32F:
primarySize = 4*4*pixels;
break;
default:
MOZ_ASSERT(false, "Unknown `primaryFormat`.");
break;

View File

@ -49,8 +49,8 @@ int64_t
WebGLTexture::ImageInfo::MemoryUsage() const {
if (mImageDataStatus == WebGLImageDataStatus::NoImageData)
return 0;
int64_t texelSizeInBits = WebGLContext::GetBitsPerTexel(mInternalFormat, mType);
return int64_t(mWidth) * int64_t(mHeight) * texelSizeInBits / 8;
int64_t bitsPerTexel = WebGLContext::GetBitsPerTexel(mInternalFormat, mType);
return int64_t(mWidth) * int64_t(mHeight) * bitsPerTexel/8;
}
int64_t

View File

@ -44,6 +44,8 @@ if CONFIG['MOZ_WEBGL']:
'WebGLContextVertices.cpp',
'WebGLElementArrayCache.cpp',
'WebGLExtensionBase.cpp',
'WebGLExtensionColorBufferFloat.cpp',
'WebGLExtensionColorBufferHalfFloat.cpp',
'WebGLExtensionCompressedTextureATC.cpp',
'WebGLExtensionCompressedTexturePVRTC.cpp',
'WebGLExtensionCompressedTextureS3TC.cpp',

View File

@ -1342,6 +1342,16 @@ DOMInterfaces = {
'headerFile': 'WebGLExtensions.h'
},
'WebGLExtensionColorBufferFloat': {
'nativeType': 'mozilla::WebGLExtensionColorBufferFloat',
'headerFile': 'WebGLExtensions.h'
},
'WebGLExtensionColorBufferHalfFloat': {
'nativeType': 'mozilla::WebGLExtensionColorBufferHalfFloat',
'headerFile': 'WebGLExtensions.h'
},
'WebGLExtensionDrawBuffers': {
'nativeType': 'mozilla::WebGLExtensionDrawBuffers',
'headerFile': 'WebGLExtensions.h'

View File

@ -917,6 +917,24 @@ interface WebGLExtensionTextureHalfFloatLinear
{
};
[NoInterfaceObject]
interface WebGLExtensionColorBufferFloat
{
const GLenum RGBA32F_EXT = 0x8814;
const GLenum RGB32F_EXT = 0x8815;
const GLenum FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT = 0x8211;
const GLenum UNSIGNED_NORMALIZED_EXT = 0x8C17;
};
[NoInterfaceObject]
interface WebGLExtensionColorBufferHalfFloat
{
const GLenum RGBA16F_EXT = 0x881A;
const GLenum RGB16F_EXT = 0x881B;
const GLenum FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT = 0x8211;
const GLenum UNSIGNED_NORMALIZED_EXT = 0x8C17;
};
[NoInterfaceObject]
interface WebGLExtensionVertexArray {
const GLenum VERTEX_ARRAY_BINDING_OES = 0x85B5;

View File

@ -86,6 +86,9 @@ static const char *sExtensionNames[] = {
"GL_OES_texture_half_float",
"GL_OES_texture_half_float_linear",
"GL_NV_half_float",
"GL_EXT_color_buffer_float",
"GL_EXT_color_buffer_half_float",
"GL_ARB_color_buffer_float",
"GL_EXT_unpack_subimage",
"GL_OES_standard_derivatives",
"GL_EXT_texture_filter_anisotropic",

View File

@ -90,6 +90,7 @@ MOZ_BEGIN_ENUM_CLASS(GLFeature)
element_index_uint,
ES2_compatibility,
ES3_compatibility,
frag_color_float,
frag_depth,
framebuffer_blit,
framebuffer_multisample,
@ -102,6 +103,8 @@ MOZ_BEGIN_ENUM_CLASS(GLFeature)
occlusion_query2,
packed_depth_stencil,
query_objects,
renderbuffer_color_float,
renderbuffer_color_half_float,
robustness,
sRGB,
standard_derivatives,
@ -365,6 +368,9 @@ public:
OES_texture_half_float,
OES_texture_half_float_linear,
NV_half_float,
EXT_color_buffer_float,
EXT_color_buffer_half_float,
ARB_color_buffer_float,
EXT_unpack_subimage,
OES_standard_derivatives,
EXT_texture_filter_anisotropic,

View File

@ -111,6 +111,18 @@ static const FeatureInfo sFeatureInfoArr[] = {
GLContext::Extensions_End
}
},
{
// Removes clamping for float color outputs from frag shaders.
"frag_color_float",
300, // OpenGL version
300, // OpenGL ES version
{
GLContext::ARB_color_buffer_float,
GLContext::EXT_color_buffer_float,
GLContext::EXT_color_buffer_half_float,
GLContext::Extensions_End
}
},
{
"frag_depth",
200, // OpenGL version
@ -252,6 +264,26 @@ static const FeatureInfo sFeatureInfoArr[] = {
* (added in OpenGL ES 3.0)
*/
},
{
"renderbuffer_float",
300, // OpenGL version
300, // OpenGL ES version
{
GLContext::ARB_texture_float,
GLContext::EXT_color_buffer_float,
GLContext::Extensions_End
}
},
{
"renderbuffer_half_float",
300, // OpenGL version
300, // OpenGL ES version
{
GLContext::ARB_texture_float,
GLContext::EXT_color_buffer_half_float,
GLContext::Extensions_End
}
},
{
"robustness",
0, // OpenGL version
@ -282,7 +314,7 @@ static const FeatureInfo sFeatureInfoArr[] = {
},
{
"texture_float",
310, // OpenGL version
300, // OpenGL version
300, // OpenGL ES version
{
GLContext::ARB_texture_float,
@ -302,7 +334,7 @@ static const FeatureInfo sFeatureInfoArr[] = {
},
{
"texture_half_float",
310, // OpenGL version
300, // OpenGL version
300, // OpenGL ES version
{
GLContext::ARB_half_float_pixel,

View File

@ -14,7 +14,8 @@ NS_IMPL_ISUPPORTS1(GfxTexturesReporter, nsIMemoryReporter)
int64_t GfxTexturesReporter::sAmount = 0;
static uint32_t GetBitsPerTexel(GLenum format, GLenum type)
static uint32_t
GetBitsPerTexel(GLenum format, GLenum type)
{
// If there is no defined format or type, we're not taking up any memory
if (!format || !type) {
@ -23,16 +24,16 @@ static uint32_t GetBitsPerTexel(GLenum format, GLenum type)
if (format == LOCAL_GL_DEPTH_COMPONENT) {
if (type == LOCAL_GL_UNSIGNED_SHORT)
return 2;
return 2*8;
else if (type == LOCAL_GL_UNSIGNED_INT)
return 4;
return 4*8;
} else if (format == LOCAL_GL_DEPTH_STENCIL) {
if (type == LOCAL_GL_UNSIGNED_INT_24_8_EXT)
return 4;
return 4*8;
}
if (type == LOCAL_GL_UNSIGNED_BYTE || type == LOCAL_GL_FLOAT) {
int multiplier = type == LOCAL_GL_FLOAT ? 32 : 8;
uint32_t multiplier = type == LOCAL_GL_FLOAT ? 32 : 8;
switch (format) {
case LOCAL_GL_ALPHA:
case LOCAL_GL_LUMINANCE:
@ -64,7 +65,7 @@ static uint32_t GetBitsPerTexel(GLenum format, GLenum type)
type == LOCAL_GL_UNSIGNED_SHORT_5_5_5_1 ||
type == LOCAL_GL_UNSIGNED_SHORT_5_6_5)
{
return 16;
return 2*8;
}
MOZ_ASSERT(false);
@ -75,8 +76,8 @@ static uint32_t GetBitsPerTexel(GLenum format, GLenum type)
GfxTexturesReporter::UpdateAmount(MemoryUse action, GLenum format,
GLenum type, uint16_t tileSize)
{
uint32_t bytesPerTexel = GetBitsPerTexel(format, type) / 8;
int64_t bytes = (int64_t)(tileSize * tileSize * bytesPerTexel);
int64_t bitsPerTexel = GetBitsPerTexel(format, type);
int64_t bytes = int64_t(tileSize) * int64_t(tileSize) * bitsPerTexel/8;
if (action == MemoryFreed) {
sAmount -= bytes;
} else {