1 /* Copyright (c) 2015 - 2016, The Linux Foundataion. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 #include <dlfcn.h>
31 #include <private/color_interface.h>
32 #include <utils/constants.h>
33 #include <utils/debug.h>
34 #include "color_manager.h"
35
36 #define __CLASS__ "ColorManager"
37
38 namespace sdm {
39
40 DynLib ColorManagerProxy::color_lib_;
41 CreateColorInterface ColorManagerProxy::create_intf_ = NULL;
42 DestroyColorInterface ColorManagerProxy::destroy_intf_ = NULL;
43 HWResourceInfo ColorManagerProxy::hw_res_info_;
44
45 // Below two functions are part of concrete implementation for SDM core private
46 // color_params.h
Reset()47 void PPFeaturesConfig::Reset() {
48 for (int i = 0; i < kMaxNumPPFeatures; i++) {
49 if (feature_[i]) {
50 delete feature_[i];
51 feature_[i] = NULL;
52 }
53 }
54 dirty_ = false;
55 next_idx_ = 0;
56 }
57
RetrieveNextFeature(PPFeatureInfo ** feature)58 DisplayError PPFeaturesConfig::RetrieveNextFeature(PPFeatureInfo **feature) {
59 DisplayError ret = kErrorNone;
60 uint32_t i(0);
61
62 for (i = next_idx_; i < kMaxNumPPFeatures; i++) {
63 if (feature_[i]) {
64 *feature = feature_[i];
65 next_idx_ = i + 1;
66 break;
67 }
68 }
69
70 if (i == kMaxNumPPFeatures) {
71 ret = kErrorParameters;
72 next_idx_ = 0;
73 }
74
75 return ret;
76 }
77
Init(const HWResourceInfo & hw_res_info)78 DisplayError ColorManagerProxy::Init(const HWResourceInfo &hw_res_info) {
79 DisplayError error = kErrorNone;
80
81 // Load color service library and retrieve its entry points.
82 if (color_lib_.Open(COLORMGR_LIBRARY_NAME)) {
83 if (!color_lib_.Sym(CREATE_COLOR_INTERFACE_NAME, reinterpret_cast<void **>(&create_intf_)) ||
84 !color_lib_.Sym(DESTROY_COLOR_INTERFACE_NAME, reinterpret_cast<void **>(&destroy_intf_))) {
85 DLOGW("Fail to retrieve = %s from %s", CREATE_COLOR_INTERFACE_NAME, COLORMGR_LIBRARY_NAME);
86 error = kErrorResources;
87 }
88 } else {
89 DLOGW("Fail to load = %s", COLORMGR_LIBRARY_NAME);
90 error = kErrorResources;
91 }
92
93 hw_res_info_ = hw_res_info;
94
95 return error;
96 }
97
Deinit()98 void ColorManagerProxy::Deinit() {
99 color_lib_.~DynLib();
100 }
101
ColorManagerProxy(DisplayType type,HWInterface * intf,const HWDisplayAttributes & attr,const HWPanelInfo & info)102 ColorManagerProxy::ColorManagerProxy(DisplayType type, HWInterface *intf,
103 const HWDisplayAttributes &attr,
104 const HWPanelInfo &info)
105 : device_type_(type), pp_hw_attributes_(), hw_intf_(intf), color_intf_(NULL), pp_features_() {}
106
CreateColorManagerProxy(DisplayType type,HWInterface * hw_intf,const HWDisplayAttributes & attribute,const HWPanelInfo & panel_info)107 ColorManagerProxy *ColorManagerProxy::CreateColorManagerProxy(DisplayType type,
108 HWInterface *hw_intf,
109 const HWDisplayAttributes &attribute,
110 const HWPanelInfo &panel_info) {
111 DisplayError error = kErrorNone;
112 PPFeatureVersion versions;
113
114 // check if all resources are available before invoking factory method from libsdm-color.so.
115 if (!color_lib_ || !create_intf_ || !destroy_intf_) {
116 DLOGW("Information for %s isn't available!", COLORMGR_LIBRARY_NAME);
117 return NULL;
118 }
119
120 ColorManagerProxy *color_manager_proxy =
121 new ColorManagerProxy(type, hw_intf, attribute, panel_info);
122 if (color_manager_proxy) {
123 // 1. need query post-processing feature version from HWInterface.
124 error = color_manager_proxy->hw_intf_->GetPPFeaturesVersion(&versions);
125 PPHWAttributes &hw_attr = color_manager_proxy->pp_hw_attributes_;
126 if (error != kErrorNone) {
127 DLOGW("Fail to get DSPP feature versions");
128 } else {
129 hw_attr.Set(hw_res_info_, panel_info, attribute, versions);
130 DLOGW("PAV2 version is versions = %d, version = %d ",
131 hw_attr.version.version[kGlobalColorFeaturePaV2],
132 versions.version[kGlobalColorFeaturePaV2]);
133 }
134
135 // 2. instantiate concrete ColorInterface from libsdm-color.so, pass all hardware info in.
136 error = create_intf_(COLOR_VERSION_TAG, color_manager_proxy->device_type_, hw_attr,
137 &color_manager_proxy->color_intf_);
138 if (error != kErrorNone) {
139 DLOGW("Unable to instantiate concrete ColorInterface from %s", COLORMGR_LIBRARY_NAME);
140 delete color_manager_proxy;
141 color_manager_proxy = NULL;
142 }
143 }
144
145 return color_manager_proxy;
146 }
147
~ColorManagerProxy()148 ColorManagerProxy::~ColorManagerProxy() {
149 if (destroy_intf_)
150 destroy_intf_(device_type_);
151 color_intf_ = NULL;
152 }
153
ColorSVCRequestRoute(const PPDisplayAPIPayload & in_payload,PPDisplayAPIPayload * out_payload,PPPendingParams * pending_action)154 DisplayError ColorManagerProxy::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
155 PPDisplayAPIPayload *out_payload,
156 PPPendingParams *pending_action) {
157 DisplayError ret = kErrorNone;
158
159 // On completion, dspp_features_ will be populated and mark dirty with all resolved dspp
160 // feature list with paramaters being transformed into target requirement.
161 ret = color_intf_->ColorSVCRequestRoute(in_payload, out_payload, &pp_features_, pending_action);
162
163 return ret;
164 }
165
ApplyDefaultDisplayMode(void)166 DisplayError ColorManagerProxy::ApplyDefaultDisplayMode(void) {
167 DisplayError ret = kErrorNone;
168
169 // On POR, will be invoked from prepare<> request once bootanimation is done.
170 ret = color_intf_->ApplyDefaultDisplayMode(&pp_features_);
171
172 return ret;
173 }
174
NeedsPartialUpdateDisable()175 bool ColorManagerProxy::NeedsPartialUpdateDisable() {
176 Locker &locker(pp_features_.GetLocker());
177 SCOPE_LOCK(locker);
178
179 return pp_features_.IsDirty();
180 }
181
Commit()182 DisplayError ColorManagerProxy::Commit() {
183 Locker &locker(pp_features_.GetLocker());
184 SCOPE_LOCK(locker);
185
186 DisplayError ret = kErrorNone;
187 if (pp_features_.IsDirty()) {
188 ret = hw_intf_->SetPPFeatures(&pp_features_);
189 }
190
191 return ret;
192 }
193
Set(const HWResourceInfo & hw_res,const HWPanelInfo & panel_info,const DisplayConfigVariableInfo & attr,const PPFeatureVersion & feature_ver)194 void PPHWAttributes::Set(const HWResourceInfo &hw_res,
195 const HWPanelInfo &panel_info,
196 const DisplayConfigVariableInfo &attr,
197 const PPFeatureVersion &feature_ver) {
198 HWResourceInfo &res = *this;
199 res = hw_res;
200 HWPanelInfo &panel = *this;
201 panel = panel_info;
202 DisplayConfigVariableInfo &attributes = *this;
203 attributes = attr;
204 version = feature_ver;
205 panel_max_brightness = panel_info.panel_max_brightness;
206
207 if (strlen(panel_info.panel_name)) {
208 snprintf(&panel_name[0], sizeof(panel_name), "%s", &panel_info.panel_name[0]);
209 char *tmp = panel_name;
210 while ((tmp = strstr(tmp, " ")) != NULL)
211 *tmp = '_';
212 if ((tmp = strstr(panel_name, "\n")) != NULL)
213 *tmp = '\0';
214 }
215 }
216
ColorMgrGetNumOfModes(uint32_t * mode_cnt)217 DisplayError ColorManagerProxy::ColorMgrGetNumOfModes(uint32_t *mode_cnt) {
218 return color_intf_->ColorIntfGetNumDisplayModes(&pp_features_, 0, mode_cnt);
219 }
220
ColorMgrGetModes(uint32_t * mode_cnt,SDEDisplayMode * modes)221 DisplayError ColorManagerProxy::ColorMgrGetModes(uint32_t *mode_cnt,
222 SDEDisplayMode *modes) {
223 return color_intf_->ColorIntfEnumerateDisplayModes(&pp_features_, 0, modes, mode_cnt);
224 }
225
ColorMgrSetMode(int32_t color_mode_id)226 DisplayError ColorManagerProxy::ColorMgrSetMode(int32_t color_mode_id) {
227 return color_intf_->ColorIntfSetDisplayMode(&pp_features_, 0, color_mode_id);
228 }
229
ColorMgrSetColorTransform(uint32_t length,const double * trans_data)230 DisplayError ColorManagerProxy::ColorMgrSetColorTransform(uint32_t length,
231 const double *trans_data) {
232 return color_intf_->ColorIntfSetColorTransform(&pp_features_, 0, length, trans_data);
233 }
234
235 } // namespace sdm
236