upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
21
android/hardware/qcom/display/msm8998/libdrmutils/Android.mk
Normal file
21
android/hardware/qcom/display/msm8998/libdrmutils/Android.mk
Normal file
|
@ -0,0 +1,21 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libdrmutils
|
||||
LOCAL_VENDOR_MODULE := true
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_C_INCLUDES := external/libdrm
|
||||
LOCAL_SHARED_LIBRARIES := libdrm libdl
|
||||
LOCAL_CFLAGS := -DLOG_TAG=\"DRMUTILS\" -Wall -std=c++11 -Werror -fno-operator-names
|
||||
LOCAL_CLANG := true
|
||||
|
||||
ifeq ($(TARGET_COMPILE_WITH_MSM_KERNEL),true)
|
||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
|
||||
LOCAL_C_INCLUDES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
|
||||
endif
|
||||
|
||||
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)
|
|
@ -0,0 +1,408 @@
|
|||
/*
|
||||
* 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: Sets PP feature
|
||||
* Arg: uint32_t - CRTC ID
|
||||
* DRMPPFeatureInfo * - PP feature data pointer
|
||||
*/
|
||||
CRTC_SET_POST_PROC,
|
||||
/*
|
||||
* 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;
|
||||
};
|
||||
|
||||
enum DRMPPFeatureID {
|
||||
kFeaturePcc,
|
||||
kFeatureIgc,
|
||||
kFeaturePgc,
|
||||
kFeatureMixerGc,
|
||||
kFeaturePaV2,
|
||||
kFeatureDither,
|
||||
kFeatureGamut,
|
||||
kFeaturePADither,
|
||||
kPPFeaturesMax,
|
||||
};
|
||||
|
||||
enum DRMPPPropType {
|
||||
kPropEnum,
|
||||
kPropRange,
|
||||
kPropBlob,
|
||||
kPropTypeMax,
|
||||
};
|
||||
|
||||
struct DRMPPFeatureInfo {
|
||||
DRMPPFeatureID id;
|
||||
DRMPPPropType type;
|
||||
uint32_t version;
|
||||
uint32_t payload_size;
|
||||
void *payload;
|
||||
};
|
||||
|
||||
/* 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)();
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/*
|
||||
* Will query post propcessing feature info of a CRTC.
|
||||
* [output]: DRMPPFeatureInfo: CRTC post processing feature info
|
||||
*/
|
||||
virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo &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__
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
void DRMLibLoader::Destroy() {
|
||||
lock_guard<mutex> obj(s_lock);
|
||||
if (s_instance) {
|
||||
delete s_instance;
|
||||
s_instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DRMLibLoader::~DRMLibLoader() {
|
||||
if (lib_) {
|
||||
::dlclose(lib_);
|
||||
lib_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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();
|
||||
static void Destroy();
|
||||
|
||||
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__
|
|
@ -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__
|
153
android/hardware/qcom/display/msm8998/libdrmutils/drm_master.cpp
Normal file
153
android/hardware/qcom/display/msm8998/libdrmutils/drm_master.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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 <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
// Intentionally included after xf86 headers so that they in-turn include libdrm version of drm.h
|
||||
// that doesn't use keyword "virtual" for a variable name. Not doing so leads to the kernel version
|
||||
// of drm.h being included causing compilation to fail
|
||||
#include <drm/msm_drm.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;
|
||||
}
|
||||
|
||||
void DRMMaster::DestroyInstance() {
|
||||
lock_guard<mutex> obj(s_lock);
|
||||
delete s_instance;
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
struct drm_mode_fb_cmd2 cmd2 {};
|
||||
cmd2.width = drm_buffer.width;
|
||||
cmd2.height = drm_buffer.height;
|
||||
cmd2.pixel_format = drm_buffer.drm_format;
|
||||
cmd2.flags = DRM_MODE_FB_MODIFIERS;
|
||||
fill(begin(cmd2.handles), begin(cmd2.handles) + drm_buffer.num_planes, *gem_handle);
|
||||
copy(begin(drm_buffer.stride), end(drm_buffer.stride), begin(cmd2.pitches));
|
||||
copy(begin(drm_buffer.offset), end(drm_buffer.offset), begin(cmd2.offsets));
|
||||
fill(begin(cmd2.modifier), begin(cmd2.modifier) + drm_buffer.num_planes,
|
||||
drm_buffer.drm_format_modifier);
|
||||
|
||||
if ((ret = drmIoctl(dev_fd_, DRM_IOCTL_MODE_ADDFB2, &cmd2))) {
|
||||
DRM_LOGE("DRM_IOCTL_MODE_ADDFB2 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 ret1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
*fb_id = cmd2.fb_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DRMMaster::RemoveFbId(uint32_t gem_handle, uint32_t fb_id) {
|
||||
struct drm_gem_close gem_close = {};
|
||||
gem_close.handle = gem_handle;
|
||||
int ret = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close);
|
||||
if (ret) {
|
||||
DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", errno);
|
||||
}
|
||||
|
||||
#ifdef DRM_IOCTL_MSM_RMFB2
|
||||
ret = drmIoctl(dev_fd_, DRM_IOCTL_MSM_RMFB2, &fb_id);
|
||||
if (ret) {
|
||||
DRM_LOGE("drmIoctl::DRM_IOCTL_MSM_RMFB2 failed for fb_id %d with error %d", fb_id, errno);
|
||||
}
|
||||
#else
|
||||
ret = drmModeRmFB(dev_fd_, fb_id);
|
||||
if (ret) {
|
||||
DRM_LOGE("drmModeRmFB failed for fb_id %d with error %d", fb_id, ret);
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace drm_utils
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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);
|
||||
static void DestroyInstance();
|
||||
|
||||
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__
|
|
@ -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
|
|
@ -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__
|
Loading…
Add table
Add a link
Reference in a new issue