1ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams/* 2ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * Copyright (C) 2013 The Android Open Source Project 3ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * 4ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * Licensed under the Apache License, Version 2.0 (the "License"); 5ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * you may not use this file except in compliance with the License. 6ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * You may obtain a copy of the License at 7ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * 8ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * http://www.apache.org/licenses/LICENSE-2.0 9ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * 10ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * Unless required by applicable law or agreed to in writing, software 11ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * distributed under the License is distributed on an "AS IS" BASIS, 12ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * See the License for the specific language governing permissions and 14ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * limitations under the License. 15ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams */ 16ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 17ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#ifndef ANDROID_RS_GRALLOC_CONSUMER_H 18ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#define ANDROID_RS_GRALLOC_CONSUMER_H 19ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 20f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang#include "NdkImage.h" 21f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang#include "NdkImageReader.h" 22ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 23ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams// --------------------------------------------------------------------------- 24ddceab9a001f07a3395226c5e06e3b420720af0fJason Samsnamespace android { 25ddceab9a001f07a3395226c5e06e3b420720af0fJason Samsnamespace renderscript { 26ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 27ddceab9a001f07a3395226c5e06e3b420720af0fJason Samsclass Allocation; 28f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wangclass Context; 29ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 30ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams/** 31ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU 32ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * access to the underlying gralloc buffers provided by BufferQueue. Multiple 33ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * buffers may be acquired by it at once, to be used concurrently by the 34ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * CpuConsumer owner. Sets gralloc usage flags to be software-read-only. 35ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams * This queue is synchronous by default. 36ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams */ 37f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wangclass GrallocConsumer 38ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams{ 39ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams public: 40f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang GrallocConsumer(const Context *, Allocation *, uint32_t numAlloc); 41ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 42ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams virtual ~GrallocConsumer(); 43f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang ANativeWindow* getNativeWindow(); 44f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang media_status_t lockNextBuffer(uint32_t idx = 0); 45f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang media_status_t unlockBuffer(uint32_t idx = 0); 46754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang uint32_t getNextAvailableIdx(Allocation *a); 47754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang bool releaseIdx(uint32_t idx); 48f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang bool isActive(); 49754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang uint32_t mNumAlloc; 50754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang 51f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang static void onFrameAvailable(void* obj, AImageReader* reader); 52ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 53ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams private: 54f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang media_status_t releaseAcquiredBufferLocked(uint32_t idx); 55754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang // Boolean array to check if a position has been occupied or not. 56754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang bool *isIdxUsed; 57754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang Allocation **mAlloc; 58ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 59f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang const Context *mCtx; 60f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang AImageReader* mImgReader; 61f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang ANativeWindow* mNativeWindow; 62f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang AImageReader_ImageListener mReaderCb; 63ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams // Tracking for buffers acquired by the user 64ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams struct AcquiredBuffer { 65f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang AImage *mImg; 66f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang uint8_t *mBufferPointer; 67ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 68ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams AcquiredBuffer() : 69f750c530392a2895cb4b7e5b5e5e5259925b2015Miao Wang mImg(nullptr), 7044bef6fba6244292b751387f3d6c31cca96c28adChris Wailes mBufferPointer(nullptr) { 71ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams } 72ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams }; 73754746883bd46ec2fbdd23572cb6c90ab589346cMiao Wang AcquiredBuffer *mAcquiredBuffer; 74ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams}; 75ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 76ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams} // namespace renderscript 77ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams} // namespace android 78ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams 79ddceab9a001f07a3395226c5e06e3b420720af0fJason Sams#endif // ANDROID_RS_GRALLOC_CONSUMER_H 80