2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_GUI_CPUCONSUMER_H
18 #define ANDROID_GUI_CPUCONSUMER_H
20 #include <gui/ConsumerBase.h>
22 #include <ui/GraphicBuffer.h>
24 #include <utils/String8.h>
25 #include <utils/Vector.h>
26 #include <utils/threads.h>
28 #define ANDROID_GRAPHICS_CPUCONSUMER_JNI_ID "mCpuConsumer"
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.
40 class CpuConsumer: public ConsumerBase
43 typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
58 // Create a new CPU consumer. The maxLockedBuffers parameter specifies
59 // how many buffers can be locked for user access at the same time.
60 CpuConsumer(uint32_t maxLockedBuffers);
62 // set the name of the CpuConsumer that will be used to identify it in
64 void setName(const String8& name);
66 // Gets the next graphics buffer from the producer and locks it for CPU use,
67 // filling out the passed-in locked buffer structure with the native pointer
68 // and metadata. Returns BAD_VALUE if no new buffer is available, and
69 // INVALID_OPERATION if the maximum number of buffers is already locked.
71 // Only a fixed number of buffers can be locked at a time, determined by the
72 // construction-time maxLockedBuffers parameter. If INVALID_OPERATION is
73 // returned by lockNextBuffer, then old buffers must be returned to the queue
74 // by calling unlockBuffer before more buffers can be acquired.
75 status_t lockNextBuffer(LockedBuffer *nativeBuffer);
77 // Returns a locked buffer to the queue, allowing it to be reused. Since
78 // only a fixed number of buffers may be locked at a time, old buffers must
79 // be released by calling unlockBuffer to ensure new buffers can be acquired by
81 status_t unlockBuffer(const LockedBuffer &nativeBuffer);
83 sp<ISurfaceTexture> getProducerInterface() const { return getBufferQueue(); }
86 // Maximum number of buffers that can be locked at a time
87 uint32_t mMaxLockedBuffers;
89 void freeBufferLocked(int slotIndex);
91 // Array for tracking pointers passed to the consumer, matching the
93 void *mBufferPointers[BufferQueue::NUM_BUFFER_SLOTS];
94 // Count of currently locked buffers
95 uint32_t mCurrentLockedBuffers;
99 } // namespace android
101 #endif // ANDROID_GUI_CPUCONSUMER_H