blob: d10710afe5cc307d32aa2fc92dbfb9fe9a37da98 [file] [log] [blame]
Jason Samsddceab92013-08-07 13:02:32 -07001/*
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 Agopian55891a72017-02-13 19:03:28 -080021#include <gui/BufferQueue.h>
Jason Samsddceab92013-08-07 13:02:32 -070022
23#include <ui/GraphicBuffer.h>
24
Jason Samsddceab92013-08-07 13:02:32 -070025
26// ---------------------------------------------------------------------------
27namespace android {
28namespace renderscript {
29
30class 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 */
39class GrallocConsumer : public ConsumerBase
40{
41 public:
42 typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
43
Miao Wang75474682015-10-26 16:50:13 -070044 GrallocConsumer(Allocation *, const sp<IGraphicBufferConsumer>& bq, int flags, uint32_t numAlloc);
Jason Samsddceab92013-08-07 13:02:32 -070045
46 virtual ~GrallocConsumer();
Miao Wang75474682015-10-26 16:50:13 -070047 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 Samsddceab92013-08-07 13:02:32 -070053
54 private:
Miao Wang75474682015-10-26 16:50:13 -070055 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 Samsddceab92013-08-07 13:02:32 -070059
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 Wailes44bef6f2014-08-12 13:51:10 -070071 mBufferPointer(nullptr) {
Jason Samsddceab92013-08-07 13:02:32 -070072 }
73 };
Miao Wang75474682015-10-26 16:50:13 -070074 AcquiredBuffer *mAcquiredBuffer;
Jason Samsddceab92013-08-07 13:02:32 -070075};
76
77} // namespace renderscript
78} // namespace android
79
80#endif // ANDROID_RS_GRALLOC_CONSUMER_H