/* * Copyright (c) 2020 Amlogic, Inc. All rights reserved. * * This source code is subject to the terms and conditions defined in the * file 'LICENSE' which is part of this source code package. * * Description: */ #include #include #include std::map DrmBoBase::mHndRefs; DrmBoBase::DrmBoBase(int32_t fd) { mDrmFd = fd; fbId = 0; width = 0; height = 0; format = 0; alpha = 0; blend = 0; z = 0; inFence = -1; color = 0; secureEnable = 0; memset(&srcRect, 0, sizeof(srcRect)); memset(&crtcRect, 0, sizeof(crtcRect)); } DrmBoBase::~DrmBoBase() { release(); } void DrmBoBase::refHandle(uint32_t hnd) { std::lock_guard lock(mMutex); mHndRefs[hnd] ++; } void DrmBoBase::unrefHandle(uint32_t hnd) { std::lock_guard lock(mMutex); if (--mHndRefs[hnd]) return ; struct drm_gem_close closeArg; memset(&closeArg, 0, sizeof(drm_gem_close)); closeArg.handle = hnd; int ret = drmIoctl(mDrmFd, DRM_IOCTL_GEM_CLOSE, &closeArg); if (ret != 0) MESON_LOGE("DRM_IOCTL_GEM_CLOSE failed hnd[%d]ret[%d]", hnd, ret); } int32_t DrmBoBase::import(std::shared_ptr /*fb*/) { return 0; } int32_t DrmBoBase::setPresentFence(int32_t fenceFd) { mPresentFence.reset(new DrmFence(fenceFd)); return 0; } int32_t DrmBoBase::release() { if (fbId == 0) return 0; mPresentFence.reset(); int ret = 0; if (inFence >=0) close(inFence); inFence = -1; ret = drmModeRmFB(mDrmFd, fbId); if (ret !=0) { MESON_LOGE("drmModeRmFB failed fb[%d]ret[%d]", fbId, ret); return ret; } for (int i = 0; i < BUF_PLANE_NUM; i++) { if (!handles[i]) continue; for (int j = i + 1; j < BUF_PLANE_NUM; j++) if (handles[j] == handles[i]) handles[j] = 0; unrefHandle(handles[i]); handles[i] = 0; } return ret; }