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 #ifndef ANDROID_GUI_ICONSUMERLISTENER_H 18 #define ANDROID_GUI_ICONSUMERLISTENER_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <utils/Errors.h> 24 #include <utils/RefBase.h> 25 26 #include <binder/IInterface.h> 27 28 namespace android { 29 // ---------------------------------------------------------------------------- 30 31 class BufferItem; 32 33 // ConsumerListener is the interface through which the BufferQueue notifies 34 // the consumer of events that the consumer may wish to react to. Because 35 // the consumer will generally have a mutex that is locked during calls from 36 // the consumer to the BufferQueue, these calls from the BufferQueue to the 37 // consumer *MUST* be called only when the BufferQueue mutex is NOT locked. 38 39 class ConsumerListener : public virtual RefBase { 40 public: ConsumerListener()41 ConsumerListener() { } ~ConsumerListener()42 virtual ~ConsumerListener() { } 43 44 // onFrameAvailable is called from queueBuffer each time an additional 45 // frame becomes available for consumption. This means that frames that 46 // are queued while in asynchronous mode only trigger the callback if no 47 // previous frames are pending. Frames queued while in synchronous mode 48 // always trigger the callback. The item passed to the callback will contain 49 // all of the information about the queued frame except for its 50 // GraphicBuffer pointer, which will always be null. 51 // 52 // This is called without any lock held and can be called concurrently 53 // 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 57 // replacing an existing slot in the queue. Any call to queueBuffer that 58 // doesn't call onFrameAvailable will call this callback instead. The item 59 // passed to the callback will contain all of the information about the 60 // queued frame except for its GraphicBuffer pointer, which will always be 61 // null. 62 // 63 // This is called without any lock held and can be called concurrently 64 // by multiple threads. onFrameReplaced(const BufferItem &)65 virtual void onFrameReplaced(const BufferItem& /* item */) {} /* Asynchronous */ 66 67 // onBuffersReleased is called to notify the buffer consumer that the 68 // BufferQueue has released its references to one or more GraphicBuffers 69 // contained in its slots. The buffer consumer should then call 70 // BufferQueue::getReleasedBuffers to retrieve the list of buffers 71 // 72 // This is called without any lock held and can be called concurrently 73 // by multiple threads. 74 virtual void onBuffersReleased() = 0; /* Asynchronous */ 75 76 // onSidebandStreamChanged is called to notify the buffer consumer that the 77 // BufferQueue's sideband buffer stream has changed. This is called when a 78 // stream is first attached and when it is either detached or replaced by a 79 // different stream. 80 virtual void onSidebandStreamChanged() = 0; /* Asynchronous */ 81 }; 82 83 84 class IConsumerListener : public ConsumerListener, public IInterface 85 { 86 public: 87 DECLARE_META_INTERFACE(ConsumerListener); 88 }; 89 90 // ---------------------------------------------------------------------------- 91 92 class BnConsumerListener : public BnInterface<IConsumerListener> 93 { 94 public: 95 virtual status_t onTransact( uint32_t code, 96 const Parcel& data, 97 Parcel* reply, 98 uint32_t flags = 0); 99 }; 100 101 // ---------------------------------------------------------------------------- 102 }; // namespace android 103 104 #endif // ANDROID_GUI_ICONSUMERLISTENER_H 105