tests/testpat: Add -m flag
[android/external-libkmsxx.git] / tests / testpat.cpp
1 #include <cstdio>
2 #include <algorithm>
4 #include "kms++.h"
6 #include "test.h"
7 #include "cmdoptions.h"
9 using namespace std;
10 using namespace kms;
12 static map<string, CmdOption> options = {
13         { "m", HAS_PARAM("Set display mode, for example 1920x1080") },
14 };
16 int main(int argc, char **argv)
17 {
18         Card card;
19         CmdOptions opts(argc, argv, options);
21         if (card.master() == false)
22                 printf("Not DRM master, modeset may fail\n");
24         //card.print_short();
26         auto pipes = card.get_connected_pipelines();
28         vector<Framebuffer*> fbs;
30         for (auto pipe : pipes)
31         {
32                 auto conn = pipe.connector;
33                 auto crtc = pipe.crtc;
35                 // RG16 XR24 UYVY YUYV NV12
37                 auto mode = conn->get_default_mode();
39                 if (opts.is_set("m"))
40                         mode = conn->get_mode(opts.opt_param("m"));
42                 auto fb = new DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, PixelFormat::XRGB8888);
43                 draw_test_pattern(*fb);
44                 fbs.push_back(fb);
46                 printf("conn %u, crtc %u, fb %u\n", conn->id(), crtc->id(), fb->id());
48                 int r = crtc->set_mode(conn, *fb, mode);
49                 ASSERT(r == 0);
50         }
52         for (auto pipe: pipes)
53         {
54                 auto crtc = pipe.crtc;
56                 Plane* plane = 0;
58                 for (Plane* p : crtc->get_possible_planes()) {
59                         if (p->plane_type() == PlaneType::Overlay) {
60                                 plane = p;
61                                 break;
62                         }
63                 }
65                 if (plane) {
66                         auto planefb = new DumbFramebuffer(card, 400, 400, PixelFormat::YUYV);
67                         draw_test_pattern(*planefb);
68                         fbs.push_back(planefb);
70                         int r = crtc->set_plane(plane, *planefb,
71                                             0, 0, planefb->width(), planefb->height(),
72                                             0, 0, planefb->width(), planefb->height());
74                         ASSERT(r == 0);
75                 }
76         }
78         printf("press enter to exit\n");
80         getchar();
82         for(auto fb : fbs)
83                 delete fb;
84 }