blob: 0706e75660aea30b2f2f9197730636dff9bf830b [file] [log] [blame]
Jesse Hall99c7dbb2013-03-14 14:29:29 -07001/*
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 Hall80e0a392013-03-15 12:32:10 -070020#include "BufferQueueInterposer.h"
Jesse Hall99c7dbb2013-03-14 14:29:29 -070021#include "DisplaySurface.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25// ---------------------------------------------------------------------------
26
27class HWComposer;
28
Jesse Hall80e0a392013-03-15 12:32:10 -070029/* 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 Hallffe1f192013-03-22 15:13:48 -070048 * 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 Hall80e0a392013-03-15 12:32:10 -070054 * 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 Hall99c7dbb2013-03-14 14:29:29 -070057class VirtualDisplaySurface : public DisplaySurface {
58public:
Jesse Hallffe1f192013-03-22 15:13:48 -070059 VirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
Jesse Hall99c7dbb2013-03-14 14:29:29 -070060 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 Hall851cfe82013-03-20 13:44:00 -070067 virtual void onFrameCommitted();
Jesse Hall99c7dbb2013-03-14 14:29:29 -070068 virtual void dump(String8& result) const;
69
70private:
71 virtual ~VirtualDisplaySurface();
72
73 // immutable after construction
74 HWComposer& mHwc;
Jesse Hallffe1f192013-03-22 15:13:48 -070075 int32_t mDisplayId;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070076 String8 mName;
Jesse Hall80e0a392013-03-15 12:32:10 -070077
Jesse Hallffe1f192013-03-22 15:13:48 -070078 // 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 Hall80e0a392013-03-15 12:32:10 -070083 // mutable, must be synchronized with mMutex
84 Mutex mMutex;
85 sp<GraphicBuffer> mAcquiredBuffer;
Jesse Hall99c7dbb2013-03-14 14:29:29 -070086};
87
88// ---------------------------------------------------------------------------
89} // namespace android
90// ---------------------------------------------------------------------------
91
92#endif // ANDROID_SF_VIRTUAL_DISPLAY_SURFACE_H
93