先定义一个宏:
- #ifndef container_of
- #define container_of(ptr, type, member) \
- (type *)((char*)(ptr) - offsetof(type, member))
- #endif
然后:
ANativeWindowBuffer *anwBuffer = container_of(buffer, ANativeWindowBuffer, handle);
其中buffer的类型是:
buffer_handle_t *buffer;
得到ANativeWindowBuffer以后:
- sp
GraphicBuffer::from(ANativeWindowBuffer* anwb) { - return static_cast
(anwb); - }