Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Sean Paul | 0aee6b2 | 2016-05-10 04:08:10 -0400 | [diff] [blame] | 17 | #define LOG_TAG "hwc-platform-drm-generic" |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 18 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 19 | #include "platformdrmgeneric.h" |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 20 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 21 | #include <xf86drm.h> |
| 22 | #include <xf86drmMode.h> |
| 23 | |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 24 | #include <cutils/properties.h> |
John Stultz | d12274d | 2018-04-02 20:57:21 -0700 | [diff] [blame] | 25 | #include <gralloc_handle.h> |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 26 | #include <hardware/gralloc.h> |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 27 | #include <log/log.h> |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | #ifdef USE_DRM_GENERIC_IMPORTER |
| 32 | // static |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 33 | Importer *Importer::CreateInstance(DrmDevice *drm) { |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 34 | DrmGenericImporter *importer = new DrmGenericImporter(drm); |
| 35 | if (!importer) |
| 36 | return NULL; |
| 37 | |
| 38 | int ret = importer->Init(); |
| 39 | if (ret) { |
| 40 | ALOGE("Failed to initialize the nv importer %d", ret); |
| 41 | delete importer; |
| 42 | return NULL; |
| 43 | } |
| 44 | return importer; |
| 45 | } |
| 46 | #endif |
| 47 | |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 48 | DrmGenericImporter::DrmGenericImporter(DrmDevice *drm) |
| 49 | : drm_(drm), exclude_non_hwfb_(false) { |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | DrmGenericImporter::~DrmGenericImporter() { |
| 53 | } |
| 54 | |
| 55 | int DrmGenericImporter::Init() { |
| 56 | int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, |
| 57 | (const hw_module_t **)&gralloc_); |
| 58 | if (ret) { |
| 59 | ALOGE("Failed to open gralloc module"); |
| 60 | return ret; |
| 61 | } |
Mykhailo Sopiha | ad43886 | 2019-06-06 14:45:27 +0300 | [diff] [blame] | 62 | |
| 63 | ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name, |
| 64 | gralloc_->common.author); |
| 65 | |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 66 | char exclude_non_hwfb_prop[PROPERTY_VALUE_MAX]; |
Jason Macnak | f1af957 | 2020-08-20 11:49:51 -0700 | [diff] [blame] | 67 | property_get("vendor.hwc.drm.exclude_non_hwfb_imports", exclude_non_hwfb_prop, |
| 68 | "0"); |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 69 | exclude_non_hwfb_ = static_cast<bool>(strncmp(exclude_non_hwfb_prop, "0", 1)); |
| 70 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
Roman Stratiienko | fbf5c0c | 2020-08-24 11:27:48 +0300 | [diff] [blame] | 74 | enum chroma_order { |
| 75 | YCbCr, |
| 76 | YCrCb, |
| 77 | }; |
| 78 | |
| 79 | struct droid_yuv_format { |
| 80 | /* Lookup keys */ |
| 81 | int native; /* HAL_PIXEL_FORMAT_ */ |
| 82 | enum chroma_order chroma_order; /* chroma order is {Cb, Cr} or {Cr, Cb} */ |
| 83 | int chroma_step; /* Distance in bytes between subsequent chroma pixels. */ |
| 84 | |
| 85 | /* Result */ |
| 86 | int fourcc; /* DRM_FORMAT_ */ |
| 87 | }; |
| 88 | |
| 89 | /* The following table is used to look up a DRI image FourCC based |
| 90 | * on native format and information contained in android_ycbcr struct. */ |
| 91 | static const struct droid_yuv_format droid_yuv_formats[] = { |
| 92 | /* Native format, YCrCb, Chroma step, DRI image FourCC */ |
| 93 | {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12}, |
| 94 | {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420}, |
| 95 | {HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420}, |
| 96 | {HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420}, |
| 97 | /* HACK: See droid_create_image_from_prime_fds() and |
| 98 | * https://issuetracker.google.com/32077885. */ |
| 99 | {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12}, |
| 100 | {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420}, |
| 101 | {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420}, |
| 102 | {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV}, |
| 103 | {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888}, |
| 104 | }; |
| 105 | |
| 106 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 107 | |
| 108 | static int get_fourcc_yuv(int native, enum chroma_order chroma_order, |
| 109 | int chroma_step) { |
| 110 | for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i) |
| 111 | if (droid_yuv_formats[i].native == native && |
| 112 | droid_yuv_formats[i].chroma_order == chroma_order && |
| 113 | droid_yuv_formats[i].chroma_step == chroma_step) |
| 114 | return droid_yuv_formats[i].fourcc; |
| 115 | |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | static bool is_yuv(int native) { |
| 120 | for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i) |
| 121 | if (droid_yuv_formats[i].native == native) |
| 122 | return true; |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | bool DrmGenericImporter::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle, |
| 128 | hwc_drm_bo_t *bo) { |
| 129 | struct android_ycbcr ycbcr; |
| 130 | enum chroma_order chroma_order; |
| 131 | int ret; |
| 132 | |
| 133 | if (!gralloc_->lock_ycbcr) { |
| 134 | static std::once_flag once; |
| 135 | std::call_once(once, |
| 136 | []() { ALOGW("Gralloc does not support lock_ycbcr()"); }); |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | memset(&ycbcr, 0, sizeof(ycbcr)); |
| 141 | ret = gralloc_->lock_ycbcr(gralloc_, handle, 0, 0, 0, 0, 0, &ycbcr); |
| 142 | if (ret) { |
| 143 | ALOGW("gralloc->lock_ycbcr failed: %d", ret); |
| 144 | return false; |
| 145 | } |
| 146 | gralloc_->unlock(gralloc_, handle); |
| 147 | |
| 148 | /* When lock_ycbcr's usage argument contains no SW_READ/WRITE flags |
| 149 | * it will return the .y/.cb/.cr pointers based on a NULL pointer, |
| 150 | * so they can be interpreted as offsets. */ |
| 151 | bo->offsets[0] = (size_t)ycbcr.y; |
| 152 | /* We assume here that all the planes are located in one DMA-buf. */ |
| 153 | if ((size_t)ycbcr.cr < (size_t)ycbcr.cb) { |
| 154 | chroma_order = YCrCb; |
| 155 | bo->offsets[1] = (size_t)ycbcr.cr; |
| 156 | bo->offsets[2] = (size_t)ycbcr.cb; |
| 157 | } else { |
| 158 | chroma_order = YCbCr; |
| 159 | bo->offsets[1] = (size_t)ycbcr.cb; |
| 160 | bo->offsets[2] = (size_t)ycbcr.cr; |
| 161 | } |
| 162 | |
| 163 | /* .ystride is the line length (in bytes) of the Y plane, |
| 164 | * .cstride is the line length (in bytes) of any of the remaining |
| 165 | * Cb/Cr/CbCr planes, assumed to be the same for Cb and Cr for fully |
| 166 | * planar formats. */ |
| 167 | bo->pitches[0] = ycbcr.ystride; |
| 168 | bo->pitches[1] = bo->pitches[2] = ycbcr.cstride; |
| 169 | |
| 170 | /* .chroma_step is the byte distance between the same chroma channel |
| 171 | * values of subsequent pixels, assumed to be the same for Cb and Cr. */ |
| 172 | bo->format = get_fourcc_yuv(bo->hal_format, chroma_order, ycbcr.chroma_step); |
| 173 | if (bo->format == -1) { |
| 174 | ALOGW( |
| 175 | "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = " |
| 176 | "%d", |
| 177 | bo->hal_format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", |
| 178 | (int)ycbcr.chroma_step); |
| 179 | return false; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * Since this is EGL_NATIVE_BUFFER_ANDROID don't assume that |
| 184 | * the single-fd case cannot happen. So handle eithe single |
| 185 | * fd or fd-per-plane case: |
| 186 | */ |
| 187 | if (num_fds == 1) { |
| 188 | bo->prime_fds[2] = bo->prime_fds[1] = bo->prime_fds[0]; |
| 189 | } else { |
| 190 | int expected_planes = (ycbcr.chroma_step == 2) ? 2 : 3; |
| 191 | if (num_fds != expected_planes) |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | return true; |
| 196 | } |
| 197 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 198 | uint32_t DrmGenericImporter::ConvertHalFormatToDrm(uint32_t hal_format) { |
| 199 | switch (hal_format) { |
| 200 | case HAL_PIXEL_FORMAT_RGB_888: |
| 201 | return DRM_FORMAT_BGR888; |
| 202 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 203 | return DRM_FORMAT_ARGB8888; |
| 204 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 205 | return DRM_FORMAT_XBGR8888; |
| 206 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 207 | return DRM_FORMAT_ABGR8888; |
| 208 | case HAL_PIXEL_FORMAT_RGB_565: |
| 209 | return DRM_FORMAT_BGR565; |
| 210 | case HAL_PIXEL_FORMAT_YV12: |
| 211 | return DRM_FORMAT_YVU420; |
| 212 | default: |
| 213 | ALOGE("Cannot convert hal format to drm format %u", hal_format); |
Roman Stratiienko | f63726c | 2019-11-06 15:03:12 +0200 | [diff] [blame] | 214 | return DRM_FORMAT_INVALID; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
John Stultz | a451483 | 2018-08-24 16:27:36 -0700 | [diff] [blame] | 218 | uint32_t DrmGenericImporter::DrmFormatToBitsPerPixel(uint32_t drm_format) { |
| 219 | switch (drm_format) { |
| 220 | case DRM_FORMAT_ARGB8888: |
| 221 | case DRM_FORMAT_XBGR8888: |
| 222 | case DRM_FORMAT_ABGR8888: |
| 223 | return 32; |
| 224 | case DRM_FORMAT_BGR888: |
| 225 | return 24; |
| 226 | case DRM_FORMAT_BGR565: |
| 227 | return 16; |
| 228 | case DRM_FORMAT_YVU420: |
| 229 | return 12; |
| 230 | default: |
| 231 | ALOGE("Cannot convert hal format %u to bpp (returning 32)", drm_format); |
| 232 | return 32; |
| 233 | } |
| 234 | } |
| 235 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 236 | int DrmGenericImporter::ConvertBoInfo(buffer_handle_t handle, |
| 237 | hwc_drm_bo_t *bo) { |
John Stultz | d12274d | 2018-04-02 20:57:21 -0700 | [diff] [blame] | 238 | gralloc_handle_t *gr_handle = gralloc_handle(handle); |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 239 | if (!gr_handle) |
| 240 | return -EINVAL; |
| 241 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 242 | bo->width = gr_handle->width; |
| 243 | bo->height = gr_handle->height; |
John Stultz | 616fb22 | 2018-08-24 16:08:57 -0700 | [diff] [blame] | 244 | bo->hal_format = gr_handle->format; |
Roman Stratiienko | fbf5c0c | 2020-08-24 11:27:48 +0300 | [diff] [blame] | 245 | |
| 246 | #if GRALLOC_HANDLE_VERSION < 4 |
| 247 | #warning libdrm >= v2.4.97 is required to support modifiers |
| 248 | #endif |
| 249 | #if GRALLOC_HANDLE_VERSION == 4 |
| 250 | bo->modifiers[0] = gr_handle->modifier; |
| 251 | bo->with_modifiers = gr_handle->modifier != DRM_FORMAT_MOD_NONE && |
| 252 | gr_handle->modifier != DRM_FORMAT_MOD_INVALID; |
| 253 | #endif |
| 254 | |
Rob Herring | aeccd89 | 2017-10-06 17:20:05 -0500 | [diff] [blame] | 255 | bo->usage = gr_handle->usage; |
Roman Stratiienko | fbf5c0c | 2020-08-24 11:27:48 +0300 | [diff] [blame] | 256 | bo->prime_fds[0] = gr_handle->prime_fd; |
| 257 | |
| 258 | if (is_yuv(gr_handle->format)) { |
| 259 | if (!GetYuvPlaneInfo(handle->numFds, handle, bo)) |
| 260 | return -EINVAL; |
| 261 | } else { |
| 262 | bo->pitches[0] = gr_handle->stride; |
| 263 | bo->offsets[0] = 0; |
| 264 | bo->format = ConvertHalFormatToDrm(gr_handle->format); |
| 265 | if (bo->format == DRM_FORMAT_INVALID) |
| 266 | return -EINVAL; |
| 267 | } |
| 268 | |
John Stultz | a451483 | 2018-08-24 16:27:36 -0700 | [diff] [blame] | 269 | bo->pixel_stride = (gr_handle->stride * 8) / |
| 270 | DrmFormatToBitsPerPixel(bo->format); |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 271 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | int DrmGenericImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { |
| 276 | memset(bo, 0, sizeof(hwc_drm_bo_t)); |
| 277 | |
| 278 | int ret = ConvertBoInfo(handle, bo); |
| 279 | if (ret) |
| 280 | return ret; |
| 281 | |
| 282 | ret = drmPrimeFDToHandle(drm_->fd(), bo->prime_fds[0], &bo->gem_handles[0]); |
| 283 | if (ret) { |
| 284 | ALOGE("failed to import prime fd %d ret=%d", bo->prime_fds[0], ret); |
| 285 | return ret; |
| 286 | } |
| 287 | |
| 288 | for (int i = 1; i < HWC_DRM_BO_MAX_PLANES; i++) { |
| 289 | int fd = bo->prime_fds[i]; |
| 290 | if (fd != 0) { |
| 291 | if (fd != bo->prime_fds[0]) { |
| 292 | ALOGE("Multiplanar FBs are not supported by this version of composer"); |
| 293 | return -ENOTSUP; |
| 294 | } |
| 295 | bo->gem_handles[i] = bo->gem_handles[0]; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (!bo->with_modifiers) |
| 300 | ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format, |
| 301 | bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, |
| 302 | 0); |
| 303 | else |
| 304 | ret = drmModeAddFB2WithModifiers(drm_->fd(), bo->width, bo->height, |
| 305 | bo->format, bo->gem_handles, bo->pitches, |
| 306 | bo->offsets, bo->modifiers, &bo->fb_id, |
| 307 | bo->modifiers[0] ? DRM_MODE_FB_MODIFIERS |
| 308 | : 0); |
| 309 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 310 | if (ret) { |
| 311 | ALOGE("could not create drm fb %d", ret); |
| 312 | return ret; |
| 313 | } |
| 314 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 315 | ImportHandle(bo->gem_handles[0]); |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 316 | |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 317 | return ret; |
| 318 | } |
| 319 | |
| 320 | int DrmGenericImporter::ReleaseBuffer(hwc_drm_bo_t *bo) { |
| 321 | if (bo->fb_id) |
| 322 | if (drmModeRmFB(drm_->fd(), bo->fb_id)) |
| 323 | ALOGE("Failed to rm fb"); |
| 324 | |
John Stultz | ee18b0e | 2018-08-27 10:53:07 -0700 | [diff] [blame] | 325 | for (int i = 0; i < HWC_DRM_BO_MAX_PLANES; i++) { |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 326 | if (!bo->gem_handles[i]) |
| 327 | continue; |
| 328 | |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 329 | if (ReleaseHandle(bo->gem_handles[i])) { |
| 330 | ALOGE("Failed to release gem handle %d", bo->gem_handles[i]); |
John Stultz | 53cb4ef | 2018-05-31 17:46:50 -0700 | [diff] [blame] | 331 | } else { |
John Stultz | ee18b0e | 2018-08-27 10:53:07 -0700 | [diff] [blame] | 332 | for (int j = i + 1; j < HWC_DRM_BO_MAX_PLANES; j++) |
John Stultz | 53cb4ef | 2018-05-31 17:46:50 -0700 | [diff] [blame] | 333 | if (bo->gem_handles[j] == bo->gem_handles[i]) |
| 334 | bo->gem_handles[j] = 0; |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 335 | bo->gem_handles[i] = 0; |
John Stultz | 53cb4ef | 2018-05-31 17:46:50 -0700 | [diff] [blame] | 336 | } |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 337 | } |
| 338 | return 0; |
| 339 | } |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 340 | |
Alexey Firago | 18ec688 | 2018-11-21 23:47:05 +0300 | [diff] [blame] | 341 | bool DrmGenericImporter::CanImportBuffer(buffer_handle_t handle) { |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 342 | hwc_drm_bo_t bo; |
| 343 | |
| 344 | int ret = ConvertBoInfo(handle, &bo); |
| 345 | if (ret) |
Alexey Firago | 18ec688 | 2018-11-21 23:47:05 +0300 | [diff] [blame] | 346 | return false; |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 347 | |
Roman Stratiienko | 4163efc | 2019-12-06 12:30:28 +0200 | [diff] [blame] | 348 | if (bo.prime_fds[0] == 0) |
| 349 | return false; |
| 350 | |
| 351 | if (exclude_non_hwfb_ && !(bo.usage & GRALLOC_USAGE_HW_FB)) |
| 352 | return false; |
Mykhailo Sopiha | 1693bc3 | 2019-07-08 18:28:56 +0300 | [diff] [blame] | 353 | |
Alexey Firago | 18ec688 | 2018-11-21 23:47:05 +0300 | [diff] [blame] | 354 | return true; |
| 355 | } |
| 356 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 357 | std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { |
Sean Paul | 4c4646e | 2016-05-10 04:19:24 -0400 | [diff] [blame] | 358 | std::unique_ptr<Planner> planner(new Planner); |
| 359 | planner->AddStage<PlanStageGreedy>(); |
| 360 | return planner; |
| 361 | } |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 362 | |
| 363 | int DrmGenericImporter::ImportHandle(uint32_t gem_handle) { |
| 364 | gem_refcount_[gem_handle]++; |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | int DrmGenericImporter::ReleaseHandle(uint32_t gem_handle) { |
| 370 | if (--gem_refcount_[gem_handle]) |
| 371 | return 0; |
| 372 | |
| 373 | gem_refcount_.erase(gem_handle); |
| 374 | |
| 375 | return CloseHandle(gem_handle); |
| 376 | } |
| 377 | |
| 378 | int DrmGenericImporter::CloseHandle(uint32_t gem_handle) { |
| 379 | struct drm_gem_close gem_close; |
| 380 | |
| 381 | memset(&gem_close, 0, sizeof(gem_close)); |
| 382 | |
| 383 | gem_close.handle = gem_handle; |
| 384 | int ret = drmIoctl(drm_->fd(), DRM_IOCTL_GEM_CLOSE, &gem_close); |
| 385 | if (ret) |
| 386 | ALOGE("Failed to close gem handle %d %d", gem_handle, ret); |
| 387 | |
| 388 | return ret; |
| 389 | } |
Sean Paul | da6270d | 2015-06-01 14:11:52 -0400 | [diff] [blame] | 390 | } |