NPAPI:DrawImage: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 5: Line 5:
= Contributors =
= Contributors =


* Last modified: April 27, 2010
* Last modified: May 12, 2010
* Authors: Oleg Romashin (Nokia), Josh Aas (Mozilla)
* Authors: Oleg Romashin (Nokia), Josh Aas (Mozilla)
* Contributors: Robert O'Callahan (Mozilla)
* Contributors: Robert O'Callahan (Mozilla)
Line 43: Line 43:
     * alpha is used. (That is, 50% transparent red is 0x80800000,
     * alpha is used. (That is, 50% transparent red is 0x80800000,
     * not 0x80ff0000.) */
     * not 0x80ff0000.) */
     NPImageFormatARGB32    = 0x1,
     NPImageFormatARGB32_pre = 0x1,
 
     /* each pixel is a 32-bit quantity, with
     /* each pixel is a 32-bit quantity, with
     * the upper 8 bits unused. Red, Green, and Blue are stored
     * the upper 8 bits unused. Red, Green, and Blue are stored
     * in the remaining 24 bits in that order. */
     * in the remaining 24 bits in that order. */
     NPImageFormatRGB24      = 0x2,  /* x8r8g8b8 */
     NPImageFormatRGB24      = 0x2,  /* x8r8g8b8 */
     NPImageFormatRGB16_565  = 0x4  /* r5g6b5  */
     NPImageFormatRGB16_565  = 0x4  /* r5g6b5  */
    /* non-premultiplied version of RGBA32 format */
    NPImageFormatARGB32    = 0x8,
     /* can be extended */
     /* can be extended */
   } NPImageFormat;
   } NPImageFormat;
    
    
   typedef struct _NPImageData
   typedef struct _NPImageData
   {
   {
Line 69: Line 68:
     /* exposeX/Y + exposeSize <= pluginSize */
     /* exposeX/Y + exposeSize <= pluginSize */
     NPSize        exposeSize;  
     NPSize        exposeSize;  
} NPImageData;
  } NPImageData;


How to initialize cairo destination surface with this info:
How to initialize cairo destination surface with this info:
Line 88: Line 87:


* NPNVsupportedImageFormats (NPNVariable = 19)
* NPNVsupportedImageFormats (NPNVariable = 19)
* NPPVpluginImageFormats (NPPVariable = 22)
* NPPVImageFormats (NPPVariable = 22)


Negotiating the image format will work similarly to [[NPAPI:Models|drawing and event model negotiation]], but the value of NPNVsupportedImageFormats will be a bitmap of supported types. Based on the browser's supported formats, the plugin should select a subset which it can handle. The format for any given event will be specified in the event, and will be from the plugin's supported subset.
Negotiating the image format will work similarly to [[NPAPI:Models|drawing and event model negotiation]], but the value of NPNVsupportedImageFormats will be a bitmap of supported types. Based on the browser's supported formats, the plugin should select a subset which it can handle. The format for any given event will be specified in the event, and will be from the plugin's supported subset.

Latest revision as of 14:48, 12 May 2010

Status

Under consideration.

Contributors

  • Last modified: May 12, 2010
  • Authors: Oleg Romashin (Nokia), Josh Aas (Mozilla)
  • Contributors: Robert O'Callahan (Mozilla)

Overview

This drawing model allows plugins to draw into a buffer.

Event Model Requirements

This drawing model is currently compatible with the following event models:

While this is currently only compatible with the extended X event model, this could change. This drawing model was designed to work on any platform.

NPDrawingModelX

As this will be the first alternative to the default X drawing model, we'll designate the original model:

  • NPDrawingModelX (NPDrawingModel = 4)
  • NPNVsupportsXDrawingBool (NPNVariable = 2004)

NPDrawingModelDrawImage

For documentation on negotiating drawing models, see NPAPI:Models. The drawing model variables for draw image events are:

  • NPDrawingModelDrawImage (NPDrawingModel = 5)
  • NPNVsupportsDrawImageBool (NPNVariable = 3005)

Event Structure

 typedef enum {
   /* each pixel is a 32-bit quantity, with
    * alpha in the upper 8 bits, then red, then green, then blue.
    * The 32-bit quantities are stored native-endian. Pre-multiplied
    * alpha is used. (That is, 50% transparent red is 0x80800000,
    * not 0x80ff0000.) */
   NPImageFormatARGB32_pre = 0x1,
   /* each pixel is a 32-bit quantity, with
    * the upper 8 bits unused. Red, Green, and Blue are stored
    * in the remaining 24 bits in that order. */
   NPImageFormatRGB24      = 0x2,  /* x8r8g8b8 */
   NPImageFormatRGB16_565  = 0x4   /* r5g6b5   */
   /* non-premultiplied version of RGBA32 format */
   NPImageFormatARGB32     = 0x8,
   /* can be extended */
 } NPImageFormat;
 
 typedef struct _NPImageData
 {
   /* Image data parameters */
   char*         data;       /* image pointer */
   int32_t       stride;     /* Stride of data image pointer */
   NPImageFormat format;     /* Format of image pointer */
   /* size of plugin window in current buffer, used for scale information */
   NPSize        pluginSize; 
   /* "data" points to exposeX/Y point, which is also offset in plugin window area */
   int32_t       exposeX; 
   int32_t       exposeY; 
   /* size of data buffer, size of area where plugin should paint */
   /* exposeX/Y + exposeSize <= pluginSize */
   NPSize        exposeSize; 
 } NPImageData;

How to initialize cairo destination surface with this info:

cairo_surface_t *src = plugin_window_image (probably cached)
cairo_surface_t *dest =
  cairo_image_surface_create_for_data((unsigned char*)event->data,
                                      CAIRO_FORMAT_XXX(event->format),
                                      event->exposeSize.width,
                                      event->exposeSize.height,
                                      event->stride);

cairo_t *cr = cairo_create(dest);
cairo_set_source_surface (cr, src, -event->exposeRect.left, -event->exposeRect.top);

NPImageFormat Type Negotiation

  • NPNVsupportedImageFormats (NPNVariable = 19)
  • NPPVImageFormats (NPPVariable = 22)

Negotiating the image format will work similarly to drawing and event model negotiation, but the value of NPNVsupportedImageFormats will be a bitmap of supported types. Based on the browser's supported formats, the plugin should select a subset which it can handle. The format for any given event will be specified in the event, and will be from the plugin's supported subset.

 NPImageFormat supportedFormats;
 browserFuncs->getvalue(instance, NPNVsupportedImageFormats, &supportedFormats);
 ...
 browserFuncs->setvalue(instance, NPPVImageFormats, (void*)supportedSubset);