| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
|
| 3 |
<?xml-stylesheet href="../../extension.xsl" type="text/xsl"?> |
| 4 |
|
| 5 |
<proposal href="proposals/WEBGL_texture_source_iframe/"> |
| 6 |
<name>WEBGL_texture_source_iframe</name> |
| 7 |
<contact><a href="https://www.khronos.org/webgl/public-mailing-list/">WebGL |
| 8 |
working group</a> (public_webgl 'at' khronos.org) </contact> |
| 9 |
<contributors> |
| 10 |
<contributor>Zhenyao Mo, Google Inc</contributor> |
| 11 |
<contributor>Members of the WebGL working group</contributor> |
| 12 |
</contributors> |
| 13 |
<number>NN</number> |
| 14 |
<depends> |
| 15 |
<api version="1.0"/> |
| 16 |
<api version="2.0"/> |
| 17 |
</depends> |
| 18 |
<overview> |
| 19 |
<p>This extension enables WebGL implementations to bind an HTMLIFrameElement object as the data source |
| 20 |
to a texture. While bound, the extension provides an API to allow applications to request the latest |
| 21 |
iframe rendering results to be blitted to the texture. The extension also provides an API to allow |
| 22 |
applications to transform and forward related user input events from WebGL canvas to the bound iframe, |
| 23 |
thus enabling the bound iframe to be interative inside a WebGL scene.</p> |
| 24 |
<p>Due to security concerns, currently this extension only supports same origin iframes. This |
| 25 |
limitaion may be lifted in the future.</p> |
| 26 |
</overview> |
| 27 |
<idl xml:space="preserve"><![CDATA[ |
| 28 |
[NoInterfaceObject] |
| 29 |
interface WEBGL_texture_source_iframe { |
| 30 |
Promise<void> bindTextureSource(GLenum target, HTMLIFrameElement iframe); |
| 31 |
Promise<void> requestFrame(GLenum target); |
| 32 |
void setEventForwarding(function(Event)); |
| 33 |
}; |
| 34 |
]]></idl> |
| 35 |
<newfun> |
| 36 |
<function name="bindTextureSource" type="Promise<void>"> |
| 37 |
<param name="target" type="GLenum"/> |
| 38 |
<param name="iframe" type="HTMLIFrameElement"/> |
| 39 |
<p> |
| 40 |
This function connects an <code>iframe</code> to the texture currently bound to <code>target</code> and returns a promise |
| 41 |
that will be fulfilled once the iframe is rendered and ready to be blitted to the texture. If the <code>iframe</code> |
| 42 |
is <code>null</code>, any existing binding between the texture and an iframe is broken. |
| 43 |
If there are any errors, generate the GL error synchronously and the returned promise is |
| 44 |
<a href="https://www.w3.org/2001/tag/doc/promises-guide/#reject-promise">rejected</a> |
| 45 |
with an <code>InvalidStateError</code>. |
| 46 |
</p> |
| 47 |
<p> |
| 48 |
Once the function returns successfully, the texture is defined as following: its effective |
| 49 |
internal format becomes <code>RGBA8</code>; its width and height becomes iframe element's |
| 50 |
width and height. |
| 51 |
</p> |
| 52 |
<p>Error cases are listed below: |
| 53 |
<ul> |
| 54 |
<li><code>target</code> must be <code>TEXTURE_2D</code>; otherwise an <code>INVALID_ENUM</code> |
| 55 |
error is generated.</li> |
| 56 |
<li>If no texture is bound to the <code>target</code>, an <code>INVALID_OPERATION</code> is |
| 57 |
generated.</li> |
| 58 |
<li>If <code>iframe</code> is not the same origin, an <code>INVALID_OPERATION</code> is |
| 59 |
generated.</li> |
| 60 |
</ul> |
| 61 |
</p> |
| 62 |
<p>Note this function returns a promise asynchronously because wiring an iframe rendering results |
| 63 |
to a WebGL texture could take multiple frames. The iframe could be invisible, therefore not part of |
| 64 |
the rendering pipeline and needs to be inserted into it. The iframe could also be in a seperate |
| 65 |
process from the one where WebGL is in, although this is likely not the case right now because we |
| 66 |
currently limit iframe to be same origin only.</p> |
| 67 |
</function> |
| 68 |
<function name="requestFrame" type="Promise<void>"> |
| 69 |
<param name="target" type="GLenum"/> |
| 70 |
<p> |
| 71 |
This function instructs implementations to update the texture with the latest iframe rendering |
| 72 |
results. The function returns a promise that will be fulfilled when the iframe rendering results from the same animation frame |
| 73 |
when this function is called has been blitted to the texture. |
| 74 |
</p> |
| 75 |
<p> |
| 76 |
If an application uses <code>requestAnimationFrame</code>, implementations must guarantee once |
| 77 |
this function is called, the iframe rendering results from the same frame has been blitted to the |
| 78 |
texture when entering the next animation frame. Therefore, it is not necessary for an |
| 79 |
application to depend on the state of the returned promise. The promise is for applications that do not |
| 80 |
use <code>requestAnimationFrame</code>. |
| 81 |
</p> |
| 82 |
<p> |
| 83 |
Once this function called, it is not recommended to read from the texture until the returns promise is |
| 84 |
fulfilled. The content of the texture during this period is undefined. |
| 85 |
</p> |
| 86 |
</function> |
| 87 |
<function name="setEventForwarding" type="void"> |
| 88 |
<param name="func" type="Function"/> |
| 89 |
<p> |
| 90 |
This function allows an application to define an event forwarding |
| 91 |
function that decides whether to forward user input events received on |
| 92 |
the WebGL canvas to the iframe. If yes, this function needs to transform |
| 93 |
event locations and displacements as needed. With this, an application |
| 94 |
can allow users to interact the iframe rendered inside the WebGL scene. |
| 95 |
</p> |
| 96 |
<p> |
| 97 |
The event forwarding function takes an event as input, and output a |
| 98 |
bool. If returning true, the event is forwarded to the iframe and event |
| 99 |
data might have been modified to transform the event from WebGL canvas |
| 100 |
coordinates to iframe coordinates. |
| 101 |
</p> |
| 102 |
<p> |
| 103 |
TODO([email protected]): need some help how to define the forwarding function |
| 104 |
signature. |
| 105 |
</p> |
| 106 |
</function> |
| 107 |
</newfun> |
| 108 |
<history> |
| 109 |
<revision date="2017/09/20"> |
| 110 |
<change>Initial revision.</change> |
| 111 |
</revision> |
| 112 |
</history> |
| 113 |
</proposal> |