From: SooChan Lim Date: Tue, 23 Jun 2020 06:45:57 +0000 (+0900) Subject: DSDisplayDeviceOutput: implement the output callback of the OutputTDM implements X-Git-Tag: accepted/tizen/unified/20200820.213435~333 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F241542%2F1;p=platform%2Fcore%2Fuifw%2Flibds.git DSDisplayDeviceOutput: implement the output callback of the OutputTDM implements There are five callback functions for the DeviceOuput. IDSDisplayDevice class has OutputAdded and OutputRemoved callbacks. virtual void registerCallbackOutputAdded(DSObject *slot, std::function func) = 0; virtual void registerCallbackOutputRemoved(DSObject *slot, std::function func) = 0; IDSDisplayDeviceOutput class has OutputConnected, OutputDisconnected and OutputResolutionSet callbacks. virtual void registerCallbackOutputConnected(DSObject *slot, std::function func) = 0; virtual void registerCallbackOutputDisconnected(DSObject *slot, std::function func) = 0; virtual void registerCallbackOutputResolutionSet(DSObject *slot, std::function func) = 0; DSDisplayDeviceTDMImpl and DSDisplayDeviceOutputTDMImpl override these functions and implement them. Change-Id: If76a02aa5348d5e1b5827960e86c2de55729792f --- diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp index 6032cc5..9941820 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.cpp @@ -5,6 +5,21 @@ namespace display_server { + +DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl() + : __toutput(nullptr), + __resolutionWidth(0), + __resolutionHeight(0), + __physicalMMWidth(0), + __physicalMMHeight(0), + __mode(nullptr), + __dpmsMode(IDSDisplayDeviceOutput::DPMS_OFF), + __displayDeviceHWC(nullptr) +{ + __initializeConnectorType(); + __updateConnectState(); +} + DSDisplayDeviceOutputTDMImpl::DSDisplayDeviceOutputTDMImpl(tdm_output *toutput) : __toutput(toutput), __resolutionWidth(0), @@ -234,4 +249,34 @@ void DSDisplayDeviceOutputTDMImpl::__updateAvailableModeList() } } +void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputConnected(DSObject *slot, std::function func) +{ + this->__connectedSignal.connect(slot, func); +} + +void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputDisconnected(DSObject *slot, std::function func) +{ + this->__disconnectedSignal.connect(slot, func); +} + +void DSDisplayDeviceOutputTDMImpl::registerCallbackOutputResolutionSet(DSObject *slot, std::function func) +{ + this->__resolutionSetSignal.connect(slot, func); +} + +void DSDisplayDeviceOutputTDMImpl::callCallbackOutputConnected() +{ + this->__connectedSignal.emit(this); +} + +void DSDisplayDeviceOutputTDMImpl::callCallbackOutputDisconnected() +{ + this->__disconnectedSignal.emit(this); +} + +void DSDisplayDeviceOutputTDMImpl::callCallbackOutputResolutionSet() +{ + this->__resolutionSetSignal.emit(this); +} + } // namespace display_server diff --git a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h index ba3041a..82dba0d 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h +++ b/src/DSDisplayDevice/DSDisplayDeviceOutputTDMImpl.h @@ -3,6 +3,7 @@ #include "IDSDisplayDeviceOutput.h" #include "IDSDisplayDeviceHWC.h" +#include "DSSignal.h" #include namespace display_server @@ -10,6 +11,7 @@ namespace display_server class DSDisplayDeviceOutputTDMImpl : public IDSDisplayDeviceOutput { public: + DSDisplayDeviceOutputTDMImpl(); DSDisplayDeviceOutputTDMImpl(tdm_output *toutput); ~DSDisplayDeviceOutputTDMImpl(); @@ -26,12 +28,16 @@ public: DPMSMode getDPMSMode() override; IDSDisplayDeviceHWC *getHWC() override; - //TODO: int CallbackOutputAdded() override; - //TODO: int CallbackOutputRemoved() override; - //TODO: int CallbackOutputConnected() override; - //TODO: int CallbackOutputDisconnected() override; - //TODO: int CallbackOutputResolutionSet() override; - //TODO: int CallbackOutputVBlankTriggered() override; + // register callback functions + void registerCallbackOutputConnected(DSObject *slot, std::function func) override; + void registerCallbackOutputDisconnected(DSObject *slot, std::function func) override; + void registerCallbackOutputResolutionSet(DSObject *slot, std::function func) override; + + // emit functions + void callCallbackOutputConnected(); + void callCallbackOutputDisconnected(); + void callCallbackOutputResolutionSet(); + private: void __initializeConnectorType(); void __updateConnectState(); @@ -50,6 +56,11 @@ private: IDSDisplayDeviceOutput::DPMSMode __dpmsMode; IDSDisplayDeviceHWC *__displayDeviceHWC; + + // signals + DSSignal __connectedSignal; + DSSignal __disconnectedSignal; + DSSignal __resolutionSetSignal; }; } diff --git a/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp b/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp index f79af90..66e35e5 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp +++ b/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.cpp @@ -41,9 +41,34 @@ std::list DSDisplayDeviceTDMImpl::getOutputList() } deviceOutput = new DSDisplayDeviceOutputTDMImpl(toutput); __outputList.emplace_back(deviceOutput); + + // emit the output added signal + this->__outputAddedSignal.emit(deviceOutput); } return __outputList; } +void DSDisplayDeviceTDMImpl::registerCallbackOutputAdded(DSObject *slot, std::function func) +{ + this->__outputAddedSignal.connect(slot, func); +} + +void DSDisplayDeviceTDMImpl::registerCallbackOutputRemoved(DSObject *slot, std::function func) +{ + this->__outputRemovedSignal.connect(slot, func); +} + +void DSDisplayDeviceTDMImpl::callCallbackOutputAdded() +{ + //TODO: create the new IDSDisplayDeviceOutput instance and put the parameter of the emit function. + this->__outputAddedSignal.emit(nullptr); +} + +void DSDisplayDeviceTDMImpl::callCallbackOutputRemoved() +{ + //TODO: create the new IDSDisplayDeviceOutput instance and put the parameter of the emit function. + this->__outputRemovedSignal.emit(nullptr); +} + } // namespace display_server diff --git a/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.h b/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.h index 8585152..013d1e4 100644 --- a/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.h +++ b/src/DSDisplayDevice/DSDisplayDeviceTDMImpl.h @@ -2,6 +2,7 @@ #define _DS_DISPLAY_DEVICE_TDM_IMPL_H_ #include "IDSDisplayDevice.h" +#include "DSSignal.h" #include namespace display_server @@ -14,10 +15,22 @@ public: std::list getOutputList() override; + // register callback functions + void registerCallbackOutputAdded(DSObject *slot, std::function func) override; + void registerCallbackOutputRemoved(DSObject *slot, std::function func) override; + + // emit functions + void callCallbackOutputAdded(); + void callCallbackOutputRemoved(); + private: tdm_display *__tdisplay; int __numOutputs; std::list __outputList; + + // signals + DSSignal __outputAddedSignal; + DSSignal __outputRemovedSignal; }; } diff --git a/src/DSDisplayDevice/IDSDisplayDevice.h b/src/DSDisplayDevice/IDSDisplayDevice.h index cccc9f0..ea03a3e 100644 --- a/src/DSDisplayDevice/IDSDisplayDevice.h +++ b/src/DSDisplayDevice/IDSDisplayDevice.h @@ -1,17 +1,20 @@ #ifndef _I_DS_DISPLAY_DEVICE_H_ #define _I_DS_DISPLAY_DEVICE_H_ +#include "DSObject.h" +#include "IDSDisplayDeviceOutput.h" #include -#include namespace display_server { -class IDSDisplayDevice +class IDSDisplayDevice : public DSObject { public: virtual ~IDSDisplayDevice() = default; virtual std::list getOutputList() = 0; + virtual void registerCallbackOutputAdded(DSObject *slot, std::function func) = 0; + virtual void registerCallbackOutputRemoved(DSObject *slot, std::function func) = 0; }; } diff --git a/src/DSDisplayDevice/IDSDisplayDeviceOutput.h b/src/DSDisplayDevice/IDSDisplayDeviceOutput.h index 4492c1a..9f0df9f 100644 --- a/src/DSDisplayDevice/IDSDisplayDeviceOutput.h +++ b/src/DSDisplayDevice/IDSDisplayDeviceOutput.h @@ -1,9 +1,11 @@ #ifndef _I_DS_DISPLAY_DEVICE_OUTPUT_H_ #define _I_DS_DISPLAY_DEVICE_OUTPUT_H_ +#include "DSObject.h" +#include "IDSDisplayDeviceHWC.h" #include #include -#include "IDSDisplayDeviceHWC.h" +#include #define NAME_LEN 64 @@ -21,7 +23,7 @@ typedef struct _DSDisplayDeviceOutputMode { const void *private_mode; } DSDisplayDeviceOutputMode; -class IDSDisplayDeviceOutput +class IDSDisplayDeviceOutput : public DSObject { public: enum ConnectState { @@ -73,12 +75,10 @@ public: virtual DPMSMode getDPMSMode() = 0; virtual IDSDisplayDeviceHWC *getHWC() = 0; - //TODO: virtual int CallbackOutputAdded() = 0; - //TODO: virtual int CallbackOutputRemoved() = 0; - //TODO: virtual int CallbackOutputConnected() = 0; - //TODO: virtual int CallbackOutputDisconnected() = 0; - //TODO: virtual int CallbackOutputResolutionSet() = 0; - //TODO: virtual int CallbackOutputVBlankTriggered() = 0; + // Callback methods + virtual void registerCallbackOutputConnected(DSObject *slot, std::function func) = 0; + virtual void registerCallbackOutputDisconnected(DSObject *slot, std::function func) = 0; + virtual void registerCallbackOutputResolutionSet(DSObject *slot, std::function func) = 0; }; } diff --git a/tests/DSDisplayDeviceTDMImpl-test.cpp b/tests/DSDisplayDeviceTDMImpl-test.cpp index 286282a..4255d9d 100644 --- a/tests/DSDisplayDeviceTDMImpl-test.cpp +++ b/tests/DSDisplayDeviceTDMImpl-test.cpp @@ -1,5 +1,6 @@ #include "libds-tests.h" #include "DSDisplayDeviceTDMImpl.h" +#include "DSDisplayDeviceOutputTDMImpl.h" using namespace display_server; @@ -18,6 +19,27 @@ public: }; // DSDisplayDeviceTDMImpl +class MockDisplayDevice : public DSObject +{ +public: + MockDisplayDevice() + : flagOutputAdded(false), + flagOutputRemoved(false) + {} + ~MockDisplayDevice() + {} + + void outputAdded(IDSDisplayDeviceOutput *output) { + flagOutputAdded = true; + } + + void outputRemoved(IDSDisplayDeviceOutput *output) { + flagOutputRemoved = true; + } + + bool flagOutputAdded; + bool flagOutputRemoved; +}; TEST_F(DSDisplayDeviceTDMImplTest, Device_New) { @@ -36,6 +58,29 @@ TEST_F(DSDisplayDeviceTDMImplTest, Device_getOutputList) delete dispayDevice; } +TEST_F(DSDisplayDeviceTDMImplTest, Device_OutputAdded) +{ + std::shared_ptr mockDisplayDevice = std::make_shared(); + std::unique_ptr displayDevice = std::make_unique(); + + displayDevice->registerCallbackOutputAdded(mockDisplayDevice.get(), std::bind(&MockDisplayDevice::outputAdded, mockDisplayDevice, std::placeholders::_1)); + displayDevice->callCallbackOutputAdded(); + + EXPECT_TRUE(mockDisplayDevice->flagOutputAdded); +} + +TEST_F(DSDisplayDeviceTDMImplTest, Device_OutputRemoved) +{ + //MockDisplayDevice *mockDisplayDevice = new MockDisplayDevice; + std::shared_ptr mockDisplayDevice = std::make_shared(); + std::unique_ptr displayDevice = std::make_unique(); + + displayDevice->registerCallbackOutputRemoved(mockDisplayDevice.get(), std::bind(&MockDisplayDevice::outputRemoved, mockDisplayDevice, std::placeholders::_1)); + displayDevice->callCallbackOutputRemoved(); + + EXPECT_TRUE(mockDisplayDevice->flagOutputRemoved); +} + // DSDisplayDeviceTDMOutputImpl TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_getInitialValues) @@ -115,6 +160,66 @@ TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_setModeBestResolution) delete dispayDevice; } +class MockDisplayDeviceOutput : public DSObject +{ +public: + MockDisplayDeviceOutput() + : flagOutputConnected(false), + flagOutputDisconnected(false), + flagOutputResolutionSet(false) + {} + ~MockDisplayDeviceOutput() = default; + + void outputConnected(IDSDisplayDeviceOutput *deviceOuptut) { + flagOutputConnected = true; + } + + void outputDisconnected(IDSDisplayDeviceOutput *deviceOuptut) { + flagOutputDisconnected = true; + } + + void outputResolutionSet(IDSDisplayDeviceOutput *deviceOuptut) { + flagOutputResolutionSet = true; + } + + bool flagOutputConnected; + bool flagOutputDisconnected; + bool flagOutputResolutionSet; +}; + +TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputConnected) +{ + std::shared_ptr mockDisplayDeviceOutput = std::make_shared(); + std::unique_ptr displayDeviceOutput = std::make_unique(); + + displayDeviceOutput->registerCallbackOutputConnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputConnected, mockDisplayDeviceOutput, std::placeholders::_1)); + displayDeviceOutput->callCallbackOutputConnected(); + + EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputConnected); +} + +TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputDisconnected) +{ + std::shared_ptr mockDisplayDeviceOutput = std::make_shared(); + std::unique_ptr displayDeviceOutput = std::make_unique(); + + displayDeviceOutput->registerCallbackOutputDisconnected(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputDisconnected, mockDisplayDeviceOutput, std::placeholders::_1)); + displayDeviceOutput->callCallbackOutputDisconnected(); + + EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputDisconnected); +} + +TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_registerCallbackOutputResolutionSet) +{ + std::shared_ptr mockDisplayDeviceOutput = std::make_shared(); + std::unique_ptr displayDeviceOutput = std::make_unique(); + + displayDeviceOutput->registerCallbackOutputResolutionSet(mockDisplayDeviceOutput.get(), std::bind(&MockDisplayDeviceOutput::outputResolutionSet, mockDisplayDeviceOutput, std::placeholders::_1)); + displayDeviceOutput->callCallbackOutputResolutionSet(); + + EXPECT_TRUE(mockDisplayDeviceOutput->flagOutputResolutionSet); +} + // DSDisplayDeviceTDMHWC TEST_F(DSDisplayDeviceTDMImplTest, DeviceOutput_createHWCWindow)