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 | * |
| 48 | * TODO(jessehall): Add a libgui test that ensures that EGL/GLES do lazy |
| 49 | * dequeBuffers; we've wanted to require that for other reasons anyway. |
| 50 | */ |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 51 | class VirtualDisplaySurface : public DisplaySurface { |
| 52 | public: |
| 53 | VirtualDisplaySurface(HWComposer& hwc, int disp, |
| 54 | const sp<IGraphicBufferProducer>& sink, |
| 55 | const String8& name); |
| 56 | |
| 57 | virtual sp<IGraphicBufferProducer> getIGraphicBufferProducer() const; |
| 58 | |
| 59 | virtual status_t compositionComplete(); |
| 60 | virtual status_t advanceFrame(); |
| 61 | virtual status_t setReleaseFenceFd(int fenceFd); |
| 62 | virtual void dump(String8& result) const; |
| 63 | |
| 64 | private: |
| 65 | virtual ~VirtualDisplaySurface(); |
| 66 | |
| 67 | // immutable after construction |
| 68 | HWComposer& mHwc; |
| 69 | int mDisplayId; |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame^] | 70 | sp<BufferQueueInterposer> mSource; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 71 | String8 mName; |
Jesse Hall | 80e0a39 | 2013-03-15 12:32:10 -0700 | [diff] [blame^] | 72 | |
| 73 | // mutable, must be synchronized with mMutex |
| 74 | Mutex mMutex; |
| 75 | sp<GraphicBuffer> mAcquiredBuffer; |
| 76 | sp<Fence> mReleaseFence; |
Jesse Hall | 99c7dbb | 2013-03-14 14:29:29 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | // --------------------------------------------------------------------------- |
| 80 | } // namespace android |
| 81 | // --------------------------------------------------------------------------- |
| 82 | |
| 83 | #endif // ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H |
| 84 | |