introduction to android window system
DESCRIPTION
olv talked about Android Window System: SurfaceFlinger, WindowManager, ActivityManager, Binder, ...TRANSCRIPT
![Page 1: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/1.jpg)
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
![Page 2: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/2.jpg)
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
![Page 3: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/3.jpg)
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
![Page 4: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/4.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
![Page 5: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/5.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
![Page 6: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/6.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
OverviewInterested Components
System Architecture
Chia-I Wu [email protected] Introduction to Android Window System
![Page 7: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/7.jpg)
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
![Page 8: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/8.jpg)
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
![Page 9: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/9.jpg)
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
![Page 10: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/11.jpg)
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
![Page 12: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/12.jpg)
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
![Page 13: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/14.jpg)
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
![Page 15: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/16.jpg)
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
![Page 17: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/17.jpg)
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
![Page 18: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/18.jpg)
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
![Page 19: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/19.jpg)
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
![Page 20: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/20.jpg)
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
![Page 21: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/23.jpg)
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
![Page 24: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/24.jpg)
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
![Page 25: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/25.jpg)
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
![Page 26: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/26.jpg)
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
![Page 27: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/27.jpg)
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
![Page 28: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/28.jpg)
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
![Page 29: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/29.jpg)
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
![Page 30: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/30.jpg)
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
![Page 31: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/31.jpg)
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
![Page 32: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/32.jpg)
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
![Page 33: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/33.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 0
Chia-I Wu [email protected] Introduction to Android Window System
![Page 34: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/34.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 1
Chia-I Wu [email protected] Introduction to Android Window System
![Page 35: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/35.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
DevelopmentCode
Frame 2
Chia-I Wu [email protected] Introduction to Android Window System
![Page 36: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/36.jpg)
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
![Page 37: Introduction to Android Window System](https://reader034.vdocument.in/reader034/viewer/2022052307/555801f5d8b42a200d8b52b7/html5/thumbnails/37.jpg)
OutlineBuilding Blocks
Under the HoodGet Dirty
Q & A
Q & A
I Questions?
Chia-I Wu [email protected] Introduction to Android Window System