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, "DEGAMMA_LUT", °amma_lut_property_))
59 ALOGI("Failed to get °amma_lut property");
60 if (drm_->GetCrtcProperty(*this, "DEGAMMA_LUT_SIZE", °amma_lut_size_property_))
61 ALOGI("Failed to get °amma_lut_size property");
62 if (drm_->GetCrtcProperty(*this, "GAMMA_LUT", &gamma_lut_property_))
63 ALOGI("Failed to get &gamma_lut property");
64 if (drm_->GetCrtcProperty(*this, "GAMMA_LUT_SIZE", &gamma_lut_size_property_))
65 ALOGI("Failed to get &gamma_lut_size property");
66 if (drm_->GetCrtcProperty(*this, "linear_matrix", &linear_matrix_property_))
67 ALOGI("Failed to get &linear_matrix property");
68 if (drm_->GetCrtcProperty(*this, "gamma_matrix", &gamma_matrix_property_))
69 ALOGI("Failed to get &gamma_matrix property");
70 if (drm_->GetCrtcProperty(*this, "force_bpc", &force_bpc_property_))
71 ALOGI("Failed to get &force_bpc_property_");
72 if (drm_->GetCrtcProperty(*this, "disp_dither", &disp_dither_property_))
73 ALOGI("Failed to get &disp_dither property");
74 if (drm_->GetCrtcProperty(*this, "cgc_dither", &cgc_dither_property_))
75 ALOGI("Failed to get &cgc_dither property");
76 if (drm_->GetCrtcProperty(*this, "adjusted_vblank", &adjusted_vblank_property_))
77 ALOGI("Failed to get &adjusted_vblank property");
78 if (drm_->GetCrtcProperty(*this, "ppc", &ppc_property_))
79 ALOGI("Failed to get &ppc property");
80 if (drm_->GetCrtcProperty(*this, "max_disp_freq", &max_disp_freq_property_))
81 ALOGI("Failed to get &max_disp_freq property");
82 if (drm_->GetCrtcProperty(*this, "dqe_enabled", &dqe_enabled_property_))
83 ALOGI("Failed to get &dqe_enabled_property property");
84 if (drm_->GetCrtcProperty(*this, "color mode", &color_mode_property_))
85 ALOGI("Failed to get color mode property");
86
87 properties_.push_back(&active_property_);
88 properties_.push_back(&mode_property_);
89 properties_.push_back(&out_fence_ptr_property_);
90 properties_.push_back(&cgc_lut_property_);
91 properties_.push_back(°amma_lut_property_);
92 properties_.push_back(°amma_lut_size_property_);
93 properties_.push_back(&gamma_lut_property_);
94 properties_.push_back(&gamma_lut_size_property_);
95 properties_.push_back(&linear_matrix_property_);
96 properties_.push_back(&gamma_matrix_property_);
97 properties_.push_back(&partial_region_property_);
98 properties_.push_back(&force_bpc_property_);
99 properties_.push_back(&disp_dither_property_);
100 properties_.push_back(&cgc_dither_property_);
101 properties_.push_back(&adjusted_vblank_property_);
102 properties_.push_back(&ppc_property_);
103 properties_.push_back(&max_disp_freq_property_);
104 properties_.push_back(&dqe_enabled_property_);
105 properties_.push_back(&color_mode_property_);
106
107 return 0;
108 }
109
id() const110 uint32_t DrmCrtc::id() const {
111 return id_;
112 }
113
pipe() const114 unsigned DrmCrtc::pipe() const {
115 return pipe_;
116 }
117
displays() const118 const std::vector<int>& DrmCrtc::displays() const {
119 return displays_;
120 }
121
has_display(int display) const122 bool DrmCrtc::has_display(int display) const {
123 auto it = find_if(displays_.begin(), displays_.end(),
124 [&display](auto disp) {
125 return (disp == display);
126 });
127 if (it != displays_.end())
128 return true;
129 return false;
130 }
131
set_display(int display)132 void DrmCrtc::set_display(int display) {
133 displays_.push_back(display);
134 }
135
can_bind(int display) const136 bool DrmCrtc::can_bind(int display) const {
137 if (displays_.size() == 0)
138 return true;
139 return has_display(display);
140 }
141
active_property() const142 const DrmProperty &DrmCrtc::active_property() const {
143 return active_property_;
144 }
145
mode_property() const146 const DrmProperty &DrmCrtc::mode_property() const {
147 return mode_property_;
148 }
149
out_fence_ptr_property() const150 const DrmProperty &DrmCrtc::out_fence_ptr_property() const {
151 return out_fence_ptr_property_;
152 }
153
cgc_lut_property() const154 const DrmProperty &DrmCrtc::cgc_lut_property() const {
155 return cgc_lut_property_;
156 }
157
degamma_lut_property() const158 const DrmProperty &DrmCrtc::degamma_lut_property() const {
159 return degamma_lut_property_;
160 }
161
degamma_lut_size_property() const162 const DrmProperty &DrmCrtc::degamma_lut_size_property() const {
163 return degamma_lut_size_property_;
164 }
165
gamma_lut_property() const166 const DrmProperty &DrmCrtc::gamma_lut_property() const {
167 return gamma_lut_property_;
168 }
169
gamma_lut_size_property() const170 const DrmProperty &DrmCrtc::gamma_lut_size_property() const {
171 return gamma_lut_size_property_;
172 }
173
linear_matrix_property() const174 const DrmProperty &DrmCrtc::linear_matrix_property() const {
175 return linear_matrix_property_;
176 }
177
gamma_matrix_property() const178 const DrmProperty &DrmCrtc::gamma_matrix_property() const {
179 return gamma_matrix_property_;
180 }
181
partial_region_property() const182 const DrmProperty &DrmCrtc::partial_region_property() const {
183 return partial_region_property_;
184 }
185
force_bpc_property() const186 const DrmProperty &DrmCrtc::force_bpc_property() const {
187 return force_bpc_property_;
188 }
189
disp_dither_property() const190 const DrmProperty &DrmCrtc::disp_dither_property() const {
191 return disp_dither_property_;
192 }
193
cgc_dither_property() const194 const DrmProperty &DrmCrtc::cgc_dither_property() const {
195 return cgc_dither_property_;
196 }
197
adjusted_vblank_property()198 DrmProperty &DrmCrtc::adjusted_vblank_property() {
199 return adjusted_vblank_property_;
200 }
201
ppc_property() const202 const DrmProperty &DrmCrtc::ppc_property() const {
203 return ppc_property_;
204 }
205
max_disp_freq_property() const206 const DrmProperty &DrmCrtc::max_disp_freq_property() const {
207 return max_disp_freq_property_;
208 }
209
dqe_enabled_property() const210 const DrmProperty &DrmCrtc::dqe_enabled_property() const {
211 return dqe_enabled_property_;
212 }
213
color_mode_property() const214 const DrmProperty &DrmCrtc::color_mode_property() const {
215 return color_mode_property_;
216 }
217
218 } // namespace android
219