从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);
}
相关推荐
方白羽15 分钟前
为什么 Android 非要用 Intent 传值?
android·ios·harmonyos
方白羽2 小时前
Android17 重写 MessageQueue,解决 Handler 隐性卡顿
android·app
蜡台3 小时前
Kotlin 零基础完整版实战教程|从语法入门到Android工程实战
android·开发语言·kotlin
律宏阔4 小时前
Android 车载 USB 开发笔记:USB Host、USB 串口、USB-CAN、HID 与系统 API
android
律宏阔4 小时前
Android 车载串口开发笔记:UART、RS232、RS485、串口配置与数据通信
android
YF02115 小时前
遥控器APP端自动重连方案
android
执明wa6 小时前
Android Studio 打包 APK
android·ide·android studio
waiting9711186 小时前
Ubuntu 26.04 + Android14安装与编译教程
android·linux·ubuntu
hunterandroid6 小时前
Android 测试全景:从单元测试到 UI 自动化的完整实践
android·前端
蜡台6 小时前
Kotlin 五大作用域函数详解|let/run/apply/also/with 选型指南+实战避坑
android·java·kotlin