• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <sys/select.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <signal.h>
10 #include <time.h>
11 #include <errno.h>
12 
13 #include <xf86drm.h>
14 
15 #include "dev.h"
16 #include "bo.h"
17 #include "modeset.h"
18 
19 static int terminate = 0;
20 
sigint_handler(int arg)21 static void sigint_handler(int arg)
22 {
23 	terminate = 1;
24 }
25 
incrementor(int * inc,int * val,int increment,int lower,int upper)26 static void incrementor(int *inc, int *val, int increment, int lower, int upper)
27 {
28 	if(*inc > 0)
29 		*inc = *val + increment >= upper ? -1 : 1;
30 	else
31 		*inc = *val - increment <= lower ? 1 : -1;
32 	*val += *inc * increment;
33 }
34 
main(int argc,char * argv[])35 int main(int argc, char *argv[])
36 {
37 	int ret, i, j, num_test_planes;
38 	int x_inc = 1, x = 0, y_inc = 1, y = 0;
39 	uint32_t plane_w = 128, plane_h = 128;
40 	struct sp_dev *dev;
41 	struct sp_plane **plane = NULL;
42 	struct sp_crtc *test_crtc;
43 	int card = 0, crtc = 0;
44 
45 	signal(SIGINT, sigint_handler);
46 
47 	parse_arguments(argc, argv, &card, &crtc);
48 
49 	dev = create_sp_dev(card);
50 	if (!dev) {
51 		printf("Failed to create sp_dev\n");
52 		return -1;
53 	}
54 
55 	if (crtc >= dev->num_crtcs) {
56 		printf("Invalid crtc %d (num=%d)\n", crtc, dev->num_crtcs);
57 		return -1;
58 	}
59 
60 	ret = initialize_screens(dev);
61 	if (ret) {
62 		printf("Failed to initialize screens\n");
63 		goto out;
64 	}
65 	test_crtc = &dev->crtcs[crtc];
66 
67 	plane = calloc(dev->num_planes, sizeof(*plane));
68 	if (!plane) {
69 		printf("Failed to allocate plane array\n");
70 		goto out;
71 	}
72 
73 	/* Create our planes */
74 	num_test_planes = test_crtc->num_planes;
75 	for (i = 0; i < num_test_planes; i++) {
76 		plane[i] = get_sp_plane(dev, test_crtc);
77 		if (!plane[i]) {
78 			printf("no unused planes available\n");
79 			goto out;
80 		}
81 
82 		plane[i]->bo = create_sp_bo(dev, plane_w, plane_h, 16,
83 				plane[i]->format, 0);
84 		if (!plane[i]->bo) {
85 			printf("failed to create plane bo\n");
86 			goto out;
87 		}
88 
89 		fill_bo(plane[i]->bo, 0xFF, 0xFF, 0xFF, 0xFF);
90 	}
91 
92 	while (!terminate) {
93 		incrementor(&x_inc, &x, 5, 0,
94 			test_crtc->crtc->mode.hdisplay - plane_w);
95 		incrementor(&y_inc, &y, 5, 0, test_crtc->crtc->mode.vdisplay -
96 						plane_h * num_test_planes);
97 
98 		for (j = 0; j < num_test_planes; j++) {
99 			ret = set_sp_plane(dev, plane[j], test_crtc,
100 					x, y + j * plane_h);
101 			if (ret) {
102 				printf("failed to set plane %d %d\n", j, ret);
103 				goto out;
104 			}
105 		}
106 		usleep(15 * 1000);
107 	}
108 
109 	for (i = 0; i < num_test_planes; i++)
110 		put_sp_plane(plane[i]);
111 
112 out:
113 	destroy_sp_dev(dev);
114 	free(plane);
115 	return ret;
116 }
117