Mozilla公开了AsyncDrawing API,,可以实现硬件加速渲染
NPAPI插件。
虽然NPDrawingModelAsyncWindowsSharedSurface模式需要Vista及更高版本,但是
NPDrawingModelAsyncBitmapSurface也适用于Windows XP
但在他们的sample code中,在函数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不允许您利用硬件加速?
由于
答案 0 :(得分:1)
这是否意味着昂贵的复制必须由CPU完成,而不是 GPU?这是否意味着NPDrawingModelAsyncBitmapSurface不会 让你利用硬件加速?
是的,是的。硬件加速表面需要特定于平台的实现,因此将纯位图表面作为后备。