diff options
author | Tomi Valkeinen | 2017-11-22 02:05:53 -0600 |
---|---|---|
committer | Tomi Valkeinen | 2017-11-22 04:47:15 -0600 |
commit | a4724a1dae7a877ae7bb7082b068bbb12032ff63 (patch) | |
tree | ef3264139d2f48c39787d3f692a834da3f8581ea | |
parent | 448dec0fa7e398bff2152f5e01671353af03bc8c (diff) | |
download | external-kmsxx-a4724a1dae7a877ae7bb7082b068bbb12032ff63.tar.gz external-kmsxx-a4724a1dae7a877ae7bb7082b068bbb12032ff63.tar.xz external-kmsxx-a4724a1dae7a877ae7bb7082b068bbb12032ff63.zip |
kmstest: use resman
-rw-r--r-- | kms++util/inc/kms++util/resourcemanager.h | 2 | ||||
-rw-r--r-- | kms++util/src/resourcemanager.cpp | 26 | ||||
-rw-r--r-- | py/pykms/pykmsutil.cpp | 4 | ||||
-rw-r--r-- | utils/kmstest.cpp | 61 |
4 files changed, 50 insertions, 43 deletions
diff --git a/kms++util/inc/kms++util/resourcemanager.h b/kms++util/inc/kms++util/resourcemanager.h index b4a210d..002b4c9 100644 --- a/kms++util/inc/kms++util/resourcemanager.h +++ b/kms++util/inc/kms++util/resourcemanager.h | |||
@@ -15,7 +15,9 @@ public: | |||
15 | Connector* reserve_connector(const std::string& name = ""); | 15 | Connector* reserve_connector(const std::string& name = ""); |
16 | Connector* reserve_connector(Connector* conn); | 16 | Connector* reserve_connector(Connector* conn); |
17 | Crtc* reserve_crtc(Connector* conn); | 17 | Crtc* reserve_crtc(Connector* conn); |
18 | Crtc* reserve_crtc(Crtc* crtc); | ||
18 | Plane* reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format = PixelFormat::Undefined); | 19 | Plane* reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format = PixelFormat::Undefined); |
20 | Plane* reserve_plane(Plane* plane); | ||
19 | Plane* reserve_generic_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); | 21 | Plane* reserve_generic_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); |
20 | Plane* reserve_primary_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); | 22 | Plane* reserve_primary_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); |
21 | Plane* reserve_overlay_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); | 23 | Plane* reserve_overlay_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined); |
diff --git a/kms++util/src/resourcemanager.cpp b/kms++util/src/resourcemanager.cpp index c4bf7f8..465d817 100644 --- a/kms++util/src/resourcemanager.cpp +++ b/kms++util/src/resourcemanager.cpp | |||
@@ -132,6 +132,19 @@ Crtc* ResourceManager::reserve_crtc(Connector* conn) | |||
132 | return nullptr; | 132 | return nullptr; |
133 | } | 133 | } |
134 | 134 | ||
135 | Crtc* ResourceManager::reserve_crtc(Crtc* crtc) | ||
136 | { | ||
137 | if (!crtc) | ||
138 | return nullptr; | ||
139 | |||
140 | if (contains(m_reserved_crtcs, crtc)) | ||
141 | return nullptr; | ||
142 | |||
143 | m_reserved_crtcs.push_back(crtc); | ||
144 | |||
145 | return crtc; | ||
146 | } | ||
147 | |||
135 | Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format) | 148 | Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format) |
136 | { | 149 | { |
137 | if (!crtc) | 150 | if (!crtc) |
@@ -154,6 +167,19 @@ Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat fo | |||
154 | return nullptr; | 167 | return nullptr; |
155 | } | 168 | } |
156 | 169 | ||
170 | Plane* ResourceManager::reserve_plane(Plane* plane) | ||
171 | { | ||
172 | if (!plane) | ||
173 | return nullptr; | ||
174 | |||
175 | if (contains(m_reserved_planes, plane)) | ||
176 | return nullptr; | ||
177 | |||
178 | m_reserved_planes.push_back(plane); | ||
179 | |||
180 | return plane; | ||
181 | } | ||
182 | |||
157 | Plane* ResourceManager::reserve_generic_plane(Crtc* crtc, PixelFormat format) | 183 | Plane* ResourceManager::reserve_generic_plane(Crtc* crtc, PixelFormat format) |
158 | { | 184 | { |
159 | if (!crtc) | 185 | if (!crtc) |
diff --git a/py/pykms/pykmsutil.cpp b/py/pykms/pykmsutil.cpp index 10dee81..518d5ea 100644 --- a/py/pykms/pykmsutil.cpp +++ b/py/pykms/pykmsutil.cpp | |||
@@ -25,8 +25,8 @@ void init_pykmstest(py::module &m) | |||
25 | .def("reset", &ResourceManager::reset) | 25 | .def("reset", &ResourceManager::reset) |
26 | .def("reserve_connector", (Connector* (ResourceManager::*)(const string& name))&ResourceManager::reserve_connector, | 26 | .def("reserve_connector", (Connector* (ResourceManager::*)(const string& name))&ResourceManager::reserve_connector, |
27 | py::arg("name") = string()) | 27 | py::arg("name") = string()) |
28 | .def("reserve_crtc", &ResourceManager::reserve_crtc) | 28 | .def("reserve_crtc", (Crtc* (ResourceManager::*)(Connector*))&ResourceManager::reserve_crtc) |
29 | .def("reserve_plane", &ResourceManager::reserve_plane, | 29 | .def("reserve_plane", (Plane* (ResourceManager::*)(Crtc*, PlaneType, PixelFormat))&ResourceManager::reserve_plane, |
30 | py::arg("crtc"), | 30 | py::arg("crtc"), |
31 | py::arg("type"), | 31 | py::arg("type"), |
32 | py::arg("format") = PixelFormat::Undefined) | 32 | py::arg("format") = PixelFormat::Undefined) |
diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index 21309d6..fee3070 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp | |||
@@ -56,9 +56,6 @@ static bool s_cvt_v2; | |||
56 | static bool s_cvt_vid_opt; | 56 | static bool s_cvt_vid_opt; |
57 | static unsigned s_max_flips; | 57 | static unsigned s_max_flips; |
58 | 58 | ||
59 | static set<Crtc*> s_used_crtcs; | ||
60 | static set<Plane*> s_used_planes; | ||
61 | |||
62 | __attribute__ ((unused)) | 59 | __attribute__ ((unused)) |
63 | static void print_regex_match(smatch sm) | 60 | static void print_regex_match(smatch sm) |
64 | { | 61 | { |
@@ -82,28 +79,15 @@ static void get_connector(ResourceManager& resman, OutputInfo& output, const str | |||
82 | output.mode = output.connector->get_default_mode(); | 79 | output.mode = output.connector->get_default_mode(); |
83 | } | 80 | } |
84 | 81 | ||
85 | static void get_default_crtc(Card& card, OutputInfo& output) | 82 | static void get_default_crtc(ResourceManager& resman, OutputInfo& output) |
86 | { | 83 | { |
87 | Crtc* crtc = output.connector->get_current_crtc(); | 84 | output.crtc = resman.reserve_crtc(output.connector); |
88 | |||
89 | if (crtc && s_used_crtcs.find(crtc) == s_used_crtcs.end()) { | ||
90 | s_used_crtcs.insert(crtc); | ||
91 | output.crtc = crtc; | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | for (const auto& possible : output.connector->get_possible_crtcs()) { | ||
96 | if (s_used_crtcs.find(possible) == s_used_crtcs.end()) { | ||
97 | s_used_crtcs.insert(possible); | ||
98 | output.crtc = possible; | ||
99 | return; | ||
100 | } | ||
101 | } | ||
102 | 85 | ||
103 | EXIT("Could not find available crtc"); | 86 | if (!output.crtc) |
87 | EXIT("Could not find available crtc"); | ||
104 | } | 88 | } |
105 | 89 | ||
106 | static void parse_crtc(Card& card, const string& crtc_str, OutputInfo& output) | 90 | static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_str, OutputInfo& output) |
107 | { | 91 | { |
108 | // @12:1920x1200i@60 | 92 | // @12:1920x1200i@60 |
109 | // @12:33000000,800/210/30/16/-,480/22/13/10/-,i | 93 | // @12:33000000,800/210/30/16/-,480/22/13/10/-,i |
@@ -226,9 +210,12 @@ static void parse_crtc(Card& card, const string& crtc_str, OutputInfo& output) | |||
226 | } else { | 210 | } else { |
227 | EXIT("Failed to parse crtc option '%s'", crtc_str.c_str()); | 211 | EXIT("Failed to parse crtc option '%s'", crtc_str.c_str()); |
228 | } | 212 | } |
213 | |||
214 | if (!resman.reserve_crtc(output.crtc)) | ||
215 | EXIT("Could not find available crtc"); | ||
229 | } | 216 | } |
230 | 217 | ||
231 | static void parse_plane(Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo) | 218 | static void parse_plane(ResourceManager& resman, Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo) |
232 | { | 219 | { |
233 | // 3:400,400-400x400 | 220 | // 3:400,400-400x400 |
234 | const regex plane_re("(?:(@?)(\\d+):)?" // 3: | 221 | const regex plane_re("(?:(@?)(\\d+):)?" // 3: |
@@ -257,22 +244,14 @@ static void parse_plane(Card& card, const string& plane_str, const OutputInfo& o | |||
257 | 244 | ||
258 | pinfo.plane = planes[num]; | 245 | pinfo.plane = planes[num]; |
259 | } | 246 | } |
260 | } else { | ||
261 | for (Plane* p : output.crtc->get_possible_planes()) { | ||
262 | if (s_used_planes.find(p) != s_used_planes.end()) | ||
263 | continue; | ||
264 | |||
265 | if (p->plane_type() != PlaneType::Overlay) | ||
266 | continue; | ||
267 | 247 | ||
268 | pinfo.plane = p; | 248 | pinfo.plane = resman.reserve_plane(pinfo.plane); |
269 | } | 249 | } else { |
270 | 250 | pinfo.plane = resman.reserve_overlay_plane(output.crtc); | |
271 | if (!pinfo.plane) | ||
272 | EXIT("Failed to find available plane"); | ||
273 | } | 251 | } |
274 | 252 | ||
275 | s_used_planes.insert(pinfo.plane); | 253 | if (!pinfo.plane) |
254 | EXIT("Failed to find available plane"); | ||
276 | 255 | ||
277 | pinfo.w = stoul(sm[5]); | 256 | pinfo.w = stoul(sm[5]); |
278 | pinfo.h = stoul(sm[6]); | 257 | pinfo.h = stoul(sm[6]); |
@@ -540,7 +519,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, | |||
540 | if (!current_output->connector) | 519 | if (!current_output->connector) |
541 | get_connector(resman, *current_output); | 520 | get_connector(resman, *current_output); |
542 | 521 | ||
543 | parse_crtc(card, arg.arg, *current_output); | 522 | parse_crtc(resman, card, arg.arg, *current_output); |
544 | 523 | ||
545 | current_output->user_set_crtc = true; | 524 | current_output->user_set_crtc = true; |
546 | 525 | ||
@@ -560,12 +539,12 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, | |||
560 | get_connector(resman, *current_output); | 539 | get_connector(resman, *current_output); |
561 | 540 | ||
562 | if (!current_output->crtc) | 541 | if (!current_output->crtc) |
563 | get_default_crtc(card, *current_output); | 542 | get_default_crtc(resman, *current_output); |
564 | 543 | ||
565 | current_output->planes.push_back(PlaneInfo { }); | 544 | current_output->planes.push_back(PlaneInfo { }); |
566 | current_plane = ¤t_output->planes.back(); | 545 | current_plane = ¤t_output->planes.back(); |
567 | 546 | ||
568 | parse_plane(card, arg.arg, *current_output, *current_plane); | 547 | parse_plane(resman, card, arg.arg, *current_output, *current_plane); |
569 | 548 | ||
570 | break; | 549 | break; |
571 | } | 550 | } |
@@ -581,7 +560,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, | |||
581 | get_connector(resman, *current_output); | 560 | get_connector(resman, *current_output); |
582 | 561 | ||
583 | if (!current_output->crtc) | 562 | if (!current_output->crtc) |
584 | get_default_crtc(card, *current_output); | 563 | get_default_crtc(resman, *current_output); |
585 | 564 | ||
586 | int def_w, def_h; | 565 | int def_w, def_h; |
587 | 566 | ||
@@ -617,7 +596,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, | |||
617 | // create default framebuffers if needed | 596 | // create default framebuffers if needed |
618 | for (OutputInfo& o : outputs) { | 597 | for (OutputInfo& o : outputs) { |
619 | if (!o.crtc) { | 598 | if (!o.crtc) { |
620 | get_default_crtc(card, o); | 599 | get_default_crtc(resman, o); |
621 | o.user_set_crtc = true; | 600 | o.user_set_crtc = true; |
622 | } | 601 | } |
623 | 602 | ||
@@ -1048,7 +1027,7 @@ int main(int argc, char **argv) | |||
1048 | if (o.fbs.empty()) | 1027 | if (o.fbs.empty()) |
1049 | continue; | 1028 | continue; |
1050 | 1029 | ||
1051 | o.primary_plane = resman.reserve_primary_plane(o.crtc); | 1030 | o.primary_plane = resman.reserve_primary_plane(o.crtc, o.fbs[0]->format()); |
1052 | 1031 | ||
1053 | if (!o.primary_plane) | 1032 | if (!o.primary_plane) |
1054 | EXIT("Could not get primary plane for crtc '%u'", o.crtc->id()); | 1033 | EXIT("Could not get primary plane for crtc '%u'", o.crtc->id()); |