cafd1606e4f0f61b7c9d2d949fe9bea8342274b6
[android/external-libkmsxx.git] / tests / kmsview.cpp
1 #include <cstdio>
2 #include <fstream>
4 #include "kms++.h"
6 #include "test.h"
8 using namespace std;
9 using namespace kms;
11 int main(int argc, char** argv)
12 {
13         if (argc != 5) {
14                 printf("Usage: %s <file> <width> <height> <fourcc>\n", argv[0]);
15                 return -1;
16         }
18         string filename = argv[1];
19         uint32_t w = stoi(argv[2]);
20         uint32_t h = stoi(argv[3]);
21         string modestr = argv[4];
23         auto pixfmt = FourCCToPixelFormat(modestr);
25         Card card;
27         auto conn = card.get_first_connected_connector();
28         auto crtc = conn->get_current_crtc();
30         auto fb = new DumbFramebuffer(card, w, h, pixfmt);
32         ifstream is(filename, ifstream::binary);
33         is.read((char*)fb->map(0), fb->size(0));
34         is.close();
36         Plane* plane = 0;
38         for (Plane* p : crtc->get_possible_planes()) {
39                 if (p->plane_type() != PlaneType::Overlay)
40                         continue;
42                 if (!p->supports_format(pixfmt))
43                         continue;
45                 plane = p;
46                 break;
47         }
49         FAIL_IF(!plane, "available plane not found");
51         int r = crtc->set_plane(plane, *fb,
52                                 0, 0, w, h,
53                                 0, 0, w, h);
55         ASSERT(r == 0);
57         printf("press enter to exit\n");
59         getchar();
61         delete fb;
62 }