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 
22 namespace android {
23 
24 class IProducerListener;
25 class NativeHandle;
26 class SurfaceFlinger;
27 
28 // MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will
29 // be notified upon its destruction
30 class MonitoredProducer : public IGraphicBufferProducer {
31 public:
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 setBufferCount(int bufferCount);
39     virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async,
40             uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
41     virtual status_t detachBuffer(int slot);
42     virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
43             sp<Fence>* outFence);
44     virtual status_t attachBuffer(int* outSlot,
45             const sp<GraphicBuffer>& buffer);
46     virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
47             QueueBufferOutput* output);
48     virtual void cancelBuffer(int slot, const sp<Fence>& fence);
49     virtual int query(int what, int* value);
50     virtual status_t connect(const sp<IProducerListener>& token, int api,
51             bool producerControlledByApp, QueueBufferOutput* output);
52     virtual status_t disconnect(int api);
53     virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
54     virtual void allocateBuffers(bool async, uint32_t width, uint32_t height,
55             uint32_t format, uint32_t usage);
56     virtual IBinder* onAsBinder();
57 
58 private:
59     sp<IGraphicBufferProducer> mProducer;
60     sp<SurfaceFlinger> mFlinger;
61 };
62 
63 }; // namespace android
64 
65 #endif // ANDROID_MONITORED_PRODUCER_H
66