| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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_GRAPHIC_BUFFER_H |
| 18 | #define ANDROID_GRAPHIC_BUFFER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 23 | #include <string> |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 24 | #include <utility> |
| 25 | #include <vector> |
| Mathias Agopian | fe2f54f | 2017-02-15 19:48:58 -0800 | [diff] [blame] | 26 | |
| Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 27 | #include <android/hardware_buffer.h> |
| Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 28 | #include <ui/ANativeObjectBase.h> |
| Valerie Hau | d2f4daf | 2019-02-15 13:49:00 -0800 | [diff] [blame] | 29 | #include <ui/GraphicBufferMapper.h> |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 30 | #include <ui/PixelFormat.h> |
| 31 | #include <ui/Rect.h> |
| Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 32 | #include <utils/Flattenable.h> |
| Mathias Agopian | e041716 | 2013-03-06 18:50:52 -0800 | [diff] [blame] | 33 | #include <utils/RefBase.h> |
| Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 34 | |
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 35 | #include <nativebase/nativebase.h> |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 36 | |
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 37 | #include <hardware/gralloc.h> |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | class GraphicBufferMapper; |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 42 | |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 43 | using GraphicBufferDeathCallback = std::function<void(void* /*context*/, uint64_t bufferId)>; |
| 44 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 45 | // =========================================================================== |
| 46 | // GraphicBuffer |
| 47 | // =========================================================================== |
| 48 | |
| 49 | class GraphicBuffer |
| Mathias Agopian | 6a3c05b | 2017-04-27 20:06:55 -0700 | [diff] [blame] | 50 | : public ANativeObjectBase<ANativeWindowBuffer, GraphicBuffer, RefBase>, |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 51 | public Flattenable<GraphicBuffer> |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 52 | { |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 53 | friend class Flattenable<GraphicBuffer>; |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 54 | public: |
| 55 | |
| 56 | enum { |
| 57 | USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER, |
| 58 | USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY, |
| 59 | USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN, |
| 60 | USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK, |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 61 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 62 | USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER, |
| 63 | USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY, |
| 64 | USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN, |
| 65 | USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK, |
| Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 66 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 67 | USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK, |
| Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 68 | |
| 69 | USAGE_PROTECTED = GRALLOC_USAGE_PROTECTED, |
| 70 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 71 | USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE, |
| 72 | USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER, |
| 73 | USAGE_HW_2D = GRALLOC_USAGE_HW_2D, |
| Jamie Gennis | 3599bf2 | 2011-08-10 11:48:07 -0700 | [diff] [blame] | 74 | USAGE_HW_COMPOSER = GRALLOC_USAGE_HW_COMPOSER, |
| Jamie Gennis | b7d87c4 | 2011-11-21 16:51:47 -0800 | [diff] [blame] | 75 | USAGE_HW_VIDEO_ENCODER = GRALLOC_USAGE_HW_VIDEO_ENCODER, |
| Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 76 | USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK, |
| 77 | |
| 78 | USAGE_CURSOR = GRALLOC_USAGE_CURSOR, |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| Mathias Agopian | f543e5a | 2017-04-03 17:16:41 -0700 | [diff] [blame] | 81 | static sp<GraphicBuffer> from(ANativeWindowBuffer *); |
| 82 | |
| Pawin Vongmasa | e672cd0 | 2019-02-14 16:01:29 -0800 | [diff] [blame] | 83 | static GraphicBuffer* fromAHardwareBuffer(AHardwareBuffer*); |
| 84 | static GraphicBuffer const* fromAHardwareBuffer(AHardwareBuffer const*); |
| 85 | AHardwareBuffer* toAHardwareBuffer(); |
| 86 | AHardwareBuffer const* toAHardwareBuffer() const; |
| Mathias Agopian | f543e5a | 2017-04-03 17:16:41 -0700 | [diff] [blame] | 87 | |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 88 | // Create a GraphicBuffer to be unflatten'ed into or be reallocated. |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 89 | GraphicBuffer(); |
| 90 | |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 91 | // Create a GraphicBuffer by allocating and managing a buffer internally. |
| 92 | // This function is privileged. See reallocate for details. |
| Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 93 | GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 94 | uint32_t inLayerCount, uint64_t inUsage, |
| 95 | std::string requestorName = "<Unknown>"); |
| Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 96 | |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 97 | // Create a GraphicBuffer from an existing handle. |
| 98 | enum HandleWrapMethod : uint8_t { |
| 99 | // Wrap and use the handle directly. It assumes the handle has been |
| 100 | // registered and never fails. The handle must have a longer lifetime |
| 101 | // than this wrapping GraphicBuffer. |
| 102 | // |
| 103 | // This can be used when, for example, you want to wrap a handle that |
| 104 | // is already managed by another GraphicBuffer. |
| 105 | WRAP_HANDLE, |
| 106 | |
| 107 | // Take ownership of the handle and use it directly. It assumes the |
| 108 | // handle has been registered and never fails. |
| 109 | // |
| 110 | // This can be used to manage an already registered handle with |
| 111 | // GraphicBuffer. |
| 112 | TAKE_HANDLE, |
| 113 | |
| 114 | // Take onwership of an unregistered handle and use it directly. It |
| 115 | // can fail when the buffer does not register. There is no ownership |
| 116 | // transfer on failures. |
| 117 | // |
| 118 | // This can be used to, for example, create a GraphicBuffer from a |
| 119 | // handle returned by Parcel::readNativeHandle. |
| 120 | TAKE_UNREGISTERED_HANDLE, |
| 121 | |
| 122 | // Make a clone of the handle and use the cloned handle. It can fail |
| 123 | // when cloning fails or when the buffer does not register. There is |
| 124 | // never ownership transfer. |
| 125 | // |
| 126 | // This can be used to create a GraphicBuffer from a handle that |
| 127 | // cannot be used directly, such as one from hidl_handle. |
| 128 | CLONE_HANDLE, |
| 129 | }; |
| Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 130 | GraphicBuffer(const native_handle_t* inHandle, HandleWrapMethod method, uint32_t inWidth, |
| 131 | uint32_t inHeight, PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage, |
| 132 | uint32_t inStride); |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 133 | |
| Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 134 | // These functions are deprecated because they only take 32 bits of usage |
| Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 135 | GraphicBuffer(const native_handle_t* inHandle, HandleWrapMethod method, uint32_t inWidth, |
| 136 | uint32_t inHeight, PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage, |
| 137 | uint32_t inStride) |
| 138 | : GraphicBuffer(inHandle, method, inWidth, inHeight, inFormat, inLayerCount, |
| 139 | static_cast<uint64_t>(inUsage), inStride) {} |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 140 | GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 141 | uint32_t inLayerCount, uint32_t inUsage, uint32_t inStride, |
| 142 | native_handle_t* inHandle, bool keepOwnership); |
| Daniel Nicoara | 1c45710 | 2017-02-07 17:27:25 -0500 | [diff] [blame] | 143 | GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 144 | uint32_t inUsage, std::string requestorName = "<Unknown>"); |
| Daniel Nicoara | 1c45710 | 2017-02-07 17:27:25 -0500 | [diff] [blame] | 145 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 146 | // return status |
| 147 | status_t initCheck() const; |
| 148 | |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 149 | uint32_t getWidth() const { return static_cast<uint32_t>(width); } |
| 150 | uint32_t getHeight() const { return static_cast<uint32_t>(height); } |
| 151 | uint32_t getStride() const { return static_cast<uint32_t>(stride); } |
| Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 152 | uint64_t getUsage() const { return usage; } |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 153 | PixelFormat getPixelFormat() const { return format; } |
| Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 154 | uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); } |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 155 | Rect getBounds() const { return Rect(width, height); } |
| Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 156 | uint64_t getId() const { return mId; } |
| 157 | |
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 158 | uint32_t getGenerationNumber() const { return mGenerationNumber; } |
| 159 | void setGenerationNumber(uint32_t generation) { |
| 160 | mGenerationNumber = generation; |
| 161 | } |
| 162 | |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 163 | // This function is privileged. It requires access to the allocator |
| 164 | // device or service, which usually involves adding suitable selinux |
| 165 | // rules. |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 166 | status_t reallocate(uint32_t inWidth, uint32_t inHeight, |
| Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 167 | PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage); |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 168 | |
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 169 | bool needsReallocation(uint32_t inWidth, uint32_t inHeight, |
| Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 170 | PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage); |
| Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 171 | |
| Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 172 | // For the following two lock functions, if bytesPerStride or bytesPerPixel |
| 173 | // are unknown or variable, -1 will be returned |
| 174 | status_t lock(uint32_t inUsage, void** vaddr, int32_t* outBytesPerPixel = nullptr, |
| 175 | int32_t* outBytesPerStride = nullptr); |
| 176 | status_t lock(uint32_t inUsage, const Rect& rect, void** vaddr, |
| 177 | int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr); |
| Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 178 | // For HAL_PIXEL_FORMAT_YCbCr_420_888 |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 179 | status_t lockYCbCr(uint32_t inUsage, android_ycbcr *ycbcr); |
| 180 | status_t lockYCbCr(uint32_t inUsage, const Rect& rect, |
| 181 | android_ycbcr *ycbcr); |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 182 | status_t unlock(); |
| Valerie Hau | b94adfd | 2019-02-07 14:25:12 -0800 | [diff] [blame] | 183 | // For the following three lockAsync functions, if bytesPerStride or bytesPerPixel |
| 184 | // are unknown or variable, -1 will be returned |
| 185 | status_t lockAsync(uint32_t inUsage, void** vaddr, int fenceFd, |
| 186 | int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr); |
| 187 | status_t lockAsync(uint32_t inUsage, const Rect& rect, void** vaddr, int fenceFd, |
| 188 | int32_t* outBytesPerPixel = nullptr, int32_t* outBytesPerStride = nullptr); |
| 189 | status_t lockAsync(uint64_t inProducerUsage, uint64_t inConsumerUsage, const Rect& rect, |
| 190 | void** vaddr, int fenceFd, int32_t* outBytesPerPixel = nullptr, |
| 191 | int32_t* outBytesPerStride = nullptr); |
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 192 | status_t lockAsyncYCbCr(uint32_t inUsage, android_ycbcr *ycbcr, |
| 193 | int fenceFd); |
| 194 | status_t lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, |
| 195 | android_ycbcr *ycbcr, int fenceFd); |
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 196 | status_t unlockAsync(int *fenceFd); |
| Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 197 | |
| Valerie Hau | ddbfaeb | 2019-02-01 09:54:20 -0800 | [diff] [blame] | 198 | status_t isSupported(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 199 | uint32_t inLayerCount, uint64_t inUsage, bool* outSupported) const; |
| 200 | |
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 201 | ANativeWindowBuffer* getNativeBuffer() const; |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 202 | |
| Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 203 | // for debugging |
| 204 | static void dumpAllocationsToSystemLog(); |
| 205 | |
| Mathias Agopian | 87f9b87 | 2013-07-31 19:18:22 -0700 | [diff] [blame] | 206 | // Flattenable protocol |
| 207 | size_t getFlattenedSize() const; |
| 208 | size_t getFdCount() const; |
| 209 | status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const; |
| 210 | status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count); |
| 211 | |
| Valerie Hau | d2f4daf | 2019-02-15 13:49:00 -0800 | [diff] [blame] | 212 | GraphicBufferMapper::Version getBufferMapperVersion() const { |
| 213 | return mBufferMapper.getMapperVersion(); |
| 214 | } |
| 215 | |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 216 | void addDeathCallback(GraphicBufferDeathCallback deathCallback, void* context); |
| 217 | |
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 218 | private: |
| Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 219 | ~GraphicBuffer(); |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 220 | |
| Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 221 | enum { |
| 222 | ownNone = 0, |
| 223 | ownHandle = 1, |
| 224 | ownData = 2, |
| 225 | }; |
| 226 | |
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 227 | inline const GraphicBufferMapper& getBufferMapper() const { |
| 228 | return mBufferMapper; |
| 229 | } |
| 230 | inline GraphicBufferMapper& getBufferMapper() { |
| 231 | return mBufferMapper; |
| 232 | } |
| Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 233 | uint8_t mOwner; |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 234 | |
| 235 | private: |
| 236 | friend class Surface; |
| 237 | friend class BpSurface; |
| 238 | friend class BnSurface; |
| 239 | friend class LightRefBase<GraphicBuffer>; |
| 240 | GraphicBuffer(const GraphicBuffer& rhs); |
| 241 | GraphicBuffer& operator = (const GraphicBuffer& rhs); |
| 242 | const GraphicBuffer& operator = (const GraphicBuffer& rhs) const; |
| 243 | |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 244 | status_t initWithSize(uint32_t inWidth, uint32_t inHeight, |
| 245 | PixelFormat inFormat, uint32_t inLayerCount, |
| Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 246 | uint64_t inUsage, std::string requestorName); |
| Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 247 | |
| Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 248 | status_t initWithHandle(const native_handle_t* inHandle, HandleWrapMethod method, |
| 249 | uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 250 | uint32_t inLayerCount, uint64_t inUsage, uint32_t inStride); |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 251 | |
| Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 252 | void free_handle(); |
| 253 | |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 254 | GraphicBufferMapper& mBufferMapper; |
| 255 | ssize_t mInitCheck; |
| Jamie Gennis | 309d3bb | 2010-10-07 13:46:55 -0700 | [diff] [blame] | 256 | |
| Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 257 | // numbers of fds/ints in native_handle_t to flatten |
| 258 | uint32_t mTransportNumFds; |
| 259 | uint32_t mTransportNumInts; |
| 260 | |
| Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 261 | uint64_t mId; |
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 262 | |
| Alec Mouri | d1d79ff | 2020-08-06 23:12:04 +0000 | [diff] [blame] | 263 | // Unused, but removing this may break GSI. |
| 264 | int32_t mBufferId = -1; |
| 265 | |
| Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 266 | // Stores the generation number of this buffer. If this number does not |
| 267 | // match the BufferQueue's internal generation number (set through |
| 268 | // IGBP::setGenerationNumber), attempts to attach the buffer will fail. |
| 269 | uint32_t mGenerationNumber; |
| Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 270 | |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 271 | // Send a callback when a GraphicBuffer dies. |
| 272 | // |
| Patrick Williams | 83f36b2 | 2022-09-14 17:57:35 +0000 | [diff] [blame] | 273 | // This is used for layer caching. GraphicBuffers are refcounted per process. When |
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 274 | // A GraphicBuffer doesn't have any more sp<> in a process, it is destroyed. This causes |
| 275 | // problems when trying to implicitcly cache across process boundaries. Ideally, both sides |
| 276 | // of the cache would hold onto wp<> references. When an app dropped its sp<>, the GraphicBuffer |
| 277 | // would be destroyed. Unfortunately, when SurfaceFlinger has only a wp<> reference to the |
| 278 | // GraphicBuffer, it immediately goes out of scope in the SurfaceFlinger process. SurfaceFlinger |
| 279 | // must hold onto a sp<> to the buffer. When the GraphicBuffer goes out of scope in the app's |
| 280 | // process, the client side cache will get this callback. It erases the buffer from its cache |
| 281 | // and informs SurfaceFlinger that it should drop its strong pointer reference to the buffer. |
| 282 | std::vector<std::pair<GraphicBufferDeathCallback, void* /*mDeathCallbackContext*/>> |
| 283 | mDeathCallbacks; |
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
| 286 | }; // namespace android |
| 287 | |
| 288 | #endif // ANDROID_GRAPHIC_BUFFER_H |