1 <html devsite> 2 <head> 3 <title>Implementing Virtual Displays</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p>Android added platform support for virtual displays in Hardware Composer 27 v1.3 (support can be used by Miracast). The virtual display composition is 28 similar to the physical display: Input layers are described in 29 <code>prepare()</code>, SurfaceFlinger conducts GPU composition, and layers and 30 GPU framebuffer are provided to Hardware Composer in <code>set()</code>.</p> 31 32 <p>Instead of the output going to the screen, it is sent to a gralloc buffer. 33 Hardware Composer writes output to a buffer and provides the completion fence. 34 The buffer is sent to an arbitrary consumer: video encoder, GPU, CPU, etc. 35 Virtual displays can use 2D/blitter or overlays if the display pipeline can 36 write to memory.</p> 37 38 <h2 id=modes>Modes</h2> 39 40 <p>Each frame is in one of three modes after <code>prepare()</code>:</p> 41 42 <ul> 43 <li><em>GLES</em>. All layers composited by GPU, which writes directly to the 44 output buffer while Hardware Composer does nothing. This is equivalent to 45 virtual display composition with Hardware Composer version older than v1.3.</li> 46 <li><em>MIXED</em>. GPU composites some layers to framebuffer, and Hardware 47 Composer composites framebuffer and remaining layers. GPU writes to scratch 48 buffer (framebuffer); Hardware Composer reads scratch buffer and writes to the 49 output buffer. Buffers may have different formats, e.g. RGBA and YCbCr.</li> 50 <li><em>HWC</em>. All layers composited by Hardware Composer, which writes 51 directly to the output buffer.</li> 52 </ul> 53 54 <h2 id=output_format>Output format</h2> 55 <p>Output format depends on the mode:</p> 56 57 <ul> 58 <li><em>MIXED and HWC modes</em>. If the consumer needs CPU access, the consumer 59 chooses the format. Otherwise, the format is IMPLEMENTATION_DEFINED. Gralloc 60 can choose best format based on usage flags. For example, choose a YCbCr format 61 if the consumer is video encoder, and Hardware Composer can write the format 62 efficiently.</li> 63 <li><em>GLES mode</em>. EGL driver chooses output buffer format in 64 <code>dequeueBuffer()</code>, typically RGBA8888. The consumer must be able to 65 accept this format.</li> 66 </ul> 67 68 <h2 id=egl_requirement>EGL requirement</h2> 69 70 <p>Hardware Composer v1.3 virtual displays require that 71 <code>eglSwapBuffers()</code> does not dequeue the next buffer immediately. 72 Instead, it should defer dequeueing the buffer until rendering begins. 73 Otherwise, EGL always owns the next output buffer. SurfaceFlinger cant get the 74 output buffer for Hardware Composer in MIXED/HWC mode.</p> 75 76 <p>If Hardware Composer always sends all virtual display layers to GPU, all 77 frames will be in GLES mode. Although not recommended, you may use this 78 method if you need to support Hardware Composer v1.3 for some other reason but 79 cant conduct virtual display composition.</p> 80 81 </body> 82 </html> 83