1/*
2 * Copyright 2014 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_MONITORED_PRODUCER_H
18#define ANDROID_MONITORED_PRODUCER_H
19
20#include <gui/IGraphicBufferProducer.h>
21
22namespace android {
23
24class IProducerListener;
25class NativeHandle;
26class SurfaceFlinger;
27
28// MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will
29// be notified upon its destruction
30class MonitoredProducer : public IGraphicBufferProducer {
31public:
32    MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
33            const sp<SurfaceFlinger>& flinger);
34    virtual ~MonitoredProducer();
35
36    // From IGraphicBufferProducer
37    virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
38    virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers);
39    virtual status_t setAsyncMode(bool async);
40    virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w,
41            uint32_t h, PixelFormat format, uint32_t usage);
42    virtual status_t detachBuffer(int slot);
43    virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
44            sp<Fence>* outFence);
45    virtual status_t attachBuffer(int* outSlot,
46            const sp<GraphicBuffer>& buffer);
47    virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
48            QueueBufferOutput* output);
49    virtual status_t cancelBuffer(int slot, const sp<Fence>& fence);
50    virtual int query(int what, int* value);
51    virtual status_t connect(const sp<IProducerListener>& token, int api,
52            bool producerControlledByApp, QueueBufferOutput* output);
53    virtual status_t disconnect(int api);
54    virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
55    virtual void allocateBuffers(uint32_t width, uint32_t height,
56            PixelFormat format, uint32_t usage);
57    virtual status_t allowAllocation(bool allow);
58    virtual status_t setGenerationNumber(uint32_t generationNumber);
59    virtual String8 getConsumerName() const override;
60    virtual uint64_t getNextFrameNumber() const override;
61    virtual status_t setDequeueTimeout(nsecs_t timeout) override;
62    virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
63            sp<Fence>* outFence, float outTransformMatrix[16]) override;
64    virtual IBinder* onAsBinder();
65    virtual status_t setSharedBufferMode(bool sharedBufferMode) override;
66    virtual status_t setAutoRefresh(bool autoRefresh) override;
67    virtual status_t getUniqueId(uint64_t* outId) const override;
68
69private:
70    sp<IGraphicBufferProducer> mProducer;
71    sp<SurfaceFlinger> mFlinger;
72};
73
74}; // namespace android
75
76#endif // ANDROID_MONITORED_PRODUCER_H
77