2
Most read
4
Most read
12
Most read
Android Graphics
Architecture Overview
2015.08.20
Project meeting: Android Graphics Architecture Overview
Android graphics stack overview
● App acquires its own Surface(s) from SurfaceFlinger
○ comes with a Canvas and a graphics buffer
● App uses Canvas to draw the screen
○ underlying implementations may use OpenGL or
software render engine (e.g. SKIA)
● SurfaceFlinger composes final screen from Surfaces
○ get Activity status from ActivityManager
○ get z-order information from WindowManager
● Gralloc maps to the framebuffer device (fb0)
Android View component
● Button, TextView… are all Views
● A page layout is composed of a tree of Views
● Actual drawing behavior implemented in onDraw()
method of each View
○ Display List: a set of graphic commands
○ commands can be mapped to OpenGL commands
● Create DeferredDisplayList in order to optimize the
rendering order
○ analyze the overlapping… relationships
○ minimize GPU usage
Android View component
● An example of Display List (button)
○ Save 3
○ DrawPatch
○ Save 3
○ ClipRect 20.00, 4.00, 99.00, 44.00, 1
○ Translate 20.00, 12.00
○ DrawText 9, 18, 9, 0.00, 19.00, 0x17e898
○ Restore
○ RestoreToCount 0
● Can be mapped to gl-prefix OpenGL commands
2D rendering path
● Can be rendered by HW or SW
○ HWUI: hardware accelerated
using OpenGL ES 2.0
○ Skia: software render engine
3D rendering path
● App can instead create
GLSurfaceView
● Use OpenGL ES bindings for
Java
● Either use vendor GPU driver or
software-based PixelFlinger to
render the drawing to Surface
SurfaceFlinger
Compose, but not render!
SurfaceFlinger
● Services connections from activities (client) via Binder
interface ISurfaceComposer (server)
● Activity acquires Surface from SurfaceFlinger
○ created by ISurfaceComposer
● Receives activity status from ActivityManager
● Receives window status (visibility, z-order) from
WindowManager
● Composes multiple Surfaces into a single image
○ by HWComposer: also generates VSYNC
SurfaceFlinger
● GraphicBuffer
○ allocated by Gralloc, accessed using mmap
○ pixel format: RGB/RGBA/RGBO
● Project Butter
○ VSYNC
○ Triple Buffer
○ Choreographer
○ http://www.androidpolice.com/2012/07/12/getting-to-know-andr
oid-4-1-part-3-project-butter-how-it-works-and-what-it-added/
VSYNC Signal
● Generated by HWComposer
○ HW source: register callback of HAL
○ or SW source: VSyncThread
● Distributed by SurfaceFlinger
○ Client can create an event connection to SurfaceFlinger’s
MessageQueue to receive the VSync event
○ SurfaceFlinger inherits HWComposer::EventHandler to handle
onVSyncRecieved() and notify listeners
Application
● Each page has its View Tree
● Need to traverse the tree when
○ App or page being launched
○ External event: touch, key press
○ Internal event: UI control change, View.Visibility
● How to traverse
○ Post a request to Choreographer (if no request left)
○ Choreograpger calls perfromTraversals() when VSYNC signal
triggered
Application
● Inside performTraversals()
○ performMeasure(): calculate size of UI controls
○ performLayout(): calculate UI layout
○ performDraw()
● Inside performDraw()
○ High level: draw to Canvas (based on Surface in Java level)
○ Low level
■ Lock Surface (native level) to dequeue a buffer from
BufferQueue
■ Render to buffer by OpenGL ES or SKIA
■ Unlock Surface to enqueue the buffer
Surface (native level)
● Each app/page can acquire one or more Surface/Layer
● Done by using ISurfaceComposerClient to connect to
SurfaceFlinger’s Binder service
● ISurfaceComposerClient will return a SurfaceControl, then use it to
create Surface
● One of two native windows in Android graphic systems (another
one is for SurfaceFlinger)
● OpenGL ES render to the buffer and enqueue to BufferQueue of
Surface, act as a “producer”
BufferQueue
● A producer/consumer pattern
○ Producer: Application (Surface)
○ Consumer: SurfaceFlinger
● Buffer operation
○ Application: dequeue()->write buffer->enqueue()
○ SurfaceFlinger: acquire()->read buffer->release()
● When a buffer being queued
○ Layer listens to onFrameAvailable() callback
○ Call Layer’s onFrameQueued() to increment counter variable:
mQueuedFrames
BufferQueue
read buffer write buffer
ApplicationSurfaceflinger
SurfaceFlinger
● When VSYNC signal triggered
○ handleMessageTransaction(): detect Layers’ changes
(including size, z-order, alpha, add/removal…), save as
mDrawingState
○ handleMessageInvalidate(): acquire a buffer from BufferQueue
if available
○ signalRefresh() ---> call handleMessageRefresh()
SurfaceFlinger
● handleMessageRefresh()
○ preComposition(): check if there is any layer with available
buffers (mQueuedFrames > 0), signal invalidate if true
○ rebuildLayerStacks(): by calculating opaque region, visible
region, covered region and transparent region
○ ……
○ doComposition(): done by HWComposer or OpenGL ES
○ Swap buffers (front/back buffer)

More Related Content

PPTX
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
PDF
The Android graphics path, in depth
PDF
Design and Concepts of Android Graphics
PDF
Introduction to Android Window System
PPT
Learning AOSP - Android Linux Device Driver
PPT
Learning AOSP - Android Booting Process
PDF
Android Boot Time Optimization
PDF
Explore Android Internals
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
The Android graphics path, in depth
Design and Concepts of Android Graphics
Introduction to Android Window System
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Booting Process
Android Boot Time Optimization
Explore Android Internals

What's hot (20)

PDF
Android internals 07 - Android graphics (rev_1.1)
PDF
Android Binder IPC for Linux
PDF
Understanding the Android System Server
PDF
Android Internals
PDF
Low Level View of Android System Architecture
PDF
Booting Android: bootloaders, fastboot and boot images
PDF
Android Internals
PPTX
Overview of Android binder IPC implementation
PPTX
Android Binder: Deep Dive
PDF
BKK16-315 Graphics Stack Update
PDF
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
PDF
Android for Embedded Linux Developers
PDF
Android's Multimedia Framework
PDF
Android's HIDL: Treble in the HAL
PPTX
Android Booting Sequence
PPT
Android booting sequece and setup and debugging
PPTX
Android internals By Rajesh Khetan
PDF
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
PDF
Android media framework overview
PPTX
Binder: Android IPC
Android internals 07 - Android graphics (rev_1.1)
Android Binder IPC for Linux
Understanding the Android System Server
Android Internals
Low Level View of Android System Architecture
Booting Android: bootloaders, fastboot and boot images
Android Internals
Overview of Android binder IPC implementation
Android Binder: Deep Dive
BKK16-315 Graphics Stack Update
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Android for Embedded Linux Developers
Android's Multimedia Framework
Android's HIDL: Treble in the HAL
Android Booting Sequence
Android booting sequece and setup and debugging
Android internals By Rajesh Khetan
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Android media framework overview
Binder: Android IPC
Ad

Similar to Project meeting: Android Graphics Architecture Overview (20)

PPT
Why your Android Apps Suck
PDF
Framing the canvas - DroidCon Paris 2014
PDF
Graphicsand animations devoxx2010 (1)
PDF
[1D6]RE-view of Android L developer PRE-view
PDF
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
PPTX
GFX Part 7 - Introduction to Rendering Targets in OpenGL ES
PPTX
Advanced #4 GPU & Animations
PDF
Developing games for Series 40 full-touch UI
PPT
Advanced Game Development with the Mobile 3D Graphics API
PPTX
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
PDF
iOS Visual F/X Using GLSL
PDF
Inside Android's UI / ABS 2013
PDF
[GEG1] 10.camera-centric engine design for multithreaded rendering
PPTX
Penn graphics
PDF
Guides To Analyzing WebKit Performance
PPT
Open gles
DOCX
Android canvas-chapter20
PDF
Android High performance in GPU using opengles and renderscript
PPTX
Optimizing Games for Mobiles
PDF
GDSC KIIT Huddle Session 4 - "Graphics Pipelining"
Why your Android Apps Suck
Framing the canvas - DroidCon Paris 2014
Graphicsand animations devoxx2010 (1)
[1D6]RE-view of Android L developer PRE-view
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
GFX Part 7 - Introduction to Rendering Targets in OpenGL ES
Advanced #4 GPU & Animations
Developing games for Series 40 full-touch UI
Advanced Game Development with the Mobile 3D Graphics API
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
iOS Visual F/X Using GLSL
Inside Android's UI / ABS 2013
[GEG1] 10.camera-centric engine design for multithreaded rendering
Penn graphics
Guides To Analyzing WebKit Performance
Open gles
Android canvas-chapter20
Android High performance in GPU using opengles and renderscript
Optimizing Games for Mobiles
GDSC KIIT Huddle Session 4 - "Graphics Pipelining"
Ad

More from Yu-Hsin Hung (7)

PDF
IoT/M2M Security
PDF
Project meeting: SVMP - Secure Virtual Mobile Platform
PDF
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
PDF
Group meeting: TaintPipe - Pipelined Symbolic Taint Analysis
PDF
Group meeting: Polaris - Faster Page Loads Using Fine-grained Dependency Trac...
PDF
Group meeting: Identifying Information Disclosure in Web Applications with Re...
PDF
DockerVC Hackathon Presentation
IoT/M2M Security
Project meeting: SVMP - Secure Virtual Mobile Platform
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: TaintPipe - Pipelined Symbolic Taint Analysis
Group meeting: Polaris - Faster Page Loads Using Fine-grained Dependency Trac...
Group meeting: Identifying Information Disclosure in Web Applications with Re...
DockerVC Hackathon Presentation

Recently uploaded (20)

PDF
Cloud Native Aachen Meetup - Aug 21, 2025
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PPT
3.Software Design for software engineering
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PDF
Workplace Software and Skills - OpenStax
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PDF
infoteam HELLAS company profile 2025 presentation
PDF
What Makes a Great Data Visualization Consulting Service.pdf
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PDF
Crypto Loss And Recovery Guide By Expert Recovery Agency.
PPTX
Why 2025 Is the Best Year to Hire Software Developers in India
PPTX
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
PDF
MiniTool Power Data Recovery 12.6 Crack + Portable (Latest Version 2025)
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PDF
Bright VPN Crack Free Download (Latest 2025)
PPTX
Chapter_05_System Modeling for software engineering
PPTX
Lesson-3-Operation-System-Support.pptx-I
Cloud Native Aachen Meetup - Aug 21, 2025
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
3.Software Design for software engineering
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Workplace Software and Skills - OpenStax
Folder Lock 10.1.9 Crack With Serial Key
infoteam HELLAS company profile 2025 presentation
What Makes a Great Data Visualization Consulting Service.pdf
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
Top 10 Project Management Software for Small Teams in 2025.pdf
Crypto Loss And Recovery Guide By Expert Recovery Agency.
Why 2025 Is the Best Year to Hire Software Developers in India
Swiggy API Scraping A Comprehensive Guide on Data Sets and Applications.pptx
MiniTool Power Data Recovery 12.6 Crack + Portable (Latest Version 2025)
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Bright VPN Crack Free Download (Latest 2025)
Chapter_05_System Modeling for software engineering
Lesson-3-Operation-System-Support.pptx-I

Project meeting: Android Graphics Architecture Overview

  • 3. Android graphics stack overview ● App acquires its own Surface(s) from SurfaceFlinger ○ comes with a Canvas and a graphics buffer ● App uses Canvas to draw the screen ○ underlying implementations may use OpenGL or software render engine (e.g. SKIA) ● SurfaceFlinger composes final screen from Surfaces ○ get Activity status from ActivityManager ○ get z-order information from WindowManager ● Gralloc maps to the framebuffer device (fb0)
  • 4. Android View component ● Button, TextView… are all Views ● A page layout is composed of a tree of Views ● Actual drawing behavior implemented in onDraw() method of each View ○ Display List: a set of graphic commands ○ commands can be mapped to OpenGL commands ● Create DeferredDisplayList in order to optimize the rendering order ○ analyze the overlapping… relationships ○ minimize GPU usage
  • 5. Android View component ● An example of Display List (button) ○ Save 3 ○ DrawPatch ○ Save 3 ○ ClipRect 20.00, 4.00, 99.00, 44.00, 1 ○ Translate 20.00, 12.00 ○ DrawText 9, 18, 9, 0.00, 19.00, 0x17e898 ○ Restore ○ RestoreToCount 0 ● Can be mapped to gl-prefix OpenGL commands
  • 6. 2D rendering path ● Can be rendered by HW or SW ○ HWUI: hardware accelerated using OpenGL ES 2.0 ○ Skia: software render engine
  • 7. 3D rendering path ● App can instead create GLSurfaceView ● Use OpenGL ES bindings for Java ● Either use vendor GPU driver or software-based PixelFlinger to render the drawing to Surface
  • 9. SurfaceFlinger ● Services connections from activities (client) via Binder interface ISurfaceComposer (server) ● Activity acquires Surface from SurfaceFlinger ○ created by ISurfaceComposer ● Receives activity status from ActivityManager ● Receives window status (visibility, z-order) from WindowManager ● Composes multiple Surfaces into a single image ○ by HWComposer: also generates VSYNC
  • 10. SurfaceFlinger ● GraphicBuffer ○ allocated by Gralloc, accessed using mmap ○ pixel format: RGB/RGBA/RGBO ● Project Butter ○ VSYNC ○ Triple Buffer ○ Choreographer ○ http://www.androidpolice.com/2012/07/12/getting-to-know-andr oid-4-1-part-3-project-butter-how-it-works-and-what-it-added/
  • 11. VSYNC Signal ● Generated by HWComposer ○ HW source: register callback of HAL ○ or SW source: VSyncThread ● Distributed by SurfaceFlinger ○ Client can create an event connection to SurfaceFlinger’s MessageQueue to receive the VSync event ○ SurfaceFlinger inherits HWComposer::EventHandler to handle onVSyncRecieved() and notify listeners
  • 12. Application ● Each page has its View Tree ● Need to traverse the tree when ○ App or page being launched ○ External event: touch, key press ○ Internal event: UI control change, View.Visibility ● How to traverse ○ Post a request to Choreographer (if no request left) ○ Choreograpger calls perfromTraversals() when VSYNC signal triggered
  • 13. Application ● Inside performTraversals() ○ performMeasure(): calculate size of UI controls ○ performLayout(): calculate UI layout ○ performDraw() ● Inside performDraw() ○ High level: draw to Canvas (based on Surface in Java level) ○ Low level ■ Lock Surface (native level) to dequeue a buffer from BufferQueue ■ Render to buffer by OpenGL ES or SKIA ■ Unlock Surface to enqueue the buffer
  • 14. Surface (native level) ● Each app/page can acquire one or more Surface/Layer ● Done by using ISurfaceComposerClient to connect to SurfaceFlinger’s Binder service ● ISurfaceComposerClient will return a SurfaceControl, then use it to create Surface ● One of two native windows in Android graphic systems (another one is for SurfaceFlinger) ● OpenGL ES render to the buffer and enqueue to BufferQueue of Surface, act as a “producer”
  • 15. BufferQueue ● A producer/consumer pattern ○ Producer: Application (Surface) ○ Consumer: SurfaceFlinger ● Buffer operation ○ Application: dequeue()->write buffer->enqueue() ○ SurfaceFlinger: acquire()->read buffer->release() ● When a buffer being queued ○ Layer listens to onFrameAvailable() callback ○ Call Layer’s onFrameQueued() to increment counter variable: mQueuedFrames
  • 16. BufferQueue read buffer write buffer ApplicationSurfaceflinger
  • 17. SurfaceFlinger ● When VSYNC signal triggered ○ handleMessageTransaction(): detect Layers’ changes (including size, z-order, alpha, add/removal…), save as mDrawingState ○ handleMessageInvalidate(): acquire a buffer from BufferQueue if available ○ signalRefresh() ---> call handleMessageRefresh()
  • 18. SurfaceFlinger ● handleMessageRefresh() ○ preComposition(): check if there is any layer with available buffers (mQueuedFrames > 0), signal invalidate if true ○ rebuildLayerStacks(): by calculating opaque region, visible region, covered region and transparent region ○ …… ○ doComposition(): done by HWComposer or OpenGL ES ○ Swap buffers (front/back buffer)