1/* 2 * Copyright (C) 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 GRAPHIC_BUFFER_LISTENER_H_ 18#define GRAPHIC_BUFFER_LISTENER_H_ 19 20#include <gui/BufferQueue.h> 21 22namespace android { 23 24struct AMessage; 25 26struct GraphicBufferListener : public BufferQueue::ConsumerListener { 27public: 28 GraphicBufferListener() {}; 29 30 status_t init( 31 const sp<AMessage> ¬ify, 32 size_t bufferWidth, size_t bufferHeight, size_t bufferCount); 33 34 virtual void onFrameAvailable(const BufferItem& item); 35 virtual void onBuffersReleased(); 36 virtual void onSidebandStreamChanged(); 37 38 // Returns the handle to the producer side of the BufferQueue. Buffers 39 // queued on this will be received by GraphicBufferListener. 40 sp<IGraphicBufferProducer> getIGraphicBufferProducer() const { 41 return mProducer; 42 } 43 44 BufferItem getBufferItem(); 45 sp<GraphicBuffer> getBuffer(BufferItem item); 46 status_t releaseBuffer(BufferItem item); 47 48 enum { 49 kWhatFrameAvailable = 'frav', 50 }; 51 52private: 53 sp<AMessage> mNotify; 54 size_t mNumFramesAvailable; 55 56 mutable Mutex mMutex; 57 58 // Our BufferQueue interfaces. mProducer is passed to the producer through 59 // getIGraphicBufferProducer, and mConsumer is used internally to retrieve 60 // the buffers queued by the producer. 61 sp<IGraphicBufferProducer> mProducer; 62 sp<IGraphicBufferConsumer> mConsumer; 63 64 // Cache of GraphicBuffers from the buffer queue. 65 sp<GraphicBuffer> mBufferSlot[BufferQueue::NUM_BUFFER_SLOTS]; 66}; 67 68} // namespace android 69 70#endif // GRAPHIC_BUFFER_LISTENER_H 71