SlideShare a Scribd company logo
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

PDF
Design and Concepts of Android Graphics
PDF
The Android graphics path, in depth
PPTX
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
PDF
Introduction to Android Window System
PDF
Low Level View of Android System Architecture
PDF
BKK16-315 Graphics Stack Update
PDF
Android internals 07 - Android graphics (rev_1.1)
PDF
Embedded Android : System Development - Part I
Design and Concepts of Android Graphics
The Android graphics path, in depth
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Introduction to Android Window System
Low Level View of Android System Architecture
BKK16-315 Graphics Stack Update
Android internals 07 - Android graphics (rev_1.1)
Embedded Android : System Development - Part I

What's hot (20)

PDF
Understanding the Android System Server
PDF
Understaing Android EGL
PDF
Explore Android Internals
PDF
Android Binder IPC for Linux
PDF
Android Internals
PPTX
Binder: Android IPC
PPTX
Overview of Android binder IPC implementation
ODP
Embedded Android : System Development - Part III
PDF
Android's HIDL: Treble in the HAL
PPTX
Android Booting Sequence
ODP
Q4.11: Porting Android to new Platforms
PDF
Android Boot Time Optimization
PDF
Android IPC Mechanism
PDF
Hardware Accelerated 2D Rendering for Android
PDF
Embedded Android : System Development - Part II (HAL)
PPTX
Android Binder: Deep Dive
PDF
Android OS Porting: Introduction
PDF
Android's Multimedia Framework
PDF
Android Things : Building Embedded Devices
PPTX
Android AIDL Concept
Understanding the Android System Server
Understaing Android EGL
Explore Android Internals
Android Binder IPC for Linux
Android Internals
Binder: Android IPC
Overview of Android binder IPC implementation
Embedded Android : System Development - Part III
Android's HIDL: Treble in the HAL
Android Booting Sequence
Q4.11: Porting Android to new Platforms
Android Boot Time Optimization
Android IPC Mechanism
Hardware Accelerated 2D Rendering for Android
Embedded Android : System Development - Part II (HAL)
Android Binder: Deep Dive
Android OS Porting: Introduction
Android's Multimedia Framework
Android Things : Building Embedded Devices
Android AIDL Concept
Ad

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

PDF
State of the Art OpenGL and Qt
 
PDF
Webrender 1.0
PDF
Inside Android's UI
PDF
COMPUTER GRAPHICS PROJECT REPORT
PDF
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
PPTX
Sergey Gonchar - Fast rendering with Starling
PDF
Firefox OS Graphics inside
PDF
Inside Android's UI at AnDevCon VI
PDF
Inside Android's UI / ABS 2013
PDF
Inside Android's UI at AnDevCon V
PPTX
Lecture 6 introduction to open gl and glut
PDF
Drools & jBPM Workshop London 2013
PDF
Virtual Reality in Android
PPTX
AGDK tutorial step by step
PPTX
Azure functions: from a function to a whole application in 60 minutes
PDF
Korea linuxforum2014 html5game-sangseoklim
PPT
openGL basics for sample program (1).ppt
PPT
openGL basics for sample program.ppt
PDF
Towards shipping Ozone/Wayland (BlinkOn 10)
PPT
OpenGL ES based UI Development on TI Platforms
State of the Art OpenGL and Qt
 
Webrender 1.0
Inside Android's UI
COMPUTER GRAPHICS PROJECT REPORT
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
Sergey Gonchar - Fast rendering with Starling
Firefox OS Graphics inside
Inside Android's UI at AnDevCon VI
Inside Android's UI / ABS 2013
Inside Android's UI at AnDevCon V
Lecture 6 introduction to open gl and glut
Drools & jBPM Workshop London 2013
Virtual Reality in Android
AGDK tutorial step by step
Azure functions: from a function to a whole application in 60 minutes
Korea linuxforum2014 html5game-sangseoklim
openGL basics for sample program (1).ppt
openGL basics for sample program.ppt
Towards shipping Ozone/Wayland (BlinkOn 10)
OpenGL ES based UI Development on TI Platforms
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)

PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
history of c programming in notes for students .pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Nekopoi APK 2025 free lastest update
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Digital Strategies for Manufacturing Companies
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
System and Network Administraation Chapter 3
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
System and Network Administration Chapter 2
Design an Analysis of Algorithms II-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
history of c programming in notes for students .pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Navsoft: AI-Powered Business Solutions & Custom Software Development
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
ISO 45001 Occupational Health and Safety Management System
ManageIQ - Sprint 268 Review - Slide Deck
Nekopoi APK 2025 free lastest update
Odoo POS Development Services by CandidRoot Solutions
Digital Strategies for Manufacturing Companies
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
System and Network Administraation Chapter 3
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
2025 Textile ERP Trends: SAP, Odoo & Oracle
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

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)