]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - utils/kmsview.cpp
modedb_dmt: update table
[android/external-libkmsxx.git] / utils / kmsview.cpp
1 #include <cstdio>
2 #include <fstream>
3 #include <unistd.h>
5 #include <kms++/kms++.h>
6 #include <kms++util/kms++util.h>
8 using namespace std;
9 using namespace kms;
11 static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* plane)
12 {
13         for (unsigned i = 0; i < fb->num_planes(); ++i)
14                 is.read((char*)fb->map(i), fb->size(i));
16         unsigned w = min(crtc->width(), fb->width());
17         unsigned h = min(crtc->height(), fb->height());
19         int r = crtc->set_plane(plane, *fb,
20                                 0, 0, w, h,
21                                 0, 0, fb->width(), fb->height());
23         ASSERT(r == 0);
24 }
26 static const char* usage_str =
27                 "Usage: kmsview [-t <ms>] <file> <width> <height> <fourcc>\n\n"
28                 "Options:\n"
29                 "  -t, --time        Milliseconds to sleep between frames\n"
30                 ;
32 static void usage()
33 {
34         puts(usage_str);
35 }
37 int main(int argc, char** argv)
38 {
39         uint32_t time = 0;
40         string dev_path = "/dev/dri/card0";
42         OptionSet optionset = {
43                 Option("|device=", [&dev_path](string s)
44                 {
45                         dev_path = s;
46                 }),
47                 Option("t|time=", [&time](const string& str)
48                 {
49                         time = stoul(str);
50                 }),
51                 Option("h|help", []()
52                 {
53                         usage();
54                         exit(-1);
55                 }),
56         };
58         optionset.parse(argc, argv);
60         vector<string> params = optionset.params();
62         if (params.size() != 4) {
63                 usage();
64                 exit(-1);
65         }
67         string filename = params[0];
68         uint32_t w = stoi(params[1]);
69         uint32_t h = stoi(params[2]);
70         string modestr = params[3];
72         auto pixfmt = FourCCToPixelFormat(modestr);
74         ifstream is(filename, ifstream::binary);
76         is.seekg(0, std::ios::end);
77         unsigned fsize = is.tellg();
78         is.seekg(0);
81         Card card(dev_path);
82         ResourceManager res(card);
84         auto conn = res.reserve_connector();
85         auto crtc = res.reserve_crtc(conn);
86         auto plane = res.reserve_overlay_plane(crtc, pixfmt);
87         FAIL_IF(!plane, "available plane not found");
89         auto fb = new DumbFramebuffer(card, w, h, pixfmt);
91         unsigned frame_size = 0;
92         for (unsigned i = 0; i < fb->num_planes(); ++i)
93                 frame_size += fb->size(i);
95         unsigned num_frames = fsize / frame_size;
96         printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames);
98         for (unsigned i = 0; i < num_frames; ++i) {
99                 printf("frame %d", i); fflush(stdout);
100                 read_frame(is, fb, crtc, plane);
101                 if (!time) {
102                         getchar();
103                 } else {
104                         usleep(time * 1000);
105                         printf("\n");
106                 }
107         }
109         is.close();
111         if (time) {
112                 printf("press enter to exit\n");
113                 getchar();
114         }
116         delete fb;