Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / ClientWebGLExtensions.h
blobf7f0f745b913ee174c9326986421df292b463a53
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"
12 namespace mozilla {
14 class ClientWebGLExtensionBase : public nsWrapperCache {
15 friend ClientWebGLContext;
17 protected:
18 WeakPtr<ClientWebGLContext> mContext;
20 public:
21 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ClientWebGLExtensionBase)
22 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(ClientWebGLExtensionBase)
24 protected:
25 explicit ClientWebGLExtensionBase(ClientWebGLContext& context)
26 : mContext(&context) {}
27 virtual ~ClientWebGLExtensionBase() = default;
29 public:
30 ClientWebGLContext* GetParentObject() const { return mContext.get(); }
33 // -
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); \
40 } \
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 { \
48 public: \
49 virtual JSObject* WrapObject(JSContext* cx, \
50 JS::Handle<JSObject*> givenProto) override; \
51 explicit Client##_Extension(ClientWebGLContext&); \
54 ////
56 class ClientWebGLExtensionCompressedTextureASTC
57 : public ClientWebGLExtensionBase {
58 public:
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`.");
66 return;
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 {
93 public:
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`.");
102 return;
104 mContext->GetTranslatedShaderSource(shader, retval);
108 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDepthClamp)
110 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDepthTexture)
112 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionElementIndexUint)
114 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionEXTColorBufferFloat)
116 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFragDepth)
118 class ClientWebGLExtensionLoseContext : public ClientWebGLExtensionBase {
119 public:
120 virtual JSObject* WrapObject(JSContext* cx,
121 JS::Handle<JSObject*> givenProto) override;
122 explicit ClientWebGLExtensionLoseContext(ClientWebGLContext&);
124 void LoseContext() {
125 if (MOZ_UNLIKELY(!mContext)) {
126 AutoJsWarning("loseContext: Extension is `invalidated`.");
127 return;
129 mContext->EmulateLoseContext();
131 void RestoreContext() {
132 if (MOZ_UNLIKELY(!mContext)) {
133 AutoJsWarning("restoreContext: Extension is `invalidated`.");
134 return;
136 mContext->RestoreContext(webgl::LossStatus::LostManually);
140 class ClientWebGLExtensionProvokingVertex : public ClientWebGLExtensionBase {
141 public:
142 virtual JSObject* WrapObject(JSContext* cx,
143 JS::Handle<JSObject*> givenProto) override;
144 explicit ClientWebGLExtensionProvokingVertex(ClientWebGLContext&);
146 void ProvokingVertexWEBGL(const GLenum mode) const {
147 if (MOZ_UNLIKELY(!mContext)) {
148 AutoJsWarning("provokingVertexWEBGL: Extension is `invalidated`.");
149 return;
151 mContext->ProvokingVertex(mode);
155 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionSRGB)
157 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionStandardDerivatives)
159 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionShaderTextureLod)
161 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFilterAnisotropic)
163 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloat)
165 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloatLinear)
167 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloat)
169 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloatLinear)
171 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureNorm16)
173 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferFloat)
175 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferHalfFloat)
177 class ClientWebGLExtensionDrawBuffers : public ClientWebGLExtensionBase {
178 public:
179 virtual JSObject* WrapObject(JSContext* cx,
180 JS::Handle<JSObject*> givenProto) override;
181 explicit ClientWebGLExtensionDrawBuffers(ClientWebGLContext&);
183 void DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers) {
184 if (MOZ_UNLIKELY(!mContext)) {
185 AutoJsWarning("drawBuffersWEBGL: Extension is `invalidated`.");
186 return;
188 mContext->DrawBuffers(buffers);
192 class ClientWebGLExtensionVertexArray : public ClientWebGLExtensionBase {
193 public:
194 virtual JSObject* WrapObject(JSContext* cx,
195 JS::Handle<JSObject*> givenProto) override;
196 explicit ClientWebGLExtensionVertexArray(ClientWebGLContext&);
198 already_AddRefed<WebGLVertexArrayJS> CreateVertexArrayOES() {
199 RefPtr<WebGLVertexArrayJS> ret;
200 if (MOZ_UNLIKELY(!mContext)) {
201 AutoJsWarning("createVertexArrayOES: Extension is `invalidated`.");
202 ret = new WebGLVertexArrayJS(nullptr);
203 } else {
204 ret = mContext->CreateVertexArray();
206 return ret.forget();
208 void DeleteVertexArrayOES(WebGLVertexArrayJS* array) {
209 if (MOZ_UNLIKELY(!mContext)) {
210 AutoJsWarning("deleteVertexArrayOES: Extension is `invalidated`.");
211 return;
213 mContext->DeleteVertexArray(array);
215 bool IsVertexArrayOES(const WebGLVertexArrayJS* array) {
216 if (MOZ_UNLIKELY(!mContext)) {
217 AutoJsWarning("isVertexArrayOES: Extension is `invalidated`.");
218 return false;
220 return mContext->IsVertexArray(array);
222 void BindVertexArrayOES(WebGLVertexArrayJS* array) {
223 if (MOZ_UNLIKELY(!mContext)) {
224 AutoJsWarning("bindVertexArrayOES: Extension is `invalidated`.");
225 return;
227 mContext->BindVertexArray(array);
231 class ClientWebGLExtensionInstancedArrays : public ClientWebGLExtensionBase {
232 public:
233 virtual JSObject* WrapObject(JSContext* cx,
234 JS::Handle<JSObject*> givenProto) override;
235 explicit ClientWebGLExtensionInstancedArrays(ClientWebGLContext&);
237 void DrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count,
238 GLsizei primcount) {
239 if (MOZ_UNLIKELY(!mContext)) {
240 AutoJsWarning("drawArraysInstancedANGLE: Extension is `invalidated`.");
241 return;
243 mContext->DrawArraysInstanced(mode, first, count, primcount);
245 void DrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type,
246 WebGLintptr offset, GLsizei primcount) {
247 if (MOZ_UNLIKELY(!mContext)) {
248 AutoJsWarning("drawElementsInstancedANGLE: Extension is `invalidated`.");
249 return;
251 mContext->DrawElementsInstanced(mode, count, type, offset, primcount);
253 void VertexAttribDivisorANGLE(GLuint index, GLuint divisor) {
254 if (MOZ_UNLIKELY(!mContext)) {
255 AutoJsWarning("vertexAttribDivisorANGLE: Extension is `invalidated`.");
256 return;
258 mContext->VertexAttribDivisor(index, divisor);
262 DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionBlendMinMax)
264 class ClientWebGLExtensionDisjointTimerQuery : public ClientWebGLExtensionBase {
265 public:
266 virtual JSObject* WrapObject(JSContext* cx,
267 JS::Handle<JSObject*> givenProto) override;
268 explicit ClientWebGLExtensionDisjointTimerQuery(ClientWebGLContext&);
270 already_AddRefed<WebGLQueryJS> CreateQueryEXT() const {
271 RefPtr<WebGLQueryJS> ret;
272 if (MOZ_UNLIKELY(!mContext)) {
273 AutoJsWarning("createQueryEXT: Extension is `invalidated`.");
274 ret = new WebGLQueryJS(nullptr);
275 } else {
276 ret = mContext->CreateQuery();
278 return ret.forget();
280 void DeleteQueryEXT(WebGLQueryJS* query) const {
281 if (MOZ_UNLIKELY(!mContext)) {
282 AutoJsWarning("deleteQueryEXT: Extension is `invalidated`.");
283 return;
285 mContext->DeleteQuery(query);
287 bool IsQueryEXT(const WebGLQueryJS* query) const {
288 if (MOZ_UNLIKELY(!mContext)) {
289 AutoJsWarning("isQueryEXT: Extension is `invalidated`.");
290 return false;
292 return mContext->IsQuery(query);
294 void BeginQueryEXT(GLenum target, WebGLQueryJS& query) const {
295 if (MOZ_UNLIKELY(!mContext)) {
296 AutoJsWarning("beginQueryEXT: Extension is `invalidated`.");
297 return;
299 mContext->BeginQuery(target, query);
301 void EndQueryEXT(GLenum target) const {
302 if (MOZ_UNLIKELY(!mContext)) {
303 AutoJsWarning("endQueryEXT: Extension is `invalidated`.");
304 return;
306 mContext->EndQuery(target);
308 void QueryCounterEXT(WebGLQueryJS& query, GLenum target) const {
309 if (MOZ_UNLIKELY(!mContext)) {
310 AutoJsWarning("queryCounterEXT: Extension is `invalidated`.");
311 return;
313 mContext->QueryCounter(query, target);
315 void GetQueryEXT(JSContext* cx, GLenum target, GLenum pname,
316 JS::MutableHandle<JS::Value> retval) const {
317 if (MOZ_UNLIKELY(!mContext)) {
318 AutoJsWarning("getQueryEXT: Extension is `invalidated`.");
319 return;
321 mContext->GetQuery(cx, target, pname, retval);
323 void GetQueryObjectEXT(JSContext* cx, WebGLQueryJS& query, GLenum pname,
324 JS::MutableHandle<JS::Value> retval) const {
325 if (MOZ_UNLIKELY(!mContext)) {
326 AutoJsWarning("getQueryObjectEXT: Extension is `invalidated`.");
327 return;
329 mContext->GetQueryParameter(cx, query, pname, retval);
333 class ClientWebGLExtensionExplicitPresent : public ClientWebGLExtensionBase {
334 public:
335 virtual JSObject* WrapObject(JSContext* cx,
336 JS::Handle<JSObject*> givenProto) override;
337 explicit ClientWebGLExtensionExplicitPresent(ClientWebGLContext&);
339 void Present() const {
340 if (MOZ_UNLIKELY(!mContext)) {
341 AutoJsWarning("present: Extension is `invalidated`.");
342 return;
344 mContext->OnBeforePaintTransaction();
348 class ClientWebGLExtensionMOZDebug : public ClientWebGLExtensionBase {
349 public:
350 virtual JSObject* WrapObject(JSContext* cx,
351 JS::Handle<JSObject*> givenProto) override;
352 explicit ClientWebGLExtensionMOZDebug(ClientWebGLContext&);
354 void GetParameter(JSContext* cx, GLenum pname,
355 JS::MutableHandle<JS::Value> retval,
356 ErrorResult& er) const {
357 if (MOZ_UNLIKELY(!mContext)) {
358 AutoJsWarning("getParameter: Extension is `invalidated`.");
359 return;
361 mContext->MOZDebugGetParameter(cx, pname, retval, er);
365 class ClientWebGLExtensionMultiview : public ClientWebGLExtensionBase {
366 public:
367 virtual JSObject* WrapObject(JSContext* cx,
368 JS::Handle<JSObject*> givenProto) override;
369 explicit ClientWebGLExtensionMultiview(ClientWebGLContext&);
371 void FramebufferTextureMultiviewOVR(const GLenum target,
372 const GLenum attachment,
373 WebGLTextureJS* const texture,
374 const GLint level,
375 const GLint baseViewIndex,
376 const GLsizei numViews) const {
377 if (MOZ_UNLIKELY(!mContext)) {
378 AutoJsWarning(
379 "framebufferTextureMultiviewOVR: Extension is `invalidated`.");
380 return;
382 mContext->FramebufferTextureMultiview(target, attachment, texture, level,
383 baseViewIndex, numViews);
387 class ClientWebGLExtensionDrawBuffersIndexed : public ClientWebGLExtensionBase {
388 public:
389 virtual JSObject* WrapObject(JSContext* cx,
390 JS::Handle<JSObject*> givenProto) override;
391 explicit ClientWebGLExtensionDrawBuffersIndexed(ClientWebGLContext&);
393 void EnableiOES(const GLenum target, const GLuint buf) const {
394 if (MOZ_UNLIKELY(!mContext)) {
395 AutoJsWarning("enableiOES: Extension is `invalidated`.");
396 return;
398 mContext->SetEnabledI(target, Some(buf), true);
401 void DisableiOES(const GLenum target, const GLuint buf) const {
402 if (MOZ_UNLIKELY(!mContext)) {
403 AutoJsWarning("disableiOES: Extension is `invalidated`.");
404 return;
406 mContext->SetEnabledI(target, Some(buf), false);
409 void BlendEquationiOES(const GLuint buf, const GLenum mode) const {
410 BlendEquationSeparateiOES(buf, mode, mode);
413 void BlendEquationSeparateiOES(const GLuint buf, const GLenum modeRgb,
414 const GLenum modeAlpha) const {
415 if (MOZ_UNLIKELY(!mContext)) {
416 AutoJsWarning("blendEquationSeparateiOES: Extension is `invalidated`.");
417 return;
419 mContext->BlendEquationSeparateI(Some(buf), modeRgb, modeAlpha);
422 void BlendFunciOES(const GLuint buf, const GLenum src,
423 const GLenum dst) const {
424 BlendFuncSeparateiOES(buf, src, dst, src, dst);
427 void BlendFuncSeparateiOES(const GLuint buf, const GLenum srcRgb,
428 const GLenum dstRgb, const GLenum srcAlpha,
429 const GLenum dstAlpha) const {
430 if (MOZ_UNLIKELY(!mContext)) {
431 AutoJsWarning("blendFuncSeparateiOES: Extension is `invalidated`.");
432 return;
434 mContext->BlendFuncSeparateI(Some(buf), srcRgb, dstRgb, srcAlpha, dstAlpha);
437 void ColorMaskiOES(const GLuint buf, const bool r, const bool g, const bool b,
438 const bool a) const {
439 if (MOZ_UNLIKELY(!mContext)) {
440 AutoJsWarning("colorMaskiOES: Extension is `invalidated`.");
441 return;
443 mContext->ColorMaskI(Some(buf), r, g, b, a);
447 } // namespace mozilla
449 #endif // CLIENTWEBGLEXTENSIONS_H_