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 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 17 | #define LOG_TAG "GraphicBuffer" |
| 18 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 19 | #include <ui/GraphicBuffer.h> |
Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 20 | |
| 21 | #include <cutils/atomic.h> |
| 22 | |
Jesse Hall | 7992781 | 2017-03-23 11:03:23 -0700 | [diff] [blame] | 23 | #include <grallocusage/GrallocUsageConversion.h> |
| 24 | |
Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 25 | #ifndef LIBUI_IN_VNDK |
| 26 | #include <ui/BufferHubBuffer.h> |
| 27 | #endif // LIBUI_IN_VNDK |
| 28 | |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 29 | #include <ui/Gralloc2.h> |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 30 | #include <ui/GraphicBufferAllocator.h> |
| 31 | #include <ui/GraphicBufferMapper.h> |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 32 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 33 | namespace android { |
| 34 | |
| 35 | // =========================================================================== |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 36 | // Buffer and implementation of ANativeWindowBuffer |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 37 | // =========================================================================== |
| 38 | |
Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 39 | static uint64_t getUniqueId() { |
| 40 | static volatile int32_t nextId = 0; |
| 41 | uint64_t id = static_cast<uint64_t>(getpid()) << 32; |
| 42 | id |= static_cast<uint32_t>(android_atomic_inc(&nextId)); |
| 43 | return id; |
| 44 | } |
| 45 | |
Mathias Agopian | f543e5a | 2017-04-03 17:16:41 -0700 | [diff] [blame] | 46 | sp<GraphicBuffer> GraphicBuffer::from(ANativeWindowBuffer* anwb) { |
| 47 | return static_cast<GraphicBuffer *>(anwb); |
| 48 | } |
| 49 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 50 | GraphicBuffer::GraphicBuffer() |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 51 | : BASE(), mOwner(ownData), mBufferMapper(GraphicBufferMapper::get()), |
Pablo Ceballos | 53390e1 | 2015-08-04 11:25:59 -0700 | [diff] [blame] | 52 | mInitCheck(NO_ERROR), mId(getUniqueId()), mGenerationNumber(0) |
Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 53 | { |
Dan Stoza | 01049c8 | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 54 | width = |
| 55 | height = |
| 56 | stride = |
| 57 | format = |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 58 | usage_deprecated = 0; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 59 | usage = 0; |
Mathias Agopian | 841abed | 2017-02-10 16:15:34 -0800 | [diff] [blame] | 60 | layerCount = 0; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 61 | handle = NULL; |
| 62 | } |
| 63 | |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 64 | // deprecated |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 65 | GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight, |
Dan Stoza | 024e931 | 2016-08-24 12:17:29 -0700 | [diff] [blame] | 66 | PixelFormat inFormat, uint32_t inUsage, std::string requestorName) |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 67 | : GraphicBuffer(inWidth, inHeight, inFormat, 1, static_cast<uint64_t>(inUsage), requestorName) |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 68 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 71 | GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 72 | uint32_t inLayerCount, uint64_t inUsage, std::string requestorName) |
| 73 | : GraphicBuffer() { |
| 74 | mInitCheck = initWithSize(inWidth, inHeight, inFormat, inLayerCount, inUsage, |
| 75 | std::move(requestorName)); |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 78 | // deprecated |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 79 | GraphicBuffer::GraphicBuffer(uint32_t inWidth, uint32_t inHeight, |
| 80 | PixelFormat inFormat, uint32_t inLayerCount, uint32_t inUsage, |
| 81 | uint32_t inStride, native_handle_t* inHandle, bool keepOwnership) |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 82 | : GraphicBuffer(inHandle, keepOwnership ? TAKE_HANDLE : WRAP_HANDLE, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 83 | inWidth, inHeight, inFormat, inLayerCount, static_cast<uint64_t>(inUsage), |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 84 | inStride) |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 85 | { |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 88 | GraphicBuffer::GraphicBuffer(const native_handle_t* inHandle, HandleWrapMethod method, |
| 89 | uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 90 | uint32_t inLayerCount, uint64_t inUsage, uint32_t inStride) |
| 91 | : GraphicBuffer() { |
| 92 | mInitCheck = initWithHandle(inHandle, method, inWidth, inHeight, inFormat, inLayerCount, |
| 93 | inUsage, inStride); |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 96 | #ifndef LIBUI_IN_VNDK |
| 97 | GraphicBuffer::GraphicBuffer(std::unique_ptr<BufferHubBuffer> buffer) : GraphicBuffer() { |
| 98 | if (buffer == nullptr) { |
| 99 | mInitCheck = BAD_VALUE; |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | mInitCheck = initWithHandle(buffer->DuplicateHandle(), /*method=*/TAKE_UNREGISTERED_HANDLE, |
| 104 | buffer->desc().width, buffer->desc().height, |
| 105 | static_cast<PixelFormat>(buffer->desc().format), |
| 106 | buffer->desc().layers, buffer->desc().usage, buffer->desc().stride); |
Jiwen 'Steve' Cai | 29160fb | 2018-12-13 12:03:28 -0800 | [diff] [blame] | 107 | mBufferId = buffer->id(); |
Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 108 | mBufferHubBuffer = std::move(buffer); |
| 109 | } |
| 110 | #endif // LIBUI_IN_VNDK |
| 111 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 112 | GraphicBuffer::~GraphicBuffer() |
| 113 | { |
| 114 | if (handle) { |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 115 | free_handle(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void GraphicBuffer::free_handle() |
| 120 | { |
| 121 | if (mOwner == ownHandle) { |
Chia-I Wu | 5bac7f3 | 2017-04-06 12:34:32 -0700 | [diff] [blame] | 122 | mBufferMapper.freeBuffer(handle); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 123 | } else if (mOwner == ownData) { |
| 124 | GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); |
| 125 | allocator.free(handle); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 126 | } |
Praveen Chavan | 22e4cc3 | 2015-09-16 11:20:00 -0700 | [diff] [blame] | 127 | handle = NULL; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | status_t GraphicBuffer::initCheck() const { |
Dan Stoza | 133caac | 2014-12-01 15:15:31 -0800 | [diff] [blame] | 131 | return static_cast<status_t>(mInitCheck); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Mathias Agopian | 678bdd6 | 2010-12-03 17:33:09 -0800 | [diff] [blame] | 134 | void GraphicBuffer::dumpAllocationsToSystemLog() |
| 135 | { |
| 136 | GraphicBufferAllocator::dumpToSystemLog(); |
| 137 | } |
| 138 | |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 139 | ANativeWindowBuffer* GraphicBuffer::getNativeBuffer() const |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 140 | { |
Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 141 | return static_cast<ANativeWindowBuffer*>( |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 142 | const_cast<GraphicBuffer*>(this)); |
| 143 | } |
| 144 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 145 | status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 146 | PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage) |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 147 | { |
Mathias Agopian | 54ba51d | 2009-10-26 20:12:37 -0700 | [diff] [blame] | 148 | if (mOwner != ownData) |
| 149 | return INVALID_OPERATION; |
| 150 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 151 | if (handle && |
| 152 | static_cast<int>(inWidth) == width && |
| 153 | static_cast<int>(inHeight) == height && |
| 154 | inFormat == format && |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 155 | inLayerCount == layerCount && |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 156 | inUsage == usage) |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 157 | return NO_ERROR; |
| 158 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 159 | if (handle) { |
| 160 | GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); |
| 161 | allocator.free(handle); |
| 162 | handle = 0; |
| 163 | } |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 164 | return initWithSize(inWidth, inHeight, inFormat, inLayerCount, inUsage, "[Reallocation]"); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 167 | bool GraphicBuffer::needsReallocation(uint32_t inWidth, uint32_t inHeight, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 168 | PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage) |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 169 | { |
| 170 | if (static_cast<int>(inWidth) != width) return true; |
| 171 | if (static_cast<int>(inHeight) != height) return true; |
| 172 | if (inFormat != format) return true; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 173 | if (inLayerCount != layerCount) return true; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 174 | if ((usage & inUsage) != inUsage) return true; |
Dan Stoza | 9de7293 | 2015-04-16 17:28:43 -0700 | [diff] [blame] | 175 | return false; |
| 176 | } |
| 177 | |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 178 | status_t GraphicBuffer::initWithSize(uint32_t inWidth, uint32_t inHeight, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 179 | PixelFormat inFormat, uint32_t inLayerCount, uint64_t inUsage, |
| 180 | std::string requestorName) |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 181 | { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 182 | GraphicBufferAllocator& allocator = GraphicBufferAllocator::get(); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 183 | uint32_t outStride = 0; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 184 | status_t err = allocator.allocate(inWidth, inHeight, inFormat, inLayerCount, |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 185 | inUsage, &handle, &outStride, mId, |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 186 | std::move(requestorName)); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 187 | if (err == NO_ERROR) { |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 188 | mBufferMapper.getTransportSize(handle, &mTransportNumFds, &mTransportNumInts); |
| 189 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 190 | width = static_cast<int>(inWidth); |
| 191 | height = static_cast<int>(inHeight); |
| 192 | format = inFormat; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 193 | layerCount = inLayerCount; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 194 | usage = inUsage; |
| 195 | usage_deprecated = int(usage); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 196 | stride = static_cast<int>(outStride); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 197 | } |
| 198 | return err; |
| 199 | } |
| 200 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 201 | status_t GraphicBuffer::initWithHandle(const native_handle_t* inHandle, HandleWrapMethod method, |
| 202 | uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 203 | uint32_t inLayerCount, uint64_t inUsage, uint32_t inStride) { |
| 204 | ANativeWindowBuffer::width = static_cast<int>(inWidth); |
| 205 | ANativeWindowBuffer::height = static_cast<int>(inHeight); |
| 206 | ANativeWindowBuffer::stride = static_cast<int>(inStride); |
| 207 | ANativeWindowBuffer::format = inFormat; |
| 208 | ANativeWindowBuffer::usage = inUsage; |
| 209 | ANativeWindowBuffer::usage_deprecated = int(inUsage); |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 210 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 211 | ANativeWindowBuffer::layerCount = inLayerCount; |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 212 | |
| 213 | mOwner = (method == WRAP_HANDLE) ? ownNone : ownHandle; |
| 214 | |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 215 | if (method == TAKE_UNREGISTERED_HANDLE || method == CLONE_HANDLE) { |
| 216 | buffer_handle_t importedHandle; |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 217 | status_t err = mBufferMapper.importBuffer(inHandle, inWidth, inHeight, inLayerCount, |
| 218 | inFormat, inUsage, inStride, &importedHandle); |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 219 | if (err != NO_ERROR) { |
Chris Forbes | 82c0498 | 2017-04-19 14:29:54 -0700 | [diff] [blame] | 220 | initWithHandle(nullptr, WRAP_HANDLE, 0, 0, 0, 0, 0, 0); |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 221 | |
| 222 | return err; |
| 223 | } |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 224 | |
| 225 | if (method == TAKE_UNREGISTERED_HANDLE) { |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 226 | native_handle_close(inHandle); |
| 227 | native_handle_delete(const_cast<native_handle_t*>(inHandle)); |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 230 | inHandle = importedHandle; |
| 231 | mBufferMapper.getTransportSize(inHandle, &mTransportNumFds, &mTransportNumInts); |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Chih-Hung Hsieh | bcc6c92 | 2018-11-13 15:20:59 -0800 | [diff] [blame] | 234 | ANativeWindowBuffer::handle = inHandle; |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 235 | |
Chia-I Wu | b42f171 | 2017-03-21 13:15:39 -0700 | [diff] [blame] | 236 | return NO_ERROR; |
| 237 | } |
| 238 | |
Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 239 | status_t GraphicBuffer::lock(uint32_t inUsage, void** vaddr, int32_t* outBytesPerPixel, |
| 240 | int32_t* outBytesPerStride) { |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 241 | const Rect lockBounds(width, height); |
Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 242 | status_t res = lock(inUsage, lockBounds, vaddr, outBytesPerPixel, outBytesPerStride); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 243 | return res; |
| 244 | } |
| 245 | |
Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 246 | status_t GraphicBuffer::lock(uint32_t inUsage, const Rect& rect, void** vaddr, |
| 247 | int32_t* outBytesPerPixel, int32_t* outBytesPerStride) { |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 248 | if (rect.left < 0 || rect.right > width || |
| 249 | rect.top < 0 || rect.bottom > height) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 250 | ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", |
Dan Stoza | 01049c8 | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 251 | rect.left, rect.top, rect.right, rect.bottom, |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 252 | width, height); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 253 | return BAD_VALUE; |
| 254 | } |
Valerie Hau | 0c9fc36 | 2019-01-22 09:17:19 -0800 | [diff] [blame] | 255 | |
Valerie Hau | 250c654 | 2019-01-31 14:23:43 -0800 | [diff] [blame] | 256 | status_t res = getBufferMapper().lock(handle, inUsage, rect, vaddr, outBytesPerPixel, |
| 257 | outBytesPerStride); |
| 258 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 259 | return res; |
| 260 | } |
| 261 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 262 | status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, android_ycbcr* ycbcr) |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 263 | { |
| 264 | const Rect lockBounds(width, height); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 265 | status_t res = lockYCbCr(inUsage, lockBounds, ycbcr); |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 266 | return res; |
| 267 | } |
| 268 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 269 | status_t GraphicBuffer::lockYCbCr(uint32_t inUsage, const Rect& rect, |
| 270 | android_ycbcr* ycbcr) |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 271 | { |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 272 | if (rect.left < 0 || rect.right > width || |
| 273 | rect.top < 0 || rect.bottom > height) { |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 274 | ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", |
| 275 | rect.left, rect.top, rect.right, rect.bottom, |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 276 | width, height); |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 277 | return BAD_VALUE; |
| 278 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 279 | status_t res = getBufferMapper().lockYCbCr(handle, inUsage, rect, ycbcr); |
Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 280 | return res; |
| 281 | } |
| 282 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 283 | status_t GraphicBuffer::unlock() |
| 284 | { |
| 285 | status_t res = getBufferMapper().unlock(handle); |
| 286 | return res; |
| 287 | } |
| 288 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 289 | status_t GraphicBuffer::lockAsync(uint32_t inUsage, void** vaddr, int fenceFd) |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 290 | { |
| 291 | const Rect lockBounds(width, height); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 292 | status_t res = lockAsync(inUsage, lockBounds, vaddr, fenceFd); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 293 | return res; |
| 294 | } |
| 295 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 296 | status_t GraphicBuffer::lockAsync(uint32_t inUsage, const Rect& rect, |
| 297 | void** vaddr, int fenceFd) |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 298 | { |
Craig Donner | e96a325 | 2017-02-02 12:13:34 -0800 | [diff] [blame] | 299 | return lockAsync(inUsage, inUsage, rect, vaddr, fenceFd); |
| 300 | } |
| 301 | |
| 302 | status_t GraphicBuffer::lockAsync(uint64_t inProducerUsage, |
| 303 | uint64_t inConsumerUsage, const Rect& rect, void** vaddr, int fenceFd) |
| 304 | { |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 305 | if (rect.left < 0 || rect.right > width || |
| 306 | rect.top < 0 || rect.bottom > height) { |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 307 | ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", |
| 308 | rect.left, rect.top, rect.right, rect.bottom, |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 309 | width, height); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 310 | return BAD_VALUE; |
| 311 | } |
Valerie Hau | 0c9fc36 | 2019-01-22 09:17:19 -0800 | [diff] [blame] | 312 | |
| 313 | int32_t bytesPerPixel, bytesPerStride; |
| 314 | status_t res = getBufferMapper().lockAsync(handle, inProducerUsage, inConsumerUsage, rect, |
| 315 | vaddr, fenceFd, &bytesPerPixel, &bytesPerStride); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 316 | return res; |
| 317 | } |
| 318 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 319 | status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, android_ycbcr* ycbcr, |
| 320 | int fenceFd) |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 321 | { |
| 322 | const Rect lockBounds(width, height); |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 323 | status_t res = lockAsyncYCbCr(inUsage, lockBounds, ycbcr, fenceFd); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 324 | return res; |
| 325 | } |
| 326 | |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 327 | status_t GraphicBuffer::lockAsyncYCbCr(uint32_t inUsage, const Rect& rect, |
| 328 | android_ycbcr* ycbcr, int fenceFd) |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 329 | { |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 330 | if (rect.left < 0 || rect.right > width || |
| 331 | rect.top < 0 || rect.bottom > height) { |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 332 | ALOGE("locking pixels (%d,%d,%d,%d) outside of buffer (w=%d, h=%d)", |
| 333 | rect.left, rect.top, rect.right, rect.bottom, |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 334 | width, height); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 335 | return BAD_VALUE; |
| 336 | } |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 337 | status_t res = getBufferMapper().lockAsyncYCbCr(handle, inUsage, rect, ycbcr, fenceFd); |
Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 338 | return res; |
| 339 | } |
| 340 | |
| 341 | status_t GraphicBuffer::unlockAsync(int *fenceFd) |
| 342 | { |
| 343 | status_t res = getBufferMapper().unlockAsync(handle, fenceFd); |
| 344 | return res; |
| 345 | } |
| 346 | |
Valerie Hau | ddbfaeb | 2019-02-01 09:54:20 -0800 | [diff] [blame^] | 347 | status_t GraphicBuffer::isSupported(uint32_t inWidth, uint32_t inHeight, PixelFormat inFormat, |
| 348 | uint32_t inLayerCount, uint64_t inUsage, |
| 349 | bool* outSupported) const { |
| 350 | return mBufferMapper.isSupported(inWidth, inHeight, inFormat, inLayerCount, inUsage, |
| 351 | outSupported); |
| 352 | } |
| 353 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 354 | size_t GraphicBuffer::getFlattenedSize() const { |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 355 | return static_cast<size_t>(13 + (handle ? mTransportNumInts : 0)) * sizeof(int); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 356 | } |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 357 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 358 | size_t GraphicBuffer::getFdCount() const { |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 359 | return static_cast<size_t>(handle ? mTransportNumFds : 0); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 362 | status_t GraphicBuffer::flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const { |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 363 | size_t sizeNeeded = GraphicBuffer::getFlattenedSize(); |
| 364 | if (size < sizeNeeded) return NO_MEMORY; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 365 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 366 | size_t fdCountNeeded = GraphicBuffer::getFdCount(); |
| 367 | if (count < fdCountNeeded) return NO_MEMORY; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 368 | |
Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 369 | int32_t* buf = static_cast<int32_t*>(buffer); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 370 | buf[0] = 'GB01'; |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 371 | buf[1] = width; |
| 372 | buf[2] = height; |
| 373 | buf[3] = stride; |
| 374 | buf[4] = format; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 375 | buf[5] = static_cast<int32_t>(layerCount); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 376 | buf[6] = int(usage); // low 32-bits |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 377 | buf[7] = static_cast<int32_t>(mId >> 32); |
| 378 | buf[8] = static_cast<int32_t>(mId & 0xFFFFFFFFull); |
| 379 | buf[9] = static_cast<int32_t>(mGenerationNumber); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 380 | buf[10] = 0; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 381 | buf[11] = 0; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 382 | buf[12] = int(usage >> 32); // high 32-bits |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 383 | |
| 384 | if (handle) { |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 385 | buf[10] = int32_t(mTransportNumFds); |
| 386 | buf[11] = int32_t(mTransportNumInts); |
| 387 | memcpy(fds, handle->data, static_cast<size_t>(mTransportNumFds) * sizeof(int)); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 388 | memcpy(buf + 13, handle->data + handle->numFds, |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 389 | static_cast<size_t>(mTransportNumInts) * sizeof(int)); |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 390 | } |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 391 | |
Dan Stoza | eea6d68 | 2015-04-20 12:07:13 -0700 | [diff] [blame] | 392 | buffer = static_cast<void*>(static_cast<uint8_t*>(buffer) + sizeNeeded); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 393 | size -= sizeNeeded; |
Andy McFadden | bc96e47 | 2014-03-17 16:48:23 -0700 | [diff] [blame] | 394 | if (handle) { |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 395 | fds += mTransportNumFds; |
| 396 | count -= static_cast<size_t>(mTransportNumFds); |
Andy McFadden | bc96e47 | 2014-03-17 16:48:23 -0700 | [diff] [blame] | 397 | } |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 398 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 399 | return NO_ERROR; |
| 400 | } |
| 401 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 402 | status_t GraphicBuffer::unflatten( |
| 403 | void const*& buffer, size_t& size, int const*& fds, size_t& count) { |
Chia-I Wu | bf8d721 | 2018-10-09 15:22:46 -0700 | [diff] [blame] | 404 | if (size < 12 * sizeof(int)) { |
| 405 | android_errorWriteLog(0x534e4554, "114223584"); |
| 406 | return NO_MEMORY; |
| 407 | } |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 408 | |
| 409 | int const* buf = static_cast<int const*>(buffer); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 410 | |
| 411 | // NOTE: it turns out that some media code generates a flattened GraphicBuffer manually!!!!! |
| 412 | // see H2BGraphicBufferProducer.cpp |
| 413 | uint32_t flattenWordCount = 0; |
| 414 | if (buf[0] == 'GB01') { |
| 415 | // new version with 64-bits usage bits |
| 416 | flattenWordCount = 13; |
| 417 | } else if (buf[0] == 'GBFR') { |
| 418 | // old version, when usage bits were 32-bits |
| 419 | flattenWordCount = 12; |
| 420 | } else { |
| 421 | return BAD_TYPE; |
| 422 | } |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 423 | |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 424 | const size_t numFds = static_cast<size_t>(buf[10]); |
| 425 | const size_t numInts = static_cast<size_t>(buf[11]); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 426 | |
Michael Lentine | c168b8a | 2015-02-18 10:14:18 -0800 | [diff] [blame] | 427 | // Limit the maxNumber to be relatively small. The number of fds or ints |
| 428 | // should not come close to this number, and the number itself was simply |
| 429 | // chosen to be high enough to not cause issues and low enough to prevent |
| 430 | // overflow problems. |
| 431 | const size_t maxNumber = 4096; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 432 | if (numFds >= maxNumber || numInts >= (maxNumber - flattenWordCount)) { |
| 433 | width = height = stride = format = usage_deprecated = 0; |
| 434 | layerCount = 0; |
| 435 | usage = 0; |
Michael Lentine | 3880326 | 2014-10-31 15:25:03 -0700 | [diff] [blame] | 436 | handle = NULL; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 437 | ALOGE("unflatten: numFds or numInts is too large: %zd, %zd", numFds, numInts); |
Michael Lentine | 3880326 | 2014-10-31 15:25:03 -0700 | [diff] [blame] | 438 | return BAD_VALUE; |
| 439 | } |
| 440 | |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 441 | const size_t sizeNeeded = (flattenWordCount + numInts) * sizeof(int); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 442 | if (size < sizeNeeded) return NO_MEMORY; |
| 443 | |
Michael Lentine | 3880326 | 2014-10-31 15:25:03 -0700 | [diff] [blame] | 444 | size_t fdCountNeeded = numFds; |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 445 | if (count < fdCountNeeded) return NO_MEMORY; |
| 446 | |
| 447 | if (handle) { |
| 448 | // free previous handle if any |
| 449 | free_handle(); |
| 450 | } |
| 451 | |
| 452 | if (numFds || numInts) { |
| 453 | width = buf[1]; |
| 454 | height = buf[2]; |
| 455 | stride = buf[3]; |
| 456 | format = buf[4]; |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 457 | layerCount = static_cast<uintptr_t>(buf[5]); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 458 | usage_deprecated = buf[6]; |
| 459 | if (flattenWordCount == 13) { |
| 460 | usage = (uint64_t(buf[12]) << 32) | uint32_t(buf[6]); |
| 461 | } else { |
| 462 | usage = uint64_t(usage_deprecated); |
| 463 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 464 | native_handle* h = native_handle_create( |
| 465 | static_cast<int>(numFds), static_cast<int>(numInts)); |
Michael Lentine | 3880326 | 2014-10-31 15:25:03 -0700 | [diff] [blame] | 466 | if (!h) { |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 467 | width = height = stride = format = usage_deprecated = 0; |
| 468 | layerCount = 0; |
| 469 | usage = 0; |
Michael Lentine | 3880326 | 2014-10-31 15:25:03 -0700 | [diff] [blame] | 470 | handle = NULL; |
| 471 | ALOGE("unflatten: native_handle_create failed"); |
| 472 | return NO_MEMORY; |
| 473 | } |
Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 474 | memcpy(h->data, fds, numFds * sizeof(int)); |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 475 | memcpy(h->data + numFds, buf + flattenWordCount, numInts * sizeof(int)); |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 476 | handle = h; |
| 477 | } else { |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 478 | width = height = stride = format = usage_deprecated = 0; |
| 479 | layerCount = 0; |
| 480 | usage = 0; |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 481 | handle = NULL; |
| 482 | } |
| 483 | |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 484 | mId = static_cast<uint64_t>(buf[7]) << 32; |
| 485 | mId |= static_cast<uint32_t>(buf[8]); |
Dan Stoza | b1363d3 | 2014-03-28 15:10:52 -0700 | [diff] [blame] | 486 | |
Craig Donner | 6ebc46a | 2016-10-21 15:23:44 -0700 | [diff] [blame] | 487 | mGenerationNumber = static_cast<uint32_t>(buf[9]); |
Dan Stoza | 812ed06 | 2015-06-02 15:45:22 -0700 | [diff] [blame] | 488 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 489 | mOwner = ownHandle; |
Jamie Gennis | 309d3bb | 2010-10-07 13:46:55 -0700 | [diff] [blame] | 490 | |
| 491 | if (handle != 0) { |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 492 | buffer_handle_t importedHandle; |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 493 | status_t err = mBufferMapper.importBuffer(handle, uint32_t(width), uint32_t(height), |
| 494 | uint32_t(layerCount), format, usage, uint32_t(stride), &importedHandle); |
Jamie Gennis | d69097f | 2012-08-30 13:28:23 -0700 | [diff] [blame] | 495 | if (err != NO_ERROR) { |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 496 | width = height = stride = format = usage_deprecated = 0; |
| 497 | layerCount = 0; |
| 498 | usage = 0; |
Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame] | 499 | handle = NULL; |
Mathias Agopian | cb496ac | 2017-05-22 14:21:00 -0700 | [diff] [blame] | 500 | ALOGE("unflatten: registerBuffer failed: %s (%d)", strerror(-err), err); |
Jamie Gennis | d69097f | 2012-08-30 13:28:23 -0700 | [diff] [blame] | 501 | return err; |
| 502 | } |
Chia-I Wu | cb8405e | 2017-04-17 15:20:19 -0700 | [diff] [blame] | 503 | |
| 504 | native_handle_close(handle); |
| 505 | native_handle_delete(const_cast<native_handle_t*>(handle)); |
| 506 | handle = importedHandle; |
Chia-I Wu | dbbe33b | 2017-09-27 15:22:21 -0700 | [diff] [blame] | 507 | mBufferMapper.getTransportSize(handle, &mTransportNumFds, &mTransportNumInts); |
Jamie Gennis | 309d3bb | 2010-10-07 13:46:55 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Dan Stoza | eea6d68 | 2015-04-20 12:07:13 -0700 | [diff] [blame] | 510 | buffer = static_cast<void const*>(static_cast<uint8_t const*>(buffer) + sizeNeeded); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 511 | size -= sizeNeeded; |
| 512 | fds += numFds; |
| 513 | count -= numFds; |
| 514 | |
Mathias Agopian | 98e71dd | 2010-02-11 17:30:52 -0800 | [diff] [blame] | 515 | return NO_ERROR; |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Jiwen 'Steve' Cai | 2daf518 | 2018-10-16 00:14:03 -0700 | [diff] [blame] | 518 | #ifndef LIBUI_IN_VNDK |
| 519 | bool GraphicBuffer::isBufferHubBuffer() const { |
| 520 | return mBufferHubBuffer != nullptr; |
| 521 | } |
| 522 | #endif // LIBUI_IN_VNDK |
| 523 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 524 | // --------------------------------------------------------------------------- |
| 525 | |
| 526 | }; // namespace android |