SurfaceTexture/Surface mapping with ANativeWindow

SurfaceTexture/Surface mapping with ANativeWindow

本文关键字:with ANativeWindow mapping Surface SurfaceTexture      更新时间:2023-10-16

给定一个GraphicBufferProduceer,我创建一个Surface,然后检索ANativeWindow。使用ANativeWindow_lock我得到一个指向缓冲区的指针。使用缓冲区,我对缓冲区进行了内存。问题是我在此缓冲区上绘制的任何内容都限制在屏幕的 25% 以下。请记住,buffer.width 和 buffer.height 的尺寸非常接近屏幕本身的分辨率。

我的问题是,为什么缓冲区只覆盖屏幕的一小部分?我如何确保它覆盖大部分(如果不是全部(屏幕?作为参考,以下是代码:

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。