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-> lockgralloc_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 );