NPAPI:DrawImage
Problem Summary
It is very painful to render plugin content to non-X surfaces on Linux using X11. (For Mozilla if MOZ_X11 is defined then HandleEvent is operating with XEvent's). When browser renders its content into a memory buffer or to some other surface (Qt::RasterPaintEngine/cairo-image-surface which are not very friendly to X), then we are forced to do data moving X-client-X...
Proposal
I propose an NPAPI DrawImage event type which would allow a plugin to render directly into an image memory buffer, without involving X-Surface.
Drawing Image Event
For documentation on negotiating event type, see Plugins:IndependentEventModel. The drawing image type variable for Platform independent image rendering is:
* NPEventType_DrawImage
Using NPImageData structure as event where NPImageData:
typedef struct _NPImageData { /* Image data parameters */ char* data; /* image pointer */ int32_t stride; /* Stride of data image pointer */ NPImageFormat format; /* Format of image pointer */ NPSize dataSize; /* Data buffer size */ /* Clip rectangle, must be used for trusted plugins */ int32_t x; /* Expose x relative to 0,0 of plugin window area*/ int32_t y; /* Expose y relative to 0,0 of plugin window area */ uint32_t width; /* Expose width */ uint32_t height; /* Expose height */ /* Position and scale values for plugin area */ float translateX; /* translate X matrix value, (x offset) */ 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;
where NPImageFormat (similar to the current Cairo image format list):
typedef enum { NPImageFormatARGB32 = 0x0001, /* a8r8g8b8 */ NPImageFormatRGB24 = 0x0002, /* x8r8g8b8 */ NPImageFormatRGB16_565 = 0x0004 /* r5g6b5 */ ...... More formats could be added here if needed ...... } NPImageFormat;
NPImageFormat type negotiation
NPNVsupportsImageFormat = 5000,
Similar to Event types negotiation Plugins:IndependentEventModel#NPEventType_negotiation
NPImageFormat aFormats; browser->getvalue(instance, NPNVsupportsImageFormat, &aFormats)
Then the plugin should decide which formats supported by plugin and browser (remove bits which are not supported by plugin), and send a value to browser:
browser->setvalue(instance, NPNVsupportsImageFormat, commonFormats);
And then browser should use only formats enumerated in commonFormats value.
According to plugin state (transparency), and platform proffered depth/image-format browser will send event to plugin with specific format.