blob: ff7f0f0e8c962a924b51ab235e4804732a48b70c [file] [log] [blame]
Dan Stozab9b08832014-03-13 11:55:57 -07001/*
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
Dan Stozaf0eaf252014-03-21 13:05:51 -070024class IProducerListener;
Dan Stozab9b08832014-03-13 11:55:57 -070025class NativeHandle;
26class SurfaceFlinger;
Robert Carr1db73f62016-12-21 12:58:51 -080027class Layer;
Dan Stozab9b08832014-03-13 11:55:57 -070028
29// MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will
30// be notified upon its destruction
Kalle Raita643f0942016-12-07 09:20:14 -080031class MonitoredProducer : public BnGraphicBufferProducer {
Dan Stozab9b08832014-03-13 11:55:57 -070032public:
Dan Stozab3d0bdf2014-04-07 16:33:59 -070033 MonitoredProducer(const sp<IGraphicBufferProducer>& producer,
Robert Carr1db73f62016-12-21 12:58:51 -080034 const sp<SurfaceFlinger>& flinger,
35 const wp<Layer>& layer);
Dan Stozab9b08832014-03-13 11:55:57 -070036 virtual ~MonitoredProducer();
37
38 // From IGraphicBufferProducer
39 virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
Pablo Ceballosfa455352015-08-12 17:47:47 -070040 virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers);
41 virtual status_t setAsyncMode(bool async);
Ian Elliotta2eb34c2017-07-18 11:05:49 -060042 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);
Dan Stozab9b08832014-03-13 11:55:57 -070045 virtual status_t detachBuffer(int slot);
Dan Stozad9822a32014-03-28 15:25:31 -070046 virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer,
47 sp<Fence>* outFence);
Dan Stozab9b08832014-03-13 11:55:57 -070048 virtual status_t attachBuffer(int* outSlot,
49 const sp<GraphicBuffer>& buffer);
50 virtual status_t queueBuffer(int slot, const QueueBufferInput& input,
51 QueueBufferOutput* output);
Pablo Ceballos583b1b32015-09-03 18:23:52 -070052 virtual status_t cancelBuffer(int slot, const sp<Fence>& fence);
Dan Stozab9b08832014-03-13 11:55:57 -070053 virtual int query(int what, int* value);
Dan Stozaf0eaf252014-03-21 13:05:51 -070054 virtual status_t connect(const sp<IProducerListener>& token, int api,
Dan Stozab9b08832014-03-13 11:55:57 -070055 bool producerControlledByApp, QueueBufferOutput* output);
Robert Carr97b9c862016-09-08 13:54:35 -070056 virtual status_t disconnect(int api, DisconnectMode mode);
Dan Stozab9b08832014-03-13 11:55:57 -070057 virtual status_t setSidebandStream(const sp<NativeHandle>& stream);
Pablo Ceballos567dbbb2015-08-26 18:59:08 -070058 virtual void allocateBuffers(uint32_t width, uint32_t height,
Mathias Agopiancb496ac2017-05-22 14:21:00 -070059 PixelFormat format, uint64_t usage);
Dan Stoza9de72932015-04-16 17:28:43 -070060 virtual status_t allowAllocation(bool allow);
Dan Stoza812ed062015-06-02 15:45:22 -070061 virtual status_t setGenerationNumber(uint32_t generationNumber);
Dan Stozac6f30bd2015-06-08 09:32:50 -070062 virtual String8 getConsumerName() const override;
Dan Stoza127fc632015-06-30 13:43:32 -070063 virtual status_t setDequeueTimeout(nsecs_t timeout) override;
Dan Stoza50101d02016-04-07 16:53:23 -070064 virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
John Reck1a61da52016-04-28 13:18:15 -070065 sp<Fence>* outFence, float outTransformMatrix[16]) override;
Dan Stozab3d0bdf2014-04-07 16:33:59 -070066 virtual IBinder* onAsBinder();
Pablo Ceballos3559fbf2016-03-17 15:50:23 -070067 virtual status_t setSharedBufferMode(bool sharedBufferMode) override;
Pablo Ceballosff95aab2016-01-13 17:09:58 -080068 virtual status_t setAutoRefresh(bool autoRefresh) override;
Brian Anderson3890c392016-07-25 12:48:08 -070069 virtual void getFrameTimestamps(FrameEventHistoryDelta *outDelta) override;
Pablo Ceballos8e3e92b2016-06-27 17:56:53 -070070 virtual status_t getUniqueId(uint64_t* outId) const override;
Dan Stozab9b08832014-03-13 11:55:57 -070071
Robert Carr1db73f62016-12-21 12:58:51 -080072 // The Layer which created this producer, and on which queued Buffer's will be displayed.
73 sp<Layer> getLayer() const;
74
Dan Stozab9b08832014-03-13 11:55:57 -070075private:
Dan Stozab3d0bdf2014-04-07 16:33:59 -070076 sp<IGraphicBufferProducer> mProducer;
Dan Stozab9b08832014-03-13 11:55:57 -070077 sp<SurfaceFlinger> mFlinger;
Robert Carr1db73f62016-12-21 12:58:51 -080078 // The Layer which created this producer, and on which queued Buffer's will be displayed.
79 wp<Layer> mLayer;
Dan Stozab9b08832014-03-13 11:55:57 -070080};
81
82}; // namespace android
83
84#endif // ANDROID_MONITORED_PRODUCER_H