Mozilla 公开了一个AsyncDrawing API,它可以在 NPAPI 插件中启用硬件加速渲染。
虽然NPDrawingModelAsyncWindowsSharedSurface模式需要 Vista 和更高版本,
但NPDrawingModelAsyncBitmapSurface也适用于 Windows XP。
但是在他们的示例代码中,在函数 drawAsyncBitmapColor 中,
插件使用 memcpy 并在像素上循环来绘制位图:
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;
}
这是否意味着昂贵的复制必须由 CPU 而不是 GPU 完成?
这是否意味着 NPDrawingModelAsyncBitmapSurface 不允许您利用硬件加速?
谢谢