How do Window and Layer from SurfaceFlinger interact?

121 Views Asked by At

As far as I know Window has Surface and View Hierarchy. And every time an Activity, Toast or Dialog is created, the WindowManager creates a Window object and attaches it to itself. The WindowManager also creates a Surface object for this Window.

From the talk Drawn out: How Android renders (Google I/O '18) (https://www.youtube.com/watch?v=zdQRIYOST64) I learned that after creating a Window, it has a sibling Layer object on the SurfaceFlinger side. And composition uses exactly Layer objects.

As I understand it, Layer is a combination of Surface and SurfaceControl. It also creates and owns a BufferQueue.

But I can't understand the relationship between Window and Layer, because Window already has a Surface, then why is Layer needed? How do buffers from the Surface belonging to the Window end up in the BufferQueue, which is in the Layer? Why in the Layer at all Surface, if the rendering takes place on the Surface from the Window.

I've read the documentation about SurfaceFlinger, Layer, WindowManager and Window but still don't understand how Window and Layer are related.

I tried to look at the implementation of these components, but the code is too complicated for me.

0

There are 0 best solutions below