Outline
Building Blocks
Under the Hood
Get Dirty
Q&A
Introduction to Android Window System
Chia-I Wu
[email protected]
May 15, 2009
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q&A
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q&A
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q&A
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
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
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
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
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
WindowManager
I frameworks/base/services/java/
com/android/server/WindowManagerService.java
I About 9000 SLOC in one file. Poorly documented, bad
namings, ...
I (Ask SurfaceManager to) create/layout surfaces on behalf of
the clients
I Dispatch input events to clients
I Transition animation
I WindowManagerPolicy
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
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
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
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
Outline
Building Blocks
Overview
Under the Hood
Interested Components
Get Dirty
Q&A
Special Keys
I HOME key
I BACK key
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Under the Hood Random Topics
Get Dirty
Q&A
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q&A
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Under the Hood Random Topics
Get Dirty
Q&A
Process View
I SurfaceManager, WindowManager, and SurfaceManager are
threads 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
Outline
Building Blocks
Under the Hood Random Topics
Get Dirty
Q&A
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
Outline
Building Blocks
Under the Hood Random Topics
Get Dirty
Q&A
Binder
I Early in the lifetime of an application process, thread(s) are
created and blocked on /dev/binder
I Binder is used mainly for RPC
I Fragile
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q&A
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
hierarchyviewer
I Display view hierarchy
I Display view
I Invalidate/Relayout
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Graphics: Memory Management
I SurfaceFlinger has a SurfaceHeapManager
I Every client has a MemoryDealer, as returned by
SurfaceHeapManager
I Every surface of a client also has dealer(s), from client or GPU
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Graphics: Memory Management cont.
Real flow
I A client asks for a new surface, createSurface
I createSurface calls createNormalSurfaceLocked
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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 and
one for back buffer
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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 and
one for back buffer
I Two LayerBitmaps are created, initialized with the two dealers
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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 and
one 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
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Hello World
I http://people.debian.org.tw/˜olv/surfaceflinger/demo.tar.gz
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
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
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Double Buffering
I Sofware v.s. Hardware
I Memory copy
I Page flipping
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Dirty Region
I Associate buffers with dirty regions
I Copy back
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Frame 0
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Frame 1
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Development
Under the Hood
Code
Get Dirty
Q&A
Frame 2
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q&A
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q&A
Chia-I Wu [email protected] Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q&A
Q&A
I Questions?
Chia-I Wu [email protected] Introduction to Android Window System