1 /*
2    Copyright (C) 2009 Red Hat, Inc.
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 /* This header should contains internal details between RedQxl and
19  * RedWorker.
20  * Should be included only by red-worker.cpp, red-qxl.cpp and
21  * red-replay-qxl.cpp (which uses message values).
22  */
23 
24 #ifndef RED_WORKER_H_
25 #define RED_WORKER_H_
26 
27 #include "red-channel.h"
28 
29 SPICE_BEGIN_DECLS
30 
31 typedef struct RedWorker RedWorker;
32 
33 RedWorker* red_worker_new(QXLInstance *qxl);
34 bool       red_worker_run(RedWorker *worker);
35 void red_worker_free(RedWorker *worker);
36 
37 struct Dispatcher *red_qxl_get_dispatcher(QXLInstance *qxl);
38 void red_qxl_destroy_primary_surface_complete(QXLState *qxl_state);
39 void red_qxl_create_primary_surface_complete(QXLState *qxl_state, const QXLDevSurfaceCreate* surface);
40 bool red_qxl_is_running(QXLInstance *qxl);
41 void red_qxl_set_running(QXLInstance *qxl, bool running);
42 
43 typedef uint32_t RedWorkerMessage;
44 
45 /* Keep message order, only append new messages!
46  * Replay code store enum values into save files.
47  */
48 enum {
49     RED_WORKER_MESSAGE_NOP,
50 
51     RED_WORKER_MESSAGE_UPDATE,
52     RED_WORKER_MESSAGE_WAKEUP,
53     RED_WORKER_MESSAGE_OOM,
54     RED_WORKER_MESSAGE_READY, /* unused */
55 
56     RED_WORKER_MESSAGE_DISPLAY_CONNECT_DEPRECATED,
57     RED_WORKER_MESSAGE_DISPLAY_DISCONNECT_DEPRECATED,
58     RED_WORKER_MESSAGE_DISPLAY_MIGRATE_DEPRECATED,
59     RED_WORKER_MESSAGE_START,
60     RED_WORKER_MESSAGE_STOP,
61     RED_WORKER_MESSAGE_CURSOR_CONNECT_DEPRECATED,
62     RED_WORKER_MESSAGE_CURSOR_DISCONNECT_DEPRECATED,
63     RED_WORKER_MESSAGE_CURSOR_MIGRATE_DEPRECATED,
64     RED_WORKER_MESSAGE_SET_COMPRESSION,
65     RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
66     RED_WORKER_MESSAGE_SET_MOUSE_MODE,
67     RED_WORKER_MESSAGE_ADD_MEMSLOT,
68     RED_WORKER_MESSAGE_DEL_MEMSLOT,
69     RED_WORKER_MESSAGE_RESET_MEMSLOTS,
70     RED_WORKER_MESSAGE_DESTROY_SURFACES,
71     RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
72     RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
73     RED_WORKER_MESSAGE_RESET_CURSOR,
74     RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
75     RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
76     RED_WORKER_MESSAGE_LOADVM_COMMANDS,
77     /* async commands */
78     RED_WORKER_MESSAGE_UPDATE_ASYNC,
79     RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
80     RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
81     RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
82     RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
83     RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
84     /* suspend/windows resolution change command */
85     RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
86 
87     RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE, /* unused */
88     RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE, /* unused */
89 
90     RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC,
91     RED_WORKER_MESSAGE_DRIVER_UNLOAD,
92     RED_WORKER_MESSAGE_GL_SCANOUT,
93     RED_WORKER_MESSAGE_GL_DRAW_ASYNC,
94     RED_WORKER_MESSAGE_SET_VIDEO_CODECS,
95 
96     /* close worker thread */
97     RED_WORKER_MESSAGE_CLOSE_WORKER,
98 
99     RED_WORKER_MESSAGE_COUNT // LAST
100 };
101 
102 typedef struct RedWorkerMessageUpdate {
103     uint32_t surface_id;
104     QXLRect * qxl_area;
105     QXLRect * qxl_dirty_rects;
106     uint32_t num_dirty_rects;
107     uint32_t clear_dirty_region;
108 } RedWorkerMessageUpdate;
109 
110 typedef struct RedWorkerMessageAsync {
111     uint64_t cookie;
112 } RedWorkerMessageAsync;
113 
114 typedef struct RedWorkerMessageUpdateAsync {
115     RedWorkerMessageAsync base;
116     uint32_t surface_id;
117     QXLRect qxl_area;
118     uint32_t clear_dirty_region;
119 } RedWorkerMessageUpdateAsync;
120 
121 typedef struct RedWorkerMessageAddMemslot {
122     QXLDevMemSlot mem_slot;
123 } RedWorkerMessageAddMemslot;
124 
125 typedef struct RedWorkerMessageAddMemslotAsync {
126     RedWorkerMessageAsync base;
127     QXLDevMemSlot mem_slot;
128 } RedWorkerMessageAddMemslotAsync;
129 
130 typedef struct RedWorkerMessageDelMemslot {
131     uint32_t slot_group_id;
132     uint32_t slot_id;
133 } RedWorkerMessageDelMemslot;
134 
135 typedef struct RedWorkerMessageDestroySurfaces {
136     uint8_t dummy_empty_field[0]; // C/C++ compatibility
137 } RedWorkerMessageDestroySurfaces;
138 
139 typedef struct RedWorkerMessageDestroySurfacesAsync {
140     RedWorkerMessageAsync base;
141 } RedWorkerMessageDestroySurfacesAsync;
142 
143 
144 typedef struct RedWorkerMessageDestroyPrimarySurface {
145     uint32_t surface_id;
146 } RedWorkerMessageDestroyPrimarySurface;
147 
148 typedef struct RedWorkerMessageDestroyPrimarySurfaceAsync {
149     RedWorkerMessageAsync base;
150     uint32_t surface_id;
151 } RedWorkerMessageDestroyPrimarySurfaceAsync;
152 
153 typedef struct RedWorkerMessageCreatePrimarySurfaceAsync {
154     RedWorkerMessageAsync base;
155     uint32_t surface_id;
156     QXLDevSurfaceCreate surface;
157 } RedWorkerMessageCreatePrimarySurfaceAsync;
158 
159 typedef struct RedWorkerMessageCreatePrimarySurface {
160     uint32_t surface_id;
161     QXLDevSurfaceCreate surface;
162 } RedWorkerMessageCreatePrimarySurface;
163 
164 typedef struct RedWorkerMessageResetImageCache {
165     uint8_t dummy_empty_field[0]; // C/C++ compatibility
166 } RedWorkerMessageResetImageCache;
167 
168 typedef struct RedWorkerMessageResetCursor {
169     uint8_t dummy_empty_field[0]; // C/C++ compatibility
170 } RedWorkerMessageResetCursor;
171 
172 typedef struct RedWorkerMessageWakeup {
173     uint8_t dummy_empty_field[0]; // C/C++ compatibility
174 } RedWorkerMessageWakeup;
175 
176 typedef struct RedWorkerMessageOom {
177     uint8_t dummy_empty_field[0]; // C/C++ compatibility
178 } RedWorkerMessageOom;
179 
180 typedef struct RedWorkerMessageStart {
181     uint8_t dummy_empty_field[0]; // C/C++ compatibility
182 } RedWorkerMessageStart;
183 
184 typedef struct RedWorkerMessageFlushSurfacesAsync {
185     RedWorkerMessageAsync base;
186 } RedWorkerMessageFlushSurfacesAsync;
187 
188 typedef struct RedWorkerMessageStop {
189     uint8_t dummy_empty_field[0]; // C/C++ compatibility
190 } RedWorkerMessageStop;
191 
192 /* this command is sync, so it's ok to pass a pointer */
193 typedef struct RedWorkerMessageLoadvmCommands {
194     uint32_t count;
195     QXLCommandExt *ext;
196 } RedWorkerMessageLoadvmCommands;
197 
198 typedef struct RedWorkerMessageSetCompression {
199     SpiceImageCompression image_compression;
200 } RedWorkerMessageSetCompression;
201 
202 typedef struct RedWorkerMessageSetStreamingVideo {
203     uint32_t streaming_video;
204 } RedWorkerMessageSetStreamingVideo;
205 
206 typedef struct RedWorkerMessageSetVideoCodecs {
207     GArray* video_codecs;
208 } RedWorkerMessageSetVideoCodecs;
209 
210 typedef struct RedWorkerMessageSetMouseMode {
211     uint32_t mode;
212 } RedWorkerMessageSetMouseMode;
213 
214 typedef struct RedWorkerMessageDestroySurfaceWait {
215     uint32_t surface_id;
216 } RedWorkerMessageDestroySurfaceWait;
217 
218 typedef struct RedWorkerMessageDestroySurfaceWaitAsync {
219     RedWorkerMessageAsync base;
220     uint32_t surface_id;
221 } RedWorkerMessageDestroySurfaceWaitAsync;
222 
223 typedef struct RedWorkerMessageResetMemslots {
224 } RedWorkerMessageResetMemslots;
225 
226 typedef struct RedWorkerMessageMonitorsConfigAsync {
227     RedWorkerMessageAsync base;
228     QXLPHYSICAL monitors_config;
229     int group_id;
230     unsigned int max_monitors;
231 } RedWorkerMessageMonitorsConfigAsync;
232 
233 typedef struct RedWorkerMessageDriverUnload {
234     uint8_t dummy_empty_field[0]; // C/C++ compatibility
235 } RedWorkerMessageDriverUnload;
236 
237 typedef struct RedWorkerMessageGlScanout {
238     uint8_t dummy_empty_field[0]; // C/C++ compatibility
239 } RedWorkerMessageGlScanout;
240 
241 typedef struct RedWorkerMessageClose {
242     uint8_t dummy_empty_field[0]; // C/C++ compatibility
243 } RedWorkerMessageClose;
244 
245 typedef struct RedWorkerMessageGlDraw {
246     SpiceMsgDisplayGlDraw draw;
247 } RedWorkerMessageGlDraw;
248 
249 enum {
250     RED_DISPATCHER_PENDING_WAKEUP,
251     RED_DISPATCHER_PENDING_OOM,
252 };
253 
254 void red_qxl_clear_pending(QXLState *qxl_state, int pending);
255 
256 SPICE_END_DECLS
257 
258 #endif /* RED_WORKER_H_ */
259