]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - tests/kmsview.cpp
kmsview: scale down to fit into screen
[android/external-libkmsxx.git] / tests / kmsview.cpp
1 #include <cstdio>
2 #include <fstream>
3 #include <unistd.h>
5 #include "kms++.h"
7 #include "test.h"
9 using namespace std;
10 using namespace kms;
12 static void read_frame(ifstream& is, DumbFramebuffer* fb, Crtc* crtc, Plane* plane)
13 {
14         for (unsigned i = 0; i < fb->num_planes(); ++i)
15                 is.read((char*)fb->map(i), fb->size(i));
17         unsigned w = min(crtc->width(), fb->width());
18         unsigned h = min(crtc->height(), fb->height());
20         int r = crtc->set_plane(plane, *fb,
21                                 0, 0, w, h,
22                                 0, 0, fb->width(), fb->height());
24         ASSERT(r == 0);
25 }
27 int main(int argc, char** argv)
28 {
29         if (argc != 5) {
30                 printf("Usage: %s <file> <width> <height> <fourcc>\n", argv[0]);
31                 return -1;
32         }
34         string filename = argv[1];
35         uint32_t w = stoi(argv[2]);
36         uint32_t h = stoi(argv[3]);
37         string modestr = argv[4];
39         auto pixfmt = FourCCToPixelFormat(modestr);
42         ifstream is(filename, ifstream::binary);
44         is.seekg(0, std::ios::end);
45         unsigned fsize = is.tellg();
46         is.seekg(0);
49         Card card;
51         auto conn = card.get_first_connected_connector();
52         auto crtc = conn->get_current_crtc();
54         auto fb = new DumbFramebuffer(card, w, h, pixfmt);
56         Plane* plane = 0;
58         for (Plane* p : crtc->get_possible_planes()) {
59                 if (p->plane_type() != PlaneType::Overlay)
60                         continue;
62                 if (!p->supports_format(pixfmt))
63                         continue;
65                 plane = p;
66                 break;
67         }
69         FAIL_IF(!plane, "available plane not found");
72         unsigned frame_size = 0;
73         for (unsigned i = 0; i < fb->num_planes(); ++i)
74                 frame_size += fb->size(i);
76         unsigned num_frames = fsize / frame_size;
77         printf("file size %u, frame size %u, frames %u\n", fsize, frame_size, num_frames);
79         for (unsigned i = 0; i < num_frames; ++i) {
80                 printf("frame %d\n", i);
81                 read_frame(is, fb, crtc, plane);
82                 usleep(1000*50);
83         }
85         printf("press enter to exit\n");
87         is.close();
89         getchar();
91         delete fb;
92 }