1289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza/* 2289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Copyright 2014 The Android Open Source Project 3289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * 4289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Licensed under the Apache License, Version 2.0 (the "License"); 5289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * you may not use this file except in compliance with the License. 6289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * You may obtain a copy of the License at 7289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * 8289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * http://www.apache.org/licenses/LICENSE-2.0 9289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * 10289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * Unless required by applicable law or agreed to in writing, software 11289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * distributed under the License is distributed on an "AS IS" BASIS, 12289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * See the License for the specific language governing permissions and 14289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza * limitations under the License. 15289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza */ 16289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 17289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#ifndef ANDROID_GUI_BUFFERITEM_H 18289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#define ANDROID_GUI_BUFFERITEM_H 19289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 203d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson#include <ui/FenceTime.h> 21289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <ui/Rect.h> 225065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza#include <ui/Region.h> 23289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 241c87e474d87d6d1380fb61d476d606b1a2fda1c1Dan Stoza#include <system/graphics.h> 251c87e474d87d6d1380fb61d476d606b1a2fda1c1Dan Stoza 26289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/Flattenable.h> 27289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#include <utils/StrongPointer.h> 28289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 29289ade165e60b5f71734d30e535f16eb1f4313adDan Stozanamespace android { 30289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 31289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass Fence; 32289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass GraphicBuffer; 33289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 34289ade165e60b5f71734d30e535f16eb1f4313adDan Stozaclass BufferItem : public Flattenable<BufferItem> { 35289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza friend class Flattenable<BufferItem>; 36289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza size_t getPodSize() const; 37289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza size_t getFlattenedSize() const; 38289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza size_t getFdCount() const; 39289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; 40289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); 41289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 42289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza public: 43289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // The default value of mBuf, used to indicate this doesn't correspond to a slot. 44289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza enum { INVALID_BUFFER_SLOT = -1 }; 45289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza BufferItem(); 468dc55396fc9bc425b5e2c82e76a38080f2a655ffDan Stoza ~BufferItem(); 473175c094d782822f6b7aaf31a8593150b5c48b41Colin Cross BufferItem(const BufferItem&) = default; 483175c094d782822f6b7aaf31a8593150b5c48b41Colin Cross BufferItem& operator=(const BufferItem&) = default; 49289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 50289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza static const char* scalingModeName(uint32_t scalingMode); 51289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 52289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mGraphicBuffer points to the buffer allocated for this slot, or is NULL 53289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // if the buffer in this slot has been acquired in the past (see 54289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // BufferSlot.mAcquireCalled). 55289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza sp<GraphicBuffer> mGraphicBuffer; 56289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 57289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mFence is a fence that will signal when the buffer is idle. 58289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza sp<Fence> mFence; 59289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 603d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson // The std::shared_ptr<FenceTime> wrapper around mFence. 613d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson std::shared_ptr<FenceTime> mFenceTime{FenceTime::NO_FENCE}; 623d4039d7a291cd9b6f2dd4b46fcdb576f2db3356Brian Anderson 63289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mCrop is the current crop rectangle for this buffer slot. 64289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza Rect mCrop; 65289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 66289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mTransform is the current transform flags for this buffer slot. 67289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h> 68289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza uint32_t mTransform; 69289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 70289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mScalingMode is the current scaling mode for this buffer slot. 71289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // refer to NATIVE_WINDOW_SCALING_* in <window.h> 72289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza uint32_t mScalingMode; 73289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 74289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mTimestamp is the current timestamp for this buffer slot. This gets 75289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // to set by queueBuffer each time this slot is queued. This value 76289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // is guaranteed to be monotonically increasing for each newly 77289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // acquired buffer. 78b1f30bae12a0df810a62f819ab3ac680b00768b9Colin Cross int64_t mTimestamp; 79289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 80289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mIsAutoTimestamp indicates whether mTimestamp was generated 81289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // automatically when the buffer was queued. 82289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mIsAutoTimestamp; 83289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 8482c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // mDataSpace is the current dataSpace value for this buffer slot. This gets 8582c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // set by queueBuffer each time this slot is queued. The meaning of the 8682c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala // dataSpace is format-dependent. 8782c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala android_dataspace mDataSpace; 8882c6bcc9705eabcaf5b9e45bc81867b0e2d61a02Eino-Ville Talvala 89289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mFrameNumber is the number of the queued frame for this slot. 90b1f30bae12a0df810a62f819ab3ac680b00768b9Colin Cross uint64_t mFrameNumber; 91289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 929d508ed8a4e45371234548da48e626b82d60d370Pablo Ceballos // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). 939d508ed8a4e45371234548da48e626b82d60d370Pablo Ceballos int mSlot; 94289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 95289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // mIsDroppable whether this buffer was queued with the 96289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // property that it can be replaced by a new buffer for the purpose of 97289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // making sure dequeueBuffer() won't block. 98289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer 99289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // was queued. 100289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mIsDroppable; 101289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 102289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // Indicates whether this buffer has been seen by a consumer yet 103289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mAcquireCalled; 104289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 105289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // Indicates this buffer must be transformed by the inverse transform of the screen 106289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza // it is displayed onto. This is applied after mTransform. 107289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza bool mTransformToDisplayInverse; 1085065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza 1095065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza // Describes the portion of the surface that has been modified since the 1105065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza // previous frame 1115065a55291b67f584d7b0be3fa3cfc4e29a3cd1cDan Stoza Region mSurfaceDamage; 112063121849890da78b1ad7fb96c54c795de5d1fd6Pablo Ceballos 113ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos // Indicates that the consumer should acquire the next frame as soon as it 114ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos // can and not wait for a frame to become available. This is only relevant 1152dcb363c6e86b463a9f4e5925746e2f1089aef16Pablo Ceballos // in shared buffer mode. 116ff95aabbcc6e8606acbd7933c90eeb9b8b382a21Pablo Ceballos bool mAutoRefresh; 117063121849890da78b1ad7fb96c54c795de5d1fd6Pablo Ceballos 1182dcb363c6e86b463a9f4e5925746e2f1089aef16Pablo Ceballos // Indicates that this buffer was queued by the producer. When in shared 119063121849890da78b1ad7fb96c54c795de5d1fd6Pablo Ceballos // buffer mode acquire() can return a BufferItem that wasn't in the queue. 120063121849890da78b1ad7fb96c54c795de5d1fd6Pablo Ceballos bool mQueuedBuffer; 12123b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos 12223b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos // Indicates that this BufferItem contains a stale buffer which has already 12323b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos // been released by the BufferQueue. 12423b4abe024ea88c45e0b94c80e1fb537a573b143Pablo Ceballos bool mIsStale; 125289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza}; 126289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 127289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza} // namespace android 128289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza 129289ade165e60b5f71734d30e535f16eb1f4313adDan Stoza#endif 130