move test.h to test/
[android/external-libkmsxx.git] / tests / testpat.cpp
1 #include <cstdio>
2 #include <algorithm>
4 #include "kms++.h"
5 #include "utils/testpat.h"
7 #include "test.h"
9 using namespace std;
10 using namespace kms;
12 int main()
13 {
14         Card card;
16         if (card.master() == false)
17                 printf("Not DRM master, modeset may fail\n");
19         //card.print_short();
21         auto connectors = card.get_connectors();
23         vector<Framebuffer*> fbs;
24         vector<Crtc*> used_crtcs;
26         for (auto conn : connectors)
27         {
28                 if (conn->connected() == false)
29                         continue;
31                 Crtc* crtc = conn->get_current_crtc();
32                 if (!crtc) {
33                         vector<Crtc*> list = conn->get_possible_crtcs();
34                         for (auto c : list) {
35                                 if (find(used_crtcs.begin(), used_crtcs.end(), c) == used_crtcs.end()) {
36                                         crtc = c;
37                                         break;
38                                 }
39                         }
40                 }
41                 used_crtcs.push_back(crtc);
43                 ASSERT(crtc);
45                 int r;
47                 // RG16 XR24 UYVY YUYV NV12
49                 auto mode = conn->get_default_mode();
51                 auto fb = new Framebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
52                 draw_test_pattern(*fb);
53                 fbs.push_back(fb);
55                 r = crtc->set_mode(conn, *fb, mode);
56                 ASSERT(r == 0);
60                 Plane* plane = 0;
62                 for (Plane* p : crtc->get_possible_planes()) {
63                         if (p->plane_type() == PlaneType::Overlay) {
64                                 plane = p;
65                                 break;
66                         }
67                 }
69                 if (plane) {
70                         auto planefb = new Framebuffer(card, 400, 400, "YUYV");
71                         draw_test_pattern(*planefb);
72                         fbs.push_back(planefb);
74                         r = crtc->set_plane(plane, *planefb,
75                                             0, 0, planefb->width(), planefb->height(),
76                                             0, 0, planefb->width(), planefb->height());
78                         ASSERT(r == 0);
79                 }
80         }
82         printf("press enter to exit\n");
84         getchar();
86         for(auto fb : fbs)
87                 delete fb;
88 }