如何在Native客户端和javascript中发送数组缓冲区
how to send array buffer from and to in Native client and javascript
我想从Javascript向Native Client模块发送一个数组缓冲区,然后将数组缓冲区转换为整数指针。我在nacl-sdk目录中看到了地球的例子。他们正在传递图像数据,并像这样转换:
//javascript
var imageData = context.getImageData(0, 0, img.width, img.height);
// Send NaCl module the raw image data obtained from canvas.
common.naclModule.postMessage({'message' : 'texture',
'name' : name,
'width' : img.width,
'height' : img.height,
'data' : imageData.data.buffer});
//nativeclient
std::string name = dictionary.Get("name").AsString();
int width = dictionary.Get("width").AsInt();
int height = dictionary.Get("height").AsInt();
pp::VarArrayBuffer array_buffer(dictionary.Get("data"));
if (!name.empty() && !array_buffer.is_null()) {
if (width > 0 && height > 0) {
uint32_t* pixels = static_cast<uint32_t*>(array_buffer.Map());
SetTexture(name, width, height, pixels);
array_buffer.Unmap();
我正在使用eclipse调试,我不知道如何检查数组缓冲区是否正确接收,以及是否可以将像素作为参数传递给某个函数,或者在传递之前必须使用pixels = new uint32_t[size]
创建它们。更重要的是,我需要知道如何将uint32_t*
像素转换为VarArrayBuffer
,并使用字典将其发送到Javascript并发布消息,以及如何在Javascript中接收并将消息作为ArrayBuffer
值处理。
最简单的例子是SDK中的ArrayBuffer示例(examples/api/var_array_buffer)。
ArrayBuffer的内存归pp::VarArrayBuff所有,所以只要您有对它的引用(并且您还没有调用pp::VarArrayBuffer::Unmap),就不必复制内存。
pp::Var变量是自动引用计数的,所以您不需要显式调用AddRef。
相关文章:
- 将ajax数组缓冲区响应绘制到画布中
- 使用 ajax 时没有从文本到数组缓冲区的转换
- JavaScript-将数组缓冲区转换为字符串
- 使用 AJAX 上传数组缓冲区(音频缓冲区)的最佳方法
- 编码然后在 base64 中解码不会输出我的输入数组缓冲区
- 有没有办法将数组缓冲区从javascript传递到Android上的java
- Firefox操作系统-在物理硬件上中断XMLHttpRequest数组缓冲区请求
- 如何将数组缓冲区转换为字符串
- Webaudio API:将数组缓冲区作为文件存储在服务器上,稍后检索
- dojo/使用NodeJS请求一个png图像数组缓冲区,并将图像返回给客户端
- 数组缓冲区IE10-类型化的数组构造函数参数无效
- 如何识别数组缓冲区是字符串还是图像
- HTML5 Audio API inputBuffer.getChannelData到音频数组缓冲区
- 将数组缓冲区转换为字符串
- 不能给类型化数组缓冲区赋值
- 音频数组缓冲区到音频元素
- javascript readAsArrayBuffer返回空数组缓冲区
- 在JavaScript中转换任何数据到数组缓冲区
- NodeJS提取数组缓冲区的视频作为图像
- RangeError:无效的数组缓冲区长度