SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
The Android graphics path
in depth
The Android graphics path 1 Copyright ©2011-2014, 2net Limited
License
These slides are available under a Creative Commons Attribution-ShareAlike 3.0
license. You can read the full text of the license here
http://creativecommons.org/licenses/by-sa/3.0/legalcode
You are free to
• copy, distribute, display, and perform the work
• make derivative works
• make commercial use of the work
Under the following conditions
• Attribution: you must give the original author credit
• Share Alike: if you alter, transform, or build upon this work, you may distribute
the resulting work only under a license identical to this one (i.e. include this
page exactly as it is)
• For any reuse or distribution, you must make clear to others the license terms of
this work
The orginals are at http://2net.co.uk/slides/android-graphics-abs-2014.pdf
The Android graphics path 2 Copyright ©2011-2014, 2net Limited
About Chris Simmonds
• Consultant and trainer
• Working with embedded Linux since 1999
• Android since 2009
• Speaker at many conferences and
workshops
"Looking after the Inner Penguin" blog at http://2net.co.uk/
https://uk.linkedin.com/in/chrisdsimmonds/
https://google.com/+chrissimmonds
The Android graphics path 3 Copyright ©2011-2014, 2net Limited
Overview
• The Android graphics stack changed a lot in Jelly
Bean as a result of project Butter
• This presentation describes the current (JB) graphics
stack from top to bottom
• Main topics covered
• The application layer
• SurfaceFlinger, interfaces and buffer queues
• The hardware modules HWComposer and Gralloc
• OpenGL ES and EGL
The Android graphics path 4 Copyright ©2011-2014, 2net Limited
The big picture
SurfaceFlinger
Activity
OpenGL vendor
libraries
OpenGL ES
GPU driver
HWComposer
ION
Gralloc alloc
FB driver
Gralloc FB
Android
framework
Vendor HAL
library
Kernel
driver
Activity
Activity
Manager
Window
Manager
BufferQueue
The Android graphics path 5 Copyright ©2011-2014, 2net Limited
Inception of a pixel
• Everything begins when an activity draws to a surface
• 2D applications can use
• drawing functions in Canvas to write to a Bitmap:
android.graphics.Canvas.drawRect(), drawText(), etc
• descendants of the View class to draw objects such
as buttons and lists
• a custom View class to implement your own
appearance and behaviour
• In all cases the drawing is rendered to a Surface
which contains a GraphicBuffer
The Android graphics path 6 Copyright ©2011-2014, 2net Limited
2D rendering path
Activity
Canvas
Surface
SkiaOpenGL ES
Vendor Open GL
GPU driver
Activity
HWUI
The Android graphics path 7 Copyright ©2011-2014, 2net Limited
Skia and hwui
• For 2D drawing there are two rendering paths
• hwui: (libwhui.so) hardware accelerated using
OpenGL ES 2.0
• skia: (libskia.so) software render engine
• hwui is the default
• Hardware rendering can be disabled per view,
window, activity, application or for the whole device
• Maybe for comparability reasons: hwui produces
results different to skia in some (rare) cases
The Android graphics path 8 Copyright ©2011-2014, 2net Limited
3D rendering path
• An activity can instead create a GLSurfaceView and
use OpenGL ES bindings for Java (the
android.opengl.* classes)
• Using either the vendor GPU driver (which must
support OpenGL ES 2.0 and optinally 3.0)
• Or as a fall-back, using PixelFlinger, a software GPU
that implements OpenGL ES 1.0 only
• Once again, the drawing is rendered to a Surface
The Android graphics path 9 Copyright ©2011-2014, 2net Limited
3D rendering path
Activity
Surface
OpenGL ES
Vendor Open GL
GPU driver
Activity
Android GL
PixelFlinger
The Android graphics path 10 Copyright ©2011-2014, 2net Limited
Composition
SurfaceFlinger
Wallpaper
Launcher
Navigation
bar
Status
bar
The Android graphics path 11 Copyright ©2011-2014, 2net Limited
SurfaceFlinger
frameworks/native/services/surfaceflinger
• A high-priority native (C++) daemon, started by init
with UID=system
• Services connections from activities via Binder
interface ISurfaceComposer
• Receives activity status from Activity Manager
• Receives window status (visibility, Z-order) from
Window Manager
• Composits multiple Surfaces into a single image
• Passes image to one or more displays
• Manages buffer allocation, synchronisation
The Android graphics path 12 Copyright ©2011-2014, 2net Limited
SurfaceFlinger binder interfaces
SurfaceFlinger
Client
ISurfaceComposer ISurfaceComposerClient IDisplayEventConnection
e.g. activity
createConnection()
createDisplayEventConnection()
createSurface()
destroySurface()
getDataChannel()
The Android graphics path 13 Copyright ©2011-2014, 2net Limited
ISurfaceComposer
• ISurfaceComposer
• Clients use this interface to set up a connection with
SurfaceFlinger
• Client begins by calling createConnection() which
spawns an ISurfaceComposerClient
• Client calls createGraphicBufferAlloc() to create an
instance of IGraphicBufferAlloc (discussed later)
• Client calls createDisplayEventConnection() to create
an instance of IDisplayEventConnection
• Other methods include captureScreen() and
setTransactionState()
The Android graphics path 14 Copyright ©2011-2014, 2net Limited
ISurfaceComposerClient
• ISurfaceComposerClient
• This interface has two methods:
• createSurface() asks SufraceFlinger to create a new
Surface
• destroySurface() destroys a Surface
The Android graphics path 15 Copyright ©2011-2014, 2net Limited
IDisplayEventConnection
• IDisplayEventConnection
• This interface passes vsync event information from
SurfaceFlinger to the client
• setVsyncRate() sets the vsync event delivery rate:
value of 1 returns all events, 0 returns none
• requestNextVsync() schedules the next vsync event:
has no effect if the vsync rate is non zero
• getDataChannel() returns a BitTube which can be
used to receive events
The Android graphics path 16 Copyright ©2011-2014, 2net Limited
BufferQueue
frameworks/native/include/gui/BufferQueue.h
• Mechanism for passing GraphicBuffers to
SurfaceFlinger
• Contains an array of between 2 and 32
GraphicBuffers
• Uses interface IGraphicBufferAlloc to allocate buffers
(see later)
• Provides two Binder interfaces
• IGraphicBufferProducer for the client (Activity)
• IGraphicBufferConsumer for the consumer
(SurfaceFlinger)
• Buffers cycle between producer and consumer
The Android graphics path 17 Copyright ©2011-2014, 2net Limited
BufferQueue state diagram
FREE
QUEUED
DEQUEUEDACQUIRED
IGraphicBufferProducer::
dequeueBuffer()
IGraphicBufferConsumer::
releaseBuffer()
IGraphicBufferProducer::
queueBuffer()
IGraphicBufferConsumer::
acquireBuffer()
IGraphicBufferProducer::
cancelBuffer()
The Android graphics path 18 Copyright ©2011-2014, 2net Limited
BufferQueue
• Default number of buffer slots since JB is 3
(previously 2)
• In JB you can compile Layer.cpp with
TARGET_DISABLE_TRIPLE_BUFFERING to return to 2 slots
• Call setBufferCount() to change the number of slots
• BufferQueue operates in two modes:
• Synchronous: client blocks until there is a free slot
• Asynchronous: queueBuffer() discards any existing
buffers in QUEUED state so the queue only holds the
most recent frame
The Android graphics path 19 Copyright ©2011-2014, 2net Limited
GraphicBuffer
frameworks/native/include/ui/GraphicBuffer.h
• Represents a buffer, wraps ANativeWindowBuffer
• Attributes including width, height, format, usage
inherited from ANativeWindowBuffer
The Android graphics path 20 Copyright ©2011-2014, 2net Limited
Composition
• On a vsync event, SurfaceFlinger calls
handleMessageRefresh() which goes through a
composition cycle:
• preComposition(): sort layers by Z order and call
onPreComposition() for each
• doComposition(): loop through displays: if there is a
dirty region, mark it to be drawn then call
postFameBuffer() to do the drawing
• postComposition(): loop through layers in Z order and
call onPostComposition()
The Android graphics path 21 Copyright ©2011-2014, 2net Limited
Layer
frameworks/native/services/surfaceflinger/Layer.h
• Each Layer has
• Z order
• Alpha value from 0 to 255
• visibleRegion
• crop region
• transformation: rotate 0, 90, 180, 270: flip H, V: scale
• SurfaceFlinger composits the layers using
• HWComposer, if it supports the operation
• Fall back to the GPU, via OpenGL ES (version 1.0
only, for historical reasons)
The Android graphics path 22 Copyright ©2011-2014, 2net Limited
HWComposer
hardware/libhardware/include/hardware/hwcomposer.h
• HWComposer is a vendor-supplied library, at run-time
in /system/lib/hw/hwcomposer.[product name].so
• Optional: in all cases there are fall-backs if HWC is
absent
• HWC does several different things
• sync framework (vsync callback)
• modesetting, display hotplug (e.g. hdmi)
• compositing layers together using features of the
display controller
• displaying frames on the screen
The Android graphics path 23 Copyright ©2011-2014, 2net Limited
prepare() and set()
• SurfaceFlinger calls HWComposer in two stages
• prepare()
• Passes a list of layers
• For each layer, HWComposer returns
• HWC_FRAMEBUFFER: SurfaceFlinger should write this
layer (using OpenGL)
• HWC_OVERLAY: will be composed by HWComposer
• set()
• Passes the list of layers for HWComposer to handle
• set() is used in place of eglSwapBuffers()
The Android graphics path 24 Copyright ©2011-2014, 2net Limited
vsync
• Since JB 4.1 SurfaceFlinger is synchronised to a
60Hz (16.7ms period) vsync event
• If HWComposer present, it is responsible for vsync
• Usually using an interrupt from the display: if no h/w
trigger, fake in software
• vsync() is a callback registered with HWComposer
• Each callback includes a display identifier and a
timestamp (in ns)
• If no HWComposer, SurfaceFlinger uses 16ms
timeout in s/w
The Android graphics path 25 Copyright ©2011-2014, 2net Limited
Displays
• HWComposer defines three display types
HWC_DISPLAY_PRIMARY e.g. built-in LCD screen
HWC_DISPLAY_EXTERNAL e.g. HDMI, WiDi
HWC_DISPLAY_VIRTUAL not a real display
• For each display there is an instance of
DisplayDevice in SurfaceFlinger
The Android graphics path 26 Copyright ©2011-2014, 2net Limited
IGraphicBufferAlloc and friends
frameworks/native/include/gui/IGraphicBufferAlloc.h
• Binder interface used by SurfaceFlinger to allocate
buffers
• Has one function createGraphicBuffer
• Implemented by class GraphicBufferAllocator, which
wraps the ANativeWindowBuffer class
• Uses Gralloc.alloc to the the actual allocation
• Underlying buffer is referenced by a buffer_handle_t
which is a file descriptor (returned by gralloc alloc)
• Binder can pass open file descriptors from process to
process
• Access buffer data using mmap
The Android graphics path 27 Copyright ©2011-2014, 2net Limited
Buffer usage and pixel format
frameworks/native/include/ui/GraphicBuffer.h
USAGE_HW_TEXTURE OpenGL ES texture
USAGE_HW_RENDER OpenGL ES render target
USAGE_HW_2D 2D hardware blitter
USAGE_HW_COMPOSER used by the HWComposer HAL
USAGE_HW_VIDEO_ENCODER HW video encoder
frameworks/native/include/ui/PixelFormat.h
PIXEL_FORMAT_RGBA_8888 4x8-bit RGBA
PIXEL_FORMAT_RGBX_8888 4x8-bit RGB0
PIXEL_FORMAT_RGB_888 3x8-bit RGB
PIXEL_FORMAT_RGB_565 16-bit RGB
PIXEL_FORMAT_BGRA_8888 4x8-bit BGRA
The Android graphics path 28 Copyright ©2011-2014, 2net Limited
Gralloc
hardware/libhardware/include/hardware/gralloc.h
• Gralloc is a vendor-supplied library, at run-time in
/system/lib/hw/gralloc.[product name].so
• Does two things
• gralloc alloc: allocates graphic buffers
• gralloc framebuffer: interface to Linux framebuffer
device, e.g. /dev/graphics/fb0
• gralloc alloc allocates all graphic buffers using a
kernel memory manager, typically ION
• Selects appropriate ION heap based on the buffer
usage flags
The Android graphics path 29 Copyright ©2011-2014, 2net Limited
OpenGL ES
• The Khronos OpenGL ES and EGL APIs are
implemented in these libraries
• /system/lib/libEGL.so
• /system/lib/libGLESv1_CM.so
• /system/lib/libGLESv2.so
• /system/lib/libGLESv3.so (optional from JB 4.3
onwards: actually a symlink to libGLESv2.so)
• In most cases they simply call down to the
vendor-supplied libraries in /system/lib/egl
The Android graphics path 30 Copyright ©2011-2014, 2net Limited
EGL
• EGL is the Khronos Native Platform Graphics
Interface
• Rendering operations are executed in an EGLContext
• In most cases the EGLContext is based on the
default display
• The mapping from the EGL generic display type is
done in
frameworks/native/opengl/include/EGL/eglplatform.h
typedef struct ANativeWindow* EGLNativeWindowType;
• EGLNativeWindowType is defined in
system/core/include/system/window.h
The Android graphics path 31 Copyright ©2011-2014, 2net Limited
OpenGL vendor implementation
• The vendor OpenGL libraries form the interface to the
GPU
• Responsible for
• creating display lists
• scheduling work for the GPU
• managing buffer synchronisation (typically using
fences, see background at the end)
• Usually there is a kernel driver which handles low
level memory management, DMA and interrupts
• The kernel interface is usually a group of ioctl
functions
The Android graphics path 32 Copyright ©2011-2014, 2net Limited
• Questions?
The Android graphics path 33 Copyright ©2011-2014, 2net Limited
Background: fences
The Android graphics path 34 Copyright ©2011-2014, 2net Limited
Buffer synchronisation
• There are many producers and consumers of
graphics buffers
• Pre JB sync was implicit: buffer not released until
operation complete
• Did not encourage parallel processing
• JB introduced explicit sync: each buffer has a sync
object called a fence
• Means a buffer can be passed to the next user before
operations complete
• The next user waits on the fence before accessing
the buffer contents
The Android graphics path 35 Copyright ©2011-2014, 2net Limited
Synchronisation using fences
• Represented by file handles: can be passed between
applications in binder messages
• Can also be passed from applications to drivers
• Each device driver (display, camera, video codec...)
has its own timeline
• A fence may have synchronisation points on multiple
timelines
• Allows buffers to be passed between multiple devices
The Android graphics path 36 Copyright ©2011-2014, 2net Limited
Timeline and sync point
• Timeline
• Per-device (display, GPU, camera, ...)
• Monotonically increasing 32-bit value
• Incremented after each event (essentially it is a count
of the jobs processed by the device)
• Sync point
• A point on a timeline
• Becomes signalled when the timeline passes it
The Android graphics path 37 Copyright ©2011-2014, 2net Limited
Fence
• Fence
• A collection of one or more sync points, possibly from
different timelines
• Represented by a file descriptor so an application can
wait using poll()
• Two fences can be merged to create a new fence that
depends on all the sync points of the original pair
The Android graphics path 38 Copyright ©2011-2014, 2net Limited
Fence: example
FB
timeline
GPU
timeline
Sync pt
Sync pt
Sync
Fence
The Android graphics path 39 Copyright ©2011-2014, 2net Limited
Background: ION
The Android graphics path 40 Copyright ©2011-2014, 2net Limited
Memory constraints
• Often necessary for a buffer to be accessed by
hardware
• Example: graphics buffer and display controller or
GPU
• Hardware may constrain memory access
• Example: hardware without IOMMU usually needs
physically contiguous memory
• To avoid copying, the memory must be allocated for
the most constrained device
The Android graphics path 41 Copyright ©2011-2014, 2net Limited
ION
• Previous memory allocators include pmem
(Qualcomm), cmem (TI), and nvmap (NVIDA)
• ION provides a unified interface for these needs
• Different allocation constraints
• Different caching requirements
• But the programmer still has to make the right choices
The Android graphics path 42 Copyright ©2011-2014, 2net Limited
Types of heap
• ION_HEAP_TYPE_SYSTEM
• memory allocated via vmalloc
• ION_HEAP_TYPE_SYSTEM_CONTIG
• memory allocated via kmalloc
• ION_HEAP_TYPE_CARVEOUT
• memory allocated from a pre reserved carveout heap
• allocations are physically contiguous
The Android graphics path 43 Copyright ©2011-2014, 2net Limited
Heap flags
• ION_FLAG_CACHED
• mappings of this buffer should be cached, ION will do
cache maintenance when the buffer is mapped for
DMA
• ION_FLAG_CACHED_NEEDS_SYNC
• Cache must be managed manually, e.g. using
ION_IOC_SYNC
The Android graphics path 44 Copyright ©2011-2014, 2net Limited

Más contenido relacionado

La actualidad más candente

Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UIOpersys inc.
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android Arvind Devaraj
 
Google I/O 2011, Android Accelerated Rendering
Google I/O 2011, Android Accelerated RenderingGoogle I/O 2011, Android Accelerated Rendering
Google I/O 2011, Android Accelerated RenderingRomain Guy
 
BKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateBKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateLinaro
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overviewJerrin George
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Opersys inc.
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Render thead of hwui
Render thead of hwuiRender thead of hwui
Render thead of hwuiRouyun Pan
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementationChethan Pchethan
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 

La actualidad más candente (20)

Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
Google I/O 2011, Android Accelerated Rendering
Google I/O 2011, Android Accelerated RenderingGoogle I/O 2011, Android Accelerated Rendering
Google I/O 2011, Android Accelerated Rendering
 
BKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack UpdateBKK16-315 Graphics Stack Update
BKK16-315 Graphics Stack Update
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Applied Computer Science Concepts in Android
Applied Computer Science Concepts in AndroidApplied Computer Science Concepts in Android
Applied Computer Science Concepts in Android
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Render thead of hwui
Render thead of hwuiRender thead of hwui
Render thead of hwui
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementation
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
 

Similar a The Android graphics path, in depth

Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...Igalia
 
WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms philn2
 
Web dev tools review
Web dev tools reviewWeb dev tools review
Web dev tools reviewChanghyun Lee
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Ryan Chou
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvmdfages
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UIOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoTOpersys inc.
 
20170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 201720170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 2017Takayoshi Tanaka
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Chris Simmonds
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Targeting Android with Qt
Targeting Android with QtTargeting Android with Qt
Targeting Android with QtEspen Riskedal
 
Android Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAndroid Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAdham Enaya
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'acorehard_by
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIOpersys inc.
 

Similar a The Android graphics path, in depth (20)

Gtug
GtugGtug
Gtug
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...
WebKit, HTML5 media and GStreamer on multiple platforms (GStreamer Conference...
 
WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms
 
Web dev tools review
Web dev tools reviewWeb dev tools review
Web dev tools review
 
Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008Introduction to Skia by Ryan Chou @20141008
Introduction to Skia by Ryan Chou @20141008
 
Droidcon uk2012 androvm
Droidcon uk2012 androvmDroidcon uk2012 androvm
Droidcon uk2012 androvm
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Customizing Android's UI
Customizing Android's UICustomizing Android's UI
Customizing Android's UI
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoT
 
20170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 201720170321 docker with Visual Studio 2017
20170321 docker with Visual Studio 2017
 
Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019Android rpi-csimmonds-fosdem-2019
Android rpi-csimmonds-fosdem-2019
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Targeting Android with Qt
Targeting Android with QtTargeting Android with Qt
Targeting Android with Qt
 
Android Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and PatternsAndroid Effective UI: Tips, Tricks and Patterns
Android Effective UI: Tips, Tricks and Patterns
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 

Más de Chris Simmonds

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDBChris Simmonds
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Chris Simmonds
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Chris Simmonds
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiChris Simmonds
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devicesChris Simmonds
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded LinuxChris Simmonds
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?Chris Simmonds
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneChris Simmonds
 
Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Chris Simmonds
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOChris Simmonds
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of playChris Simmonds
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practiceChris Simmonds
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphoneChris Simmonds
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easierChris Simmonds
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016Chris Simmonds
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)Chris Simmonds
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015Chris Simmonds
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAMChris Simmonds
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded LinuxChris Simmonds
 

Más de Chris Simmonds (20)

Debugging embedded devices using GDB
Debugging embedded devices using GDBDebugging embedded devices using GDB
Debugging embedded devices using GDB
 
Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?Debian or Yocto Project? Which is the best for your Embedded Linux project?
Debian or Yocto Project? Which is the best for your Embedded Linux project?
 
Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5Embedded Linux Quick Start Guide v1.5
Embedded Linux Quick Start Guide v1.5
 
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry PiRunning Android on the Raspberry Pi: Android Pie meets Raspberry Pi
Running Android on the Raspberry Pi: Android Pie meets Raspberry Pi
 
Reducing the boot time of Linux devices
Reducing the boot time of Linux devicesReducing the boot time of Linux devices
Reducing the boot time of Linux devices
 
Reducing boot time in embedded Linux
Reducing boot time in embedded LinuxReducing boot time in embedded Linux
Reducing boot time in embedded Linux
 
Linux power management: are you doing it right?
Linux power management: are you doing it right?Linux power management: are you doing it right?
Linux power management: are you doing it right?
 
Embedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphoneEmbedded Android: Android beyond the smartphone
Embedded Android: Android beyond the smartphone
 
Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017Software update for IoT Embedded World 2017
Software update for IoT Embedded World 2017
 
Quick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIOQuick and Easy Device Drivers for Embedded Linux Using UIO
Quick and Easy Device Drivers for Embedded Linux Using UIO
 
Software update for IoT: the current state of play
Software update for IoT: the current state of playSoftware update for IoT: the current state of play
Software update for IoT: the current state of play
 
Read-only rootfs: theory and practice
Read-only rootfs: theory and practiceRead-only rootfs: theory and practice
Read-only rootfs: theory and practice
 
Android beyond the smartphone
Android beyond the smartphoneAndroid beyond the smartphone
Android beyond the smartphone
 
10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier10 ways hardware engineers can make software integration easier
10 ways hardware engineers can make software integration easier
 
Userspace drivers-2016
Userspace drivers-2016Userspace drivers-2016
Userspace drivers-2016
 
The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)The end of embedded Linux (as we know it)
The end of embedded Linux (as we know it)
 
Linux field-update-2015
Linux field-update-2015Linux field-update-2015
Linux field-update-2015
 
Tuning Android for low RAM
Tuning Android for low RAMTuning Android for low RAM
Tuning Android for low RAM
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
A timeline for embedded Linux
A timeline for embedded LinuxA timeline for embedded Linux
A timeline for embedded Linux
 

Último

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Último (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

The Android graphics path, in depth

  • 1. The Android graphics path in depth The Android graphics path 1 Copyright ©2011-2014, 2net Limited
  • 2. License These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full text of the license here http://creativecommons.org/licenses/by-sa/3.0/legalcode You are free to • copy, distribute, display, and perform the work • make derivative works • make commercial use of the work Under the following conditions • Attribution: you must give the original author credit • Share Alike: if you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one (i.e. include this page exactly as it is) • For any reuse or distribution, you must make clear to others the license terms of this work The orginals are at http://2net.co.uk/slides/android-graphics-abs-2014.pdf The Android graphics path 2 Copyright ©2011-2014, 2net Limited
  • 3. About Chris Simmonds • Consultant and trainer • Working with embedded Linux since 1999 • Android since 2009 • Speaker at many conferences and workshops "Looking after the Inner Penguin" blog at http://2net.co.uk/ https://uk.linkedin.com/in/chrisdsimmonds/ https://google.com/+chrissimmonds The Android graphics path 3 Copyright ©2011-2014, 2net Limited
  • 4. Overview • The Android graphics stack changed a lot in Jelly Bean as a result of project Butter • This presentation describes the current (JB) graphics stack from top to bottom • Main topics covered • The application layer • SurfaceFlinger, interfaces and buffer queues • The hardware modules HWComposer and Gralloc • OpenGL ES and EGL The Android graphics path 4 Copyright ©2011-2014, 2net Limited
  • 5. The big picture SurfaceFlinger Activity OpenGL vendor libraries OpenGL ES GPU driver HWComposer ION Gralloc alloc FB driver Gralloc FB Android framework Vendor HAL library Kernel driver Activity Activity Manager Window Manager BufferQueue The Android graphics path 5 Copyright ©2011-2014, 2net Limited
  • 6. Inception of a pixel • Everything begins when an activity draws to a surface • 2D applications can use • drawing functions in Canvas to write to a Bitmap: android.graphics.Canvas.drawRect(), drawText(), etc • descendants of the View class to draw objects such as buttons and lists • a custom View class to implement your own appearance and behaviour • In all cases the drawing is rendered to a Surface which contains a GraphicBuffer The Android graphics path 6 Copyright ©2011-2014, 2net Limited
  • 7. 2D rendering path Activity Canvas Surface SkiaOpenGL ES Vendor Open GL GPU driver Activity HWUI The Android graphics path 7 Copyright ©2011-2014, 2net Limited
  • 8. Skia and hwui • For 2D drawing there are two rendering paths • hwui: (libwhui.so) hardware accelerated using OpenGL ES 2.0 • skia: (libskia.so) software render engine • hwui is the default • Hardware rendering can be disabled per view, window, activity, application or for the whole device • Maybe for comparability reasons: hwui produces results different to skia in some (rare) cases The Android graphics path 8 Copyright ©2011-2014, 2net Limited
  • 9. 3D rendering path • An activity can instead create a GLSurfaceView and use OpenGL ES bindings for Java (the android.opengl.* classes) • Using either the vendor GPU driver (which must support OpenGL ES 2.0 and optinally 3.0) • Or as a fall-back, using PixelFlinger, a software GPU that implements OpenGL ES 1.0 only • Once again, the drawing is rendered to a Surface The Android graphics path 9 Copyright ©2011-2014, 2net Limited
  • 10. 3D rendering path Activity Surface OpenGL ES Vendor Open GL GPU driver Activity Android GL PixelFlinger The Android graphics path 10 Copyright ©2011-2014, 2net Limited
  • 12. SurfaceFlinger frameworks/native/services/surfaceflinger • A high-priority native (C++) daemon, started by init with UID=system • Services connections from activities via Binder interface ISurfaceComposer • Receives activity status from Activity Manager • Receives window status (visibility, Z-order) from Window Manager • Composits multiple Surfaces into a single image • Passes image to one or more displays • Manages buffer allocation, synchronisation The Android graphics path 12 Copyright ©2011-2014, 2net Limited
  • 13. SurfaceFlinger binder interfaces SurfaceFlinger Client ISurfaceComposer ISurfaceComposerClient IDisplayEventConnection e.g. activity createConnection() createDisplayEventConnection() createSurface() destroySurface() getDataChannel() The Android graphics path 13 Copyright ©2011-2014, 2net Limited
  • 14. ISurfaceComposer • ISurfaceComposer • Clients use this interface to set up a connection with SurfaceFlinger • Client begins by calling createConnection() which spawns an ISurfaceComposerClient • Client calls createGraphicBufferAlloc() to create an instance of IGraphicBufferAlloc (discussed later) • Client calls createDisplayEventConnection() to create an instance of IDisplayEventConnection • Other methods include captureScreen() and setTransactionState() The Android graphics path 14 Copyright ©2011-2014, 2net Limited
  • 15. ISurfaceComposerClient • ISurfaceComposerClient • This interface has two methods: • createSurface() asks SufraceFlinger to create a new Surface • destroySurface() destroys a Surface The Android graphics path 15 Copyright ©2011-2014, 2net Limited
  • 16. IDisplayEventConnection • IDisplayEventConnection • This interface passes vsync event information from SurfaceFlinger to the client • setVsyncRate() sets the vsync event delivery rate: value of 1 returns all events, 0 returns none • requestNextVsync() schedules the next vsync event: has no effect if the vsync rate is non zero • getDataChannel() returns a BitTube which can be used to receive events The Android graphics path 16 Copyright ©2011-2014, 2net Limited
  • 17. BufferQueue frameworks/native/include/gui/BufferQueue.h • Mechanism for passing GraphicBuffers to SurfaceFlinger • Contains an array of between 2 and 32 GraphicBuffers • Uses interface IGraphicBufferAlloc to allocate buffers (see later) • Provides two Binder interfaces • IGraphicBufferProducer for the client (Activity) • IGraphicBufferConsumer for the consumer (SurfaceFlinger) • Buffers cycle between producer and consumer The Android graphics path 17 Copyright ©2011-2014, 2net Limited
  • 19. BufferQueue • Default number of buffer slots since JB is 3 (previously 2) • In JB you can compile Layer.cpp with TARGET_DISABLE_TRIPLE_BUFFERING to return to 2 slots • Call setBufferCount() to change the number of slots • BufferQueue operates in two modes: • Synchronous: client blocks until there is a free slot • Asynchronous: queueBuffer() discards any existing buffers in QUEUED state so the queue only holds the most recent frame The Android graphics path 19 Copyright ©2011-2014, 2net Limited
  • 20. GraphicBuffer frameworks/native/include/ui/GraphicBuffer.h • Represents a buffer, wraps ANativeWindowBuffer • Attributes including width, height, format, usage inherited from ANativeWindowBuffer The Android graphics path 20 Copyright ©2011-2014, 2net Limited
  • 21. Composition • On a vsync event, SurfaceFlinger calls handleMessageRefresh() which goes through a composition cycle: • preComposition(): sort layers by Z order and call onPreComposition() for each • doComposition(): loop through displays: if there is a dirty region, mark it to be drawn then call postFameBuffer() to do the drawing • postComposition(): loop through layers in Z order and call onPostComposition() The Android graphics path 21 Copyright ©2011-2014, 2net Limited
  • 22. Layer frameworks/native/services/surfaceflinger/Layer.h • Each Layer has • Z order • Alpha value from 0 to 255 • visibleRegion • crop region • transformation: rotate 0, 90, 180, 270: flip H, V: scale • SurfaceFlinger composits the layers using • HWComposer, if it supports the operation • Fall back to the GPU, via OpenGL ES (version 1.0 only, for historical reasons) The Android graphics path 22 Copyright ©2011-2014, 2net Limited
  • 23. HWComposer hardware/libhardware/include/hardware/hwcomposer.h • HWComposer is a vendor-supplied library, at run-time in /system/lib/hw/hwcomposer.[product name].so • Optional: in all cases there are fall-backs if HWC is absent • HWC does several different things • sync framework (vsync callback) • modesetting, display hotplug (e.g. hdmi) • compositing layers together using features of the display controller • displaying frames on the screen The Android graphics path 23 Copyright ©2011-2014, 2net Limited
  • 24. prepare() and set() • SurfaceFlinger calls HWComposer in two stages • prepare() • Passes a list of layers • For each layer, HWComposer returns • HWC_FRAMEBUFFER: SurfaceFlinger should write this layer (using OpenGL) • HWC_OVERLAY: will be composed by HWComposer • set() • Passes the list of layers for HWComposer to handle • set() is used in place of eglSwapBuffers() The Android graphics path 24 Copyright ©2011-2014, 2net Limited
  • 25. vsync • Since JB 4.1 SurfaceFlinger is synchronised to a 60Hz (16.7ms period) vsync event • If HWComposer present, it is responsible for vsync • Usually using an interrupt from the display: if no h/w trigger, fake in software • vsync() is a callback registered with HWComposer • Each callback includes a display identifier and a timestamp (in ns) • If no HWComposer, SurfaceFlinger uses 16ms timeout in s/w The Android graphics path 25 Copyright ©2011-2014, 2net Limited
  • 26. Displays • HWComposer defines three display types HWC_DISPLAY_PRIMARY e.g. built-in LCD screen HWC_DISPLAY_EXTERNAL e.g. HDMI, WiDi HWC_DISPLAY_VIRTUAL not a real display • For each display there is an instance of DisplayDevice in SurfaceFlinger The Android graphics path 26 Copyright ©2011-2014, 2net Limited
  • 27. IGraphicBufferAlloc and friends frameworks/native/include/gui/IGraphicBufferAlloc.h • Binder interface used by SurfaceFlinger to allocate buffers • Has one function createGraphicBuffer • Implemented by class GraphicBufferAllocator, which wraps the ANativeWindowBuffer class • Uses Gralloc.alloc to the the actual allocation • Underlying buffer is referenced by a buffer_handle_t which is a file descriptor (returned by gralloc alloc) • Binder can pass open file descriptors from process to process • Access buffer data using mmap The Android graphics path 27 Copyright ©2011-2014, 2net Limited
  • 28. Buffer usage and pixel format frameworks/native/include/ui/GraphicBuffer.h USAGE_HW_TEXTURE OpenGL ES texture USAGE_HW_RENDER OpenGL ES render target USAGE_HW_2D 2D hardware blitter USAGE_HW_COMPOSER used by the HWComposer HAL USAGE_HW_VIDEO_ENCODER HW video encoder frameworks/native/include/ui/PixelFormat.h PIXEL_FORMAT_RGBA_8888 4x8-bit RGBA PIXEL_FORMAT_RGBX_8888 4x8-bit RGB0 PIXEL_FORMAT_RGB_888 3x8-bit RGB PIXEL_FORMAT_RGB_565 16-bit RGB PIXEL_FORMAT_BGRA_8888 4x8-bit BGRA The Android graphics path 28 Copyright ©2011-2014, 2net Limited
  • 29. Gralloc hardware/libhardware/include/hardware/gralloc.h • Gralloc is a vendor-supplied library, at run-time in /system/lib/hw/gralloc.[product name].so • Does two things • gralloc alloc: allocates graphic buffers • gralloc framebuffer: interface to Linux framebuffer device, e.g. /dev/graphics/fb0 • gralloc alloc allocates all graphic buffers using a kernel memory manager, typically ION • Selects appropriate ION heap based on the buffer usage flags The Android graphics path 29 Copyright ©2011-2014, 2net Limited
  • 30. OpenGL ES • The Khronos OpenGL ES and EGL APIs are implemented in these libraries • /system/lib/libEGL.so • /system/lib/libGLESv1_CM.so • /system/lib/libGLESv2.so • /system/lib/libGLESv3.so (optional from JB 4.3 onwards: actually a symlink to libGLESv2.so) • In most cases they simply call down to the vendor-supplied libraries in /system/lib/egl The Android graphics path 30 Copyright ©2011-2014, 2net Limited
  • 31. EGL • EGL is the Khronos Native Platform Graphics Interface • Rendering operations are executed in an EGLContext • In most cases the EGLContext is based on the default display • The mapping from the EGL generic display type is done in frameworks/native/opengl/include/EGL/eglplatform.h typedef struct ANativeWindow* EGLNativeWindowType; • EGLNativeWindowType is defined in system/core/include/system/window.h The Android graphics path 31 Copyright ©2011-2014, 2net Limited
  • 32. OpenGL vendor implementation • The vendor OpenGL libraries form the interface to the GPU • Responsible for • creating display lists • scheduling work for the GPU • managing buffer synchronisation (typically using fences, see background at the end) • Usually there is a kernel driver which handles low level memory management, DMA and interrupts • The kernel interface is usually a group of ioctl functions The Android graphics path 32 Copyright ©2011-2014, 2net Limited
  • 33. • Questions? The Android graphics path 33 Copyright ©2011-2014, 2net Limited
  • 34. Background: fences The Android graphics path 34 Copyright ©2011-2014, 2net Limited
  • 35. Buffer synchronisation • There are many producers and consumers of graphics buffers • Pre JB sync was implicit: buffer not released until operation complete • Did not encourage parallel processing • JB introduced explicit sync: each buffer has a sync object called a fence • Means a buffer can be passed to the next user before operations complete • The next user waits on the fence before accessing the buffer contents The Android graphics path 35 Copyright ©2011-2014, 2net Limited
  • 36. Synchronisation using fences • Represented by file handles: can be passed between applications in binder messages • Can also be passed from applications to drivers • Each device driver (display, camera, video codec...) has its own timeline • A fence may have synchronisation points on multiple timelines • Allows buffers to be passed between multiple devices The Android graphics path 36 Copyright ©2011-2014, 2net Limited
  • 37. Timeline and sync point • Timeline • Per-device (display, GPU, camera, ...) • Monotonically increasing 32-bit value • Incremented after each event (essentially it is a count of the jobs processed by the device) • Sync point • A point on a timeline • Becomes signalled when the timeline passes it The Android graphics path 37 Copyright ©2011-2014, 2net Limited
  • 38. Fence • Fence • A collection of one or more sync points, possibly from different timelines • Represented by a file descriptor so an application can wait using poll() • Two fences can be merged to create a new fence that depends on all the sync points of the original pair The Android graphics path 38 Copyright ©2011-2014, 2net Limited
  • 39. Fence: example FB timeline GPU timeline Sync pt Sync pt Sync Fence The Android graphics path 39 Copyright ©2011-2014, 2net Limited
  • 40. Background: ION The Android graphics path 40 Copyright ©2011-2014, 2net Limited
  • 41. Memory constraints • Often necessary for a buffer to be accessed by hardware • Example: graphics buffer and display controller or GPU • Hardware may constrain memory access • Example: hardware without IOMMU usually needs physically contiguous memory • To avoid copying, the memory must be allocated for the most constrained device The Android graphics path 41 Copyright ©2011-2014, 2net Limited
  • 42. ION • Previous memory allocators include pmem (Qualcomm), cmem (TI), and nvmap (NVIDA) • ION provides a unified interface for these needs • Different allocation constraints • Different caching requirements • But the programmer still has to make the right choices The Android graphics path 42 Copyright ©2011-2014, 2net Limited
  • 43. Types of heap • ION_HEAP_TYPE_SYSTEM • memory allocated via vmalloc • ION_HEAP_TYPE_SYSTEM_CONTIG • memory allocated via kmalloc • ION_HEAP_TYPE_CARVEOUT • memory allocated from a pre reserved carveout heap • allocations are physically contiguous The Android graphics path 43 Copyright ©2011-2014, 2net Limited
  • 44. Heap flags • ION_FLAG_CACHED • mappings of this buffer should be cached, ION will do cache maintenance when the buffer is mapped for DMA • ION_FLAG_CACHED_NEEDS_SYNC • Cache must be managed manually, e.g. using ION_IOC_SYNC The Android graphics path 44 Copyright ©2011-2014, 2net Limited