1/*
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 <gui/HdrMetadata.h>
21
22#include <ui/FenceTime.h>
23#include <ui/Rect.h>
24#include <ui/Region.h>
25
26#include <system/graphics.h>
27
28#include <utils/Flattenable.h>
29#include <utils/StrongPointer.h>
30
31namespace android {
32
33class Fence;
34class GraphicBuffer;
35
36class BufferItem : public Flattenable<BufferItem> {
37    friend class Flattenable<BufferItem>;
38    size_t getPodSize() const;
39    size_t getFlattenedSize() const;
40    size_t getFdCount() const;
41    status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
42    status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);
43
44    public:
45    // The default value of mBuf, used to indicate this doesn't correspond to a slot.
46    enum { INVALID_BUFFER_SLOT = -1 };
47    BufferItem();
48    ~BufferItem();
49    BufferItem(const BufferItem&) = default;
50    BufferItem& operator=(const BufferItem&) = default;
51
52    static const char* scalingModeName(uint32_t scalingMode);
53
54    // mGraphicBuffer points to the buffer allocated for this slot, or is NULL
55    // if the buffer in this slot has been acquired in the past (see
56    // BufferSlot.mAcquireCalled).
57    sp<GraphicBuffer> mGraphicBuffer;
58
59    // mFence is a fence that will signal when the buffer is idle.
60    sp<Fence> mFence;
61
62    // The std::shared_ptr<FenceTime> wrapper around mFence.
63    std::shared_ptr<FenceTime> mFenceTime{FenceTime::NO_FENCE};
64
65    // mCrop is the current crop rectangle for this buffer slot.
66    Rect mCrop;
67
68    // mTransform is the current transform flags for this buffer slot.
69    // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h>
70    uint32_t mTransform;
71
72    // mScalingMode is the current scaling mode for this buffer slot.
73    // refer to NATIVE_WINDOW_SCALING_* in <window.h>
74    uint32_t mScalingMode;
75
76    // mTimestamp is the current timestamp for this buffer slot. This gets
77    // to set by queueBuffer each time this slot is queued. This value
78    // is guaranteed to be monotonically increasing for each newly
79    // acquired buffer.
80    int64_t mTimestamp;
81
82    // mIsAutoTimestamp indicates whether mTimestamp was generated
83    // automatically when the buffer was queued.
84    bool mIsAutoTimestamp;
85
86    // mDataSpace is the current dataSpace value for this buffer slot. This gets
87    // set by queueBuffer each time this slot is queued. The meaning of the
88    // dataSpace is format-dependent.
89    android_dataspace mDataSpace;
90
91    // mHdrMetadata is the HDR metadata associated with this buffer slot.
92    HdrMetadata mHdrMetadata;
93
94    // mFrameNumber is the number of the queued frame for this slot.
95    uint64_t mFrameNumber;
96
97    // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT).
98    int mSlot;
99
100    // mIsDroppable whether this buffer was queued with the
101    // property that it can be replaced by a new buffer for the purpose of
102    // making sure dequeueBuffer() won't block.
103    // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer
104    // was queued.
105    bool mIsDroppable;
106
107    // Indicates whether this buffer has been seen by a consumer yet
108    bool mAcquireCalled;
109
110    // Indicates this buffer must be transformed by the inverse transform of the screen
111    // it is displayed onto. This is applied after mTransform.
112    bool mTransformToDisplayInverse;
113
114    // Describes the portion of the surface that has been modified since the
115    // previous frame
116    Region mSurfaceDamage;
117
118    // Indicates that the consumer should acquire the next frame as soon as it
119    // can and not wait for a frame to become available. This is only relevant
120    // in shared buffer mode.
121    bool mAutoRefresh;
122
123    // Indicates that this buffer was queued by the producer. When in shared
124    // buffer mode acquire() can return a BufferItem that wasn't in the queue.
125    bool mQueuedBuffer;
126
127    // Indicates that this BufferItem contains a stale buffer which has already
128    // been released by the BufferQueue.
129    bool mIsStale;
130
131    // Indicates the API (NATIVE_WINDOW_API_xxx) that queues the buffer.
132    int mApi;
133};
134
135} // namespace android
136
137#endif
138