NPAPI:AsyncDrawing: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 34: Line 34:


<pre>
<pre>
  /* "P" suffix means pre-multiplied alpha. */
  typedef enum {
    NPImageFormatARGB32P    = 0x1,
    NPImageFormatARGB32    = 0x2,
    NPImageFormatXRGB32    = 0x4
  } NPImageFormat;
   typedef struct _NPAsyncSurface
   typedef struct _NPAsyncSurface
   {
   {
     uint32_t version;
     uint32_t version;
     NPSize size;
     NPSize size;
     NPBool opaque;
     NPImageFormat format;
    uint32_t      stride;
     struct {
     struct {
       void *handle;
       void *data;
     }
     }
   } NPAsyncSurface;
   } NPAsyncSurface;
Line 51: Line 60:
</pre>
</pre>


The <code>width</code> and <code>height</code> members of the <code>NPAsyncSurface</code> should be set to the desired width and height of the surface. The <code>opaque</code> field of the <code>NPAsyncSurface</code> should reflect whether or not all pixels on the surface should be treated as opaque regardless of the alpha value. Upon return the <code>handle</code> pointer should point to a valid surface, it will be set to NULL in the failure case.
The <code>size</code> member of the <code>NPAsyncSurface</code> should be set to the desired width and height of the surface. The <code>format</code> field of the <code>NPAsyncSurface</code> should reflect the format of the surface that is to be created. Upon return the <code>data</code> pointer should point to a valid surface data. The exact content depends on the type of surface requested, it will be set to NULL in the failure case.


Surfaces can be destroyed via a new function called <code>NPN_DestroyAsyncSurface</code>:
Surfaces can be destroyed via a new function called <code>NPN_DestroyAsyncSurface</code>:
Line 75: Line 84:
This model should be available on all platforms.
This model should be available on all platforms.


The <code>handle</code> pointer of the <code>NPAsyncSurface</code> will point to an <code>NPImageData</code> structure.
On succesful return the <code>data</code> pointer of the <code>NPAsyncSurface</code> will point to the data in memory for the surface. The <code>stride</code> member will reflect the stride of the returned image surface.
 
/* "P" suffix means pre-multiplied alpha. */
typedef enum {
  NPImageFormatARGB32P  = 0x1,
  NPImageFormatARGB32    = 0x2,
  NPImageFormatRGB24    = 0x4
} NPImageFormat;
typedef struct _NPImageData
{
  uint32_t      version;
  NPImageFormat format;
  NPSize        size;
  uint32_t      stride;
  char*        data;
} NPImageData;


If an <code>NPImageFormat</code> is not supported then surface creation will fail.
If an <code>NPImageFormat</code> is not supported then surface creation will fail.
Line 99: Line 92:
This drawing model will only be valid on Windows Vista and higher in order to simplify hardware accelerated surface sharing.
This drawing model will only be valid on Windows Vista and higher in order to simplify hardware accelerated surface sharing.


The <code>handle</code> pointer of the <code>NPAsyncSurface</code> will be a HANDLE that can be used, for example, through [http://msdn.microsoft.com/en-us/library/bb173598%28v=VS.85%29.aspx OpenSharedResource] in order to create a texture for the user. In order to allow fast drawing to any hardware surfaces the host will acquire the handle from [http://msdn.microsoft.com/en-us/library/bb174562%28v=VS.85%29.aspx IDXGISurface::GetSharedHandle]. This shared handle will represent a texture which is usable as a render target and is valid as a shader resource. The plugin can open this shared handle as a texture and then use it as a render target for any drawing operations.
The <code>data</code> pointer of the <code>NPAsyncSurface</code> will be a HANDLE that can be used, for example, through [http://msdn.microsoft.com/en-us/library/bb173598%28v=VS.85%29.aspx OpenSharedResource] in order to create a texture for the user. In order to allow fast drawing to any hardware surfaces the host will acquire the handle from [http://msdn.microsoft.com/en-us/library/bb174562%28v=VS.85%29.aspx IDXGISurface::GetSharedHandle]. This shared handle will represent a texture which is usable as a render target and is valid as a shader resource. The plugin can open this shared handle as a texture and then use it as a render target for any drawing operations.


This sample code illustrates usage of this drawing model:
This sample code illustrates usage of this drawing model:
Line 111: Line 104:
  ID3D10Texture2D *backBuffer;
  ID3D10Texture2D *backBuffer;
   
   
  npFrontBuffer->width = npBackBuffer->width = pluginwidth;
  npFrontBuffer->size.width = npBackBuffer->size.width = pluginwidth;
  npFrontBuffer->height = npBackBuffer->height = pluginheight;
  npFrontBuffer->size.height = npBackBuffer->size.height = pluginheight;
  npFrontBuffer->opaque = npBackBuffer->opaque = 1;
  npFrontBuffer->format = npBackBuffer->format = NPImageFormatXRGB32;
   
   
  NPN_CreateAsyncSurface(instance, npFrontBuffer);
  NPN_CreateAsyncSurface(instance, npFrontBuffer);
Confirmed users
138

edits

Navigation menu