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 #include <com_android_graphics_libgui_flags.h> 29 30 namespace android { 31 32 // ProducerListener is the interface through which the BufferQueue notifies the 33 // producer of events that the producer may wish to react to. Because the 34 // producer will generally have a mutex that is locked during calls from the 35 // producer to the BufferQueue, these calls from the BufferQueue to the 36 // producer *MUST* be called only when the BufferQueue mutex is NOT locked. 37 38 class ProducerListener : public virtual RefBase 39 { 40 public: ProducerListener()41 ProducerListener() {} 42 virtual ~ProducerListener(); 43 44 // onBufferReleased is called from IGraphicBufferConsumer::releaseBuffer to 45 // notify the producer that a new buffer is free and ready to be dequeued. 46 // 47 // This is called without any lock held and can be called concurrently by 48 // multiple threads. 49 virtual void onBufferReleased() = 0; // Asynchronous 50 virtual bool needsReleaseNotify() = 0; 51 // onBuffersFreed is called from IGraphicBufferConsumer::discardFreeBuffers 52 // to notify the producer that certain free buffers are discarded by the consumer. 53 virtual void onBuffersDiscarded(const std::vector<int32_t>& slots) = 0; // Asynchronous 54 // onBufferDetached is called from IGraphicBufferConsumer::detachBuffer to 55 // notify the producer that a buffer slot is free and ready to be dequeued. 56 // 57 // This is called without any lock held and can be called concurrently by 58 // multiple threads. onBufferDetached(int)59 virtual void onBufferDetached(int /*slot*/) {} // Asynchronous 60 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK) 61 // onBufferAttached is called from IGraphicBufferConsumer::attachBuffer to 62 // notify the producer that a buffer is attached. 63 // 64 // This is called without any lock held and can be called concurrently by 65 // multiple threads. This callback is enabled only when needsAttachNotify() 66 // returns {@code true}. onBufferAttached()67 virtual void onBufferAttached() {} // Asynchronous needsAttachNotify()68 virtual bool needsAttachNotify() { return false; } 69 #endif 70 }; 71 72 #ifndef NO_BINDER 73 class IProducerListener : public ProducerListener, public IInterface 74 { 75 public: 76 using HProducerListener1 = 77 ::android::hardware::graphics::bufferqueue::V1_0::IProducerListener; 78 using HProducerListener2 = 79 ::android::hardware::graphics::bufferqueue::V2_0::IProducerListener; 80 DECLARE_HYBRID_META_INTERFACE( 81 ProducerListener, 82 HProducerListener1, 83 HProducerListener2) 84 }; 85 86 class BnProducerListener : public BnInterface<IProducerListener> 87 { 88 public: 89 virtual status_t onTransact(uint32_t code, const Parcel& data, 90 Parcel* reply, uint32_t flags = 0); 91 virtual bool needsReleaseNotify(); 92 virtual void onBuffersDiscarded(const std::vector<int32_t>& slots); 93 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK) 94 virtual bool needsAttachNotify(); 95 #endif 96 }; 97 98 #else 99 class IProducerListener : public ProducerListener { 100 }; 101 class BnProducerListener : public IProducerListener { 102 }; 103 #endif 104 class StubProducerListener : public BnProducerListener { 105 public: 106 virtual ~StubProducerListener(); onBufferReleased()107 virtual void onBufferReleased() {} needsReleaseNotify()108 virtual bool needsReleaseNotify() { return false; } 109 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(BQ_CONSUMER_ATTACH_CALLBACK) needsAttachNotify()110 virtual bool needsAttachNotify() { return false; } 111 #endif 112 }; 113 114 } // namespace android 115 116 #endif 117