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_GUI_IPRODUCERLISTENER_H 18 #define ANDROID_GUI_IPRODUCERLISTENER_H 19 20 #include <vector> 21 22 #include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h> 23 #include <android/hardware/graphics/bufferqueue/2.0/IProducerListener.h> 24 #include <binder/IInterface.h> 25 #include <hidl/HybridInterface.h> 26 #include <utils/RefBase.h> 27 28 namespace android { 29 30 // ProducerListener is the interface through which the BufferQueue notifies the 31 // producer of events that the producer may wish to react to. Because the 32 // producer will generally have a mutex that is locked during calls from the 33 // producer to the BufferQueue, these calls from the BufferQueue to the 34 // producer *MUST* be called only when the BufferQueue mutex is NOT locked. 35 36 class ProducerListener : public virtual RefBase 37 { 38 public: ProducerListener()39 ProducerListener() {} 40 virtual ~ProducerListener(); 41 42 // onBufferReleased is called from IGraphicBufferConsumer::releaseBuffer to 43 // notify the producer that a new buffer is free and ready to be dequeued. 44 // 45 // This is called without any lock held and can be called concurrently by 46 // multiple threads. 47 virtual void onBufferReleased() = 0; // Asynchronous 48 virtual bool needsReleaseNotify() = 0; 49 // onBuffersFreed is called from IGraphicBufferConsumer::discardFreeBuffers 50 // to notify the producer that certain free buffers are discarded by the consumer. 51 virtual void onBuffersDiscarded(const std::vector<int32_t>& slots) = 0; // Asynchronous 52 }; 53 54 #ifndef NO_BINDER 55 class IProducerListener : public ProducerListener, public IInterface 56 { 57 public: 58 using HProducerListener1 = 59 ::android::hardware::graphics::bufferqueue::V1_0::IProducerListener; 60 using HProducerListener2 = 61 ::android::hardware::graphics::bufferqueue::V2_0::IProducerListener; 62 DECLARE_HYBRID_META_INTERFACE( 63 ProducerListener, 64 HProducerListener1, 65 HProducerListener2) 66 }; 67 68 class BnProducerListener : public BnInterface<IProducerListener> 69 { 70 public: 71 virtual status_t onTransact(uint32_t code, const Parcel& data, 72 Parcel* reply, uint32_t flags = 0); 73 virtual bool needsReleaseNotify(); 74 virtual void onBuffersDiscarded(const std::vector<int32_t>& slots); 75 }; 76 77 #else 78 class IProducerListener : public ProducerListener { 79 }; 80 class BnProducerListener : public IProducerListener { 81 }; 82 #endif 83 class DummyProducerListener : public BnProducerListener 84 { 85 public: 86 virtual ~DummyProducerListener(); onBufferReleased()87 virtual void onBufferReleased() {} needsReleaseNotify()88 virtual bool needsReleaseNotify() { return false; } 89 }; 90 91 } // namespace android 92 93 #endif 94