blob: 48227b0f7764129ce6836d6e91635600a29a666e [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
Colin Cross02eb1092017-05-04 17:56:11 -070020#include <media/NdkImage.h>
21#include <media/NdkImageReader.h>
Jason Samsddceab92013-08-07 13:02:32 -070022
23// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
27class Allocation;
Miao Wangf750c532017-03-03 16:03:44 -080028class Context;
Jason Samsddceab92013-08-07 13:02:32 -070029
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 Wangf750c532017-03-03 16:03:44 -080037class GrallocConsumer
Jason Samsddceab92013-08-07 13:02:32 -070038{
39 public:
Miao Wangf750c532017-03-03 16:03:44 -080040 GrallocConsumer(const Context *, Allocation *, uint32_t numAlloc);
Jason Samsddceab92013-08-07 13:02:32 -070041
42 virtual ~GrallocConsumer();
Miao Wangf750c532017-03-03 16:03:44 -080043 ANativeWindow* getNativeWindow();
44 media_status_t lockNextBuffer(uint32_t idx = 0);
45 media_status_t unlockBuffer(uint32_t idx = 0);
Miao Wang75474682015-10-26 16:50:13 -070046 uint32_t getNextAvailableIdx(Allocation *a);
47 bool releaseIdx(uint32_t idx);
Miao Wangf750c532017-03-03 16:03:44 -080048 bool isActive();
Miao Wang75474682015-10-26 16:50:13 -070049 uint32_t mNumAlloc;
50
Miao Wangf750c532017-03-03 16:03:44 -080051 static void onFrameAvailable(void* obj, AImageReader* reader);
Jason Samsddceab92013-08-07 13:02:32 -070052
53 private:
Miao Wangf750c532017-03-03 16:03:44 -080054 media_status_t releaseAcquiredBufferLocked(uint32_t idx);
Miao Wang75474682015-10-26 16:50:13 -070055 // Boolean array to check if a position has been occupied or not.
56 bool *isIdxUsed;
57 Allocation **mAlloc;
Jason Samsddceab92013-08-07 13:02:32 -070058
Miao Wangf750c532017-03-03 16:03:44 -080059 const Context *mCtx;
60 AImageReader* mImgReader;
61 ANativeWindow* mNativeWindow;
62 AImageReader_ImageListener mReaderCb;
Jason Samsddceab92013-08-07 13:02:32 -070063 // Tracking for buffers acquired by the user
64 struct AcquiredBuffer {
Miao Wangf750c532017-03-03 16:03:44 -080065 AImage *mImg;
66 uint8_t *mBufferPointer;
Jason Samsddceab92013-08-07 13:02:32 -070067
68 AcquiredBuffer() :
Miao Wangf750c532017-03-03 16:03:44 -080069 mImg(nullptr),
Chris Wailes44bef6f2014-08-12 13:51:10 -070070 mBufferPointer(nullptr) {
Jason Samsddceab92013-08-07 13:02:32 -070071 }
72 };
Miao Wang75474682015-10-26 16:50:13 -070073 AcquiredBuffer *mAcquiredBuffer;
Jason Samsddceab92013-08-07 13:02:32 -070074};
75
76} // namespace renderscript
77} // namespace android
78
79#endif // ANDROID_RS_GRALLOC_CONSUMER_H