Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 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 | |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 20 | #include "BufferQueueInterposer.h" |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 21 | #include "DisplaySurface.h" |
| 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | // --------------------------------------------------------------------------- |
| 26 | |
| 27 | class HWComposer; |
| 28 | |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 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 | * |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame^] | 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 | * |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 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 | */ |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 57 | class VirtualDisplaySurface : public DisplaySurface { |
| 58 | public: |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame^] | 59 | VirtualDisplaySurface(HWComposer& hwc, int32_t dispId, |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 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(); |
Jesse Hall | 851cfe8 | 2013-03-20 13:44:00 -0700 | [diff] [blame] | 67 | virtual void onFrameCommitted(); |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 68 | virtual void dump(String8& result) const; |
| 69 | |
| 70 | private: |
| 71 | virtual ~VirtualDisplaySurface(); |
| 72 | |
| 73 | // immutable after construction |
| 74 | HWComposer& mHwc; |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame^] | 75 | int32_t mDisplayId; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 76 | String8 mName; |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 77 | |
Jesse Hall | ffe1f19 | 2013-03-22 15:13:48 -0700 | [diff] [blame^] | 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 | |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame] | 83 | // mutable, must be synchronized with mMutex |
| 84 | Mutex mMutex; |
| 85 | sp<GraphicBuffer> mAcquiredBuffer; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | // --------------------------------------------------------------------------- |
| 89 | } // namespace android |
| 90 | // --------------------------------------------------------------------------- |
| 91 | |
| 92 | #endif // ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H |
| 93 | |