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 // onFrameAvailable is called from queueBuffer each time an additional frame becomes available 47 // for consumption. This means that frames that are queued while in asynchronous mode only 48 // trigger the callback if no previous frames are pending. Frames queued while in synchronous 49 // mode always trigger the callback. The item passed to the callback will contain all of the 50 // information about the queued frame except for its GraphicBuffer pointer, which will always be 51 // null (except if the consumer is SurfaceFlinger). 52 // 53 // This is called without any lock held and can be called concurrently by multiple threads. 54 virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */ 55 56 // onFrameReplaced is called from queueBuffer if the frame being queued is replacing an existing 57 // slot in the queue. Any call to queueBuffer that doesn't call onFrameAvailable will call this 58 // callback instead. The item passed to the callback will contain all of the information about 59 // the queued frame except for its GraphicBuffer pointer, which will always be null. 60 // 61 // This is called without any lock held and can be called concurrently by multiple threads. onFrameReplaced(const BufferItem &)62 virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */ 63 64 // onBuffersReleased is called to notify the buffer consumer that the BufferQueue has released 65 // its references to one or more GraphicBuffers contained in its slots. The buffer consumer 66 // should then call BufferQueue::getReleasedBuffers to retrieve the list of buffers. 67 // 68 // This is called without any lock held and can be called concurrently by multiple threads. 69 virtual void onBuffersReleased() = 0; /* Asynchronous */ 70 71 // onSidebandStreamChanged is called to notify the buffer consumer that the BufferQueue's 72 // sideband buffer stream has changed. This is called when a stream is first attached and when 73 // it is either detached or replaced by a different stream. 74 virtual void onSidebandStreamChanged() = 0; /* Asynchronous */ 75 76 // Notifies the consumer of any new producer-side timestamps and returns the combined frame 77 // history that hasn't already been retrieved. 78 // 79 // WARNING: This method can only be called when the BufferQueue is in the consumer's process. addAndGetFrameTimestamps(const NewFrameEventsEntry *,FrameEventHistoryDelta *)80 virtual void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/, 81 FrameEventHistoryDelta* /*outDelta*/) {} 82 }; 83 84 class IConsumerListener : public ConsumerListener, public IInterface { 85 public: 86 DECLARE_META_INTERFACE(ConsumerListener) 87 }; 88 89 class BnConsumerListener : public SafeBnInterface<IConsumerListener> { 90 public: BnConsumerListener()91 BnConsumerListener() : SafeBnInterface<IConsumerListener>("BnConsumerListener") {} 92 93 status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, 94 uint32_t flags = 0) override; 95 }; 96 97 } // namespace android 98