从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);
}
相关推荐
我就是马云飞10 分钟前
我废了!大厂10年的我面了20家公司,面试官让我回去等通知!
android·前端·程序员
limuyang21 小时前
在 Android 上用上原生的 xxHash,性能直接拉满
android
Fate_I_C2 小时前
ViewModel 的生命周期与数据保持
android·kotlin
凛_Lin~~2 小时前
安卓实现textview跑马灯效果
android·java
Fate_I_C3 小时前
Kotlin函数一
android·开发语言·kotlin
我讲个笑话你可别哭啊3 小时前
Android Studio无线调试连接安卓设备
android·ide·android studio
pengyu3 小时前
【Kotlin 协程修仙录 · 炼气境 · 初阶】 | 感受天地灵气,写出第一个挂起函数
android·kotlin
林栩link3 小时前
Android CLI 与 Skills:提升 AI Coding 效率
android
AI玫瑰助手4 小时前
Python基础:列表的定义、增删改查核心操作
android·开发语言·python
AirDroid_cn4 小时前
安卓15分享Wi-Fi二维码能换颜色吗?自定义颜色方法
android