1289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza/*
2289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Copyright 2014 The Android Open Source Project
3289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
4289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Licensed under the Apache License, Version 2.0 (the "License");
5289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * you may not use this file except in compliance with the License.
6289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * You may obtain a copy of the License at
7289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
8289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *      http://www.apache.org/licenses/LICENSE-2.0
9289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza *
10289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Unless required by applicable law or agreed to in writing, software
11289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * distributed under the License is distributed on an "AS IS" BASIS,
12289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * See the License for the specific language governing permissions and
14289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * limitations under the License.
15289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza */
16289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
17289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#ifndef ANDROID_GUI_BUFFERSLOT_H
18289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ANDROID_GUI_BUFFERSLOT_H
19289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
20289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <ui/Fence.h>
21289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <ui/GraphicBuffer.h>
22289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
23289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <EGL/egl.h>
24289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <EGL/eglext.h>
25289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
26289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/StrongPointer.h>
27289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
28289ade165e60b5f71734d30e535f16eb1f4313adDan Stozanamespace android {
29289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
30289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass Fence;
31289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
32ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos// BufferState tracks the states in which a buffer slot can be.
33ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballosstruct BufferState {
34ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
35ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // All slots are initially FREE (not dequeued, queued, acquired, or shared).
36ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    BufferState()
37ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    : mDequeueCount(0),
38ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos      mQueueCount(0),
39ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos      mAcquireCount(0),
40ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos      mShared(false) {
41ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
42ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
43ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    uint32_t mDequeueCount;
44ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    uint32_t mQueueCount;
45ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    uint32_t mAcquireCount;
46ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    bool mShared;
47ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
48ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // A buffer can be in one of five states, represented as below:
49ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
50ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //         | mShared | mDequeueCount | mQueueCount | mAcquireCount |
51ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // --------|---------|---------------|-------------|---------------|
52ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // FREE    |  false  |       0       |      0      |       0       |
53ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // DEQUEUED|  false  |       1       |      0      |       0       |
54ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // QUEUED  |  false  |       0       |      1      |       0       |
55ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // ACQUIRED|  false  |       0       |      0      |       1       |
56ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // SHARED  |  true   |      any      |     any     |      any      |
57ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
58ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // FREE indicates that the buffer is available to be dequeued by the
59ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // producer. The slot is "owned" by BufferQueue. It transitions to DEQUEUED
60ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // when dequeueBuffer is called.
61ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
62ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // DEQUEUED indicates that the buffer has been dequeued by the producer, but
63ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // has not yet been queued or canceled. The producer may modify the
64ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // buffer's contents as soon as the associated release fence is signaled.
65ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // The slot is "owned" by the producer. It can transition to QUEUED (via
66ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // queueBuffer or attachBuffer) or back to FREE (via cancelBuffer or
67ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // detachBuffer).
68ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
69ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // QUEUED indicates that the buffer has been filled by the producer and
70ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // queued for use by the consumer. The buffer contents may continue to be
71ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // modified for a finite time, so the contents must not be accessed until
72ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // the associated fence is signaled. The slot is "owned" by BufferQueue. It
73ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // can transition to ACQUIRED (via acquireBuffer) or to FREE (if another
74ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // buffer is queued in asynchronous mode).
75ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
76ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // ACQUIRED indicates that the buffer has been acquired by the consumer. As
77ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // with QUEUED, the contents must not be accessed by the consumer until the
78ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // acquire fence is signaled. The slot is "owned" by the consumer. It
79ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // transitions to FREE when releaseBuffer (or detachBuffer) is called. A
80ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // detached buffer can also enter the ACQUIRED state via attachBuffer.
81ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    //
823559fbf93801e2c0d9d8fb246fb9b867a361b464Pablo Ceballos    // SHARED indicates that this buffer is being used in shared buffer
83ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // mode. It can be in any combination of the other states at the same time,
84ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // except for FREE (since that excludes being in any other state). It can
85ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    // also be dequeued, queued, or acquired multiple times.
86ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
87ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline bool isFree() const {
88ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        return !isAcquired() && !isDequeued() && !isQueued();
89ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
90ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
91ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline bool isDequeued() const {
92ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        return mDequeueCount > 0;
93ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
94ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
95ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline bool isQueued() const {
96ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        return mQueueCount > 0;
97ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
98ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
99ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline bool isAcquired() const {
100ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        return mAcquireCount > 0;
101ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
102ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
103ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline bool isShared() const {
104ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        return mShared;
105ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
106ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
107ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void reset() {
108ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        *this = BufferState();
109ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
110ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
111ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    const char* string() const;
112ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
113ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void dequeue() {
114ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mDequeueCount++;
115ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
116ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
117ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void detachProducer() {
118ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mDequeueCount > 0) {
119ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mDequeueCount--;
120ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
121ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
122ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
123ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void attachProducer() {
124ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mDequeueCount++;
125ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
126ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
127ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void queue() {
128ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mDequeueCount > 0) {
129ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mDequeueCount--;
130ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
131ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mQueueCount++;
132ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
133ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
134ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void cancel() {
135ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mDequeueCount > 0) {
136ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mDequeueCount--;
137ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
138ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
139ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
140ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void freeQueued() {
141ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mQueueCount > 0) {
142ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mQueueCount--;
143ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
144ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
145ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
146ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void acquire() {
147ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mQueueCount > 0) {
148ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mQueueCount--;
149ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
150ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mAcquireCount++;
151ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
152ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
153ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void acquireNotInQueue() {
154ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mAcquireCount++;
155ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
156ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
157ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void release() {
158ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mAcquireCount > 0) {
159ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mAcquireCount--;
160ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
161ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
162ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
163ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void detachConsumer() {
164ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        if (mAcquireCount > 0) {
165ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos            mAcquireCount--;
166ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        }
167ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
168ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
169ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    inline void attachConsumer() {
170ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos        mAcquireCount++;
171ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos    }
172ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos};
173ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos
174289ade165e60b5f71734d30e535f16eb1f4313adDan Stozastruct BufferSlot {
175289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
176289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    BufferSlot()
17723b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    : mGraphicBuffer(nullptr),
17823b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos      mEglDisplay(EGL_NO_DISPLAY),
179ccdfd60d79a8b7f1ed6401d0f2e8e29166a10584Pablo Ceballos      mBufferState(),
180289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza      mRequestBufferCalled(false),
181289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza      mFrameNumber(0),
182289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza      mEglFence(EGL_NO_SYNC_KHR),
18323b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos      mFence(Fence::NO_FENCE),
184289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza      mAcquireCalled(false),
18523b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos      mNeedsReallocation(false) {
186289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    }
187289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
188289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mGraphicBuffer points to the buffer allocated for this slot or is NULL
189289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // if no buffer has been allocated.
190289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    sp<GraphicBuffer> mGraphicBuffer;
191289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
192289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mEglDisplay is the EGLDisplay used to create EGLSyncKHR objects.
193289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    EGLDisplay mEglDisplay;
194289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
195289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mBufferState is the current state of this buffer slot.
196289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    BufferState mBufferState;
197289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
198289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mRequestBufferCalled is used for validating that the producer did
199289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // call requestBuffer() when told to do so. Technically this is not
200289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // needed but useful for debugging and catching producer bugs.
201289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mRequestBufferCalled;
202289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
203289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mFrameNumber is the number of the queued frame for this slot.  This
204289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // is used to dequeue buffers in LRU order (useful because buffers
205289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // may be released before their release fence is signaled).
206289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    uint64_t mFrameNumber;
207289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
208289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mEglFence is the EGL sync object that must signal before the buffer
209289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // associated with this buffer slot may be dequeued. It is initialized
210289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // to EGL_NO_SYNC_KHR when the buffer is created and may be set to a
211289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // new sync object in releaseBuffer.  (This is deprecated in favor of
212289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mFence, below.)
213289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    EGLSyncKHR mEglFence;
214289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
215289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // mFence is a fence which will signal when work initiated by the
216289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // previous owner of the buffer is finished. When the buffer is FREE,
217289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // the fence indicates when the consumer has finished reading
218289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // from the buffer, or when the producer has finished writing if it
219289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // called cancelBuffer after queueing some writes. When the buffer is
220289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // QUEUED, it indicates when the producer has finished filling the
221289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // buffer. When the buffer is DEQUEUED or ACQUIRED, the fence has been
222289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // passed to the consumer or producer along with ownership of the
223289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // buffer, and mFence is set to NO_FENCE.
224289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    sp<Fence> mFence;
225289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
226289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    // Indicates whether this buffer has been seen by a consumer yet
227289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza    bool mAcquireCalled;
228289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
22923b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // Indicates whether the buffer was re-allocated without notifying the
23023b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // producer. If so, it needs to set the BUFFER_NEEDS_REALLOCATION flag when
23123b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    // dequeued to prevent the producer from using a stale cached buffer.
23223b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos    bool mNeedsReallocation;
233289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza};
234289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
235289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android
236289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza
237289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif
238