Surface&canvas
Canvas for the meaning of the canvas. Most of the graphics on the Android top are done by canvas instances, but canvas is more of an interface wrapper. Drawpaints, Drawpoints,drawrect,drawbitmap ...
1 The essential relationship between canvas and surface
For this section, we're not going to look at the Skia graphics engine itself, we need to know where our graphics are placed in the end, and how this canvas is connected to surface.
Canvas (Java) corresponds to 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 Action:
Graphicbuffer:lock
Getbuffermapper () .lock<-> Graphicbuffermapper:: Lock
Mallocmod->lock<->gralloc_module_t::lock
The graphics buffer address of surface (Mlockedbuffe) can be obtained by Surfacelock.
(1) Establish a bitmap device connected with the Skcanvas, which uses the graphics buffer address obtained above to make its own bitmap memory.
(2) The mapping target device for setting Skcanvas is the bitmap.
Through this process, the relationship between Surfacecontrol and canvas is established. 2 origin of View:ondraw
Instead of using OpenGL to draw, when Android changes the View property, creates a new view, or z-order changes, it needs to repaint the view on the system screen, where our view executes OnDraw (canvas).
Viewroot.java
Performtraversals (..)
...
Draw ()
Canvas = Surface.lockcanvas (dirty);
...
Mview.draw (canvas);
Draw (Cavas) @view. java
Background.draw (canvas);
OnDraw (Cavas)
Dispatchdraw (Cavas)
Ondrawscrolbars (Cavas)
Surface.unlockcanvasandpost (canvas);