blob: ab676ccda21a9af22ef3c2a1152238c3a8e82b79 [file] [log] [blame]
Dan Stoza289ade12014-02-28 11:17:17 -08001/*
2 * Copyright 2014 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_GUI_BUFFERITEM_H
18#define ANDROID_GUI_BUFFERITEM_H
19
20#include <EGL/egl.h>
21#include <EGL/eglext.h>
22
Brian Anderson3d4039d2016-09-23 16:31:30 -070023#include <ui/FenceTime.h>
Dan Stoza289ade12014-02-28 11:17:17 -080024#include <ui/Rect.h>
Dan Stoza5065a552015-03-17 16:23:42 -070025#include <ui/Region.h>
Dan Stoza289ade12014-02-28 11:17:17 -080026
Dan Stoza1c87e472015-03-13 14:40:34 -070027#include <system/graphics.h>
28
Dan Stoza289ade12014-02-28 11:17:17 -080029#include <utils/Flattenable.h>
30#include <utils/StrongPointer.h>
31
32namespace android {
33
34class Fence;
35class GraphicBuffer;
36
37class BufferItem : public Flattenable<BufferItem> {
38 friend class Flattenable<BufferItem>;
39 size_t getPodSize() const;
40 size_t getFlattenedSize() const;
41 size_t getFdCount() const;
42 status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
43 status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
44
45 public:
46 // The default value of mBuf, used to indicate this doesn't correspond to a slot.
47 enum { INVALID_BUFFER_SLOT = -1 };
48 BufferItem();
Dan Stoza8dc55392014-11-04 11:37:46 -080049 ~BufferItem();
Colin Cross3175c092016-09-26 18:11:41 -070050 BufferItem(const BufferItem&) = default;
51 BufferItem& operator=(const BufferItem&) = default;
Dan Stoza289ade12014-02-28 11:17:17 -080052
53 static const char* scalingModeName(uint32_t scalingMode);
54
55 // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
56 // if the buffer in this slot has been acquired in the past (see
57 // BufferSlot.mAcquireCalled).
58 sp<GraphicBuffer> mGraphicBuffer;
59
60 // mFence is a fence that will signal when the buffer is idle.
61 sp<Fence> mFence;
62
Brian Anderson3d4039d2016-09-23 16:31:30 -070063 // The std::shared_ptr<FenceTime> wrapper around mFence.
64 std::shared_ptr<FenceTime> mFenceTime{FenceTime::NO_FENCE};
65
Dan Stoza289ade12014-02-28 11:17:17 -080066 // mCrop is the current crop rectangle for this buffer slot.
67 Rect mCrop;
68
69 // mTransform is the current transform flags for this buffer slot.
70 // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h>
71 uint32_t mTransform;
72
73 // mScalingMode is the current scaling mode for this buffer slot.
74 // refer to NATIVE_WINDOW_SCALING_* in <window.h>
75 uint32_t mScalingMode;
76
77 // mTimestamp is the current timestamp for this buffer slot. This gets
78 // to set by queueBuffer each time this slot is queued. This value
79 // is guaranteed to be monotonically increasing for each newly
80 // acquired buffer.
Colin Crossb1f30ba2016-09-30 17:24:06 -070081 int64_t mTimestamp;
Dan Stoza289ade12014-02-28 11:17:17 -080082
83 // mIsAutoTimestamp indicates whether mTimestamp was generated
84 // automatically when the buffer was queued.
85 bool mIsAutoTimestamp;
86
Eino-Ville Talvala82c6bcc2015-02-19 16:10:43 -080087 // mDataSpace is the current dataSpace value for this buffer slot. This gets
88 // set by queueBuffer each time this slot is queued. The meaning of the
89 // dataSpace is format-dependent.
90 android_dataspace mDataSpace;
91
Dan Stoza289ade12014-02-28 11:17:17 -080092 // mFrameNumber is the number of the queued frame for this slot.
Colin Crossb1f30ba2016-09-30 17:24:06 -070093 uint64_t mFrameNumber;
Dan Stoza289ade12014-02-28 11:17:17 -080094
Pablo Ceballos9d508ed2015-09-14 11:43:01 -070095 // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT).
96 int mSlot;
Dan Stoza289ade12014-02-28 11:17:17 -080097
98 // mIsDroppable whether this buffer was queued with the
99 // property that it can be replaced by a new buffer for the purpose of
100 // making sure dequeueBuffer() won't block.
101 // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
102 // was queued.
103 bool mIsDroppable;
104
105 // Indicates whether this buffer has been seen by a consumer yet
106 bool mAcquireCalled;
107
108 // Indicates this buffer must be transformed by the inverse transform of the screen
109 // it is displayed onto. This is applied after mTransform.
110 bool mTransformToDisplayInverse;
Dan Stoza5065a552015-03-17 16:23:42 -0700111
112 // Describes the portion of the surface that has been modified since the
113 // previous frame
114 Region mSurfaceDamage;
Pablo Ceballos06312182015-10-07 16:32:12 -0700115
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800116 // Indicates that the consumer should acquire the next frame as soon as it
117 // can and not wait for a frame to become available. This is only relevant
Pablo Ceballos2dcb3632016-03-17 15:50:23 -0700118 // in shared buffer mode.
Pablo Ceballosff95aab2016-01-13 17:09:58 -0800119 bool mAutoRefresh;
Pablo Ceballos06312182015-10-07 16:32:12 -0700120
Pablo Ceballos2dcb3632016-03-17 15:50:23 -0700121 // Indicates that this buffer was queued by the producer. When in shared
Pablo Ceballos06312182015-10-07 16:32:12 -0700122 // buffer mode acquire() can return a BufferItem that wasn't in the queue.
123 bool mQueuedBuffer;
Pablo Ceballos23b4abe2016-01-08 12:15:22 -0800124
125 // Indicates that this BufferItem contains a stale buffer which has already
126 // been released by the BufferQueue.
127 bool mIsStale;
Dan Stoza289ade12014-02-28 11:17:17 -0800128};
129
130} // namespace android
131
132#endif