Introduction to Android Window System

baroohspottyMobile - Wireless

Jul 19, 2012 (5 years and 1 month ago)

1,087 views

Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Introduction to Android Window System
Chia-I Wu
olv@0xlab.org
May 15,2009
Chia-I Wu olv@0xlab.org
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q & A
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
System Architecture
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
System Architecture
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
System Architecture
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
Building Blocks
There are more,but we focus on
I
SurfaceManager
I
WindowManager
I
ActivityManager
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested 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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
WindowManager
I
frameworks/base/services/java/
com/android/server/WindowManagerService.java
I
About 9000 SLOC in one le.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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested 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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested 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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Overview
Interested Components
Special Keys
I
HOME key
I
BACK key
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Random Topics
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q & A
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Random Topics
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get 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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Random Topics
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Outline
Building Blocks
Overview
Interested Components
Under the Hood
Random Topics
Get Dirty
Development
Code
Q & A
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
adb
I
ADBHOST for transport over TCP/IP
I
kill-server
I
remount
I
pull/push
I
logcat
I
shell
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
hierarchyviewer
I
Display view hierarchy
I
Display view
I
Invalidate/Relayout
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Graphics:Memory Management cont.
Real ow
I
A client asks for a new surface,createSurface
I
createSurface calls createNormalSurfaceLocked
I
A layer is created and setBuers is called to allocate buers
I
Two dealers are created from client,one for front buer and
one for back buer
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Hello World
I
http://people.debian.org.tw/~olv/surface inger/demo.tar.gz
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Many Buers
I
Surface is double buered
I
EGLDisplaySurface is double buered
I
Same technique;Dierent code pathes,dierent purposes
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Double Buering
I
Sofware v.s.Hardware
I
Memory copy
I
Page ipping
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Dirty Region
I
Associate buers with dirty regions
I
Copy back
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Frame 0
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Frame 1
Chia-I Wu olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Development
Code
Frame 2
Chia-I Wu olv@0xlab.org
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 olv@0xlab.org
Introduction to Android Window System
Outline
Building Blocks
Under the Hood
Get Dirty
Q & A
Q & A
I
Questions?
Chia-I Wu olv@0xlab.org
Introduction to Android Window System