2009-09-02 17:47:49 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2009-09-17 23:01:12 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
|
|
|
* Mark Steele <mwsteele@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
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 "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMDataContainerEvent.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2011-07-06 19:00:02 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2009-09-02 17:47:49 -07:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include "nsIContentURIGrouper.h"
|
|
|
|
#include "nsIContentPrefService.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
void
|
|
|
|
WebGLContext::LogMessage(const char *fmt, ...)
|
|
|
|
{
|
2010-09-13 08:40:01 -07:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-09-13 08:40:01 -07:00
|
|
|
LogMessage(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
|
|
|
|
WebGLContext::LogMessage(const char *fmt, va_list ap)
|
2009-09-02 17:47:49 -07:00
|
|
|
{
|
2010-10-15 14:50:15 -07:00
|
|
|
if (!fmt) return;
|
|
|
|
|
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");
|
|
|
|
JSContext* ccx = nsnull;
|
|
|
|
if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx)
|
|
|
|
JS_ReportWarning(ccx, "WebGL: %s", buf);
|
2010-09-13 08:40:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLContext::LogMessageIfVerbose(const char *fmt, ...)
|
2010-09-13 08:40:01 -07:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
LogMessageIfVerbose(fmt, ap);
|
2010-09-13 08:40:01 -07:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-15 14:50:15 -07:00
|
|
|
WebGLContext::LogMessageIfVerbose(const char *fmt, va_list ap)
|
2010-09-13 08:40:01 -07:00
|
|
|
{
|
2010-12-06 03:34:35 -08:00
|
|
|
static PRBool firstTime = PR_TRUE;
|
2010-09-13 08:40:01 -07:00
|
|
|
|
2010-12-06 03:34:35 -08:00
|
|
|
if (mVerbose)
|
|
|
|
LogMessage(fmt, ap);
|
|
|
|
else if (firstTime)
|
|
|
|
LogMessage("There are WebGL warnings or messages in this page, but they are hidden. To see them, "
|
|
|
|
"go to about:config, set the webgl.verbose preference, and reload this page.");
|
|
|
|
|
|
|
|
firstTime = PR_FALSE;
|
2010-05-15 06:55:45 -07:00
|
|
|
}
|
2009-09-02 17:47:49 -07:00
|
|
|
|
2010-05-15 06:55:45 -07:00
|
|
|
nsresult
|
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
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
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);
|
2010-10-15 14:50:15 -07:00
|
|
|
LogMessageIfVerbose(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
WebGLContext::ErrorInvalidEnum(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2010-10-15 14:50:15 -07:00
|
|
|
LogMessageIfVerbose(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_ENUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
WebGLContext::ErrorInvalidOperation(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2010-10-15 14:50:15 -07:00
|
|
|
LogMessageIfVerbose(fmt, va);
|
2010-05-15 06:55:45 -07:00
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
WebGLContext::ErrorInvalidValue(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
2010-10-15 14:50:15 -07:00
|
|
|
LogMessageIfVerbose(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
|
|
|
|
|
|
|
nsresult
|
|
|
|
WebGLContext::ErrorOutOfMemory(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_start(va, fmt);
|
|
|
|
LogMessageIfVerbose(fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
return SynthesizeGLError(LOCAL_GL_OUT_OF_MEMORY);
|
|
|
|
}
|
|
|
|
|