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; |
| 27 | |
| 28 | // MonitoredProducer wraps an IGraphicBufferProducer so that SurfaceFlinger will |
| 29 | // be notified upon its destruction |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 30 | class MonitoredProducer : public IGraphicBufferProducer { |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 31 | public: |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 32 | MonitoredProducer(const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 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); |
Pablo Ceballos | fa45535 | 2015-08-12 17:47:47 -0700 | [diff] [blame^] | 39 | virtual status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers); |
| 40 | virtual status_t setAsyncMode(bool async); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 41 | virtual status_t dequeueBuffer(int* slot, sp<Fence>* fence, bool async, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 42 | uint32_t w, uint32_t h, PixelFormat format, uint32_t usage); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 43 | virtual status_t detachBuffer(int slot); |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 44 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 45 | sp<Fence>* outFence); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 46 | virtual status_t attachBuffer(int* outSlot, |
| 47 | const sp<GraphicBuffer>& buffer); |
| 48 | virtual status_t queueBuffer(int slot, const QueueBufferInput& input, |
| 49 | QueueBufferOutput* output); |
| 50 | virtual void cancelBuffer(int slot, const sp<Fence>& fence); |
| 51 | virtual int query(int what, int* value); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 52 | virtual status_t connect(const sp<IProducerListener>& token, int api, |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 53 | bool producerControlledByApp, QueueBufferOutput* output); |
| 54 | virtual status_t disconnect(int api); |
| 55 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream); |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame] | 56 | virtual void allocateBuffers(bool async, uint32_t width, uint32_t height, |
Dan Stoza | 3be1c6b | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 57 | PixelFormat format, uint32_t usage); |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 58 | virtual status_t allowAllocation(bool allow); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 59 | virtual status_t setGenerationNumber(uint32_t generationNumber); |
Dan Stoza | c6f30bd | 2015-06-08 09:32:50 -0700 | [diff] [blame] | 60 | virtual String8 getConsumerName() const override; |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 61 | virtual IBinder* onAsBinder(); |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
Dan Stoza | b3d0bdf | 2014-04-07 16:33:59 -0700 | [diff] [blame] | 64 | sp<IGraphicBufferProducer> mProducer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 65 | sp<SurfaceFlinger> mFlinger; |
| 66 | }; |
| 67 | |
| 68 | }; // namespace android |
| 69 | |
| 70 | #endif // ANDROID_MONITORED_PRODUCER_H |