xref: /aosp_15_r20/frameworks/native/include/gui/BufferItem.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_GUI_BUFFERITEM_H
18*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_GUI_BUFFERITEM_H
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker #include <optional>
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker #include <gui/HdrMetadata.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include <ui/FenceTime.h>
25*38e8c45fSAndroid Build Coastguard Worker #include <ui/PictureProfileHandle.h>
26*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rect.h>
27*38e8c45fSAndroid Build Coastguard Worker #include <ui/Region.h>
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker #include <system/graphics.h>
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker #include <utils/Flattenable.h>
32*38e8c45fSAndroid Build Coastguard Worker #include <utils/StrongPointer.h>
33*38e8c45fSAndroid Build Coastguard Worker 
34*38e8c45fSAndroid Build Coastguard Worker namespace android {
35*38e8c45fSAndroid Build Coastguard Worker 
36*38e8c45fSAndroid Build Coastguard Worker class Fence;
37*38e8c45fSAndroid Build Coastguard Worker class GraphicBuffer;
38*38e8c45fSAndroid Build Coastguard Worker 
39*38e8c45fSAndroid Build Coastguard Worker class BufferItem : public Flattenable<BufferItem> {
40*38e8c45fSAndroid Build Coastguard Worker     friend class Flattenable<BufferItem>;
41*38e8c45fSAndroid Build Coastguard Worker     size_t getPodSize() const;
42*38e8c45fSAndroid Build Coastguard Worker     size_t getFlattenedSize() const;
43*38e8c45fSAndroid Build Coastguard Worker     size_t getFdCount() const;
44*38e8c45fSAndroid Build Coastguard Worker     status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
45*38e8c45fSAndroid Build Coastguard Worker     status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
46*38e8c45fSAndroid Build Coastguard Worker 
47*38e8c45fSAndroid Build Coastguard Worker     public:
48*38e8c45fSAndroid Build Coastguard Worker     // The default value of mBuf, used to indicate this doesn't correspond to a slot.
49*38e8c45fSAndroid Build Coastguard Worker     enum { INVALID_BUFFER_SLOT = -1 };
50*38e8c45fSAndroid Build Coastguard Worker     BufferItem();
51*38e8c45fSAndroid Build Coastguard Worker     ~BufferItem();
52*38e8c45fSAndroid Build Coastguard Worker     BufferItem(const BufferItem&) = default;
53*38e8c45fSAndroid Build Coastguard Worker     BufferItem& operator=(const BufferItem&) = default;
54*38e8c45fSAndroid Build Coastguard Worker 
55*38e8c45fSAndroid Build Coastguard Worker     static const char* scalingModeName(uint32_t scalingMode);
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker     // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
58*38e8c45fSAndroid Build Coastguard Worker     // if the buffer in this slot has been acquired in the past (see
59*38e8c45fSAndroid Build Coastguard Worker     // BufferSlot.mAcquireCalled).
60*38e8c45fSAndroid Build Coastguard Worker     sp<GraphicBuffer> mGraphicBuffer;
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker     // mFence is a fence that will signal when the buffer is idle.
63*38e8c45fSAndroid Build Coastguard Worker     sp<Fence> mFence;
64*38e8c45fSAndroid Build Coastguard Worker 
65*38e8c45fSAndroid Build Coastguard Worker     // The std::shared_ptr<FenceTime> wrapper around mFence.
66*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<FenceTime> mFenceTime{FenceTime::NO_FENCE};
67*38e8c45fSAndroid Build Coastguard Worker 
68*38e8c45fSAndroid Build Coastguard Worker     // mCrop is the current crop rectangle for this buffer slot.
69*38e8c45fSAndroid Build Coastguard Worker     Rect mCrop;
70*38e8c45fSAndroid Build Coastguard Worker 
71*38e8c45fSAndroid Build Coastguard Worker     // mTransform is the current transform flags for this buffer slot.
72*38e8c45fSAndroid Build Coastguard Worker     // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h>
73*38e8c45fSAndroid Build Coastguard Worker     uint32_t mTransform;
74*38e8c45fSAndroid Build Coastguard Worker 
75*38e8c45fSAndroid Build Coastguard Worker     // mScalingMode is the current scaling mode for this buffer slot.
76*38e8c45fSAndroid Build Coastguard Worker     // refer to NATIVE_WINDOW_SCALING_* in <window.h>
77*38e8c45fSAndroid Build Coastguard Worker     uint32_t mScalingMode;
78*38e8c45fSAndroid Build Coastguard Worker 
79*38e8c45fSAndroid Build Coastguard Worker     // mTimestamp is the current timestamp for this buffer slot. This gets
80*38e8c45fSAndroid Build Coastguard Worker     // to set by queueBuffer each time this slot is queued. This value
81*38e8c45fSAndroid Build Coastguard Worker     // is guaranteed to be monotonically increasing for each newly
82*38e8c45fSAndroid Build Coastguard Worker     // acquired buffer.
83*38e8c45fSAndroid Build Coastguard Worker     int64_t mTimestamp;
84*38e8c45fSAndroid Build Coastguard Worker 
85*38e8c45fSAndroid Build Coastguard Worker     // mIsAutoTimestamp indicates whether mTimestamp was generated
86*38e8c45fSAndroid Build Coastguard Worker     // automatically when the buffer was queued.
87*38e8c45fSAndroid Build Coastguard Worker     bool mIsAutoTimestamp;
88*38e8c45fSAndroid Build Coastguard Worker 
89*38e8c45fSAndroid Build Coastguard Worker     // mDataSpace is the current dataSpace value for this buffer slot. This gets
90*38e8c45fSAndroid Build Coastguard Worker     // set by queueBuffer each time this slot is queued. The meaning of the
91*38e8c45fSAndroid Build Coastguard Worker     // dataSpace is format-dependent.
92*38e8c45fSAndroid Build Coastguard Worker     android_dataspace mDataSpace;
93*38e8c45fSAndroid Build Coastguard Worker 
94*38e8c45fSAndroid Build Coastguard Worker     // mHdrMetadata is the HDR metadata associated with this buffer slot.
95*38e8c45fSAndroid Build Coastguard Worker     HdrMetadata mHdrMetadata;
96*38e8c45fSAndroid Build Coastguard Worker 
97*38e8c45fSAndroid Build Coastguard Worker     // mPictureProfileHandle is a handle that points to a set of parameters that configure picture
98*38e8c45fSAndroid Build Coastguard Worker     // processing hardware to enhance the quality of buffer contents.
99*38e8c45fSAndroid Build Coastguard Worker     std::optional<PictureProfileHandle> mPictureProfileHandle;
100*38e8c45fSAndroid Build Coastguard Worker 
101*38e8c45fSAndroid Build Coastguard Worker     // mFrameNumber is the number of the queued frame for this slot.
102*38e8c45fSAndroid Build Coastguard Worker     uint64_t mFrameNumber;
103*38e8c45fSAndroid Build Coastguard Worker 
104*38e8c45fSAndroid Build Coastguard Worker     // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT).
105*38e8c45fSAndroid Build Coastguard Worker     int mSlot;
106*38e8c45fSAndroid Build Coastguard Worker 
107*38e8c45fSAndroid Build Coastguard Worker     // mIsDroppable whether this buffer was queued with the
108*38e8c45fSAndroid Build Coastguard Worker     // property that it can be replaced by a new buffer for the purpose of
109*38e8c45fSAndroid Build Coastguard Worker     // making sure dequeueBuffer() won't block.
110*38e8c45fSAndroid Build Coastguard Worker     // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
111*38e8c45fSAndroid Build Coastguard Worker     // was queued.
112*38e8c45fSAndroid Build Coastguard Worker     bool mIsDroppable;
113*38e8c45fSAndroid Build Coastguard Worker 
114*38e8c45fSAndroid Build Coastguard Worker     // Indicates whether this buffer has been seen by a consumer yet
115*38e8c45fSAndroid Build Coastguard Worker     bool mAcquireCalled;
116*38e8c45fSAndroid Build Coastguard Worker 
117*38e8c45fSAndroid Build Coastguard Worker     // Indicates this buffer must be transformed by the inverse transform of the screen
118*38e8c45fSAndroid Build Coastguard Worker     // it is displayed onto. This is applied after mTransform.
119*38e8c45fSAndroid Build Coastguard Worker     bool mTransformToDisplayInverse;
120*38e8c45fSAndroid Build Coastguard Worker 
121*38e8c45fSAndroid Build Coastguard Worker     // Describes the portion of the surface that has been modified since the
122*38e8c45fSAndroid Build Coastguard Worker     // previous frame
123*38e8c45fSAndroid Build Coastguard Worker     Region mSurfaceDamage;
124*38e8c45fSAndroid Build Coastguard Worker 
125*38e8c45fSAndroid Build Coastguard Worker     // Indicates that the consumer should acquire the next frame as soon as it
126*38e8c45fSAndroid Build Coastguard Worker     // can and not wait for a frame to become available. This is only relevant
127*38e8c45fSAndroid Build Coastguard Worker     // in shared buffer mode.
128*38e8c45fSAndroid Build Coastguard Worker     bool mAutoRefresh;
129*38e8c45fSAndroid Build Coastguard Worker 
130*38e8c45fSAndroid Build Coastguard Worker     // Indicates that this buffer was queued by the producer. When in shared
131*38e8c45fSAndroid Build Coastguard Worker     // buffer mode acquire() can return a BufferItem that wasn't in the queue.
132*38e8c45fSAndroid Build Coastguard Worker     bool mQueuedBuffer;
133*38e8c45fSAndroid Build Coastguard Worker 
134*38e8c45fSAndroid Build Coastguard Worker     // Indicates that this BufferItem contains a stale buffer which has already
135*38e8c45fSAndroid Build Coastguard Worker     // been released by the BufferQueue.
136*38e8c45fSAndroid Build Coastguard Worker     bool mIsStale;
137*38e8c45fSAndroid Build Coastguard Worker 
138*38e8c45fSAndroid Build Coastguard Worker     // Indicates the API (NATIVE_WINDOW_API_xxx) that queues the buffer.
139*38e8c45fSAndroid Build Coastguard Worker     int mApi;
140*38e8c45fSAndroid Build Coastguard Worker };
141*38e8c45fSAndroid Build Coastguard Worker 
142*38e8c45fSAndroid Build Coastguard Worker } // namespace android
143*38e8c45fSAndroid Build Coastguard Worker 
144*38e8c45fSAndroid Build Coastguard Worker #endif
145