VirtualDisplaySurface.h revision ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0a
199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall/* 299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Copyright 2013 The Android Open Source Project 399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * 499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Licensed under the Apache License, Version 2.0 (the "License"); 599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * you may not use this file except in compliance with the License. 699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * You may obtain a copy of the License at 799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * 899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * http://www.apache.org/licenses/LICENSE-2.0 999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * 1099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * Unless required by applicable law or agreed to in writing, software 1199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * distributed under the License is distributed on an "AS IS" BASIS, 1299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * See the License for the specific language governing permissions and 1499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall * limitations under the License. 1599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall */ 1699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 1799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#ifndef ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 1899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#define ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 1999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 2080e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall#include "BufferQueueInterposer.h" 2199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#include "DisplaySurface.h" 2299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 2399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// --------------------------------------------------------------------------- 2499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallnamespace android { 2599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// --------------------------------------------------------------------------- 2699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 2799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallclass HWComposer; 2899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 2980e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall/* This DisplaySurface implementation uses a BufferQueueInterposer to pass 3080e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * partially- or fully-composited buffers from the OpenGL ES driver to 3180e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * HWComposer to use as the output buffer for virtual displays. Allowing HWC 3280e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * to compose into the same buffer that contains GLES results saves bandwidth 3380e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * compared to having two separate BufferQueues for frames with at least some 3480e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * GLES composition. 3580e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * 3680e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * The alternative would be to have two complete BufferQueues, one from GLES 3780e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * to HWC and one from HWC to the virtual display sink (e.g. video encoder). 3880e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * For GLES-only frames, the same bandwidth saving could be achieved if buffers 3980e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * could be acquired from the GLES->HWC queue and inserted into the HWC->sink 4080e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * queue. That would be complicated and doesn't help the mixed GLES+HWC case. 4180e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * 4280e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * On frames with no GLES composition, the VirtualDisplaySurface dequeues a 4380e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * buffer directly from the sink IGraphicBufferProducer and passes it to HWC, 4480e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * bypassing the GLES driver. This is only guaranteed to work if 4580e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * eglSwapBuffers doesn't immediately dequeue a buffer for the next frame, 4680e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * since we can't rely on being able to dequeue more than one buffer at a time. 4780e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * 48ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * This class also has a passthrough mode, where it doesn't use a 49ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * BufferQueueInterposer and never sends buffers to HWC. Instead, OpenGL ES 50ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * output buffers are queued directly to the virtual display sink; this class 51ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * is inactive after construction. This mode is used when the HWC doesn't 52ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * support compositing for virtual displays. 53ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall * 5480e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * TODO(jessehall): Add a libgui test that ensures that EGL/GLES do lazy 5580e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall * dequeBuffers; we've wanted to require that for other reasons anyway. 5680e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall */ 5799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallclass VirtualDisplaySurface : public DisplaySurface { 5899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallpublic: 59ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, 6099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall const sp<IGraphicBufferProducer>& sink, 6199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall const String8& name); 6299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 6399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall virtual sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; 6499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 6599c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall virtual status_t compositionComplete(); 6699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall virtual status_t advanceFrame(); 67851cfe834295224cd64bdd499872b95b19c4de8cJesse Hall virtual void onFrameCommitted(); 6899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall virtual void dump(String8& result) const; 6999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 7099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hallprivate: 7199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall virtual ~VirtualDisplaySurface(); 7299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 7399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall // immutable after construction 7499c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall HWComposer& mHwc; 75ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall int32_t mDisplayId; 7699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall String8 mName; 7780e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall 78ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall // with HWC support, both of these point to the same object. 79ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall // otherwise, mInterposer is NULL and mSourceProducer is the sink. 80ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall sp<BufferQueueInterposer> mInterposer; 81ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall sp<IGraphicBufferProducer> mSourceProducer; 82ffe1f19ca9707f84cb9fdb06209bf36cd8c2ef0aJesse Hall 8380e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall // mutable, must be synchronized with mMutex 8480e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall Mutex mMutex; 8580e0a397a4712666661ecc629a64ec26e7f6aac3Jesse Hall sp<GraphicBuffer> mAcquiredBuffer; 8699c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall}; 8799c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 8899c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// --------------------------------------------------------------------------- 8999c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall} // namespace android 9099c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall// --------------------------------------------------------------------------- 9199c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 9299c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall#endif // ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H 9399c7dbb24994df2f3e175f7b25dd2c9dd92a72f0Jesse Hall 94