| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -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 | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 17 | #define LOG_TAG "GraphicBufferMapper" | 
| Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 20 |  | 
|  | 21 | #include <stdint.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 22 | #include <errno.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 23 |  | 
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 24 | // We would eliminate the non-conforming zero-length array, but we can't since | 
|  | 25 | // this is effectively included from the Linux kernel | 
|  | 26 | #pragma clang diagnostic push | 
|  | 27 | #pragma clang diagnostic ignored "-Wzero-length-array" | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 28 | #include <sync/sync.h> | 
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 29 | #pragma clang diagnostic pop | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 30 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | #include <utils/Errors.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <utils/Log.h> | 
| Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 33 | #include <utils/Trace.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 35 | #include <ui/Gralloc1On0Adapter.h> | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 36 | #include <ui/GrallocMapper.h> | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 37 | #include <ui/GraphicBufferMapper.h> | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 38 | #include <ui/Rect.h> | 
|  | 39 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 40 | #include <system/graphics.h> | 
| Mathias Agopian | 8b765b7 | 2009-04-10 20:34:46 -0700 | [diff] [blame] | 41 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 42 | namespace android { | 
|  | 43 | // --------------------------------------------------------------------------- | 
|  | 44 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 45 | ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) | 
| Mathias Agopian | 4243e66 | 2009-04-15 18:34:24 -0700 | [diff] [blame] | 46 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 47 | GraphicBufferMapper::GraphicBufferMapper() | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 48 | : mMapper(std::make_unique<const Gralloc2::Mapper>()) | 
|  | 49 | { | 
|  | 50 | if (!mMapper->valid()) { | 
|  | 51 | mLoader = std::make_unique<Gralloc1::Loader>(); | 
|  | 52 | mDevice = mLoader->getDevice(); | 
|  | 53 | } | 
|  | 54 | } | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 55 |  | 
|  | 56 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 57 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 58 | status_t GraphicBufferMapper::registerBuffer(buffer_handle_t handle) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 59 | { | 
| Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 60 | ATRACE_CALL(); | 
| Mathias Agopian | 0a75781 | 2010-12-08 16:40:01 -0800 | [diff] [blame] | 61 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 62 | gralloc1_error_t error; | 
|  | 63 | if (mMapper->valid()) { | 
|  | 64 | error = static_cast<gralloc1_error_t>(mMapper->retain(handle)); | 
|  | 65 | } else { | 
|  | 66 | error = mDevice->retain(handle); | 
|  | 67 | } | 
|  | 68 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 69 | ALOGW_IF(error != GRALLOC1_ERROR_NONE, "registerBuffer(%p) failed: %d", | 
|  | 70 | handle, error); | 
| Mathias Agopian | 0a75781 | 2010-12-08 16:40:01 -0800 | [diff] [blame] | 71 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 72 | return error; | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | status_t GraphicBufferMapper::registerBuffer(const GraphicBuffer* buffer) | 
|  | 76 | { | 
|  | 77 | ATRACE_CALL(); | 
|  | 78 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 79 | gralloc1_error_t error; | 
|  | 80 | if (mMapper->valid()) { | 
|  | 81 | error = static_cast<gralloc1_error_t>( | 
|  | 82 | mMapper->retain(buffer->getNativeBuffer()->handle)); | 
|  | 83 | } else { | 
|  | 84 | error = mDevice->retain(buffer); | 
|  | 85 | } | 
|  | 86 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 87 | ALOGW_IF(error != GRALLOC1_ERROR_NONE, "registerBuffer(%p) failed: %d", | 
|  | 88 | buffer->getNativeBuffer()->handle, error); | 
|  | 89 |  | 
|  | 90 | return error; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 93 | status_t GraphicBufferMapper::unregisterBuffer(buffer_handle_t handle) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 94 | { | 
| Mathias Agopian | cf56319 | 2012-02-29 20:43:29 -0800 | [diff] [blame] | 95 | ATRACE_CALL(); | 
| Mathias Agopian | 0a75781 | 2010-12-08 16:40:01 -0800 | [diff] [blame] | 96 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 97 | gralloc1_error_t error; | 
|  | 98 | if (mMapper->valid()) { | 
|  | 99 | mMapper->release(handle); | 
|  | 100 | error = GRALLOC1_ERROR_NONE; | 
|  | 101 | } else { | 
|  | 102 | error = mDevice->release(handle); | 
|  | 103 | } | 
|  | 104 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 105 | ALOGW_IF(error != GRALLOC1_ERROR_NONE, "unregisterBuffer(%p): failed %d", | 
|  | 106 | handle, error); | 
| Mathias Agopian | 0a75781 | 2010-12-08 16:40:01 -0800 | [diff] [blame] | 107 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 108 | return error; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 109 | } | 
|  | 110 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 111 | static inline gralloc1_rect_t asGralloc1Rect(const Rect& rect) { | 
|  | 112 | gralloc1_rect_t outRect{}; | 
|  | 113 | outRect.left = rect.left; | 
|  | 114 | outRect.top = rect.top; | 
|  | 115 | outRect.width = rect.width(); | 
|  | 116 | outRect.height = rect.height(); | 
|  | 117 | return outRect; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 118 | } | 
|  | 119 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 120 | status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage, | 
|  | 121 | const Rect& bounds, void** vaddr) | 
| Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 122 | { | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 123 | return lockAsync(handle, usage, bounds, vaddr, -1); | 
|  | 124 | } | 
| Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 125 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 126 | status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, uint32_t usage, | 
|  | 127 | const Rect& bounds, android_ycbcr *ycbcr) | 
|  | 128 | { | 
|  | 129 | return lockAsyncYCbCr(handle, usage, bounds, ycbcr, -1); | 
| Eino-Ville Talvala | c43946b | 2013-05-04 18:07:43 -0700 | [diff] [blame] | 130 | } | 
|  | 131 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 132 | status_t GraphicBufferMapper::unlock(buffer_handle_t handle) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 133 | { | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 134 | int32_t fenceFd = -1; | 
|  | 135 | status_t error = unlockAsync(handle, &fenceFd); | 
|  | 136 | if (error == NO_ERROR) { | 
|  | 137 | sync_wait(fenceFd, -1); | 
|  | 138 | close(fenceFd); | 
|  | 139 | } | 
|  | 140 | return error; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 143 | status_t GraphicBufferMapper::lockAsync(buffer_handle_t handle, | 
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 144 | uint32_t usage, const Rect& bounds, void** vaddr, int fenceFd) | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 145 | { | 
|  | 146 | ATRACE_CALL(); | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 147 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 148 | gralloc1_rect_t accessRegion = asGralloc1Rect(bounds); | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 149 | gralloc1_error_t error; | 
|  | 150 | if (mMapper->valid()) { | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 151 | const Gralloc2::IMapper::Rect& accessRect = | 
|  | 152 | *reinterpret_cast<Gralloc2::IMapper::Rect*>(&accessRegion); | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 153 | error = static_cast<gralloc1_error_t>(mMapper->lock( | 
| Chia-I Wu | 67e376d | 2016-12-19 11:36:22 +0800 | [diff] [blame] | 154 | handle, usage, usage, accessRect, fenceFd, vaddr)); | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 155 | } else { | 
|  | 156 | sp<Fence> fence = new Fence(fenceFd); | 
|  | 157 | error = mDevice->lock(handle, | 
|  | 158 | static_cast<gralloc1_producer_usage_t>(usage), | 
|  | 159 | static_cast<gralloc1_consumer_usage_t>(usage), | 
|  | 160 | &accessRegion, vaddr, fence); | 
|  | 161 | } | 
|  | 162 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 163 | ALOGW_IF(error != GRALLOC1_ERROR_NONE, "lock(%p, ...) failed: %d", handle, | 
|  | 164 | error); | 
|  | 165 |  | 
|  | 166 | return error; | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | static inline bool isValidYCbCrPlane(const android_flex_plane_t& plane) { | 
|  | 170 | if (plane.bits_per_component != 8) { | 
|  | 171 | ALOGV("Invalid number of bits per component: %d", | 
|  | 172 | plane.bits_per_component); | 
|  | 173 | return false; | 
|  | 174 | } | 
|  | 175 | if (plane.bits_used != 8) { | 
|  | 176 | ALOGV("Invalid number of bits used: %d", plane.bits_used); | 
|  | 177 | return false; | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 180 | bool hasValidIncrement = plane.h_increment == 1 || | 
|  | 181 | (plane.component != FLEX_COMPONENT_Y && plane.h_increment == 2); | 
|  | 182 | hasValidIncrement = hasValidIncrement && plane.v_increment > 0; | 
|  | 183 | if (!hasValidIncrement) { | 
|  | 184 | ALOGV("Invalid increment: h %d v %d", plane.h_increment, | 
|  | 185 | plane.v_increment); | 
|  | 186 | return false; | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | return true; | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 190 | } | 
|  | 191 |  | 
|  | 192 | status_t GraphicBufferMapper::lockAsyncYCbCr(buffer_handle_t handle, | 
| Dan Stoza | d318240 | 2014-11-17 12:03:59 -0800 | [diff] [blame] | 193 | uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr, int fenceFd) | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 194 | { | 
|  | 195 | ATRACE_CALL(); | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 196 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 197 | gralloc1_rect_t accessRegion = asGralloc1Rect(bounds); | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 198 |  | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 199 | std::vector<android_flex_plane_t> planes; | 
|  | 200 | android_flex_layout_t flexLayout{}; | 
|  | 201 | gralloc1_error_t error; | 
|  | 202 |  | 
|  | 203 | if (mMapper->valid()) { | 
|  | 204 | const Gralloc2::IMapper::Rect& accessRect = | 
|  | 205 | *reinterpret_cast<Gralloc2::IMapper::Rect*>(&accessRegion); | 
|  | 206 | Gralloc2::FlexLayout layout{}; | 
|  | 207 | error = static_cast<gralloc1_error_t>(mMapper->lock( | 
|  | 208 | handle, usage, usage, accessRect, fenceFd, &layout)); | 
|  | 209 |  | 
|  | 210 | if (error == GRALLOC1_ERROR_NONE) { | 
|  | 211 | planes.resize(layout.planes.size()); | 
|  | 212 | memcpy(planes.data(), layout.planes.data(), | 
|  | 213 | sizeof(planes[0]) * planes.size()); | 
|  | 214 |  | 
|  | 215 | flexLayout.format = static_cast<android_flex_format_t>( | 
|  | 216 | layout.format); | 
|  | 217 | flexLayout.num_planes = static_cast<uint32_t>(planes.size()); | 
|  | 218 | flexLayout.planes = planes.data(); | 
|  | 219 | } | 
|  | 220 | } else { | 
|  | 221 | sp<Fence> fence = new Fence(fenceFd); | 
|  | 222 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 223 | if (mDevice->hasCapability(GRALLOC1_CAPABILITY_ON_ADAPTER)) { | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 224 | error = mDevice->lockYCbCr(handle, | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 225 | static_cast<gralloc1_producer_usage_t>(usage), | 
|  | 226 | static_cast<gralloc1_consumer_usage_t>(usage), | 
|  | 227 | &accessRegion, ycbcr, fence); | 
|  | 228 | ALOGW_IF(error != GRALLOC1_ERROR_NONE, | 
|  | 229 | "lockYCbCr(%p, ...) failed: %d", handle, error); | 
|  | 230 | return error; | 
|  | 231 | } | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 232 |  | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 233 | uint32_t numPlanes = 0; | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 234 | error = mDevice->getNumFlexPlanes(handle, &numPlanes); | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 235 |  | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 236 | if (error != GRALLOC1_ERROR_NONE) { | 
|  | 237 | ALOGV("Failed to retrieve number of flex planes: %d", error); | 
|  | 238 | return error; | 
|  | 239 | } | 
|  | 240 | if (numPlanes < 3) { | 
|  | 241 | ALOGV("Not enough planes for YCbCr (%u found)", numPlanes); | 
|  | 242 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 243 | } | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 244 |  | 
| Chia-I Wu | 3166947 | 2016-12-07 14:55:24 +0800 | [diff] [blame] | 245 | planes.resize(numPlanes); | 
|  | 246 | flexLayout.num_planes = numPlanes; | 
|  | 247 | flexLayout.planes = planes.data(); | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 248 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 249 | error = mDevice->lockFlex(handle, | 
|  | 250 | static_cast<gralloc1_producer_usage_t>(usage), | 
|  | 251 | static_cast<gralloc1_consumer_usage_t>(usage), | 
|  | 252 | &accessRegion, &flexLayout, fence); | 
|  | 253 | } | 
|  | 254 |  | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 255 | if (error != GRALLOC1_ERROR_NONE) { | 
|  | 256 | ALOGW("lockFlex(%p, ...) failed: %d", handle, error); | 
|  | 257 | return error; | 
|  | 258 | } | 
|  | 259 | if (flexLayout.format != FLEX_FORMAT_YCbCr) { | 
|  | 260 | ALOGV("Unable to convert flex-format buffer to YCbCr"); | 
|  | 261 | unlock(handle); | 
|  | 262 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 263 | } | 
|  | 264 |  | 
|  | 265 | // Find planes | 
|  | 266 | auto yPlane = planes.cend(); | 
|  | 267 | auto cbPlane = planes.cend(); | 
|  | 268 | auto crPlane = planes.cend(); | 
|  | 269 | for (auto planeIter = planes.cbegin(); planeIter != planes.cend(); | 
|  | 270 | ++planeIter) { | 
|  | 271 | if (planeIter->component == FLEX_COMPONENT_Y) { | 
|  | 272 | yPlane = planeIter; | 
|  | 273 | } else if (planeIter->component == FLEX_COMPONENT_Cb) { | 
|  | 274 | cbPlane = planeIter; | 
|  | 275 | } else if (planeIter->component == FLEX_COMPONENT_Cr) { | 
|  | 276 | crPlane = planeIter; | 
|  | 277 | } | 
|  | 278 | } | 
|  | 279 | if (yPlane == planes.cend()) { | 
|  | 280 | ALOGV("Unable to find Y plane"); | 
|  | 281 | unlock(handle); | 
|  | 282 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 283 | } | 
|  | 284 | if (cbPlane == planes.cend()) { | 
|  | 285 | ALOGV("Unable to find Cb plane"); | 
|  | 286 | unlock(handle); | 
|  | 287 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 288 | } | 
|  | 289 | if (crPlane == planes.cend()) { | 
|  | 290 | ALOGV("Unable to find Cr plane"); | 
|  | 291 | unlock(handle); | 
|  | 292 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 293 | } | 
|  | 294 |  | 
|  | 295 | // Validate planes | 
|  | 296 | if (!isValidYCbCrPlane(*yPlane)) { | 
|  | 297 | ALOGV("Y plane is invalid"); | 
|  | 298 | unlock(handle); | 
|  | 299 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 300 | } | 
|  | 301 | if (!isValidYCbCrPlane(*cbPlane)) { | 
|  | 302 | ALOGV("Cb plane is invalid"); | 
|  | 303 | unlock(handle); | 
|  | 304 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 305 | } | 
|  | 306 | if (!isValidYCbCrPlane(*crPlane)) { | 
|  | 307 | ALOGV("Cr plane is invalid"); | 
|  | 308 | unlock(handle); | 
|  | 309 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 310 | } | 
|  | 311 | if (cbPlane->v_increment != crPlane->v_increment) { | 
|  | 312 | ALOGV("Cb and Cr planes have different step (%d vs. %d)", | 
|  | 313 | cbPlane->v_increment, crPlane->v_increment); | 
|  | 314 | unlock(handle); | 
|  | 315 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 316 | } | 
|  | 317 | if (cbPlane->h_increment != crPlane->h_increment) { | 
|  | 318 | ALOGV("Cb and Cr planes have different stride (%d vs. %d)", | 
|  | 319 | cbPlane->h_increment, crPlane->h_increment); | 
|  | 320 | unlock(handle); | 
|  | 321 | return GRALLOC1_ERROR_UNSUPPORTED; | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | // Pack plane data into android_ycbcr struct | 
|  | 325 | ycbcr->y = yPlane->top_left; | 
|  | 326 | ycbcr->cb = cbPlane->top_left; | 
|  | 327 | ycbcr->cr = crPlane->top_left; | 
|  | 328 | ycbcr->ystride = static_cast<size_t>(yPlane->v_increment); | 
|  | 329 | ycbcr->cstride = static_cast<size_t>(cbPlane->v_increment); | 
|  | 330 | ycbcr->chroma_step = static_cast<size_t>(cbPlane->h_increment); | 
|  | 331 |  | 
|  | 332 | return error; | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 333 | } | 
|  | 334 |  | 
|  | 335 | status_t GraphicBufferMapper::unlockAsync(buffer_handle_t handle, int *fenceFd) | 
|  | 336 | { | 
|  | 337 | ATRACE_CALL(); | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 338 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 339 | gralloc1_error_t error; | 
|  | 340 | if (mMapper->valid()) { | 
|  | 341 | *fenceFd = mMapper->unlock(handle); | 
|  | 342 | error = GRALLOC1_ERROR_NONE; | 
|  | 343 | } else { | 
|  | 344 | sp<Fence> fence = Fence::NO_FENCE; | 
|  | 345 | error = mDevice->unlock(handle, &fence); | 
|  | 346 | if (error != GRALLOC1_ERROR_NONE) { | 
|  | 347 | ALOGE("unlock(%p) failed: %d", handle, error); | 
|  | 348 | return error; | 
|  | 349 | } | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 350 |  | 
| Chia-I Wu | 9ba189d | 2016-09-22 17:13:08 +0800 | [diff] [blame] | 351 | *fenceFd = fence->dup(); | 
|  | 352 | } | 
| Dan Stoza | 8deb4da | 2016-06-01 18:21:44 -0700 | [diff] [blame] | 353 | return error; | 
| Francis Hart | 8f39601 | 2014-04-01 15:30:53 +0300 | [diff] [blame] | 354 | } | 
|  | 355 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 356 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 357 | }; // namespace android |