NPAPI:DrawImage: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(16 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:  
* Contributors: Robert O'Callahan (Mozilla)


= Overview =
= Overview =
Line 38: Line 38:


   typedef enum {
   typedef enum {
     NPImageFormatARGB32     = 0, /* a8r8g8b8 */
     /* each pixel is a 32-bit quantity, with
     NPImageFormatRGB24      = 2,  /* x8r8g8b8 */
    * alpha in the upper 8 bits, then red, then green, then blue.
     NPImageFormatRGB16_565  = 3   /* r5g6b5  */
    * 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;
   } NPImageFormat;
    
    
Line 50: Line 60:
     int32_t      stride;    /* Stride of data image pointer */
     int32_t      stride;    /* Stride of data image pointer */
     NPImageFormat format;    /* Format of image pointer */
     NPImageFormat format;    /* Format of image pointer */
     NPSize        dataSize;  /* Data buffer size */
     /* size of plugin window in current buffer, used for scale information */
    /* Clip rectangle, must be used for trusted plugins */
     NPSize        pluginSize;  
     int32_t      x;     /* Expose x relative to 0,0 of plugin window area*/
    /* "data" points to exposeX/Y point, which is also offset in plugin window area */
     int32_t      y;     /* Expose y relative to 0,0 of plugin window area */
     int32_t      exposeX;  
     uint32_t      width; /* Expose width */
     int32_t      exposeY;  
     uint32_t      height; /* Expose height */
     /* size of data buffer, size of area where plugin should paint */
    /* Position and scale values for plugin area */
     /* exposeX/Y + exposeSize <= pluginSize */
     float        translateX; /* translate X matrix value, (x offset) */
     NPSize        exposeSize;  
    float        translateY; /* translate Y matrix value, (y offset) */
    /* Defines plugin window size on scaled context, if 1 then size = window size */
     float        scaleX;     /* scale X matrix value */
    float        scaleY;    /* scale Y matrix value */
   } NPImageData;
   } NPImageData;
How to initialize cairo destination surface with this info:
<pre>
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);
</pre>


= NPImageFormat Type Negotiation =
= NPImageFormat Type Negotiation =


* NPNVSupportedImageFormats (NPNVariable = ?)
* NPNVsupportedImageFormats (NPNVariable = 19)
* NPPVImageFormat (NPPVariable = ?)
* NPPVImageFormats (NPPVariable = 22)


Negotiating the image format will work similarly to [[NPAPI:Models|drawing and event model negotiation]], but the value of NPNVsupportsImageFormat will be a bitmap of supported types. Based on the browser's supported formats, the plugin should select a format.
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.


   NPImageFormat supportedFormats;
   NPImageFormat supportedFormats;
   browserFuncs->getvalue(instance, NPNVsupportsImageFormat, &supportedFormats);
   browserFuncs->getvalue(instance, NPNVsupportedImageFormats, &supportedFormats);
   ...
   ...
   browserFuncs->setvalue(instance, NPPVImageFormat, (void*)selectedFormat);
   browserFuncs->setvalue(instance, NPPVImageFormats, (void*)supportedSubset);
Confirmed users
180

edits