Mozilla exposes an AsyncDrawing API, that enables hardware accelerated rendering in
an NPAPI plugin.
While the NPDrawingModelAsyncWindowsSharedSurface mode requires Vista and higher,
the NPDrawingModelAsyncBitmapSurface works also on Windows XP.
But in their sample code, in the function drawAsyncBitmapColor,
the plugin uses memcpy and loops on the pixels to draw the bitmap:
void drawAsyncBitmapColor(InstanceData* instanceData)
{
NPP npp = instanceData->npp;
uint32_t *pixelData = (uint32_t*)instanceData->backBuffer->bitmap.data;
uint32_t rgba = instanceData->scriptableObject->drawColor;
unsigned char subpixels[4];
subpixels[0] = rgba & 0xFF;
subpixels[1] = (rgba & 0xFF00) >> 8;
subpixels[2] = (rgba & 0xFF0000) >> 16;
subpixels[3] = (rgba & 0xFF000000) >> 24;
subpixels[0] = uint8_t(float(subpixels[3] * subpixels[0]) / 0xFF);
subpixels[1] = uint8_t(float(subpixels[3] * subpixels[1]) / 0xFF);
subpixels[2] = uint8_t(float(subpixels[3] * subpixels[2]) / 0xFF);
uint32_t premultiplied;
memcpy(&premultiplied, subpixels, sizeof(premultiplied));
for (uint32_t* lastPixel = pixelData + instanceData->backBuffer->size.width * instanceData->backBuffer->size.height;
pixelData < lastPixel;
++pixelData) {
*pixelData = premultiplied;
}
NPN_SetCurrentAsyncSurface(npp, instanceData->backBuffer, NULL);
NPAsyncSurface *oldFront = instanceData->frontBuffer;
instanceData->frontBuffer = instanceData->backBuffer;
instanceData->backBuffer = oldFront;
}
Does it mean the expensive copying must be done by the CPU, and not the GPU?
Does it mean that NPDrawingModelAsyncBitmapSurface does not let you take advantage of hardware-acceleration?
Thanks
Yes and yes. Hardware-accelerated surfaces require platform-specific implementations, hence the plain bitmap surface as a fallback.