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