NPAPI:Pepper: Difference between revisions

Line 85: Line 85:
== Plugins and Rendering ==
== Plugins and Rendering ==


We expect to use the term renderer in a more general sense than just graphics, so we present NPAPI with a structure that can be extended as other interfaces are added (e.g., audio, 3D graphics, hardware accelerators).  To facilitate this, we propose the addition of a new struct type.
We will use device context to refer to platform independent devices (e.g., audio, 3D graphics, hardware accelerators).  To facilitate this, we propose the addition of a new struct type.


A plugin will request rendering contexts using the following structure.
A plugin will request device contexts using the following structure.


<pre>
<pre>
typedef struct _NPRenderContext
typedef struct _NPDeviceContext
{
{
   union {
   NPDeviceQueryCapabilityPtr queryCapability;
    struct {
  NPDeviceQueryConfigPtr queryConfig;
      void* region;
  NPDeviceInitializeContextPtr initializeContext;
      int32 stride;
  NPDeviceSetStateContextPtr setStateContext;
      ...  /* Other information as needed for 2D RGBA */
  NPDeviceGetStateContextPtr getStateContext;
    } graphicsRgba;
  NPDeviceFlushContextPtr flushContext;
    ...  /* Other variants for renderers. */
   NPDeviceDestroyContextPtr destroyContext;
   } u;
} NPDeviceContext;
} NPRenderContext;
</pre>
</pre>


=== Getting a Context to Render ===
=== Query a Device for Capabilities and Configurations ===


<pre>
<pre>
typedef NPError (*NPInitializeRenderContextPtr)(NPP instance,
typedef NPError (*NPDeviceQueryCapabilityPtr(NPP instance,
                                                NPRenderType type,
                                            int32 capability,
                                                NPRenderContext* context);
                                            int32 *value);
typedef NPError (*NPDeviceQueryConfigPtr(NPP instance,
                                        const NPDeviceConfig* request,
                                        NPDeviceConfig* obtain);
</pre>
</pre>


Causes the creation of a render context of the specified type for use by the specified instance.
Use queryCapability to ask a device about a specific capability.  Use queryConfig to ask a device about a set of capabilities.  The obtained configuration is the closest match to the requested configuration.
 
=== Getting a Device Context ===
 
<pre>
typedef NPError (*NPDeviceInitializeContextPtr)(NPP instance,
                                                const NPDeviceConfig *config,
                                                NPDeviceContext* context);
</pre>
 
Causes the creation of a device context for use by the specified instance.


=== Publishing a Context ===
=== Publishing a Context ===


<pre>
<pre>
typedef void (*NPFlushRenderContextCallbackPtr)(NPRenderContext* context,
typedef void (*NPDeviceFlushRenderContextCallbackPtr)(NPP instance,
                                                NPError err,
                                                      NPDeviceContext* context,
                                                void* userData);
                                                      NPError err,
                                                      void* userData);


typedef NPError (*NPFlushRenderContextPtr)(NPP instance,
typedef NPError (*NPDeviceFlushRenderContextPtr)(NPP instance,
                                          NPRenderContext* context,
                                                NPDeviceContext* context,
                                          NPFlushRenderContextCallbackPtr callback,
                                                NPFlushRenderContextCallbackPtr callback,
                                          void* userData);
                                                void* userData);
</pre>
</pre>


Causes the contents of the region to be presented to the renderer for output to the user. Because the final output may be done by another process, the call is asynchronous. Return from the flush guarantees it is safe to write to the region again, but does not say that the data has reached the user. The callback is provided to add this capability. The callback should be invoked once the data has been output or an error has been detected.
Causes the contents of the context to be presented to the device for input/output to the user. Because the final input/output may be done by another process, the call is asynchronous. Return from the flush guarantees it is safe to write to the region again, but does not say that the data has reached the user. The callback is provided to add this capability. The callback should be invoked once the data has been output or an error has been detected.
 
If no callback is specified, the flush becomes a blocking call.


=== Destroying a Rendering Context ===
=== Destroying a Rendering Context ===


<pre>
<pre>
typedef NPError (*NPDestroyRenderContextPtr)(NPP instance,
typedef NPError (*NPDeviceDestroyContextPtr)(NPP instance,
                                             NPRenderContext* context);
                                             NPDeviceContext* context);
</pre>
</pre>


45

edits