Android 中有多个窗口,每个窗口都是一个 Renderer,每个窗口渲染后把 buffer 传递给 Composer。由 Composer 来合成每个窗口的 buffer,最后发送给显示器显示。
Graphic data flow through Android
Renderer 和 Composer 通过 BufferQueue 交互,它是一个生产者消费者模式,Renderer 是生产者,Composer 是消费者。
BufferQueue communication process
该文档介绍 BufferQueue 如何管理 Buffer。
commit 289ade165e60b5f71734d30e535f16eb1f4313ad
Author: Dan Stoza <[email protected]>
Date: Fri Feb 28 11:17:17 2014 -0800
Split BufferQueue into core + producer + consumer
Change-Id: Idc39f1e511d68ce4f02202d35425a419bc0bcd92
include/gui/BufferItem.h | 103 +++++++++++++++++
include/gui/BufferQueueConsumer.h | 148 ++++++++++++++++++++++++
include/gui/BufferQueueCore.h | 120 ++++++++++++++++++++
include/gui/BufferQueueProducer.h | 165 +++++++++++++++++++++++++++
include/gui/BufferSlot.h | 136 ++++++++++++++++++++++
libs/gui/Android.mk | 5 +
libs/gui/BufferItem.cpp | 190 +++++++++++++++++++++++++++++++
libs/gui/BufferQueueConsumer.cpp | 398 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/gui/BufferQueueCore.cpp | 209 ++++++++++++++++++++++++++++++++++
libs/gui/BufferQueueProducer.cpp | 705 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
libs/gui/BufferSlot.cpp | 15 +++
11 files changed, 2194 insertions(+)
2014 年,Google 把 BufferQueue 拆分成了 BufferQueueCore、BufferQueueProducer 和 BufferQueueConsumer。
BufferQueueCore 管理 BufferSlot,它有一个成员 BufferQueueDefs::SlotsType
,它是 BufferSlot 数组,BufferSlot 有成员 sp<GraphicBuffer>
。BufferQueueProducer 和 BufferQueueConsumer 中有 BufferQueueDefs::SlotsType
引用,通过引用可以访问 BufferSlot。
typedef BufferSlot SlotsType[NUM_BUFFER_SLOTS];
BufferQueueDefs::SlotsType mSlots;
struct BufferSlot {
sp<GraphicBuffer> mGraphicBuffer;
BufferState mBufferState;
}
BufferSlot,顾名思义是 buffer 插槽,它有成员 BufferState 和 sp<GraphicBuffer>
。生产者和消费者获取 BufferSlot 并改变其状态。