Merge "sdm: Consider external display as active in doze suspend."
diff --git a/sdm/.clang-format b/.clang-format
similarity index 100%
rename from sdm/.clang-format
rename to .clang-format
diff --git a/Android.mk b/Android.mk
index 6eef2fc..226e8a0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,7 +3,7 @@
ifneq ($(TARGET_IS_HEADLESS), true)
display-hals += libcopybit liblight libmemtrack hdmi_cec \
- $(sdm-libs)/hwc $(sdm-libs)/hwc2 gpu_tonemapper
+ $(sdm-libs)/hwc $(sdm-libs)/hwc2 gpu_tonemapper libdrmutils
endif
ifneq ($(TARGET_USES_GRALLOC1), true)
diff --git a/common.mk b/common.mk
index 1044238..f105330 100644
--- a/common.mk
+++ b/common.mk
@@ -4,6 +4,9 @@
#Common C flags
common_flags := -DDEBUG_CALC_FPS -Wno-missing-field-initializers
common_flags += -Wconversion -Wall -Werror -std=c++11
+ifneq ($(TARGET_IS_HEADLESS), true)
+ common_flags += -DCOMPILE_DRM
+endif
ifeq ($(TARGET_USES_COLOR_METADATA), true)
common_flags += -DUSE_COLOR_METADATA
@@ -28,6 +31,7 @@
common_includes += $(display_top)/gpu_tonemapper
ifneq ($(TARGET_IS_HEADLESS), true)
common_includes += $(display_top)/libcopybit
+ common_includes += $(display_top)/libdrmutils
endif
common_includes += $(display_top)/include
@@ -60,10 +64,6 @@
common_flags += -D__ARM_HAVE_NEON
endif
-ifeq ($(call is-board-platform-in-list, $(MSM_VIDC_TARGET_LIST)), true)
- common_flags += -DVENUS_COLOR_FORMAT
-endif
-
ifeq ($(call is-board-platform-in-list, $(MASTER_SIDE_CP_TARGET_LIST)), true)
common_flags += -DMASTER_SIDE_CP
endif
diff --git a/gpu_tonemapper/Android.mk b/gpu_tonemapper/Android.mk
index 4f716d2..5d1f9a9 100644
--- a/gpu_tonemapper/Android.mk
+++ b/gpu_tonemapper/Android.mk
@@ -10,6 +10,7 @@
LOCAL_MODULE := libgpu_tonemapper
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/qcom/display/
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_CFLAGS := $(version_flag) -Wno-missing-field-initializers -Wall \
-Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
diff --git a/gpu_tonemapper/EGLImageWrapper.cpp b/gpu_tonemapper/EGLImageWrapper.cpp
index 1d5d57e..84f4343 100644
--- a/gpu_tonemapper/EGLImageWrapper.cpp
+++ b/gpu_tonemapper/EGLImageWrapper.cpp
@@ -21,21 +21,101 @@
#include <cutils/native_handle.h>
#include <gralloc_priv.h>
#include <ui/GraphicBuffer.h>
+#include <fcntl.h>
+#include <linux/msm_ion.h>
//-----------------------------------------------------------------------------
-EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
+void free_ion_cookie(int ion_fd, int cookie)
//-----------------------------------------------------------------------------
{
- const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle);
+ if (ion_fd && !ioctl(ion_fd, ION_IOC_FREE, &cookie)) {
+ } else {
+ ALOGE("ION_IOC_FREE failed: ion_fd = %d, cookie = %d", ion_fd, cookie);
+ }
+}
- EGLImageBuffer *result = 0;
- std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.find(src->fd);
- if (it == eglImageBufferMap.end()) {
+//-----------------------------------------------------------------------------
+int get_ion_cookie(int ion_fd, int fd)
+//-----------------------------------------------------------------------------
+{
+ int cookie = 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);
+ }
+
+ return cookie;
+}
+
+//-----------------------------------------------------------------------------
+EGLImageWrapper::DeleteEGLImageCallback::DeleteEGLImageCallback(int fd)
+//-----------------------------------------------------------------------------
+{
+ ion_fd = fd;
+}
+
+//-----------------------------------------------------------------------------
+void EGLImageWrapper::DeleteEGLImageCallback::operator()(int& k, EGLImageBuffer*& eglImage)
+//-----------------------------------------------------------------------------
+{
+ free_ion_cookie(ion_fd, k);
+ if( eglImage != 0 )
+ {
+ delete eglImage;
+ }
+}
+
+//-----------------------------------------------------------------------------
+EGLImageWrapper::EGLImageWrapper()
+//-----------------------------------------------------------------------------
+{
+ eglImageBufferMap = new android::LruCache<int, EGLImageBuffer*>(32);
+ ion_fd = open("/dev/ion", O_RDONLY);
+ callback = new DeleteEGLImageCallback(ion_fd);
+ eglImageBufferMap->setOnEntryRemovedListener(callback);
+}
+
+//-----------------------------------------------------------------------------
+EGLImageWrapper::~EGLImageWrapper()
+//-----------------------------------------------------------------------------
+{
+ if( eglImageBufferMap != 0 )
+ {
+ eglImageBufferMap->clear();
+ delete eglImageBufferMap;
+ eglImageBufferMap = 0;
+ }
+
+ if( callback != 0 )
+ {
+ delete callback;
+ callback = 0;
+ }
+
+ if( ion_fd > 0 )
+ {
+ close(ion_fd);
+ }
+ ion_fd = -1;
+}
+//-----------------------------------------------------------------------------
+static EGLImageBuffer* L_wrap(const private_handle_t *src)
+//-----------------------------------------------------------------------------
+{
+ EGLImageBuffer* result = 0;
+
native_handle_t *native_handle = const_cast<private_handle_t *>(src);
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;
}
@@ -50,21 +130,25 @@
result = new EGLImageBuffer(graphicBuffer);
- eglImageBufferMap[src->fd] = result;
- } else {
- result = it->second;
- }
-
- return result;
+ return result;
}
//-----------------------------------------------------------------------------
-void EGLImageWrapper::destroy()
+EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
//-----------------------------------------------------------------------------
{
- std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin();
- for (; it != eglImageBufferMap.end(); it++) {
- delete it->second;
- }
- eglImageBufferMap.clear();
+ const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle);
+
+ int ion_cookie = get_ion_cookie(ion_fd, src->fd);
+ EGLImageBuffer* eglImage = eglImageBufferMap->get(ion_cookie);
+ if( eglImage == 0 )
+ {
+ eglImage = L_wrap(src);
+ eglImageBufferMap->put(ion_cookie, eglImage);
+ }
+ else {
+ free_ion_cookie(ion_fd, ion_cookie);
+ }
+
+ return eglImage;
}
diff --git a/gpu_tonemapper/EGLImageWrapper.h b/gpu_tonemapper/EGLImageWrapper.h
index 90aaf58..e9a4d68 100644
--- a/gpu_tonemapper/EGLImageWrapper.h
+++ b/gpu_tonemapper/EGLImageWrapper.h
@@ -20,15 +20,28 @@
#ifndef __TONEMAPPER_EGLIMAGEWRAPPER_H__
#define __TONEMAPPER_EGLIMAGEWRAPPER_H__
-#include <map>
+#include <utils/LruCache.h>
#include "EGLImageBuffer.h"
class EGLImageWrapper {
- std::map<int, EGLImageBuffer *> eglImageBufferMap;
+ private:
+ class DeleteEGLImageCallback : public android::OnEntryRemoved<int, EGLImageBuffer*>
+ {
+ private:
+ int ion_fd;
+ public:
+ DeleteEGLImageCallback(int ion_fd);
+ void operator()(int& ion_cookie, EGLImageBuffer*& eglImage);
+ };
- public:
- EGLImageBuffer *wrap(const void *pvt_handle);
- void destroy();
+ android::LruCache<int, EGLImageBuffer *>* eglImageBufferMap;
+ DeleteEGLImageCallback* callback;
+ int ion_fd;
+
+ public:
+ EGLImageWrapper();
+ ~EGLImageWrapper();
+ EGLImageBuffer* wrap(const void *pvt_handle);
};
#endif //__TONEMAPPER_EGLIMAGEWRAPPER_H__
diff --git a/gpu_tonemapper/TonemapFactory.cpp b/gpu_tonemapper/TonemapFactory.cpp
index cffc33a..5aae697 100644
--- a/gpu_tonemapper/TonemapFactory.cpp
+++ b/gpu_tonemapper/TonemapFactory.cpp
@@ -27,19 +27,8 @@
void *lutXform, int lutXformSize)
//----------------------------------------------------------------------------------------------------------------------------------------------------------
{
- // initializes the engine - does nothing if already initialized
- engine_initialize();
-
// build the tonemapper
Tonemapper *tonemapper = Tonemapper::build(type, colorMap, colorMapSize, lutXform, lutXformSize);
return tonemapper;
}
-
-//------------------------------------------
-void TonemapperFactory_Destroy()
-//------------------------------------------
-{
- // shutdown the engine
- engine_shutdown();
-}
diff --git a/gpu_tonemapper/TonemapFactory.h b/gpu_tonemapper/TonemapFactory.h
index 1004170..404f4cd 100644
--- a/gpu_tonemapper/TonemapFactory.h
+++ b/gpu_tonemapper/TonemapFactory.h
@@ -30,9 +30,6 @@
Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize,
void *lutXform, int lutXformSize);
-// destroy tonemap session
-void TonemapperFactory_Destroy();
-
#ifdef __cplusplus
}
#endif
diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp
index bb7ba1b..ec74b80 100644
--- a/gpu_tonemapper/Tonemapper.cpp
+++ b/gpu_tonemapper/Tonemapper.cpp
@@ -39,17 +39,18 @@
Tonemapper::~Tonemapper()
//-----------------------------------------------------------------------------
{
- engine_bind();
+ engine_bind(engineContext);
engine_deleteInputBuffer(tonemapTexture);
engine_deleteInputBuffer(lutXformTexture);
engine_deleteProgram(programID);
// clear EGLImage mappings
if (eglImageWrapper != 0) {
- eglImageWrapper->destroy();
delete eglImageWrapper;
eglImageWrapper = 0;
}
+
+ engine_shutdown(engineContext);
}
//-----------------------------------------------------------------------------
@@ -61,10 +62,14 @@
ALOGE("Invalid Color Map size = %d", colorMapSize);
return NULL;
}
- engine_bind();
// build new tonemapper
Tonemapper *tonemapper = new Tonemapper();
+
+ tonemapper->engineContext = engine_initialize();
+
+ engine_bind(tonemapper->engineContext);
+
// load the 3d lut
tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0);
// load the non-uniform xform
@@ -101,7 +106,7 @@
//-----------------------------------------------------------------------------
{
// make current
- engine_bind();
+ engine_bind(engineContext);
// create eglimages if required
EGLImageBuffer *dst_buffer = eglImageWrapper->wrap(dst);
diff --git a/gpu_tonemapper/Tonemapper.h b/gpu_tonemapper/Tonemapper.h
index 0f9bd51..1d6f808 100644
--- a/gpu_tonemapper/Tonemapper.h
+++ b/gpu_tonemapper/Tonemapper.h
@@ -24,9 +24,11 @@
#define TONEMAP_INVERSE 1
#include "EGLImageWrapper.h"
+#include "engine.h"
class Tonemapper {
private:
+ void* engineContext;
unsigned int tonemapTexture;
unsigned int lutXformTexture;
unsigned int programID;
diff --git a/gpu_tonemapper/engine.h b/gpu_tonemapper/engine.h
index 5635ee3..ca914b2 100644
--- a/gpu_tonemapper/engine.h
+++ b/gpu_tonemapper/engine.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright 2015 The Android Open Source Project
@@ -20,9 +20,9 @@
#ifndef __TONEMAPPER_ENGINE_H__
#define __TONEMAPPER_ENGINE_H__
-bool engine_initialize();
-void engine_bind();
-void engine_shutdown();
+void* engine_initialize();
+void engine_bind(void*);
+void engine_shutdown(void*);
unsigned int engine_loadProgram(int, const char **, int, const char **);
void engine_setProgram(int);
@@ -39,4 +39,4 @@
int engine_blit(int);
-#endif //__TONEMAPPER_ENGINE_H__
\ No newline at end of file
+#endif //__TONEMAPPER_ENGINE_H__
diff --git a/gpu_tonemapper/glengine.cpp b/gpu_tonemapper/glengine.cpp
index e5c8e68..eda4e6b 100644
--- a/gpu_tonemapper/glengine.cpp
+++ b/gpu_tonemapper/glengine.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright 2015 The Android Open Source Project
@@ -24,37 +24,42 @@
void checkGlError(const char *, int);
void checkEglError(const char *, int);
-static EGLDisplay eglDisplay;
-static EGLContext eglContext;
-static EGLSurface eglSurface;
-
-static bool isEngineInitialized = false;
+class EngineContext {
+ public:
+ EGLDisplay eglDisplay;
+ EGLContext eglContext;
+ EGLSurface eglSurface;
+ EngineContext()
+ {
+ eglDisplay = EGL_NO_DISPLAY;
+ eglContext = EGL_NO_CONTEXT;
+ eglSurface = EGL_NO_SURFACE;
+ }
+};
//-----------------------------------------------------------------------------
// Make Current
-void engine_bind()
+void engine_bind(void* context)
//-----------------------------------------------------------------------------
{
- EGL(eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
+ EngineContext* engineContext = (EngineContext*)(context);
+ EGL(eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext));
}
//-----------------------------------------------------------------------------
// initialize GL
//
-bool engine_initialize()
+void* engine_initialize()
//-----------------------------------------------------------------------------
{
- if (isEngineInitialized)
- return true;
-
- EGLBoolean result = false;
+ EngineContext* engineContext = new EngineContext();
// display
- eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ engineContext->eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGL(eglBindAPI(EGL_OPENGL_ES_API));
// initialize
- EGL(eglInitialize(eglDisplay, 0, 0));
+ EGL(eglInitialize(engineContext->eglDisplay, 0, 0));
// config
EGLConfig eglConfig;
@@ -65,38 +70,36 @@
EGL_ALPHA_SIZE, 8,
EGL_NONE};
int numConfig = 0;
- EGL(eglChooseConfig(eglDisplay, eglConfigAttribList, &eglConfig, 1, &numConfig));
+ EGL(eglChooseConfig(engineContext->eglDisplay, eglConfigAttribList, &eglConfig, 1, &numConfig));
// context
EGLint eglContextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
- eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, eglContextAttribList);
+ engineContext->eglContext = eglCreateContext(engineContext->eglDisplay, eglConfig, NULL, eglContextAttribList);
// surface
EGLint eglSurfaceAttribList[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, EGL_NONE};
- eglSurface = eglCreatePbufferSurface(eglDisplay, eglConfig, eglSurfaceAttribList);
+ engineContext->eglSurface = eglCreatePbufferSurface(engineContext->eglDisplay, eglConfig, eglSurfaceAttribList);
- result = (EGL_TRUE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
+ eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext);
- isEngineInitialized = result;
+ ALOGI("In %s context = %p", __FUNCTION__, (void *)(engineContext->eglContext));
- ALOGI("In %s result = %d context = %p", __FUNCTION__, result, (void *)eglContext);
-
- return result;
+ return (void*)(engineContext);
}
//-----------------------------------------------------------------------------
// Shutdown.
-void engine_shutdown()
+void engine_shutdown(void* context)
//-----------------------------------------------------------------------------
{
- EGL(eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
- EGL(eglDestroySurface(eglDisplay, eglSurface));
- EGL(eglDestroyContext(eglDisplay, eglContext));
- EGL(eglTerminate(eglDisplay));
- eglDisplay = EGL_NO_DISPLAY;
- eglContext = EGL_NO_CONTEXT;
- eglSurface = EGL_NO_SURFACE;
- isEngineInitialized = false;
+ EngineContext* engineContext = (EngineContext*)context;
+ EGL(eglMakeCurrent(engineContext->eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
+ EGL(eglDestroySurface(engineContext->eglDisplay, engineContext->eglSurface));
+ EGL(eglDestroyContext(engineContext->eglDisplay, engineContext->eglContext));
+ EGL(eglTerminate(engineContext->eglDisplay));
+ engineContext->eglDisplay = EGL_NO_DISPLAY;
+ engineContext->eglContext = EGL_NO_CONTEXT;
+ engineContext->eglSurface = EGL_NO_SURFACE;
}
//-----------------------------------------------------------------------------
@@ -158,7 +161,7 @@
void dumpShaderLog(int shader)
//-----------------------------------------------------------------------------
{
- int success;
+ int success = 0;
GLchar infoLog[512];
GL(glGetShaderiv(shader, GL_COMPILE_STATUS, &success));
if (!success) {
@@ -206,14 +209,14 @@
if (fd != -1) {
EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd, EGL_NONE};
- EGLSyncKHR sync = eglCreateSyncKHR(eglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
+ EGLSyncKHR sync = eglCreateSyncKHR(eglGetCurrentDisplay(), EGL_SYNC_NATIVE_FENCE_ANDROID, attribs);
if (sync == EGL_NO_SYNC_KHR) {
ALOGE("%s - Failed to Create sync from source fd", __FUNCTION__);
} else {
// the gpu will wait for this sync - not this cpu thread.
- EGL(eglWaitSyncKHR(eglDisplay, sync, 0));
- EGL(eglDestroySyncKHR(eglDisplay, sync));
+ EGL(eglWaitSyncKHR(eglGetCurrentDisplay(), sync, 0));
+ EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync));
}
}
}
@@ -224,16 +227,16 @@
{
int fd = -1;
- EGLSyncKHR sync = eglCreateSyncKHR(eglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL);
+ EGLSyncKHR sync = eglCreateSyncKHR(eglGetCurrentDisplay(), EGL_SYNC_NATIVE_FENCE_ANDROID, NULL);
GL(glFlush());
if (sync == EGL_NO_SYNC_KHR) {
ALOGE("%s - Failed to Create Native Fence sync", __FUNCTION__);
} else {
- fd = eglDupNativeFenceFDANDROID(eglDisplay, sync);
+ fd = eglDupNativeFenceFDANDROID(eglGetCurrentDisplay(), sync);
if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) {
ALOGE("%s - Failed to dup sync", __FUNCTION__);
}
- EGL(eglDestroySyncKHR(eglDisplay, sync));
+ EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync));
}
return fd;
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index 10f5943..80b3cfe 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -148,6 +148,8 @@
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: return MDP_Y_CBCR_H2V2_VENUS;
case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: return MDP_Y_CRCB_H2V2_VENUS;
case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: return MDP_Y_CBCR_H2V2;
+ case HAL_PIXEL_FORMAT_CbYCrY_422_I: return MDP_CBYCRY_H2V1;
+ case HAL_PIXEL_FORMAT_BGR_888: return MDP_BGR_888;
}
return -1;
}
diff --git a/libdrmutils/Android.mk b/libdrmutils/Android.mk
new file mode 100644
index 0000000..8d9205d
--- /dev/null
+++ b/libdrmutils/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libdrmutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include \
+ external/libdrm
+LOCAL_SHARED_LIBRARIES := libdrm libdl
+LOCAL_CFLAGS := -DLOG_TAG=\"DRMUTILS\" -Wall -std=c++11 -Werror
+LOCAL_CLANG := true
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+LOCAL_SRC_FILES := drm_master.cpp drm_res_mgr.cpp drm_lib_loader.cpp
+LOCAL_COPY_HEADERS_TO := qcom/display
+LOCAL_COPY_HEADERS := drm_master.h drm_res_mgr.h drm_lib_loader.h drm_logger.h drm_interface.h
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/libdrmutils/drm_interface.h b/libdrmutils/drm_interface.h
new file mode 100644
index 0000000..6c06e20
--- /dev/null
+++ b/libdrmutils/drm_interface.h
@@ -0,0 +1,370 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_INTERFACE_H__
+#define __DRM_INTERFACE_H__
+
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "xf86drm.h"
+#include "xf86drmMode.h"
+
+namespace sde_drm {
+/*
+ * Drm Atomic Operation Codes
+ */
+enum struct DRMOps {
+ /*
+ * Op: Sets plane source crop
+ * Arg: uint32_t - Plane ID
+ * DRMRect - Source Rectangle
+ */
+ PLANE_SET_SRC_RECT,
+ /*
+ * Op: Sets plane destination rect
+ * Arg: uint32_t - Plane ID
+ * DRMRect - Dst Rectangle
+ */
+ PLANE_SET_DST_RECT,
+ /*
+ * Op: Sets plane zorder
+ * Arg: uint32_t - Plane ID
+ * uint32_t - zorder
+ */
+ PLANE_SET_ZORDER,
+ /*
+ * Op: Sets plane rotation flags
+ * Arg: uint32_t - Plane ID
+ * uint32_t - bit mask of rotation flags (See drm_mode.h for enums)
+ */
+ PLANE_SET_ROTATION,
+ /*
+ * Op: Sets plane alpha
+ * Arg: uint32_t - Plane ID
+ * uint32_t - alpha value
+ */
+ PLANE_SET_ALPHA,
+ /*
+ * Op: Sets the blend type
+ * Arg: uint32_t - Plane ID
+ * uint32_t - blend type (see DRMBlendType)
+ */
+ PLANE_SET_BLEND_TYPE,
+ /*
+ * Op: Sets horizontal decimation
+ * Arg: uint32_t - Plane ID
+ * uint32_t - decimation factor
+ */
+ PLANE_SET_H_DECIMATION,
+ /*
+ * Op: Sets vertical decimation
+ * Arg: uint32_t - Plane ID
+ * uint32_t - decimation factor
+ */
+ PLANE_SET_V_DECIMATION,
+ /*
+ * Op: Sets frame buffer ID for plane. Set together with CRTC.
+ * Arg: uint32_t - Plane ID
+ * uint32_t - Framebuffer ID
+ */
+ PLANE_SET_FB_ID,
+ /*
+ * Op: Sets the crtc for this plane. Set together with FB_ID.
+ * Arg: uint32_t - Plane ID
+ * uint32_t - CRTC ID
+ */
+ PLANE_SET_CRTC,
+ /*
+ * Op: Sets acquire fence for this plane's buffer. Set together with FB_ID, CRTC.
+ * Arg: uint32_t - Plane ID
+ * uint32_t - Input fence
+ */
+ PLANE_SET_INPUT_FENCE,
+ /*
+ * Op: Activate or deactivate a CRTC
+ * Arg: uint32_t - CRTC ID
+ * uint32_t - 1 to enable, 0 to disable
+ */
+ CRTC_SET_ACTIVE,
+ /*
+ * Op: Sets display mode
+ * Arg: uint32_t - CRTC ID
+ * drmModeModeInfo* - Pointer to display mode
+ */
+ CRTC_SET_MODE,
+ /*
+ * Op: Sets an offset indicating when a release fence should be signalled.
+ * Arg: uint32_t - offset
+ * 0: non-speculative, default
+ * 1: speculative
+ */
+ CRTC_SET_OUTPUT_FENCE_OFFSET,
+ /*
+ * Op: Returns release fence for this frame. Should be called after Commit() on
+ * DRMAtomicReqInterface.
+ * Arg: uint32_t - CRTC ID
+ * int * - Pointer to an integer that will hold the returned fence
+ */
+ CRTC_GET_RELEASE_FENCE,
+ /*
+ * Op: Returns retire fence for this commit. Should be called after Commit() on
+ * DRMAtomicReqInterface.
+ * Arg: uint32_t - Connector ID
+ * int * - Pointer to an integer that will hold the returned fence
+ */
+ CONNECTOR_GET_RETIRE_FENCE,
+ /*
+ * Op: Sets writeback connector destination rect
+ * Arg: uint32_t - Connector ID
+ * DRMRect - Dst Rectangle
+ */
+ CONNECTOR_SET_OUTPUT_RECT,
+ /*
+ * Op: Sets frame buffer ID for writeback connector.
+ * Arg: uint32_t - Connector ID
+ * uint32_t - Framebuffer ID
+ */
+ CONNECTOR_SET_OUTPUT_FB_ID,
+};
+
+enum struct DRMBlendType {
+ UNDEFINED = 0,
+ OPAQUE = 1,
+ PREMULTIPLIED = 2,
+ COVERAGE = 3,
+};
+
+/* Display type to identify a suitable connector */
+enum struct DRMDisplayType {
+ PERIPHERAL,
+ TV,
+ VIRTUAL,
+};
+
+struct DRMRect {
+ uint32_t left; // Left-most pixel coordinate.
+ uint32_t top; // Top-most pixel coordinate.
+ uint32_t right; // Right-most pixel coordinate.
+ uint32_t bottom; // Bottom-most pixel coordinate.
+};
+
+//------------------------------------------------------------------------
+// DRM Info Query Types
+//------------------------------------------------------------------------
+
+enum struct QSEEDVersion {
+ V1,
+ V2,
+ V3,
+};
+
+/* Per CRTC Resource Info*/
+struct DRMCrtcInfo {
+ bool has_src_split;
+ uint32_t max_blend_stages;
+ QSEEDVersion qseed_version;
+};
+
+enum struct DRMPlaneType {
+ // Has CSC and scaling capability
+ VIG = 0,
+ // Has scaling capability but no CSC
+ RGB,
+ // No scaling support
+ DMA,
+ // Supports a small dimension and doesn't use a CRTC stage
+ CURSOR,
+ MAX,
+};
+
+struct DRMPlaneTypeInfo {
+ // FourCC format enum and modifier
+ std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
+ uint32_t max_linewidth;
+ uint32_t max_upscale;
+ uint32_t max_downscale;
+ uint32_t max_horizontal_deci;
+ uint32_t max_vertical_deci;
+};
+
+/* All DRM Planes Info*/
+struct DRMPlanesInfo {
+ // Plane id and plane type sorted by highest to lowest priority
+ std::vector<std::pair<uint32_t, DRMPlaneType>> planes;
+ // Plane type and type info
+ std::map<DRMPlaneType, DRMPlaneTypeInfo> types;
+};
+
+enum struct DRMTopology {
+ UNKNOWN, // To be compat with driver defs in sde_kms.h
+ SINGLE_LM,
+ DUAL_LM,
+ PPSPLIT,
+ DUAL_LM_MERGE,
+};
+
+enum struct DRMPanelMode {
+ VIDEO,
+ COMMAND,
+};
+
+/* Per Connector Info*/
+struct DRMConnectorInfo {
+ uint32_t mmWidth;
+ uint32_t mmHeight;
+ uint32_t type;
+ uint32_t num_modes;
+ drmModeModeInfo *modes;
+ DRMTopology topology;
+ std::string panel_name;
+ DRMPanelMode panel_mode;
+ bool is_primary;
+ // Valid only if DRMPanelMode is VIDEO
+ bool dynamic_fps;
+ // FourCC format enum and modifier
+ std::vector<std::pair<uint32_t, uint64_t>> formats_supported;
+ // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL
+ uint32_t max_linewidth;
+};
+
+/* Identifier token for a display */
+struct DRMDisplayToken {
+ uint32_t conn_id;
+ uint32_t crtc_id;
+};
+
+/* DRM Atomic Request Property Set.
+ *
+ * Helper class to create and populate atomic properties of DRM components
+ * when rendered in DRM atomic mode */
+class DRMAtomicReqInterface {
+ public:
+ virtual ~DRMAtomicReqInterface() {}
+ /* Perform request operation.
+ *
+ * [input]: opcode: operation code from DRMOps list.
+ * var_arg: arguments for DRMOps's can differ in number and
+ * data type. Refer above DRMOps to details.
+ * [return]: Error code if the API fails, 0 on success.
+ */
+ virtual int Perform(DRMOps opcode, ...) = 0;
+
+ /*
+ * Commit the params set via Perform(). Also resets the properties after commit. Needs to be
+ * called every frame.
+ * [input]: synchronous: Determines if the call should block until a h/w flip
+ * [return]: Error code if the API fails, 0 on success.
+ */
+ virtual int Commit(bool synchronous) = 0;
+ /*
+ * Validate the params set via Perform().
+ * [return]: Error code if the API fails, 0 on success.
+ */
+ virtual int Validate() = 0;
+};
+
+class DRMManagerInterface;
+
+/* Populates a singleton instance of DRMManager */
+typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf);
+
+/* Destroy DRMManager instance */
+typedef int (*DestroyDRMManager)(DRMManagerInterface *intf);
+
+/*
+ * DRM Manager Interface - Any class which plans to implement helper function for vendor
+ * specific DRM driver implementation must implement the below interface routines to work
+ * with SDM.
+ */
+
+class DRMManagerInterface {
+ public:
+ virtual ~DRMManagerInterface() {}
+
+ /*
+ * Since SDM completely manages the planes. GetPlanesInfo will provide all
+ * the plane information.
+ * [output]: DRMPlanesInfo: Resource Info for planes.
+ */
+ virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0;
+
+ /*
+ * Will provide all the information of a selected crtc.
+ * [input]: Use crtc id 0 to obtain system wide info
+ * [output]: DRMCrtcInfo: Resource Info for the given CRTC id.
+ */
+ virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0;
+
+ /*
+ * Will provide all the information of a selected connector.
+ * [output]: DRMConnectorInfo: Resource Info for the given connector id
+ */
+ virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0;
+
+ /*
+ * Register a logical display to receive a token.
+ * Each display pipeline in DRM is identified by its CRTC and Connector(s).
+ * On display connect(bootup or hotplug), clients should invoke this interface to
+ * establish the pipeline for the display and should get a DisplayToken
+ * populated with crtc and connnector(s) id's. Here onwards, Client should
+ * use this token to represent the display for any Perform operations if
+ * needed.
+ *
+ * [input]: disp_type - Peripheral / TV / Virtual
+ * [output]: DRMDisplayToken - CRTC and Connector id's for the display
+ * [return]: 0 on success, a negative error value otherwise
+ */
+ virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0;
+
+ /* Client should invoke this interface on display disconnect.
+ * [input]: DRMDisplayToken - identifier for the display.
+ */
+ virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0;
+
+ /*
+ * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token
+ * returned as part of RegisterDisplay API. Needs to be called per display.
+ * [input]: DRMDisplayToken that identifies a display pipeline
+ * [output]: Pointer to an instance of DRMAtomicReqInterface.
+ * [return]: Error code if the API fails, 0 on success.
+ */
+ virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0;
+
+ /*
+ * Destroys the instance of DRMAtomicReqInterface
+ * [input]: Pointer to a DRMAtomicReqInterface
+ * [return]: Error code if the API fails, 0 on success.
+ */
+ virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0;
+};
+} // namespace sde_drm
+#endif // __DRM_INTERFACE_H__
diff --git a/libdrmutils/drm_lib_loader.cpp b/libdrmutils/drm_lib_loader.cpp
new file mode 100644
index 0000000..845c150
--- /dev/null
+++ b/libdrmutils/drm_lib_loader.cpp
@@ -0,0 +1,77 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <dlfcn.h>
+
+#include "drm_lib_loader.h"
+
+#define __CLASS__ "DRMLibLoader"
+
+using std::mutex;
+using std::lock_guard;
+
+namespace drm_utils {
+
+DRMLibLoader *DRMLibLoader::s_instance = nullptr;
+mutex DRMLibLoader::s_lock;
+
+DRMLibLoader *DRMLibLoader::GetInstance() {
+ lock_guard<mutex> obj(s_lock);
+
+ if (!s_instance) {
+ s_instance = new DRMLibLoader();
+ }
+
+ return s_instance;
+}
+
+DRMLibLoader::DRMLibLoader() {
+ if (Open("libsdedrm.so")) {
+ if (Sym("GetDRMManager", reinterpret_cast<void **>(&func_get_drm_manager_)) &&
+ Sym("DestroyDRMManager", reinterpret_cast<void **>(&func_destroy_drm_manager_))) {
+ is_loaded_ = true;
+ }
+ }
+}
+
+bool DRMLibLoader::Open(const char *lib_name) {
+ lib_ = ::dlopen(lib_name, RTLD_NOW);
+
+ return (lib_ != nullptr);
+}
+
+bool DRMLibLoader::Sym(const char *func_name, void **func_ptr) {
+ if (lib_) {
+ *func_ptr = ::dlsym(lib_, func_name);
+ }
+
+ return (*func_ptr != nullptr);
+}
+
+} // namespace drm_utils
diff --git a/libdrmutils/drm_lib_loader.h b/libdrmutils/drm_lib_loader.h
new file mode 100644
index 0000000..dbc31a5
--- /dev/null
+++ b/libdrmutils/drm_lib_loader.h
@@ -0,0 +1,63 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_LIB_LOADER_H__
+#define __DRM_LIB_LOADER_H__
+
+#include <drm_interface.h>
+#include <mutex>
+
+namespace drm_utils {
+
+class DRMLibLoader {
+ public:
+ ~DRMLibLoader() {}
+ bool IsLoaded() { return is_loaded_; }
+ sde_drm::GetDRMManager FuncGetDRMManager() { return func_get_drm_manager_; }
+ sde_drm::DestroyDRMManager FuncDestroyDRMManager() { return func_destroy_drm_manager_; }
+
+ static DRMLibLoader *GetInstance();
+
+ private:
+ DRMLibLoader();
+ bool Open(const char *lib_name);
+ bool Sym(const char *func_name, void **func_ptr);
+
+ void *lib_ = {};
+ sde_drm::GetDRMManager func_get_drm_manager_ = {};
+ sde_drm::DestroyDRMManager func_destroy_drm_manager_ = {};
+ bool is_loaded_ = false;
+
+ static DRMLibLoader *s_instance; // Singleton instance
+ static std::mutex s_lock;
+};
+
+} // namespace drm_utils
+
+#endif // __DRM_LIB_LOADER_H__
diff --git a/libdrmutils/drm_logger.h b/libdrmutils/drm_logger.h
new file mode 100644
index 0000000..d0b0773
--- /dev/null
+++ b/libdrmutils/drm_logger.h
@@ -0,0 +1,69 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_LOGGER_H__
+#define __DRM_LOGGER_H__
+
+#include <utility>
+
+namespace drm_utils {
+
+class DRMLogger {
+ public:
+ virtual ~DRMLogger() {}
+ virtual void Error(const char *format, ...) = 0;
+ virtual void Warning(const char *format, ...) = 0;
+ virtual void Info(const char *format, ...) = 0;
+ virtual void Debug(const char *format, ...) = 0;
+
+ static void Set(DRMLogger *logger) { s_instance = logger; }
+ static DRMLogger *Get() { return s_instance; }
+
+ private:
+ static DRMLogger *s_instance;
+};
+
+#define DRM_LOG(method, format, ...) \
+ if (drm_utils::DRMLogger::Get()) { \
+ drm_utils::DRMLogger::Get()->method(format, ##__VA_ARGS__); \
+ }
+
+#define DRM_LOG_CONTEXT(method, format, ...) \
+ DRM_LOG(method, __CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__);
+
+#define DRM_LOGE(format, ...) DRM_LOG_CONTEXT(Error, format, ##__VA_ARGS__)
+#define DRM_LOGW(format, ...) DRM_LOG_CONTEXT(Warning, format, ##__VA_ARGS__)
+#define DRM_LOGI(format, ...) DRM_LOG_CONTEXT(Info, format, ##__VA_ARGS__)
+#define DRM_LOGD_IF(pred, format, ...) \
+ if (pred) \
+ DRM_LOG_CONTEXT(Debug, format, ##__VA_ARGS__)
+
+} // namespace drm_utils
+
+#endif // __DRM_LOGGER_H__
diff --git a/libdrmutils/drm_master.cpp b/libdrmutils/drm_master.cpp
new file mode 100644
index 0000000..46ea24e
--- /dev/null
+++ b/libdrmutils/drm_master.cpp
@@ -0,0 +1,137 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <drm/drm_fourcc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <algorithm>
+#include <iterator>
+
+#include "drm_master.h"
+
+#define __CLASS__ "DRMMaster"
+
+using std::mutex;
+using std::lock_guard;
+using std::begin;
+using std::copy;
+using std::end;
+using std::fill;
+
+namespace drm_utils {
+
+DRMLogger *DRMLogger::s_instance = nullptr;
+DRMMaster *DRMMaster::s_instance = nullptr;
+mutex DRMMaster::s_lock;
+
+int DRMMaster::GetInstance(DRMMaster **master) {
+ lock_guard<mutex> obj(s_lock);
+
+ if (!s_instance) {
+ s_instance = new DRMMaster();
+ if (s_instance->Init() < 0) {
+ delete s_instance;
+ s_instance = nullptr;
+ return -ENODEV;
+ }
+ }
+
+ *master = s_instance;
+ return 0;
+}
+
+int DRMMaster::Init() {
+ dev_fd_ = drmOpen("msm_drm", nullptr);
+ if (dev_fd_ < 0) {
+ DRM_LOGE("drmOpen failed with error %d", dev_fd_);
+ return -ENODEV;
+ }
+
+ return 0;
+}
+
+DRMMaster::~DRMMaster() {
+ drmClose(dev_fd_);
+ dev_fd_ = -1;
+}
+
+int DRMMaster::CreateFbId(const DRMBuffer &drm_buffer, uint32_t *gem_handle, uint32_t *fb_id) {
+ int ret = drmPrimeFDToHandle(dev_fd_, drm_buffer.fd, gem_handle);
+ if (ret) {
+ DRM_LOGE("drmPrimeFDToHandle failed with error %d", ret);
+ return ret;
+ }
+
+ uint32_t gem_handles[4] = {0};
+ uint32_t pitches[4] = {0};
+ uint32_t offsets[4] = {0};
+ uint64_t modifier[4] = {0};
+
+ fill(begin(gem_handles), begin(gem_handles) + drm_buffer.num_planes, *gem_handle);
+ copy(begin(drm_buffer.stride), end(drm_buffer.stride), begin(pitches));
+ copy(begin(drm_buffer.offset), end(drm_buffer.offset), begin(offsets));
+ fill(begin(modifier), begin(modifier) + drm_buffer.num_planes, drm_buffer.drm_format_modifier);
+
+ ret = drmModeAddFB3(dev_fd_, drm_buffer.width, drm_buffer.height, drm_buffer.drm_format,
+ gem_handles, pitches, offsets, modifier, fb_id, DRM_MODE_FB_MODIFIERS);
+ if (ret) {
+ DRM_LOGE("drmModeAddFB3 failed with error %d", ret);
+ struct drm_gem_close gem_close = {};
+ gem_close.handle = *gem_handle;
+ int ret1 = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
+ if (ret1) {
+ DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", ret1);
+ }
+ }
+
+ return ret;
+}
+
+int DRMMaster::RemoveFbId(uint32_t gem_handle, uint32_t fb_id) {
+ int ret = drmModeRmFB(dev_fd_, fb_id);
+ if (ret) {
+ DRM_LOGE("drmModeRmFB failed with error %d", ret);
+ }
+
+ struct drm_gem_close gem_close = {};
+ gem_close.handle = gem_handle;
+ ret = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
+ if (ret) {
+ DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", ret);
+ }
+
+ return ret;
+}
+
+} // namespace drm_utils
diff --git a/libdrmutils/drm_master.h b/libdrmutils/drm_master.h
new file mode 100644
index 0000000..8c32a1b
--- /dev/null
+++ b/libdrmutils/drm_master.h
@@ -0,0 +1,94 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_MASTER_H__
+#define __DRM_MASTER_H__
+
+#include <mutex>
+
+#include "drm_logger.h"
+
+namespace drm_utils {
+
+struct DRMBuffer {
+ int fd = -1;
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint32_t drm_format = 0;
+ uint64_t drm_format_modifier = 0;
+ uint32_t stride[4] = {};
+ uint32_t offset[4] = {};
+ uint32_t num_planes = 1;
+};
+
+class DRMMaster {
+ public:
+ ~DRMMaster();
+ /* Converts from ION fd --> Prime Handle --> FB_ID.
+ * Input:
+ * drm_buffer: A DRMBuffer obj that packages description of buffer
+ * Output:
+ * fb_id: Pointer to store DRM framebuffer id into
+ * Returns:
+ * ioctl error code
+ */
+ int CreateFbId(const DRMBuffer &drm_buffer, uint32_t *gem_handle, uint32_t *fb_id);
+ /* Removes the fb_id from DRM
+ * Input:
+ * fb_id: DRM FB to be removed
+ * Returns:
+ * ioctl error code
+ */
+ int RemoveFbId(uint32_t gem_handle, uint32_t fb_id);
+ /* Poplulates master DRM fd
+ * Input:
+ * fd: Pointer to store master fd into
+ */
+ void GetHandle(int *fd) { *fd = dev_fd_; }
+
+ /* Creates an instance of DRMMaster if it doesn't exist and initializes it. Threadsafe.
+ * Input:
+ * master: Pointer to store a pointer to the instance
+ * Returns:
+ * -ENODEV if device cannot be opened or initilization fails
+ */
+ static int GetInstance(DRMMaster **master);
+
+ private:
+ DRMMaster() {}
+ int Init();
+
+ int dev_fd_ = -1; // Master fd for DRM
+ static DRMMaster *s_instance; // Singleton instance
+ static std::mutex s_lock;
+};
+
+} // namespace drm_utils
+
+#endif // __DRM_MASTER_H__
diff --git a/libdrmutils/drm_res_mgr.cpp b/libdrmutils/drm_res_mgr.cpp
new file mode 100644
index 0000000..1d29495
--- /dev/null
+++ b/libdrmutils/drm_res_mgr.cpp
@@ -0,0 +1,151 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <errno.h>
+
+#include "drm_master.h"
+#include "drm_res_mgr.h"
+
+#define DEBUG 0
+#define __CLASS__ "DRMResMgr"
+
+using std::mutex;
+using std::lock_guard;
+
+namespace drm_utils {
+
+DRMResMgr *DRMResMgr::s_instance = nullptr;
+mutex DRMResMgr::s_lock;
+
+static bool GetConnector(int dev_fd, drmModeRes *res, drmModeConnector **connector) {
+ for (auto i = 0; i < res->count_connectors; i++) {
+ drmModeConnector *conn = drmModeGetConnector(dev_fd, res->connectors[i]);
+ if (conn && conn->connector_type == DRM_MODE_CONNECTOR_DSI && conn->count_modes &&
+ conn->connection == DRM_MODE_CONNECTED) {
+ *connector = conn;
+ DRM_LOGI("Found connector %d", conn->connector_id);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool GetEncoder(int dev_fd, drmModeConnector *conn, drmModeEncoder **encoder) {
+ for (auto i = 0; i < conn->count_encoders; i++) {
+ drmModeEncoder *enc = drmModeGetEncoder(dev_fd, conn->encoders[i]);
+ if (enc && enc->encoder_type == DRM_MODE_ENCODER_DSI) {
+ *encoder = enc;
+ DRM_LOGI("Found encoder %d", enc->encoder_id);
+ return true;
+ }
+ }
+ return false;
+}
+
+static bool GetCrtc(int dev_fd, drmModeRes *res, drmModeEncoder *enc, drmModeCrtc **crtc) {
+ for (auto i = 0; i < res->count_crtcs; i++) {
+ if (enc->possible_crtcs & (1 << i)) {
+ drmModeCrtc *c = drmModeGetCrtc(dev_fd, res->crtcs[i]);
+ if (c) {
+ *crtc = c;
+ DRM_LOGI("Found crtc %d", c->crtc_id);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+#define __CLASS__ "DRMResMgr"
+
+int DRMResMgr::GetInstance(DRMResMgr **res_mgr) {
+ lock_guard<mutex> obj(s_lock);
+
+ if (!s_instance) {
+ s_instance = new DRMResMgr();
+ if (s_instance->Init() < 0) {
+ delete s_instance;
+ s_instance = nullptr;
+ return -ENODEV;
+ }
+ }
+
+ *res_mgr = s_instance;
+ return 0;
+}
+
+int DRMResMgr::Init() {
+ DRMMaster *master = nullptr;
+ int dev_fd = -1;
+
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ return ret;
+ }
+
+ master->GetHandle(&dev_fd);
+ drmModeRes *res = drmModeGetResources(dev_fd);
+ if (res == nullptr) {
+ DRM_LOGE("drmModeGetResources failed");
+ return -ENODEV;
+ }
+
+ drmModeConnector *conn = nullptr;
+ if (!GetConnector(dev_fd, res, &conn)) {
+ DRM_LOGE("Failed to find a connector");
+ return -ENODEV;
+ }
+
+ drmModeEncoder *enc = nullptr;
+ if (!GetEncoder(dev_fd, conn, &enc)) {
+ DRM_LOGE("Failed to find an encoder");
+ drmModeFreeConnector(conn);
+ return -ENODEV;
+ }
+
+ drmModeCrtc *crtc = nullptr;
+ if (!GetCrtc(dev_fd, res, enc, &crtc)) {
+ DRM_LOGE("Failed to find a crtc");
+ drmModeFreeEncoder(enc);
+ drmModeFreeConnector(conn);
+ drmModeFreeResources(res);
+ return -ENODEV;
+ }
+
+ res_ = res;
+ conn_ = conn;
+ enc_ = enc;
+ crtc_ = crtc;
+
+ return 0;
+}
+
+} // namespace drm_utils
diff --git a/libdrmutils/drm_res_mgr.h b/libdrmutils/drm_res_mgr.h
new file mode 100644
index 0000000..3a8378c
--- /dev/null
+++ b/libdrmutils/drm_res_mgr.h
@@ -0,0 +1,72 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __DRM_RES_MGR_H__
+#define __DRM_RES_MGR_H__
+
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include <mutex>
+
+namespace drm_utils {
+
+class DRMResMgr {
+ public:
+ /* Returns the default connector id for primary panel */
+ void GetConnectorId(uint32_t *id) { *id = conn_->connector_id; }
+ /* Returns the default crtc id for primary pipeline */
+ void GetCrtcId(uint32_t *id) { *id = crtc_->crtc_id; }
+ /* Returns the default mode currently used by the connector */
+ void GetMode(drmModeModeInfo *mode) { *mode = conn_->modes[0]; }
+ /* Returns the panel dimensions in mm */
+ void GetDisplayDimInMM(uint32_t *w, uint32_t *h) {
+ *w = conn_->mmWidth;
+ *h = conn_->mmHeight;
+ }
+
+ /* Creates and initializes an instance of DRMResMgr. On success, returns a pointer to it, on
+ * failure returns -ENODEV */
+ static int GetInstance(DRMResMgr **res_mgr);
+
+ private:
+ int Init();
+
+ drmModeRes *res_ = nullptr;
+ drmModeConnector *conn_ = nullptr;
+ drmModeEncoder *enc_ = nullptr;
+ drmModeCrtc *crtc_ = nullptr;
+
+ static DRMResMgr *s_instance;
+ static std::mutex s_lock;
+};
+
+} // namespace drm_utils
+
+#endif // __DRM_RES_MGR_H__
diff --git a/libgralloc/Android.mk b/libgralloc/Android.mk
index c1d4d79..6a0f868 100644
--- a/libgralloc/Android.mk
+++ b/libgralloc/Android.mk
@@ -23,7 +23,7 @@
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
LOCAL_SHARED_LIBRARIES := $(common_libs) libmemalloc libqdMetaData libqdutils
ifneq ($(TARGET_IS_HEADLESS), true)
-LOCAL_SHARED_LIBRARIES += libGLESv1_CM
+LOCAL_SHARED_LIBRARIES += libGLESv1_CM libdrmutils
endif
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 7190fc0..805948b 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -30,24 +30,18 @@
#include <cutils/log.h>
#include <fcntl.h>
#include <dlfcn.h>
+#include <media/msm_media_info.h>
+#include <qdMetaData.h>
+#include <utils/Singleton.h>
+#include <utils/Mutex.h>
+#include <algorithm>
+
#include "gralloc_priv.h"
#include "alloc_controller.h"
#include "memalloc.h"
#include "ionalloc.h"
#include "gr.h"
#include "qd_utils.h"
-#include <qdMetaData.h>
-#include <utils/Singleton.h>
-#include <utils/Mutex.h>
-#include <algorithm>
-
-#ifdef VENUS_COLOR_FORMAT
-#include <media/msm_media_info.h>
-#else
-#define VENUS_Y_STRIDE(args...) 0
-#define VENUS_Y_SCANLINES(args...) 0
-#define VENUS_BUFFER_SIZE(args...) 0
-#endif
#define ASTC_BLOCK_SIZE 16
@@ -203,6 +197,7 @@
case HAL_PIXEL_FORMAT_R_8:
case HAL_PIXEL_FORMAT_RG_88:
case HAL_PIXEL_FORMAT_BGRX_8888:
+ case HAL_PIXEL_FORMAT_BGR_888:
case HAL_PIXEL_FORMAT_RGBA_1010102:
case HAL_PIXEL_FORMAT_ARGB_2101010:
case HAL_PIXEL_FORMAT_RGBX_1010102:
@@ -262,6 +257,7 @@
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case HAL_PIXEL_FORMAT_YCrCb_422_I:
case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ case HAL_PIXEL_FORMAT_CbYCrY_422_I:
aligned_w = ALIGN(width, 16);
break;
case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
@@ -593,6 +589,7 @@
case HAL_PIXEL_FORMAT_YCrCb_422_SP:
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case HAL_PIXEL_FORMAT_YCrCb_422_I:
+ case HAL_PIXEL_FORMAT_CbYCrY_422_I:
if(width & 1) {
ALOGE("width is odd for the YUV422_SP format");
return 0;
@@ -813,6 +810,16 @@
ycbcr->cstride = cstride;
ycbcr->chroma_step = 1;
break;
+ case HAL_PIXEL_FORMAT_CbYCrY_422_I:
+ ystride = width * 2;
+ cstride = 0;
+ ycbcr->y = (void*)hnd->base;
+ ycbcr->cr = NULL;
+ ycbcr->cb = NULL;
+ ycbcr->ystride = ystride;
+ ycbcr->cstride = 0;
+ ycbcr->chroma_step = 0;
+ break;
//Unsupported formats
case HAL_PIXEL_FORMAT_YCbCr_422_I:
case HAL_PIXEL_FORMAT_YCrCb_422_I:
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index a0339b4..848c741 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -20,16 +20,216 @@
#include <fcntl.h>
#include <cutils/properties.h>
#include <sys/mman.h>
+#include <linux/msm_ion.h>
+#ifdef COMPILE_DRM
+#include <drm/drm_fourcc.h>
+#include <drm_master.h>
+#endif
+#include <qdMetaData.h>
+#include <qd_utils.h>
+
+#include <algorithm>
#include "gr.h"
#include "gpu.h"
#include "memalloc.h"
#include "alloc_controller.h"
-#include <qdMetaData.h>
-#include <linux/msm_ion.h>
+
+#ifdef COMPILE_DRM
+#ifndef DRM_FORMAT_MOD_QCOM_COMPRESSED
+#define DRM_FORMAT_MOD_QCOM_COMPRESSED fourcc_mod_code(QCOM, 1)
+#endif
+#endif
using namespace gralloc;
+#ifdef COMPILE_DRM
+using namespace drm_utils;
+
+static int getPlaneStrideOffset(private_handle_t *hnd, uint32_t *stride,
+ uint32_t *offset, uint32_t *num_planes) {
+ struct android_ycbcr yuvInfo = {};
+ *num_planes = 1;
+
+ switch (hnd->format) {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ case HAL_PIXEL_FORMAT_BGR_565:
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ stride[0] = hnd->width * 2;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ stride[0] = hnd->width * 3;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ case HAL_PIXEL_FORMAT_RGBA_1010102:
+ case HAL_PIXEL_FORMAT_ARGB_2101010:
+ case HAL_PIXEL_FORMAT_RGBX_1010102:
+ case HAL_PIXEL_FORMAT_XRGB_2101010:
+ case HAL_PIXEL_FORMAT_BGRA_1010102:
+ case HAL_PIXEL_FORMAT_ABGR_2101010:
+ case HAL_PIXEL_FORMAT_BGRX_1010102:
+ case HAL_PIXEL_FORMAT_XBGR_2101010:
+ stride[0] = hnd->width * 4;
+ break;
+ }
+
+ // Format is RGB
+ if (stride[0]) {
+ return 0;
+ }
+
+ (*num_planes)++;
+ int ret = getYUVPlaneInfo(hnd, &yuvInfo);
+ if (ret < 0) {
+ ALOGE("%s failed", __FUNCTION__);
+ return ret;
+ }
+
+ stride[0] = static_cast<uint32_t>(yuvInfo.ystride);
+ offset[0] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base);
+ stride[1] = static_cast<uint32_t>(yuvInfo.cstride);
+ switch (hnd->format) {
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
+ break;
+ case HAL_PIXEL_FORMAT_YV12:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
+ stride[2] = static_cast<uint32_t>(yuvInfo.cstride);
+ offset[2] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
+ (*num_planes)++;
+ break;
+ default:
+ ALOGW("%s: Unsupported format %s", __FUNCTION__,
+ qdutils::GetHALPixelFormatString(hnd->format));
+ }
+
+ if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+ std::fill(offset, offset + 4, 0);
+ }
+
+ return 0;
+}
+
+static void getDRMFormat(int hal_format, int flags, uint32_t *drm_format,
+ uint64_t *drm_format_modifier) {
+
+ if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+ *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
+ }
+
+ switch (hal_format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ *drm_format = DRM_FORMAT_RGBA8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ *drm_format = DRM_FORMAT_RGBA5551;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ *drm_format = DRM_FORMAT_RGBA4444;
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ *drm_format = DRM_FORMAT_BGRA8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ *drm_format = DRM_FORMAT_RGBX8888;
+ break;
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ *drm_format = DRM_FORMAT_BGRX8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ *drm_format = DRM_FORMAT_RGB888;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ *drm_format = DRM_FORMAT_RGB565;
+ break;
+ case HAL_PIXEL_FORMAT_BGR_565:
+ *drm_format = DRM_FORMAT_BGR565;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_1010102:
+ *drm_format = DRM_FORMAT_RGBA1010102;
+ break;
+ case HAL_PIXEL_FORMAT_ARGB_2101010:
+ *drm_format = DRM_FORMAT_ARGB2101010;
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_1010102:
+ *drm_format = DRM_FORMAT_RGBX1010102;
+ break;
+ case HAL_PIXEL_FORMAT_XRGB_2101010:
+ *drm_format = DRM_FORMAT_XRGB2101010;
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_1010102:
+ *drm_format = DRM_FORMAT_BGRA1010102;
+ break;
+ case HAL_PIXEL_FORMAT_ABGR_2101010:
+ *drm_format = DRM_FORMAT_ABGR2101010;
+ break;
+ case HAL_PIXEL_FORMAT_BGRX_1010102:
+ *drm_format = DRM_FORMAT_BGRX1010102;
+ break;
+ case HAL_PIXEL_FORMAT_XBGR_2101010:
+ *drm_format = DRM_FORMAT_XBGR2101010;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ *drm_format = DRM_FORMAT_NV12;
+ break;
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ *drm_format = DRM_FORMAT_NV12;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ *drm_format = DRM_FORMAT_NV12;
+ *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ *drm_format = DRM_FORMAT_NV21;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
+ *drm_format = DRM_FORMAT_NV21;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ // TODO *drm_format = DRM_FORMAT_P010;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+ // TODO *drm_format = DRM_FORMAT_P010;
+ // *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED |
+ // DRM_FORMAT_MOD_QCOM_TIGHT;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ *drm_format = DRM_FORMAT_NV16;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ *drm_format = DRM_FORMAT_NV61;
+ break;
+ case HAL_PIXEL_FORMAT_YV12:
+ *drm_format = DRM_FORMAT_YVU420;
+ break;
+ default:
+ ALOGW("%s: Unsupported format %s", __FUNCTION__,
+ qdutils::GetHALPixelFormatString(hal_format));
+ }
+}
+#endif
+
gpu_context_t::gpu_context_t(const private_module_t* module,
IAllocController* alloc_ctrl ) :
mAllocCtrl(alloc_ctrl)
@@ -169,11 +369,46 @@
ColorSpace_t colorSpace = ITU_R_601;
setMetaData(hnd, UPDATE_COLOR_SPACE, (void*) &colorSpace);
+#ifdef COMPILE_DRM
+ if (qdutils::getDriverType() == qdutils::DriverType::DRM &&
+ usage & GRALLOC_USAGE_HW_COMPOSER) {
+ DRMBuffer buf = {};
+ int ret = getPlaneStrideOffset(hnd, buf.stride, buf.offset,
+ &buf.num_planes);
+ if (ret < 0) {
+ ALOGE("%s failed", __FUNCTION__);
+ return ret;
+ }
+
+ buf.fd = hnd->fd;
+ buf.width = hnd->width;
+ buf.height = hnd->height;
+ getDRMFormat(hnd->format, flags, &buf.drm_format,
+ &buf.drm_format_modifier);
+
+ DRMMaster *master = nullptr;
+ ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
+ return ret;
+ }
+
+ ret = master->CreateFbId(buf, &hnd->gem_handle, &hnd->fb_id);
+ if (ret < 0) {
+ ALOGE("%s: CreateFbId failed. width %d, height %d, " \
+ "format: %s, stride %u, error %d", __FUNCTION__,
+ buf.width, buf.height,
+ qdutils::GetHALPixelFormatString(hnd->format),
+ buf.stride[0], errno);
+ return ret;
+ }
+ }
+#endif
+
*pHandle = hnd;
}
ALOGE_IF(err, "gralloc failed err=%s", strerror(-err));
-
return err;
}
@@ -369,6 +604,23 @@
if (err)
return err;
}
+
+#ifdef COMPILE_DRM
+ if (hnd->fb_id) {
+ DRMMaster *master = nullptr;
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
+ return ret;
+ }
+ ret = master->RemoveFbId(hnd->gem_handle, hnd->fb_id);
+ if (ret < 0) {
+ ALOGE("%s: Removing fb_id %d failed with error %d", __FUNCTION__,
+ hnd->fb_id, errno);
+ }
+ }
+#endif
+
delete hnd;
return 0;
}
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 738b63f..5782180 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2011 - 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011 - 2017, The Linux Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,6 +118,8 @@
#define HAL_PIXEL_FORMAT_BGRX_1010102 0x11C
#define HAL_PIXEL_FORMAT_XBGR_2101010 0x11D
#define HAL_PIXEL_FORMAT_YCbCr_420_P010 0x11F
+#define HAL_PIXEL_FORMAT_CbYCrY_422_I 0x120
+#define HAL_PIXEL_FORMAT_BGR_888 0x121
#define HAL_PIXEL_FORMAT_INTERLACE 0x180
@@ -245,6 +247,8 @@
uint64_t base_metadata __attribute__((aligned(8)));
int unaligned_width; // holds width client asked to allocate
int unaligned_height; // holds height client asked to allocate
+ unsigned int gem_handle;
+ unsigned int fb_id;
#ifdef __cplusplus
static const int sNumFds = 2;
@@ -261,7 +265,7 @@
base(0), offset_metadata(0), gpuaddr(0),
format(format), width(width), height(height),
base_metadata(0), unaligned_width(width),
- unaligned_height(height)
+ unaligned_height(height), gem_handle(0), fb_id(0)
{
version = (int) sizeof(native_handle);
numInts = sNumInts();
diff --git a/libgralloc1/Android.mk b/libgralloc1/Android.mk
index b66a027..fb8c74a 100644
--- a/libgralloc1/Android.mk
+++ b/libgralloc1/Android.mk
@@ -10,6 +10,9 @@
external/libcxx/include/
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libqdutils
+ifneq ($(TARGET_IS_HEADLESS), true)
+LOCAL_SHARED_LIBRARIES += libdrmutils
+endif
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -std=c++11 -Werror
LOCAL_CFLAGS += -isystem $(kernel_includes)
LOCAL_CLANG := true
diff --git a/libgralloc1/gr_adreno_info.h b/libgralloc1/gr_adreno_info.h
index 9b239c7..7ad6801 100644
--- a/libgralloc1/gr_adreno_info.h
+++ b/libgralloc1/gr_adreno_info.h
@@ -30,13 +30,7 @@
#ifndef __GR_ADRENO_INFO_H__
#define __GR_ADRENO_INFO_H__
-#ifdef VENUS_COLOR_FORMAT
#include <media/msm_media_info.h>
-#else
-#define VENUS_Y_STRIDE(args...) 0
-#define VENUS_Y_SCANLINES(args...) 0
-#define VENUS_BUFFER_SIZE(args...) 0
-#endif
namespace gralloc1 {
diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp
index cea8ac9..c2d8598 100644
--- a/libgralloc1/gr_buf_mgr.cpp
+++ b/libgralloc1/gr_buf_mgr.cpp
@@ -17,6 +17,9 @@
* limitations under the License.
*/
+#include <drm/drm_fourcc.h>
+#include <drm_master.h>
+
#include <utility>
#include "qd_utils.h"
@@ -28,6 +31,192 @@
namespace gralloc1 {
+using namespace drm_utils;
+
+static int getPlaneStrideOffset(private_handle_t *hnd, uint32_t *stride,
+ uint32_t *offset, uint32_t *num_planes) {
+ struct android_ycbcr yuvInfo = {};
+ *num_planes = 1;
+
+ switch (hnd->format) {
+ case HAL_PIXEL_FORMAT_RGB_565:
+ case HAL_PIXEL_FORMAT_BGR_565:
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ stride[0] = hnd->width * 2;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ stride[0] = hnd->width * 3;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ case HAL_PIXEL_FORMAT_RGBA_1010102:
+ case HAL_PIXEL_FORMAT_ARGB_2101010:
+ case HAL_PIXEL_FORMAT_RGBX_1010102:
+ case HAL_PIXEL_FORMAT_XRGB_2101010:
+ case HAL_PIXEL_FORMAT_BGRA_1010102:
+ case HAL_PIXEL_FORMAT_ABGR_2101010:
+ case HAL_PIXEL_FORMAT_BGRX_1010102:
+ case HAL_PIXEL_FORMAT_XBGR_2101010:
+ stride[0] = hnd->width * 4;
+ break;
+ }
+
+ // Format is RGB
+ if (stride[0]) {
+ return 0;
+ }
+
+ (*num_planes)++;
+ int ret = getYUVPlaneInfo(hnd, &yuvInfo);
+ if (ret < 0) {
+ ALOGE("%s failed", __FUNCTION__);
+ return ret;
+ }
+
+ stride[0] = static_cast<uint32_t>(yuvInfo.ystride);
+ offset[0] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.y) - hnd->base);
+ stride[1] = static_cast<uint32_t>(yuvInfo.cstride);
+ switch (hnd->format) {
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
+ break;
+ case HAL_PIXEL_FORMAT_YV12:
+ offset[1] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cr) - hnd->base);
+ stride[2] = static_cast<uint32_t>(yuvInfo.cstride);
+ offset[2] = static_cast<uint32_t>(
+ reinterpret_cast<uint64_t>(yuvInfo.cb) - hnd->base);
+ (*num_planes)++;
+ break;
+ default:
+ ALOGW("%s: Unsupported format %s", __FUNCTION__,
+ qdutils::GetHALPixelFormatString(hnd->format));
+ }
+
+ if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+ std::fill(offset, offset + 4, 0);
+ }
+
+ return 0;
+}
+
+static void getDRMFormat(int hal_format, int flags, uint32_t *drm_format,
+ uint64_t *drm_format_modifier) {
+
+ if (flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
+ *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
+ }
+
+ switch (hal_format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ *drm_format = DRM_FORMAT_RGBA8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ *drm_format = DRM_FORMAT_RGBA5551;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ *drm_format = DRM_FORMAT_RGBA4444;
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ *drm_format = DRM_FORMAT_BGRA8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ *drm_format = DRM_FORMAT_RGBX8888;
+ break;
+ case HAL_PIXEL_FORMAT_BGRX_8888:
+ *drm_format = DRM_FORMAT_BGRX8888;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_888:
+ *drm_format = DRM_FORMAT_RGB888;
+ break;
+ case HAL_PIXEL_FORMAT_RGB_565:
+ *drm_format = DRM_FORMAT_RGB565;
+ break;
+ case HAL_PIXEL_FORMAT_BGR_565:
+ *drm_format = DRM_FORMAT_BGR565;
+ break;
+ case HAL_PIXEL_FORMAT_RGBA_1010102:
+ *drm_format = DRM_FORMAT_RGBA1010102;
+ break;
+ case HAL_PIXEL_FORMAT_ARGB_2101010:
+ *drm_format = DRM_FORMAT_ARGB2101010;
+ break;
+ case HAL_PIXEL_FORMAT_RGBX_1010102:
+ *drm_format = DRM_FORMAT_RGBX1010102;
+ break;
+ case HAL_PIXEL_FORMAT_XRGB_2101010:
+ *drm_format = DRM_FORMAT_XRGB2101010;
+ break;
+ case HAL_PIXEL_FORMAT_BGRA_1010102:
+ *drm_format = DRM_FORMAT_BGRA1010102;
+ break;
+ case HAL_PIXEL_FORMAT_ABGR_2101010:
+ *drm_format = DRM_FORMAT_ABGR2101010;
+ break;
+ case HAL_PIXEL_FORMAT_BGRX_1010102:
+ *drm_format = DRM_FORMAT_BGRX1010102;
+ break;
+ case HAL_PIXEL_FORMAT_XBGR_2101010:
+ *drm_format = DRM_FORMAT_XBGR2101010;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ *drm_format = DRM_FORMAT_NV12;
+ break;
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ *drm_format = DRM_FORMAT_NV12;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ *drm_format = DRM_FORMAT_NV12;
+ *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ *drm_format = DRM_FORMAT_NV21;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
+ *drm_format = DRM_FORMAT_NV21;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ // TODO *drm_format = DRM_FORMAT_P010;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+ // TODO *drm_format = DRM_FORMAT_P010;
+ // *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED |
+ // DRM_FORMAT_MOD_QCOM_TIGHT;
+ break;
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ *drm_format = DRM_FORMAT_NV16;
+ break;
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ *drm_format = DRM_FORMAT_NV61;
+ break;
+ case HAL_PIXEL_FORMAT_YV12:
+ *drm_format = DRM_FORMAT_YVU420;
+ break;
+ default:
+ ALOGW("%s: Unsupported format %s", __FUNCTION__,
+ qdutils::GetHALPixelFormatString(hal_format));
+
+ }
+}
+
BufferManager::BufferManager() {
char property[PROPERTY_VALUE_MAX];
@@ -139,6 +328,8 @@
descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetProducerUsage(),
descriptor.GetConsumerUsage());
+ // TODO(user): Not sure what to do for fb_id. Use duped fd and new dimensions?
+
*outbuffer = out_hnd;
}
@@ -156,6 +347,19 @@
// delete handle also
private_handle_t *handle = const_cast<private_handle_t *>(hnd);
+ if (handle->fb_id) {
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
+ return ret;
+ }
+ ret = master->RemoveFbId(hnd->gem_handle, hnd->fb_id);
+ if (ret < 0) {
+ ALOGE("%s: Removing fb_id %d failed with error %d", __FUNCTION__,
+ hnd->fb_id, errno);
+ }
+ }
+
delete handle;
return GRALLOC1_ERROR_NONE;
@@ -409,6 +613,39 @@
hnd->gpuaddr = 0;
setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast<void *>(&colorSpace));
+ if (qdutils::getDriverType() == qdutils::DriverType::DRM &&
+ cons_usage & GRALLOC_USAGE_HW_COMPOSER) {
+ DRMBuffer buf = {};
+ int ret = getPlaneStrideOffset(hnd, buf.stride, buf.offset,
+ &buf.num_planes);
+ if (ret < 0) {
+ ALOGE("%s failed", __FUNCTION__);
+ return ret;
+ }
+
+ buf.fd = hnd->fd;
+ buf.width = hnd->width;
+ buf.height = hnd->height;
+ getDRMFormat(hnd->format, flags, &buf.drm_format,
+ &buf.drm_format_modifier);
+
+ DRMMaster *master = nullptr;
+ ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ ALOGE("%s Failed to acquire DRMMaster instance", __FUNCTION__);
+ return ret;
+ }
+
+ ret = master->CreateFbId(buf, &hnd->gem_handle, &hnd->fb_id);
+ if (ret < 0) {
+ ALOGE("%s: CreateFbId failed. width %d, height %d, " \
+ "format: %s, stride %u, error %d", __FUNCTION__,
+ buf.width, buf.height,
+ qdutils::GetHALPixelFormatString(hnd->format),
+ buf.stride[0], errno);
+ return ret;
+ }
+ }
*handle = hnd;
diff --git a/libgralloc1/gr_priv_handle.h b/libgralloc1/gr_priv_handle.h
index ee38b4d..8a01d38 100644
--- a/libgralloc1/gr_priv_handle.h
+++ b/libgralloc1/gr_priv_handle.h
@@ -84,6 +84,7 @@
int stride;
uint64_t base_metadata __attribute__((aligned(8)));
+ unsigned int fb_id;
// added for gralloc1
int unaligned_width; // holds width client asked to allocate
@@ -117,7 +118,8 @@
unaligned_width(width),
unaligned_height(height),
producer_usage(GRALLOC1_PRODUCER_USAGE_NONE),
- consumer_usage(GRALLOC1_CONSUMER_USAGE_NONE) {
+ consumer_usage(GRALLOC1_CONSUMER_USAGE_NONE),
+ fb_id(0) {
version = static_cast<int>(sizeof(native_handle));
numInts = NumInts();
numFds = kNumFds;
diff --git a/libmemtrack/kgsl.c b/libmemtrack/kgsl.c
index 877b54e..3f36b8d 100644
--- a/libmemtrack/kgsl.c
+++ b/libmemtrack/kgsl.c
@@ -74,7 +74,7 @@
while (1) {
unsigned long size, mapsize;
char line_type[7];
- char flags[9];
+ char flags[10];
char line_usage[19];
int ret, egl_surface_count = 0, egl_image_count = 0;
@@ -86,9 +86,9 @@
* gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg
* 545ba000 545ba000 4096 1 -----pY gpumem arraybuffer 1 4096 0 0
*/
- ret = sscanf(line, "%*x %*x %lu %*d %8s %6s %18s %*d %lu %6d %6d\n",
- &size, flags, line_type, line_usage, &mapsize,
- &egl_surface_count, &egl_image_count);
+ ret = sscanf(line, "%*x %*x %lu %*d %9s %6s %18s %*d %lu %6d %6d\n",
+ &size, flags, line_type, line_usage, &mapsize,
+ &egl_surface_count, &egl_image_count);
if (ret != 7) {
continue;
}
diff --git a/libqdutils/qd_utils.cpp b/libqdutils/qd_utils.cpp
index 170b1d8..10ac90b 100644
--- a/libqdutils/qd_utils.cpp
+++ b/libqdutils/qd_utils.cpp
@@ -28,6 +28,7 @@
*/
#include <unistd.h>
+#include <gralloc_priv.h>
#include "qd_utils.h"
namespace qdutils {
@@ -281,4 +282,79 @@
return access(fb_caps, F_OK) ? DriverType::DRM : DriverType::FB;
}
+const char *GetHALPixelFormatString(int format) {
+ switch (format) {
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return "RGBA_8888";
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ return "RGBX_8888";
+ case HAL_PIXEL_FORMAT_RGB_888:
+ return "RGB_888";
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return "RGB_565";
+ case HAL_PIXEL_FORMAT_BGR_565:
+ return "BGR_565";
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ return "BGRA_8888";
+ case HAL_PIXEL_FORMAT_RGBA_5551:
+ return "RGBA_5551";
+ case HAL_PIXEL_FORMAT_RGBA_4444:
+ return "RGBA_4444";
+ case HAL_PIXEL_FORMAT_YV12:
+ return "YV12";
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ return "YCbCr_422_SP_NV16";
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ return "YCrCb_420_SP_NV21";
+ case HAL_PIXEL_FORMAT_YCbCr_422_I:
+ return "YCbCr_422_I_YUY2";
+ case HAL_PIXEL_FORMAT_YCrCb_422_I:
+ return "YCrCb_422_I_YVYU";
+ case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
+ return "NV12_ENCODEABLE";
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
+ return "YCbCr_420_SP_TILED_TILE_4x2";
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+ return "YCbCr_420_SP";
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
+ return "YCrCb_420_SP_ADRENO";
+ case HAL_PIXEL_FORMAT_YCrCb_422_SP:
+ return "YCrCb_422_SP";
+ case HAL_PIXEL_FORMAT_R_8:
+ return "R_8";
+ case HAL_PIXEL_FORMAT_RG_88:
+ return "RG_88";
+ case HAL_PIXEL_FORMAT_INTERLACE:
+ return "INTERLACE";
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
+ return "YCbCr_420_SP_VENUS";
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
+ return "YCrCb_420_SP_VENUS";
+ case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
+ return "YCbCr_420_SP_VENUS_UBWC";
+ case HAL_PIXEL_FORMAT_RGBA_1010102:
+ return "RGBA_1010102";
+ case HAL_PIXEL_FORMAT_ARGB_2101010:
+ return "ARGB_2101010";
+ case HAL_PIXEL_FORMAT_RGBX_1010102:
+ return "RGBX_1010102";
+ case HAL_PIXEL_FORMAT_XRGB_2101010:
+ return "XRGB_2101010";
+ case HAL_PIXEL_FORMAT_BGRA_1010102:
+ return "BGRA_1010102";
+ case HAL_PIXEL_FORMAT_ABGR_2101010:
+ return "ABGR_2101010";
+ case HAL_PIXEL_FORMAT_BGRX_1010102:
+ return "BGRX_1010102";
+ case HAL_PIXEL_FORMAT_XBGR_2101010:
+ return "XBGR_2101010";
+ case HAL_PIXEL_FORMAT_YCbCr_420_P010:
+ return "YCbCr_420_P010";
+ case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
+ return "YCbCr_420_TP10_UBWC";
+ default:
+ return "Unknown_format";
+ }
+}
+
}; //namespace qdutils
diff --git a/libqdutils/qd_utils.h b/libqdutils/qd_utils.h
index 7b3ae40..f3b0c04 100644
--- a/libqdutils/qd_utils.h
+++ b/libqdutils/qd_utils.h
@@ -69,6 +69,7 @@
DRM,
};
DriverType getDriverType();
+const char *GetHALPixelFormatString(int format);
}; //namespace qdutils
#endif
diff --git a/sdm/include/core/layer_buffer.h b/sdm/include/core/layer_buffer.h
index 4b42e7b..636982c 100644
--- a/sdm/include/core/layer_buffer.h
+++ b/sdm/include/core/layer_buffer.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014, 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014, 2016-2017, 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:
@@ -149,6 +149,7 @@
//!< y(0), u(0), y(1), v(0), y(2), u(2), y(3), v(2)
//!< y(n-1), u(n-1), y(n), v(n-1)
+ kFormatCbYCrY422H2V1Packed,
kFormatInvalid = 0xFFFFFFFF,
};
@@ -265,6 +266,7 @@
//!< could be modified by both client and SDM.
uint64_t buffer_id __attribute__((aligned(8))) = 0;
//!< Specifies the buffer id.
+ uint32_t fb_id = 0; // DRM f/w registered framebuffer id
};
// This enum represents buffer layout types.
diff --git a/sdm/include/core/sdm_types.h b/sdm/include/core/sdm_types.h
index af7a20b..367ab38 100644
--- a/sdm/include/core/sdm_types.h
+++ b/sdm/include/core/sdm_types.h
@@ -53,6 +53,7 @@
kErrorHardware, //!< A hardware error has occured.
kErrorTimeOut, //!< The operation has timed out to prevent client from waiting forever.
kErrorShutDown, //!< Driver is processing shutdown sequence
+ kErrorPerfValidation, //!< Bandwidth or Clock requirement validation failure.
};
/*! @brief This structure is defined for client and library compatibility check purpose only. This
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 657d4ac..03b5eab 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -483,6 +483,7 @@
uint32_t v_back_porch = 0; //!< Vertical back porch of panel
uint32_t v_pulse_width = 0; //!< Vertical pulse width of panel
uint32_t h_total = 0; //!< Total width of panel (hActive + hFP + hBP + hPulseWidth)
+ uint32_t v_total = 0; //!< Total height of panel (vActive + vFP + vBP + vPulseWidth)
std::bitset<32> s3d_config; //!< Stores the bit mask of S3D modes
void Reset() { *this = HWDisplayAttributes(); }
@@ -498,6 +499,7 @@
(v_front_porch != display_attributes.v_front_porch) ||
(v_back_porch != display_attributes.v_back_porch) ||
(v_pulse_width != display_attributes.v_pulse_width) ||
+ (h_total != display_attributes.h_total) ||
(is_yuv != display_attributes.is_yuv));
}
diff --git a/sdm/include/utils/utils.h b/sdm/include/utils/utils.h
index ed2c6ae..b1c55c4 100644
--- a/sdm/include/utils/utils.h
+++ b/sdm/include/utils/utils.h
@@ -36,6 +36,13 @@
float lcm(float a, float b);
void CloseFd(int *fd);
+enum class DriverType {
+ FB = 0,
+ DRM,
+};
+
+DriverType GetDriverType();
+
} // namespace sdm
#endif // __UTILS_H__
diff --git a/sdm/libs/core/Android.mk b/sdm/libs/core/Android.mk
index 50f087d..cdf8925 100644
--- a/sdm/libs/core/Android.mk
+++ b/sdm/libs/core/Android.mk
@@ -5,9 +5,20 @@
LOCAL_MODULE := libsdmcore
LOCAL_MODULE_TAGS := optional
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) $(common_header_export_path)
-LOCAL_CFLAGS := -Wno-unused-parameter -DLOG_TAG=\"SDM\" $(common_flags)
-LOCAL_HW_INTF_PATH := fb
+LOCAL_CFLAGS := -Wno-unused-parameter -DLOG_TAG=\"SDM\" \
+ $(common_flags)
+ifeq ($(use_hwc2),false)
+ LOCAL_CFLAGS += -DUSE_SPECULATIVE_FENCES
+endif
+LOCAL_HW_INTF_PATH_1 := fb
LOCAL_SHARED_LIBRARIES := libdl libsdmutils
+
+ifneq ($(TARGET_IS_HEADLESS), true)
+ LOCAL_CFLAGS += -isystem external/libdrm
+ LOCAL_SHARED_LIBRARIES += libdrm libdrmutils
+ LOCAL_HW_INTF_PATH_2 := drm
+endif
+
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
LOCAL_SRC_FILES := core_interface.cpp \
core_impl.cpp \
@@ -20,14 +31,23 @@
resource_default.cpp \
dump_impl.cpp \
color_manager.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_info.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_device.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_primary.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_hdmi.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_virtual.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_color_manager.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_scale.cpp \
- $(LOCAL_HW_INTF_PATH)/hw_events.cpp
+ hw_events_interface.cpp \
+ hw_info_interface.cpp \
+ hw_interface.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_info.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_device.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_primary.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_hdmi.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_virtual.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_color_manager.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_scale.cpp \
+ $(LOCAL_HW_INTF_PATH_1)/hw_events.cpp
+
+ifneq ($(TARGET_IS_HEADLESS), true)
+ LOCAL_SRC_FILES += $(LOCAL_HW_INTF_PATH_2)/hw_info_drm.cpp \
+ $(LOCAL_HW_INTF_PATH_2)/hw_device_drm.cpp \
+ $(LOCAL_HW_INTF_PATH_2)/hw_events_drm.cpp
+endif
include $(BUILD_SHARED_LIBRARY)
diff --git a/sdm/libs/core/Makefile.am b/sdm/libs/core/Makefile.am
index 9041394..2b45d8e 100644
--- a/sdm/libs/core/Makefile.am
+++ b/sdm/libs/core/Makefile.am
@@ -11,6 +11,9 @@
resource_default.cpp \
dump_impl.cpp \
color_manager.cpp \
+ hw_interface.cpp \
+ hw_info_interface.cpp \
+ hw_events_interface.cpp \
fb/hw_info.cpp \
fb/hw_device.cpp \
fb/hw_primary.cpp \
@@ -41,4 +44,4 @@
libsdmcore_la_CFLAGS = $(COMMON_CFLAGS) -DLOG_TAG=\"SDM\"
libsdmcore_la_CPPFLAGS = $(AM_CPPFLAGS)
libsdmcore_la_LIBADD = ../utils/libsdmutils.la
-libsdmcore_la_LDFLAGS = -shared -avoid-version
\ No newline at end of file
+libsdmcore_la_LDFLAGS = -shared -avoid-version
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index 0592ba4..b070c41 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -245,13 +245,17 @@
// Set use_cursor constraint to Strategy
constraints->use_cursor = display_comp_ctx->valid_cursor;
- // Avoid idle fallback, if there is only one app layer.
// TODO(user): App layer count will change for hybrid composition
uint32_t app_layer_count = UINT32(hw_layers->info.stack->layers.size()) - 1;
- if ((app_layer_count > 1 && display_comp_ctx->idle_fallback) || display_comp_ctx->fallback_) {
+ if (display_comp_ctx->idle_fallback || display_comp_ctx->thermal_fallback_) {
// Handle the idle timeout by falling back
constraints->safe_mode = true;
}
+
+ // Avoid safe mode, if there is only one app layer.
+ if (app_layer_count == 1) {
+ constraints->safe_mode = false;
+ }
}
void CompManager::PrePrepare(Handle display_ctx, HWLayers *hw_layers) {
@@ -413,9 +417,9 @@
reinterpret_cast<DisplayCompositionContext *>(display_ctx);
if (thermal_level >= kMaxThermalLevel) {
- display_comp_ctx->fallback_ = true;
+ display_comp_ctx->thermal_fallback_ = true;
} else {
- display_comp_ctx->fallback_ = false;
+ display_comp_ctx->thermal_fallback_ = false;
}
}
@@ -485,8 +489,9 @@
return supported;
}
Layer *cursor_layer = layer_stack->layers.at(UINT32(gpu_index) - 1);
- if (cursor_layer->flags.cursor && resource_intf_->ValidateCursorConfig(display_resource_ctx,
- cursor_layer, true) == kErrorNone) {
+ if (cursor_layer->flags.cursor && !cursor_layer->flags.skip &&
+ resource_intf_->ValidateCursorConfig(display_resource_ctx,
+ cursor_layer, true) == kErrorNone) {
supported = true;
}
diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h
index f0044ec..3713971 100644
--- a/sdm/libs/core/comp_manager.h
+++ b/sdm/libs/core/comp_manager.h
@@ -92,7 +92,7 @@
uint32_t max_strategies = 0;
uint32_t remaining_strategies = 0;
bool idle_fallback = false;
- bool fallback_ = false;
+ bool thermal_fallback_ = false;
// Using primary panel flag of hw panel to configure Constraints. We do not need other hw
// panel parameters for now.
bool is_primary_panel = false;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 59a4dd8..64cebc1 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -716,8 +716,8 @@
}
DisplayError error = kErrorNone;
- // Set client requests when not in HDR Mode.
- if (!hdr_playback_mode_) {
+ // Set client requests when not in HDR Mode or lut generation is disabled
+ if (disable_hdr_lut_gen_ || !hdr_playback_mode_) {
error = SetColorModeInternal(color_mode);
if (error != kErrorNone) {
return error;
@@ -1106,6 +1106,7 @@
hw_layer.input_buffer.planes[0].stride = sdm_layer->input_buffer.planes[0].stride;
hw_layer.input_buffer.size = sdm_layer->input_buffer.size;
hw_layer.input_buffer.acquire_fence_fd = sdm_layer->input_buffer.acquire_fence_fd;
+ hw_layer.input_buffer.fb_id = sdm_layer->input_buffer.fb_id;
}
return;
@@ -1198,8 +1199,8 @@
DisplayError DisplayBase::HandleHDR(LayerStack *layer_stack) {
DisplayError error = kErrorNone;
- if (disable_hdr_lut_gen_) {
- // Do not apply HDR Mode when hdr lut generation is disabled
+ if (display_type_ != kPrimary) {
+ // Handling is needed for only primary displays
return kErrorNone;
}
@@ -1207,8 +1208,10 @@
// HDR playback off - set prev mode
if (hdr_playback_mode_) {
hdr_playback_mode_ = false;
- if (color_mgr_) {
+ if (color_mgr_ && !disable_hdr_lut_gen_) {
+ // Do not apply HDR Mode when hdr lut generation is disabled
DLOGI("Setting color mode = %s", current_color_mode_.c_str());
+ // HDR playback off - set prev mode
error = SetColorModeInternal(current_color_mode_);
}
comp_manager_->ControlDpps(true); // Enable Dpps
@@ -1218,7 +1221,7 @@
if (!hdr_playback_mode_ && !layer_stack->flags.animating) {
// hdr is starting
hdr_playback_mode_ = true;
- if (color_mgr_) {
+ if (color_mgr_ && !disable_hdr_lut_gen_) {
DLOGI("Setting HDR color mode = %s", hdr_color_mode_.c_str());
error = SetColorModeInternal(hdr_color_mode_);
}
diff --git a/sdm/libs/core/display_hdmi.cpp b/sdm/libs/core/display_hdmi.cpp
index 46d1a20..783cad9 100644
--- a/sdm/libs/core/display_hdmi.cpp
+++ b/sdm/libs/core/display_hdmi.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2017, 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:
@@ -86,7 +86,7 @@
s3d_format_to_mode_.insert(std::pair<LayerBufferS3DFormat, HWS3DMode>
(kS3dFormatFramePacking, kS3DModeFP));
- error = HWEventsInterface::Create(INT(display_type_), this, &event_list_, &hw_events_intf_);
+ error = HWEventsInterface::Create(INT(display_type_), this, event_list_, &hw_events_intf_);
if (error != kErrorNone) {
DisplayBase::Deinit();
HWInterface::Destroy(hw_intf_);
diff --git a/sdm/libs/core/display_hdmi.h b/sdm/libs/core/display_hdmi.h
index 868b141..6db2304 100644
--- a/sdm/libs/core/display_hdmi.h
+++ b/sdm/libs/core/display_hdmi.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2017, 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:
@@ -30,6 +30,7 @@
#include "display_base.h"
#include "dump_impl.h"
+#include "hw_events_interface.h"
namespace sdm {
@@ -61,11 +62,10 @@
bool underscan_supported_ = false;
HWScanSupport scan_support_;
std::map<LayerBufferS3DFormat, HWS3DMode> s3d_format_to_mode_;
- std::vector<const char *> event_list_ = {"vsync_event", "idle_notify", "cec/rd_msg",
- "thread_exit"};
+ std::vector<HWEvent> event_list_ = { HWEvent::VSYNC, HWEvent::IDLE_NOTIFY, HWEvent::EXIT,
+ HWEvent::CEC_READ_MESSAGE };
};
} // namespace sdm
#endif // __DISPLAY_HDMI_H__
-
diff --git a/sdm/libs/core/display_primary.cpp b/sdm/libs/core/display_primary.cpp
index 99aa3d5..3a1541e 100644
--- a/sdm/libs/core/display_primary.cpp
+++ b/sdm/libs/core/display_primary.cpp
@@ -71,7 +71,7 @@
avr_prop_disabled_ = Debug::IsAVRDisabled();
- error = HWEventsInterface::Create(INT(display_type_), this, &event_list_, &hw_events_intf_);
+ error = HWEventsInterface::Create(INT(display_type_), this, event_list_, &hw_events_intf_);
if (error != kErrorNone) {
DLOGE("Failed to create hardware events interface. Error = %d", error);
DisplayBase::Deinit();
diff --git a/sdm/libs/core/display_primary.h b/sdm/libs/core/display_primary.h
index 7471899..70c938e 100644
--- a/sdm/libs/core/display_primary.h
+++ b/sdm/libs/core/display_primary.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2017, 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:
@@ -29,6 +29,7 @@
#include "display_base.h"
#include "dump_impl.h"
+#include "hw_events_interface.h"
namespace sdm {
@@ -62,8 +63,8 @@
bool NeedsAVREnable();
uint32_t idle_timeout_ms_ = 0;
- std::vector<const char *> event_list_ = {"vsync_event", "show_blank_event", "idle_notify",
- "msm_fb_thermal_level", "thread_exit"};
+ std::vector<HWEvent> event_list_ = { HWEvent::VSYNC, HWEvent::EXIT, HWEvent::IDLE_NOTIFY,
+ HWEvent::SHOW_BLANK_EVENT, HWEvent::THERMAL_LEVEL };
bool avr_prop_disabled_ = false;
bool switch_to_cmd_ = false;
};
diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp
new file mode 100644
index 0000000..a72aae7
--- /dev/null
+++ b/sdm/libs/core/drm/hw_device_drm.cpp
@@ -0,0 +1,701 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#define __STDC_FORMAT_MACROS
+
+#include <ctype.h>
+#include <drm_lib_loader.h>
+#include <drm_master.h>
+#include <drm_res_mgr.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <linux/fb.h>
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <utils/constants.h>
+#include <utils/debug.h>
+#include <utils/sys.h>
+
+#include <algorithm>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "hw_device_drm.h"
+#include "hw_info_interface.h"
+
+#define __CLASS__ "HWDeviceDRM"
+
+using std::string;
+using std::to_string;
+using std::fstream;
+using drm_utils::DRMMaster;
+using drm_utils::DRMResMgr;
+using drm_utils::DRMLibLoader;
+using sde_drm::GetDRMManager;
+using sde_drm::DestroyDRMManager;
+using sde_drm::DRMDisplayType;
+using sde_drm::DRMDisplayToken;
+using sde_drm::DRMConnectorInfo;
+using sde_drm::DRMRect;
+using sde_drm::DRMBlendType;
+using sde_drm::DRMOps;
+using sde_drm::DRMTopology;
+
+namespace sdm {
+
+HWDeviceDRM::HWDeviceDRM(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf)
+ : hw_info_intf_(hw_info_intf), buffer_sync_handler_(buffer_sync_handler) {
+ device_type_ = kDevicePrimary;
+ device_name_ = "Peripheral Display";
+ hw_info_intf_ = hw_info_intf;
+}
+
+DisplayError HWDeviceDRM::Init() {
+ default_mode_ = (DRMLibLoader::GetInstance()->IsLoaded() == false);
+
+ if (!default_mode_) {
+ DRMMaster *drm_master = {};
+ int dev_fd = -1;
+ DRMMaster::GetInstance(&drm_master);
+ drm_master->GetHandle(&dev_fd);
+ DRMLibLoader::GetInstance()->FuncGetDRMManager()(dev_fd, &drm_mgr_intf_);
+ if (drm_mgr_intf_->RegisterDisplay(DRMDisplayType::PERIPHERAL, &token_)) {
+ DLOGE("RegisterDisplay failed");
+ return kErrorResources;
+ }
+
+ drm_mgr_intf_->CreateAtomicReq(token_, &drm_atomic_intf_);
+ drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_);
+ InitializeConfigs();
+ drm_atomic_intf_->Perform(DRMOps::CRTC_SET_MODE, token_.crtc_id, ¤t_mode_);
+#ifdef USE_SPECULATIVE_FENCES
+ drm_atomic_intf_->Perform(DRMOps::CRTC_SET_OUTPUT_FENCE_OFFSET, token_.crtc_id, 1);
+#endif
+ // TODO(user): Enable this and remove the one in SetupAtomic() onces underruns are fixed
+ // drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1);
+ // Commit to setup pipeline with mode, which then tells us the topology etc
+ if (drm_atomic_intf_->Commit(true /* synchronous */)) {
+ DLOGE("Setting up CRTC %d, Connector %d for %s failed", token_.crtc_id, token_.conn_id,
+ device_name_);
+ return kErrorResources;
+ }
+
+ // Reload connector info for updated info after 1st commit
+ drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_);
+ DLOGI("Setup CRTC %d, Connector %d for %s", token_.crtc_id, token_.conn_id, device_name_);
+ }
+
+ PopulateDisplayAttributes();
+ PopulateHWPanelInfo();
+ UpdateMixerAttributes();
+ hw_info_intf_->GetHWResourceInfo(&hw_resource_);
+
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::Deinit() {
+ drm_mgr_intf_->DestroyAtomicReq(drm_atomic_intf_);
+ drm_atomic_intf_ = {};
+ drm_mgr_intf_->UnregisterDisplay(token_);
+ return kErrorNone;
+}
+
+void HWDeviceDRM::InitializeConfigs() {
+ // TODO(user): Update modes
+ current_mode_ = connector_info_.modes[0];
+}
+
+DisplayError HWDeviceDRM::PopulateDisplayAttributes() {
+ drmModeModeInfo mode = {};
+ uint32_t mm_width = 0;
+ uint32_t mm_height = 0;
+ DRMTopology topology = DRMTopology::SINGLE_LM;
+
+ if (default_mode_) {
+ DRMResMgr *res_mgr = nullptr;
+ int ret = DRMResMgr::GetInstance(&res_mgr);
+ if (ret < 0) {
+ DLOGE("Failed to acquire DRMResMgr instance");
+ return kErrorResources;
+ }
+
+ res_mgr->GetMode(&mode);
+ res_mgr->GetDisplayDimInMM(&mm_width, &mm_height);
+ } else {
+ mode = current_mode_;
+ mm_width = connector_info_.mmWidth;
+ mm_height = connector_info_.mmHeight;
+ topology = connector_info_.topology;
+ }
+
+ display_attributes_.x_pixels = mode.hdisplay;
+ display_attributes_.y_pixels = mode.vdisplay;
+ display_attributes_.fps = mode.vrefresh;
+ display_attributes_.vsync_period_ns = UINT32(1000000000L / display_attributes_.fps);
+
+ /*
+ Active Front Sync Back
+ Region Porch Porch
+ <-----------------------><----------------><-------------><-------------->
+ <----- [hv]display ----->
+ <------------- [hv]sync_start ------------>
+ <--------------------- [hv]sync_end --------------------->
+ <-------------------------------- [hv]total ----------------------------->
+ */
+
+ display_attributes_.v_front_porch = mode.vsync_start - mode.vdisplay;
+ display_attributes_.v_pulse_width = mode.vsync_end - mode.vsync_start;
+ display_attributes_.v_back_porch = mode.vtotal - mode.vsync_end;
+ display_attributes_.v_total = mode.vtotal;
+
+ display_attributes_.h_total = mode.htotal;
+ uint32_t h_blanking = mode.htotal - mode.hdisplay;
+ display_attributes_.is_device_split =
+ (topology == DRMTopology::DUAL_LM || topology == DRMTopology::DUAL_LM_MERGE);
+ display_attributes_.h_total += display_attributes_.is_device_split ? h_blanking : 0;
+
+ display_attributes_.x_dpi = (FLOAT(mode.hdisplay) * 25.4f) / FLOAT(mm_width);
+ display_attributes_.y_dpi = (FLOAT(mode.vdisplay) * 25.4f) / FLOAT(mm_height);
+
+ return kErrorNone;
+}
+
+void HWDeviceDRM::PopulateHWPanelInfo() {
+ hw_panel_info_ = {};
+
+ snprintf(hw_panel_info_.panel_name, sizeof(hw_panel_info_.panel_name), "%s",
+ connector_info_.panel_name.c_str());
+ hw_panel_info_.split_info.left_split = display_attributes_.x_pixels;
+ if (display_attributes_.is_device_split) {
+ hw_panel_info_.split_info.left_split = hw_panel_info_.split_info.right_split =
+ display_attributes_.x_pixels / 2;
+ }
+
+ hw_panel_info_.partial_update = 0;
+ hw_panel_info_.left_align = 0;
+ hw_panel_info_.width_align = 0;
+ hw_panel_info_.top_align = 0;
+ hw_panel_info_.height_align = 0;
+ hw_panel_info_.min_roi_width = 0;
+ hw_panel_info_.min_roi_height = 0;
+ hw_panel_info_.needs_roi_merge = 0;
+ hw_panel_info_.dynamic_fps = connector_info_.dynamic_fps;
+ hw_panel_info_.min_fps = 60;
+ hw_panel_info_.max_fps = 60;
+ hw_panel_info_.is_primary_panel = connector_info_.is_primary;
+ hw_panel_info_.is_pluggable = 0;
+
+ if (!default_mode_) {
+ hw_panel_info_.needs_roi_merge = (connector_info_.topology == DRMTopology::DUAL_LM_MERGE);
+ }
+
+ GetHWDisplayPortAndMode();
+ GetHWPanelMaxBrightness();
+
+ DLOGI("%s, Panel Interface = %s, Panel Mode = %s, Is Primary = %d", device_name_,
+ interface_str_.c_str(), hw_panel_info_.mode == kModeVideo ? "Video" : "Command",
+ hw_panel_info_.is_primary_panel);
+ DLOGI("Partial Update = %d, Dynamic FPS = %d", hw_panel_info_.partial_update,
+ hw_panel_info_.dynamic_fps);
+ DLOGI("Align: left = %d, width = %d, top = %d, height = %d", hw_panel_info_.left_align,
+ hw_panel_info_.width_align, hw_panel_info_.top_align, hw_panel_info_.height_align);
+ DLOGI("ROI: min_width = %d, min_height = %d, need_merge = %d", hw_panel_info_.min_roi_width,
+ hw_panel_info_.min_roi_height, hw_panel_info_.needs_roi_merge);
+ DLOGI("FPS: min = %d, max =%d", hw_panel_info_.min_fps, hw_panel_info_.max_fps);
+ DLOGI("Left Split = %d, Right Split = %d", hw_panel_info_.split_info.left_split,
+ hw_panel_info_.split_info.right_split);
+}
+
+void HWDeviceDRM::GetHWDisplayPortAndMode() {
+ hw_panel_info_.port = kPortDefault;
+ hw_panel_info_.mode =
+ (connector_info_.panel_mode == sde_drm::DRMPanelMode::VIDEO) ? kModeVideo : kModeCommand;
+
+ if (default_mode_) {
+ return;
+ }
+
+ switch (connector_info_.type) {
+ case DRM_MODE_CONNECTOR_DSI:
+ hw_panel_info_.port = kPortDSI;
+ interface_str_ = "DSI";
+ break;
+ case DRM_MODE_CONNECTOR_LVDS:
+ hw_panel_info_.port = kPortLVDS;
+ interface_str_ = "LVDS";
+ break;
+ case DRM_MODE_CONNECTOR_eDP:
+ hw_panel_info_.port = kPortEDP;
+ interface_str_ = "EDP";
+ break;
+ case DRM_MODE_CONNECTOR_TV:
+ case DRM_MODE_CONNECTOR_HDMIA:
+ case DRM_MODE_CONNECTOR_HDMIB:
+ hw_panel_info_.port = kPortDTV;
+ interface_str_ = "HDMI";
+ break;
+ case DRM_MODE_CONNECTOR_VIRTUAL:
+ hw_panel_info_.port = kPortWriteBack;
+ interface_str_ = "Virtual";
+ break;
+ case DRM_MODE_CONNECTOR_DisplayPort:
+ // TODO(user): Add when available
+ interface_str_ = "DisplayPort";
+ break;
+ }
+
+ return;
+}
+
+void HWDeviceDRM::GetHWPanelMaxBrightness() {
+ char brightness[kMaxStringLength] = {0};
+ char kMaxBrightnessNode[64] = {0};
+
+ snprintf(kMaxBrightnessNode, sizeof(kMaxBrightnessNode), "%s",
+ "/sys/class/leds/lcd-backlight/max_brightness");
+
+ hw_panel_info_.panel_max_brightness = 255;
+ int fd = Sys::open_(kMaxBrightnessNode, O_RDONLY);
+ if (fd < 0) {
+ DLOGW("Failed to open max brightness node = %s, error = %s", kMaxBrightnessNode,
+ strerror(errno));
+ return;
+ }
+
+ if (Sys::pread_(fd, brightness, sizeof(brightness), 0) > 0) {
+ hw_panel_info_.panel_max_brightness = atoi(brightness);
+ DLOGI("Max brightness level = %d", hw_panel_info_.panel_max_brightness);
+ } else {
+ DLOGW("Failed to read max brightness level. error = %s", strerror(errno));
+ }
+
+ Sys::close_(fd);
+}
+
+DisplayError HWDeviceDRM::GetActiveConfig(uint32_t *active_config) {
+ *active_config = 0;
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::GetNumDisplayAttributes(uint32_t *count) {
+ *count = 1;
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::GetDisplayAttributes(uint32_t index,
+ HWDisplayAttributes *display_attributes) {
+ *display_attributes = display_attributes_;
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::GetHWPanelInfo(HWPanelInfo *panel_info) {
+ *panel_info = hw_panel_info_;
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::SetDisplayAttributes(uint32_t index) {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::SetDisplayAttributes(const HWDisplayAttributes &display_attributes) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::GetConfigIndex(uint32_t mode, uint32_t *index) {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::PowerOn() {
+ DTRACE_SCOPED();
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::PowerOff() {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::Doze() {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::DozeSuspend() {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::Standby() {
+ return kErrorNone;
+}
+
+void HWDeviceDRM::SetupAtomic(HWLayers *hw_layers, bool validate) {
+ if (default_mode_) {
+ return;
+ }
+
+ HWLayersInfo &hw_layer_info = hw_layers->info;
+ uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size());
+
+ for (uint32_t i = 0; i < hw_layer_count; i++) {
+ Layer &layer = hw_layer_info.hw_layers.at(i);
+ LayerBuffer &input_buffer = layer.input_buffer;
+ HWPipeInfo *left_pipe = &hw_layers->config[i].left_pipe;
+ HWPipeInfo *right_pipe = &hw_layers->config[i].right_pipe;
+
+ // TODO(user): Add support for solid fill
+ if (layer.flags.solid_fill) {
+ continue;
+ }
+
+ for (uint32_t count = 0; count < 2; count++) {
+ HWPipeInfo *pipe_info = (count == 0) ? left_pipe : right_pipe;
+ if (pipe_info->valid) {
+ uint32_t pipe_id = pipe_info->pipe_id;
+ if (input_buffer.fb_id == 0) {
+ // We set these to 0 to clear any previous cycle's state from another buffer.
+ // Unfortunately this layer will be skipped from validation because it's dimensions are
+ // tied to fb_id which is not available yet.
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_ID, pipe_id, 0);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CRTC, pipe_id, 0);
+ continue;
+ }
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ALPHA, pipe_id, layer.plane_alpha);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ZORDER, pipe_id, pipe_info->z_order);
+ DRMBlendType blending = {};
+ SetBlending(layer.blending, &blending);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_BLEND_TYPE, pipe_id, blending);
+ DRMRect src = {};
+ SetRect(pipe_info->src_roi, &src);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_RECT, pipe_id, src);
+ DRMRect dst = {};
+ SetRect(pipe_info->dst_roi, &dst);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_DST_RECT, pipe_id, dst);
+ uint32_t rot_bit_mask = 0;
+ if (layer.transform.flip_horizontal) {
+ rot_bit_mask |= 1 << DRM_REFLECT_X;
+ }
+ if (layer.transform.flip_vertical) {
+ rot_bit_mask |= 1 << DRM_REFLECT_Y;
+ }
+
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_H_DECIMATION, pipe_id,
+ pipe_info->horizontal_decimation);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_V_DECIMATION, pipe_id,
+ pipe_info->vertical_decimation);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION, pipe_id, rot_bit_mask);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_ID, pipe_id, input_buffer.fb_id);
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CRTC, pipe_id, token_.crtc_id);
+ if (!validate && input_buffer.acquire_fence_fd >= 0) {
+ drm_atomic_intf_->Perform(DRMOps::PLANE_SET_INPUT_FENCE, pipe_id,
+ input_buffer.acquire_fence_fd);
+ }
+ }
+ }
+
+ // TODO(user): Remove this and enable the one in Init() onces underruns are fixed
+ drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1);
+ }
+}
+
+DisplayError HWDeviceDRM::Validate(HWLayers *hw_layers) {
+ DTRACE_SCOPED();
+ SetupAtomic(hw_layers, true /* validate */);
+
+ int ret = drm_atomic_intf_->Validate();
+ if (ret) {
+ DLOGE("%s failed with error %d", __FUNCTION__, ret);
+ return kErrorHardware;
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::Commit(HWLayers *hw_layers) {
+ DTRACE_SCOPED();
+ if (default_mode_) {
+ return DefaultCommit(hw_layers);
+ }
+
+ return AtomicCommit(hw_layers);
+}
+
+DisplayError HWDeviceDRM::DefaultCommit(HWLayers *hw_layers) {
+ DTRACE_SCOPED();
+
+ HWLayersInfo &hw_layer_info = hw_layers->info;
+ LayerStack *stack = hw_layer_info.stack;
+
+ stack->retire_fence_fd = -1;
+ for (Layer &layer : hw_layer_info.hw_layers) {
+ layer.input_buffer.release_fence_fd = -1;
+ }
+
+ DRMMaster *master = nullptr;
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ DLOGE("Failed to acquire DRMMaster instance");
+ return kErrorResources;
+ }
+
+ DRMResMgr *res_mgr = nullptr;
+ ret = DRMResMgr::GetInstance(&res_mgr);
+ if (ret < 0) {
+ DLOGE("Failed to acquire DRMResMgr instance");
+ return kErrorResources;
+ }
+
+ int dev_fd = -1;
+ master->GetHandle(&dev_fd);
+
+ uint32_t connector_id = 0;
+ res_mgr->GetConnectorId(&connector_id);
+
+ uint32_t crtc_id = 0;
+ res_mgr->GetCrtcId(&crtc_id);
+
+ drmModeModeInfo mode;
+ res_mgr->GetMode(&mode);
+
+ LayerBuffer &input_buffer = hw_layer_info.hw_layers.at(0).input_buffer;
+ ret = drmModeSetCrtc(dev_fd, crtc_id, input_buffer.fb_id, 0 /* x */, 0 /* y */, &connector_id,
+ 1 /* num_connectors */, &mode);
+ if (ret < 0) {
+ DLOGE("drmModeSetCrtc failed dev fd %d, fb_id %d, crtc id %d, connector id %d, %s", dev_fd,
+ input_buffer.fb_id, crtc_id, connector_id, strerror(errno));
+ return kErrorHardware;
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::AtomicCommit(HWLayers *hw_layers) {
+ DTRACE_SCOPED();
+ SetupAtomic(hw_layers, false /* validate */);
+
+ int ret = drm_atomic_intf_->Commit(false /* synchronous */);
+ if (ret) {
+ DLOGE("%s failed with error %d", __FUNCTION__, ret);
+ return kErrorHardware;
+ }
+
+ int release_fence = -1;
+ int retire_fence = -1;
+
+ drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, &release_fence);
+ drm_atomic_intf_->Perform(DRMOps::CONNECTOR_GET_RETIRE_FENCE, token_.conn_id, &retire_fence);
+
+ HWLayersInfo &hw_layer_info = hw_layers->info;
+ LayerStack *stack = hw_layer_info.stack;
+ stack->retire_fence_fd = retire_fence;
+
+ for (Layer &layer : hw_layer_info.hw_layers) {
+ layer.input_buffer.release_fence_fd = Sys::dup_(release_fence);
+ }
+
+ hw_layer_info.sync_handle = release_fence;
+
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::Flush() {
+ return kErrorNone;
+}
+
+void HWDeviceDRM::SetBlending(const LayerBlending &source, DRMBlendType *target) {
+ switch (source) {
+ case kBlendingPremultiplied:
+ *target = DRMBlendType::PREMULTIPLIED;
+ break;
+ case kBlendingOpaque:
+ *target = DRMBlendType::OPAQUE;
+ break;
+ case kBlendingCoverage:
+ *target = DRMBlendType::COVERAGE;
+ break;
+ default:
+ *target = DRMBlendType::UNDEFINED;
+ }
+}
+
+void HWDeviceDRM::SetRect(const LayerRect &source, DRMRect *target) {
+ target->left = UINT32(source.left);
+ target->top = UINT32(source.top);
+ target->right = UINT32(source.right);
+ target->bottom = UINT32(source.bottom);
+}
+
+bool HWDeviceDRM::EnableHotPlugDetection(int enable) {
+ return true;
+}
+
+void HWDeviceDRM::ResetDisplayParams() {}
+
+DisplayError HWDeviceDRM::SetCursorPosition(HWLayers *hw_layers, int x, int y) {
+ DTRACE_SCOPED();
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::GetPPFeaturesVersion(PPFeatureVersion *vers) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetPPFeatures(PPFeaturesConfig *feature_list) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetVSyncState(bool enable) {
+ return kErrorNone;
+}
+
+void HWDeviceDRM::SetIdleTimeoutMs(uint32_t timeout_ms) {}
+
+DisplayError HWDeviceDRM::SetDisplayMode(const HWDisplayMode hw_display_mode) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetRefreshRate(uint32_t refresh_rate) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetPanelBrightness(int level) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::GetHWScanInfo(HWScanInfo *scan_info) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::GetVideoFormat(uint32_t config_index, uint32_t *video_format) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::GetMaxCEAFormat(uint32_t *max_cea_format) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::GetPanelBrightness(int *level) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetS3DMode(HWS3DMode s3d_mode) {
+ return kErrorNotSupported;
+}
+
+DisplayError HWDeviceDRM::SetScaleLutConfig(HWScaleLutInfo *lut_info) {
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::SetMixerAttributes(const HWMixerAttributes &mixer_attributes) {
+ if (!hw_resource_.hw_dest_scalar_info.count) {
+ return kErrorNotSupported;
+ }
+
+ if (mixer_attributes.width > display_attributes_.x_pixels ||
+ mixer_attributes.height > display_attributes_.y_pixels) {
+ DLOGW("Input resolution exceeds display resolution! input: res %dx%d display: res %dx%d",
+ mixer_attributes.width, mixer_attributes.height, display_attributes_.x_pixels,
+ display_attributes_.y_pixels);
+ return kErrorNotSupported;
+ }
+
+ uint32_t max_input_width = hw_resource_.hw_dest_scalar_info.max_input_width;
+ if (display_attributes_.is_device_split) {
+ max_input_width *= 2;
+ }
+
+ if (mixer_attributes.width > max_input_width) {
+ DLOGW("Input width exceeds width limit! input_width %d width_limit %d", mixer_attributes.width,
+ max_input_width);
+ return kErrorNotSupported;
+ }
+
+ float mixer_aspect_ratio = FLOAT(mixer_attributes.width) / FLOAT(mixer_attributes.height);
+ float display_aspect_ratio =
+ FLOAT(display_attributes_.x_pixels) / FLOAT(display_attributes_.y_pixels);
+
+ if (display_aspect_ratio != mixer_aspect_ratio) {
+ DLOGW("Aspect ratio mismatch! input: res %dx%d display: res %dx%d", mixer_attributes.width,
+ mixer_attributes.height, display_attributes_.x_pixels, display_attributes_.y_pixels);
+ return kErrorNotSupported;
+ }
+
+ float scale_x = FLOAT(display_attributes_.x_pixels) / FLOAT(mixer_attributes.width);
+ float scale_y = FLOAT(display_attributes_.y_pixels) / FLOAT(mixer_attributes.height);
+ float max_scale_up = hw_resource_.hw_dest_scalar_info.max_scale_up;
+ if (scale_x > max_scale_up || scale_y > max_scale_up) {
+ DLOGW(
+ "Up scaling ratio exceeds for destination scalar upscale limit scale_x %f scale_y %f "
+ "max_scale_up %f",
+ scale_x, scale_y, max_scale_up);
+ return kErrorNotSupported;
+ }
+
+ float mixer_split_ratio = FLOAT(mixer_attributes_.split_left) / FLOAT(mixer_attributes_.width);
+
+ mixer_attributes_ = mixer_attributes;
+ mixer_attributes_.split_left = mixer_attributes_.width;
+ if (display_attributes_.is_device_split) {
+ mixer_attributes_.split_left = UINT32(FLOAT(mixer_attributes.width) * mixer_split_ratio);
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWDeviceDRM::GetMixerAttributes(HWMixerAttributes *mixer_attributes) {
+ if (!mixer_attributes) {
+ return kErrorParameters;
+ }
+
+ mixer_attributes_.width = display_attributes_.x_pixels;
+ mixer_attributes_.height = display_attributes_.y_pixels;
+ mixer_attributes_.split_left = display_attributes_.is_device_split
+ ? hw_panel_info_.split_info.left_split
+ : mixer_attributes_.width;
+ *mixer_attributes = mixer_attributes_;
+
+ return kErrorNone;
+}
+
+void HWDeviceDRM::UpdateMixerAttributes() {
+ mixer_attributes_.width = display_attributes_.x_pixels;
+ mixer_attributes_.height = display_attributes_.y_pixels;
+ mixer_attributes_.split_left = display_attributes_.is_device_split
+ ? hw_panel_info_.split_info.left_split
+ : mixer_attributes_.width;
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/drm/hw_device_drm.h b/sdm/libs/core/drm/hw_device_drm.h
new file mode 100644
index 0000000..db135a0
--- /dev/null
+++ b/sdm/libs/core/drm/hw_device_drm.h
@@ -0,0 +1,137 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __HW_DEVICE_DRM_H__
+#define __HW_DEVICE_DRM_H__
+
+#include <drm_interface.h>
+#include <errno.h>
+#include <pthread.h>
+#include <xf86drmMode.h>
+#include <string>
+#include <vector>
+
+#include "hw_interface.h"
+
+#define IOCTL_LOGE(ioctl, type) \
+ DLOGE("ioctl %s, device = %d errno = %d, desc = %s", #ioctl, type, errno, strerror(errno))
+
+namespace sdm {
+class HWInfoInterface;
+
+class HWDeviceDRM : public HWInterface {
+ public:
+ explicit HWDeviceDRM(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf);
+ virtual ~HWDeviceDRM() {}
+ virtual DisplayError Init();
+ virtual DisplayError Deinit();
+
+ protected:
+ // From HWInterface
+ virtual DisplayError GetActiveConfig(uint32_t *active_config);
+ virtual DisplayError GetNumDisplayAttributes(uint32_t *count);
+ virtual DisplayError GetDisplayAttributes(uint32_t index,
+ HWDisplayAttributes *display_attributes);
+ virtual DisplayError GetHWPanelInfo(HWPanelInfo *panel_info);
+ virtual DisplayError SetDisplayAttributes(uint32_t index);
+ virtual DisplayError SetDisplayAttributes(const HWDisplayAttributes &display_attributes);
+ virtual DisplayError GetConfigIndex(uint32_t mode, uint32_t *index);
+ virtual DisplayError PowerOn();
+ virtual DisplayError PowerOff();
+ virtual DisplayError Doze();
+ virtual DisplayError DozeSuspend();
+ virtual DisplayError Standby();
+ virtual DisplayError Validate(HWLayers *hw_layers);
+ virtual DisplayError Commit(HWLayers *hw_layers);
+ virtual DisplayError Flush();
+ virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers);
+ virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list);
+ virtual DisplayError SetVSyncState(bool enable);
+ virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
+ virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode);
+ virtual DisplayError SetRefreshRate(uint32_t refresh_rate);
+ virtual DisplayError SetPanelBrightness(int level);
+ virtual DisplayError GetHWScanInfo(HWScanInfo *scan_info);
+ virtual DisplayError GetVideoFormat(uint32_t config_index, uint32_t *video_format);
+ virtual DisplayError GetMaxCEAFormat(uint32_t *max_cea_format);
+ virtual DisplayError SetCursorPosition(HWLayers *hw_layers, int x, int y);
+ virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
+ virtual DisplayError GetPanelBrightness(int *level);
+ virtual DisplayError SetAutoRefresh(bool enable) { return kErrorNone; }
+ virtual DisplayError SetS3DMode(HWS3DMode s3d_mode);
+ virtual DisplayError SetScaleLutConfig(HWScaleLutInfo *lut_info);
+ virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes);
+ virtual DisplayError GetMixerAttributes(HWMixerAttributes *mixer_attributes);
+
+ enum {
+ kHWEventVSync,
+ kHWEventBlank,
+ };
+
+ static const int kMaxStringLength = 1024;
+ static const int kNumPhysicalDisplays = 2;
+
+ DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target);
+ DisplayError SetStride(HWDeviceType device_type, LayerBufferFormat format, uint32_t width,
+ uint32_t *target);
+ DisplayError PopulateDisplayAttributes();
+ void PopulateHWPanelInfo();
+ void GetHWDisplayPortAndMode();
+ void GetHWPanelMaxBrightness();
+ void ResetDisplayParams();
+ bool EnableHotPlugDetection(int enable);
+ void UpdateMixerAttributes();
+ void InitializeConfigs();
+ void SetBlending(const LayerBlending &source, sde_drm::DRMBlendType *target);
+ void SetRect(const LayerRect &source, sde_drm::DRMRect *target);
+ DisplayError DefaultCommit(HWLayers *hw_layers);
+ DisplayError AtomicCommit(HWLayers *hw_layers);
+ void SetupAtomic(HWLayers *hw_layers, bool validate);
+
+ HWResourceInfo hw_resource_ = {};
+ HWPanelInfo hw_panel_info_ = {};
+ HWInfoInterface *hw_info_intf_ = {};
+ BufferSyncHandler *buffer_sync_handler_ = {};
+ HWDeviceType device_type_ = {};
+ const char *device_name_ = {};
+ bool synchronous_commit_ = false;
+ HWDisplayAttributes display_attributes_ = {};
+ HWMixerAttributes mixer_attributes_ = {};
+ sde_drm::DRMManagerInterface *drm_mgr_intf_ = {};
+ sde_drm::DRMAtomicReqInterface *drm_atomic_intf_ = {};
+ sde_drm::DRMDisplayToken token_ = {};
+ drmModeModeInfo current_mode_ = {};
+ bool default_mode_ = false;
+ sde_drm::DRMConnectorInfo connector_info_ = {};
+ std::string interface_str_ = "DSI";
+};
+
+} // namespace sdm
+
+#endif // __HW_DEVICE_DRM_H__
diff --git a/sdm/libs/core/drm/hw_events_drm.cpp b/sdm/libs/core/drm/hw_events_drm.cpp
new file mode 100644
index 0000000..81384e4
--- /dev/null
+++ b/sdm/libs/core/drm/hw_events_drm.cpp
@@ -0,0 +1,298 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <drm_master.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <math.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/prctl.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <utils/debug.h>
+#include <utils/sys.h>
+#include <xf86drm.h>
+
+#include <algorithm>
+#include <map>
+#include <utility>
+#include <vector>
+
+#include "hw_events_drm.h"
+
+#define __CLASS__ "HWEventsDRM"
+
+namespace sdm {
+
+using drm_utils::DRMMaster;
+
+DisplayError HWEventsDRM::InitializePollFd() {
+ for (uint32_t i = 0; i < event_data_list_.size(); i++) {
+ char data[kMaxStringLength]{};
+ HWEventData &event_data = event_data_list_[i];
+ poll_fds_[i].fd = -1;
+
+ switch (event_data.event_type) {
+ case HWEvent::VSYNC: {
+ poll_fds_[i].events = POLLIN | POLLPRI | POLLERR;
+ DRMMaster *master = nullptr;
+ int ret = DRMMaster::GetInstance(&master);
+ if (ret < 0) {
+ DLOGE("Failed to acquire DRMMaster instance");
+ return kErrorNotSupported;
+ }
+ master->GetHandle(&poll_fds_[i].fd);
+ vsync_index_ = i;
+ } break;
+ case HWEvent::EXIT: {
+ // Create an eventfd to be used to unblock the poll system call when
+ // a thread is exiting.
+ poll_fds_[i].fd = Sys::eventfd_(0, 0);
+ poll_fds_[i].events |= POLLIN;
+ // Clear any existing data
+ Sys::pread_(poll_fds_[i].fd, data, kMaxStringLength, 0);
+ } break;
+ case HWEvent::IDLE_NOTIFY:
+ case HWEvent::CEC_READ_MESSAGE:
+ case HWEvent::SHOW_BLANK_EVENT:
+ case HWEvent::THERMAL_LEVEL:
+ break;
+ }
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWEventsDRM::SetEventParser() {
+ DisplayError error = kErrorNone;
+
+ for (auto &event_data : event_data_list_) {
+ switch (event_data.event_type) {
+ case HWEvent::VSYNC:
+ event_data.event_parser = &HWEventsDRM::HandleVSync;
+ break;
+ case HWEvent::IDLE_NOTIFY:
+ event_data.event_parser = &HWEventsDRM::HandleIdleTimeout;
+ break;
+ case HWEvent::CEC_READ_MESSAGE:
+ event_data.event_parser = &HWEventsDRM::HandleCECMessage;
+ break;
+ case HWEvent::EXIT:
+ event_data.event_parser = &HWEventsDRM::HandleThreadExit;
+ break;
+ case HWEvent::SHOW_BLANK_EVENT:
+ event_data.event_parser = &HWEventsDRM::HandleBlank;
+ break;
+ case HWEvent::THERMAL_LEVEL:
+ event_data.event_parser = &HWEventsDRM::HandleThermal;
+ break;
+ default:
+ error = kErrorParameters;
+ break;
+ }
+ }
+
+ return error;
+}
+
+void HWEventsDRM::PopulateHWEventData(const vector<HWEvent> &event_list) {
+ for (auto &event : event_list) {
+ HWEventData event_data;
+ event_data.event_type = event;
+ event_data_list_.push_back(std::move(event_data));
+ }
+
+ SetEventParser();
+ InitializePollFd();
+}
+
+DisplayError HWEventsDRM::Init(int display_type, HWEventHandler *event_handler,
+ const vector<HWEvent> &event_list) {
+ if (!event_handler)
+ return kErrorParameters;
+
+ event_handler_ = event_handler;
+ poll_fds_.resize(event_list.size());
+ event_thread_name_ += " - " + std::to_string(display_type);
+
+ PopulateHWEventData(event_list);
+
+ if (pthread_create(&event_thread_, NULL, &DisplayEventThread, this) < 0) {
+ DLOGE("Failed to start %s, error = %s", event_thread_name_.c_str());
+ return kErrorResources;
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWEventsDRM::Deinit() {
+ exit_threads_ = true;
+ Sys::pthread_cancel_(event_thread_);
+
+ for (uint32_t i = 0; i < event_data_list_.size(); i++) {
+ if (event_data_list_[i].event_type == HWEvent::EXIT) {
+ uint64_t exit_value = 1;
+ ssize_t write_size = Sys::write_(poll_fds_[i].fd, &exit_value, sizeof(uint64_t));
+ if (write_size != sizeof(uint64_t)) {
+ DLOGW("Error triggering exit fd (%d). write size = %d, error = %s", poll_fds_[i].fd,
+ write_size, strerror(errno));
+ }
+ }
+ }
+
+ pthread_join(event_thread_, NULL);
+ CloseFds();
+
+ return kErrorNone;
+}
+
+DisplayError HWEventsDRM::CloseFds() {
+ for (uint32_t i = 0; i < event_data_list_.size(); i++) {
+ switch (event_data_list_[i].event_type) {
+ case HWEvent::VSYNC:
+ poll_fds_[i].fd = -1;
+ break;
+ case HWEvent::EXIT:
+ Sys::close_(poll_fds_[i].fd);
+ poll_fds_[i].fd = -1;
+ break;
+ case HWEvent::IDLE_NOTIFY:
+ case HWEvent::CEC_READ_MESSAGE:
+ case HWEvent::SHOW_BLANK_EVENT:
+ case HWEvent::THERMAL_LEVEL:
+ break;
+ default:
+ return kErrorNotSupported;
+ }
+ }
+
+ return kErrorNone;
+}
+
+void *HWEventsDRM::DisplayEventThread(void *context) {
+ if (context) {
+ return reinterpret_cast<HWEventsDRM *>(context)->DisplayEventHandler();
+ }
+
+ return NULL;
+}
+
+void *HWEventsDRM::DisplayEventHandler() {
+ char data[kMaxStringLength]{};
+
+ prctl(PR_SET_NAME, event_thread_name_.c_str(), 0, 0, 0);
+ setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent);
+
+ while (!exit_threads_) {
+ if (RegisterVSync() != kErrorNone) {
+ pthread_exit(0);
+ return nullptr;
+ }
+
+ int error = Sys::poll_(poll_fds_.data(), UINT32(poll_fds_.size()), -1);
+ if (error <= 0) {
+ DLOGW("poll failed. error = %s", strerror(errno));
+ continue;
+ }
+
+ for (uint32_t i = 0; i < event_data_list_.size(); i++) {
+ pollfd &poll_fd = poll_fds_[i];
+ switch (event_data_list_[i].event_type) {
+ case HWEvent::VSYNC:
+ (this->*(event_data_list_[i]).event_parser)(nullptr);
+ break;
+ case HWEvent::EXIT:
+ if ((poll_fd.revents & POLLIN) &&
+ (Sys::read_(poll_fd.fd, data, kMaxStringLength) > 0)) {
+ (this->*(event_data_list_[i]).event_parser)(data);
+ }
+ break;
+ case HWEvent::IDLE_NOTIFY:
+ case HWEvent::CEC_READ_MESSAGE:
+ case HWEvent::SHOW_BLANK_EVENT:
+ case HWEvent::THERMAL_LEVEL:
+ if (poll_fd.fd >= 0 && (poll_fd.revents & POLLPRI) &&
+ (Sys::pread_(poll_fd.fd, data, kMaxStringLength, 0) > 0)) {
+ (this->*(event_data_list_[i]).event_parser)(data);
+ }
+ break;
+ }
+ }
+ }
+
+ pthread_exit(0);
+
+ return nullptr;
+}
+
+DisplayError HWEventsDRM::RegisterVSync() {
+ drmVBlank vblank{};
+ vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT);
+ vblank.request.sequence = 1;
+ // DRM hack to pass in context to unused field signal. Driver will write this to the node being
+ // polled on, and will be read as part of drm event handling and sent to handler
+ vblank.request.signal = reinterpret_cast<unsigned long>(this); // NOLINT
+ int error = drmWaitVBlank(poll_fds_[vsync_index_].fd, &vblank);
+ if (error < 0) {
+ DLOGE("drmWaitVBlank failed with err %d", errno);
+ return kErrorResources;
+ }
+
+ return kErrorNone;
+}
+
+void HWEventsDRM::HandleVSync(char *data) {
+ if (poll_fds_[vsync_index_].revents & (POLLIN | POLLPRI)) {
+ drmEventContext event = {};
+ event.version = DRM_EVENT_CONTEXT_VERSION;
+ event.vblank_handler = &HWEventsDRM::VSyncHandlerCallback;
+ int error = drmHandleEvent(poll_fds_[vsync_index_].fd, &event);
+ if (error != 0) {
+ DLOGE("drmHandleEvent failed: %i", error);
+ }
+ }
+}
+
+void HWEventsDRM::VSyncHandlerCallback(int fd, unsigned int sequence, unsigned int tv_sec,
+ unsigned int tv_usec, void *data) {
+ int64_t timestamp = (int64_t)(tv_sec)*1000000000 + (int64_t)(tv_usec)*1000;
+ reinterpret_cast<HWEventsDRM *>(data)->event_handler_->VSync(timestamp);
+}
+
+void HWEventsDRM::HandleIdleTimeout(char *data) {
+ event_handler_->IdleTimeout();
+}
+
+void HWEventsDRM::HandleCECMessage(char *data) {
+ event_handler_->CECMessage(data);
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/drm/hw_events_drm.h b/sdm/libs/core/drm/hw_events_drm.h
new file mode 100644
index 0000000..9f8dc38
--- /dev/null
+++ b/sdm/libs/core/drm/hw_events_drm.h
@@ -0,0 +1,90 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __HW_EVENTS_DRM_H__
+#define __HW_EVENTS_DRM_H__
+
+#include <sys/poll.h>
+#include <map>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "hw_events_interface.h"
+#include "hw_interface.h"
+
+namespace sdm {
+
+using std::vector;
+
+class HWEventsDRM : public HWEventsInterface {
+ public:
+ virtual DisplayError Init(int display_type, HWEventHandler *event_handler,
+ const vector<HWEvent> &event_list);
+ virtual DisplayError Deinit();
+
+ private:
+ static const int kMaxStringLength = 1024;
+
+ typedef void (HWEventsDRM::*EventParser)(char *);
+
+ struct HWEventData {
+ HWEvent event_type {};
+ EventParser event_parser {};
+ };
+
+ static void *DisplayEventThread(void *context);
+ static void VSyncHandlerCallback(int fd, unsigned int sequence, unsigned int tv_sec,
+ unsigned int tv_usec, void *data);
+
+ void *DisplayEventHandler();
+ void HandleVSync(char *data);
+ void HandleIdleTimeout(char *data);
+ void HandleCECMessage(char *data);
+ void HandleThreadExit(char *data) {}
+ void HandleThermal(char *data) {}
+ void HandleBlank(char *data) {}
+ void PopulateHWEventData(const vector<HWEvent> &event_list);
+ DisplayError SetEventParser();
+ DisplayError InitializePollFd();
+ DisplayError CloseFds();
+ DisplayError RegisterVSync();
+
+ HWEventHandler *event_handler_{};
+ vector<HWEventData> event_data_list_{};
+ vector<pollfd> poll_fds_{};
+ pthread_t event_thread_{};
+ std::string event_thread_name_ = "SDM_EventThread";
+ bool exit_threads_ = false;
+ uint32_t vsync_index_ = 0;
+};
+
+} // namespace sdm
+
+#endif // __HW_EVENTS_DRM_H__
diff --git a/sdm/libs/core/drm/hw_info_drm.cpp b/sdm/libs/core/drm/hw_info_drm.cpp
new file mode 100644
index 0000000..3fb87d3
--- /dev/null
+++ b/sdm/libs/core/drm/hw_info_drm.cpp
@@ -0,0 +1,461 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <dlfcn.h>
+#include <drm/drm_fourcc.h>
+#include <drm_lib_loader.h>
+#include <drm_master.h>
+#include <drm_res_mgr.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <utils/constants.h>
+#include <utils/debug.h>
+#include <utils/sys.h>
+
+#include <algorithm>
+#include <fstream>
+#include <iostream>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "hw_info_drm.h"
+
+#define __CLASS__ "HWInfoDRM"
+
+using drm_utils::DRMMaster;
+using drm_utils::DRMResMgr;
+using drm_utils::DRMLogger;
+using drm_utils::DRMLibLoader;
+using sde_drm::GetDRMManager;
+using sde_drm::DRMPlanesInfo;
+using sde_drm::DRMCrtcInfo;
+using sde_drm::DRMPlaneType;
+
+using std::vector;
+using std::map;
+using std::string;
+using std::fstream;
+using std::to_string;
+
+namespace sdm {
+
+class DRMLoggerImpl : public DRMLogger {
+ public:
+#define PRINTLOG(method, format, buf) \
+ va_list list; \
+ va_start(list, format); \
+ vsnprintf(buf, sizeof(buf), format, list); \
+ va_end(list); \
+ Debug::Get()->method(kTagNone, "%s", buf);
+
+ void Error(const char *format, ...) { PRINTLOG(Error, format, buf_); }
+ void Warning(const char *format, ...) { PRINTLOG(Warning, format, buf_); }
+ void Info(const char *format, ...) { PRINTLOG(Info, format, buf_); }
+ void Debug(const char *format, ...) { PRINTLOG(Debug, format, buf_); }
+
+ private:
+ char buf_[1024] = {};
+};
+
+HWResourceInfo *HWInfoDRM::hw_resource_ = nullptr;
+
+HWInfoDRM::HWInfoDRM() {
+ DRMLogger::Set(new DRMLoggerImpl());
+ default_mode_ = (DRMLibLoader::GetInstance()->IsLoaded() == false);
+ if (!default_mode_) {
+ DRMMaster *drm_master = {};
+ int dev_fd = -1;
+ DRMMaster::GetInstance(&drm_master);
+ if (!drm_master) {
+ DLOGE("Failed to acquire DRMMaster instance");
+ return;
+ }
+ drm_master->GetHandle(&dev_fd);
+ DRMLibLoader::GetInstance()->FuncGetDRMManager()(dev_fd, &drm_mgr_intf_);
+ }
+}
+
+DisplayError HWInfoDRM::GetDynamicBWLimits(HWResourceInfo *hw_resource) {
+ HWDynBwLimitInfo* bw_info = &hw_resource->dyn_bw_info;
+ for (int index = 0; index < kBwModeMax; index++) {
+ bw_info->total_bw_limit[index] = UINT32(hw_resource->max_bandwidth_low);
+ bw_info->pipe_bw_limit[index] = hw_resource->max_pipe_bw;
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWInfoDRM::GetHWResourceInfo(HWResourceInfo *hw_resource) {
+ if (hw_resource_) {
+ *hw_resource = *hw_resource_;
+ return kErrorNone;
+ }
+
+ hw_resource->num_blending_stages = 1;
+ hw_resource->max_pipe_width = 2560;
+ hw_resource->max_cursor_size = 128;
+ hw_resource->max_scale_down = 1;
+ hw_resource->max_scale_up = 1;
+ hw_resource->has_decimation = false;
+ hw_resource->max_bandwidth_low = 9600000;
+ hw_resource->max_bandwidth_high = 9600000;
+ hw_resource->max_pipe_bw = 4500000;
+ hw_resource->max_sde_clk = 412500000;
+ hw_resource->clk_fudge_factor = FLOAT(105) / FLOAT(100);
+ hw_resource->macrotile_nv12_factor = 8;
+ hw_resource->macrotile_factor = 4;
+ hw_resource->linear_factor = 1;
+ hw_resource->scale_factor = 1;
+ hw_resource->extra_fudge_factor = 2;
+ hw_resource->amortizable_threshold = 0;
+ hw_resource->system_overhead_lines = 0;
+ hw_resource->hw_dest_scalar_info.count = 0;
+ hw_resource->hw_dest_scalar_info.max_scale_up = 0;
+ hw_resource->hw_dest_scalar_info.max_input_width = 0;
+ hw_resource->hw_dest_scalar_info.max_output_width = 0;
+ hw_resource->is_src_split = true;
+ hw_resource->perf_calc = false;
+ hw_resource->has_dyn_bw_support = false;
+ hw_resource->has_qseed3 = false;
+ hw_resource->has_concurrent_writeback = false;
+
+ // TODO(user): Deprecate
+ hw_resource->hw_version = kHWMdssVersion5;
+ hw_resource->hw_revision = 0;
+ hw_resource->max_mixer_width = 0;
+ hw_resource->writeback_index = 0;
+ hw_resource->has_bwc = false;
+ hw_resource->has_ubwc = true;
+ hw_resource->has_macrotile = true;
+ hw_resource->separate_rotator = true;
+ hw_resource->has_non_scalar_rgb = false;
+
+ GetSystemInfo(hw_resource);
+ GetHWPlanesInfo(hw_resource);
+ GetWBInfo(hw_resource);
+
+ // Disable destination scalar count to 0 if extension library is not present
+ DynLib extension_lib;
+ if (!extension_lib.Open("libsdmextension.so")) {
+ hw_resource->hw_dest_scalar_info.count = 0;
+ }
+
+ DLOGI("Max plane width = %d", hw_resource->max_pipe_width);
+ DLOGI("Max cursor width = %d", hw_resource->max_cursor_size);
+ DLOGI("Max plane upscale = %d", hw_resource->max_scale_up);
+ DLOGI("Max plane downscale = %d", hw_resource->max_scale_down);
+ DLOGI("Has Decimation = %d", hw_resource->has_decimation);
+ DLOGI("Max Blending Stages = %d", hw_resource->num_blending_stages);
+ DLOGI("Has Source Split = %d", hw_resource->is_src_split);
+ DLOGI("Has QSEED3 = %d", hw_resource->has_qseed3);
+ DLOGI("Has UBWC = %d", hw_resource->has_ubwc);
+ DLOGI("Has Concurrent Writeback = %d", hw_resource->has_concurrent_writeback);
+ DLOGI("Max Low Bw = %" PRIu64 "", hw_resource->max_bandwidth_low);
+ DLOGI("Max High Bw = % " PRIu64 "", hw_resource->max_bandwidth_high);
+ DLOGI("Max Pipe Bw = %" PRIu64 " KBps", hw_resource->max_pipe_bw);
+ DLOGI("MaxSDEClock = % " PRIu64 " Hz", hw_resource->max_sde_clk);
+ DLOGI("Clock Fudge Factor = %f", hw_resource->clk_fudge_factor);
+ DLOGI("Prefill factors:");
+ DLOGI("\tTiled_NV12 = %d", hw_resource->macrotile_nv12_factor);
+ DLOGI("\tTiled = %d", hw_resource->macrotile_factor);
+ DLOGI("\tLinear = %d", hw_resource->linear_factor);
+ DLOGI("\tScale = %d", hw_resource->scale_factor);
+ DLOGI("\tFudge_factor = %d", hw_resource->extra_fudge_factor);
+
+ if (hw_resource->separate_rotator || hw_resource->num_dma_pipe) {
+ GetHWRotatorInfo(hw_resource);
+ }
+
+ if (hw_resource->has_dyn_bw_support) {
+ DisplayError ret = GetDynamicBWLimits(hw_resource);
+ if (ret != kErrorNone) {
+ DLOGE("Failed to read dynamic band width info");
+ return ret;
+ }
+
+ DLOGI("Has Support for multiple bw limits shown below");
+ for (int index = 0; index < kBwModeMax; index++) {
+ DLOGI("Mode-index=%d total_bw_limit=%d and pipe_bw_limit=%d", index,
+ hw_resource->dyn_bw_info.total_bw_limit[index],
+ hw_resource->dyn_bw_info.pipe_bw_limit[index]);
+ }
+ }
+
+ if (!hw_resource_) {
+ hw_resource_ = new HWResourceInfo();
+ *hw_resource_ = *hw_resource;
+ }
+
+ return kErrorNone;
+}
+
+void HWInfoDRM::GetSystemInfo(HWResourceInfo *hw_resource) {
+ DRMCrtcInfo info;
+ drm_mgr_intf_->GetCrtcInfo(0 /* system_info */, &info);
+ hw_resource->is_src_split = info.has_src_split;
+ hw_resource->has_qseed3 = (info.qseed_version == sde_drm::QSEEDVersion::V3);
+ hw_resource->num_blending_stages = info.max_blend_stages;
+}
+
+void HWInfoDRM::GetHWPlanesInfo(HWResourceInfo *hw_resource) {
+ DRMPlanesInfo info;
+ drm_mgr_intf_->GetPlanesInfo(&info);
+ for (auto &pipe_obj : info.planes) {
+ HWPipeCaps pipe_caps;
+ string name = {};
+ switch (pipe_obj.second) {
+ case DRMPlaneType::RGB:
+ pipe_caps.type = kPipeTypeRGB;
+ hw_resource->num_rgb_pipe++;
+ name = "RGB";
+ break;
+ case DRMPlaneType::VIG:
+ pipe_caps.type = kPipeTypeVIG;
+ hw_resource->num_vig_pipe++;
+ name = "VIG";
+ break;
+ case DRMPlaneType::DMA:
+ pipe_caps.type = kPipeTypeDMA;
+ hw_resource->num_dma_pipe++;
+ name = "DMA";
+ break;
+ case DRMPlaneType::CURSOR:
+ pipe_caps.type = kPipeTypeCursor;
+ hw_resource->num_cursor_pipe++;
+ name = "CURSOR";
+ break;
+ default:
+ break;
+ }
+ pipe_caps.id = pipe_obj.first;
+ pipe_caps.max_rects = 1;
+ DLOGI("%s Pipe : Id %d", name.c_str(), pipe_obj.first);
+ hw_resource->hw_pipes.push_back(std::move(pipe_caps));
+ }
+
+ for (auto &pipe_type : info.types) {
+ vector<LayerBufferFormat> supported_sdm_formats = {};
+ for (auto &fmts : pipe_type.second.formats_supported) {
+ GetSDMFormat(fmts.first, fmts.second, &supported_sdm_formats);
+ }
+
+ HWSubBlockType sub_blk_type = kHWSubBlockMax;
+ switch (pipe_type.first) {
+ case DRMPlaneType::RGB:
+ sub_blk_type = kHWRGBPipe;
+ // These properties are per plane but modeled in SDM as system-wide.
+ hw_resource->max_pipe_width = pipe_type.second.max_linewidth;
+ hw_resource->max_scale_down = pipe_type.second.max_downscale;
+ hw_resource->max_scale_up = pipe_type.second.max_upscale;
+ hw_resource->has_decimation =
+ pipe_type.second.max_horizontal_deci > 1 && pipe_type.second.max_vertical_deci > 1;
+ break;
+ case DRMPlaneType::VIG:
+ sub_blk_type = kHWVIGPipe;
+ // These properties are per plane but modeled in SDM as system-wide.
+ hw_resource->max_pipe_width = pipe_type.second.max_linewidth;
+ hw_resource->max_scale_down = pipe_type.second.max_downscale;
+ hw_resource->max_scale_up = pipe_type.second.max_upscale;
+ hw_resource->has_decimation =
+ pipe_type.second.max_horizontal_deci > 1 && pipe_type.second.max_vertical_deci > 1;
+ break;
+ case DRMPlaneType::DMA:
+ sub_blk_type = kHWDMAPipe;
+ break;
+ case DRMPlaneType::CURSOR:
+ sub_blk_type = kHWCursorPipe;
+ hw_resource->max_cursor_size = pipe_type.second.max_linewidth;
+ break;
+ default:
+ break;
+ }
+
+ if (sub_blk_type != kHWSubBlockMax) {
+ hw_resource->supported_formats_map.erase(sub_blk_type);
+ hw_resource->supported_formats_map.insert(make_pair(sub_blk_type, supported_sdm_formats));
+ }
+ }
+}
+
+void HWInfoDRM::GetWBInfo(HWResourceInfo *hw_resource) {
+ HWSubBlockType sub_blk_type = kHWWBIntfOutput;
+ vector<LayerBufferFormat> supported_sdm_formats = {};
+ sde_drm::DRMDisplayToken token;
+
+ // Fake register
+ if (drm_mgr_intf_->RegisterDisplay(sde_drm::DRMDisplayType::VIRTUAL, &token)) {
+ return;
+ }
+
+ sde_drm::DRMConnectorInfo connector_info;
+ drm_mgr_intf_->GetConnectorInfo(token.conn_id, &connector_info);
+ for (auto &fmts : connector_info.formats_supported) {
+ GetSDMFormat(fmts.first, fmts.second, &supported_sdm_formats);
+ }
+
+ hw_resource->supported_formats_map.erase(sub_blk_type);
+ hw_resource->supported_formats_map.insert(make_pair(sub_blk_type, supported_sdm_formats));
+
+ drm_mgr_intf_->UnregisterDisplay(token);
+}
+
+DisplayError HWInfoDRM::GetHWRotatorInfo(HWResourceInfo *hw_resource) {
+ const uint32_t kMaxV4L2Nodes = 64;
+ bool found = false;
+
+ for (uint32_t i = 0; (i < kMaxV4L2Nodes) && (false == found); i++) {
+ string path = "/sys/class/video4linux/video" + to_string(i) + "/name";
+ Sys::fstream fs(path, fstream::in);
+ if (!fs.is_open()) {
+ continue;
+ }
+
+ string line;
+ if (Sys::getline_(fs, line) && (!strncmp(line.c_str(), "sde_rotator", strlen("sde_rotator")))) {
+ hw_resource->hw_rot_info.device_path = string("/dev/video" + to_string(i));
+ hw_resource->hw_rot_info.num_rotator++;
+ hw_resource->hw_rot_info.type = HWRotatorInfo::ROT_TYPE_V4L2;
+ hw_resource->hw_rot_info.has_downscale = true;
+ // We support only 1 rotator
+ found = true;
+ }
+ }
+
+ DLOGI("V4L2 Rotator: Count = %d, Downscale = %d", hw_resource->hw_rot_info.num_rotator,
+ hw_resource->hw_rot_info.has_downscale);
+
+ return kErrorNone;
+}
+
+void HWInfoDRM::GetSDMFormat(uint32_t drm_format, uint64_t drm_format_modifier,
+ vector<LayerBufferFormat> *sdm_formats) {
+ vector<LayerBufferFormat> &fmts(*sdm_formats);
+ switch (drm_format) {
+ case DRM_FORMAT_ARGB8888:
+ fmts.push_back(kFormatARGB8888);
+ break;
+ case DRM_FORMAT_RGBA8888:
+ fmts.push_back(drm_format_modifier ? kFormatRGBA8888Ubwc : kFormatRGBA8888);
+ break;
+ case DRM_FORMAT_BGRA8888:
+ fmts.push_back(kFormatBGRA8888);
+ break;
+ case DRM_FORMAT_XRGB8888:
+ fmts.push_back(kFormatXRGB8888);
+ break;
+ case DRM_FORMAT_RGBX8888:
+ fmts.push_back(drm_format_modifier ? kFormatRGBX8888Ubwc : kFormatRGBX8888);
+ break;
+ case DRM_FORMAT_BGRX8888:
+ fmts.push_back(kFormatBGRX8888);
+ break;
+ case DRM_FORMAT_RGBA5551:
+ fmts.push_back(kFormatRGBA5551);
+ break;
+ case DRM_FORMAT_RGBA4444:
+ fmts.push_back(kFormatRGBA4444);
+ break;
+ case DRM_FORMAT_RGB888:
+ fmts.push_back(kFormatRGB888);
+ break;
+ case DRM_FORMAT_BGR888:
+ fmts.push_back(kFormatBGR888);
+ break;
+ case DRM_FORMAT_RGB565:
+ fmts.push_back(drm_format_modifier ? kFormatBGR565Ubwc : kFormatBGR565);
+ break;
+ case DRM_FORMAT_BGR565:
+ fmts.push_back(kFormatBGR565);
+ break;
+ case DRM_FORMAT_RGBA1010102:
+ fmts.push_back(drm_format_modifier ? kFormatRGBA1010102Ubwc : kFormatRGBA1010102);
+ break;
+ case DRM_FORMAT_ARGB2101010:
+ fmts.push_back(kFormatARGB2101010);
+ break;
+ case DRM_FORMAT_RGBX1010102:
+ fmts.push_back(drm_format_modifier ? kFormatRGBX1010102Ubwc : kFormatRGBX1010102);
+ break;
+ case DRM_FORMAT_XRGB2101010:
+ fmts.push_back(kFormatXRGB2101010);
+ break;
+ case DRM_FORMAT_BGRA1010102:
+ fmts.push_back(kFormatBGRA1010102);
+ break;
+ case DRM_FORMAT_ABGR2101010:
+ fmts.push_back(kFormatABGR2101010);
+ break;
+ case DRM_FORMAT_BGRX1010102:
+ fmts.push_back(kFormatBGRX1010102);
+ break;
+ case DRM_FORMAT_XBGR2101010:
+ fmts.push_back(kFormatXBGR2101010);
+ break;
+ /* case DRM_FORMAT_P010:
+ fmts.push_back(drm_format_modifier == (DRM_FORMAT_MOD_QCOM_COMPRESSED |
+ DRM_FORMAT_MOD_QCOM_TIGHT) ?
+ kFormatYCbCr420TP10Ubwc : kFormatYCbCr420P010; */
+ case DRM_FORMAT_YVU420:
+ fmts.push_back(kFormatYCrCb420PlanarStride16);
+ break;
+ case DRM_FORMAT_NV12:
+ if (drm_format_modifier) {
+ fmts.push_back(kFormatYCbCr420SPVenusUbwc);
+ } else {
+ fmts.push_back(kFormatYCbCr420SemiPlanarVenus);
+ fmts.push_back(kFormatYCbCr420SemiPlanar);
+ }
+ break;
+ case DRM_FORMAT_NV21:
+ fmts.push_back(kFormatYCrCb420SemiPlanarVenus);
+ fmts.push_back(kFormatYCrCb420SemiPlanar);
+ break;
+ case DRM_FORMAT_NV16:
+ fmts.push_back(kFormatYCbCr422H2V1SemiPlanar);
+ break;
+ default:
+ break;
+ }
+}
+
+DisplayError HWInfoDRM::GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) {
+ hw_disp_info->type = kPrimary;
+ hw_disp_info->is_connected = true;
+
+ return kErrorNone;
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/drm/hw_info_drm.h b/sdm/libs/core/drm/hw_info_drm.h
new file mode 100644
index 0000000..143cbdf
--- /dev/null
+++ b/sdm/libs/core/drm/hw_info_drm.h
@@ -0,0 +1,70 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#ifndef __HW_INFO_DRM_H__
+#define __HW_INFO_DRM_H__
+
+#include <core/core_interface.h>
+#include <core/sdm_types.h>
+#include <drm_interface.h>
+#include <private/hw_info_types.h>
+#include <bitset>
+#include <vector>
+
+#include "hw_info_interface.h"
+
+namespace sdm {
+
+class HWInfoDRM: public HWInfoInterface {
+ public:
+ HWInfoDRM();
+ virtual DisplayError GetHWResourceInfo(HWResourceInfo *hw_resource);
+ virtual DisplayError GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info);
+
+ private:
+ DisplayError GetHWRotatorInfo(HWResourceInfo *hw_resource);
+ void GetSystemInfo(HWResourceInfo *hw_resource);
+ void GetHWPlanesInfo(HWResourceInfo *hw_resource);
+ void GetWBInfo(HWResourceInfo *hw_resource);
+ DisplayError GetDynamicBWLimits(HWResourceInfo *hw_resource);
+ void GetSDMFormat(uint32_t drm_format, uint64_t drm_format_modifier,
+ std::vector<LayerBufferFormat> *sdm_formats);
+
+ sde_drm::DRMManagerInterface *drm_mgr_intf_ = {};
+ bool default_mode_ = false;
+
+ // TODO(user): Read Mdss version from the driver
+ static const int kHWMdssVersion5 = 500; // MDSS_V5
+ static const int kMaxStringLength = 1024;
+ static HWResourceInfo *hw_resource_;
+};
+
+} // namespace sdm
+
+#endif // __HW_INFO_DRM_H__
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index f6c9ae0..10ff6fb 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -61,46 +61,6 @@
namespace sdm {
-DisplayError HWInterface::Create(DisplayType type, HWInfoInterface *hw_info_intf,
- BufferSyncHandler *buffer_sync_handler,
- HWInterface **intf) {
- DisplayError error = kErrorNone;
- HWDevice *hw = nullptr;
-
- switch (type) {
- case kPrimary:
- hw = new HWPrimary(buffer_sync_handler, hw_info_intf);
- break;
- case kHDMI:
- hw = new HWHDMI(buffer_sync_handler, hw_info_intf);
- break;
- case kVirtual:
- hw = new HWVirtual(buffer_sync_handler, hw_info_intf);
- break;
- default:
- DLOGE("Undefined display type");
- return kErrorUndefined;
- }
-
- error = hw->Init();
- if (error != kErrorNone) {
- delete hw;
- DLOGE("Init on HW Intf type %d failed", type);
- return error;
- }
- *intf = hw;
-
- return error;
-}
-
-DisplayError HWInterface::Destroy(HWInterface *intf) {
- HWDevice *hw = static_cast<HWDevice *>(intf);
- hw->Deinit();
- delete hw;
-
- return kErrorNone;
-}
-
HWDevice::HWDevice(BufferSyncHandler *buffer_sync_handler)
: fb_node_index_(-1), fb_path_("/sys/devices/virtual/graphics/fb"),
buffer_sync_handler_(buffer_sync_handler), synchronous_commit_(false) {
@@ -613,6 +573,7 @@
case kFormatRGBX8888Ubwc: *target = MDP_RGBX_8888_UBWC; break;
case kFormatBGR565Ubwc: *target = MDP_RGB_565_UBWC; break;
case kFormatYCbCr420SPVenusUbwc: *target = MDP_Y_CBCR_H2V2_UBWC; break;
+ case kFormatCbYCrY422H2V1Packed: *target = MDP_CBYCRY_H2V1; break;
case kFormatRGBA1010102: *target = MDP_RGBA_1010102; break;
case kFormatARGB2101010: *target = MDP_ARGB_2101010; break;
case kFormatRGBX1010102: *target = MDP_RGBX_1010102; break;
@@ -683,6 +644,7 @@
*target = width;
break;
case kFormatYCbCr422H2V1Packed:
+ case kFormatCbYCrY422H2V1Packed:
case kFormatYCrCb422H2V1SemiPlanar:
case kFormatYCrCb422H1V2SemiPlanar:
case kFormatYCbCr422H2V1SemiPlanar:
diff --git a/sdm/libs/core/fb/hw_events.cpp b/sdm/libs/core/fb/hw_events.cpp
index 4015796..ea8034f 100644
--- a/sdm/libs/core/fb/hw_events.cpp
+++ b/sdm/libs/core/fb/hw_events.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2015 - 2017, 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,55 +49,28 @@
namespace sdm {
-DisplayError HWEventsInterface::Create(int fb_num, HWEventHandler *event_handler,
- std::vector<const char *> *event_list,
- HWEventsInterface **intf) {
- DisplayError error = kErrorNone;
- HWEvents *hw_events = NULL;
-
- hw_events = new HWEvents();
- error = hw_events->Init(fb_num, event_handler, event_list);
- if (error != kErrorNone) {
- delete hw_events;
- } else {
- *intf = hw_events;
- }
-
- return error;
-}
-
-DisplayError HWEventsInterface::Destroy(HWEventsInterface *intf) {
- HWEvents *hw_events = static_cast<HWEvents *>(intf);
-
- if (hw_events) {
- hw_events->Deinit();
- delete hw_events;
- }
-
- return kErrorNone;
-}
-
pollfd HWEvents::InitializePollFd(HWEventData *event_data) {
char node_path[kMaxStringLength] = {0};
char data[kMaxStringLength] = {0};
pollfd poll_fd = {0};
poll_fd.fd = -1;
- if (!strncmp(event_data->event_name, "thread_exit", strlen("thread_exit"))) {
+ if (event_data->event_type == HWEvent::EXIT) {
// Create an eventfd to be used to unblock the poll system call when
// a thread is exiting.
poll_fd.fd = Sys::eventfd_(0, 0);
poll_fd.events |= POLLIN;
exit_fd_ = poll_fd.fd;
} else {
- snprintf(node_path, sizeof(node_path), "%s%d/%s", fb_path_, fb_num_, event_data->event_name);
+ snprintf(node_path, sizeof(node_path), "%s%d/%s", fb_path_, fb_num_,
+ map_event_to_node_[event_data->event_type]);
poll_fd.fd = Sys::open_(node_path, O_RDONLY);
poll_fd.events |= POLLPRI | POLLERR;
}
if (poll_fd.fd < 0) {
- DLOGW("open failed for display=%d event=%s, error=%s", fb_num_, event_data->event_name,
- strerror(errno));
+ DLOGW("open failed for display=%d event=%s, error=%s", fb_num_,
+ map_event_to_node_[event_data->event_type], strerror(errno));
return poll_fd;
}
@@ -107,49 +80,58 @@
return poll_fd;
}
-DisplayError HWEvents::SetEventParser(const char *event_name, HWEventData *event_data) {
+DisplayError HWEvents::SetEventParser(HWEvent event_type, HWEventData *event_data) {
DisplayError error = kErrorNone;
-
- if (!strncmp(event_name, "vsync_event", strlen("vsync_event"))) {
- event_data->event_parser = &HWEvents::HandleVSync;
- } else if (!strncmp(event_name, "show_blank_event", strlen("show_blank_event"))) {
- event_data->event_parser = &HWEvents::HandleBlank;
- } else if (!strncmp(event_name, "idle_notify", strlen("idle_notify"))) {
- event_data->event_parser = &HWEvents::HandleIdleTimeout;
- } else if (!strncmp(event_name, "msm_fb_thermal_level", strlen("msm_fb_thermal_level"))) {
- event_data->event_parser = &HWEvents::HandleThermal;
- } else if (!strncmp(event_name, "cec/rd_msg", strlen("cec/rd_msg"))) {
- event_data->event_parser = &HWEvents::HandleCECMessage;
- } else if (!strncmp(event_name, "thread_exit", strlen("thread_exit"))) {
- event_data->event_parser = &HWEvents::HandleThreadExit;
- } else {
- error = kErrorParameters;
+ switch (event_type) {
+ case HWEvent::VSYNC:
+ event_data->event_parser = &HWEvents::HandleVSync;
+ break;
+ case HWEvent::IDLE_NOTIFY:
+ event_data->event_parser = &HWEvents::HandleIdleTimeout;
+ break;
+ case HWEvent::CEC_READ_MESSAGE:
+ event_data->event_parser = &HWEvents::HandleCECMessage;
+ break;
+ case HWEvent::EXIT:
+ event_data->event_parser = &HWEvents::HandleThreadExit;
+ break;
+ case HWEvent::SHOW_BLANK_EVENT:
+ event_data->event_parser = &HWEvents::HandleBlank;
+ break;
+ case HWEvent::THERMAL_LEVEL:
+ event_data->event_parser = &HWEvents::HandleThermal;
+ break;
+ default:
+ error = kErrorParameters;
+ break;
}
return error;
}
void HWEvents::PopulateHWEventData() {
- for (uint32_t i = 0; i < event_list_->size(); i++) {
- const char *event_name = event_list_->at(i);
+ for (uint32_t i = 0; i < event_list_.size(); i++) {
HWEventData event_data;
- event_data.event_name = event_name;
- SetEventParser(event_name, &event_data);
+ event_data.event_type = event_list_[i];
+ SetEventParser(event_list_[i], &event_data);
poll_fds_[i] = InitializePollFd(&event_data);
event_data_list_.push_back(event_data);
}
}
DisplayError HWEvents::Init(int fb_num, HWEventHandler *event_handler,
- vector<const char *> *event_list) {
+ const vector<HWEvent> &event_list) {
if (!event_handler)
return kErrorParameters;
event_handler_ = event_handler;
fb_num_ = fb_num;
event_list_ = event_list;
- poll_fds_.resize(event_list_->size());
+ poll_fds_.resize(event_list_.size());
event_thread_name_ += " - " + std::to_string(fb_num_);
+ map_event_to_node_ = {{HWEvent::VSYNC, "vsync_event"}, {HWEvent::EXIT, "thread_exit"},
+ {HWEvent::IDLE_NOTIFY, "idle_notify"}, {HWEvent::SHOW_BLANK_EVENT, "show_blank_event"},
+ {HWEvent::CEC_READ_MESSAGE, "cec/rd_msg"}, {HWEvent::THERMAL_LEVEL, "msm_fb_thermal_level"}};
PopulateHWEventData();
@@ -173,7 +155,7 @@
pthread_join(event_thread_, NULL);
- for (uint32_t i = 0; i < event_list_->size(); i++) {
+ for (uint32_t i = 0; i < event_list_.size(); i++) {
Sys::close_(poll_fds_[i].fd);
poll_fds_[i].fd = -1;
}
@@ -196,17 +178,17 @@
setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent);
while (!exit_threads_) {
- int error = Sys::poll_(poll_fds_.data(), UINT32(event_list_->size()), -1);
+ int error = Sys::poll_(poll_fds_.data(), UINT32(event_list_.size()), -1);
if (error <= 0) {
DLOGW("poll failed. error = %s", strerror(errno));
continue;
}
- for (uint32_t event = 0; event < event_list_->size(); event++) {
+ for (uint32_t event = 0; event < event_list_.size(); event++) {
pollfd &poll_fd = poll_fds_[event];
- if (!strncmp(event_list_->at(event), "thread_exit", strlen("thread_exit"))) {
+ if (event_list_.at(event) == HWEvent::EXIT) {
if ((poll_fd.revents & POLLIN) && (Sys::read_(poll_fd.fd, data, kMaxStringLength) > 0)) {
(this->*(event_data_list_[event]).event_parser)(data);
}
@@ -253,4 +235,3 @@
}
} // namespace sdm
-
diff --git a/sdm/libs/core/fb/hw_events.h b/sdm/libs/core/fb/hw_events.h
index bcc5ef6..e024924 100644
--- a/sdm/libs/core/fb/hw_events.h
+++ b/sdm/libs/core/fb/hw_events.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2015 - 2017, 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:
@@ -37,12 +37,13 @@
namespace sdm {
using std::vector;
+using std::map;
class HWEvents : public HWEventsInterface {
public:
- DisplayError Init(int fb_num, HWEventHandler *event_handler,
- vector<const char *> *event_list);
- DisplayError Deinit();
+ virtual DisplayError Init(int fb_num, HWEventHandler *event_handler,
+ const vector<HWEvent> &event_list);
+ virtual DisplayError Deinit();
private:
static const int kMaxStringLength = 1024;
@@ -50,8 +51,8 @@
typedef void (HWEvents::*EventParser)(char *);
struct HWEventData {
- const char* event_name = NULL;
- EventParser event_parser = NULL;
+ HWEvent event_type {};
+ EventParser event_parser {};
};
static void* DisplayEventThread(void *context);
@@ -63,14 +64,15 @@
void HandleCECMessage(char *data);
void HandleThreadExit(char *data) { }
void PopulateHWEventData();
- DisplayError SetEventParser(const char *event_name, HWEventData *event_data);
+ DisplayError SetEventParser(HWEvent event_type, HWEventData *event_data);
pollfd InitializePollFd(HWEventData *event_data);
- HWEventHandler *event_handler_ = NULL;
- vector<const char *> *event_list_ = NULL;
+ HWEventHandler *event_handler_ = {};
+ vector<HWEvent> event_list_ = {};
vector<HWEventData> event_data_list_ = {};
- vector<pollfd> poll_fds_;
- pthread_t event_thread_;
+ vector<pollfd> poll_fds_ = {};
+ map<HWEvent, const char *> map_event_to_node_ = {};
+ pthread_t event_thread_ = {};
std::string event_thread_name_ = "SDM_EventThread";
bool exit_threads_ = false;
const char* fb_path_ = "/sys/devices/virtual/graphics/fb";
diff --git a/sdm/libs/core/fb/hw_info.cpp b/sdm/libs/core/fb/hw_info.cpp
index 2931638..d898cd2 100644
--- a/sdm/libs/core/fb/hw_info.cpp
+++ b/sdm/libs/core/fb/hw_info.cpp
@@ -86,27 +86,6 @@
return 0;
}
-DisplayError HWInfoInterface::Create(HWInfoInterface **intf) {
- DisplayError error = kErrorNone;
- HWInfo *hw_info = NULL;
-
- hw_info = new HWInfo();
- if (!hw_info) {
- error = kErrorMemory;
- } else {
- *intf = hw_info;
- }
-
- return error;
-}
-
-DisplayError HWInfoInterface::Destroy(HWInfoInterface *intf) {
- HWInfo *hw_info = static_cast<HWInfo *>(intf);
- delete hw_info;
-
- return kErrorNone;
-}
-
DisplayError HWInfo::GetDynamicBWLimits(HWResourceInfo *hw_resource) {
Sys::fstream fs(kBWModeBitmap, fstream::in);
if (!fs.is_open()) {
diff --git a/sdm/libs/core/fb/hw_primary.cpp b/sdm/libs/core/fb/hw_primary.cpp
index a381d7f..3fdc8b2 100644
--- a/sdm/libs/core/fb/hw_primary.cpp
+++ b/sdm/libs/core/fb/hw_primary.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2015 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2015 - 2017, 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
@@ -250,8 +250,8 @@
(FLOAT(var_screeninfo.yres) * 25.4f) / FLOAT(var_screeninfo.height);
display_attributes_.fps = meta_data.data.panel_frame_rate;
display_attributes_.vsync_period_ns = UINT32(1000000000L / display_attributes_.fps);
- display_attributes_.is_device_split = (hw_panel_info_.split_info.left_split ||
- (var_screeninfo.xres > hw_resource_.max_mixer_width)) ? true : false;
+ display_attributes_.is_device_split = (hw_panel_info_.split_info.right_split ||
+ (var_screeninfo.xres > hw_resource_.max_mixer_width));
display_attributes_.h_total += (display_attributes_.is_device_split ||
hw_panel_info_.ping_pong_split)? h_blanking : 0;
diff --git a/sdm/libs/core/hw_events_interface.cpp b/sdm/libs/core/hw_events_interface.cpp
new file mode 100644
index 0000000..ed62b86
--- /dev/null
+++ b/sdm/libs/core/hw_events_interface.cpp
@@ -0,0 +1,75 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <utils/utils.h>
+#include <vector>
+
+#include "hw_events_interface.h"
+#include "fb/hw_events.h"
+#ifdef COMPILE_DRM
+#include "drm/hw_events_drm.h"
+#endif
+
+#define __CLASS__ "HWEventsInterface"
+
+namespace sdm {
+
+DisplayError HWEventsInterface::Create(int display_type, HWEventHandler *event_handler,
+ const std::vector<HWEvent> &event_list,
+ HWEventsInterface **intf) {
+ DisplayError error = kErrorNone;
+ HWEventsInterface *hw_events = nullptr;
+ if (GetDriverType() == DriverType::FB) {
+ hw_events = new HWEvents();
+ } else {
+#ifdef COMPILE_DRM
+ hw_events = new HWEventsDRM();
+#endif
+ }
+
+ error = hw_events->Init(display_type, event_handler, event_list);
+ if (error != kErrorNone) {
+ delete hw_events;
+ } else {
+ *intf = hw_events;
+ }
+
+ return error;
+}
+
+DisplayError HWEventsInterface::Destroy(HWEventsInterface *intf) {
+ if (intf) {
+ intf->Deinit();
+ delete intf;
+ }
+
+ return kErrorNone;
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/hw_events_interface.h b/sdm/libs/core/hw_events_interface.h
index a133a3a..bcb7d43 100644
--- a/sdm/libs/core/hw_events_interface.h
+++ b/sdm/libs/core/hw_events_interface.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2016-2017, 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:
@@ -32,10 +32,25 @@
namespace sdm {
+class HWEventHandler;
+
+enum HWEvent {
+ VSYNC = 0,
+ EXIT,
+ IDLE_NOTIFY,
+ CEC_READ_MESSAGE,
+ SHOW_BLANK_EVENT,
+ THERMAL_LEVEL,
+};
+
class HWEventsInterface {
public:
- static DisplayError Create(int fb_num, HWEventHandler *event_handler,
- std::vector<const char *> *event_list, HWEventsInterface **intf);
+ virtual DisplayError Init(int display_type, HWEventHandler *event_handler,
+ const std::vector<HWEvent> &event_list) = 0;
+ virtual DisplayError Deinit() = 0;
+
+ static DisplayError Create(int display_type, HWEventHandler *event_handler,
+ const std::vector<HWEvent> &event_list, HWEventsInterface **intf);
static DisplayError Destroy(HWEventsInterface *intf);
protected:
diff --git a/sdm/libs/core/hw_info_interface.cpp b/sdm/libs/core/hw_info_interface.cpp
new file mode 100644
index 0000000..1773fe5
--- /dev/null
+++ b/sdm/libs/core/hw_info_interface.cpp
@@ -0,0 +1,62 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <utils/utils.h>
+
+#include "hw_info_interface.h"
+#include "fb/hw_info.h"
+#ifdef COMPILE_DRM
+#include "drm/hw_info_drm.h"
+#endif
+
+#define __CLASS__ "HWInfoInterface"
+
+namespace sdm {
+
+DisplayError HWInfoInterface::Create(HWInfoInterface **intf) {
+ if (GetDriverType() == DriverType::FB) {
+ *intf = new HWInfo();
+ } else {
+#ifdef COMPILE_DRM
+ *intf = new HWInfoDRM();
+#endif
+ }
+
+ return kErrorNone;
+}
+
+DisplayError HWInfoInterface::Destroy(HWInfoInterface *intf) {
+ if (intf) {
+ delete intf;
+ }
+
+ return kErrorNone;
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/hw_interface.cpp b/sdm/libs/core/hw_interface.cpp
new file mode 100644
index 0000000..b328831
--- /dev/null
+++ b/sdm/libs/core/hw_interface.cpp
@@ -0,0 +1,102 @@
+/*
+* Copyright (c) 2017, 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:
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of The Linux Foundation nor the names of its
+* contributors may be used to endorse or promote products derived
+* from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <utils/debug.h>
+#include <utils/utils.h>
+
+#include "hw_interface.h"
+#include "fb/hw_device.h"
+#include "fb/hw_primary.h"
+#include "fb/hw_hdmi.h"
+#include "fb/hw_virtual.h"
+#ifdef COMPILE_DRM
+#include "drm/hw_device_drm.h"
+#endif
+
+#define __CLASS__ "HWInterface"
+
+namespace sdm {
+
+DisplayError HWInterface::Create(DisplayType type, HWInfoInterface *hw_info_intf,
+ BufferSyncHandler *buffer_sync_handler,
+ HWInterface **intf) {
+ DisplayError error = kErrorNone;
+ HWInterface *hw = nullptr;
+ DriverType driver_type = GetDriverType();
+
+ switch (type) {
+ case kPrimary:
+ if (driver_type == DriverType::FB) {
+ hw = new HWPrimary(buffer_sync_handler, hw_info_intf);
+ } else {
+#ifdef COMPILE_DRM
+ hw = new HWDeviceDRM(buffer_sync_handler, hw_info_intf);
+#endif
+ }
+ break;
+ case kHDMI:
+ if (driver_type == DriverType::FB) {
+ hw = new HWHDMI(buffer_sync_handler, hw_info_intf);
+ } else {
+ return kErrorNotSupported;
+ }
+ break;
+ case kVirtual:
+ if (driver_type == DriverType::FB) {
+ hw = new HWVirtual(buffer_sync_handler, hw_info_intf);
+ } else {
+ return kErrorNotSupported;
+ }
+ break;
+ default:
+ DLOGE("Undefined display type");
+ return kErrorUndefined;
+ }
+
+ error = hw->Init();
+ if (error != kErrorNone) {
+ delete hw;
+ DLOGE("Init on HW Intf type %d failed", type);
+ return error;
+ }
+ *intf = hw;
+
+ return error;
+}
+
+DisplayError HWInterface::Destroy(HWInterface *intf) {
+ if (intf) {
+ intf->Deinit();
+ delete intf;
+ }
+
+ return kErrorNone;
+}
+
+} // namespace sdm
diff --git a/sdm/libs/core/hw_interface.h b/sdm/libs/core/hw_interface.h
index da3ac4d..2e082ae 100644
--- a/sdm/libs/core/hw_interface.h
+++ b/sdm/libs/core/hw_interface.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2017, 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:
@@ -70,6 +70,8 @@
BufferSyncHandler *buffer_sync_handler, HWInterface **intf);
static DisplayError Destroy(HWInterface *intf);
+ virtual DisplayError Init() = 0;
+ virtual DisplayError Deinit() = 0;
virtual DisplayError GetActiveConfig(uint32_t *active_config) = 0;
virtual DisplayError GetNumDisplayAttributes(uint32_t *count) = 0;
virtual DisplayError GetDisplayAttributes(uint32_t index,
diff --git a/sdm/libs/core/strategy.cpp b/sdm/libs/core/strategy.cpp
index 97a6cc3..aa89e64 100644
--- a/sdm/libs/core/strategy.cpp
+++ b/sdm/libs/core/strategy.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved.
+* Copyright (c) 2014 - 2017, 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:
@@ -177,9 +177,7 @@
float layer_mixer_width = mixer_attributes_.width;
float layer_mixer_height = mixer_attributes_.height;
- if (!hw_resource_info_.is_src_split &&
- ((layer_mixer_width > hw_resource_info_.max_mixer_width) ||
- ((hw_panel_info_.is_primary_panel) && hw_panel_info_.split_info.right_split))) {
+ if (!hw_resource_info_.is_src_split && display_attributes_.is_device_split) {
split_display = true;
}
diff --git a/sdm/libs/hwc/hwc_buffer_allocator.cpp b/sdm/libs/hwc/hwc_buffer_allocator.cpp
index bda316f..7e32d65 100644
--- a/sdm/libs/hwc/hwc_buffer_allocator.cpp
+++ b/sdm/libs/hwc/hwc_buffer_allocator.cpp
@@ -211,6 +211,7 @@
case kFormatYCrCb420SemiPlanar: *target = HAL_PIXEL_FORMAT_YCrCb_420_SP; break;
case kFormatYCbCr420SemiPlanar: *target = HAL_PIXEL_FORMAT_YCbCr_420_SP; break;
case kFormatYCbCr422H2V1Packed: *target = HAL_PIXEL_FORMAT_YCbCr_422_I; break;
+ case kFormatCbYCrY422H2V1Packed: *target = HAL_PIXEL_FORMAT_CbYCrY_422_I; break;
case kFormatYCbCr422H2V1SemiPlanar: *target = HAL_PIXEL_FORMAT_YCbCr_422_SP; break;
case kFormatYCbCr420SemiPlanarVenus: *target = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; break;
case kFormatYCrCb420SemiPlanarVenus: *target = HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS; break;
diff --git a/sdm/libs/hwc/hwc_display.cpp b/sdm/libs/hwc/hwc_display.cpp
index 2f0c42b..aff6bbf 100644
--- a/sdm/libs/hwc/hwc_display.cpp
+++ b/sdm/libs/hwc/hwc_display.cpp
@@ -37,6 +37,7 @@
#include <utils/debug.h>
#include <sync/sync.h>
#include <cutils/properties.h>
+#include <qd_utils.h>
#include <map>
#include <utility>
#include <vector>
@@ -517,6 +518,7 @@
layer_buffer.planes[0].offset = pvt_handle->offset;
layer_buffer.planes[0].stride = UINT32(pvt_handle->width);
layer_buffer.size = pvt_handle->size;
+ layer_buffer.fb_id = pvt_handle->fb_id;
}
// if swapinterval property is set to 0 then close and reset the acquireFd
@@ -1014,6 +1016,7 @@
case HAL_PIXEL_FORMAT_YCbCr_420_SP: format = kFormatYCbCr420SemiPlanar; break;
case HAL_PIXEL_FORMAT_YCbCr_422_SP: format = kFormatYCbCr422H2V1SemiPlanar; break;
case HAL_PIXEL_FORMAT_YCbCr_422_I: format = kFormatYCbCr422H2V1Packed; break;
+ case HAL_PIXEL_FORMAT_CbYCrY_422_I: format = kFormatCbYCrY422H2V1Packed; break;
case HAL_PIXEL_FORMAT_RGBA_1010102: format = kFormatRGBA1010102; break;
case HAL_PIXEL_FORMAT_ARGB_2101010: format = kFormatARGB2101010; break;
case HAL_PIXEL_FORMAT_RGBX_1010102: format = kFormatRGBX1010102; break;
@@ -1071,7 +1074,7 @@
snprintf(dump_file_name, sizeof(dump_file_name), "%s/input_layer%d_%dx%d_%s_frame%d.raw",
dir_path, i, pvt_handle->width, pvt_handle->height,
- GetHALPixelFormatString(pvt_handle->format), dump_frame_index_);
+ qdutils::GetHALPixelFormatString(pvt_handle->format), dump_frame_index_);
FILE* fp = fopen(dump_file_name, "w+");
if (fp) {
@@ -1127,81 +1130,6 @@
}
}
-const char *HWCDisplay::GetHALPixelFormatString(int format) {
- switch (format) {
- case HAL_PIXEL_FORMAT_RGBA_8888:
- return "RGBA_8888";
- case HAL_PIXEL_FORMAT_RGBX_8888:
- return "RGBX_8888";
- case HAL_PIXEL_FORMAT_RGB_888:
- return "RGB_888";
- case HAL_PIXEL_FORMAT_RGB_565:
- return "RGB_565";
- case HAL_PIXEL_FORMAT_BGR_565:
- return "BGR_565";
- case HAL_PIXEL_FORMAT_BGRA_8888:
- return "BGRA_8888";
- case HAL_PIXEL_FORMAT_RGBA_5551:
- return "RGBA_5551";
- case HAL_PIXEL_FORMAT_RGBA_4444:
- return "RGBA_4444";
- case HAL_PIXEL_FORMAT_YV12:
- return "YV12";
- case HAL_PIXEL_FORMAT_YCbCr_422_SP:
- return "YCbCr_422_SP_NV16";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP:
- return "YCrCb_420_SP_NV21";
- case HAL_PIXEL_FORMAT_YCbCr_422_I:
- return "YCbCr_422_I_YUY2";
- case HAL_PIXEL_FORMAT_YCrCb_422_I:
- return "YCrCb_422_I_YVYU";
- case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
- return "NV12_ENCODEABLE";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
- return "YCbCr_420_SP_TILED_TILE_4x2";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP:
- return "YCbCr_420_SP";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
- return "YCrCb_420_SP_ADRENO";
- case HAL_PIXEL_FORMAT_YCrCb_422_SP:
- return "YCrCb_422_SP";
- case HAL_PIXEL_FORMAT_R_8:
- return "R_8";
- case HAL_PIXEL_FORMAT_RG_88:
- return "RG_88";
- case HAL_PIXEL_FORMAT_INTERLACE:
- return "INTERLACE";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
- return "YCbCr_420_SP_VENUS";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
- return "YCrCb_420_SP_VENUS";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
- return "YCbCr_420_SP_VENUS_UBWC";
- case HAL_PIXEL_FORMAT_RGBA_1010102:
- return "RGBA_1010102";
- case HAL_PIXEL_FORMAT_ARGB_2101010:
- return "ARGB_2101010";
- case HAL_PIXEL_FORMAT_RGBX_1010102:
- return "RGBX_1010102";
- case HAL_PIXEL_FORMAT_XRGB_2101010:
- return "XRGB_2101010";
- case HAL_PIXEL_FORMAT_BGRA_1010102:
- return "BGRA_1010102";
- case HAL_PIXEL_FORMAT_ABGR_2101010:
- return "ABGR_2101010";
- case HAL_PIXEL_FORMAT_BGRX_1010102:
- return "BGRX_1010102";
- case HAL_PIXEL_FORMAT_XBGR_2101010:
- return "XBGR_2101010";
- case HAL_PIXEL_FORMAT_YCbCr_420_P010:
- return "YCbCr_420_P010";
- case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
- return "YCbCr_420_TP10_UBWC";
- default:
- return "Unknown_format";
- }
-}
-
const char *HWCDisplay::GetDisplayString() {
switch (type_) {
case kPrimary:
diff --git a/sdm/libs/hwc/hwc_display.h b/sdm/libs/hwc/hwc_display.h
index 8da8516..5652996 100644
--- a/sdm/libs/hwc/hwc_display.h
+++ b/sdm/libs/hwc/hwc_display.h
@@ -192,7 +192,6 @@
int SetFormat(const int32_t &source, const int flags, LayerBufferFormat *target);
void SetLayerS3DMode(const LayerBufferS3DFormat &source, uint32_t *target);
LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
- const char *GetHALPixelFormatString(int format);
const char *GetDisplayString();
void MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list);
virtual void ApplyScanAdjustment(hwc_rect_t *display_frame);
diff --git a/sdm/libs/hwc/hwc_tonemapper.cpp b/sdm/libs/hwc/hwc_tonemapper.cpp
index 93ff452..0ceb2e5 100644
--- a/sdm/libs/hwc/hwc_tonemapper.cpp
+++ b/sdm/libs/hwc/hwc_tonemapper.cpp
@@ -140,11 +140,13 @@
// then SDM marks them for SDE Composition because the cached FB layer gets displayed.
// GPU count will be 0 in this case. Try to use the existing tone-mapped frame buffer.
// No ToneMap/Blit is required. Just update the buffer & acquire fence fd of FB layer.
- ToneMapSession *fb_tone_map_session = tone_map_sessions_.at(fb_session_index_);
- fb_tone_map_session->UpdateBuffer(-1 /* acquire_fence */, &layer->input_buffer);
- fb_tone_map_session->layer_index_ = INT(i);
- fb_tone_map_session->acquired_ = true;
- return 0;
+ if (!tone_map_sessions_.empty()) {
+ ToneMapSession *fb_tone_map_session = tone_map_sessions_.at(fb_session_index_);
+ fb_tone_map_session->UpdateBuffer(-1 /* acquire_fence */, &layer->input_buffer);
+ fb_tone_map_session->layer_index_ = INT(i);
+ fb_tone_map_session->acquired_ = true;
+ return 0;
+ }
}
error = AcquireToneMapSession(layer, &session_index);
fb_session_index_ = session_index;
@@ -223,7 +225,6 @@
delete tone_map_sessions_.back();
tone_map_sessions_.pop_back();
}
- TonemapperFactory_Destroy();
fb_session_index_ = 0;
}
}
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index 3b0015d..382e234 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -27,6 +27,7 @@
#include <utils/debug.h>
#include <utils/formats.h>
#include <utils/rect.h>
+#include <qd_utils.h>
#include <algorithm>
#include <map>
@@ -1164,7 +1165,7 @@
snprintf(dump_file_name, sizeof(dump_file_name), "%s/input_layer%d_%dx%d_%s_frame%d.raw",
dir_path, i, pvt_handle->width, pvt_handle->height,
- GetHALPixelFormatString(pvt_handle->format), dump_frame_index_);
+ qdutils::GetHALPixelFormatString(pvt_handle->format), dump_frame_index_);
FILE *fp = fopen(dump_file_name, "w+");
if (fp) {
@@ -1219,81 +1220,6 @@
}
}
-const char *HWCDisplay::GetHALPixelFormatString(int format) {
- switch (format) {
- case HAL_PIXEL_FORMAT_RGBA_8888:
- return "RGBA_8888";
- case HAL_PIXEL_FORMAT_RGBX_8888:
- return "RGBX_8888";
- case HAL_PIXEL_FORMAT_RGB_888:
- return "RGB_888";
- case HAL_PIXEL_FORMAT_RGB_565:
- return "RGB_565";
- case HAL_PIXEL_FORMAT_BGR_565:
- return "BGR_565";
- case HAL_PIXEL_FORMAT_BGRA_8888:
- return "BGRA_8888";
- case HAL_PIXEL_FORMAT_RGBA_5551:
- return "RGBA_5551";
- case HAL_PIXEL_FORMAT_RGBA_4444:
- return "RGBA_4444";
- case HAL_PIXEL_FORMAT_YV12:
- return "YV12";
- case HAL_PIXEL_FORMAT_YCbCr_422_SP:
- return "YCbCr_422_SP_NV16";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP:
- return "YCrCb_420_SP_NV21";
- case HAL_PIXEL_FORMAT_YCbCr_422_I:
- return "YCbCr_422_I_YUY2";
- case HAL_PIXEL_FORMAT_YCrCb_422_I:
- return "YCrCb_422_I_YVYU";
- case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
- return "NV12_ENCODEABLE";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
- return "YCbCr_420_SP_TILED_TILE_4x2";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP:
- return "YCbCr_420_SP";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
- return "YCrCb_420_SP_ADRENO";
- case HAL_PIXEL_FORMAT_YCrCb_422_SP:
- return "YCrCb_422_SP";
- case HAL_PIXEL_FORMAT_R_8:
- return "R_8";
- case HAL_PIXEL_FORMAT_RG_88:
- return "RG_88";
- case HAL_PIXEL_FORMAT_INTERLACE:
- return "INTERLACE";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
- return "YCbCr_420_SP_VENUS";
- case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
- return "YCrCb_420_SP_VENUS";
- case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
- return "YCbCr_420_SP_VENUS_UBWC";
- case HAL_PIXEL_FORMAT_RGBA_1010102:
- return "RGBA_1010102";
- case HAL_PIXEL_FORMAT_ARGB_2101010:
- return "ARGB_2101010";
- case HAL_PIXEL_FORMAT_RGBX_1010102:
- return "RGBX_1010102";
- case HAL_PIXEL_FORMAT_XRGB_2101010:
- return "XRGB_2101010";
- case HAL_PIXEL_FORMAT_BGRA_1010102:
- return "BGRA_1010102";
- case HAL_PIXEL_FORMAT_ABGR_2101010:
- return "ABGR_2101010";
- case HAL_PIXEL_FORMAT_BGRX_1010102:
- return "BGRX_1010102";
- case HAL_PIXEL_FORMAT_XBGR_2101010:
- return "XBGR_2101010";
- case HAL_PIXEL_FORMAT_YCbCr_420_P010:
- return "YCbCr_420_P010";
- case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
- return "YCbCr_420_TP10_UBWC";
- default:
- return "Unknown_format";
- }
-}
-
const char *HWCDisplay::GetDisplayString() {
switch (type_) {
case kPrimary:
diff --git a/sdm/libs/hwc2/hwc_display.h b/sdm/libs/hwc2/hwc_display.h
index 165e2c3..bc3c929 100644
--- a/sdm/libs/hwc2/hwc_display.h
+++ b/sdm/libs/hwc2/hwc_display.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright 2015 The Android Open Source Project
@@ -212,7 +212,6 @@
return kErrorNotSupported;
}
LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags);
- const char *GetHALPixelFormatString(int format);
const char *GetDisplayString();
void MarkLayersForGPUBypass(void);
void MarkLayersForClientComposition(void);
diff --git a/sdm/libs/hwc2/hwc_layers.cpp b/sdm/libs/hwc2/hwc_layers.cpp
index 2ed21df..c8fd163 100644
--- a/sdm/libs/hwc2/hwc_layers.cpp
+++ b/sdm/libs/hwc2/hwc_layers.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright 2015 The Android Open Source Project
@@ -143,6 +143,7 @@
layer_buffer->acquire_fence_fd = acquire_fence;
layer_buffer->size = handle->size;
layer_buffer->buffer_id = reinterpret_cast<uint64_t>(handle);
+ layer_buffer->fb_id = handle->fb_id;
return HWC2::Error::None;
}
diff --git a/sdm/libs/utils/formats.cpp b/sdm/libs/utils/formats.cpp
index 8e9d0b8..43abb63 100644
--- a/sdm/libs/utils/formats.cpp
+++ b/sdm/libs/utils/formats.cpp
@@ -98,6 +98,7 @@
case kFormatYCrCb422H2V1SemiPlanar: return "Y_CRCB_422_H2V2";
case kFormatYCbCr420SPVenusUbwc: return "Y_CBCR_420_VENUS_UBWC";
case kFormatYCbCr422H2V1Packed: return "YCBYCR_422_H2V1";
+ case kFormatCbYCrY422H2V1Packed: return "CBYCRY_422_H2V1";
case kFormatRGBA1010102: return "RGBA_1010102";
case kFormatARGB2101010: return "ARGB_2101010";
case kFormatRGBX1010102: return "RGBX_1010102";
diff --git a/sdm/libs/utils/utils.cpp b/sdm/libs/utils/utils.cpp
index 2ca9039..07211a1 100644
--- a/sdm/libs/utils/utils.cpp
+++ b/sdm/libs/utils/utils.cpp
@@ -27,8 +27,11 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <utils/sys.h>
+#include <unistd.h>
#include <math.h>
+#include <utils/sys.h>
+#include <utils/utils.h>
+
#include <algorithm>
#define __CLASS__ "Utils"
@@ -60,4 +63,9 @@
}
}
+DriverType GetDriverType() {
+ const char *fb_caps = "/sys/devices/virtual/graphics/fb0/mdp/caps";
+ // 0 - File exists
+ return Sys::access_(fb_caps, F_OK) ? DriverType::DRM : DriverType::FB;
+}
} // namespace sdm