1 /*
2 * Copyright (C) 2015 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 #define LOG_TAG "hwc-drm-crtc"
18
19 #include "drmcrtc.h"
20 #include "drmdevice.h"
21
22 #include <stdint.h>
23 #include <xf86drmMode.h>
24
25 #include <log/log.h>
26
27 namespace android {
28
DrmCrtc(DrmDevice * drm,drmModeCrtcPtr c,unsigned pipe)29 DrmCrtc::DrmCrtc(DrmDevice *drm, drmModeCrtcPtr c, unsigned pipe)
30 : drm_(drm), id_(c->crtc_id), pipe_(pipe), mode_(&c->mode) {
31 displays_.clear();
32 }
33
Init()34 int DrmCrtc::Init() {
35 int ret = drm_->GetCrtcProperty(*this, "ACTIVE", &active_property_);
36 if (ret) {
37 ALOGE("Failed to get ACTIVE property");
38 return ret;
39 }
40
41 ret = drm_->GetCrtcProperty(*this, "MODE_ID", &mode_property_);
42 if (ret) {
43 ALOGE("Failed to get MODE_ID property");
44 return ret;
45 }
46
47 ret = drm_->GetCrtcProperty(*this, "OUT_FENCE_PTR", &out_fence_ptr_property_);
48 if (ret) {
49 ALOGE("Failed to get OUT_FENCE_PTR property");
50 return ret;
51 }
52
53 if (drm_->GetCrtcProperty(*this, "partial_region", &partial_region_property_))
54 ALOGI("Failed to get &partial_region_property");
55
56 if (drm_->GetCrtcProperty(*this, "cgc_lut", &cgc_lut_property_))
57 ALOGI("Failed to get cgc_lut property");
58 if (drm_->GetCrtcProperty(*this, "cgc_lut_fd", &cgc_lut_fd_property_))
59 ALOGI("Failed to get cgc_lut_fd property");
60 if (drm_->GetCrtcProperty(*this, "DEGAMMA_LUT", °amma_lut_property_))
61 ALOGI("Failed to get °amma_lut property");
62 if (drm_->GetCrtcProperty(*this, "DEGAMMA_LUT_SIZE", °amma_lut_size_property_))
63 ALOGI("Failed to get °amma_lut_size property");
64 if (drm_->GetCrtcProperty(*this, "GAMMA_LUT", &gamma_lut_property_))
65 ALOGI("Failed to get &gamma_lut property");
66 if (drm_->GetCrtcProperty(*this, "GAMMA_LUT_SIZE", &gamma_lut_size_property_))
67 ALOGI("Failed to get &gamma_lut_size property");
68 if (drm_->GetCrtcProperty(*this, "linear_matrix", &linear_matrix_property_))
69 ALOGI("Failed to get &linear_matrix property");
70 if (drm_->GetCrtcProperty(*this, "gamma_matrix", &gamma_matrix_property_))
71 ALOGI("Failed to get &gamma_matrix property");
72 if (drm_->GetCrtcProperty(*this, "force_bpc", &force_bpc_property_))
73 ALOGI("Failed to get &force_bpc_property_");
74 if (drm_->GetCrtcProperty(*this, "disp_dither", &disp_dither_property_))
75 ALOGI("Failed to get &disp_dither property");
76 if (drm_->GetCrtcProperty(*this, "cgc_dither", &cgc_dither_property_))
77 ALOGI("Failed to get &cgc_dither property");
78 if (drm_->GetCrtcProperty(*this, "adjusted_vblank", &adjusted_vblank_property_))
79 ALOGI("Failed to get &adjusted_vblank property");
80 if (drm_->GetCrtcProperty(*this, "ppc", &ppc_property_))
81 ALOGI("Failed to get &ppc property");
82 if (drm_->GetCrtcProperty(*this, "max_disp_freq", &max_disp_freq_property_))
83 ALOGI("Failed to get &max_disp_freq property");
84 if (drm_->GetCrtcProperty(*this, "dqe_enabled", &dqe_enabled_property_))
85 ALOGI("Failed to get &dqe_enabled_property property");
86 if (drm_->GetCrtcProperty(*this, "color mode", &color_mode_property_))
87 ALOGI("Failed to get color mode property");
88 if (drm_->GetCrtcProperty(*this, "expected_present_time", &expected_present_time_property_))
89 ALOGI("Failed to get expected_present_time property");
90 if (drm_->GetCrtcProperty(*this, "rcd_plane_id", &rcd_plane_id_property_))
91 ALOGI("Failed to get &rcd_plane_id property");
92
93 /* Histogram Properties */
94 if (drm_->GetCrtcProperty(*this, "histogram_roi", &histogram_roi_property_))
95 ALOGI("Failed to get &histogram_roi property");
96 if (drm_->GetCrtcProperty(*this, "histogram_weights", &histogram_weights_property_))
97 ALOGI("Failed to get &histogram_weights property");
98 if (drm_->GetCrtcProperty(*this, "histogram_threshold", &histogram_threshold_property_))
99 ALOGI("Failed to get &histogram_threshold property");
100 if (drm_->GetCrtcProperty(*this, "histogram_pos", &histogram_position_property_))
101 ALOGI("Failed to get &histogram_position property");
102
103 properties_.push_back(&active_property_);
104 properties_.push_back(&mode_property_);
105 properties_.push_back(&out_fence_ptr_property_);
106 properties_.push_back(&cgc_lut_property_);
107 properties_.push_back(&cgc_lut_fd_property_);
108 properties_.push_back(°amma_lut_property_);
109 properties_.push_back(°amma_lut_size_property_);
110 properties_.push_back(&gamma_lut_property_);
111 properties_.push_back(&gamma_lut_size_property_);
112 properties_.push_back(&linear_matrix_property_);
113 properties_.push_back(&gamma_matrix_property_);
114 properties_.push_back(&partial_region_property_);
115 properties_.push_back(&force_bpc_property_);
116 properties_.push_back(&disp_dither_property_);
117 properties_.push_back(&cgc_dither_property_);
118 properties_.push_back(&adjusted_vblank_property_);
119 properties_.push_back(&ppc_property_);
120 properties_.push_back(&max_disp_freq_property_);
121 properties_.push_back(&dqe_enabled_property_);
122 properties_.push_back(&color_mode_property_);
123 properties_.push_back(&expected_present_time_property_);
124 properties_.push_back(&rcd_plane_id_property_);
125
126 /* Histogram Properties */
127 properties_.push_back(&histogram_roi_property_);
128 properties_.push_back(&histogram_weights_property_);
129 properties_.push_back(&histogram_threshold_property_);
130 properties_.push_back(&histogram_position_property_);
131
132 /* Histogram Properties :: multichannel */
133 // TODO: b/295786065 - Get available channels from crtc property.
134 for (int i = 0; i < histogram_channels_max; i++) {
135 char pname[64];
136
137 sprintf(pname, "histogram_%d", i);
138 if (!drm_->GetCrtcProperty(*this, pname, &histogram_channel_property_[i])) {
139 ALOGD("histogram_channel #%d property found", i);
140 properties_.push_back(&histogram_channel_property_[i]);
141 } else {
142 ALOGD("histogram_channel #%d property not found, break", i);
143 break;
144 }
145 }
146 return 0;
147 }
148
id() const149 uint32_t DrmCrtc::id() const {
150 return id_;
151 }
152
pipe() const153 unsigned DrmCrtc::pipe() const {
154 return pipe_;
155 }
156
displays() const157 const std::vector<int>& DrmCrtc::displays() const {
158 return displays_;
159 }
160
has_display(int display) const161 bool DrmCrtc::has_display(int display) const {
162 auto it = find_if(displays_.begin(), displays_.end(),
163 [&display](auto disp) {
164 return (disp == display);
165 });
166 if (it != displays_.end())
167 return true;
168 return false;
169 }
170
set_display(int display)171 void DrmCrtc::set_display(int display) {
172 displays_.push_back(display);
173 }
174
can_bind(int display) const175 bool DrmCrtc::can_bind(int display) const {
176 if (displays_.size() == 0)
177 return true;
178 return has_display(display);
179 }
180
active_property() const181 const DrmProperty &DrmCrtc::active_property() const {
182 return active_property_;
183 }
184
mode_property() const185 const DrmProperty &DrmCrtc::mode_property() const {
186 return mode_property_;
187 }
188
out_fence_ptr_property() const189 const DrmProperty &DrmCrtc::out_fence_ptr_property() const {
190 return out_fence_ptr_property_;
191 }
192
cgc_lut_property() const193 const DrmProperty &DrmCrtc::cgc_lut_property() const {
194 return cgc_lut_property_;
195 }
196
cgc_lut_fd_property() const197 const DrmProperty &DrmCrtc::cgc_lut_fd_property() const {
198 return cgc_lut_fd_property_;
199 }
200
degamma_lut_property() const201 const DrmProperty &DrmCrtc::degamma_lut_property() const {
202 return degamma_lut_property_;
203 }
204
degamma_lut_size_property() const205 const DrmProperty &DrmCrtc::degamma_lut_size_property() const {
206 return degamma_lut_size_property_;
207 }
208
gamma_lut_property() const209 const DrmProperty &DrmCrtc::gamma_lut_property() const {
210 return gamma_lut_property_;
211 }
212
gamma_lut_size_property() const213 const DrmProperty &DrmCrtc::gamma_lut_size_property() const {
214 return gamma_lut_size_property_;
215 }
216
linear_matrix_property() const217 const DrmProperty &DrmCrtc::linear_matrix_property() const {
218 return linear_matrix_property_;
219 }
220
gamma_matrix_property() const221 const DrmProperty &DrmCrtc::gamma_matrix_property() const {
222 return gamma_matrix_property_;
223 }
224
partial_region_property() const225 const DrmProperty &DrmCrtc::partial_region_property() const {
226 return partial_region_property_;
227 }
228
force_bpc_property() const229 const DrmProperty &DrmCrtc::force_bpc_property() const {
230 return force_bpc_property_;
231 }
232
disp_dither_property() const233 const DrmProperty &DrmCrtc::disp_dither_property() const {
234 return disp_dither_property_;
235 }
236
cgc_dither_property() const237 const DrmProperty &DrmCrtc::cgc_dither_property() const {
238 return cgc_dither_property_;
239 }
240
adjusted_vblank_property()241 DrmProperty &DrmCrtc::adjusted_vblank_property() {
242 return adjusted_vblank_property_;
243 }
244
ppc_property() const245 const DrmProperty &DrmCrtc::ppc_property() const {
246 return ppc_property_;
247 }
248
max_disp_freq_property() const249 const DrmProperty &DrmCrtc::max_disp_freq_property() const {
250 return max_disp_freq_property_;
251 }
252
dqe_enabled_property() const253 const DrmProperty &DrmCrtc::dqe_enabled_property() const {
254 return dqe_enabled_property_;
255 }
256
color_mode_property() const257 const DrmProperty &DrmCrtc::color_mode_property() const {
258 return color_mode_property_;
259 }
260
expected_present_time_property() const261 const DrmProperty &DrmCrtc::expected_present_time_property() const {
262 return expected_present_time_property_;
263 }
264
265 /* Histogram Properties */
histogram_roi_property() const266 const DrmProperty &DrmCrtc::histogram_roi_property() const {
267 return histogram_roi_property_;
268 }
269
histogram_weights_property() const270 const DrmProperty &DrmCrtc::histogram_weights_property() const {
271 return histogram_weights_property_;
272 }
273
histogram_threshold_property() const274 const DrmProperty &DrmCrtc::histogram_threshold_property() const {
275 return histogram_threshold_property_;
276 }
277
histogram_position_property() const278 const DrmProperty &DrmCrtc::histogram_position_property() const {
279 return histogram_position_property_;
280 }
281
rcd_plane_id_property() const282 const DrmProperty &DrmCrtc::rcd_plane_id_property() const {
283 return rcd_plane_id_property_;
284 }
285
286 /* Histogram Properties */
histogram_channel_property(uint8_t channelId) const287 const DrmProperty &DrmCrtc::histogram_channel_property(uint8_t channelId) const {
288 if (histogram_channels_max <= channelId) {
289 ALOGE("Invalid histogram channel number %u\n", channelId);
290 return histogram_channel_property_[0];
291 }
292 return histogram_channel_property_[channelId];
293 }
294
295 } // namespace android
296