Bug 890049 - WebGL2 Replace WebGLContext by WebGLContext with one subclass WebGL1Context. r=jgilbert

This commit is contained in:
Guillaume Abadie 2013-07-16 10:32:24 -04:00
parent c75be1c126
commit 79fae3c7f5
6 changed files with 93 additions and 23 deletions

View File

@ -0,0 +1,50 @@
/* -*- 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 "WebGL1Context.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "mozilla/Telemetry.h"
using namespace mozilla;
// -----------------------------------------------------------------------------
// CONSTRUCTOR & DESTRUCTOR
WebGL1Context::WebGL1Context()
: WebGLContext()
{
}
WebGL1Context::~WebGL1Context()
{
}
// -----------------------------------------------------------------------------
// IMPLEMENT nsWrapperCache
JSObject*
WebGL1Context::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
{
return dom::WebGLRenderingContextBinding::Wrap(cx, scope, this);
}
// -----------------------------------------------------------------------------
// INSTANCING nsIDOMWebGLRenderingContext
nsresult
NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult)
{
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_USED, 1);
nsIDOMWebGLRenderingContext* ctx = new WebGL1Context();
NS_ADDREF(*aResult = ctx);
return NS_OK;
}

View File

@ -0,0 +1,38 @@
/* -*- 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 WEBGL1CONTEXT_H_
#define WEBGL1CONTEXT_H_
#include "WebGLContext.h"
namespace mozilla {
class WebGL1Context
: public WebGLContext
{
// -----------------------------------------------------------------------------
// PUBLIC
public:
// -------------------------------------------------------------------------
// CONSTRUCTOR & DESTRUCTOR
WebGL1Context();
virtual ~WebGL1Context();
// -------------------------------------------------------------------------
// IMPLEMENT nsWrapperCache
virtual JSObject* WrapObject(JSContext *cx,
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
};
} // namespace mozilla
#endif

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLContext.h"
#include "WebGL1Context.h"
#include "WebGLObjectModel.h"
#include "WebGLExtensions.h"
#include "WebGLContextUtils.h"
@ -88,20 +89,6 @@ WebGLMemoryPressureObserver::Observe(nsISupports* aSubject,
}
nsresult NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult);
nsresult
NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult)
{
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_USED, 1);
nsIDOMWebGLRenderingContext* ctx = new WebGLContext();
if (!ctx)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult = ctx);
return NS_OK;
}
WebGLContextOptions::WebGLContextOptions()
: alpha(true), depth(true), stencil(false),
premultipliedAlpha(true), antialias(true),
@ -227,12 +214,6 @@ WebGLContext::~WebGLContext()
mContextRestorer = nullptr;
}
JSObject*
WebGLContext::WrapObject(JSContext *cx, JS::Handle<JSObject*> scope)
{
return dom::WebGLRenderingContextBinding::Wrap(cx, scope, this);
}
void
WebGLContext::DestroyResourcesAndContext()
{

View File

@ -151,7 +151,7 @@ public:
nsIDOMWebGLRenderingContext)
virtual JSObject* WrapObject(JSContext *cx,
JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
JS::Handle<JSObject*> scope) = 0;
NS_DECL_NSIDOMWEBGLRENDERINGCONTEXT

View File

@ -28,6 +28,7 @@ if CONFIG['MOZ_WEBGL']:
CPP_SOURCES += [
'WebGLActiveInfo.cpp',
'WebGLBuffer.cpp',
'WebGL1Context.cpp',
'WebGLContext.cpp',
'WebGLContextGL.cpp',
'WebGLContextUtils.cpp',

View File

@ -1287,8 +1287,8 @@ DOMInterfaces = {
},
'WebGLRenderingContext': {
'nativeType': 'mozilla::WebGLContext',
'headerFile': 'WebGLContext.h',
'nativeType': 'mozilla::WebGL1Context',
'headerFile': 'WebGL1Context.h',
'resultNotAddRefed': [ 'canvas', 'getContextAttributes', 'getExtension',
'getAttachedShaders' ],
'implicitJSContext': [ 'getSupportedExtensions' ],