0

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

Gil
  • 395
  • 4
  • 19

1 Answers1

1

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?

Yes and yes. Hardware-accelerated surfaces require platform-specific implementations, hence the plain bitmap surface as a fallback.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
  • So why not fallback to the normal windowless plugin drawing (onto the HDC supplied by the browser)? – Gil Jan 22 '13 at 14:43
  • 1
    The HDC is shared with the browser, which has to wait for the plugin to draw for proper rendering. With async surfaces the plugin just tells the browser which surface is current and the browser can use that as it sees fit. – Georg Fritzsche Jan 22 '13 at 17:11