The Android graphics system adopts the Client/Server architecture. SurfaceFlinger is mainly written by C ++ code. The Client code is divided into two parts. One part is the supplied and used APIs provided by Java, and the other part is the underlying implementation written by C ++.
An important concept and clue in the Android graphics system is surface. View and its subclass, such as TextView and Button, must be painted on the surface. Creates a Canvas object for each surface, but its attributes change frequently. This object is used to manage the drawing operations of a view on the surface, such as drawing points and draw lines. Each canvas object corresponds to a bitmap that stores the content drawn on the surface.
There are several objects closely related to the Surface concept:
1. Java Surface frameworks/base/core/java/android/view/Surface. java ). This object is indirectly called by the application through SurfaceView, ViewRoot, etc.), the application needs to create a surface, and create a canvas at the same time), draw the image to this object and finally deliver it to the screen.
2. C ++ Surface (frameworks/base/libs/ui/Surface. cpp. This object is called by Java Surface through Jni to implement the Java Surface function.
3. ISurface (and its derived class BnSurface ). This object is the interface between the application and the server. C ++ Surface creates this ISurface BnSurface) and sends commands, such as updating the surface content to the screen. The Server accepts the command and performs the corresponding operation.
The functions of android. graphics, android. view, and android. widget are similar to those of other similar graphics libraries such as Qt/Gtk +, which provide basic graphics primitives such as drawing points and setting the image context ). Event mechanism and controls for developing graphical user interfaces. Canvas is used to develop 2D images. Surface represents a surface that can be drawn by the graphic system. You can draw Android images on it.
Graphics-related code is mainly located in the following directories:
- 1、frameworks/base/graphics/java/android/graphics
- 2、frameworks/base/core/java/android/view
- 3、frameworks/base/core/java/android/widget
- 4、frameworks/base/opengl/
- 5、frameworks/base/libs/ui
- 6、frameworks/base/libs/surfaceflinger
- 7、frameworks/base/core/jni/android/graphics
- 8、frameworks/base/core/jni/android/opengl
- 9、frameworks/base/core/jni/android/android_view_*.cpp
- 10、external/skia