sm8250-common: livedisplay: Say hello to PictureAdjustment ^.^
This commit is contained in:
@@ -14,39 +14,143 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define LOG_TAG "lineage.livedisplay@2.0-service.oneplus_kona"
|
||||
|
||||
#define SDM_DISP_LIB "libsdm-disp-apis.qti.so"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <binder/ProcessState.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include "DisplayModes.h"
|
||||
#include "PictureAdjustment.h"
|
||||
#include "SunlightEnhancement.h"
|
||||
|
||||
using android::OK;
|
||||
using android::sp;
|
||||
using android::status_t;
|
||||
using android::hardware::configureRpcThreadpool;
|
||||
using android::hardware::joinRpcThreadpool;
|
||||
|
||||
using ::vendor::lineage::livedisplay::V2_0::IDisplayModes;
|
||||
using ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment;
|
||||
using ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement;
|
||||
using ::vendor::lineage::livedisplay::V2_0::implementation::DisplayModes;
|
||||
using ::vendor::lineage::livedisplay::V2_0::implementation::PictureAdjustment;
|
||||
using ::vendor::lineage::livedisplay::V2_0::implementation::SunlightEnhancement;
|
||||
|
||||
int main() {
|
||||
android::sp<IDisplayModes> modesService = new DisplayModes();
|
||||
android::sp<ISunlightEnhancement> sreService = new SunlightEnhancement();
|
||||
// Vendor backend
|
||||
void* libHandle = nullptr;
|
||||
const char* libName = nullptr;
|
||||
int32_t (*disp_api_init)(uint64_t*, uint32_t) = nullptr;
|
||||
int32_t (*disp_api_deinit)(uint64_t, uint32_t) = nullptr;
|
||||
uint64_t cookie = 0;
|
||||
|
||||
android::hardware::configureRpcThreadpool(2, true /*callerWillJoin*/);
|
||||
// HIDL frontend
|
||||
sp<DisplayModes> dm;
|
||||
sp<PictureAdjustment> pa;
|
||||
sp<SunlightEnhancement> se;
|
||||
|
||||
if (modesService->registerAsService() != android::OK) {
|
||||
LOG(ERROR) << "Cannot register display modes HAL service.";
|
||||
return 1;
|
||||
status_t status = OK;
|
||||
|
||||
android::ProcessState::initWithDriver("/dev/binder");
|
||||
|
||||
LOG(INFO) << "LiveDisplay HAL service is starting.";
|
||||
|
||||
libHandle = dlopen(SDM_DISP_LIB, RTLD_NOW);
|
||||
if (libHandle == nullptr) {
|
||||
LOG(ERROR) << "Failed to load SDM display lib, exiting.";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
if (sreService->registerAsService() != android::OK) {
|
||||
LOG(ERROR) << "Cannot register sunlight enhancement HAL service.";
|
||||
return 1;
|
||||
disp_api_init =
|
||||
reinterpret_cast<int32_t (*)(uint64_t*, uint32_t)>(dlsym(libHandle, "disp_api_init"));
|
||||
if (disp_api_init == nullptr) {
|
||||
LOG(ERROR) << "Can not get disp_api_init from " << libName << " (" << dlerror() << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
LOG(INFO) << "LiveDisplay HAL service ready.";
|
||||
disp_api_deinit =
|
||||
reinterpret_cast<int32_t (*)(uint64_t, uint32_t)>(dlsym(libHandle, "disp_api_deinit"));
|
||||
if (disp_api_deinit == nullptr) {
|
||||
LOG(ERROR) << "Can not get disp_api_deinit from " << libName << " (" << dlerror() << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
android::hardware::joinRpcThreadpool();
|
||||
status = disp_api_init(&cookie, 0);
|
||||
if (status != OK) {
|
||||
LOG(ERROR) << "Can not initialize " << libName << " (" << status << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
LOG(ERROR) << "LiveDisplay HAL service failed to join thread pool.";
|
||||
dm = new DisplayModes();
|
||||
if (dm == nullptr) {
|
||||
LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayModes Iface, exiting.";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
pa = new PictureAdjustment(libHandle, cookie);
|
||||
if (pa == nullptr) {
|
||||
LOG(ERROR) << "Can not create an instance of LiveDisplay HAL PictureAdjustment Iface, "
|
||||
"exiting.";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
se = new SunlightEnhancement();
|
||||
if (se == nullptr) {
|
||||
LOG(ERROR) << "Can not create an instance of LiveDisplay HAL SunlightEnhancement Iface, "
|
||||
"exiting.";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
if (!pa->isSupported()) {
|
||||
// Backend isn't ready yet, so restart and try again
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||
|
||||
status = dm->registerAsService();
|
||||
if (status != OK) {
|
||||
LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface ("
|
||||
<< status << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
if (pa->isSupported()) {
|
||||
status = pa->registerAsService();
|
||||
if (status != OK) {
|
||||
LOG(ERROR) << "Could not register service for LiveDisplay HAL PictureAdjustment Iface ("
|
||||
<< status << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
status = se->registerAsService();
|
||||
if (status != OK) {
|
||||
LOG(ERROR) << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface ("
|
||||
<< status << ")";
|
||||
goto shutdown;
|
||||
}
|
||||
|
||||
LOG(INFO) << "LiveDisplay HAL service is ready.";
|
||||
joinRpcThreadpool();
|
||||
// Should not pass this line
|
||||
|
||||
shutdown:
|
||||
// Cleanup what we started
|
||||
if (disp_api_deinit != nullptr) {
|
||||
disp_api_deinit(cookie, 0);
|
||||
}
|
||||
|
||||
if (libHandle != nullptr) {
|
||||
dlclose(libHandle);
|
||||
}
|
||||
|
||||
// In normal operation, we don't expect the thread pool to shutdown
|
||||
LOG(ERROR) << "LiveDisplay HAL service is shutting down.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user