1 /* 2 * Copyright (C) 2013 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 #pragma once 18 19 #include <binder/IInterface.h> 20 #include <binder/SafeInterface.h> 21 22 #include <utils/Errors.h> 23 #include <utils/RefBase.h> 24 25 #include <cstdint> 26 27 namespace android { 28 29 class BufferItem; 30 class FrameEventHistoryDelta; 31 struct NewFrameEventsEntry; 32 33 // ConsumerListener is the interface through which the BufferQueue notifies the consumer of events 34 // that the consumer may wish to react to. Because the consumer will generally have a mutex that is 35 // locked during calls from the consumer to the BufferQueue, these calls from the BufferQueue to the 36 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked. 37 38 class ConsumerListener : public virtual RefBase { 39 public: ConsumerListener()40 ConsumerListener() {} 41 virtual ~ConsumerListener(); 42 43 // onDisconnect is called when a producer disconnects from the BufferQueue. onDisconnect()44 virtual void onDisconnect() {} /* Asynchronous */ 45 46 // onFrameDequeued is called when a call to the BufferQueueProducer::dequeueBuffer successfully 47 // returns a slot from the BufferQueue. onFrameDequeued(const uint64_t)48 virtual void onFrameDequeued(const uint64_t) {} 49 50 // onFrameCancelled is called when the client calls cancelBuffer, thereby releasing the slot 51 // back to the BufferQueue. onFrameCancelled(const uint64_t)52 virtual void onFrameCancelled(const uint64_t) {} 53 54 // onFrameDetached is called after a successful detachBuffer() call while in asynchronous mode. onFrameDetached(const uint64_t)55 virtual void onFrameDetached(const uint64_t) {} 56 57 // onFrameAvailable is called from queueBuffer each time an additional frame becomes available 58 // for consumption. This means that frames that are queued while in asynchronous mode only 59 // trigger the callback if no previous frames are pending. Frames queued while in synchronous 60 // mode always trigger the callback. The item passed to the callback will contain all of the 61 // information about the queued frame except for its GraphicBuffer pointer, which will always be 62 // null (except if the consumer is SurfaceFlinger). 63 // 64 // This is called without any lock held and can be called concurrently by multiple threads. 65 virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */ 66 67 // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing 68 // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this 69 // callback instead. The item passed to the callback will contain all of the information about 70 // the queued frame except for its GraphicBuffer pointer, which will always be null. 71 // 72 // This is called without any lock held and can be called concurrently by multiple threads. onFrameReplaced(const BufferItem &)73 virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */ 74 75 // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released 76 // its references to one or more GraphicBuffers contained in its slots. The buffer consumer 77 // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers. 78 // 79 // This is called without any lock held and can be called concurrently by multiple threads. 80 virtual void onBuffersReleased() = 0; /* Asynchronous */ 81 82 // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's 83 // sideband buffer stream has changed. This is called when a stream is first attached and when 84 // it is either detached or replaced by a different stream. 85 virtual void onSidebandStreamChanged() = 0; /* Asynchronous */ 86 87 // Notifies the consumer of any new producer-side timestamps and returns the combined frame 88 // history that hasn't already been retrieved. 89 // 90 // WARNING: This method can only be called when the BufferQueue is in the consumer's process. addAndGetFrameTimestamps(const NewFrameEventsEntry *,FrameEventHistoryDelta *)91 virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/, 92 FrameEventHistoryDelta* /*outDelta*/) {} 93 }; 94 95 #ifndef NO_BINDER 96 class IConsumerListener : public ConsumerListener, public IInterface { 97 public: 98 DECLARE_META_INTERFACE(ConsumerListener) 99 }; 100 101 class BnConsumerListener : public SafeBnInterface<IConsumerListener> { 102 public: BnConsumerListener()103 BnConsumerListener() : SafeBnInterface<IConsumerListener>("BnConsumerListener") {} 104 105 status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, 106 uint32_t flags = 0) override; 107 }; 108 109 #else 110 class IConsumerListener : public ConsumerListener { 111 }; 112 class BnConsumerListener : public IConsumerListener { 113 }; 114 #endif 115 116 } // namespace android 117