DRI2: report swap events correctly in direct rendered case
[mesa.git] / progs / openvg / trivial / stroke.c
1 #include "eglcommon.h"
2
3 #include <VG/openvg.h>
4 #include <X11/keysym.h>
5 #include <stdio.h>
6
7 const VGfloat white_color[4] = {1.0, 1.0, 1.0, 1.0};
8 const VGfloat color[4] = {0.4, 0.1, 1.0, 1.0};
9
10 VGPath path;
11 VGPaint fill;
12
13 VGint cap_style = VG_CAP_BUTT;
14 VGint join_style = VG_JOIN_MITER;
15
16 static void
17 init(void)
18 {
19 #if 0
20 static const VGubyte cmds[] = {VG_MOVE_TO_ABS,
21 VG_CUBIC_TO_ABS,
22 };
23 static const VGfloat coords[] = {30, 30, 264, 0, 0, 264, 234, 234
24 };
25 #else
26 static const VGubyte cmds[] = {VG_MOVE_TO_ABS,
27 VG_LINE_TO_ABS,
28 VG_LINE_TO_ABS
29 };
30 static const VGfloat coords[] = {30, 30, 202, 30, 150, 224
31 };
32 #endif
33 VGfloat dash_pattern[2] = { 20.f, 20.f };
34 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
35 VG_PATH_CAPABILITY_APPEND_TO);
36 vgAppendPathData(path, 3, cmds, coords);
37
38 fill = vgCreatePaint();
39 vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
40 vgSetPaint(fill, VG_FILL_PATH);
41
42 vgSetfv(VG_CLEAR_COLOR, 4, white_color);
43 vgSetf(VG_STROKE_LINE_WIDTH, 20);
44 vgSeti(VG_STROKE_CAP_STYLE, cap_style);
45 vgSeti(VG_STROKE_JOIN_STYLE, join_style);
46 vgSetfv(VG_STROKE_DASH_PATTERN, 2, dash_pattern);
47 vgSetf(VG_STROKE_DASH_PHASE, 0.0f);
48 }
49
50 /* new window size or exposure */
51 static void
52 reshape(int w, int h)
53 {
54 vgLoadIdentity();
55 }
56
57 static void
58 draw(void)
59 {
60 vgClear(0, 0, window_width(), window_height());
61 vgDrawPath(path, VG_STROKE_PATH);
62
63 vgFlush();
64 }
65
66 static int key_press(unsigned key)
67 {
68 switch(key) {
69 case XK_c:
70 case XK_C:
71 ++cap_style;
72 if (cap_style > VG_CAP_SQUARE)
73 cap_style = VG_CAP_BUTT;
74 switch(cap_style) {
75 case VG_CAP_BUTT:
76 fprintf(stderr, "Cap style 'butt'\n");
77 break;
78 case VG_CAP_ROUND:
79 fprintf(stderr, "Cap style 'round'\n");
80 break;
81 case VG_CAP_SQUARE:
82 fprintf(stderr, "Cap style 'square'\n");
83 break;
84 }
85 vgSeti(VG_STROKE_CAP_STYLE, cap_style);
86 break;
87 case XK_j:
88 case XK_J:
89 ++join_style;
90 if (join_style > VG_JOIN_BEVEL)
91 join_style = VG_JOIN_MITER;
92 switch(join_style) {
93 case VG_JOIN_MITER:
94 fprintf(stderr, "Join style 'miter'\n");
95 break;
96 case VG_JOIN_ROUND:
97 fprintf(stderr, "Join style 'round'\n");
98 break;
99 case VG_JOIN_BEVEL:
100 fprintf(stderr, "Join style 'bevel'\n");
101 break;
102 }
103 vgSeti(VG_STROKE_JOIN_STYLE, join_style);
104 break;
105 default:
106 break;
107 }
108
109 return VG_TRUE;
110 }
111
112 int main(int argc, char **argv)
113 {
114 return run(argc, argv, init, reshape,
115 draw, key_press);
116 }