Clay Murphy | e3ae396 | 2014-09-02 17:30:57 -0700 | [diff] [blame] | 1 | page.title=Graphics architecture |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 2 | @jd:body |
| 3 | |
| 4 | <!-- |
| 5 | Copyright 2014 The Android Open Source Project |
| 6 | |
| 7 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | you may not use this file except in compliance with the License. |
| 9 | You may obtain a copy of the License at |
| 10 | |
| 11 | http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | |
| 13 | Unless required by applicable law or agreed to in writing, software |
| 14 | distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | See the License for the specific language governing permissions and |
| 17 | limitations under the License. |
| 18 | --> |
| 19 | <div id="qv-wrapper"> |
| 20 | <div id="qv"> |
| 21 | <h2>In this document</h2> |
| 22 | <ol id="auto-toc"> |
| 23 | </ol> |
| 24 | </div> |
| 25 | </div> |
| 26 | |
| 27 | |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 28 | <p><em>What every developer should know about Surface, SurfaceHolder, |
| 29 | EGLSurface, SurfaceView, GLSurfaceView, SurfaceTexture, TextureView, |
| 30 | SurfaceFlinger, and Vulkan.</em></p> |
| 31 | |
| 32 | <p>This page describes essential elements of the Android system-level graphics |
| 33 | architecture and how they are used by the application framework and multimedia |
| 34 | system. The focus is on how buffers of graphical data move through the system. |
| 35 | If you've ever wondered why SurfaceView and TextureView behave the way they do, |
| 36 | or how Surface and EGLSurface interact, you are in the correct place.</p> |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 37 | |
| 38 | <p>Some familiarity with Android devices and application development is assumed. |
Heidi von Markham | 2684c46 | 2016-06-24 13:46:53 -0700 | [diff] [blame] | 39 | You don't need detailed knowledge of the app framework and very few API calls |
| 40 | are mentioned, but the material doesn't overlap with other public |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 41 | documentation. The goal is to provide details on the significant events |
Heidi von Markham | 2684c46 | 2016-06-24 13:46:53 -0700 | [diff] [blame] | 42 | involved in rendering a frame for output to help you make informed choices |
| 43 | when designing an application. To achieve this, we work from the bottom up, |
| 44 | describing how the UI classes work rather than how they can be used.</p> |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 45 | |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 46 | <p>This section includes several pages covering everything from background |
| 47 | material to HAL details to use cases. It starts with an explanation of Android |
| 48 | graphics buffers, describes the composition and display mechanism, then proceeds |
| 49 | to the higher-level mechanisms that supply the compositor with data. We |
| 50 | recommend reading pages in the order listed below rather than skipping to a |
| 51 | topic that sounds interesting.</p> |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 52 | |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 53 | <h2 id=low_level>Low-level components</h2> |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 54 | |
| 55 | <ul> |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 56 | <li><a href="{@docRoot}devices/graphics/arch-bq-gralloc.html">BufferQueue and |
| 57 | gralloc</a>. BufferQueue connects something that generates buffers of graphical |
| 58 | data (the <em>producer</em>) to something that accepts the data for display or |
| 59 | further processing (the <em>consumer</em>). Buffer allocations are performed |
| 60 | through the <em>gralloc</em> memory allocator implemented through a |
| 61 | vendor-specific HAL interface.</li> |
| 62 | |
| 63 | <li><a href="{@docRoot}devices/graphics/arch-sf-hwc.html">SurfaceFlinger, |
| 64 | Hardware Composer, and virtual displays</a>. SurfaceFlinger accepts buffers of |
| 65 | data from multiple sources, composites them, and sends them to the display. The |
| 66 | Hardware Composer HAL (HWC) determines the most efficient way to composite |
| 67 | buffers with the available hardware, and virtual displays make composited output |
| 68 | available within the system (recording the screen or sending the screen over a |
| 69 | network).</li> |
| 70 | |
| 71 | <li><a href="{@docRoot}devices/graphics/arch-sh.html">Surface, Canvas, and |
| 72 | SurfaceHolder</a>. A Surface produces a buffer queue that is often consumed by |
| 73 | SurfaceFlinger. When rendering onto a Surface, the result ends up in a buffer |
| 74 | that gets shipped to the consumer. Canvas APIs provide a software implementation |
| 75 | (with hardware-acceleration support) for drawing directly on a Surface |
| 76 | (low-level alternative to OpenGL ES). Anything having to do with a View involves |
| 77 | a SurfaceHolder, whose APIs enable getting and setting Surface parameters such |
| 78 | as size and format.</li> |
| 79 | |
| 80 | <li><a href="{@docRoot}devices/graphics/arch-egl-opengl.html">EGLSurface and |
| 81 | OpenGL ES</a>. OpenGL ES (GLES) defines a graphics-rendering API designed to be |
| 82 | combined with EGL, a library that knows how to create and access windows through |
| 83 | the operating system (to draw textured polygons, use GLES calls; to put |
| 84 | rendering on the screen, use EGL calls). This page also covers ANativeWindow, |
| 85 | the C/C++ equivalent of the Java Surface class used to create an EGL window |
| 86 | surface from native code.</li> |
| 87 | |
| 88 | <li><a href="{@docRoot}devices/graphics/arch-vulkan.html">Vulkan</a>. Vulkan is |
| 89 | a low-overhead, cross-platform API for high-performance 3D graphics. Like OpenGL |
| 90 | ES, Vulkan provides tools for creating high-quality, real-time graphics in |
| 91 | applications. Vulkan advantages include reductions in CPU overhead and support |
| 92 | for the <a href="https://www.khronos.org/spir">SPIR-V Binary Intermediate</a> |
| 93 | language.</li> |
| 94 | |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 95 | </ul> |
| 96 | |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 97 | <h2 id=high_level>High-level components</h2> |
Clay Murphy | ccf3037 | 2014-04-07 16:13:19 -0700 | [diff] [blame] | 98 | |
Heidi von Markham | 2684c46 | 2016-06-24 13:46:53 -0700 | [diff] [blame] | 99 | <ul> |
Heidi von Markham | 6bda398 | 2016-06-30 17:04:44 -0700 | [diff] [blame] | 100 | <li><a href="{@docRoot}devices/graphics/arch-sv.html">SurfaceView and |
| 101 | GLSurfaceView</a>. SurfaceView combines a Surface and a View. SurfaceView's View |
| 102 | components are composited by SurfaceFlinger (and not the app), enabling |
| 103 | rendering from a separate thread/process and isolation from app UI rendering. |
| 104 | GLSurfaceView provides helper classes to manage EGL contexts, inter-thread |
| 105 | communication, and interaction with the Activity lifecycle (but is not required |
| 106 | to use GLES).</li> |
| 107 | |
| 108 | <li><a href="{@docRoot}devices/graphics/arch-st.html">SurfaceTexture</a>. |
| 109 | SurfaceTexture combines a Surface and GLES texture to create a BufferQueue for |
| 110 | which your app is the consumer. When a producer queues a new buffer, it notifies |
| 111 | your app, which in turn releases the previously-held buffer, acquires the new |
| 112 | buffer from the queue, and makes EGL calls to make the buffer available to GLES |
| 113 | as an external texture. Android 7.0 adds support for secure texture video |
| 114 | playback enabling GPU post-processing of protected video content.</li> |
| 115 | |
| 116 | <li><a href="{@docRoot}devices/graphics/arch-tv.html">TextureView</a>. |
| 117 | TextureView combines a View with a SurfaceTexture. TextureView wraps a |
| 118 | SurfaceTexture and takes responsibility for responding to callbacks and |
| 119 | acquiring new buffers. When drawing, TextureView uses the contents of the most |
| 120 | recently received buffer as its data source, rendering wherever and however the |
| 121 | View state indicates it should. View composition is always performed with GLES, |
| 122 | meaning updates to contents may cause other View elements to redraw as well.</li> |
Heidi von Markham | 2684c46 | 2016-06-24 13:46:53 -0700 | [diff] [blame] | 123 | </ul> |