Platform/GFX/WebGL/Contribute/Extensions: Difference between revisions

no edit summary
No edit summary
Line 11: Line 11:
For the purposes of this page, we will pretend there is a WebGL extension named <code>WEBGL_foo_bar</code> that we're trying to implement.
For the purposes of this page, we will pretend there is a WebGL extension named <code>WEBGL_foo_bar</code> that we're trying to implement.


===Adding the IDL===
===Adding the Web IDL===
Add the IDL from the extension spec to {{moz-central|dom/webidl/WebGLRenderingContext.webidl}}. For the interface name, instead of the one given in the extension spec, try to choose a name more in line with existing interface names here. For example, for WEBGL_foo_bar, you could choose WebGLExtensionFooBar.


Do not use any prefix here (like MOZ_ or EXT_), or in general elsewhere. Prefixes are only wanted in the extension string.
Files to be modified in this section:
* {{moz-central|dom/webidl/WebGLRenderingContext.webidl}}
* {{moz-central|dom/bindings/Bindings.conf}}


Here like in other places where all WebGL extensions are listed, please preserve alphabetic order.
WebIDL stands for "Web interface definition language". It's how Web APIs are specified. The extension spec should provide a snippet of WebIDL. In most cases, it can be used as-is or with very little modification in Mozilla's IDL system.
 
Add the Web IDL from the extension spec to {{moz-central|dom/webidl/WebGLRenderingContext.webidl}}. For the interface name, instead of the one given in the extension spec, try to choose a name more in line with existing interface names here. For example, for WEBGL_foo_bar, you could choose WebGLExtensionFooBar.
 
Do not use any prefix (like MOZ_ or EXT_). Prefixes are only wanted in the extension string (see below). Here like in other places where all WebGL extensions are listed, '''please preserve alphabetic order'''.
 
Add an entry about your new interface to {{moz-central|dom/bindings/Bindings.conf}}. Check existing WebGLExtension* entries for examples. You should have something like:
 
'WebGLExtensionFooBar': {
  'nativeType': 'mozilla::WebGLExtensionFooBar',
  'headerFile': 'WebGLExtensions.h'
},
 
If you need more information, consult [https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings WebIDL bindings] or ask for help on IRC in channel #content


===The interfaces test===
===The interfaces test===
File to be modified in this section:
* {{moz-central|dom/tests/mochitest/general/test_interfaces.html}}


You will need to add the extension's class to the list in {{moz-central|dom/tests/mochitest/general/test_interfaces.html}}.
You will need to add the extension's class to the list in {{moz-central|dom/tests/mochitest/general/test_interfaces.html}}.
Line 28: Line 45:


===The Extension Class===
===The Extension Class===
Edit {{moz-central|content/canvas/src/WebGLExtensions.h}} and define the <code>WebGLExtensionFooBar</code> class, inheriting <code>nsIWebGLExtensionFooBar</code>, similar to what's being done for <code>WebGLExtensionStandardDerivatives</code>.


You shouldn't have to do anything nontrivial there, as this class only has to expose the constants that were already defined in the IDL, so it's already inheriting them. I would implement the (empty) constructor and destructor inline there, to save the hassle of having to add a new .cpp file just for them.
File to be '''created''' in this section:
* {{moz-central|content/canvas/src/WebGLExtensionFooBar.h}}
File to be modified in this section:
* {{moz-central|content/canvas/src/WebGLExtensions.h}}
* {{moz-central|content/canvas/src/Makefile.in}}
 
Edit {{moz-central|content/canvas/src/WebGLExtensions.h}} and define the <code>WebGLExtensionFooBar</code> class, similar to what's being done for <code>WebGLExtensionStandardDerivatives</code>.
 
Create a new implementation file for your extension, say {{moz-central|content/canvas/src/WebGLExtensionFooBar.cpp}}, mimicking existing extension implementation files such as {{moz-central|content/canvas/src/WebGLExtensionStandardDerivatives.cpp}}. Add it to the list of source files in {{moz-central|content/canvas/src/Makefile.in}}.
 
This C++ class won't automatically be aware of what you've put in the IDL. If the IDL interface for this extension has methods or attributes (the majority are empty or only have constants, which don't require any C++ work), you will need to manually declare and implement the corresponding C++ methods here. See <code>WebGLExtensionLoseContext</code> for an example. For general documentation about that, refer to [https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings WebIDL bindings].


===Exposing the Extension===
===Exposing the Extension===
Now let's do the work to actually expose this extension, in WebGL <code>getExtension</code> and <code>getSupportedExtensions</code> methods.
Now let's do the work to actually expose this extension, in WebGL <code>getExtension</code> and <code>getSupportedExtensions</code> methods.
The file to edit is {{moz-central|content/canvas/src/WebGLContext.cpp}}. You will also need to add an enum value in WebGLExtensionID in {{moz-central|content/canvas/src/WebGLContext.h}}.
The file to edit is {{moz-central|content/canvas/src/WebGLContext.cpp}}. You will also need to add an enum value in WebGLExtensionID in {{moz-central|content/canvas/src/WebGLContext.h}}.
Confirmed users
753

edits