VirtualDisplaySurface.h revision ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0a
1/* 2 * Copyright 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 18#define ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 19 20#include "BufferQueueInterposer.h" 21#include "DisplaySurface.h" 22 23// --------------------------------------------------------------------------- 24namespace android { 25// --------------------------------------------------------------------------- 26 27class HWComposer; 28 29/* This DisplaySurface implementation uses a BufferQueueInterposer to pass 30 * partially- or fully-composited buffers from the OpenGL ES driver to 31 * HWComposer to use as the output buffer for virtual displays. Allowing HWC 32 * to compose into the same buffer that contains GLES results saves bandwidth 33 * compared to having two separate BufferQueues for frames with at least some 34 * GLES composition. 35 * 36 * The alternative would be to have two complete BufferQueues, one from GLES 37 * to HWC and one from HWC to the virtual display sink (e.g. video encoder). 38 * For GLES-only frames, the same bandwidth saving could be achieved if buffers 39 * could be acquired from the GLES->HWC queue and inserted into the HWC->sink 40 * queue. That would be complicated and doesn't help the mixed GLES+HWC case. 41 * 42 * On frames with no GLES composition, the VirtualDisplaySurface dequeues a 43 * buffer directly from the sink IGraphicBufferProducer and passes it to HWC, 44 * bypassing the GLES driver. This is only guaranteed to work if 45 * eglSwapBuffers doesn't immediately dequeue a buffer for the next frame, 46 * since we can't rely on being able to dequeue more than one buffer at a time. 47 * 48 * This class also has a passthrough mode, where it doesn't use a 49 * BufferQueueInterposer and never sends buffers to HWC. Instead, OpenGL ES 50 * output buffers are queued directly to the virtual display sink; this class 51 * is inactive after construction. This mode is used when the HWC doesn't 52 * support compositing for virtual displays. 53 * 54 * TODO(jessehall): Add a libgui test that ensures that EGL/GLES do lazy 55 * dequeBuffers; we've wanted to require that for other reasons anyway. 56 */ 57class VirtualDisplaySurface : public DisplaySurface { 58public: 59 VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, 60 const sp<IGraphicBufferProducer>& sink, 61 const String8& name); 62 63 virtual sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; 64 65 virtual status_t compositionComplete(); 66 virtual status_t advanceFrame(); 67 virtual void onFrameCommitted(); 68 virtual void dump(String8& result) const; 69 70private: 71 virtual ~VirtualDisplaySurface(); 72 73 // immutable after construction 74 HWComposer& mHwc; 75 int32_t mDisplayId; 76 String8 mName; 77 78 // with HWC support, both of these point to the same object. 79 // otherwise, mInterposer is NULL and mSourceProducer is the sink. 80 sp<BufferQueueInterposer> mInterposer; 81 sp<IGraphicBufferProducer> mSourceProducer; 82 83 // mutable, must be synchronized with mMutex 84 Mutex mMutex; 85 sp<GraphicBuffer> mAcquiredBuffer; 86}; 87 88// --------------------------------------------------------------------------- 89} // namespace android 90// --------------------------------------------------------------------------- 91 92#endif // ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 93 94