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_RS_GRALLOC_CONSUMER_H 18#define ANDROID_RS_GRALLOC_CONSUMER_H 19 20#include <gui/ConsumerBase.h> 21 22#include <ui/GraphicBuffer.h> 23 24#include <utils/String8.h> 25#include <utils/Vector.h> 26#include <utils/threads.h> 27 28 29// --------------------------------------------------------------------------- 30namespace android { 31namespace renderscript { 32 33class Allocation; 34 35/** 36 * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU 37 * access to the underlying gralloc buffers provided by BufferQueue. Multiple 38 * buffers may be acquired by it at once, to be used concurrently by the 39 * CpuConsumer owner. Sets gralloc usage flags to be software-read-only. 40 * This queue is synchronous by default. 41 */ 42class GrallocConsumer : public ConsumerBase 43{ 44 public: 45 typedef ConsumerBase::FrameAvailableListener FrameAvailableListener; 46 47 GrallocConsumer(Allocation *, const sp<IGraphicBufferConsumer>& bq, int flags); 48 49 virtual ~GrallocConsumer(); 50 status_t lockNextBuffer(); 51 status_t unlockBuffer(); 52 53 private: 54 status_t releaseAcquiredBufferLocked(); 55 Allocation *mAlloc; 56 57 // Tracking for buffers acquired by the user 58 struct AcquiredBuffer { 59 // Need to track the original mSlot index and the buffer itself because 60 // the mSlot entry may be freed/reused before the acquired buffer is 61 // released. 62 int mSlot; 63 sp<GraphicBuffer> mGraphicBuffer; 64 void *mBufferPointer; 65 66 AcquiredBuffer() : 67 mSlot(BufferQueue::INVALID_BUFFER_SLOT), 68 mBufferPointer(nullptr) { 69 } 70 }; 71 AcquiredBuffer mAcquiredBuffer; 72}; 73 74} // namespace renderscript 75} // namespace android 76 77#endif // ANDROID_RS_GRALLOC_CONSUMER_H 78 79