Merge remote branch 'upstream/gallium-0.2' into nouveau-gallium-0.2
[mesa.git] / src / gallium / state_trackers / g3dvl / tests / test_i_rendering.c
1 #include <stdio.h>
2 #include <X11/Xlib.h>
3 #include <vl_context.h>
4 #include <vl_surface.h>
5 #include <xsp_winsys.h>
6
7 static const unsigned short ycbcr16x16_420[8*8*6] =
8 {
9 0x00A5,0x00A5,0x00A5,0x0072,0x00A5,0x0072,0x0072,0x0072,
10 0x0072,0x00A5,0x0072,0x0072,0x00A5,0x0072,0x0072,0x0072,
11 0x0072,0x00A5,0x0072,0x0072,0x00A5,0x00A5,0x0072,0x0072,
12 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
13 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
14 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
15 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
16 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
17
18 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
19 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
20 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
21 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
22 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
23 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
24 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
25 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
26
27 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
28 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
29 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
30 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
31 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
32 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
33 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
34 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
35
36 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
37 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
38 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
39 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,
40 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x00A5,
41 0x0072,0x0072,0x0072,0x0072,0x0072,0x0072,0x00A5,0x00A5,
42 0x0072,0x0072,0x0072,0x0072,0x0072,0x00A5,0x00A5,0x00A5,
43 0x0072,0x0072,0x0072,0x0072,0x00A5,0x00A5,0x00A5,0x00A5,
44
45 0x004F,0x004F,0x004F,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
46 0x00B2,0x00B2,0x004F,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
47 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
48 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
49 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
50 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,
51 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x004F,
52 0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x00B2,0x004F,0x004F,
53
54 0x003E,0x003E,0x003E,0x0060,0x0060,0x0060,0x0060,0x0060,
55 0x0060,0x0060,0x003E,0x0060,0x0060,0x0060,0x0060,0x0060,
56 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,
57 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,
58 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,
59 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,
60 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x003E,
61 0x0060,0x0060,0x0060,0x0060,0x0060,0x0060,0x003E,0x003E
62 };
63
64 int main(int argc, char **argv)
65 {
66 const unsigned int video_width = 32, video_height = 32;
67 const unsigned int window_width = video_width * 2, window_height = video_height * 2;
68 int quit = 0;
69 Display *display;
70 Window root, window;
71 Pixmap framebuffer;
72 XEvent event;
73 struct pipe_context *pipe;
74 struct VL_CONTEXT *ctx;
75 struct VL_SURFACE *sfc;
76
77 display = XOpenDisplay(NULL);
78 root = XDefaultRootWindow(display);
79 window = XCreateSimpleWindow(display, root, 0, 0, window_width, window_height, 0, 0, 0);
80 framebuffer = XCreatePixmap(display, root, window_width, window_height, 24);
81
82 XSelectInput(display, window, ExposureMask | KeyPressMask);
83 XMapWindow(display, window);
84 XSync(display, 0);
85
86 pipe = create_pipe_context(display);
87 vlCreateContext(display, pipe, video_width, video_height, VL_FORMAT_YCBCR_420, &ctx);
88 vlCreateSurface(ctx, &sfc);
89
90 vlRenderIMacroBlock(VL_FRAME_PICTURE, VL_FIELD_FIRST, 0, 0, 0x3F, VL_DCT_FRAME_CODED, (short*)ycbcr16x16_420, sfc);
91 vlRenderIMacroBlock(VL_FRAME_PICTURE, VL_FIELD_FIRST, 1, 0, 0x3F, VL_DCT_FRAME_CODED, (short*)ycbcr16x16_420, sfc);
92 vlRenderIMacroBlock(VL_FRAME_PICTURE, VL_FIELD_FIRST, 0, 1, 0x3F, VL_DCT_FRAME_CODED, (short*)ycbcr16x16_420, sfc);
93 vlRenderIMacroBlock(VL_FRAME_PICTURE, VL_FIELD_FIRST, 1, 1, 0x3F, VL_DCT_FRAME_CODED, (short*)ycbcr16x16_420, sfc);
94 vlPutSurface(sfc, framebuffer, 0, 0, video_width, video_height, 0, 0, window_width, window_height, VL_FRAME_PICTURE);
95
96 puts("Press any key to continue...");
97
98 while (!quit)
99 {
100 XNextEvent(display, &event);
101 switch (event.type)
102 {
103 case Expose:
104 {
105 XCopyArea
106 (
107 display,
108 framebuffer,
109 window,
110 XDefaultGC(display, XDefaultScreen(display)),
111 0,
112 0,
113 window_width,
114 window_height,
115 0,
116 0
117 );
118 break;
119 }
120 case KeyPress:
121 {
122 quit = 1;
123 break;
124 }
125 }
126 }
127
128 vlDestroySurface(sfc);
129 vlDestroyContext(ctx);
130
131 XFreePixmap(display, framebuffer);
132 XDestroyWindow(display, window);
133 XCloseDisplay(display);
134
135 return 0;
136 }
137