NPAPI:AsyncDrawing: Difference between revisions

No edit summary
Line 89: Line 89:
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>data</code> pointer of the <code>NPAsyncSurface</code> will be a <code>HANDLE</code> 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.
Plugins should create a Windows shared surface by calling <code>NPN_InitAsyncSurface</code> with a <code>NULL</code> value for the data member of <code>NPAsyncSurface</code>. On successful return, the stride member will have been set by the browser and it will reflect the stride of the returned image surface. The <code>data</code> member will point to a <code>HANDLE</code> 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.


When a surface is set as current the plugin is responsible for making sure all drawing calls on that surface have completed execution!
When a surface is set as current the plugin is responsible for making sure all drawing calls on that  
surface have completed execution!
 
Plugins should finalize Windows shared surfaces by calling <code>NPN_FinalizeAsyncSurface</code> when they are done with the surface.


This sample code illustrates usage of this drawing model:
This sample code illustrates usage of this drawing model:
Line 107: Line 110:
  npFrontBuffer->format = npBackBuffer->format = NPImageFormatXRGB32;
  npFrontBuffer->format = npBackBuffer->format = NPImageFormatXRGB32;
   
   
  NPN_CreateAsyncSurface(instance, npFrontBuffer);
  NPN_InitAsyncSurface(instance, npFrontBuffer);
  NPN_CreateAsyncSurface(instance, npBackBuffer);
  NPN_InitAsyncSurface(instance, npBackBuffer);
   
   
  pDevice10->OpenSharedResource(npFrontBuffer->handle,
  pDevice10->OpenSharedResource(npFrontBuffer->handle,
Line 132: Line 135:
  backBuffer->Release();
  backBuffer->Release();
   
   
  NPN_DestroyAsyncSurface(instance, npFrontBuffer);
  NPN_FinalizeAsyncSurface(instance, npFrontBuffer);
  NPN_DestroyAsyncSurface(instance, npBackBuffer);
  NPN_FinalizeAsyncSurface(instance, npBackBuffer);
   
   
  delete npFrontBuffer;
  delete npFrontBuffer;
Confirmed users, Bureaucrats and Sysops emeriti
1,680

edits