36

I would just like to ask if SurfaceFlinger is always called for any type of drawing into the screen? Example, displaying of JPG file to the screen.

3 Answers 3

38

SurfaceFlinger is not what draws your window. It allocates a frame buffer for your window, which the framework running in your application draws directly to without interacting with SurfaceFlinger. The only interaction SurfaceFlinger is involved with when you draw your window is to composite the final new frame buffer to the screen once you are done drawing a frame.

5
  • 1
    To hackbod and Frank, thanks for the info. I am really confused about the SurfaceFlinger. When I checked the android documentation for Android at developer.android.com/guide/topics/graphics/index.html, there are two ways to draw a 2D graphic to a screen. One is on a View and the other is on a SurfaceView. I have checked the source code for SurfaceView and it seems it is actually interacting with SurfaceFlinger. However, I can not see the connection yet for drawing in the Canvas using the View. (ex. ImageView) for it seems to be calling SKIA library.
    – artsylar
    Commented Apr 18, 2011 at 8:32
  • 1
    I am thinking that android graphics is getting the surface from WindowManager component. The surface is actually created by SurfaceFlinger and managed by WindowManager. Is my understanding correct?
    – artsylar
    Commented Apr 19, 2011 at 1:02
  • Well first, unless you are coding in the platform itself, you simply don't care about SurfaceFlinger so don't worry about it. The difference between a regular view and a SurfaceView really has nothing to do with SurfaceFlinger; a SurfaceView is essentially another way to create a window and this one is attached to the window of the SurfaceView's view hierarchy. Again, this is not of concern for you unless you are modifying the platform. I would really recommend you ask questions about what you are trying to do, not how things work, so people can give you useful answers.
    – hackbod
    Commented Apr 19, 2011 at 2:52
  • 6
    Thanks again for your reply. I am actually not yet developing an android application right now but I will be in the near future. I am just trying to understand how things work in android. Since I am not just studying the application framework but I am also interested in the Library layer.
    – artsylar
    Commented Apr 19, 2011 at 4:32
  • Sometimes it releases and recreate again. Hence there are duplicated same Activity at the same app. Commented Jul 15, 2019 at 13:43
22

http://pierrchen.blogspot.jp/2014/02/what-is-surfaceflinger-in-android.html

SurfaceFlinger is an Android system service, responsible for compositing all the application and system surfaces into a single buffer that is finally to be displayed by display controller.

Let's zoom in above statement.

SurfaceFlinger is a system wide service but it is not directly available to application developer as Sensor or other services can be. Every time you want to update your UI, SurfaceFlinger will kick in. This explains why SurfaceFlinger is a battery drainer.

Besides your application surfaces, there are system surfaces, including status bar, navigation bar and, when rotation happens, surfaces created by the system for rotation animation. Most applications have only one active surface - the one of current foreground activity, others have more than one when SurfaceView is used in the view hierarchy or Presentation mode is used.

SurfaceFlinger is responsible for COMPOSITING all those surfaces. A common misunderstanding is that SurfaceFinger is for DRAWING. It is not correct. Drawing is the job of OpenGL. The interesting thing is SurfaceFlinger used openGL for compositing as well.

The composition result will be put in a system buffer, or native window, which is the source for display controller to fetch data from. This is what you see in the screen.

17

Yes, SurfaceFlinger is Android's compositor so it takes everything that will get displayed, figures out what the resulting frame will look like and then sends it off to be displayed on the screen via the graphics card's EGL interface.

You can get the idea that it controls the result of everything you see in a post by Android developer Jeff Sharkey where he tints the whole screen for nightmode. I also found a beamer presentation that looks good about this topic.

Not the answer you're looking for? Browse other questions tagged or ask your own question.