1 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3    Copyright (C) 2009-2015 Red Hat, Inc.
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef __TEST_DISPLAY_BASE_H__
19 #define __TEST_DISPLAY_BASE_H__
20 
21 #include <spice.h>
22 #include "basic-event-loop.h"
23 
24 SPICE_BEGIN_DECLS
25 
26 /*
27  * simple queue for commands.
28  * each command can have up to two parameters (grow as needed)
29  *
30  * TODO: switch to gtk main loop. Then add gobject-introspection. then
31  * write tests in python/guile/whatever.
32  */
33 typedef enum {
34     PATH_PROGRESS,
35     SIMPLE_CREATE_SURFACE,
36     SIMPLE_DRAW,
37     SIMPLE_DRAW_BITMAP,
38     SIMPLE_DRAW_SOLID,
39     SIMPLE_COPY_BITS,
40     SIMPLE_DESTROY_SURFACE,
41     SIMPLE_UPDATE,
42     DESTROY_PRIMARY,
43     CREATE_PRIMARY,
44     SLEEP
45 } CommandType;
46 
47 typedef struct CommandCreatePrimary {
48     uint32_t width;
49     uint32_t height;
50 } CommandCreatePrimary;
51 
52 typedef struct CommandCreateSurface {
53     uint32_t surface_id;
54     uint32_t format;
55     uint32_t width;
56     uint32_t height;
57     uint8_t *data;
58 } CommandCreateSurface;
59 
60 typedef struct CommandDrawBitmap {
61     QXLRect bbox;
62     uint8_t *bitmap;
63     uint32_t surface_id;
64     uint32_t num_clip_rects;
65     QXLRect *clip_rects;
66 } CommandDrawBitmap;
67 
68 typedef struct CommandDrawSolid {
69     QXLRect bbox;
70     uint32_t color;
71     uint32_t surface_id;
72 } CommandDrawSolid;
73 
74 typedef struct CommandSleep {
75     uint32_t secs;
76 } CommandSleep;
77 
78 typedef struct Command Command;
79 typedef struct Test Test;
80 
81 struct Command {
82     CommandType command;
83     void (*cb)(Test *test, Command *command);
84     void *cb_opaque;
85     union {
86         CommandCreatePrimary create_primary;
87         CommandDrawBitmap bitmap;
88         CommandDrawSolid solid;
89         CommandSleep sleep;
90         CommandCreateSurface create_surface;
91     };
92 };
93 
94 #define MAX_HEIGHT 2048
95 #define MAX_WIDTH 2048
96 
97 #define SURF_WIDTH 320
98 #define SURF_HEIGHT 240
99 
100 struct Test {
101     SpiceCoreInterface *core;
102     SpiceServer *server;
103 
104     QXLInstance qxl_instance;
105 
106     uint8_t primary_surface[MAX_HEIGHT * MAX_WIDTH * 4];
107     int primary_height;
108     int primary_width;
109 
110     SpiceTimer *wakeup_timer;
111     int wakeup_ms;
112 
113     int cursor_notify;
114 
115     uint8_t secondary_surface[SURF_WIDTH * SURF_HEIGHT * 4];
116     int has_secondary;
117 
118     // Current mode (set by create_primary)
119     int width;
120     int height;
121 
122     // qxl scripted rendering commands and io
123     Command *commands;
124     int num_commands;
125     int cmd_index;
126 
127     int target_surface;
128 
129     // callbacks
130     void (*on_client_connected)(Test *test);
131     void (*on_client_disconnected)(Test *test);
132 };
133 
134 void test_set_simple_command_list(Test *test, const int *command, int num_commands);
135 void test_set_command_list(Test *test, Command *command, int num_commands);
136 void test_add_display_interface(Test *test);
137 void test_add_agent_interface(SpiceServer *server); // TODO - Test *test
138 Test* test_new(SpiceCoreInterface* core);
139 void test_destroy(Test *test);
140 
141 uint32_t test_get_width(void);
142 uint32_t test_get_height(void);
143 
144 void spice_test_config_parse_args(int argc, char **argv);
145 
146 SPICE_END_DECLS
147 
148 #endif /* __TEST_DISPLAY_BASE_H__ */
149