使用 ANativeWindow 的 SurfaceTexture/Surface 映射 [英] SurfaceTexture/Surface mapping with ANativeWindow
问题描述
给定一个 GraphicBufferProducer,我创建一个 Surface,然后检索 ANativeWindow.使用 ANativeWindow_lock 我得到一个指向缓冲区的指针.使用缓冲区,我对缓冲区执行了 memcpy.问题是我在这个缓冲区上绘制的任何内容都被限制在屏幕的 25% 以下.请记住,buffer.width 和 buffer.height 的尺寸非常接近屏幕本身的分辨率.
Given a GraphicBufferProducer I create a Surface and then retrieve ANativeWindow. Using ANativeWindow_lock I get a pointer to the buffer. Using the buffer, I do a memcpy into the buffer. The problem is that whatever I draw on this buffer is restricted to less than 25% of the screen. Keep in mind that the dimensions of buffer.width and buffer.height are very close to the resolution of the screen itself.
我的问题是,为什么缓冲区只覆盖屏幕的一小部分?我如何确保它覆盖大部分(如果不是全部)屏幕?代码如下:
My question is, why does the buffer only cover a small portion of the screen? And how do I make sure it covers most if not all of the screen? For reference here's the code:
ANativeWindow_Buffer buffer;
// window is created from a "new Surface(sp<IGraphicBufferProducer>)"
if (ANativeWindow_lock(window, &buffer, NULL) == 0) {
// For testing purposes just put grey in the buffer
memcpy(buffer.bits, 0x99, buffer.width * buffer.height);
ANativeWindow_unlockAndPost(window);
}
推荐答案
我有一个猜测,虽然我从未使用过 ANativeWindow_Buffer.memcpy 复制一定数量的字节.您的图像每像素有多少位?如果该值大于 8,则不会传输完整的缓冲区.由于它可能是每像素 4 个字节 (AARRGGBB),因此您可能需要将其乘以 4.
I have a guess, although I've never used an ANativeWindow_Buffer. memcpy copies a certain number of bytes. How many bits per pixel is your image? If the value is greater than 8, you aren't transfering the full buffer. Since its probably 4 bytes per pixel (AARRGGBB), you probably need to multiply that by 4.
这篇关于使用 ANativeWindow 的 SurfaceTexture/Surface 映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!