Drawn out: How Android renders (Google I/O '18)

Android Developers · 55K views · 2018 · 36:03

Open on YouTube

Software performance & optimizationComputer graphics & renderingOperating systems & kernelstalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering or asking about how Android draws views, the render thread, frame rate and jank, and how windows relate to SurfaceFlinger layers.

Recommended by 2 people across 4 different months, 2012 to 2023.

What it is

A Google I/O 2018 talk by Android engineers Chet Haase and Romain Guy explaining how Android turns an app's view hierarchy into pixels on screen. It covers the rendering pipeline, from the UI and render threads through windows, surfaces and SurfaceFlinger composition, with a focus on how this affects performance.

What people said

Recommends Morrison Chang · 2012-06 · Stack Overflow · on “FPS testing in android application”

As mention by Guykun and kcoppock, if you are only using the View widgets or Canvas you normally don't look for FPS to determine visual performance. As you don't mention what you are doing other than 'not a game' you may want to review how Android does drawing. [LINK] Most of the performance issues come from doing stuff on the UI thread. Use Strict Mode for finding problems. [LINK] Also use the tools to find performance hot spots: [LINK] [LINK] [LINK] And if you want more details of what's going on under the hood see the Google IO session on what they did for Hardware Accelerated Rendering Google I/O 2011: Accelerated Android Rendering [LINK] Google has done additional work on UI performance

Recommends Morrison Chang · 2021-02 · Stack Overflow · on “Android non-square hit areas. Can it be done?”

Views were in Android from 2008 and base GUI elements have been to my knowledge rectangular. If you don't have the math skills, find a library (or search). The framework is doing a lot under the hood for rendering, see: Drawn out: How Android renders (Google I/O '18) [this video]

Recommends JumperBot_ · 2022-07 · Stack Overflow · on “What does virtual display in Android do with Image pixels when smaller display dimensions are set than grabbed one?”

By digging in the AOSP [LINK] , watching [this video] , looking at a thread [LINK] and experimenting~ I have come to my own (might be overly) simplified conclusion. Android calls the native Java SDK which produces the information that's needed to render a bitmap/pixels on a Java program. If the results are the same don't need to pass/copy it again to the GPU. If the results are not the same pass/copy it to the GPU to be "invalidated" then re-rendered. Now to your question. By looking at the Bitmap [LINK] class and looking at this thread [LINK] It came to my mind that resizing depends on the scaling ratio passed on to the Matrix [LINK] class. If resized, it will expensively create a new Bitmap tha

Recommends Morrison Chang · 2022-07 · Stack Overflow · on “Get Frame Rate of Android using Kotlin”

I'm not sure what problem you are trying to solve by getting the 'frame rate' of the system. I recommend reviewing the Google IO video: Drawn out: How Android renders (Google I/O '18) [this video] and UI Jank Detection [LINK] documentation.

Recommends Morrison Chang · 2023-05 · Stack Overflow · on “Is there any way to attach a cpp char* buffer(using jni maybe) to an Edittext Widget in Android”

Do realize that the Android rendering system is doing a lot of stuff, see youtube video: Drawn out: How Android renders (Google I/O '18) [this video] , so if you need to be so invasive you may have to write your own EditText class, Android is open-source.

Cites Morrison Chang · 2020-02 · Stack Overflow · on “Are Android Views backed by OpenGL?”

Do native Android views (View class and everything that extends it, i.e. TextView, ImageView, etc...), use OpenGL under the hood? Basically yes, OpenGL ES [LINK] is the API used by the display hardware system to draw things on the screen. More recently Vulkan [LINK] is gaining support as an alternate API and would be using a project like ANGLE [LINK] to provide support for OpenGL ES. As the Android Open Source Project [LINK] already has a document on Graphics system in Android [LINK] you should look there for more detail. Are there any advantages to using OpenGL to the average Android Developer as opposed to using the regular views for custom UI components? If you want complete control over

Cites Heiko Averbeck · 2020-06 · Stack Overflow · on “Android Rendering: Is actually in the end everything rendered via OpenGL”

Is actually in the end everything rendered via OpenGL in Android. I have already checked out this video [this video] and the relevant documents. And it seems that not all is rendered via OpenGL or maybe Vulkan nowadays. But when it is not rendered via this, how is it rendered, via some internal stuff inside the SurfaceFlinger? Can someone show up the way through the code from the application level to the very last point before the hardware?

Cites Morrison Chang · 2021-04 · Stack Overflow · on “Is the UI thread of Android an OpenGL thread”

Not sure what you mean by 'bound', but the render thread is separate from the UI thread. See: Drawn out: How Android renders (Google I/O '18) [this video]

Cites Morrison Chang · 2022-05 · Stack Overflow · on “Android draw part of a bitmap to a Canvas without creating a new Bitmap”

Without seeing code, multiple passes with porter-duff sounds like what you want but are trying to avoid. Off-topic: if you are doing a 2D game, I would use one of the existing 2D game engines as they use OpenGL ES based engines. If you are writing your own engine these old videos: Google I/O - Writing Real-Time Games for Android [LINK] and Google I/O - Writing real-time games for Android redux [LINK] which provides good info. Canvas drawing uses and is limited by: Drawn out: How Android renders (Google IO 2018) [this video]

Cites Bulart46_ · 2022-11 · Stack Overflow · on “How do Window and Layer from SurfaceFlinger interact?”

As far as I know Window has Surface and View Hierarchy. And every time an Activity, Toast or Dialog is created, the WindowManager creates a Window object and attaches it to itself. The WindowManager also creates a Surface object for this Window. From the talk Drawn out: How Android renders (Google I/O '18) ( [this video] ) I learned that after creating a Window, it has a sibling Layer object on the SurfaceFlinger side. And composition uses exactly Layer objects. As I understand it, Layer is a combination of Surface and SurfaceControl. It also creates and owns a BufferQueue. But I can't understand the relationship between Window and Layer, because Window already has a Surface, then why is Layer ne