1 page.title=Implementing Virtual Displays 2 @jd:body 3 4 <!-- 5 Copyright 2016 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 20 <div id="qv-wrapper"> 21 <div id="qv"> 22 <h2>In this document</h2> 23 <ol id="auto-toc"> 24 </ol> 25 </div> 26 </div> 27 28 <p>Android added platform support for virtual displays in Hardware Composer 29 v1.3 (support can be used by Miracast). The virtual display composition is 30 similar to the physical display: Input layers are described in 31 <code>prepare()</code>, SurfaceFlinger conducts GPU composition, and layers and 32 GPU framebuffer are provided to Hardware Composer in <code>set()</code>.</p> 33 34 <p>Instead of the output going to the screen, it is sent to a gralloc buffer. 35 Hardware Composer writes output to a buffer and provides the completion fence. 36 The buffer is sent to an arbitrary consumer: video encoder, GPU, CPU, etc. 37 Virtual displays can use 2D/blitter or overlays if the display pipeline can 38 write to memory.</p> 39 40 <h2 id=modes>Modes</h2> 41 42 <p>Each frame is in one of three modes after <code>prepare()</code>:</p> 43 44 <ul> 45 <li><em>GLES</em>. All layers composited by GPU, which writes directly to the 46 output buffer while Hardware Composer does nothing. This is equivalent to 47 virtual display composition with Hardware Composer version older than v1.3.</li> 48 <li><em>MIXED</em>. GPU composites some layers to framebuffer, and Hardware 49 Composer composites framebuffer and remaining layers. GPU writes to scratch 50 buffer (framebuffer); Hardware Composer reads scratch buffer and writes to the 51 output buffer. Buffers may have different formats, e.g. RGBA and YCbCr.</li> 52 <li><em>HWC</em>. All layers composited by Hardware Composer, which writes 53 directly to the output buffer.</li> 54 </ul> 55 56 <h2 id=output_format>Output format</h2> 57 <p>Output format depends on the mode:</p> 58 59 <ul> 60 <li><em>MIXED and HWC modes</em>. If the consumer needs CPU access, the consumer 61 chooses the format. Otherwise, the format is IMPLEMENTATION_DEFINED. Gralloc 62 can choose best format based on usage flags. For example, choose a YCbCr format 63 if the consumer is video encoder, and Hardware Composer can write the format 64 efficiently.</li> 65 <li><em>GLES mode</em>. EGL driver chooses output buffer format in 66 <code>dequeueBuffer()</code>, typically RGBA8888. The consumer must be able to 67 accept this format.</li> 68 </ul> 69 70 <h2 id=egl_requirement>EGL requirement</h2> 71 72 <p>Hardware Composer v1.3 virtual displays require that 73 <code>eglSwapBuffers()</code> does not dequeue the next buffer immediately. 74 Instead, it should defer dequeueing the buffer until rendering begins. 75 Otherwise, EGL always owns the next output buffer. SurfaceFlinger cant get the 76 output buffer for Hardware Composer in MIXED/HWC mode.</p> 77 78 <p>If Hardware Composer always sends all virtual display layers to GPU, all 79 frames will be in GLES mode. Although not recommended, you may use this 80 method if you need to support Hardware Composer v1.3 for some other reason but 81 cant conduct virtual display composition.</p> 82