WebAssembly迁移指南

P)NaCl弃用公告

鉴于跨浏览器WebAssembly支持的势头,我们计划将我们的本机代码工作重点放在WebAssembly上,并计划在2018年第一季度删除对PNaCl的支持(Chrome应用除外)。我们相信围绕WebAssembly的充满活力的生态系统 使其更适合新的和现有的高性能Web应用程序,并且PNaCl的使用率足够低以保证弃用。

我们最近还宣布了 ChromeOS以外的Chrome应用程序 2018年第一季度的弃用 。

工具链迁移

对于大多数(P)NaCl用例,我们建议从NaCl SDK转换到Emscripten。如果您的应用程序可移植到Linux,使用SDL或POSIX API ,则迁移可能相当简单 。虽然没有直接支持NaCl / Pepper API,但我们试图列出Web API等价物。对于更具挑战性的移植案例,请与 本地客户讨论@ googlegroups联系。COM

API迁移

我们在此概述了Web平台替代每个暴露于(P)NaCl的API的状态。此外,该表列出了Emscripten中提供最接近替代品的库或选项。

我们希望在2017年为WebAssembly添加共享内存线程支持,因为线程对匹配(P)NaCl最有趣的用例至关重要。假定即将支持线程的迁移项目标记如下。如果您的应用程序的流控制在很大程度上依赖于阻止API,您可能还会发现需要线程支持才能方便地移植。

虽然我们在此表中试图准确,但毫无疑问会有错误或遗漏。如果您遇到一个,请通过 native-client-discuss @googlegroups联系我们。COM

PPAPI

PPB_Audio

PPAPI方法假设线程EmscriptenWeb API限制
CreateXSDL(部分)GAP(部分) - AudioWorkletNode相当于ROUGHLY仍在标准化。
GetCurrentConfig SDLAudioContext.*(获取传入的设置) 
StartPlayback SDLAudioBufferSourceNode.start 
StopPlayback SDLAudioBufferSourceNode.stop 

PPB_AudioBuffer

PPAPI方法假设线程EmscriptenWeb API限制
GetTimestamp SDLAudioBufferSourceNode.start(parameter)每次传递而不是附加到缓冲区。
setTimestamp SDLAudioBufferSourceNode.start(parameter) 
GetSampleRate SDLAudioBuffer.sampleRate 
GetSampleSize GAPGAP - WebAudio仅使用32位浮点数,PPAPI使用16位int。PPAPI理论上支持多种采样大小。实际上,它只支持16位采样。不幸的是,开发人员已经要求16位样本大小以节省内存使用。
GetNumberOfChannels SDLAudioBuffer.numberOfChannels 
GetDataBuffer SDLAudioBuffer.getChannelData 
GetBufferSize SDLAudioBuffer.length 

PPB_AudioConfig

PPAPI方法假设线程EmscriptenWeb API限制
CreateStereo16Bit GAPGAP - 仅支持32位浮点样本 
GetSampleRate SDLAudioContext.sampleRate 
GetSampleFrameCount SDLAudioBuffer.length 
RecommendSampleRate SDLAudioContext.sampleRate(来自默认构造)默认情况下,AudioContext将具有首选采样率。
RecommendSampleFrameCount GAPGAP - 没有获得推荐缓冲区大小的机制。 

PPB_Console

PPAPI方法假设线程EmscriptenWeb API限制
Log UTIMEconsole.log/warn/error/... 
LogWithSource GAPGAPPPAPI提供了一种覆盖控制台消息中的源文件名和行号的方法。(虽然JS API提供了样式文本的方法)。

PPB_Core

PPAPI方法假设线程EmscriptenWeb API限制
getTime utimenew Date().getTime() 
getTimeTicks utimenew Date().getTime() 
IsMainThread GAPwindow.document !== undefined 
CallOnMainThread GAPWorker.postMessage + Atomics.wait可以构建等效同步。

PPB_FileIO

PPAPI方法假设线程EmscriptenWeb API限制
Create FS (partial)FileReader / FileWrite (Entry.createReader / Entry.createWriter)创建和打开使用的方式不同,但这些部分具有相同的功能。
Open FS (partial)FileReader / FileWrite (Entry.createReader / Entry.createWriter) 
Query FS (partial)Entry.getMetadata 
Touch FS (partial)GAP (partial) - No direct equivalent, but no access time either.修改时间可以通过写入来提高。
Read FS (partial)Entry.getFile + Blob.slice + FileReader.getBinaryData请注意,此API需要额外的副本才能读取线性内存,如果Blob切片未使用mmap进行优化,则可能会更糟。
Write FS (partial)FileWriter.seek + FileWriter.write 'write*' Events 
SetLength FS (partial)FileWriter.truncate + 'write*' Events 
Flush GAPGAP - No equivalent, no way to flush. 
Close FS (partial)No equivalent, open files and directories are implicitly closed. 
ReadToArray GAPGAP - No equivalent.允许并行多个子范围读取。

PPB_FileRef

 

PPAPI方法假设线程EmscriptenWeb API限制
Create FS (partial)Entry.getFile(..., {create:true}) 
GetFileSystemType FS (partial)FileSystem.type 
GetName FS (partial)Entry.name 
GetPath FS (partial)Entry.fullPath 
GetParent FS (partial)Entry.getParent 
MakeDirectory FS (partial)Entry.getDirectory(..., {create:true}) 
Touch FS (partial)GAP (partial) - No direct equivalent, but no access time either.修改时间可以通过写入来提高。
Delete FS (partial)Entry.remove 
Rename FS (partial)Entry.moveTo 
Query GAPEntry.getMetadataGAP - JS API具有文件大小和上次修改日期,但没有创建日期和上次访问日期。
ReadDirectoryEntries FS (partial)Directory.readEntries 

PPB_FileSystem

PPAPI方法假设线程EmscriptenWeb API限制
Create FS (partial)window.requestFileSystemJS API只需一步即可完成
Open GAPwindow.requestFileSystemGAP - Filesystems API仅限chrome。IndexedDB在子范围写入方面具有额外的性能限制。
GetType GAPFileSystem.type 

PPB_Fullscreen

PPAPI方法假设线程EmscriptenWeb API限制
IsFullScreen html5.hDocument.fullscreenEnabled 
SetFullscreen html5.hDocument.requestFullscreen 
GetScreenSize html5.hDocument.exitFullscreen 

PPB_Gamepad

PPAPI方法假设线程EmscriptenWeb API限制
Sample SDLGamepad.*GAP - PPAPI公开了一个时间戳值,但JS API没有提供这个(虽然它是规范的)。

PPB_Graphics2D

PPAPI方法假设线程EmscriptenWeb API限制
Create SDLCanvas.getContext('2d') 
Describe SDLCanvas.clientWidth + Canvas.clientHeight 
PaintImageData SDLCanvasRenderingContext2d.putImageData 
Scroll GAPCanvasRenderingContext2d.scrollIntoViewGAP(部分) - 不完全匹配(可能必须求助于getImageData + putImageData,这将很慢)。不是跨浏览器标准。
ReplaceContents SDLCanvasRenderingContext2d.drawImage 
Flush GAPGAP - 仅返回事件循环会触发刷新。 
SetScale SDLCanvasRenderingContext2d.scale 
GetScale SDLCanvasRenderingContext2d.currentTransform 
SetLayerTransform SDLCanvasRenderingContext2d.setTransform CanvasRenderingContext2d.scale CanvasRenderingContext2d.translate 

PPB_Graphics3D

PPAPI方法假设线程EmscriptenWeb API限制
GetAttribMaxValue 
GAP
GAP - Canvas.getContext允许您设置请求某些大小的深度/模板缓冲区的布尔值,但无法查询可能的内容(或者获取除了开启或关闭之外的任何内容) 
Create SDLCanvas.getContext 
GetAttribs SDLWebGLRenderingContext.getContextAttributes 
SetAttribs SDLCanvas.getContext(.., OPTIONS) 
GetError SDLWebGLRenderingContext.getError 
ResizeBuffers SDLCanvas.width = w; Canvas.height = h; 
SwapBuffers GAPGAP - 无法显式翻转帧,必须返回事件循环. 

PPB_ImageData

PPAPI方法假设线程EmscriptenWeb API限制
GetNativeImageDataFormat SDLImageData mandates RGBA order 
IsImageDataFormatSupported SDLImageData mandates RGBA order 
Create SDLCanvasRenderingContext2d.createImageData 
Describe SDLImageData never has a stride 
Map SDLImageData.data 
Unmap SDLImageData.data 

PPB_InputEvent

PPAPI方法假设线程EmscriptenWeb API限制
RequestInputEvents SDL没有直接的等价物

由于JS / Wasm在主线程上运行,

并且可以更便宜地过滤事件而不

会导致跨进程往返,因此缺少此

功能可能不太相关。

RequestFilteringInputEvents SDLmouse* key* wheel* touch* composition* Events 
  SDLElement.addEventListener 
ClearInputEventRequest SDLElement.removeEventListener 
GetType SDLEvent class descendants 
GetTimeStamp SDLEvent.timeStamp 
GetModifiers SDL*Event.altKey/shiftKey/metaKey/ctrlKey 

PPB_MouseInputEvent

PPAPI方法假设线程EmscriptenWeb API限制
Create SDLMouseEvent 
GetButton SDLMouseEvent.button 
GetPosition SDLMouseEvent.client*/page*/offset* 
GetClickCount SDLdblclick' vs 'mousedown' Events 
GetMovement SDLMouseEvent.movement* 

PPB_WheelInputEvent

PPAPI方法假设线程EmscriptenWeb API限制
Create SDLWheelEvent 
GetDelta SDLWheelEvent.delta * 
GetTicks GAPGAP - deltaMode有点包含此信息,但不完整。 
GetScrollByPage GAPGAP - deltaMode有点包含此信息,但不完整。 

PPB_KeyboardInputEvent

PPAPI方法假设线程EmscriptenWeb API限制
Create SDL的KeyboardEvent 
GetKeyCode SDLKeyboardEvent.keyCode 
GetCharacterText SDLKeyboardEvent.key 
GetScrollByPage SDLKeyboardEvent.code 

PPB_TouchInputEvent

PPAPI方法假设线程EmscriptenWeb API限制
Create SDL的TouchEvent 
AddTouchPoint SDLTouchEvent.touches.push 
GetTouchCount SDLTouchEvent.touches.length 
GetTouchByIndex SDLTouchEvent.touches [I] 
GetTouchById SDLTouch.indentifer(自己想出来) 

PPB_IMEInputEvent

PPAPI方法假设线程EmscriptenWeb API限制
Create GAPCompositionEvent 
getText GAPCompositionEvent.data 
GetSegmentNumber GAPGAP - 没有直接的等价物 
GetSegmentOffset GAPGAP - 没有直接的等价物 
GetTargetSegment GAPGAP - 没有直接的等价物 
GetSelection GAPGAP - 没有直接的等价物 

PPB_Instance

PPAPI方法假设线程EmscriptenWeb API限制
BindGraphics SDLCanvas.getContext(作为绑定是自动的)。 
IsFullFrame GAPGAP - 不等同于mime类型处理程序。可以注册NaCl应用程序来处理特定的mime类型并拥有整个文档。

PPB_MediaStreamAudioTrack

PPAPI方法假设线程EmscriptenWeb API限制
配置 GAPGAP - 没有等价物 
GetAttrib GAPMediaStreamSettings.channelCount 
  GAPMediaStreamSettings.sampleSize 
  GAPMediaStreamSettings.sampleRate 
  GAPGAP - 不等同于PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS 
  GAPGAP - 不等同于PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION 
GetId GAPMediaStream.id 
HasEnded GAPMediaStream.ended 
GetBuffer GAPGAP - 没有等价物 
RecycleBuffer GAPGAP - 没有等价物 
Close  GAP - 没有等价物 

PPB_MediaStreamVideoTrack

PPAPI方法假设线程EmscriptenWeb API限制
Create GAPGAP - 没有等价物能够创建合成流。
Configure GAPGAP - 没有等价物 
GetAttrib GAPMediaStreamSettings.width 
  GAPMediaStreamSettings.height 
  GAPGAP - 不等同于PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES 
  GAPGAP - 不等同于PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT 
GetId GAPMediaStream.id 
HasEnded GAPMediaStream.ended 
getFrame GAPGAP - 没有等价物 
RecycleFrame GAPGAP - 没有等价物 
Close GAPGAP - 没有等价物 
GetEmptyFrame GAPGAP - 没有等价物 
PutFrame GAPGAP - 没有等价物 

PPB_MessageLoop

PPAPI方法假设线程EmscriptenWeb API限制
Create N / A工人得到一个隐含的事件循环。 
GetForMainThread N / A工人得到一个隐含的事件循环。 
GetCurrent N / A工人得到一个隐含的事件循环。 
AttachToCurrentThread N / A工人得到一个隐含的事件循环。 
Run N / A工人得到一个隐含的事件循环。 
PostWork N / A工人得到一个隐含的事件循环。 
PostQuit N / A工人得到一个隐含的事件循环。 

PPB_Messaging

PPAPI方法假设线程EmscriptenWeb API限制
PostMessage的 N / AWindow.postMessage 
RegisterMessageHandler N / AWindow.addEventListener 
UnregisterMessageHandler N / AWindow.removeEventListener 

PPB_MouseCursor

PPAPI方法假设线程EmscriptenWeb API限制
setCursor SDLElement.style.cursor支持相同的库存光标集。自定义游标可以使用url(..)完成。动态自定义游标可以使用数据URI完成。CSS3支持指定热点。

PPB_MouseLock

PPAPI方法假设线程EmscriptenWeb API限制
LockMouse SDLElement.requestPointerLock 
UnlockMouse SDLElement.exitPointerLock 

PPB_OpenGLES2

PPAPI方法假设线程EmscriptenWeb API限制
Several Methods OpenGLES在功能上接近WebGL 1.0。 
 X GAP - 没有屏幕外画布,渲染必须在主线程上完成。 

PPB_TextInputController

PPAPI方法假设线程EmscriptenWeb API限制
SetTextInputType GAPGAP - 没有关于浏览器包含输入的等效提示。一些开发人员希望能够以这种方式提示,或者最好能够在画布内嵌入和显示内联的IME事件/输出。
UpdateCaretPosition GAPGAP - 没有关于浏览器包含输入的等效提示。 
CancelCompositionText GAPGAP - 没有关于浏览器包含输入的等效提示。 
UpdateSurroundingText GAPGAP - 没有关于浏览器包含输入的等效提示。 

PPB_URLLoader

PPAPI方法假设线程EmscriptenWeb API限制
Create embindnew XMLHttpRequest(); 
Open embindXMLHttpRequest.open 
FollowRedirect embindRequest.redirect 
  GAPGAP - 没有XMLHTTPRequest等价物 
GetUploadProgress embindXMLHttpRequest'progress'事件 
  GAPGAP - 没有等效的Fetch API 
GetDownloadProgress embindXMLHttpRequest'progress'事件 
  GAPGAP - 没有等效的Fetch API 
GetResponseInfo embindXMLHttpRequest.getAllResponseHeaders 
  embind获取响应。* 
ReadResponseBody embindXMLHttpRequest.response 
  embind身体。*(响应是身体) 
FinishStreamingToFile embindGAP - 没有直接的等价物XMLHttpRequest和Fetch都假设流式传输到内存,而不是直接到存储。
Close embindXMLHttpRequest.abort 
  GAPGAP - 没有等效的Fetch API 

PPB_URLRequestInfo

PPAPI方法假设线程EmscriptenWeb API限制
Create embindXMLHttpRequest的 
  embind获取请求无法流式传输到文件。
SetProperty GAPGAP - 没有XMLHttpRequest的直接等价物XMLHttpRequest不提供重定向后的每个请求限制的直接方法,流式传输到文件,设置引用者或凭据策略。
  embind请求。* 
AppendDataToBody embindXMLHttpRequest.sendGAP - 两者都必须拥有整个身体,而不是一块。
  embindfetch(..,options:body) 
AppendFileToBody GAPGAP - 没有直接的等价物 
  N / A<FORM>您也可以使用FileReader阅读并上传,但这更像是AppendDataToBody

PPB_URLResponseInfo

PPAPI方法假设线程EmscriptenWeb API限制
getProperty embindXMLHttpRequest.getAllResponseHeaders + others 
  embindFetch Response.* 
GetBodyAsFileRef embindFetch Response (Body) .blob()假设存储层优化传输。

PPB_Var

PPAPI方法假设线程EmscriptenWeb API限制
VarFromUtf8 embindTextDecoder.decode 
VarToUtf8 embindTextEncoder.encode 
VarFromResource N / AN / A 
VarToResource N / AN / A 

PPB_VarArray

PPAPI方法假设线程EmscriptenWeb API限制
Get embind阵列[I] 
Set embind数组[i] = x 
GetLength embindArray.length 
SetLength embindArray.length = n 

PPB_VarArrayBuffer

PPAPI方法假设线程EmscriptenWeb API限制
Create embindnew ArrayBuffer(n) 
ByteLength embindArrayBuffer.byteLength 
Map GAPGAP - 没有直接的等价物Asm.js / Wasm模块无法映射除单个线性内存堆之外的ArrayBuffer区域。未来的多个记忆或内存映射可能会改善这一点
Unmap GAPGAP - 没有直接的等价物 

PPB_VarDictionary

PPAPI方法假设线程EmscriptenWeb API限制
Create embind{} 
Get embind<Object>[i] 
Set embind<Object>[i] = x 
Delete embinddelete <Object>[i] 
HasKey embindx in <Object> 
GetKeys embindfor (k in <Object>) {}没有字面上的等价物,但它可以构建。

PPB_VideoDecoder

PPAPI方法假设线程EmscriptenWeb API限制
Create GAPGAP - No equivalent 
Initialize GAPGAP - No equivalent 
Decode GAPGAP - No equivalent 
GetPicture GAPGAP - No equivalent 
RecyclePicture GAPGAP - No equivalent 
Flush GAPGAP - No equivalent 
Reset GAPGAP - No equivalent 

PPB_VideoEncoder

PPAPI方法假设线程EmscriptenWeb API限制
Create GAPGAP - No equivalentOverlap with MediaRecorder API, but not exact.
GetSupportedProfiles GAPGAP - No equivalent 
Initialize GAPGAP - No equivalent 
GetFramesRequired GAPGAP - No equivalent 
GetFrameCodedSize GAPGAP - No equivalent 
GetVideoFrame GAPGAP - No equivalent 
Encode GAPGAP - No equivalent 
GetBitstreamBuffer GAPGAP - No equivalent 
RecycleBitstreamBuffer GAPGAP - No equivalent 
RequestEncodingParametersChange GAPGAP - No equivalent 
Close GAPGAP - No equivalent

 

PPB_VideoFrame

PPAPI方法假设线程EmscriptenWeb API限制
GetTimestamp 间隙GAP - 没有等价物 
setTimestamp 间隙GAP - 没有等价物 
getFormat 间隙GAP - 没有等价物 
getSize 间隙GAP - 没有等价物 
GetDataBuffer 间隙GAP - 没有等价物 
GetDataBufferSize 间隙GAP - 没有等价物 

PPB_View

PPAPI方法假设线程EmscriptenWeb API限制
GetRect embindElement.getBoundingClientRect 
IsFullscreen embindDocument.fullScreenEnabled与文档相关而不仅仅是单个元素。
ISVISIBLE embindIntersectionObserver 
IsPageVisible embinddocument.visibilityState 
GetClipRect embindIntersectionObserver 
GetDeviceScale embindwindow.devicePixelRatio 
GetCSSScale embind<Element> .getBoundingClientRect()。width / <Element> .offsetWidth 
GetScrollOffset embind<Element> .scrollTop / <Element> .scrollLeft 

PPB_WebSocket

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPWebSocket.WebSocket 
Connect GAPWebSocket.WebSocket(url, ...) WebSocket 'open' Event 
Close GAPWebSocket.close 
ReceiveMessage GAPWebSocket 'message' Event WebSocket 'error' Event WebSocket 'close' Event 
SendMessage GAPWebSocket.send 
GetBufferedAmount GAPWebSocket.bufferedAmount 
GetCloseCode GAPCloseEvent.code 
GetCloseReason GAPCloseEvent.reason 
GetCloseWasClean GAPCloseEvent.wasClean 
GetExtensions GAPWebSocket.extensions 
GetProtocol GAPWebSocket.protocol 
GetReadyState GAPWebSocket.readyState 
GetURL GAPWebSocket.url 

PPP_Graphics3D

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Graphics3DContextLost SDLCanvas 'webglcontextlost' Event 

PPP_InputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleInputEvent SDLElement.addEventListener 

PPP_Instance

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
DidCreate N/A<Element>[key]General DOM access lets you fish out tag attributes
DidDestroy N/AN/ANot triggered for NaCl
DidChangeView N/AElement 'resize' Event 
DidChangeFocus N/AElement 'focus', 'focusin', 'focusout' Events 
HandleDocumentLoad N/AGAP - No way to register as a mime type handlerNaCl modules via apps + a manifest entry can be set up to handle particular mime types.

PPP_MessageHandler

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleMessage embindMessagePort 'message' Event Window 'message' Event 
HandleBlockingMessage N/AGAP - No direct equivalentSimilar synchronization can be done off main thread with Atomics.wait. This was added to support emulation of synchronous plugin APIs.

PPP_Messaging

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleMessage embindMessagePort 'message' Event Window 'message' Event 

PPP_MouseLock

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
MouseLockLost SDLElement 'pointerlockchange', 'pointerlockerror' Events 

IRT

PPB_Audio

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreatexSDL (partial)GAP (partial) - AudioWorkletNode ROUGHLY equivalentStill being standardized.
GetCurrentConfig SDLAudioContext.* (gets back settings passed in) 
StartPlayback SDLAudioBufferSourceNode.start 
StopPlayback SDLAudioBufferSourceNode.stop 

PPB_AudioBuffer

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetTimestamp SDLAudioBufferSourceNode.start (parameter)Passed in each time instead of attached to the buffer.
SetTimestamp SDLAudioBufferSourceNode.start (parameter) 
GetSampleRate SDLAudioBuffer.sampleRate 
GetSampleSize GAPGAP - WebAudio only uses 32-bit float, PPAPI does 16-bit int.PPAPI theoretically supports multiple sampling sizes. In practice, it only supports 16-bit samples. Unfortunately, developers have requested 16-bit sample sizes to save on memory use.
GetNumberOfChannels SDLAudioBuffer.numberOfChannels 
GetDataBuffer SDLAudioBuffer.getChannelData 
GetBufferSize SDLAudioBuffer.length 

PPB_AudioConfig

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreateStereo16Bit GAPGAP - Only 32-bit float samples supported 
GetSampleRate SDLAudioContext.sampleRate 
GetSampleFrameCount SDLAudioBuffer.length 
RecommendSampleRate SDLAudioContext.sampleRate (from default construct)An AudioContext will have the preferred sampling rate by default.
RecommendSampleFrameCount GAPGAP - No mechanism to get a recommended buffer size. 

PPB_Console

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Log utimeconsole.log/warn/error/... 
LogWithSource GAPGAPPPAPI provides a way to override the source filename and line number in a console message. (Though JS API provides way to style text).

PPB_Core

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
getTime utimenew Date().getTime() 
getTimeTicks utimenew Date().getTime() 
IsMainThread GAPwindow.document !== undefined 
CallOnMainThread GAPWorker.postMessage + Atomics.waitEquivalent synchronization can be built.

PPB_FileIO

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create FS (partial)FileReader / FileWrite (Entry.createReader / Entry.createWriter)Create and open are used differently, but the pieces are of equal power.
Open FS (partial)FileReader / FileWrite (Entry.createReader / Entry.createWriter) 
Query FS (partial)Entry.getMetadata 
Touch FS (partial)GAP (partial) - No direct equivalent, but no access time either.Modify time can be bumped by writing.
Read FS (partial)Entry.getFile + Blob.slice + FileReader.getBinaryDataNote, this API requires an extra copy to get a read into linear memory, and may be worse than that if Blob slices are not optimizes to use mmap.
Write FS (partial)FileWriter.seek + FileWriter.write 'write*' Events 
SetLength FS (partial)FileWriter.truncate + 'write*' Events 
Flush GAPGAP - No equivalent, no way to flush. 
Close FS (partial)No equivalent, open files and directories are implicitly closed. 
ReadToArray GAPGAP - No equivalent.Allows multiple subrange reads in parallel.

PPB_FileRef

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create FS (partial)Entry.getFile(..., {create:true}) 
GetFileSystemType FS (partial)FileSystem.type 
GetName FS (partial)Entry.name 
GetPath FS (partial)Entry.fullPath 
GetParent FS (partial)Entry.getParent 
MakeDirectory FS (partial)Entry.getDirectory(..., {create:true}) 
Touch FS (partial)GAP (partial) - No direct equivalent, but no access time either.Modify time can be bumped by writing.
Delete FS (partial)Entry.remove 
Rename FS (partial)Entry.moveTo 
Query GAPEntry.getMetadataGAP - JS API has file size and last modified date, but doesn't have creation date and last accessed date.
ReadDirectoryEntries FS (partial)Directory.readEntries 

PPB_FileSystem

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create FS (partial)window.requestFileSystemJS API does both in one step
Open GAPwindow.requestFileSystemGAP - Filesystems API is chrome only. IndexedDB has additional performance limitations around subrange writes.
GetType GAPFileSystem.type 

PPB_Fullscreen

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
IsFullScreen html5.hDocument.fullscreenEnabled 
SetFullscreen html5.hDocument.requestFullscreen 
GetScreenSize html5.hDocument.exitFullscreen 

PPB_Gamepad

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Sample SDLGamepad.*GAP - PPAPI exposes a timestamp value, but the JS API doesn't provide this (though it is spec'd).

PPB_Graphics2D

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create SDLCanvas.getContext('2d') 
Describe SDLCanvas.clientWidth + Canvas.clientHeight 
PaintImageData SDLCanvasRenderingContext2d.putImageData 
Scroll GAPCanvasRenderingContext2d.scrollIntoViewGAP (partial) - Not an exact match (might have to resort to getImageData + putImageData which will be slow). Not a cross-browser standard.
ReplaceContents SDLCanvasRenderingContext2d.drawImage 
Flush GAPGAP - Only returning to the event loop triggers the flush. 
SetScale SDLCanvasRenderingContext2d.scale 
GetScale SDLCanvasRenderingContext2d.currentTransform 
SetLayerTransform SDLCanvasRenderingContext2d.setTransform CanvasRenderingContext2d.scale CanvasRenderingContext2d.translate 

PPB_Graphics3D

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetAttribMaxValue GAPGAP - Canvas.getContext lets you set booleans requesting depth / stencil buffers of certain sizes, but does not have a way to query what's possible (or get anything other than on or off for each) 
Create SDLCanvas.getContext 
GetAttribs SDLWebGLRenderingContext.getContextAttributes 
SetAttribs SDLCanvas.getContext(.., OPTIONS) 
GetError SDLWebGLRenderingContext.getError 
ResizeBuffers SDLCanvas.width = w; Canvas.height = h; 
SwapBuffers GAPGAP - No way to explicitly flip a frame, must return to the event loop. 

PPB_ImageData

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetNativeImageDataFormat SDLImageData mandates RGBA order 
IsImageDataFormatSupported SDLImageData mandates RGBA order 
Create SDLCanvasRenderingContext2d.createImageData 
Describe SDLImageData never has a stride 
Map SDLImageData.data 
Unmap SDLImageData.data 

PPB_InputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
RequestInputEvents SDLNo direct equivalentThe lack of this feature is probably less relevant as JS / Wasm runs on the main thread and can more cheaply filter events without incurring a cross process round-trip.
RequestFilteringInputEvents SDLmouse* key* wheel* touch* composition* Events 
  SDLElement.addEventListener 
ClearInputEventRequest SDLElement.removeEventListener 
GetType SDLEvent class descendants 
GetTimeStamp SDLEvent.timeStamp 
GetModifiers SDL*Event.altKey/shiftKey/metaKey/ctrlKey 

PPB_MouseInputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create SDLMouseEvent 
GetButton SDLMouseEvent.button 
GetPosition SDLMouseEvent.client*/page*/offset* 
GetClickCount SDLdblclick' vs 'mousedown' Events 
GetMovement SDLMouseEvent.movement* 

PPB_WheelInputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create SDLWheelEvent 
GetDelta SDLWheelEvent.delta* 
GetTicks GAPGAP - deltaMode kinda of contains this info, but incompletely. 
GetScrollByPage GAPGAP - deltaMode kinda of contains this info, but incompletely. 

PPB_KeyboardInputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create SDLKeyboardEvent 
GetKeyCode SDLKeyboardEvent.keyCode 
GetCharacterText SDLKeyboardEvent.key 
GetCode SDLKeyboardEvent.code 

PPB_TouchInputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create SDLTouchEvent 
AddTouchPoint SDLTouchEvent.touches.push 
GetTouchCount SDLTouchEvent.touches.length 
GetTouchByIndex SDLTouchEvent.touches[i] 
GetTouchById SDLTouch.indentifer (to figure this out yourself) 

PPB_IMEInputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPCompositionEvent 
GetText GAPCompositionEvent.data 
GetSegmentNumber GAPGAP - No direct equivalent 
GetSegmentOffset GAPGAP - No direct equivalent 
GetTargetSegment GAPGAP - No direct equivalent 
GetSelection GAPGAP - No direct equivalent 

PPB_Instance

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
BindGraphics SDLCanvas.getContext (moot as binding is automatic). 
IsFullFrame GAPGAP - No equivalent to mime type handlers.NaCl apps can be registered to handle a particular mime type and own the whole document.

PPB_MediaStreamAudioTrack

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Configure GAPGAP - No equivalent 
GetAttrib GAPMediaStreamSettings.channelCount 
  GAPMediaStreamSettings.sampleSize 
  GAPMediaStreamSettings.sampleRate 
  GAPGAP - no equivalent to PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS 
  GAPGAP - no equivalent to PP_MEDIASTREAMAUDIOTRACK_ATTRIB_DURATION 
GetId GAPMediaStream.id 
HasEnded GAPMediaStream.ended 
GetBuffer GAPGAP - No equivalent 
RecycleBuffer GAPGAP - No equivalent 
Close GAPGAP - No equivalent 

PPB_MediaStreamVideoTrack

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPGAP - No equivalentAbility to create synthetic stream.
Configure GAPGAP - No equivalent 
GetAttrib GAPMediaStreamSettings.width 
  GAPMediaStreamSettings.height 
  GAPGAP - no equivalent to PP_MEDIASTREAMVIDEOTRACK_ATTRIB_BUFFERED_FRAMES 
  GAPGAP - no equivalent to PP_MEDIASTREAMVIDEOTRACK_ATTRIB_FORMAT 
GetId GAPMediaStream.id 
HasEnded GAPMediaStream.ended 
GetFrame GAPGAP - No equivalent 
RecycleFrame GAPGAP - No equivalent 
Close GAPGAP - No equivalent 
GetEmptyFrame GAPGAP - No equivalent 
PutFrame GAPGAP - No equivalent 

PPB_MessageLoop

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create N/AMostly moot, workers get an implicit event loop. 
GetForMainThread N/AMostly moot, workers get an implicit event loop. 
GetCurrent N/AMostly moot, workers get an implicit event loop. 
AttachToCurrentThread N/AMostly moot, workers get an implicit event loop. 
Run N/AMostly moot, workers get an implicit event loop. 
PostWork N/AMostly moot, workers get an implicit event loop. 
PostQuit N/AMostly moot, workers get an implicit event loop. 

PPB_Messaging

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
PostMessage N/AWindow.postMessage 
RegisterMessageHandler N/AWindow.addEventListener 
UnregisterMessageHandler N/AWindow.removeEventListener 

PPB_MouseCursor

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
SetCursor SDLElement.style.cursorSame set of stock cursors are supported. Custom cursors can be done with url(..). Dynamic custom cursors can be done with data URIs. CSS3 supports specifying the hotspot.

PPB_MouseLock

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
LockMouse SDLElement.requestPointerLock 
UnlockMouse SDLElement.exitPointerLock 

PPB_OpenGLES2

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Several Methods OpenGLESClose to WebGL 1.0 in functionality. 
 x GAP - Without offscreen canvas, rendering must be done on the main thread. 

PPB_TextInputController

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
SetTextInputType GAPGAP - No equivalent hints to browser about canvas containing input.Some developers would like to either be able to hint in this fashion, or preferably the ability to intercept and display IME events / output inline inside a canvas.
UpdateCaretPosition GAPGAP - No equivalent hints to browser about canvas containing input. 
CancelCompositionText GAPGAP - No equivalent hints to browser about canvas containing input. 
UpdateSurroundingText GAPGAP - No equivalent hints to browser about canvas containing input. 

PPB_URLLoader

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create embindnew XMLHttpRequest(); 
Open embindXMLHttpRequest.open 
FollowRedirect embindRequest.redirect 
  GAPGAP - No XMLHTTPRequest equivalent 
GetUploadProgress embindXMLHttpRequest 'progress' Event 
  GAPGAP - No Fetch API equivalent 
GetDownloadProgress embindXMLHttpRequest 'progress' Event 
  GAPGAP - No Fetch API equivalent 
GetResponseInfo embindXMLHttpRequest.getAllResponseHeaders 
  embindFetch Response.* 
ReadResponseBody embindXMLHttpRequest.response 
  embindBody.* (Response is a Body) 
FinishStreamingToFile embindGAP - No direct equivalentXMLHttpRequest and Fetch both assume streaming to memory, rather than directly to a storage.
Close embindXMLHttpRequest.abort 
  GAPGAP - No Fetch API equivalent 

PPB_URLRequestInfo

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create embindXMLHttpRequest 
  embindFetch RequestNo way to stream to a file.
SetProperty GAPGAP - No direct equivalent for XMLHttpRequestXMLHttpRequest doesn't provide direct ways to per-request limit following redirects, stream to a file, set referrer or credentials policy.
  embindRequest.* 
AppendDataToBody embindXMLHttpRequest.sendGAP - Both must have the whole body, rather than a chunk.
  embindfetch(.., options:body) 
AppendFileToBody GAPGAP - No direct equivalent 
  N/A<form>You can also read with FileReader and upload, but that's more like AppendDataToBody

PPB_URLResponseInfo

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetProperty embindXMLHttpRequest.getAllResponseHeaders + others 
  embindFetch Response.* 
GetBodyAsFileRef embindFetch Response (Body) .blob()Assumes storage layer optimizes transfer.

PPB_Var

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
VarFromUtf8 embindTextDecoder.decode 
VarToUtf8 embindTextEncoder.encode 
VarFromResource N/AN/A 
VarToResource N/AN/A 

PPB_VarArray

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Get embindArray[i] 
Set embindArray[i] = x 
GetLength embindArray.length 
SetLength embindArray.length = n 

PPB_VarArrayBuffer

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create embindnew ArrayBuffer(n) 
ByteLength embindArrayBuffer.byteLength 
Map GAPGAP - No direct equivalentAsm.js / Wasm modules are unable to map regions of an ArrayBuffer other than their single linear memory heap. Future multiple memories or memory mapping might improve this.
Unmap GAPGAP - No direct equivalent 

PPB_VarDictionary

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create embind{} 
Get embind<Object>[i] 
Set embind<Object>[i] = x 
Delete embinddelete <Object>[i] 
HasKey embindx in <Object> 
GetKeys embindfor (k in <Object>) {}No literal equivalent, but it can be built.

PPB_VideoDecoder

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPGAP - No equivalent 
Initialize GAPGAP - No equivalent 
Decode GAPGAP - No equivalent 
GetPicture GAPGAP - No equivalent 
RecyclePicture GAPGAP - No equivalent 
Flush GAPGAP - No equivalent 
Reset GAPGAP - No equivalent 

PPB_VideoEncoder

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPGAP - No equivalentOverlap with MediaRecorder API, but not exact.
GetSupportedProfiles GAPGAP - No equivalent 
Initialize GAPGAP - No equivalent 
GetFramesRequired GAPGAP - No equivalent 
GetFrameCodedSize GAPGAP - No equivalent 
GetVideoFrame GAPGAP - No equivalent 
Encode GAPGAP - No equivalent 
GetBitstreamBuffer GAPGAP - No equivalent 
RecycleBitstreamBuffer GAPGAP - No equivalent 
RequestEncodingParametersChange GAPGAP - No equivalent 
Close GAPGAP - No equivalent 

PPB_VideoFrame

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetTimestamp GAPGAP - No equivalent 
SetTimestamp GAPGAP - No equivalent 
GetFormat GAPGAP - No equivalent 
GetSize GAPGAP - No equivalent 
GetDataBuffer GAPGAP - No equivalent 
GetDataBufferSize GAPGAP - No equivalent 

PPB_View

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetRect embindElement.getBoundingClientRect 
IsFullscreen embindDocument.fullScreenEnabledPertains to document instead of just single element.
IsVisible embindIntersectionObserver 
IsPageVisible embinddocument.visibilityState 
GetClipRect embindIntersectionObserver 
GetDeviceScale embindwindow.devicePixelRatio 
GetCSSScale embind<Element>.getBoundingClientRect().width / <Element>.offsetWidth 
GetScrollOffset embind<Element>.scrollTop / <Element>.scrollLeft 

PPB_WebSocket

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Create GAPWebSocket.WebSocket 
Connect GAPWebSocket.WebSocket(url, ...) WebSocket 'open' Event 
Close GAPWebSocket.close 
ReceiveMessage GAPWebSocket 'message' Event WebSocket 'error' Event WebSocket 'close' Event 
SendMessage GAPWebSocket.send 
GetBufferedAmount GAPWebSocket.bufferedAmount 
GetCloseCode GAPCloseEvent.code 
GetCloseReason GAPCloseEvent.reason 
GetCloseWasClean GAPCloseEvent.wasClean 
GetExtensions GAPWebSocket.extensions 
GetProtocol GAPWebSocket.protocol 
GetReadyState GAPWebSocket.readyState 
GetURL GAPWebSocket.url 

PPP_Graphics3D

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
Graphics3DContextLost SDLCanvas 'webglcontextlost' Event 

PPP_InputEvent

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleInputEvent SDLElement.addEventListener 

PPP_Instance

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
DidCreate N/A<Element>[key]General DOM access lets you fish out tag attributes
DidDestroy N/AN/ANot triggered for NaCl
DidChangeView N/AElement 'resize' Event 
DidChangeFocus N/AElement 'focus', 'focusin', 'focusout' Events 
HandleDocumentLoad N/AGAP - No way to register as a mime type handlerNaCl modules via apps + a manifest entry can be set up to handle particular mime types.

PPP_MessageHandler

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleMessage embindMessagePort 'message' Event Window 'message' Event 
HandleBlockingMessage N/AGAP - No direct equivalentSimilar synchronization can be done off main thread with Atomics.wait. This was added to support emulation of synchronous plugin APIs.

PPP_Messaging

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
HandleMessage embindMessagePort 'message' Event Window 'message' Event 

PPP_MouseLock

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
MouseLockLost SDLElement 'pointerlockchange', 'pointerlockerror' Events 

PPAPI (Apps)

PPB_HostResolver

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreatexGAPGAP (partial) - No direct equivalent 
ResolvexGAPGAP (partial) - No direct equivalent 
GetCanonicalNamexGAPGAP (partial) - No direct equivalent 
GetNetAddressCountxGAPGAP (partial) - No direct equivalent 
GetNetAddressxGAPGAP (partial) - No direct equivalent 

PPB_NetAddress

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreateFromIPv4AddressxGAPGAP (partial) - No direct equivalent 
CreateFromIPv6AddressxGAPGAP (partial) - No direct equivalent 
GetFamilyxGAPGAP (partial) - No direct equivalent 
DescribeAsStringxGAPGAP (partial) - No direct equivalent 
DescribeAsIPv4AddressxGAPGAP (partial) - No direct equivalent 
DescribeAsIPv6AddressxGAPGAP (partial) - No direct equivalent 

PPB_NetworkList

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetCountxGAPGAP - No direct equivalent 
GetNamexGAPGAP - No direct equivalent 
GetTypexGAPGAP - No direct equivalent 
GetStatexGAPGAP - No direct equivalent 
GetIpAddressxGAPGAP - No direct equivalent 
GetDisplayNamexGAPGAP - No direct equivalent 
GetMTUxGAPGAP - No direct equivalent 

PPB_NetworkMonitor

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreatexGAPGAP - No direct equivalent 
UpdateNetworkListxGAPGAP - No direct equivalent 

PPB_NetworkProxy

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
GetProxyForURLxGAPGAP - No direct equivalent 

PPB_TCPSocket

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreatexGAPchrome.sockets.tcp.createWebSockets / WebRTC closest practical equivalent on open Web.
 xGAPchrome.sockets.tcpServer.create 
BindxGAPchrome.sockets.tcpServer.create 
ConnectxGAPchrome.sockets.tcp.connect 
GetLocalAddressxGAPchrome.sockets.udp.SocketInfo 
GetRemoteAddressxGAPchrome.sockets.udp.SocketInfo 
ReadxGAPonReceive* Events 
WritexGAPchrome.sockets.tcp.send 
ListenxGAPchrome.sockets.tcpServer.listen 
AcceptxGAPonAccept* Events 
ClosexGAPchrome.sockets.tcp.close 
 xGAPchrome.sockets.tcpServer.close 
SetOptionxGAPchrome.sockets.tcp.update 
 xGAPchrome.sockets.tcpServer.update 

PPB_UDPSocket

PPAPI MethodAssumes ThreadsEmscriptenWeb APILimitations
CreatexGAPchrome.sockets.udp.createGAP (partial) - WebRTC closest practical open Web equivalent
BindxGAPchrome.sockets.udp.bind 
GetBoundAddressxGAPchrome.sockets.udp.SocketInfo 
RecvFromxGAPonReceive* Events 
SendToxGAPchrome.sockets.udp.send 
ClosexGAPchrome.sockets.udp.close 
SetOptionxGAPchrome.sockets.udp.update 
JoinGroupxGAPchrome.sockets.udp.joinGroup 
LeaveGroupxGAPchrome.sockets.udp.leaveGroup

CC-By 3.0许可下提供的内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值