diff --git a/common.mk b/common.mk index 978d700f..7c847cc4 100644 --- a/common.mk +++ b/common.mk @@ -4,6 +4,16 @@ display_config_version := $(shell \ if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.1" ];\ then echo DISPLAY_CONFIG_1_1; fi) +display_config_version := $(shell \ + if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.7" ];\ + then echo DISPLAY_CONFIG_1_7; fi) +display_config_version := $(shell \ + if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.8" ];\ + then echo DISPLAY_CONFIG_1_8; fi) +display_config_version := $(shell \ + if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.9" ];\ + then echo DISPLAY_CONFIG_1_9; fi) + #Common C flags common_flags := -DDEBUG_CALC_FPS -Wno-missing-field-initializers common_flags += -Wconversion -Wall -Werror -std=c++14 @@ -16,6 +26,22 @@ ifeq ($(display_config_version), DISPLAY_CONFIG_1_1) common_flags += -DDISPLAY_CONFIG_1_1 endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_7) + common_flags += -DDISPLAY_CONFIG_1_7 \ + -DDISPLAY_CONFIG_1_6 -DDISPLAY_CONFIG_1_5 -DDISPLAY_CONFIG_1_4 \ + -DDISPLAY_CONFIG_1_3 -DDISPLAY_CONFIG_1_2 -DDISPLAY_CONFIG_1_1 +endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_8) + common_flags += -DDISPLAY_CONFIG_1_1 -DDISPLAY_CONFIG_1_2 -DDISPLAY_CONFIG_1_3 + common_flags += -DDISPLAY_CONFIG_1_4 -DDISPLAY_CONFIG_1_5 -DDISPLAY_CONFIG_1_6 + common_flags += -DDISPLAY_CONFIG_1_7 -DDISPLAY_CONFIG_1_8 +endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_9) + common_flags += -DDISPLAY_CONFIG_1_1 -DDISPLAY_CONFIG_1_2 -DDISPLAY_CONFIG_1_3 + common_flags += -DDISPLAY_CONFIG_1_4 -DDISPLAY_CONFIG_1_5 -DDISPLAY_CONFIG_1_6 + common_flags += -DDISPLAY_CONFIG_1_7 -DDISPLAY_CONFIG_1_8 -DDISPLAY_CONFIG_1_9 +endif + ifeq ($(TARGET_USES_COLOR_METADATA), true) common_flags += -DUSE_COLOR_METADATA endif diff --git a/gpu_tonemapper/EGLImageWrapper.cpp b/gpu_tonemapper/EGLImageWrapper.cpp index dfc16d84..65f5e5ba 100644 --- a/gpu_tonemapper/EGLImageWrapper.cpp +++ b/gpu_tonemapper/EGLImageWrapper.cpp @@ -22,10 +22,19 @@ #include #include #include -#include +#include +#include +#include +using std::string; +using std::map; +using std::pair; + +static string pidString = std::to_string(getpid()); + +#ifndef TARGET_ION_ABI_VERSION //----------------------------------------------------------------------------- -void free_ion_cookie(int ion_fd, int cookie) +static void free_ion_cookie(int ion_fd, int cookie) //----------------------------------------------------------------------------- { if (ion_fd && !ioctl(ion_fd, ION_IOC_FREE, &cookie)) { @@ -35,120 +44,167 @@ void free_ion_cookie(int ion_fd, int cookie) } //----------------------------------------------------------------------------- -int get_ion_cookie(int ion_fd, int fd) +static int get_ion_cookie(int ion_fd, int fd) //----------------------------------------------------------------------------- { - int cookie = fd; + int cookie = fd; - struct ion_fd_data fdData; - memset(&fdData, 0, sizeof(fdData)); - fdData.fd = fd; + struct ion_fd_data fdData; + memset(&fdData, 0, sizeof(fdData)); + fdData.fd = fd; - if (ion_fd && !ioctl(ion_fd, ION_IOC_IMPORT, &fdData)) { - cookie = fdData.handle; - } else { - ALOGE("ION_IOC_IMPORT failed: ion_fd = %d, fd = %d", ion_fd, fd); - } + if (ion_fd && !ioctl(ion_fd, ION_IOC_IMPORT, &fdData)) { + cookie = fdData.handle; + } else { + ALOGE("ION_IOC_IMPORT failed: ion_fd = %d, fd = %d", ion_fd, fd); + } - return cookie; + return cookie; } - +#else //----------------------------------------------------------------------------- -EGLImageWrapper::DeleteEGLImageCallback::DeleteEGLImageCallback(int fd) +static string get_ion_buff_str(int buff_fd) //----------------------------------------------------------------------------- { - ion_fd = fd; + string retStr = {}; + if (buff_fd >= 0) { + string fdString = std::to_string(buff_fd); + string symlinkPath = "/proc/"+pidString+"/fd/"+fdString; + char buffer[1024] = {}; + ssize_t ret = ::readlink(symlinkPath.c_str(), buffer, sizeof(buffer) - 1); + if (ret != -1) { + buffer[ret] = '\0'; + retStr = buffer; + } + } + + return retStr; } +#endif //----------------------------------------------------------------------------- -void EGLImageWrapper::DeleteEGLImageCallback::operator()(int& k, EGLImageBuffer*& eglImage) +void EGLImageWrapper::DeleteEGLImageCallback::operator()(int& buffInt, EGLImageBuffer*& eglImage) //----------------------------------------------------------------------------- { - free_ion_cookie(ion_fd, k); - if( eglImage != 0 ) - { - delete eglImage; + if (eglImage != 0) { + delete eglImage; + } + +#ifndef TARGET_ION_ABI_VERSION + free_ion_cookie(ion_fd, buffInt /* cookie */); +#else + if (!mapClearPending) { + for (auto it = buffStrbuffIntMapPtr->begin(); it != buffStrbuffIntMapPtr->end(); it++) { + if (it->second == buffInt /* counter */) { + buffStrbuffIntMapPtr->erase(it); + return; + } } + } +#endif } //----------------------------------------------------------------------------- EGLImageWrapper::EGLImageWrapper() //----------------------------------------------------------------------------- { - eglImageBufferMap = new android::LruCache(32); - ion_fd = open("/dev/ion", O_RDONLY); - callback = new DeleteEGLImageCallback(ion_fd); - eglImageBufferMap->setOnEntryRemovedListener(callback); + eglImageBufferCache = new android::LruCache(32); + callback = new DeleteEGLImageCallback(&buffStrbuffIntMap); + eglImageBufferCache->setOnEntryRemovedListener(callback); + +#ifndef TARGET_ION_ABI_VERSION + ion_fd = open("/dev/ion", O_RDONLY); + callback->ion_fd = ion_fd; +#endif } //----------------------------------------------------------------------------- EGLImageWrapper::~EGLImageWrapper() //----------------------------------------------------------------------------- { - if( eglImageBufferMap != 0 ) - { - eglImageBufferMap->clear(); - delete eglImageBufferMap; - eglImageBufferMap = 0; + if (eglImageBufferCache != 0) { + if (callback != 0) { + callback->mapClearPending = true; } + eglImageBufferCache->clear(); + delete eglImageBufferCache; + eglImageBufferCache = 0; + buffStrbuffIntMap.clear(); + } - if( callback != 0 ) - { - delete callback; - callback = 0; - } + if (callback != 0) { + delete callback; + callback = 0; + } - if( ion_fd > 0 ) - { - close(ion_fd); - } +#ifndef TARGET_ION_ABI_VERSION + if (ion_fd > 0) { + close(ion_fd); ion_fd = -1; + } +#endif } + //----------------------------------------------------------------------------- static EGLImageBuffer* L_wrap(const private_handle_t *src) //----------------------------------------------------------------------------- { - EGLImageBuffer* result = 0; + EGLImageBuffer* result = 0; - native_handle_t *native_handle = const_cast(src); + native_handle_t *native_handle = const_cast(src); - int flags = android::GraphicBuffer::USAGE_HW_TEXTURE | - android::GraphicBuffer::USAGE_SW_READ_NEVER | - android::GraphicBuffer::USAGE_SW_WRITE_NEVER; + int flags = android::GraphicBuffer::USAGE_HW_TEXTURE | + android::GraphicBuffer::USAGE_SW_READ_NEVER | + android::GraphicBuffer::USAGE_SW_WRITE_NEVER; - if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { - flags |= android::GraphicBuffer::USAGE_PROTECTED; - } + if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { + flags |= android::GraphicBuffer::USAGE_PROTECTED; + } - android::sp graphicBuffer = - new android::GraphicBuffer(src->unaligned_width, src->unaligned_height, src->format, + android::sp graphicBuffer = + new android::GraphicBuffer(src->unaligned_width, src->unaligned_height, src->format, #ifndef __NOUGAT__ - 1, // Layer count + 1, // Layer count #endif - flags, src->width /*src->stride*/, - native_handle, false); + flags, src->width /*src->stride*/, + native_handle, false); - result = new EGLImageBuffer(graphicBuffer); + result = new EGLImageBuffer(graphicBuffer); - return result; + return result; } //----------------------------------------------------------------------------- EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle) //----------------------------------------------------------------------------- { - const private_handle_t *src = static_cast(pvt_handle); - - int ion_cookie = get_ion_cookie(ion_fd, src->fd); - EGLImageBuffer* eglImage = eglImageBufferMap->get(ion_cookie); - if( eglImage == 0 ) - { + const private_handle_t *src = static_cast(pvt_handle); + EGLImageBuffer* eglImage = nullptr; +#ifndef TARGET_ION_ABI_VERSION + int ion_cookie = get_ion_cookie(ion_fd, src->fd); + eglImage = eglImageBufferCache->get(ion_cookie); + if (eglImage == 0) { + eglImage = L_wrap(src); + eglImageBufferCache->put(ion_cookie, eglImage); + } else { + free_ion_cookie(ion_fd, ion_cookie); + } +#else + string buffStr = get_ion_buff_str(src->fd); + if (!buffStr.empty()) { + auto it = buffStrbuffIntMap.find(buffStr); + if (it != buffStrbuffIntMap.end()) { + eglImage = eglImageBufferCache->get(it->second); + } else { eglImage = L_wrap(src); - eglImageBufferMap->put(ion_cookie, eglImage); - } - else { - free_ion_cookie(ion_fd, ion_cookie); + buffStrbuffIntMap.insert(pair(buffStr, buffInt)); + eglImageBufferCache->put(buffInt, eglImage); + buffInt++; } + } else { + ALOGE("Could not provide an eglImage for fd = %d, EGLImageWrapper = %p", src->fd, this); + } +#endif - return eglImage; + return eglImage; } diff --git a/gpu_tonemapper/EGLImageWrapper.h b/gpu_tonemapper/EGLImageWrapper.h index e9a4d68f..296aa667 100644 --- a/gpu_tonemapper/EGLImageWrapper.h +++ b/gpu_tonemapper/EGLImageWrapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -21,27 +21,40 @@ #define __TONEMAPPER_EGLIMAGEWRAPPER_H__ #include +#include +#include +#include #include "EGLImageBuffer.h" +using std::string; +using std::map; + class EGLImageWrapper { - private: - class DeleteEGLImageCallback : public android::OnEntryRemoved - { - private: - int ion_fd; - public: - DeleteEGLImageCallback(int ion_fd); - void operator()(int& ion_cookie, EGLImageBuffer*& eglImage); - }; + private: + class DeleteEGLImageCallback : public android::OnEntryRemoved { + public: + explicit DeleteEGLImageCallback(map* mapPtr) { buffStrbuffIntMapPtr = mapPtr; } + void operator()(int& buffInt, EGLImageBuffer*& eglImage); + map* buffStrbuffIntMapPtr = nullptr; + bool mapClearPending = false; + #ifndef TARGET_ION_ABI_VERSION + int ion_fd = -1; + #endif + }; - android::LruCache* eglImageBufferMap; - DeleteEGLImageCallback* callback; - int ion_fd; + android::LruCache* eglImageBufferCache; + map buffStrbuffIntMap = {}; + DeleteEGLImageCallback* callback = 0; + #ifndef TARGET_ION_ABI_VERSION + int ion_fd = -1; + #else + uint64_t buffInt = 0; + #endif - public: - EGLImageWrapper(); - ~EGLImageWrapper(); - EGLImageBuffer* wrap(const void *pvt_handle); + public: + EGLImageWrapper(); + ~EGLImageWrapper(); + EGLImageBuffer* wrap(const void *pvt_handle); }; -#endif //__TONEMAPPER_EGLIMAGEWRAPPER_H__ +#endif // __TONEMAPPER_EGLIMAGEWRAPPER_H__ diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp index 811e091a..2605c7fe 100644 --- a/gpu_tonemapper/Tonemapper.cpp +++ b/gpu_tonemapper/Tonemapper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -137,10 +137,14 @@ int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd) } // set destination - engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(), - dst_buffer->getHeight()); + if (dst_buffer) { + engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(), + dst_buffer->getHeight()); + } // set source - engine_setExternalInputBuffer(0, src_buffer->getTexture()); + if (src_buffer) { + engine_setExternalInputBuffer(0, src_buffer->getTexture()); + } // set 3d lut engine_set3DInputBuffer(1, tonemapTexture); // set non-uniform xform diff --git a/gralloc/Android.mk b/gralloc/Android.mk index 19cb87be..7157b8e1 100644 --- a/gralloc/Android.mk +++ b/gralloc/Android.mk @@ -8,12 +8,21 @@ LOCAL_VENDOR_MODULE := true LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(common_includes) - -LOCAL_HEADER_LIBRARIES := display_headers +LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -Werror LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libgrallocutils \ android.hardware.graphics.common@1.1 -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -Werror +ifeq ($(TARGET_KERNEL_VERSION), 4.14) +LOCAL_C_INCLUDES += external/libcxx/include \ + system/core/libion/include/ \ + system/core/libion/kernel-headers/ \ + $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include +LOCAL_SHARED_LIBRARIES += libion +LOCAL_CFLAGS += -std=c++14 +endif +LOCAL_HEADER_LIBRARIES := display_headers +ifneq ($(TARGET_KERNEL_VERSION), 4.14) LOCAL_CFLAGS += -isystem $(kernel_includes) +endif LOCAL_CLANG := true LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps) LOCAL_SRC_FILES := gr_ion_alloc.cpp \ @@ -35,6 +44,10 @@ LOCAL_MODULE := libgrallocutils LOCAL_VENDOR_MODULE := true LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) +ifeq ($(TARGET_KERNEL_VERSION), 4.14) +LOCAL_C_INCLUDES += system/core/libion/include \ + system/core/libion/kernel-headers +endif LOCAL_HEADER_LIBRARIES := display_headers LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl android.hardware.graphics.common@1.1 LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"grallocutils\" -Wno-sign-conversion diff --git a/gralloc/gr_allocator.cpp b/gralloc/gr_allocator.cpp index 35a0980f..6aff3acd 100644 --- a/gralloc/gr_allocator.cpp +++ b/gralloc/gr_allocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -49,6 +49,12 @@ #define ION_FLAG_CP_CAMERA_PREVIEW 0 #endif +#if TARGET_ION_ABI_VERSION >= 2 +#ifndef ION_SECURE +#define ION_SECURE ION_FLAG_SECURE +#endif +#endif + #ifdef MASTER_SIDE_CP #define CP_HEAP_ID ION_SECURE_HEAP_ID #define SD_HEAP_ID ION_SECURE_DISPLAY_HEAP_ID @@ -141,9 +147,10 @@ int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, in return -EINVAL; } -int Allocator::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op) { +int Allocator::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op, + int fd) { if (ion_allocator_) { - return ion_allocator_->CleanBuffer(base, size, offset, handle, op); + return ion_allocator_->CleanBuffer(base, size, offset, handle, op, fd); } return -EINVAL; diff --git a/gralloc/gr_allocator.h b/gralloc/gr_allocator.h index 0b0bb28a..5a72a7be 100644 --- a/gralloc/gr_allocator.h +++ b/gralloc/gr_allocator.h @@ -1,6 +1,5 @@ /* * Copyright (c) 2011-2017,2019, The Linux Foundation. All rights reserved. - * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: @@ -47,7 +46,7 @@ class Allocator { int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); int ImportBuffer(int fd); int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle); - int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op); + int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op, int fd); int AllocateMem(AllocData *data, gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage); // @return : index of the descriptor with maximum buffer size req diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp index 068e0700..c7cfd1df 100644 --- a/gralloc/gr_buf_mgr.cpp +++ b/gralloc/gr_buf_mgr.cpp @@ -347,7 +347,7 @@ gralloc1_error_t BufferManager::LockBuffer(const private_handle_t *hnd, if ((cons_usage & (GRALLOC1_CONSUMER_USAGE_CPU_READ | GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN)) && (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER)) { if (allocator_->CleanBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, - buf->ion_handle_main, CACHE_INVALIDATE)) { + buf->ion_handle_main, CACHE_INVALIDATE, hnd->fd)) { return GRALLOC1_ERROR_BAD_HANDLE; } @@ -375,7 +375,7 @@ gralloc1_error_t BufferManager::UnlockBuffer(const private_handle_t *handle) { if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) { if (allocator_->CleanBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, - buf->ion_handle_main, CACHE_CLEAN) != 0) { + buf->ion_handle_main, CACHE_CLEAN, hnd->fd) != 0) { status = GRALLOC1_ERROR_BAD_HANDLE; } hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; diff --git a/gralloc/gr_ion_alloc.cpp b/gralloc/gr_ion_alloc.cpp index 680a516a..851c8352 100644 --- a/gralloc/gr_ion_alloc.cpp +++ b/gralloc/gr_ion_alloc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -32,6 +32,11 @@ #include #include #include +#include +#if TARGET_ION_ABI_VERSION >= 2 +#include +#include +#endif #include #include #include @@ -46,7 +51,7 @@ namespace gralloc1 { bool IonAlloc::Init() { if (ion_dev_fd_ == FD_INIT) { - ion_dev_fd_ = open(kIonDevice, O_RDONLY); + ion_dev_fd_ = OpenIonDevice(); } if (ion_dev_fd_ < 0) { @@ -58,6 +63,103 @@ bool IonAlloc::Init() { return true; } +#if TARGET_ION_ABI_VERSION >= 2 // Use libion APIs for new ion + +int IonAlloc::OpenIonDevice() { + return ion_open(); +} + +void IonAlloc::CloseIonDevice() { + if (ion_dev_fd_ > FD_INIT) { + ion_close(ion_dev_fd_); + } + + ion_dev_fd_ = FD_INIT; +} + +int IonAlloc::AllocBuffer(AllocData *data) { + ATRACE_CALL(); + int err = 0; + int fd = -1; + unsigned int flags = data->flags; + + flags |= data->uncached ? 0 : ION_FLAG_CACHED; + + std::string tag_name{}; + if (ATRACE_ENABLED()) { + tag_name = "libion alloc size: " + std::to_string(data->size); + } + + ATRACE_BEGIN(tag_name.c_str()); + err = ion_alloc_fd(ion_dev_fd_, data->size, data->align, data->heap_id, flags, &fd); + ATRACE_END(); + if (err) { + ALOGE("libion alloc failed"); + return err; + } + + data->fd = fd; + data->ion_handle = fd; // For new ion api ion_handle does not exists so reusing fd for now + ALOGD_IF(DEBUG, "libion: Allocated buffer size:%u fd:%d", data->size, data->fd); + + return 0; +} + +int IonAlloc::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, + int /*ion_handle*/) { + ATRACE_CALL(); + int err = 0; + ALOGD_IF(DEBUG, "libion: Freeing buffer base:%p size:%u fd:%d", base, size, fd); + + if (base) { + err = UnmapBuffer(base, size, offset); + } + + close(fd); + return err; +} + +int IonAlloc::ImportBuffer(int fd) { + // For new ion api ion_handle does not exists so reusing fd for now + return fd; +} + +int IonAlloc::CleanBuffer(void */*base*/, unsigned int /*size*/, unsigned int /*offset*/, + int /*handle*/, int op, int dma_buf_fd) { + ATRACE_CALL(); + ATRACE_INT("operation id", op); + + struct dma_buf_sync sync; + int err = 0; + + switch (op) { + case CACHE_CLEAN: + sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW; + break; + case CACHE_INVALIDATE: + sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW; + break; + default: + ALOGE("%s: Invalid operation %d", __FUNCTION__, op); + return -1; + } + + if (ioctl(dma_buf_fd, INT(DMA_BUF_IOCTL_SYNC), &sync)) { + err = -errno; + ALOGE("%s: DMA_BUF_IOCTL_SYNC failed with error - %s", __FUNCTION__, strerror(errno)); + return err; + } + + return 0; +} + +#else +#ifndef TARGET_ION_ABI_VERSION // Use old ion apis directly + +int IonAlloc::OpenIonDevice() { + return open(kIonDevice, O_RDONLY); +} + void IonAlloc::CloseIonDevice() { if (ion_dev_fd_ > FD_INIT) { close(ion_dev_fd_); @@ -122,25 +224,6 @@ int IonAlloc::FreeBuffer(void *base, unsigned int size, unsigned int offset, int return err; } -int IonAlloc::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { - ATRACE_CALL(); - int err = 0; - void *addr = 0; - - // It is a (quirky) requirement of ION to have opened the - // ion fd in the process that is doing the mapping - addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - *base = addr; - if (addr == MAP_FAILED) { - err = -errno; - ALOGE("ion: Failed to map memory in the client: %s", strerror(errno)); - } else { - ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u offset:%u fd:%d", addr, size, offset, fd); - } - - return err; -} - int IonAlloc::ImportBuffer(int fd) { struct ion_fd_data fd_data; int err = 0; @@ -153,20 +236,8 @@ int IonAlloc::ImportBuffer(int fd) { return fd_data.handle; } -int IonAlloc::UnmapBuffer(void *base, unsigned int size, unsigned int /*offset*/) { - ATRACE_CALL(); - ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size); - - int err = 0; - if (munmap(base, size)) { - err = -errno; - ALOGE("ion: Failed to unmap memory at %p : %s", base, strerror(errno)); - } - - return err; -} - -int IonAlloc::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op) { +int IonAlloc::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op, + int /*fd*/) { ATRACE_CALL(); ATRACE_INT("operation id", op); struct ion_flush_data flush_data; @@ -201,4 +272,65 @@ int IonAlloc::CleanBuffer(void *base, unsigned int size, unsigned int offset, in return 0; } +#else // This ion version is not supported + +int IonAlloc::OpenIonDevice() { + return -EINVAL; +} + +void IonAlloc::CloseIonDevice() { +} + +int IonAlloc::AllocBuffer(AllocData * /*data*/) { + return -EINVAL; +} + +int IonAlloc::FreeBuffer(void * /*base*/, unsigned int /*size*/, unsigned int /*offset*/, + int /*fd*/, int /*ion_handle*/) { + return -EINVAL; +} + +int IonAlloc::ImportBuffer(int /*fd*/) { + return -EINVAL; +} + +int IonAlloc::CleanBuffer(void * /*base*/, unsigned int /*size*/, unsigned int /*offset*/, + int /*handle*/, int /*op*/, int /*fd*/) { + return -EINVAL; +} + +#endif +#endif // TARGET_ION_ABI_VERSION + + +int IonAlloc::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { + ATRACE_CALL(); + int err = 0; + void *addr = 0; + + addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + *base = addr; + if (addr == MAP_FAILED) { + err = -errno; + ALOGE("ion: Failed to map memory in the client: %s", strerror(errno)); + } else { + ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u offset:%u fd:%d", addr, size, offset, fd); + } + + return err; +} + +int IonAlloc::UnmapBuffer(void *base, unsigned int size, unsigned int /*offset*/) { + ATRACE_CALL(); + ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size); + + int err = 0; + if (munmap(base, size)) { + err = -errno; + ALOGE("ion: Failed to unmap memory at %p : %s", base, strerror(errno)); + } + + return err; +} + } // namespace gralloc1 diff --git a/gralloc/gr_ion_alloc.h b/gralloc/gr_ion_alloc.h index b25f509b..2e779a98 100644 --- a/gralloc/gr_ion_alloc.h +++ b/gralloc/gr_ion_alloc.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2019, The Linux Foundation. All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -68,10 +68,11 @@ class IonAlloc { int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); int ImportBuffer(int fd); int UnmapBuffer(void *base, unsigned int size, unsigned int offset); - int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op); - + int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op, int fd); private: +#ifndef TARGET_ION_ABI_VERSION const char *kIonDevice = "/dev/ion"; +#endif int OpenIonDevice(); void CloseIonDevice(); diff --git a/include/display_properties.h b/include/display_properties.h index 1cb4a98b..f78fb9de 100644 --- a/include/display_properties.h +++ b/include/display_properties.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2018, The Linux Foundation. All rights reserved. +* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -91,6 +91,11 @@ #define DISABLE_HDR_LUT_GEN DISPLAY_PROP("disable_hdr_lut_gen") #define ENABLE_DEFAULT_COLOR_MODE DISPLAY_PROP("enable_default_color_mode") #define DISABLE_HDR DISPLAY_PROP("hwc_disable_hdr") +#define DISABLE_QTI_BSP DISPLAY_PROP("disable_qti_bsp") +#define UPDATE_VSYNC_ON_DOZE DISPLAY_PROP("update_vsync_on_doze") +#define PANEL_MOUNTFLIP DISPLAY_PROP("panel_mountflip") +#define VDS_ALLOW_HWC DISPLAY_PROP("vds_allow_hwc") +#define QDFRAMEWORK_LOGS DISPLAY_PROP("qdframework_logs") #define HDR_CONFIG_PROP RO_DISPLAY_PROP("hdr.config") #define QDCM_PCC_TRANS_PROP DISPLAY_PROP("qdcm.pcc_for_trans") diff --git a/sdm/libs/hwc2/Android.mk b/sdm/libs/hwc2/Android.mk index a0ea3587..b65af1d0 100644 --- a/sdm/libs/hwc2/Android.mk +++ b/sdm/libs/hwc2/Android.mk @@ -8,7 +8,8 @@ LOCAL_MODULE := hwcomposer.$(TARGET_BOARD_PLATFORM) LOCAL_VENDOR_MODULE := true LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) +LOCAL_C_INCLUDES := $(common_includes) \ + $(kernel_includes) LOCAL_HEADER_LIBRARIES := display_headers LOCAL_CFLAGS := -Wno-missing-field-initializers -Wno-unused-parameter \ @@ -36,6 +37,26 @@ ifeq ($(display_config_version), DISPLAY_CONFIG_1_1) LOCAL_SHARED_LIBRARIES += vendor.display.config@1.1 endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_7) +LOCAL_SHARED_LIBRARIES += vendor.display.config@1.7 \ + vendor.display.config@1.6 vendor.display.config@1.5 \ + vendor.display.config@1.4 vendor.display.config@1.3 \ + vendor.display.config@1.2 vendor.display.config@1.1 +endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_8) +LOCAL_SHARED_LIBRARIES += vendor.display.config@1.1 vendor.display.config@1.2 \ + vendor.display.config@1.3 vendor.display.config@1.4 \ + vendor.display.config@1.5 vendor.display.config@1.6 \ + vendor.display.config@1.7 vendor.display.config@1.8 +endif +ifeq ($(display_config_version), DISPLAY_CONFIG_1_9) +LOCAL_SHARED_LIBRARIES += vendor.display.config@1.1 vendor.display.config@1.2 \ + vendor.display.config@1.3 vendor.display.config@1.4 \ + vendor.display.config@1.5 vendor.display.config@1.6 \ + vendor.display.config@1.7 vendor.display.config@1.8 \ + vendor.display.config@1.9 +endif + LOCAL_SRC_FILES := hwc_session.cpp \ hwc_session_services.cpp \ hwc_display.cpp \ diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp index 93b321de..c4afd510 100644 --- a/sdm/libs/hwc2/hwc_session.cpp +++ b/sdm/libs/hwc2/hwc_session.cpp @@ -1720,13 +1720,6 @@ int HWCSession::CreateExternalDisplay(int disp, uint32_t primary_width, } } -#ifdef DISPLAY_CONFIG_1_1 -// Methods from ::vendor::hardware::display::config::V1_1::IDisplayConfig follow. -Return HWCSession::setDisplayAnimating(uint64_t display_id, bool animating ) { - return CallDisplayFunction(static_cast(this), display_id, - &HWCDisplay::SetDisplayAnimating, animating); -} -#endif void HWCSession::CreateNullDisplay() { auto hwc_display = &hwc_display_[HWC_DISPLAY_PRIMARY]; diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h index 78d49fca..f606982a 100644 --- a/sdm/libs/hwc2/hwc_session.h +++ b/sdm/libs/hwc2/hwc_session.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2017, 2018, 2019 The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -20,7 +20,13 @@ #ifndef __HWC_SESSION_H__ #define __HWC_SESSION_H__ -#ifdef DISPLAY_CONFIG_1_1 +#ifdef DISPLAY_CONFIG_1_9 +#include +#elif DISPLAY_CONFIG_1_8 +#include +#elif DISPLAY_CONFIG_1_7 +#include +#elif DISPLAY_CONFIG_1_1 #include #else #include @@ -41,12 +47,19 @@ namespace sdm { -#ifdef DISPLAY_CONFIG_1_1 +#ifdef DISPLAY_CONFIG_1_9 +using vendor::display::config::V1_9::IDisplayConfig; +#elif DISPLAY_CONFIG_1_8 +using vendor::display::config::V1_8::IDisplayConfig; +#elif DISPLAY_CONFIG_1_7 +using vendor::display::config::V1_7::IDisplayConfig; +#elif DISPLAY_CONFIG_1_1 using vendor::display::config::V1_1::IDisplayConfig; #else -using ::vendor::display::config::V1_0::IDisplayConfig; +using vendor::display::config::V1_0::IDisplayConfig; #endif using ::android::hardware::Return; +using ::android::hardware::hidl_string; // Create a singleton uevent listener thread valid for life of hardware composer process. // This thread blocks on uevents poll inside uevent library implementation. This poll exits @@ -216,10 +229,47 @@ class HWCSession : hwc2_device_t, HWCUEventListener, IDisplayConfig, public qCli Return setCameraLaunchStatus(uint32_t on) override; Return displayBWTransactionPending(displayBWTransactionPending_cb _hidl_cb) override; - // Methods from ::android::hardware::display::config::V1_1::IDisplayConfig follow. + // Methods from ::android::hardware::display::config::V1_7::IDisplayConfig follow. #ifdef DISPLAY_CONFIG_1_1 Return setDisplayAnimating(uint64_t display_id, bool animating) override; #endif +#ifdef DISPLAY_CONFIG_1_2 + Return setDisplayIndex(IDisplayConfig::DisplayTypeExt disp_type, + uint32_t base, uint32_t count) override; +#endif +#ifdef DISPLAY_CONFIG_1_3 + Return controlIdlePowerCollapse(bool enable, bool synchronous) override; +#endif +#ifdef DISPLAY_CONFIG_1_4 + Return getWriteBackCapabilities(getWriteBackCapabilities_cb _hidl_cb) override; +#endif +#ifdef DISPLAY_CONFIG_1_5 + Return SetDisplayDppsAdROI(uint32_t display_id, uint32_t h_start, uint32_t h_end, + uint32_t v_start, uint32_t v_end, uint32_t factor_in, + uint32_t factor_out) override; +#endif +#ifdef DISPLAY_CONFIG_1_6 + Return updateVSyncSourceOnPowerModeOff() override; + Return updateVSyncSourceOnPowerModeDoze() override; +#endif +#ifdef DISPLAY_CONFIG_1_7 + Return setPowerMode(uint32_t disp_id, PowerMode power_mode) override; + Return isPowerModeOverrideSupported(uint32_t disp_id) override; + Return isHDRSupported(uint32_t disp_id) override; + Return isWCGSupported(uint32_t disp_id) override; + Return setLayerAsMask(uint32_t disp_id, uint64_t layer_id) override; + Return getDebugProperty(const hidl_string &prop_name, + getDebugProperty_cb _hidl_cb) override; +#endif +#ifdef DISPLAY_CONFIG_1_8 + Return getActiveBuiltinDisplayAttributes(getDisplayAttributes_cb _hidl_cb) override; +#endif + +#ifdef DISPLAY_CONFIG_1_9 + Return setPanelLuminanceAttributes(uint32_t disp_id, float min_lum, + float max_lum) override; + Return isBuiltInDisplay(uint32_t disp_id) override; +#endif // QClient methods virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel, diff --git a/sdm/libs/hwc2/hwc_session_services.cpp b/sdm/libs/hwc2/hwc_session_services.cpp index be1aa7c5..a2b816aa 100644 --- a/sdm/libs/hwc2/hwc_session_services.cpp +++ b/sdm/libs/hwc2/hwc_session_services.cpp @@ -34,6 +34,7 @@ #include "hwc_buffer_sync_handler.h" #include "hwc_session.h" +#include "hwc_debugger.h" #define __CLASS__ "HWCSession" @@ -496,4 +497,140 @@ Return HWCSession::displayBWTransactionPending(displayBWTransactionPending return Void(); } +#ifdef DISPLAY_CONFIG_1_1 +Return HWCSession::setDisplayAnimating(uint64_t display_id, bool animating ) { + return CallDisplayFunction(static_cast(this), display_id, + &HWCDisplay::SetDisplayAnimating, animating); +} +#endif + +#ifdef DISPLAY_CONFIG_1_2 +Return HWCSession::setDisplayIndex(IDisplayConfig::DisplayTypeExt disp_type, + uint32_t base, uint32_t count) { + DLOGW("Not implemented."); + return 0; +} +#endif + +#ifdef DISPLAY_CONFIG_1_3 +Return HWCSession::controlIdlePowerCollapse(bool enable, bool synchronous) { + DLOGW("Not implemented."); + return 0; +} +#endif + +#ifdef DISPLAY_CONFIG_1_4 +Return HWCSession::getWriteBackCapabilities(getWriteBackCapabilities_cb _hidl_cb) { + DLOGW("Not implemented."); + return Void(); +} +#endif + +#ifdef DISPLAY_CONFIG_1_5 +Return HWCSession::SetDisplayDppsAdROI(uint32_t display_id, uint32_t h_start, + uint32_t h_end, uint32_t v_start, uint32_t v_end, + uint32_t factor_in, uint32_t factor_out) { + DLOGW("Not implemented."); + return 0; +} +#endif + +#ifdef DISPLAY_CONFIG_1_6 +Return HWCSession::updateVSyncSourceOnPowerModeOff() { + DLOGW("Not implemented."); + return 0; +} + +Return HWCSession::updateVSyncSourceOnPowerModeDoze() { + DLOGW("Not implemented."); + return 0; +} +#endif + +#ifdef DISPLAY_CONFIG_1_7 +Return HWCSession::setPowerMode(uint32_t disp_id, PowerMode power_mode) { + return 0; +} + +Return HWCSession::isPowerModeOverrideSupported(uint32_t disp_id) { + return false; +} + +Return HWCSession::isHDRSupported(uint32_t disp_id) { + SEQUENCE_WAIT_SCOPE_LOCK(locker_[disp_id]); + HWCDisplay *hwc_display = hwc_display_[disp_id]; + if (!hwc_display) { + DLOGW("Display = %d is not connected.", disp_id); + return false; + } + + // query number of hdr types + uint32_t out_num_types = 0; + if (hwc_display->GetHdrCapabilities(&out_num_types, nullptr, nullptr, nullptr, nullptr) + != HWC2::Error::None) { + return false; + } + + if (!out_num_types) { + return false; + } + + return true; +} + +Return HWCSession::isWCGSupported(uint32_t disp_id) { + // todo(user): Query wcg from sdm. For now assume them same. + return isHDRSupported(disp_id); +} + +Return HWCSession::setLayerAsMask(uint32_t disp_id, uint64_t layer_id) { + return 0; +} + +Return HWCSession::getDebugProperty(const hidl_string &prop_name, + getDebugProperty_cb _hidl_cb) { + std::string vendor_prop_name = DISP_PROP_PREFIX; + char value[64] = {}; + hidl_string result = ""; + int32_t error = -EINVAL; + + vendor_prop_name += prop_name.c_str(); + if (HWCDebugHandler::Get()->GetProperty(vendor_prop_name.c_str(), value) != kErrorNone) { + result = value; + error = 0; + } + + _hidl_cb(result, error); + + return Void(); +} +#endif + + +#ifdef DISPLAY_CONFIG_1_8 +Return HWCSession::getActiveBuiltinDisplayAttributes( + getDisplayAttributes_cb _hidl_cb) { + DLOGE("Not supported at present"); + return Void(); +} +#endif // DISPLAY_CONFIG_1_8 + +#ifdef DISPLAY_CONFIG_1_9 +Return HWCSession::setPanelLuminanceAttributes(uint32_t disp_id, float pan_min_lum, + float pan_max_lum) { + DLOGE("Not supported at present"); + return -1; +} + +Return HWCSession::isBuiltInDisplay(uint32_t disp_id) { + if ((HWC_DISPLAY_PRIMARY == disp_id) || (HWC_DISPLAY_BUILTIN_2 == disp_id) || + (HWC_DISPLAY_BUILTIN_3 == disp_id) || (HWC_DISPLAY_BUILTIN_4 == disp_id)) { + return true; + } + else { + return false; + } +} +#endif // DISPLAY_CONFIG_1_9 + } // namespace sdm