| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 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 <EGL/egl.h> | 
 | 21 | #include <EGL/eglext.h> | 
 | 22 |  | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 23 | #include <ui/Rect.h> | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 24 | #include <ui/Region.h> | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 25 |  | 
| Dan Stoza | 1c87e47 | 2015-03-13 14:40:34 -0700 | [diff] [blame] | 26 | #include <system/graphics.h> | 
 | 27 |  | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 28 | #include <utils/Flattenable.h> | 
 | 29 | #include <utils/StrongPointer.h> | 
 | 30 |  | 
 | 31 | namespace android { | 
 | 32 |  | 
 | 33 | class Fence; | 
 | 34 | class GraphicBuffer; | 
 | 35 |  | 
 | 36 | class 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(); | 
| Dan Stoza | 8dc5539 | 2014-11-04 11:37:46 -0800 | [diff] [blame] | 48 |     ~BufferItem(); | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 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 |     // mCrop is the current crop rectangle for this buffer slot. | 
 | 61 |     Rect mCrop; | 
 | 62 |  | 
 | 63 |     // mTransform is the current transform flags for this buffer slot. | 
 | 64 |     // refer to NATIVE_WINDOW_TRANSFORM_* in <window.h> | 
 | 65 |     uint32_t mTransform; | 
 | 66 |  | 
 | 67 |     // mScalingMode is the current scaling mode for this buffer slot. | 
 | 68 |     // refer to NATIVE_WINDOW_SCALING_* in <window.h> | 
 | 69 |     uint32_t mScalingMode; | 
 | 70 |  | 
 | 71 |     // mTimestamp is the current timestamp for this buffer slot. This gets | 
 | 72 |     // to set by queueBuffer each time this slot is queued. This value | 
 | 73 |     // is guaranteed to be monotonically increasing for each newly | 
 | 74 |     // acquired buffer. | 
| Chong Zhang | 47f674d | 2015-05-22 10:54:25 -0700 | [diff] [blame] | 75 |     union { | 
 | 76 |         int64_t mTimestamp; | 
 | 77 |         struct { | 
 | 78 |             uint32_t mTimestampLo; | 
 | 79 |             uint32_t mTimestampHi; | 
 | 80 |         }; | 
 | 81 |     }; | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 82 |  | 
 | 83 |     // mIsAutoTimestamp indicates whether mTimestamp was generated | 
 | 84 |     // automatically when the buffer was queued. | 
 | 85 |     bool mIsAutoTimestamp; | 
 | 86 |  | 
| Eino-Ville Talvala | 82c6bcc | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 87 |     // mDataSpace is the current dataSpace value for this buffer slot. This gets | 
 | 88 |     // set by queueBuffer each time this slot is queued. The meaning of the | 
 | 89 |     // dataSpace is format-dependent. | 
 | 90 |     android_dataspace mDataSpace; | 
 | 91 |  | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 92 |     // mFrameNumber is the number of the queued frame for this slot. | 
| Chong Zhang | 47f674d | 2015-05-22 10:54:25 -0700 | [diff] [blame] | 93 |     union { | 
 | 94 |         uint64_t mFrameNumber; | 
 | 95 |         struct { | 
 | 96 |             uint32_t mFrameNumberLo; | 
 | 97 |             uint32_t mFrameNumberHi; | 
 | 98 |         }; | 
 | 99 |     }; | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 100 |  | 
| Pablo Ceballos | 9d508ed | 2015-09-14 11:43:01 -0700 | [diff] [blame] | 101 |     // mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT). | 
 | 102 |     int mSlot; | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 103 |  | 
 | 104 |     // mIsDroppable whether this buffer was queued with the | 
 | 105 |     // property that it can be replaced by a new buffer for the purpose of | 
 | 106 |     // making sure dequeueBuffer() won't block. | 
 | 107 |     // i.e.: was the BufferQueue in "mDequeueBufferCannotBlock" when this buffer | 
 | 108 |     // was queued. | 
 | 109 |     bool mIsDroppable; | 
 | 110 |  | 
 | 111 |     // Indicates whether this buffer has been seen by a consumer yet | 
 | 112 |     bool mAcquireCalled; | 
 | 113 |  | 
 | 114 |     // Indicates this buffer must be transformed by the inverse transform of the screen | 
 | 115 |     // it is displayed onto. This is applied after mTransform. | 
 | 116 |     bool mTransformToDisplayInverse; | 
| Dan Stoza | 5065a55 | 2015-03-17 16:23:42 -0700 | [diff] [blame] | 117 |  | 
 | 118 |     // Describes the portion of the surface that has been modified since the | 
 | 119 |     // previous frame | 
 | 120 |     Region mSurfaceDamage; | 
| Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 121 |  | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 122 |     // Indicates that the consumer should acquire the next frame as soon as it | 
 | 123 |     // can and not wait for a frame to become available. This is only relevant | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 124 |     // in shared buffer mode. | 
| Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 125 |     bool mAutoRefresh; | 
| Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 126 |  | 
| Pablo Ceballos | 3559fbf | 2016-03-17 15:50:23 -0700 | [diff] [blame] | 127 |     // Indicates that this buffer was queued by the producer. When in shared | 
| Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 128 |     // buffer mode acquire() can return a BufferItem that wasn't in the queue. | 
 | 129 |     bool mQueuedBuffer; | 
| Pablo Ceballos | 23b4abe | 2016-01-08 12:15:22 -0800 | [diff] [blame] | 130 |  | 
 | 131 |     // Indicates that this BufferItem contains a stale buffer which has already | 
 | 132 |     // been released by the BufferQueue. | 
 | 133 |     bool mIsStale; | 
| Dan Stoza | 289ade1 | 2014-02-28 11:17:17 -0800 | [diff] [blame] | 134 | }; | 
 | 135 |  | 
 | 136 | } // namespace android | 
 | 137 |  | 
 | 138 | #endif |