从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);
}
相关推荐
程序员码歌7 小时前
短思考第263天,每天复盘10分钟,胜过盲目努力一整年
android·前端·后端
安卓兼职framework应用工程师7 小时前
Android 10.0 按键智能机按键连续响两次的异常处理
android·audio·audioservice·按键音·按键声音
studyForMokey7 小时前
【Android 项目】个人学习demo随笔
android
吃喝不愁霸王餐APP开发者7 小时前
利用责任链模式解耦多平台(美团/饿了么)霸王餐接口的适配逻辑
android·责任链模式
百***78757 小时前
Step-Audio-2 轻量化接入全流程详解
android·java·gpt·php·llama
yangpipi-10 小时前
《C++并发编程实战》第5章 C++内存模型和原子操作
android·java·c++
云水木石12 小时前
Android 的下一个战场:Windows 应用与游戏?
android·windows·游戏
雨声不在12 小时前
Android文字渐变的实现
android·textview
GoldenPlayer12 小时前
KTS语法
android
GoldenPlayer12 小时前
后台服务Service销毁逻辑+单例造成的内存泄露
android