[Change] Android technology - graphics system Xiangjie

This paper describes the underlying implementation of graphics system Android. Android underlying graphics system to achieve a very complex document less, to use popular graphic form, such as X window, Cairo, etc..

Android's graphics system, Client / Server architecture. Server (ie SurfaceFlinger) mainly written in c + + code. Client-side code is divided into two parts, the supply is provided by the use of Java to use the api, the other one is written in c + + by the underlying implementation. The following diagram outlines the android graphics system architecture and key components used to.

Android graphics system is an important concept and clues that surface. View and sub-categories (eg TextView, Button) to draw on the surface. Each surface to create a Canvas object (but often attribute change), used to manage view on the surface of the drawing operation, the picturesque dotted line. Each canvas object corresponds to a bitmap, store content on the painted surface.

Surface usually corresponds to each of the two buffer, a front buffer, a back buffer. Which, back buffer is the canvas drawing corresponding bitmap (of android_view_Surface.cpp:: lockCanvas). Therefore, the painting is always in the back buffer, the need to update, will be back buffer and front buffer exchange.

The window is tied to a Surface and the ViewRoot asks the Surface for a
Canvas that is then used by the Views to draw onto. After View draw its data to canvas, ViewRoot
will call surface.unlockCanvasAndPost (canvas) to schedule surfaceFlinger:: composeSurfaces () which do the actually display to display panel. SurfaceFlinger handles to transfers drawn data in canvas to surface front buffer or backbuffer

Except for SurfaceViews, different views within the same ViewRoot share the same surface.

Layer concept:

 Each surface and corresponds to a  layer, SurfaceFlinger Responsible for the various layer  front buffer Synthesis  (composite) Drawn to the screen  .
A Layer is something that can be composited by SurfaceFlinger (should have been called LayerFlinger). There are several types of Layers if you look in the code, in particular the regular ones (Layer.cpp) , they are backed by a Surface, and the LayerBuffer (very badly chosen name) which don't have a backing store, but receive one from their client. . Note that the GGLSurface type, should have been called GGLBuffer
Multiple layers are just composited to the final buffer in  their Z order.

There are several closely related concepts of objects and Surface:
1. Java Surface (frameworks / base / core / java / android / view / Surface.java). Application of the indirect object is called (by SurfaceView, ViewRoot, etc.), applications need to create a surface, (and also create a canvas), drawing graphics to the object and finally delivered to the screen.
2. C + + Surface (frameworks / base / libs / ui / Surface.cpp. The object is Java Surface by Jni call the function to achieve Java Surface
3. ISurface (and its derived classes BnSurface). This object is the interface between application and server. C + + Surface to create this ISurface (BnSurface) and send commands, such as updating the content to the screen surface. Server-side to accept the command and the implementation of the action.

How to create a surface of the critical path is as follows:
1. Frameworks / base / core / java / android / view / Surface.java - Surface:: Surface ()
2. Frameworks / base / core / jni / android_view_Surface.cpp - Surface_init (). In this function SurfaceComposerClient object is created.
3. Frameworks / base / libs / ui / SurfaceComposerClient.cpp - SurfaceComposerClient:: SurfaceComposerClient (). This function is very important here to establish a bridge between the client and the server. By function _get_surface_manager () was a point of IBinder server object (with ISurfaceComposer interface), followed by the IBinder can access Server functions across the process. Then call ISurfaceComposer:: createConnection () Creates and returns a ISurfaceFlingerClient of IBinder.
4. Frameworks / base / libs / ui / SurfaceComposerClient.cpp - SurfaceComposerClient:: createSurface (). This function, use the previous obtained ISurfaceFlingerClient the IBinder, call its createSurface interfaces.
5.frameworks/base/libs/surfaceflinger/SurfaceFlinger.cpp - BClient:: createSurface (). BClient derived from the ISurfaceFlingerClient.
6. Frameworks / base / libs / surfaceflinger / SurfaceFlinger.cpp - SurfaceFlinger:: createSurface (). This function creates a corresponding Surface Layer.

The critical path, 1,2,3,4 process running on the client, while the 5,6-operation with the server process. server as a service to provide access to the client.

And graphics related code are mainly located in the following directory:
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

1, the following directory part of the code:
1, frameworks / base / graphics / java / android / graphics
2, frameworks / base / core / java / android / view
3, frameworks / base / core / java / android / widget

android.graphics, android.view and android.widget features and other similar graphics library such as Qt / Gtk + similar to the provision of basic graphics were primitive (picturesque dotted line, set the graphics context, etc.), events, mechanisms, and the development of graphical user interface controls and so on. canvas for the development of 2D graphics, Surface behalf of a graphics system for rendering the surface. Can live in their draw 2D 3D graphics.

2. Frameworks / base / opengl /
This directory contains opengel of interfaces and software. In http://developer.android.com/guide/topics/graphics/opengl.html have details on how to use android.opengl develop 3d graphics.

3 .external / skia, Mr. Jserv Taiwan has a good introduction, interested readers can refer to his Bowen (http://blog.linux.org.tw/ ~ jserv/archives/002095.html). In short, skia and cairo functionally equivalent, the underlying graphics hardware package for the above graphics library to provide the most basic operation of graphics hardware primitives.

4. Frameworks / base / libs / ui and frameworks / base / libs / surfaceflinger
ISurface defined based Surface interface for graphics system client (application) and server-side (ie surfaceflinger) interactions.
BpSurface is ISurface derived classes, provide interfaces for the server call the client function;
BnSurface is ISurface another derived class, providing an interface for the client calls the server function. When the server received from the client (through BnSurace) call request, such as registerBuffers, postBuffer so, BnSurface:: onTransact be triggered.
Surface (LayerBaseClient private class) is BnSurface derived class.
SurfaceBuffer (SurfaceBuffer private class) is the Surface of the derived class.

ISurfaceComposer defined based interface for client and server side interaction.
BpSurfaceComposer is a derived class, providing an interface for the server call the client function;
BnSurfaceComposer is another derived class, providing an interface for the client calls the server function. Class SurfaceFlinger derived from the BnSurfaceComposer.

SurfaceComposerClient used directly for the client, call ISurface (BnSurface) and ISurfaceComposer (BnSurfaceComposer) and ISurfaceFlingerClient interface, and server interaction.

BClient derived from ISurfaceFlingerClient (BnSurfaceFlingerClient), call the server's createSurface, really create a surface. Each surface corresponds to a layer.

egl_native_window_t defines a local window class. This class provides all the description of the local window for egl (opengl graphics system with local interface) method of operation of all local windwo.
EGLNativeSurface is egl_native_window_t a derived class.
EGLDisplaySurface is EGLNativeSurface derived class. EGLDisplaySurface is a very important category in this class, the truly open framebuffer device (/ dev/graphics/fb0 or / dev/fb0), and the device in the form of packaged EGLDisplaySurface for server use. Function mapFrameBuffer open framebuffer, create two buffers (one is on screen front buffer and one back buffer, may be located offscreen framebuffer, may also be located in system memory). Function swapBuffers the back buffer copied to the front buffer of the content.

DisplayHardware class initialization of the egl system and for the local window object to create the corresponding EGLSurface EGLDisplaySurface object. surfaceflinger use DisplayHardware to deal with local window.

5, part of the code in the following directory
7, frameworks / base / core / jni / android / graphics
8, frameworks / base / core / jni / android / opengl
9, frameworks / base / core / jni / android / android_view_ *. cpp

The directory of the Java code level graphics components and native (c + +) interface between components, the java level function calls to switch to the corresponding local calls.

hardware / libhardware achieved HAL (Hardware Abstraction Layer) layer, copybit device is one of the module.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of [Change] Android technology - graphics system Xiangjie

  • Hibernate II Study Notes

    11. Many-to-many Of many that can be converted to two one-to-many <set name="students" table="teacher_student"> <key column="techer_id"/> <many-to-many column="student_id"/> </set> many-to-many data only from one end of the mainten

  • Software development sunflower Baodian [reprint]

    Master the ability to reuse code very familiar with the new API's fast. This is because, he once used a lot of the API, have a lot of reusable code. He knows what is available and what is deficient. He has been using Qt, also used by gtk +, also used

  • js page Jump implementation of a number of ways

    The first is: <script language="javascript" type="text/javascript"> window.location.href = "login.jsp? backurl =" + window.location.href; </ script> The second: <script language="javascript"> alert

  • Dynamic loading JS script four kinds of methods

    To achieve dynamic loading JS script has four kinds of methods: 1, direct document.write <script language="javascript"> document.write ( "<script src='test.js'> <\ / script>"); </ script> 2, dynamic scri

  • Hibernate primary key strategy-sequence

    Today, the use of hibernate in the company encountered a troublesome problem, the use of hibernate when the primary key generation strategy set sequence, but always reported in the implementation could not get next sequence value of the error, then o ...

  • Hibernate pessimistic locking mechanism for locking and optimistic locking

    hibernate lock mechanism 1. Pessimistic lock It refers to the modification of data by outsiders hold a conservative attitude. The assumption that at any time access to data, may also have another client to access the same data, in order to maintain t ...

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries