我使用 NPAPI 进行视频流。
但是在 Mac Safari (Mt.Lion, v6.0.2) 中,加载时 CPU 使用率很高 (7~80%)。Chrome 或 FireFox 是常态。
我猜当调用 NPNFuncs.invalidaterect 函数时。
int16_t PLUGINAPI::handleEvent(void* event)
{
NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
ScriptablePluginObject* pObject = (ScriptablePluginObject*)m_pScriptableObject;
if(cocoaEvent->type == NPCocoaEventDrawRect) {
CGContextRef cgContext = cocoaEvent->data.draw.context;
if(!cgContext)
return true;
//Add rect and translate the video
CGContextAddRect(cgContext, CGRectMake (0, 0, m_Window->width, m_Window->height));
CGContextTranslateCTM(cgContext, 0, m_Window->height);
CGContextScaleCTM(cgContext, 1.0, -1.0);
//Display the video here
if(pObject && pObject->m_pNpapiPlugin)
pObject->m_pNpapiPlugin->WEBVIEWER_DisplayFrame(cgContext, m_Window->width, m_Window->height);
//Fulsh cgcontextref
CGContextFlush(cgContext);
//Generate DrawRect event
NPRect rect = {0, 0, m_Window->height, m_Window->width};
NPNFuncs.invalidaterect(m_pNPInstance, &rect);
NPNFuncs.forceredraw(m_pNPInstance);
} else {
if(pObject && pObject->m_pNpapiPlugin)
pObject->m_pNpapiPlugin->WEBVIEWER_SendEvent(cocoaEvent);
}
return true;
}
插件绘图还有其他方法吗?或者我想要解决这个问题。