Android – How does SurfaceFlinger work

androidwindow

I'm developing a very simple cross platform window class in C++ just so I have a surface to render to. I've gotten it working on Linux and Windows so far. After I get it working on OS-X I want to try to get it working on my android phone.

However, I need to know if all "windows" created with SurfaceFlinger are full screen or if they can take up only a section of the desktop like a window on Linux or Windows? I ask this because I know I can place widgets on my phone's desktop but I've never seen an app do anything like a popup or a frame that hovers over the desktop.

How does creating a "window" that is smaller than the resolution of the phone work? Does it just center the drawable surface and leave black borders? Also can an application have multiple "windows?"

Best Answer

The Surfaceflinger, as its name suggests, deals with surfaces, not windows. Each window actually holds one surface it can draw onto, but these are different types of classes. Whenever the ViewRootImpl (top view of a window) of a certain application's window is created or changed in some way, a call is made to the WindowManagerService's relayout function. Now, skipping some boring details, the WindowManagerService creates a surface. A surface can be of any size, and if you are using multiple displays, it can even be attached to a certain display (though this is not yet implemented). This brings us back to your question(s): - A surface (window if you like) can be of any size. The black borders that you mentioned actually come from the window that is placed below the current window (and is painted black). - Yes, an application can have multiple windows (a window, for example, can be a dialog).

As for widgets, I know how the Launcher (the desktop app) supports them and supports their drag and drop behaviours, but I never asked myself whether they were in fact new windows - so I can't really answer that.