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