Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 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 | |
Colin Cross | 02eb109 | 2017-05-04 17:56:11 -0700 | [diff] [blame] | 20 | #include <media/NdkImage.h> |
| 21 | #include <media/NdkImageReader.h> |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 22 | |
| 23 | // --------------------------------------------------------------------------- |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | class Allocation; |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 28 | class Context; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU |
| 32 | * access to the underlying gralloc buffers provided by BufferQueue. Multiple |
| 33 | * buffers may be acquired by it at once, to be used concurrently by the |
| 34 | * CpuConsumer owner. Sets gralloc usage flags to be software-read-only. |
| 35 | * This queue is synchronous by default. |
| 36 | */ |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 37 | class GrallocConsumer |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 38 | { |
| 39 | public: |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 40 | GrallocConsumer(const Context *, Allocation *, uint32_t numAlloc); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 41 | |
| 42 | virtual ~GrallocConsumer(); |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 43 | ANativeWindow* getNativeWindow(); |
| 44 | media_status_t lockNextBuffer(uint32_t idx = 0); |
| 45 | media_status_t unlockBuffer(uint32_t idx = 0); |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 46 | uint32_t getNextAvailableIdx(Allocation *a); |
| 47 | bool releaseIdx(uint32_t idx); |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 48 | bool isActive(); |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 49 | uint32_t mNumAlloc; |
| 50 | |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 51 | static void onFrameAvailable(void* obj, AImageReader* reader); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 52 | |
| 53 | private: |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 54 | media_status_t releaseAcquiredBufferLocked(uint32_t idx); |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 55 | // Boolean array to check if a position has been occupied or not. |
| 56 | bool *isIdxUsed; |
| 57 | Allocation **mAlloc; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 58 | |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 59 | const Context *mCtx; |
| 60 | AImageReader* mImgReader; |
| 61 | ANativeWindow* mNativeWindow; |
| 62 | AImageReader_ImageListener mReaderCb; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 63 | // Tracking for buffers acquired by the user |
| 64 | struct AcquiredBuffer { |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 65 | AImage *mImg; |
| 66 | uint8_t *mBufferPointer; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 67 | |
| 68 | AcquiredBuffer() : |
Miao Wang | f750c53 | 2017-03-03 16:03:44 -0800 | [diff] [blame] | 69 | mImg(nullptr), |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 70 | mBufferPointer(nullptr) { |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 71 | } |
| 72 | }; |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 73 | AcquiredBuffer *mAcquiredBuffer; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace renderscript |
| 77 | } // namespace android |
| 78 | |
| 79 | #endif // ANDROID_RS_GRALLOC_CONSUMER_H |