зеркало из https://github.com/mozilla/gecko-dev.git
Bug 890311 - [WebGL 2.0] Add WebGL2Context C++ class inheriting WebGLContext. r=jgilbert
This commit is contained in:
Родитель
c9704d86cb
Коммит
09e5e38a50
|
@ -24,6 +24,15 @@ public:
|
|||
virtual ~WebGL1Context();
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// IMPLEMENT WebGLContext
|
||||
|
||||
virtual bool IsWebGL2() const MOZ_OVERRIDE
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// IMPLEMENT nsWrapperCache
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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 "WebGL2Context.h"
|
||||
#include "mozilla/dom/WebGL2RenderingContextBinding.h"
|
||||
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// CONSTRUCTOR & DESTRUCTOR
|
||||
|
||||
WebGL2Context::WebGL2Context()
|
||||
: WebGLContext()
|
||||
{
|
||||
MOZ_ASSERT(IsSupported(), "not supposed to create a WebGL2Context"
|
||||
"context when not supported");
|
||||
}
|
||||
|
||||
WebGL2Context::~WebGL2Context()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// STATIC FUNCTIONS
|
||||
|
||||
bool
|
||||
WebGL2Context::IsSupported()
|
||||
{
|
||||
#ifdef RELEASE_BUILD
|
||||
return false;
|
||||
#else
|
||||
return Preferences::GetBool("webgl.enable-prototype-webgl2", false);
|
||||
#endif
|
||||
}
|
||||
|
||||
WebGL2Context*
|
||||
WebGL2Context::Create()
|
||||
{
|
||||
#ifdef RELEASE_BUILD
|
||||
return nullptr;
|
||||
#else
|
||||
return new WebGL2Context();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// IMPLEMENT nsWrapperCache
|
||||
|
||||
JSObject*
|
||||
WebGL2Context::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
|
||||
{
|
||||
return dom::WebGL2RenderingContextBinding::Wrap(cx, scope, this);
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef WEBGL2CONTEXT_H_
|
||||
#define WEBGL2CONTEXT_H_
|
||||
|
||||
#include "WebGLContext.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class WebGL2Context
|
||||
: public WebGLContext
|
||||
{
|
||||
// -----------------------------------------------------------------------------
|
||||
// PUBLIC
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// DESTRUCTOR
|
||||
|
||||
virtual ~WebGL2Context();
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// STATIC FUNCTIONS
|
||||
|
||||
static bool IsSupported();
|
||||
|
||||
static WebGL2Context* Create();
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// IMPLEMENT WebGLContext
|
||||
|
||||
virtual bool IsWebGL2() const MOZ_OVERRIDE
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// IMPLEMENT nsWrapperCache
|
||||
|
||||
virtual JSObject* WrapObject(JSContext *cx,
|
||||
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// PRIVATE
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// CONSTRUCTOR
|
||||
|
||||
WebGL2Context();
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
|
@ -153,6 +153,8 @@ public:
|
|||
virtual JSObject* WrapObject(JSContext *cx,
|
||||
JS::Handle<JSObject*> scope) = 0;
|
||||
|
||||
virtual bool IsWebGL2() const = 0;
|
||||
|
||||
NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT
|
||||
|
||||
// nsICanvasRenderingContextInternal
|
||||
|
|
|
@ -2113,7 +2113,18 @@ WebGLContext::GetParameter(JSContext* cx, WebGLenum pname, ErrorResult& rv)
|
|||
case LOCAL_GL_RENDERER:
|
||||
return StringValue(cx, "Mozilla", rv);
|
||||
case LOCAL_GL_VERSION:
|
||||
return StringValue(cx, "WebGL 1.0", rv);
|
||||
{
|
||||
const char* version = 0;
|
||||
|
||||
if (IsWebGL2()) {
|
||||
version = "WebGL 2.0";
|
||||
} else {
|
||||
version = "WebGL 1.0";
|
||||
}
|
||||
|
||||
MOZ_ASSERT(version != 0);
|
||||
return StringValue(cx, version, rv);
|
||||
}
|
||||
case LOCAL_GL_SHADING_LANGUAGE_VERSION:
|
||||
return StringValue(cx, "WebGL GLSL ES 1.0", rv);
|
||||
|
||||
|
|
|
@ -4,7 +4,13 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsIDOMWebGLRenderingContext.h"
|
||||
#include "WebGL2Context.h"
|
||||
|
||||
#define DUMMY(func,rtype) nsresult func (rtype ** aResult) { return NS_ERROR_FAILURE; }
|
||||
|
||||
DUMMY(NS_NewCanvasRenderingContextWebGL, nsIDOMWebGLRenderingContext)
|
||||
|
||||
WebGL2Context * WebGL2Context::Create()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ if CONFIG['MOZ_WEBGL']:
|
|||
'WebGLActiveInfo.cpp',
|
||||
'WebGLBuffer.cpp',
|
||||
'WebGL1Context.cpp',
|
||||
'WebGL2Context.cpp',
|
||||
'WebGLContext.cpp',
|
||||
'WebGLContextGL.cpp',
|
||||
'WebGLContextUtils.cpp',
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include "nsNetUtil.h"
|
||||
#include "nsStreamUtils.h"
|
||||
|
||||
#include "../canvas/src/WebGL2Context.h"
|
||||
|
||||
using namespace mozilla::layers;
|
||||
|
||||
NS_IMPL_NS_NEW_HTML_ELEMENT(Canvas)
|
||||
|
@ -682,6 +684,20 @@ HTMLCanvasElement::GetContextHelper(const nsAString& aContextId,
|
|||
ctx.forget(aContext);
|
||||
return NS_OK;
|
||||
}
|
||||
else if (WebGL2Context::IsSupported() &&
|
||||
aContextId.EqualsLiteral("experimental-webgl2"))
|
||||
{
|
||||
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_USED, 1);
|
||||
nsRefPtr<WebGL2Context> ctx = WebGL2Context::Create();
|
||||
|
||||
if (ctx == nullptr) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
ctx->SetCanvasElement(this);
|
||||
ctx.forget(aContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 ctxId(aContextId);
|
||||
|
||||
|
|
|
@ -1287,8 +1287,16 @@ DOMInterfaces = {
|
|||
},
|
||||
|
||||
'WebGLRenderingContext': {
|
||||
'nativeType': 'mozilla::WebGL1Context',
|
||||
'headerFile': 'WebGL1Context.h',
|
||||
'nativeType': 'mozilla::WebGLContext',
|
||||
'headerFile': 'WebGLContext.h',
|
||||
'resultNotAddRefed': [ 'canvas', 'getContextAttributes', 'getExtension',
|
||||
'getAttachedShaders' ],
|
||||
'implicitJSContext': [ 'getSupportedExtensions' ],
|
||||
},
|
||||
|
||||
'WebGL2RenderingContext': {
|
||||
'nativeType': 'mozilla::WebGLContext',
|
||||
'headerFile': 'WebGLContext.h',
|
||||
'resultNotAddRefed': [ 'canvas', 'getContextAttributes', 'getExtension',
|
||||
'getAttachedShaders' ],
|
||||
'implicitJSContext': [ 'getSupportedExtensions' ],
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* 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/.
|
||||
*
|
||||
* This IDL depend on WebGLRenderingContext.webidl
|
||||
*/
|
||||
|
||||
interface WebGL2RenderingContext : WebGLRenderingContext {
|
||||
|
||||
};
|
||||
|
|
@ -389,6 +389,7 @@ endif
|
|||
ifdef MOZ_WEBGL
|
||||
webidl_files += \
|
||||
WebGLRenderingContext.webidl \
|
||||
WebGL2RenderingContext.webidl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче