• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class Layer;
28 
29 // MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will
30 // be notified upon its destruction
31 class MonitoredProducer : public BnGraphicBufferProducer {
32 public:
33     MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
34             const sp<SurfaceFlinger>& flinger,
35             const wp<Layer>& layer);
36     virtual ~MonitoredProducer();
37 
38     // From IGraphicBufferProducer
39     virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
40     virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers);
41     virtual status_t setAsyncMode(bool async);
42     virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
43                                    PixelFormat format, uint64_t usage, uint64_t* outBufferAge,
44                                    FrameEventHistoryDelta* outTimestamps);
45     virtual status_t detachBuffer(int slot);
46     virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
47             sp<Fence>* outFence);
48     virtual status_t attachBuffer(int* outSlot,
49             const sp<GraphicBuffer>& buffer);
50     virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
51             QueueBufferOutput* output);
52     virtual status_t cancelBuffer(int slot, const sp<Fence>& fence);
53     virtual int query(int what, int* value);
54     virtual status_t connect(const sp<IProducerListener>& token, int api,
55             bool producerControlledByApp, QueueBufferOutput* output);
56     virtual status_t disconnect(int api, DisconnectMode mode);
57     virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
58     virtual void allocateBuffers(uint32_t width, uint32_t height,
59             PixelFormat format, uint64_t usage);
60     virtual status_t allowAllocation(bool allow);
61     virtual status_t setGenerationNumber(uint32_t generationNumber);
62     virtual String8 getConsumerName() const override;
63     virtual status_t setDequeueTimeout(nsecs_t timeout) override;
64     virtual status_t setLegacyBufferDrop(bool drop) override;
65     virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
66             sp<Fence>* outFence, float outTransformMatrix[16]) override;
67     virtual IBinder* onAsBinder();
68     virtual status_t setSharedBufferMode(bool sharedBufferMode) override;
69     virtual status_t setAutoRefresh(bool autoRefresh) override;
70     virtual void getFrameTimestamps(FrameEventHistoryDelta *outDelta) override;
71     virtual status_t getUniqueId(uint64_t* outId) const override;
72     virtual status_t getConsumerUsage(uint64_t* outUsage) const override;
73 
74     // The Layer which created this producer, and on which queued Buffer's will be displayed.
75     sp<Layer> getLayer() const;
76 
77 private:
78     sp<IGraphicBufferProducer> mProducer;
79     sp<SurfaceFlinger> mFlinger;
80     // The Layer which created this producer, and on which queued Buffer's will be displayed.
81     wp<Layer> mLayer;
82 };
83 
84 }; // namespace android
85 
86 #endif // ANDROID_MONITORED_PRODUCER_H
87