summaryrefslogtreecommitdiffstats
path: root/dom/canvas/ClientWebGLExtensions.h
blob: 7d1062530d3a506c5ae51474312d43f8bcac5c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 CLIENTWEBGLEXTENSIONS_H_
#define CLIENTWEBGLEXTENSIONS_H_

#include "WebGLExtensions.h"
#include "ClientWebGLContext.h"

namespace mozilla {

class ClientWebGLExtensionBase : public nsWrapperCache {
  friend ClientWebGLContext;

 protected:
  WeakPtr<ClientWebGLContext> mContext;

 public:
  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ClientWebGLExtensionBase)
  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(ClientWebGLExtensionBase)

 protected:
  explicit ClientWebGLExtensionBase(ClientWebGLContext& context)
      : mContext(&context) {}
  virtual ~ClientWebGLExtensionBase() = default;

 public:
  ClientWebGLContext* GetParentObject() const { return mContext.get(); }
};

// -

// To be used for implementations of ClientWebGLExtensionBase
#define DEFINE_WEBGL_EXTENSION_GOOP(_WebGLBindingType, _Extension)             \
  JSObject* Client##_Extension::WrapObject(JSContext* cx,                      \
                                           JS::Handle<JSObject*> givenProto) { \
    return dom::_WebGLBindingType##_Binding::Wrap(cx, this, givenProto);       \
  }                                                                            \
  Client##_Extension::Client##_Extension(ClientWebGLContext& aClient)          \
      : ClientWebGLExtensionBase(aClient) {}

// Many extensions have no methods.  This is a shorthand for declaring client
// versions of such classes.
#define DECLARE_SIMPLE_WEBGL_EXTENSION(_Extension)                           \
  class Client##_Extension : public ClientWebGLExtensionBase {               \
   public:                                                                   \
    virtual JSObject* WrapObject(JSContext* cx,                              \
                                 JS::Handle<JSObject*> givenProto) override; \
    explicit Client##_Extension(ClientWebGLContext&);                        \
  };

////

class ClientWebGLExtensionCompressedTextureASTC
    : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionCompressedTextureASTC(ClientWebGLContext&);

  void GetSupportedProfiles(dom::Nullable<nsTArray<nsString>>& retval) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("getSupportedProfiles: Extension is `invalidated`.");
      return;
    }
    mContext->GetSupportedProfilesASTC(retval);
  }
};

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFloatBlend)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureBPTC)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureES3)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureETC1)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTexturePVRTC)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureRGTC)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFBORenderMipmap)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureS3TC)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionCompressedTextureS3TC_SRGB)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDebugRendererInfo)

class ClientWebGLExtensionDebugShaders : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionDebugShaders(ClientWebGLContext&);

  void GetTranslatedShaderSource(const WebGLShaderJS& shader,
                                 nsAString& retval) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("getTranslatedShaderSource: Extension is `invalidated`.");
      return;
    }
    mContext->GetTranslatedShaderSource(shader, retval);
  }
};

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionDepthTexture)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionElementIndexUint)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionEXTColorBufferFloat)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionFragDepth)

class ClientWebGLExtensionLoseContext : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionLoseContext(ClientWebGLContext&);

  void LoseContext() {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("loseContext: Extension is `invalidated`.");
      return;
    }
    mContext->EmulateLoseContext();
  }
  void RestoreContext() {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("restoreContext: Extension is `invalidated`.");
      return;
    }
    mContext->RestoreContext(webgl::LossStatus::LostManually);
  }
};

class ClientWebGLExtensionProvokingVertex : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionProvokingVertex(ClientWebGLContext&);

  void ProvokingVertexWEBGL(const GLenum mode) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("provokingVertexWEBGL: Extension is `invalidated`.");
      return;
    }
    mContext->ProvokingVertex(mode);
  }
};

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionSRGB)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionStandardDerivatives)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionShaderTextureLod)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFilterAnisotropic)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloat)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureFloatLinear)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloat)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureHalfFloatLinear)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionTextureNorm16)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferFloat)

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionColorBufferHalfFloat)

class ClientWebGLExtensionDrawBuffers : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionDrawBuffers(ClientWebGLContext&);

  void DrawBuffersWEBGL(const dom::Sequence<GLenum>& buffers) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("drawBuffersWEBGL: Extension is `invalidated`.");
      return;
    }
    mContext->DrawBuffers(buffers);
  }
};

class ClientWebGLExtensionVertexArray : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionVertexArray(ClientWebGLContext&);

  already_AddRefed<WebGLVertexArrayJS> CreateVertexArrayOES() {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("createVertexArrayOES: Extension is `invalidated`.");
      return nullptr;
    }
    return mContext->CreateVertexArray();
  }
  void DeleteVertexArrayOES(WebGLVertexArrayJS* array) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("deleteVertexArrayOES: Extension is `invalidated`.");
      return;
    }
    mContext->DeleteVertexArray(array);
  }
  bool IsVertexArrayOES(const WebGLVertexArrayJS* array) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("isVertexArrayOES: Extension is `invalidated`.");
      return false;
    }
    return mContext->IsVertexArray(array);
  }
  void BindVertexArrayOES(WebGLVertexArrayJS* array) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("bindVertexArrayOES: Extension is `invalidated`.");
      return;
    }
    mContext->BindVertexArray(array);
  }
};

class ClientWebGLExtensionInstancedArrays : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionInstancedArrays(ClientWebGLContext&);

  void DrawArraysInstancedANGLE(GLenum mode, GLint first, GLsizei count,
                                GLsizei primcount) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("drawArraysInstancedANGLE: Extension is `invalidated`.");
      return;
    }
    mContext->DrawArraysInstanced(mode, first, count, primcount);
  }
  void DrawElementsInstancedANGLE(GLenum mode, GLsizei count, GLenum type,
                                  WebGLintptr offset, GLsizei primcount) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("drawElementsInstancedANGLE: Extension is `invalidated`.");
      return;
    }
    mContext->DrawElementsInstanced(mode, count, type, offset, primcount);
  }
  void VertexAttribDivisorANGLE(GLuint index, GLuint divisor) {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("vertexAttribDivisorANGLE: Extension is `invalidated`.");
      return;
    }
    mContext->VertexAttribDivisor(index, divisor);
  }
};

DECLARE_SIMPLE_WEBGL_EXTENSION(WebGLExtensionBlendMinMax)

class ClientWebGLExtensionDisjointTimerQuery : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionDisjointTimerQuery(ClientWebGLContext&);

  already_AddRefed<WebGLQueryJS> CreateQueryEXT() const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("createQueryEXT: Extension is `invalidated`.");
      return nullptr;
    }
    return mContext->CreateQuery();
  }
  void DeleteQueryEXT(WebGLQueryJS* query) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("deleteQueryEXT: Extension is `invalidated`.");
      return;
    }
    mContext->DeleteQuery(query);
  }
  bool IsQueryEXT(const WebGLQueryJS* query) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("isQueryEXT: Extension is `invalidated`.");
      return false;
    }
    return mContext->IsQuery(query);
  }
  void BeginQueryEXT(GLenum target, WebGLQueryJS& query) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("beginQueryEXT: Extension is `invalidated`.");
      return;
    }
    mContext->BeginQuery(target, query);
  }
  void EndQueryEXT(GLenum target) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("endQueryEXT: Extension is `invalidated`.");
      return;
    }
    mContext->EndQuery(target);
  }
  void QueryCounterEXT(WebGLQueryJS& query, GLenum target) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("queryCounterEXT: Extension is `invalidated`.");
      return;
    }
    mContext->QueryCounter(query, target);
  }
  void GetQueryEXT(JSContext* cx, GLenum target, GLenum pname,
                   JS::MutableHandle<JS::Value> retval) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("getQueryEXT: Extension is `invalidated`.");
      return;
    }
    mContext->GetQuery(cx, target, pname, retval);
  }
  void GetQueryObjectEXT(JSContext* cx, WebGLQueryJS& query, GLenum pname,
                         JS::MutableHandle<JS::Value> retval) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("getQueryObjectEXT: Extension is `invalidated`.");
      return;
    }
    mContext->GetQueryParameter(cx, query, pname, retval);
  }
};

class ClientWebGLExtensionExplicitPresent : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionExplicitPresent(ClientWebGLContext&);

  void Present() const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("present: Extension is `invalidated`.");
      return;
    }
    mContext->OnBeforePaintTransaction();
  }
};

class ClientWebGLExtensionMOZDebug : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionMOZDebug(ClientWebGLContext&);

  void GetParameter(JSContext* cx, GLenum pname,
                    JS::MutableHandle<JS::Value> retval,
                    ErrorResult& er) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("getParameter: Extension is `invalidated`.");
      return;
    }
    mContext->MOZDebugGetParameter(cx, pname, retval, er);
  }
};

class ClientWebGLExtensionMultiview : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionMultiview(ClientWebGLContext&);

  void FramebufferTextureMultiviewOVR(const GLenum target,
                                      const GLenum attachment,
                                      WebGLTextureJS* const texture,
                                      const GLint level,
                                      const GLint baseViewIndex,
                                      const GLsizei numViews) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning(
          "framebufferTextureMultiviewOVR: Extension is `invalidated`.");
      return;
    }
    mContext->FramebufferTextureMultiview(target, attachment, texture, level,
                                          baseViewIndex, numViews);
  }
};

class ClientWebGLExtensionDrawBuffersIndexed : public ClientWebGLExtensionBase {
 public:
  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> givenProto) override;
  explicit ClientWebGLExtensionDrawBuffersIndexed(ClientWebGLContext&);

  void EnableiOES(const GLenum target, const GLuint buf) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("enableiOES: Extension is `invalidated`.");
      return;
    }
    mContext->SetEnabledI(target, Some(buf), true);
  }

  void DisableiOES(const GLenum target, const GLuint buf) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("disableiOES: Extension is `invalidated`.");
      return;
    }
    mContext->SetEnabledI(target, Some(buf), false);
  }

  void BlendEquationiOES(const GLuint buf, const GLenum mode) const {
    BlendEquationSeparateiOES(buf, mode, mode);
  }

  void BlendEquationSeparateiOES(const GLuint buf, const GLenum modeRgb,
                                 const GLenum modeAlpha) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("blendEquationSeparateiOES: Extension is `invalidated`.");
      return;
    }
    mContext->BlendEquationSeparateI(Some(buf), modeRgb, modeAlpha);
  }

  void BlendFunciOES(const GLuint buf, const GLenum src,
                     const GLenum dst) const {
    BlendFuncSeparateiOES(buf, src, dst, src, dst);
  }

  void BlendFuncSeparateiOES(const GLuint buf, const GLenum srcRgb,
                             const GLenum dstRgb, const GLenum srcAlpha,
                             const GLenum dstAlpha) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("blendFuncSeparateiOES: Extension is `invalidated`.");
      return;
    }
    mContext->BlendFuncSeparateI(Some(buf), srcRgb, dstRgb, srcAlpha, dstAlpha);
  }

  void ColorMaskiOES(const GLuint buf, const bool r, const bool g, const bool b,
                     const bool a) const {
    if (MOZ_UNLIKELY(!mContext)) {
      AutoJsWarning("colorMaskiOES: Extension is `invalidated`.");
      return;
    }
    mContext->ColorMaskI(Some(buf), r, g, b, a);
  }
};

}  // namespace mozilla

#endif  // CLIENTWEBGLEXTENSIONS_H_