author | baocheng sun <baocheng.sun@amlogic.com> | 2020-01-03 06:52:38 (GMT) |
---|---|---|
committer | sky zhou <sky.zhou@amlogic.com> | 2020-05-21 11:49:30 (GMT) |
commit | 97285ba4f268891766a3fcca2b61a19c9fa72790 (patch) | |
tree | 4cafe2025eec2a50b837d882738399ad269bbb44 | |
parent | 9718b398e2943a557b7295d3ecf0fd2d740fe2b2 (diff) | |
download | hwcomposer-97285ba4f268891766a3fcca2b61a19c9fa72790.zip hwcomposer-97285ba4f268891766a3fcca2b61a19c9fa72790.tar.gz hwcomposer-97285ba4f268891766a3fcca2b61a19c9fa72790.tar.bz2 |
hwc: set uvm device [1/1]
PD#SWPL-18878
Problem:
It will stuck 1s and show black screen during playing movie
when press power key to sleep.
Solution:
set uvm device
Verify:
newton
Change-Id: I5bd37f2af6e03b0d4f985d921f6abdc692bb2b30
Signed-off-by: baocheng sun <baocheng.sun@amlogic.com>
3 files changed, 105 insertions, 10 deletions
diff --git a/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.cpp b/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.cpp index d851105..e6e38a9 100644 --- a/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.cpp +++ b/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.cpp @@ -10,8 +10,9 @@ #include "MultiplanesWithDiComposition.h" #include <DrmTypes.h> #include <MesonLog.h> +#include <sys/ioctl.h> #include "HwcVideoPlane.h" - +#include "am_gralloc_ext.h" #define LEGACY_VIDEO_MODE_SWITCH 0 // Only use in current device (Only one legacy video plane) @@ -41,12 +42,28 @@ #define IS_FB_COMPOSED(fb) \ (fb->mZorder >= mMinComposerZorder && fb->mZorder <= mMaxComposerZorder) +#define UVM_DEV_PATH "/dev/uvm" +#define UVM_IOC_MAGIC 'U' +#define UVM_IOC_SET_FD _IOWR(UVM_IOC_MAGIC, 3, struct uvm_fd_data) + +struct uvm_fd_data { + int fd; + int commit_display; +}; /* Constructor function */ -MultiplanesWithDiComposition::MultiplanesWithDiComposition() {} +MultiplanesWithDiComposition::MultiplanesWithDiComposition() { + mUVMFd = open(UVM_DEV_PATH, O_RDONLY | O_CLOEXEC); + if (mUVMFd < 0) { + MESON_LOGE("open uvm device error"); + } +} /* Deconstructor function */ -MultiplanesWithDiComposition::~MultiplanesWithDiComposition() {} +MultiplanesWithDiComposition::~MultiplanesWithDiComposition() { + if (mUVMFd >= 0) + close(mUVMFd); +} /* Clean FrameBuffer, Composer and Plane. */ void MultiplanesWithDiComposition::init() { @@ -196,6 +213,31 @@ int MultiplanesWithDiComposition::applyCompositionFlags() { return 0; } +/* handle uvm, */ +int MultiplanesWithDiComposition::handleUVM() { + if (mUVMFd > 0) { + std::shared_ptr<DrmFramebuffer> fb; + auto fbIt = mFramebuffers.begin(); + struct uvm_fd_data fd_data; + + for (; fbIt != mFramebuffers.end(); ++fbIt) { + fb = fbIt->second; + + if (am_gralloc_is_uvm_dma_buffer(fb->mBufferHandle)) { + fd_data.fd = am_gralloc_get_buffer_fd(fb->mBufferHandle); + fd_data.commit_display = + (fb->mCompositionType == MESON_COMPOSITION_DUMMY) ? 0 : 1; + + if (ioctl(mUVMFd, UVM_IOC_SET_FD, &fd_data) != 0) { + MESON_LOGE("setUVM fd data ioctl error %s", strerror(errno)); + return -1; + } + } + } + } + return 0; +} + /* Delete dummy and video Fbs, then pickout OSD Fbs. */ int MultiplanesWithDiComposition::pickoutOsdFbs() { std::shared_ptr<DrmFramebuffer> fb; @@ -1138,6 +1180,9 @@ int MultiplanesWithDiComposition::decideComposition() { /* handle HDR mode, hide secure layer, and force client. */ applyCompositionFlags(); + /* handle uvm */ + handleUVM(); + /* Remove dummy and video Fbs for later osd composition. * Pickout OSD Fbs. * Save client flag. diff --git a/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.h b/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.h index 4e8853e..a5e20ae 100644 --- a/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.h +++ b/composition/simplestrategy/MultiplanesWithDiComposition/MultiplanesWithDiComposition.h @@ -86,6 +86,7 @@ protected: int handleOsdCompostionWithVideo(); void handleDiComposition(); int32_t compareFbScale(drm_rect_t & aSrc, drm_rect_t & aDst, drm_rect_t & bSrc, drm_rect_t & bDst); + int handleUVM(); protected: struct DisplayPair { @@ -139,6 +140,9 @@ protected: std::shared_ptr<IComposer> mDiComposer; std::vector<std::shared_ptr<DrmFramebuffer>> mDiInFbs; std::vector<std::shared_ptr<DrmFramebuffer>> mDiOutFbs; + + /* Use for UVM */ + int mUVMFd; }; diff --git a/service/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h b/service/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h index ba864f4..aab7d59 100644 --- a/service/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h +++ b/service/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h @@ -29,8 +29,13 @@ #include <android/hardware/graphics/mapper/3.0/IMapper.h> #include <log/log.h> +#include <hwbinder/IPCThreadState.h> #include "am_gralloc_ext.h" +#define UVM_DEV_PATH "/dev/uvm" +#define UVM_IOC_MAGIC 'U' +#define UVM_IOC_SET_PID _IOWR(UVM_IOC_MAGIC, 2, struct uvm_pid_data) + namespace android { namespace hardware { namespace graphics { @@ -38,6 +43,47 @@ namespace composer { namespace V2_1 { namespace hal { +class ComposerUVMHandle { +public: + ComposerUVMHandle() : mFd(-1) {} + + ~ComposerUVMHandle() { + if (mFd >=0) + close(mFd); + } + + int setUVM() { + ::android::hardware::IPCThreadState *ipc = ::android::hardware::IPCThreadState::self(); + const pid_t pid = ipc->getCallingPid(); + + struct uvm_pid_data { + int pid; + } pid_data; + + pid_data.pid = pid; + + ALOGD("setUVM with pid %d", pid); + if (ioctl(mFd, UVM_IOC_SET_PID, &pid_data) != 0) { + ALOGE("setUVM pid %d ioctl error %s", pid, strerror(errno)); + return -1; + } + return 0; + } + + bool init() { + mFd = open(UVM_DEV_PATH, O_RDWR); + if (mFd <= 0) { + ALOGE("open uvm device error"); + return false; + } + setUVM(); + return true; + } + +private: + int mFd; +}; + // wrapper for IMapper to import buffers and sideband streams class ComposerHandleImporter { public: @@ -139,8 +185,6 @@ class ComposerHandleCache { DRM_FB_RENDER = 1, // contiguous buffer, can be used for scanout. DRM_FB_SCANOUT, - // no image data, fill with color. - DRM_FB_DIM, // video type, used for video. DRM_FB_VIDEO, DRM_FB_VIDEO_OVERLAY, @@ -239,18 +283,14 @@ class ComposerHandleCache { mFbType = DrmFbType::DRM_FB_VIDEO; } else if (am_gralloc_is_overlay_buffer(handle)) { mFbType = DrmFbType::DRM_FB_VIDEO_OVERLAY; - } else if (am_gralloc_get_width(handle) <= 1 && am_gralloc_get_height(handle) <= 1) { - mFbType = DrmFbType::DRM_FB_DIM; } else if (am_gralloc_is_coherent_buffer(handle)) { if (mFbType == DrmFbType::DRM_FB_VIDEO || - mFbType == DrmFbType::DRM_FB_DIM || mFbType == DrmFbType::DRM_FB_VIDEO_OVERLAY) { changed = true; } mFbType = DrmFbType::DRM_FB_SCANOUT; } else { if (mFbType == DrmFbType::DRM_FB_VIDEO || - mFbType == DrmFbType::DRM_FB_DIM || mFbType == DrmFbType::DRM_FB_VIDEO_OVERLAY) { changed = true; } @@ -406,7 +446,12 @@ class ComposerResources { ComposerResources() = default; virtual ~ComposerResources() = default; - bool init() { return mImporter.init(); } + bool init() { + bool result = mImporter.init(); + mUVMHandle.init(); + + return result; + } using RemoveDisplay = std::function<void(Display display, bool isVirtual, const std::vector<Layer>& layers)>; @@ -546,6 +591,7 @@ class ComposerResources { } ComposerHandleImporter mImporter; + ComposerUVMHandle mUVMHandle; std::mutex mDisplayResourcesMutex; std::unordered_map<Display, std::unique_ptr<ComposerDisplayResource>> mDisplayResources; |