1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ExynosDeviceModule.h"
18 
19 #include "ExynosDisplayDrmInterfaceModule.h"
20 #include "ExynosExternalDisplayModule.h"
21 #include "ExynosPrimaryDisplayModule.h"
22 
23 extern struct exynos_hwc_control exynosHWCControl;
24 
25 using namespace gs101;
26 
ExynosDeviceModule(bool isVrrApiSupported)27 ExynosDeviceModule::ExynosDeviceModule(bool isVrrApiSupported)
28       : ExynosDevice(isVrrApiSupported), mDisplayColorLoader(DISPLAY_COLOR_LIB) {
29     exynosHWCControl.skipStaticLayers = false;
30 
31     std::vector<displaycolor::DisplayInfo> display_info;
32     for (uint32_t i = 0; i < mDisplays.size(); i++) {
33         ExynosDisplay* display = mDisplays[i];
34         if (display->mType == HWC_DISPLAY_PRIMARY || display->mType == HWC_DISPLAY_EXTERNAL) {
35             ExynosDisplayDrmInterfaceModule* moduleDisplayInterface =
36                     (ExynosDisplayDrmInterfaceModule*)(display->mDisplayInterface.get());
37             moduleDisplayInterface->getDisplayInfo(display_info);
38         }
39     }
40     initDisplayColor(display_info);
41     for (uint32_t i = 0; i < mDisplays.size(); i++) {
42         ExynosDisplay* display = mDisplays[i];
43         if (display->mType == HWC_DISPLAY_PRIMARY) {
44             ExynosPrimaryDisplayModule* modulePrimaryDisplay = (ExynosPrimaryDisplayModule*)display;
45             modulePrimaryDisplay->updateBrightnessTable();
46         }
47     }
48 }
49 
~ExynosDeviceModule()50 ExynosDeviceModule::~ExynosDeviceModule() {
51 }
52 
initDisplayColor(const std::vector<displaycolor::DisplayInfo> & display_info)53 int ExynosDeviceModule::initDisplayColor(
54         const std::vector<displaycolor::DisplayInfo>& display_info) {
55     mDisplayColorInterface = mDisplayColorLoader.GetDisplayColor(display_info);
56     if (mDisplayColorInterface == nullptr) {
57         ALOGW("%s failed to load displaycolor", __func__);
58     }
59 
60     return NO_ERROR;
61 }
62 
getDisplayColorManager(ExynosDisplay * display)63 ColorManager* ExynosDeviceModule::getDisplayColorManager(ExynosDisplay* display) {
64     if (display->mType == HWC_DISPLAY_PRIMARY) {
65         ExynosPrimaryDisplayModule* primaryDisplay =
66                 static_cast<ExynosPrimaryDisplayModule*>(display);
67         return primaryDisplay->getColorManager();
68     } else if (display->mType == HWC_DISPLAY_EXTERNAL) {
69         ExynosExternalDisplayModule* externaDisplay =
70                 static_cast<ExynosExternalDisplayModule*>(display);
71         return externaDisplay->getColorManager();
72     }
73     ALOGW("%s: no color manager for display->mType=%d", __func__, display->mType);
74     return nullptr;
75 }
76