Upload
jim-huang
View
5.835
Download
2
Tags:
Embed Size (px)
DESCRIPTION
olv talked about Android Window System: SurfaceFlinger, WindowManager, ActivityManager, Binder, ...
Citation preview
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Introduction to Android Window System
Chia-I [email protected]
May 15, 2009
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Building BlocksOverviewInterested Components
Under the HoodRandom Topics
Get DirtyDevelopmentCode
Q & A
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
Outline
Building BlocksOverviewInterested Components
Under the HoodRandom Topics
Get DirtyDevelopmentCode
Q & A
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
Building Blocks
There are more, but we focus on
I SurfaceManager
I WindowManager
I ActivityManager
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
SurfaceManager
I frameworks/base/libs/surfaceflinger/
I a.k.a SurfaceFlinger
I Allocate surfaces. Backed by ashmem/pmem/?
I Composite surfaces
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
WindowManager
I frameworks/base/services/java/com/android/server/WindowManagerService.java
I About 9000 SLOC in one file. Poorly documented, badnamings, ...
I (Ask SurfaceManager to) create/layout surfaces on behalf ofthe clients
I Dispatch input events to clients
I Transition animation
I WindowManagerPolicy
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
ActivityManager
I frameworks/base/services/java/com/android/server/am/
I Manage lifecycles of activities
I Manage stacking of activities
I Dispatch intents
I Spawn processes
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
Confusions
I An activity has one or more windows (e.g. dialogs)
I A window has one or more surfaces (e.g. surface views)
I However, in window manager, a window is called a session
I A surface is called a window
I And an activity becomes roughly a token
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
Special Keys
I HOME key
I BACK key
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Random Topics
Outline
Building BlocksOverviewInterested Components
Under the HoodRandom Topics
Get DirtyDevelopmentCode
Q & A
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Random Topics
Process View
I SurfaceManager, WindowManager, and SurfaceManager arethreads of a single process (system server)
I Every application is usually a process of itself
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Random Topics
Zygote
I Is a process started on system initialization
I Preloads java classes and resources
I Forks system server
I Listens silently on /dev/socket/zygote
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Random Topics
Binder
I Early in the lifetime of an application process, thread(s) arecreated and blocked on /dev/binder
I Binder is used mainly for RPC
I Fragile
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Outline
Building BlocksOverviewInterested Components
Under the HoodRandom Topics
Get DirtyDevelopmentCode
Q & A
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Build System
I build/core/core/build-system.html
I . build/envsetup.sh
I showcommands
I export ANDROID JAVA HOME if non-standard
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
adb
I ADBHOST for transport over TCP/IP
I kill-server
I remount
I pull/push
I logcat
I shell
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
hierarchyviewer
I Display view hierarchy
I Display view
I Invalidate/Relayout
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management
I SurfaceFlinger has a SurfaceHeapManager
I Every client has a MemoryDealer, as returned bySurfaceHeapManager
I Every surface of a client also has dealer(s), from client or GPU
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
I A dealer consists of a heap and an allocator
I A heap represents a sharable big chunk of memory
I An allocator is an algorithm
I Small chunks of memory from the heap are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
I A layer is created and setBuffers is called to allocate buffers
I Two dealers are created from client, one for front buffer andone for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
I Heaps of dealers along with info about the layer are returned
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Hello World
I http://people.debian.org.tw/˜olv/surfaceflinger/demo.tar.gz
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Many Buffers
I Surface is double buffered
I EGLDisplaySurface is double buffered
I Same technique; Different code pathes, different purposes
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Double Buffering
I Sofware v.s. Hardware
I Memory copy
I Page flipping
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Dirty Region
I Associate buffers with dirty regions
I Copy back
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 0
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 1
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 2
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Outline
Building BlocksOverviewInterested Components
Under the HoodRandom Topics
Get DirtyDevelopmentCode
Q & A
Chia-I Wu [email protected] Introduction to Android Window System
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Q & A
I Questions?
Chia-I Wu [email protected] Introduction to Android Window System