• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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", &degamma_lut_property_))
61     ALOGI("Failed to get &degamma_lut property");
62   if (drm_->GetCrtcProperty(*this, "DEGAMMA_LUT_SIZE", &degamma_lut_size_property_))
63     ALOGI("Failed to get &degamma_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(&degamma_lut_property_);
109   properties_.push_back(&degamma_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   if (!has_display(display))
173     displays_.push_back(display);
174 }
175 
can_bind(int display) const176 bool DrmCrtc::can_bind(int display) const {
177   if (displays_.size() == 0)
178     return true;
179   return has_display(display);
180 }
181 
active_property() const182 const DrmProperty &DrmCrtc::active_property() const {
183   return active_property_;
184 }
185 
mode_property() const186 const DrmProperty &DrmCrtc::mode_property() const {
187   return mode_property_;
188 }
189 
out_fence_ptr_property() const190 const DrmProperty &DrmCrtc::out_fence_ptr_property() const {
191   return out_fence_ptr_property_;
192 }
193 
cgc_lut_property() const194 const DrmProperty &DrmCrtc::cgc_lut_property() const {
195     return cgc_lut_property_;
196 }
197 
cgc_lut_fd_property() const198 const DrmProperty &DrmCrtc::cgc_lut_fd_property() const {
199     return cgc_lut_fd_property_;
200 }
201 
degamma_lut_property() const202 const DrmProperty &DrmCrtc::degamma_lut_property() const {
203     return degamma_lut_property_;
204 }
205 
degamma_lut_size_property() const206 const DrmProperty &DrmCrtc::degamma_lut_size_property() const {
207     return degamma_lut_size_property_;
208 }
209 
gamma_lut_property() const210 const DrmProperty &DrmCrtc::gamma_lut_property() const {
211     return gamma_lut_property_;
212 }
213 
gamma_lut_size_property() const214 const DrmProperty &DrmCrtc::gamma_lut_size_property() const {
215     return gamma_lut_size_property_;
216 }
217 
linear_matrix_property() const218 const DrmProperty &DrmCrtc::linear_matrix_property() const {
219     return linear_matrix_property_;
220 }
221 
gamma_matrix_property() const222 const DrmProperty &DrmCrtc::gamma_matrix_property() const {
223     return gamma_matrix_property_;
224 }
225 
partial_region_property() const226 const DrmProperty &DrmCrtc::partial_region_property() const {
227     return partial_region_property_;
228 }
229 
force_bpc_property() const230 const DrmProperty &DrmCrtc::force_bpc_property() const {
231     return force_bpc_property_;
232 }
233 
disp_dither_property() const234 const DrmProperty &DrmCrtc::disp_dither_property() const {
235     return disp_dither_property_;
236 }
237 
cgc_dither_property() const238 const DrmProperty &DrmCrtc::cgc_dither_property() const {
239     return cgc_dither_property_;
240 }
241 
adjusted_vblank_property()242 DrmProperty &DrmCrtc::adjusted_vblank_property() {
243     return adjusted_vblank_property_;
244 }
245 
ppc_property() const246 const DrmProperty &DrmCrtc::ppc_property() const {
247     return ppc_property_;
248 }
249 
max_disp_freq_property() const250 const DrmProperty &DrmCrtc::max_disp_freq_property() const {
251     return max_disp_freq_property_;
252 }
253 
dqe_enabled_property() const254 const DrmProperty &DrmCrtc::dqe_enabled_property() const {
255     return dqe_enabled_property_;
256 }
257 
color_mode_property() const258 const DrmProperty &DrmCrtc::color_mode_property() const {
259     return color_mode_property_;
260 }
261 
expected_present_time_property() const262 const DrmProperty &DrmCrtc::expected_present_time_property() const {
263     return expected_present_time_property_;
264 }
265 
266 /* Histogram Properties */
histogram_roi_property() const267 const DrmProperty &DrmCrtc::histogram_roi_property() const {
268     return histogram_roi_property_;
269 }
270 
histogram_weights_property() const271 const DrmProperty &DrmCrtc::histogram_weights_property() const {
272     return histogram_weights_property_;
273 }
274 
histogram_threshold_property() const275 const DrmProperty &DrmCrtc::histogram_threshold_property() const {
276     return histogram_threshold_property_;
277 }
278 
histogram_position_property() const279 const DrmProperty &DrmCrtc::histogram_position_property() const {
280     return histogram_position_property_;
281 }
282 
rcd_plane_id_property() const283 const DrmProperty &DrmCrtc::rcd_plane_id_property() const {
284     return rcd_plane_id_property_;
285 }
286 
287 /* Histogram Properties */
histogram_channel_property(uint8_t channelId) const288 const DrmProperty &DrmCrtc::histogram_channel_property(uint8_t channelId) const {
289     if (histogram_channels_max <= channelId) {
290         ALOGE("Invalid histogram channel number %u\n", channelId);
291         return histogram_channel_property_[0];
292     }
293     return histogram_channel_property_[channelId];
294 }
295 
296 }  // namespace android
297