1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef CLIENTWEBGLEXTENSIONS_H_
7 #define CLIENTWEBGLEXTENSIONS_H_
9 #include "WebGLExtensions.h"
10 #include "ClientWebGLContext.h"
14 class ClientWebGLExtensionBase
: public nsWrapperCache
{
15 friend ClientWebGLContext
;
18 WeakPtr
<ClientWebGLContext
> mContext
;
21 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ClientWebGLExtensionBase
)
22 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(ClientWebGLExtensionBase
)
25 explicit ClientWebGLExtensionBase(ClientWebGLContext
& context
)
26 : mContext(&context
) {}
27 virtual ~ClientWebGLExtensionBase() = default;
30 ClientWebGLContext
* GetParentObject() const { return mContext
.get(); }
35 // To be used for implementations of ClientWebGLExtensionBase
36 #define DEFINE_WEBGL_EXTENSION_GOOP(_WebGLBindingType, _Extension) \
37 JSObject* Client##_Extension::WrapObject(JSContext* cx, \
38 JS::Handle<JSObject*> givenProto) { \
39 return dom::_WebGLBindingType##_Binding::Wrap(cx, this, givenProto); \
41 Client##_Extension::Client##_Extension(ClientWebGLContext& aClient) \
42 : ClientWebGLExtensionBase(aClient) {}
44 // Many extensions have no methods. This is a shorthand for declaring client
45 // versions of such classes.
46 #define DECLARE_SIMPLE_WEBGL_EXTENSION(_Extension) \
47 class Client##_Extension : public ClientWebGLExtensionBase { \
49 virtual JSObject* WrapObject(JSContext* cx, \
50 JS::Handle<JSObject*> givenProto) override; \
51 explicit Client##_Extension(ClientWebGLContext&); \
56 class ClientWebGLExtensionCompressedTextureASTC
57 : public ClientWebGLExtensionBase
{
59 virtual JSObject
* WrapObject(JSContext
* cx
,
60 JS::Handle
<JSObject
*> givenProto
) override
;
61 explicit ClientWebGLExtensionCompressedTextureASTC(ClientWebGLContext
&);
63 void GetSupportedProfiles(dom::Nullable
<nsTArray
<nsString
>>& retval
) const {
64 if (MOZ_UNLIKELY(!mContext
)) {
65 AutoJsWarning("getSupportedProfiles: Extension is `invalidated`.");
68 mContext
->GetSupportedProfilesASTC(retval
);
72 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFloatBlend
)
74 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureBPTC
)
76 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureES3
)
78 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureETC1
)
80 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTexturePVRTC
)
82 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureRGTC
)
84 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFBORenderMipmap
)
86 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureS3TC
)
88 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureS3TC_SRGB
)
90 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDebugRendererInfo
)
92 class ClientWebGLExtensionDebugShaders
: public ClientWebGLExtensionBase
{
94 virtual JSObject
* WrapObject(JSContext
* cx
,
95 JS::Handle
<JSObject
*> givenProto
) override
;
96 explicit ClientWebGLExtensionDebugShaders(ClientWebGLContext
&);
98 void GetTranslatedShaderSource(const WebGLShaderJS
& shader
,
99 nsAString
& retval
) const {
100 if (MOZ_UNLIKELY(!mContext
)) {
101 AutoJsWarning("getTranslatedShaderSource: Extension is `invalidated`.");
104 mContext
->GetTranslatedShaderSource(shader
, retval
);
108 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDepthTexture
)
110 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionElementIndexUint
)
112 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionEXTColorBufferFloat
)
114 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFragDepth
)
116 class ClientWebGLExtensionLoseContext
: public ClientWebGLExtensionBase
{
118 virtual JSObject
* WrapObject(JSContext
* cx
,
119 JS::Handle
<JSObject
*> givenProto
) override
;
120 explicit ClientWebGLExtensionLoseContext(ClientWebGLContext
&);
123 if (MOZ_UNLIKELY(!mContext
)) {
124 AutoJsWarning("loseContext: Extension is `invalidated`.");
127 mContext
->EmulateLoseContext();
129 void RestoreContext() {
130 if (MOZ_UNLIKELY(!mContext
)) {
131 AutoJsWarning("restoreContext: Extension is `invalidated`.");
134 mContext
->RestoreContext(webgl::LossStatus::LostManually
);
138 class ClientWebGLExtensionProvokingVertex
: public ClientWebGLExtensionBase
{
140 virtual JSObject
* WrapObject(JSContext
* cx
,
141 JS::Handle
<JSObject
*> givenProto
) override
;
142 explicit ClientWebGLExtensionProvokingVertex(ClientWebGLContext
&);
144 void ProvokingVertexWEBGL(const GLenum mode
) const {
145 if (MOZ_UNLIKELY(!mContext
)) {
146 AutoJsWarning("provokingVertexWEBGL: Extension is `invalidated`.");
149 mContext
->ProvokingVertex(mode
);
153 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionSRGB
)
155 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionStandardDerivatives
)
157 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionShaderTextureLod
)
159 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFilterAnisotropic
)
161 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloat
)
163 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloatLinear
)
165 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloat
)
167 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloatLinear
)
169 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureNorm16
)
171 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferFloat
)
173 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferHalfFloat
)
175 class ClientWebGLExtensionDrawBuffers
: public ClientWebGLExtensionBase
{
177 virtual JSObject
* WrapObject(JSContext
* cx
,
178 JS::Handle
<JSObject
*> givenProto
) override
;
179 explicit ClientWebGLExtensionDrawBuffers(ClientWebGLContext
&);
181 void DrawBuffersWEBGL(const dom::Sequence
<GLenum
>& buffers
) {
182 if (MOZ_UNLIKELY(!mContext
)) {
183 AutoJsWarning("drawBuffersWEBGL: Extension is `invalidated`.");
186 mContext
->DrawBuffers(buffers
);
190 class ClientWebGLExtensionVertexArray
: public ClientWebGLExtensionBase
{
192 virtual JSObject
* WrapObject(JSContext
* cx
,
193 JS::Handle
<JSObject
*> givenProto
) override
;
194 explicit ClientWebGLExtensionVertexArray(ClientWebGLContext
&);
196 already_AddRefed
<WebGLVertexArrayJS
> CreateVertexArrayOES() {
197 if (MOZ_UNLIKELY(!mContext
)) {
198 AutoJsWarning("createVertexArrayOES: Extension is `invalidated`.");
201 return mContext
->CreateVertexArray();
203 void DeleteVertexArrayOES(WebGLVertexArrayJS
* array
) {
204 if (MOZ_UNLIKELY(!mContext
)) {
205 AutoJsWarning("deleteVertexArrayOES: Extension is `invalidated`.");
208 mContext
->DeleteVertexArray(array
);
210 bool IsVertexArrayOES(const WebGLVertexArrayJS
* array
) {
211 if (MOZ_UNLIKELY(!mContext
)) {
212 AutoJsWarning("isVertexArrayOES: Extension is `invalidated`.");
215 return mContext
->IsVertexArray(array
);
217 void BindVertexArrayOES(WebGLVertexArrayJS
* array
) {
218 if (MOZ_UNLIKELY(!mContext
)) {
219 AutoJsWarning("bindVertexArrayOES: Extension is `invalidated`.");
222 mContext
->BindVertexArray(array
);
226 class ClientWebGLExtensionInstancedArrays
: public ClientWebGLExtensionBase
{
228 virtual JSObject
* WrapObject(JSContext
* cx
,
229 JS::Handle
<JSObject
*> givenProto
) override
;
230 explicit ClientWebGLExtensionInstancedArrays(ClientWebGLContext
&);
232 void DrawArraysInstancedANGLE(GLenum mode
, GLint first
, GLsizei count
,
234 if (MOZ_UNLIKELY(!mContext
)) {
235 AutoJsWarning("drawArraysInstancedANGLE: Extension is `invalidated`.");
238 mContext
->DrawArraysInstanced(mode
, first
, count
, primcount
);
240 void DrawElementsInstancedANGLE(GLenum mode
, GLsizei count
, GLenum type
,
241 WebGLintptr offset
, GLsizei primcount
) {
242 if (MOZ_UNLIKELY(!mContext
)) {
243 AutoJsWarning("drawElementsInstancedANGLE: Extension is `invalidated`.");
246 mContext
->DrawElementsInstanced(mode
, count
, type
, offset
, primcount
);
248 void VertexAttribDivisorANGLE(GLuint index
, GLuint divisor
) {
249 if (MOZ_UNLIKELY(!mContext
)) {
250 AutoJsWarning("vertexAttribDivisorANGLE: Extension is `invalidated`.");
253 mContext
->VertexAttribDivisor(index
, divisor
);
257 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionBlendMinMax
)
259 class ClientWebGLExtensionDisjointTimerQuery
: public ClientWebGLExtensionBase
{
261 virtual JSObject
* WrapObject(JSContext
* cx
,
262 JS::Handle
<JSObject
*> givenProto
) override
;
263 explicit ClientWebGLExtensionDisjointTimerQuery(ClientWebGLContext
&);
265 already_AddRefed
<WebGLQueryJS
> CreateQueryEXT() const {
266 if (MOZ_UNLIKELY(!mContext
)) {
267 AutoJsWarning("createQueryEXT: Extension is `invalidated`.");
270 return mContext
->CreateQuery();
272 void DeleteQueryEXT(WebGLQueryJS
* query
) const {
273 if (MOZ_UNLIKELY(!mContext
)) {
274 AutoJsWarning("deleteQueryEXT: Extension is `invalidated`.");
277 mContext
->DeleteQuery(query
);
279 bool IsQueryEXT(const WebGLQueryJS
* query
) const {
280 if (MOZ_UNLIKELY(!mContext
)) {
281 AutoJsWarning("isQueryEXT: Extension is `invalidated`.");
284 return mContext
->IsQuery(query
);
286 void BeginQueryEXT(GLenum target
, WebGLQueryJS
& query
) const {
287 if (MOZ_UNLIKELY(!mContext
)) {
288 AutoJsWarning("beginQueryEXT: Extension is `invalidated`.");
291 mContext
->BeginQuery(target
, query
);
293 void EndQueryEXT(GLenum target
) const {
294 if (MOZ_UNLIKELY(!mContext
)) {
295 AutoJsWarning("endQueryEXT: Extension is `invalidated`.");
298 mContext
->EndQuery(target
);
300 void QueryCounterEXT(WebGLQueryJS
& query
, GLenum target
) const {
301 if (MOZ_UNLIKELY(!mContext
)) {
302 AutoJsWarning("queryCounterEXT: Extension is `invalidated`.");
305 mContext
->QueryCounter(query
, target
);
307 void GetQueryEXT(JSContext
* cx
, GLenum target
, GLenum pname
,
308 JS::MutableHandle
<JS::Value
> retval
) const {
309 if (MOZ_UNLIKELY(!mContext
)) {
310 AutoJsWarning("getQueryEXT: Extension is `invalidated`.");
313 mContext
->GetQuery(cx
, target
, pname
, retval
);
315 void GetQueryObjectEXT(JSContext
* cx
, WebGLQueryJS
& query
, GLenum pname
,
316 JS::MutableHandle
<JS::Value
> retval
) const {
317 if (MOZ_UNLIKELY(!mContext
)) {
318 AutoJsWarning("getQueryObjectEXT: Extension is `invalidated`.");
321 mContext
->GetQueryParameter(cx
, query
, pname
, retval
);
325 class ClientWebGLExtensionExplicitPresent
: public ClientWebGLExtensionBase
{
327 virtual JSObject
* WrapObject(JSContext
* cx
,
328 JS::Handle
<JSObject
*> givenProto
) override
;
329 explicit ClientWebGLExtensionExplicitPresent(ClientWebGLContext
&);
331 void Present() const {
332 if (MOZ_UNLIKELY(!mContext
)) {
333 AutoJsWarning("present: Extension is `invalidated`.");
336 mContext
->OnBeforePaintTransaction();
340 class ClientWebGLExtensionMOZDebug
: public ClientWebGLExtensionBase
{
342 virtual JSObject
* WrapObject(JSContext
* cx
,
343 JS::Handle
<JSObject
*> givenProto
) override
;
344 explicit ClientWebGLExtensionMOZDebug(ClientWebGLContext
&);
346 void GetParameter(JSContext
* cx
, GLenum pname
,
347 JS::MutableHandle
<JS::Value
> retval
,
348 ErrorResult
& er
) const {
349 if (MOZ_UNLIKELY(!mContext
)) {
350 AutoJsWarning("getParameter: Extension is `invalidated`.");
353 mContext
->MOZDebugGetParameter(cx
, pname
, retval
, er
);
357 class ClientWebGLExtensionMultiview
: public ClientWebGLExtensionBase
{
359 virtual JSObject
* WrapObject(JSContext
* cx
,
360 JS::Handle
<JSObject
*> givenProto
) override
;
361 explicit ClientWebGLExtensionMultiview(ClientWebGLContext
&);
363 void FramebufferTextureMultiviewOVR(const GLenum target
,
364 const GLenum attachment
,
365 WebGLTextureJS
* const texture
,
367 const GLint baseViewIndex
,
368 const GLsizei numViews
) const {
369 if (MOZ_UNLIKELY(!mContext
)) {
371 "framebufferTextureMultiviewOVR: Extension is `invalidated`.");
374 mContext
->FramebufferTextureMultiview(target
, attachment
, texture
, level
,
375 baseViewIndex
, numViews
);
379 class ClientWebGLExtensionDrawBuffersIndexed
: public ClientWebGLExtensionBase
{
381 virtual JSObject
* WrapObject(JSContext
* cx
,
382 JS::Handle
<JSObject
*> givenProto
) override
;
383 explicit ClientWebGLExtensionDrawBuffersIndexed(ClientWebGLContext
&);
385 void EnableiOES(const GLenum target
, const GLuint buf
) const {
386 if (MOZ_UNLIKELY(!mContext
)) {
387 AutoJsWarning("enableiOES: Extension is `invalidated`.");
390 mContext
->SetEnabledI(target
, Some(buf
), true);
393 void DisableiOES(const GLenum target
, const GLuint buf
) const {
394 if (MOZ_UNLIKELY(!mContext
)) {
395 AutoJsWarning("disableiOES: Extension is `invalidated`.");
398 mContext
->SetEnabledI(target
, Some(buf
), false);
401 void BlendEquationiOES(const GLuint buf
, const GLenum mode
) const {
402 BlendEquationSeparateiOES(buf
, mode
, mode
);
405 void BlendEquationSeparateiOES(const GLuint buf
, const GLenum modeRgb
,
406 const GLenum modeAlpha
) const {
407 if (MOZ_UNLIKELY(!mContext
)) {
408 AutoJsWarning("blendEquationSeparateiOES: Extension is `invalidated`.");
411 mContext
->BlendEquationSeparateI(Some(buf
), modeRgb
, modeAlpha
);
414 void BlendFunciOES(const GLuint buf
, const GLenum src
,
415 const GLenum dst
) const {
416 BlendFuncSeparateiOES(buf
, src
, dst
, src
, dst
);
419 void BlendFuncSeparateiOES(const GLuint buf
, const GLenum srcRgb
,
420 const GLenum dstRgb
, const GLenum srcAlpha
,
421 const GLenum dstAlpha
) const {
422 if (MOZ_UNLIKELY(!mContext
)) {
423 AutoJsWarning("blendFuncSeparateiOES: Extension is `invalidated`.");
426 mContext
->BlendFuncSeparateI(Some(buf
), srcRgb
, dstRgb
, srcAlpha
, dstAlpha
);
429 void ColorMaskiOES(const GLuint buf
, const bool r
, const bool g
, const bool b
,
430 const bool a
) const {
431 if (MOZ_UNLIKELY(!mContext
)) {
432 AutoJsWarning("colorMaskiOES: Extension is `invalidated`.");
435 mContext
->ColorMaskI(Some(buf
), r
, g
, b
, a
);
439 } // namespace mozilla
441 #endif // CLIENTWEBGLEXTENSIONS_H_