2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-09-17 23:01:12 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
|
2009-09-04 14:57:33 -07:00
|
|
|
#include "prprf.h"
|
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "jsapi.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIVariant.h"
|
|
|
|
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMDataContainerEvent.h"
|
|
|
|
|
2011-07-06 19:00:02 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
void
|
2012-05-23 09:07:29 -07:00
|
|
|
WebGLContext::GenerateWarning(const char *fmt, ...)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2010-09-13 08:40:01 -07:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, ap);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
va_end(ap);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
void
|
2012-05-23 09:07:29 -07:00
|
|
|
WebGLContext::GenerateWarning(const char *fmt, va_list ap)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2012-05-29 11:44:31 -07:00
|
|
|
if (!ShouldGenerateWarnings())
|
2012-05-23 09:07:10 -07:00
|
|
|
return;
|
|
|
|
|
2012-05-29 11:44:31 -07:00
|
|
|
mAlreadyGeneratedWarnings++;
|
2010-10-15 14:50:15 -07:00
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
char buf[1024];
|
2010-10-15 14:50:15 -07:00
|
|
|
PR_vsnprintf(buf, 1024, fmt, ap);
|
2010-09-13 08:40:01 -07:00
|
|
|
|
2010-10-15 14:50:15 -07:00
|
|
|
// no need to print to stderr, as JS_ReportWarning takes care of this for us.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
2012-07-30 07:20:58 -07:00
|
|
|
JSContext* ccx = nullptr;
|
2012-05-23 09:07:10 -07:00
|
|
|
if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) {
|
2010-10-15 14:50:15 -07:00
|
|
|
JS_ReportWarning(ccx, "WebGL: %s", buf);
|
2012-05-29 11:44:31 -07:00
|
|
|
if (!ShouldGenerateWarnings()) {
|
2012-05-23 09:07:10 -07:00
|
|
|
JS_ReportWarning(ccx,
|
2012-05-29 11:44:31 -07:00
|
|
|
"WebGL: No further warnings will be reported for this WebGL context "
|
|
|
|
"(already reported %d warnings)", mAlreadyGeneratedWarnings);
|
2012-05-23 09:07:10 -07:00
|
|
|
}
|
|
|
|
}
|
2010-09-13 08:40:01 -07:00
|
|
|
}
|
|
|
|
|
2011-09-01 12:28:34 -07:00
|
|
|
CheckedUint32
|
|
|
|
WebGLContext::GetImageSize(WebGLsizei height,
|
|
|
|
WebGLsizei width,
|
2012-05-23 09:07:01 -07:00
|
|
|
uint32_t pixelSize,
|
|
|
|
uint32_t packOrUnpackAlignment)
|
2011-09-01 12:28:34 -07:00
|
|
|
{
|
|
|
|
CheckedUint32 checked_plainRowSize = CheckedUint32(width) * pixelSize;
|
|
|
|
|
|
|
|
// alignedRowSize = row size rounded up to next multiple of packAlignment
|
|
|
|
CheckedUint32 checked_alignedRowSize = RoundedToNextMultipleOf(checked_plainRowSize, packOrUnpackAlignment);
|
|
|
|
|
|
|
|
// if height is 0, we don't need any memory to store this; without this check, we'll get an overflow
|
|
|
|
CheckedUint32 checked_neededByteLength
|
|
|
|
= height <= 0 ? 0 : (height-1) * checked_alignedRowSize + checked_plainRowSize;
|
|
|
|
|
|
|
|
return checked_neededByteLength;
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::SynthesizeGLError(WebGLenum err)
|
2010-05-15 06:55:45 -07:00
|
|
|
{
|
|
|
|
// If there is already a pending error, don't overwrite it;
|
|
|
|
// but if there isn't, then we need to check for a gl error
|
|
|
|
// that may have occurred before this one and use that code
|
|
|
|
// instead.
|
2011-07-07 17:01:16 -07:00
|
|
|
|
|
|
|
MakeContextCurrent();
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
UpdateWebGLErrorAndClearGLError();
|
2010-05-15 06:55:45 -07:00
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
if (!mWebGLError)
|
|
|
|
mWebGLError = err;
|
2010-05-15 06:55:45 -07:00
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-28 15:52:39 -07:00
|
|
|
WebGLContext::SynthesizeGLError(WebGLenum err, const char *fmt, ...)
|
2010-05-15 06:55:45 -07:00
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(err);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidEnum(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2010-05-15 06:55:45 -07:00
|
|
|
WebGLContext::ErrorInvalidValue(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_VALUE);
|
2009-09-02 17:47:49 -07:00
|
|
|
}
|
2011-02-24 14:17:34 -08:00
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2012-01-24 13:12:31 -08:00
|
|
|
WebGLContext::ErrorInvalidFramebufferOperation(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2012-01-24 13:12:31 -08:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION);
|
|
|
|
}
|
|
|
|
|
2012-05-04 09:38:44 -07:00
|
|
|
void
|
2011-02-24 14:17:34 -08:00
|
|
|
WebGLContext::ErrorOutOfMemory(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2012-05-23 09:07:29 -07:00
|
|
|
GenerateWarning(fmt, va);
|
2011-02-24 14:17:34 -08:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:01:16 -07:00
|
|
|
const char *
|
|
|
|
WebGLContext::ErrorName(GLenum error)
|
|
|
|
{
|
|
|
|
switch(error) {
|
|
|
|
case LOCAL_GL_INVALID_ENUM:
|
|
|
|
return "INVALID_ENUM";
|
|
|
|
case LOCAL_GL_INVALID_OPERATION:
|
|
|
|
return "INVALID_OPERATION";
|
|
|
|
case LOCAL_GL_INVALID_VALUE:
|
|
|
|
return "INVALID_VALUE";
|
|
|
|
case LOCAL_GL_OUT_OF_MEMORY:
|
|
|
|
return "OUT_OF_MEMORY";
|
|
|
|
case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
|
|
|
|
return "INVALID_FRAMEBUFFER_OPERATION";
|
|
|
|
case LOCAL_GL_NO_ERROR:
|
|
|
|
return "NO_ERROR";
|
|
|
|
default:
|
|
|
|
NS_ABORT();
|
|
|
|
return "[unknown WebGL error!]";
|
|
|
|
}
|
2012-04-03 16:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WebGLContext::IsTextureFormatCompressed(GLenum format)
|
|
|
|
{
|
|
|
|
switch(format) {
|
|
|
|
case LOCAL_GL_RGB:
|
|
|
|
case LOCAL_GL_RGBA:
|
|
|
|
case LOCAL_GL_ALPHA:
|
|
|
|
case LOCAL_GL_LUMINANCE:
|
|
|
|
case LOCAL_GL_LUMINANCE_ALPHA:
|
2012-08-13 18:17:55 -07:00
|
|
|
case LOCAL_GL_DEPTH_COMPONENT:
|
|
|
|
case LOCAL_GL_DEPTH_STENCIL:
|
2012-04-03 16:42:06 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
case LOCAL_GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
|
|
|
|
case LOCAL_GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("Invalid WebGL texture format?");
|
|
|
|
NS_ABORT();
|
|
|
|
return false;
|
|
|
|
}
|