IConsumerListener.h revision 8dc55396fc9bc425b5e2c82e76a38080f2a655ff
1a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian/* 2a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Copyright (C) 2013 The Android Open Source Project 3a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 4a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * you may not use this file except in compliance with the License. 6a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * You may obtain a copy of the License at 7a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 8a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * 10a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * Unless required by applicable law or agreed to in writing, software 11a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * See the License for the specific language governing permissions and 14a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian * limitations under the License. 15a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian */ 16a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 17a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#ifndef ANDROID_GUI_ICONSUMERLISTENER_H 18a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#define ANDROID_GUI_ICONSUMERLISTENER_H 19a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 20a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <stdint.h> 21a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <sys/types.h> 22a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 23a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/Errors.h> 24a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <utils/RefBase.h> 25a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 26a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#include <binder/IInterface.h> 27a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 28a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopiannamespace android { 29a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// ---------------------------------------------------------------------------- 30a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 318dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stozaclass BufferItem; 328dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza 33a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// ConsumerListener is the interface through which the BufferQueue notifies 34a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// the consumer of events that the consumer may wish to react to. Because 35a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// the consumer will generally have a mutex that is locked during calls from 36a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// the consumer to the BufferQueue, these calls from the BufferQueue to the 37a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// consumer *MUST* be called only when the BufferQueue mutex is NOT locked. 38a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 39a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianclass ConsumerListener : public virtual RefBase { 40a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 41a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian ConsumerListener() { } 42a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian virtual ~ConsumerListener() { } 43a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 44a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // onFrameAvailable is called from queueBuffer each time an additional 45a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // frame becomes available for consumption. This means that frames that 46a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // are queued while in asynchronous mode only trigger the callback if no 47a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // previous frames are pending. Frames queued while in synchronous mode 488dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // always trigger the callback. The item passed to the callback will contain 498dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // all of the information about the queued frame except for its 508dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // GraphicBuffer pointer, which will always be null. 518dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // 528dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // This is called without any lock held and can be called concurrently 538dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // by multiple threads. 548dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza virtual void onFrameAvailable(const BufferItem& item) = 0; /* Asynchronous */ 558dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza 568dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // onFrameReplaced is called from queueBuffer if the frame being queued is 578dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // replacing an existing slot in the queue. Any call to queueBuffer that 588dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // doesn't call onFrameAvailable will call this callback instead. The item 598dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // passed to the callback will contain all of the information about the 608dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // queued frame except for its GraphicBuffer pointer, which will always be 618dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza // null. 62a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // 63a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // This is called without any lock held and can be called concurrently 64a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // by multiple threads. 658dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza virtual void onFrameReplaced(const BufferItem& item) {} /* Asynchronous */ 66a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 67a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // onBuffersReleased is called to notify the buffer consumer that the 68a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // BufferQueue has released its references to one or more GraphicBuffers 69a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // contained in its slots. The buffer consumer should then call 70a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // BufferQueue::getReleasedBuffers to retrieve the list of buffers 71a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // 72a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // This is called without any lock held and can be called concurrently 73a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian // by multiple threads. 74a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian virtual void onBuffersReleased() = 0; /* Asynchronous */ 75399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall 76399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall // onSidebandStreamChanged is called to notify the buffer consumer that the 77399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall // BufferQueue's sideband buffer stream has changed. This is called when a 78399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall // stream is first attached and when it is either detached or replaced by a 79399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall // different stream. 80399184a4cd728ea1421fb0bc1722274a29e38f4aJesse Hall virtual void onSidebandStreamChanged() = 0; /* Asynchronous */ 81a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 82a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 83a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 84a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianclass IConsumerListener : public ConsumerListener, public IInterface 85a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian{ 86a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 87a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian DECLARE_META_INTERFACE(ConsumerListener); 88a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 89a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 90a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// ---------------------------------------------------------------------------- 91a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 92a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianclass BnConsumerListener : public BnInterface<IConsumerListener> 93a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian{ 94a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopianpublic: 95a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian virtual status_t onTransact( uint32_t code, 96a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian const Parcel& data, 97a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian Parcel* reply, 98a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian uint32_t flags = 0); 99a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; 100a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 101a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian// ---------------------------------------------------------------------------- 102a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian}; // namespace android 103a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian 104a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian#endif // ANDROID_GUI_ICONSUMERLISTENER_H 105