Surfaceflinger object creation process
1 surfacesession Creation
When a client requests to create a surface, it first establishes a session with surfaceflinger, and then creates a connection on the session to return the bclient object through the concept. Windowmanagerservice checks whether a surfacesession is established before adding the first window. If no surfacesession is established, a new instance is created to represent a connection with surfaceflinger.
New surfacesession () @ windowaddedlocked () @ windowmanagerservice. java.
The surfacesession creation process is mostly completed in the C ++ native space, as shown in the surfacesession initialization function: Init () Local function. You can see from the initialization function below:
Init () <-> SurfaceSession_init@Android_view_Surface.cpp
New surfacecomposerclient
Surfacesession creates a surfacecomposerclient instance in the C ++ native space. The establishment of this instance implements the following communication basis with surfaceflinger:
(1) established a proxy server for the proxy surfaceflinger Service
(2) establish an isurfaceflingerclient connection, establish a corresponding client on surfaceflinger, and return the bclient to windowmanagerservice.
2 create a surface
In the windowstate class of windowmanagerservice, we know that a surface corresponds to each child of the main window. Win. createsurfacelocked () @ relayoutwindow
Surface. Java
Init () <--> surface_init (...., Session, PID, dpy, W, H, format) @ android_view_surface.cpp
Surfacecontrol surface (client-> createsurface
On the mclient connection: Create the isurface interface:
M_client-> greatesurface (...)@
Bclient: createsurface (mid...) @ surfaceflinger. cpp
Mflinger-> createsurface (clientid ....)
Createnormalsurfacelocked
* Createnormalsurfacelocked: Creates a layer to allocate the Display memory.
* Createpushbufferssurfacelocked: Creates a laybuffer without allocating the Display memory.
Surface & canvas
Canvas indicates the meaning of the canvas. The upper-layer plotting of Android is almost done through the canvas instance. In fact, canvas is more of an interface packaging. Drawpaints
, Drawpoints, drawrect, drawbitmap...
1 Essential Relationship Between canvas and Surface
For this section, we will not study the skia graphics engine itself. What we need to know is how the image we make is placed in that place and how the canvas is connected to the surface.
Canvas (Java) has a native canvas C ++ object in the C ++ native layer.
Lockcanvas () @ Java
Surface_lockCanvas@Android_view_Surface.cpp
Surfacecontrol-> New Surface (Control) @ surface. cpp
Surface: Lock operation:
Graphicbuffer: Lock
Getbuffermapper (). Lock <-> graphicbuffermapper: Lock
Mallocmod-> lock <-> gralloc_module_t: Lock
Surfacelock can be used to obtain the graphic buffer address corresponding to the surface (mlockedbuffe.
(1) create a bitmap device connected to skcanvas. The bitmap uses the image buffer address obtained above as its own bitmap memory.
(2) set the drawing target device of skcanvas to this bitmap.
Through this process, the connection between surfacecontrol and canvas is established.
2 view: ondraw Source
When OpenGL is not used for rendering, the view attribute of Android changes. When a new view or Z-order changes, you need to re-draw the view on the System screen, at this time, our view will execute ondraw (canvas). Where is the root cause?
Viewroot. Java
Extends mtraversals (..)
...
Draw ()
Canvas = surface. lockcanvas (dirty );
...
Mview. Draw (canvas );
Draw (CAVAS) @ view. Java
Background. Draw (canvas );
Ondraw (CAVAS)
Dispatchdraw (CAVAS)
Ondrawscrolbars (CAVAS)
Surface. unlockcanvasandpost (canvas );