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 void *ColorManagerProxy::color_lib_ = NULL;
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 color_lib_ = ::dlopen(COLORMGR_LIBRARY_NAME, RTLD_NOW);
83 if (color_lib_) {
84 *(reinterpret_cast<void **>(&create_intf_)) = ::dlsym(color_lib_, CREATE_COLOR_INTERFACE_NAME);
85 *(reinterpret_cast<void **>(&destroy_intf_)) =
86 ::dlsym(color_lib_, DESTROY_COLOR_INTERFACE_NAME);
87 if (!create_intf_ || !destroy_intf_) {
88 DLOGW("Fail to retrieve = %s from %s", CREATE_COLOR_INTERFACE_NAME, COLORMGR_LIBRARY_NAME);
89 ::dlclose(color_lib_);
90 error = kErrorResources;
91 }
92 } else {
93 DLOGW("Fail to load = %s", COLORMGR_LIBRARY_NAME);
94 error = kErrorResources;
95 }
96
97 hw_res_info_ = hw_res_info;
98
99 return error;
100 }
101
Deinit()102 void ColorManagerProxy::Deinit() {
103 if (color_lib_)
104 ::dlclose(color_lib_);
105 }
106
ColorManagerProxy(DisplayType type,HWInterface * intf,const HWDisplayAttributes & attr,const HWPanelInfo & info)107 ColorManagerProxy::ColorManagerProxy(DisplayType type, HWInterface *intf,
108 const HWDisplayAttributes &attr,
109 const HWPanelInfo &info)
110 : device_type_(type), pp_hw_attributes_(), hw_intf_(intf), color_intf_(NULL), pp_features_() {}
111
CreateColorManagerProxy(DisplayType type,HWInterface * hw_intf,const HWDisplayAttributes & attribute,const HWPanelInfo & panel_info)112 ColorManagerProxy *ColorManagerProxy::CreateColorManagerProxy(DisplayType type,
113 HWInterface *hw_intf,
114 const HWDisplayAttributes &attribute,
115 const HWPanelInfo &panel_info) {
116 DisplayError error = kErrorNone;
117 PPFeatureVersion versions;
118
119 // check if all resources are available before invoking factory method from libsdm-color.so.
120 if (!color_lib_ || !create_intf_ || !destroy_intf_) {
121 DLOGW("Information for %s isn't available!", COLORMGR_LIBRARY_NAME);
122 return NULL;
123 }
124
125 ColorManagerProxy *color_manager_proxy =
126 new ColorManagerProxy(type, hw_intf, attribute, panel_info);
127 if (color_manager_proxy) {
128 // 1. need query post-processing feature version from HWInterface.
129 error = color_manager_proxy->hw_intf_->GetPPFeaturesVersion(&versions);
130 PPHWAttributes &hw_attr = color_manager_proxy->pp_hw_attributes_;
131 if (error != kErrorNone) {
132 DLOGW("Fail to get DSPP feature versions");
133 } else {
134 hw_attr.Set(hw_res_info_, panel_info, attribute, versions);
135 DLOGW("PAV2 version is versions = %d, version = %d ",
136 hw_attr.version.version[kGlobalColorFeaturePaV2],
137 versions.version[kGlobalColorFeaturePaV2]);
138 }
139
140 // 2. instantiate concrete ColorInterface from libsdm-color.so, pass all hardware info in.
141 error = create_intf_(COLOR_VERSION_TAG, color_manager_proxy->device_type_, hw_attr,
142 &color_manager_proxy->color_intf_);
143 if (error != kErrorNone) {
144 DLOGW("Unable to instantiate concrete ColorInterface from %s", COLORMGR_LIBRARY_NAME);
145 delete color_manager_proxy;
146 color_manager_proxy = NULL;
147 }
148 }
149
150 return color_manager_proxy;
151 }
152
~ColorManagerProxy()153 ColorManagerProxy::~ColorManagerProxy() {
154 if (destroy_intf_)
155 destroy_intf_(device_type_);
156 color_intf_ = NULL;
157 }
158
ColorSVCRequestRoute(const PPDisplayAPIPayload & in_payload,PPDisplayAPIPayload * out_payload,PPPendingParams * pending_action)159 DisplayError ColorManagerProxy::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
160 PPDisplayAPIPayload *out_payload,
161 PPPendingParams *pending_action) {
162 DisplayError ret = kErrorNone;
163
164 // On completion, dspp_features_ will be populated and mark dirty with all resolved dspp
165 // feature list with paramaters being transformed into target requirement.
166 ret = color_intf_->ColorSVCRequestRoute(in_payload, out_payload, &pp_features_, pending_action);
167
168 return ret;
169 }
170
ApplyDefaultDisplayMode(void)171 DisplayError ColorManagerProxy::ApplyDefaultDisplayMode(void) {
172 DisplayError ret = kErrorNone;
173
174 // On POR, will be invoked from prepare<> request once bootanimation is done.
175 ret = color_intf_->ApplyDefaultDisplayMode(&pp_features_);
176
177 return ret;
178 }
179
NeedsPartialUpdateDisable()180 bool ColorManagerProxy::NeedsPartialUpdateDisable() {
181 Locker &locker(pp_features_.GetLocker());
182 SCOPE_LOCK(locker);
183
184 return pp_features_.IsDirty();
185 }
186
Commit()187 DisplayError ColorManagerProxy::Commit() {
188 Locker &locker(pp_features_.GetLocker());
189 SCOPE_LOCK(locker);
190
191 DisplayError ret = kErrorNone;
192 if (pp_features_.IsDirty()) {
193 ret = hw_intf_->SetPPFeatures(&pp_features_);
194 }
195
196 return ret;
197 }
198
Set(const HWResourceInfo & hw_res,const HWPanelInfo & panel_info,const DisplayConfigVariableInfo & attr,const PPFeatureVersion & feature_ver)199 void PPHWAttributes::Set(const HWResourceInfo &hw_res,
200 const HWPanelInfo &panel_info,
201 const DisplayConfigVariableInfo &attr,
202 const PPFeatureVersion &feature_ver) {
203 HWResourceInfo &res = *this;
204 res = hw_res;
205 HWPanelInfo &panel = *this;
206 panel = panel_info;
207 DisplayConfigVariableInfo &attributes = *this;
208 attributes = attr;
209 version = feature_ver;
210 panel_max_brightness = panel_info.panel_max_brightness;
211
212 if (strlen(panel_info.panel_name)) {
213 snprintf(&panel_name[0], sizeof(panel_name), "%s", &panel_info.panel_name[0]);
214 char *tmp = panel_name;
215 while ((tmp = strstr(tmp, " ")) != NULL)
216 *tmp = '_';
217 if ((tmp = strstr(panel_name, "\n")) != NULL)
218 *tmp = '\0';
219 }
220 }
221
222 } // namespace sdm
223