Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 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 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 24 | class IProducerListener; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 25 | class NativeHandle; |
| 26 | class SurfaceFlinger; |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 27 | class Layer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 28 | |
| 29 | // MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will |
| 30 | // be notified upon its destruction |
Kalle Raita | 643f094 | 2016-12-07 09:20:14 -0800 | [diff] [blame] | 31 | class MonitoredProducer : public BnGraphicBufferProducer { |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 32 | public: |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 33 | MonitoredProducer(const sp<IGraphicBufferProducer>& producer, |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 34 | const sp<SurfaceFlinger>& flinger, |
| 35 | const wp<Layer>& layer); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 36 | virtual ~MonitoredProducer(); |
| 37 | |
| 38 | // From IGraphicBufferProducer |
| 39 | virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf); |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame] | 40 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); |
| 41 | virtual status_t setAsyncMode(bool async); |
Ian Elliott | a2eb34c | 2017-07-18 11:05:49 -0600 | [diff] [blame^] | 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); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 45 | virtual status_t detachBuffer(int slot); |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 46 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 47 | sp<Fence>* outFence); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 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); |
Pablo Ceballos | 583b1b3 | 2015-09-03 18:23:52 -0700 | [diff] [blame] | 52 | virtual status_t cancelBuffer(int slot, const sp<Fence>& fence); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 53 | virtual int query(int what, int* value); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 54 | virtual status_t connect(const sp<IProducerListener>& token, int api, |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 55 | bool producerControlledByApp, QueueBufferOutput* output); |
Robert Carr | 97b9c86 | 2016-09-08 13:54:35 -0700 | [diff] [blame] | 56 | virtual status_t disconnect(int api, DisconnectMode mode); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 57 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream); |
Pablo Ceballos | 567dbbb | 2015-08-26 18:59:08 -0700 | [diff] [blame] | 58 | virtual void allocateBuffers(uint32_t width, uint32_t height, |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 59 | PixelFormat format, uint64_t usage); |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 60 | virtual status_t allowAllocation(bool allow); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 61 | virtual status_t setGenerationNumber(uint32_t generationNumber); |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 62 | virtual String8 getConsumerName() const override; |
Dan Stoza | 127fc63 | 2015-06-30 13:43:32 -0700 | [diff] [blame] | 63 | virtual status_t setDequeueTimeout(nsecs_t timeout) override; |
Dan Stoza | 50101d0 | 2016-04-07 16:53:23 -0700 | [diff] [blame] | 64 | virtual status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer, |
John Reck | 1a61da5 | 2016-04-28 13:18:15 -0700 | [diff] [blame] | 65 | sp<Fence>* outFence, float outTransformMatrix[16]) override; |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 66 | virtual IBinder* onAsBinder(); |
Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 67 | virtual status_t setSharedBufferMode(bool sharedBufferMode) override; |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 68 | virtual status_t setAutoRefresh(bool autoRefresh) override; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 69 | virtual void getFrameTimestamps(FrameEventHistoryDelta *outDelta) override; |
Pablo Ceballos | 8e3e92b | 2016-06-27 17:56:53 -0700 | [diff] [blame] | 70 | virtual status_t getUniqueId(uint64_t* outId) const override; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 71 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 72 | // The Layer which created this producer, and on which queued Buffer's will be displayed. |
| 73 | sp<Layer> getLayer() const; |
| 74 | |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 75 | private: |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 76 | sp<IGraphicBufferProducer> mProducer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 77 | sp<SurfaceFlinger> mFlinger; |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 78 | // The Layer which created this producer, and on which queued Buffer's will be displayed. |
| 79 | wp<Layer> mLayer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_MONITORED_PRODUCER_H |