从handle得到GraphicBuffer

先定义一个宏:

cpp 复制代码
#ifndef container_of
#define container_of(ptr, type, member) \
    (type *)((char*)(ptr) - offsetof(type, member))
#endif

然后:

cpp 复制代码
ANativeWindowBuffer *anwBuffer = container_of(buffer, ANativeWindowBuffer, handle);

其中buffer的类型是:

cpp 复制代码
buffer_handle_t *buffer;

得到ANativeWindowBuffer以后:

cpp 复制代码
sp<GraphicBuffer> GraphicBuffer::from(ANativeWindowBuffer* anwb) {
    return static_cast<GraphicBuffer *>(anwb);
}
相关推荐
KdanMin2 小时前
Android Launcher3 首屏图标锁定技术方案解析
android
VincentStory7 小时前
分享一个项目中遇到的一个算法题
android·算法
yechaoa9 小时前
【揭秘大厂】技术专项落地全流程
android·前端·后端
Cachel wood10 小时前
Mysql相关知识:存储引擎、sql执行流程、索引失效
android·人工智能·sql·mysql·算法·前端框架·ab测试
alexhilton11 小时前
实战:在Compose中绘制睡眠时间线
android·kotlin·android jetpack
每次的天空11 小时前
Android第四次面试总结(基础算法篇)
android·算法·面试
王景程11 小时前
Android Zygote的进程机制
android·github·模块测试·zygote
thinkMoreAndDoMore11 小时前
Android Audio基础(54)——数字音频接口 I2S、PCM(TDM) 、PDM
android·嵌入式硬件·pcm
江太翁12 小时前
Android Composable 与 View 的联系和区别
android