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 | |
| 20 | #include <gui/ConsumerBase.h> |
Mathias Agopian | 55891a7 | 2017-02-13 19:03:28 -0800 | [diff] [blame] | 21 | #include <gui/BufferQueue.h> |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 22 | |
| 23 | #include <ui/GraphicBuffer.h> |
| 24 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 25 | |
| 26 | // --------------------------------------------------------------------------- |
| 27 | namespace android { |
| 28 | namespace renderscript { |
| 29 | |
| 30 | class Allocation; |
| 31 | |
| 32 | /** |
| 33 | * CpuConsumer is a BufferQueue consumer endpoint that allows direct CPU |
| 34 | * access to the underlying gralloc buffers provided by BufferQueue. Multiple |
| 35 | * buffers may be acquired by it at once, to be used concurrently by the |
| 36 | * CpuConsumer owner. Sets gralloc usage flags to be software-read-only. |
| 37 | * This queue is synchronous by default. |
| 38 | */ |
| 39 | class GrallocConsumer : public ConsumerBase |
| 40 | { |
| 41 | public: |
| 42 | typedef ConsumerBase::FrameAvailableListener FrameAvailableListener; |
| 43 | |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 44 | GrallocConsumer(Allocation *, const sp<IGraphicBufferConsumer>& bq, int flags, uint32_t numAlloc); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 45 | |
| 46 | virtual ~GrallocConsumer(); |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 47 | status_t lockNextBuffer(uint32_t idx = 0); |
| 48 | status_t unlockBuffer(uint32_t idx = 0); |
| 49 | uint32_t getNextAvailableIdx(Allocation *a); |
| 50 | bool releaseIdx(uint32_t idx); |
| 51 | uint32_t mNumAlloc; |
| 52 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 53 | |
| 54 | private: |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 55 | status_t releaseAcquiredBufferLocked(uint32_t idx); |
| 56 | // Boolean array to check if a position has been occupied or not. |
| 57 | bool *isIdxUsed; |
| 58 | Allocation **mAlloc; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 59 | |
| 60 | // Tracking for buffers acquired by the user |
| 61 | struct AcquiredBuffer { |
| 62 | // Need to track the original mSlot index and the buffer itself because |
| 63 | // the mSlot entry may be freed/reused before the acquired buffer is |
| 64 | // released. |
| 65 | int mSlot; |
| 66 | sp<GraphicBuffer> mGraphicBuffer; |
| 67 | void *mBufferPointer; |
| 68 | |
| 69 | AcquiredBuffer() : |
| 70 | mSlot(BufferQueue::INVALID_BUFFER_SLOT), |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 71 | mBufferPointer(nullptr) { |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 72 | } |
| 73 | }; |
Miao Wang | 7547468 | 2015-10-26 16:50:13 -0700 | [diff] [blame] | 74 | AcquiredBuffer *mAcquiredBuffer; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // namespace renderscript |
| 78 | } // namespace android |
| 79 | |
| 80 | #endif // ANDROID_RS_GRALLOC_CONSUMER_H |