block/curl: Check protocol prefix
[qemu/ar7.git] / hw / display / qxl-logger.c
blob2ec6d8fa3d6cd3b6596d76654d53a923e64c5164
1 /*
2 * qxl command logging -- for debug purposes
4 * Copyright (C) 2010 Red Hat, Inc.
6 * maintained by Gerd Hoffmann <kraxel@redhat.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 or
11 * (at your option) version 3 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "qemu/osdep.h"
23 #include "qemu/timer.h"
24 #include "qxl.h"
26 static const char *const qxl_type[] = {
27 [ QXL_CMD_NOP ] = "nop",
28 [ QXL_CMD_DRAW ] = "draw",
29 [ QXL_CMD_UPDATE ] = "update",
30 [ QXL_CMD_CURSOR ] = "cursor",
31 [ QXL_CMD_MESSAGE ] = "message",
32 [ QXL_CMD_SURFACE ] = "surface",
35 static const char *const qxl_draw_type[] = {
36 [ QXL_DRAW_NOP ] = "nop",
37 [ QXL_DRAW_FILL ] = "fill",
38 [ QXL_DRAW_OPAQUE ] = "opaque",
39 [ QXL_DRAW_COPY ] = "copy",
40 [ QXL_COPY_BITS ] = "copy-bits",
41 [ QXL_DRAW_BLEND ] = "blend",
42 [ QXL_DRAW_BLACKNESS ] = "blackness",
43 [ QXL_DRAW_WHITENESS ] = "whitemess",
44 [ QXL_DRAW_INVERS ] = "invers",
45 [ QXL_DRAW_ROP3 ] = "rop3",
46 [ QXL_DRAW_STROKE ] = "stroke",
47 [ QXL_DRAW_TEXT ] = "text",
48 [ QXL_DRAW_TRANSPARENT ] = "transparent",
49 [ QXL_DRAW_ALPHA_BLEND ] = "alpha-blend",
52 static const char *const qxl_draw_effect[] = {
53 [ QXL_EFFECT_BLEND ] = "blend",
54 [ QXL_EFFECT_OPAQUE ] = "opaque",
55 [ QXL_EFFECT_REVERT_ON_DUP ] = "revert-on-dup",
56 [ QXL_EFFECT_BLACKNESS_ON_DUP ] = "blackness-on-dup",
57 [ QXL_EFFECT_WHITENESS_ON_DUP ] = "whiteness-on-dup",
58 [ QXL_EFFECT_NOP_ON_DUP ] = "nop-on-dup",
59 [ QXL_EFFECT_NOP ] = "nop",
60 [ QXL_EFFECT_OPAQUE_BRUSH ] = "opaque-brush",
63 static const char *const qxl_surface_cmd[] = {
64 [ QXL_SURFACE_CMD_CREATE ] = "create",
65 [ QXL_SURFACE_CMD_DESTROY ] = "destroy",
68 static const char *const spice_surface_fmt[] = {
69 [ SPICE_SURFACE_FMT_INVALID ] = "invalid",
70 [ SPICE_SURFACE_FMT_1_A ] = "alpha/1",
71 [ SPICE_SURFACE_FMT_8_A ] = "alpha/8",
72 [ SPICE_SURFACE_FMT_16_555 ] = "555/16",
73 [ SPICE_SURFACE_FMT_16_565 ] = "565/16",
74 [ SPICE_SURFACE_FMT_32_xRGB ] = "xRGB/32",
75 [ SPICE_SURFACE_FMT_32_ARGB ] = "ARGB/32",
78 static const char *const qxl_cursor_cmd[] = {
79 [ QXL_CURSOR_SET ] = "set",
80 [ QXL_CURSOR_MOVE ] = "move",
81 [ QXL_CURSOR_HIDE ] = "hide",
82 [ QXL_CURSOR_TRAIL ] = "trail",
85 static const char *const spice_cursor_type[] = {
86 [ SPICE_CURSOR_TYPE_ALPHA ] = "alpha",
87 [ SPICE_CURSOR_TYPE_MONO ] = "mono",
88 [ SPICE_CURSOR_TYPE_COLOR4 ] = "color4",
89 [ SPICE_CURSOR_TYPE_COLOR8 ] = "color8",
90 [ SPICE_CURSOR_TYPE_COLOR16 ] = "color16",
91 [ SPICE_CURSOR_TYPE_COLOR24 ] = "color24",
92 [ SPICE_CURSOR_TYPE_COLOR32 ] = "color32",
95 static const char *qxl_v2n(const char *const n[], size_t l, int v)
97 if (v >= l || !n[v]) {
98 return "???";
100 return n[v];
102 #define qxl_name(_list, _value) qxl_v2n(_list, ARRAY_SIZE(_list), _value)
104 static int qxl_log_image(PCIQXLDevice *qxl, QXLPHYSICAL addr, int group_id)
106 QXLImage *image;
107 QXLImageDescriptor *desc;
109 image = qxl_phys2virt(qxl, addr, group_id);
110 if (!image) {
111 return 1;
113 desc = &image->descriptor;
114 fprintf(stderr, " (id %" PRIx64 " type %d flags %d width %d height %d",
115 desc->id, desc->type, desc->flags, desc->width, desc->height);
116 switch (desc->type) {
117 case SPICE_IMAGE_TYPE_BITMAP:
118 fprintf(stderr, ", fmt %d flags %d x %d y %d stride %d"
119 " palette %" PRIx64 " data %" PRIx64,
120 image->bitmap.format, image->bitmap.flags,
121 image->bitmap.x, image->bitmap.y,
122 image->bitmap.stride,
123 image->bitmap.palette, image->bitmap.data);
124 break;
126 fprintf(stderr, ")");
127 return 0;
130 static void qxl_log_rect(QXLRect *rect)
132 fprintf(stderr, " %dx%d+%d+%d",
133 rect->right - rect->left,
134 rect->bottom - rect->top,
135 rect->left, rect->top);
138 static int qxl_log_cmd_draw_copy(PCIQXLDevice *qxl, QXLCopy *copy,
139 int group_id)
141 int ret;
143 fprintf(stderr, " src %" PRIx64,
144 copy->src_bitmap);
145 ret = qxl_log_image(qxl, copy->src_bitmap, group_id);
146 if (ret != 0) {
147 return ret;
149 fprintf(stderr, " area");
150 qxl_log_rect(&copy->src_area);
151 fprintf(stderr, " rop %d", copy->rop_descriptor);
152 return 0;
155 static int qxl_log_cmd_draw(PCIQXLDevice *qxl, QXLDrawable *draw, int group_id)
157 fprintf(stderr, ": surface_id %d type %s effect %s",
158 draw->surface_id,
159 qxl_name(qxl_draw_type, draw->type),
160 qxl_name(qxl_draw_effect, draw->effect));
161 switch (draw->type) {
162 case QXL_DRAW_COPY:
163 return qxl_log_cmd_draw_copy(qxl, &draw->u.copy, group_id);
164 break;
166 return 0;
169 static int qxl_log_cmd_draw_compat(PCIQXLDevice *qxl, QXLCompatDrawable *draw,
170 int group_id)
172 fprintf(stderr, ": type %s effect %s",
173 qxl_name(qxl_draw_type, draw->type),
174 qxl_name(qxl_draw_effect, draw->effect));
175 if (draw->bitmap_offset) {
176 fprintf(stderr, ": bitmap %d",
177 draw->bitmap_offset);
178 qxl_log_rect(&draw->bitmap_area);
180 switch (draw->type) {
181 case QXL_DRAW_COPY:
182 return qxl_log_cmd_draw_copy(qxl, &draw->u.copy, group_id);
183 break;
185 return 0;
188 static void qxl_log_cmd_surface(PCIQXLDevice *qxl, QXLSurfaceCmd *cmd)
190 fprintf(stderr, ": %s id %d",
191 qxl_name(qxl_surface_cmd, cmd->type),
192 cmd->surface_id);
193 if (cmd->type == QXL_SURFACE_CMD_CREATE) {
194 fprintf(stderr, " size %dx%d stride %d format %s (count %d, max %d)",
195 cmd->u.surface_create.width,
196 cmd->u.surface_create.height,
197 cmd->u.surface_create.stride,
198 qxl_name(spice_surface_fmt, cmd->u.surface_create.format),
199 qxl->guest_surfaces.count, qxl->guest_surfaces.max);
201 if (cmd->type == QXL_SURFACE_CMD_DESTROY) {
202 fprintf(stderr, " (count %d)", qxl->guest_surfaces.count);
206 int qxl_log_cmd_cursor(PCIQXLDevice *qxl, QXLCursorCmd *cmd, int group_id)
208 QXLCursor *cursor;
210 fprintf(stderr, ": %s",
211 qxl_name(qxl_cursor_cmd, cmd->type));
212 switch (cmd->type) {
213 case QXL_CURSOR_SET:
214 fprintf(stderr, " +%d+%d visible %s, shape @ 0x%" PRIx64,
215 cmd->u.set.position.x,
216 cmd->u.set.position.y,
217 cmd->u.set.visible ? "yes" : "no",
218 cmd->u.set.shape);
219 cursor = qxl_phys2virt(qxl, cmd->u.set.shape, group_id);
220 if (!cursor) {
221 return 1;
223 fprintf(stderr, " type %s size %dx%d hot-spot +%d+%d"
224 " unique 0x%" PRIx64 " data-size %d",
225 qxl_name(spice_cursor_type, cursor->header.type),
226 cursor->header.width, cursor->header.height,
227 cursor->header.hot_spot_x, cursor->header.hot_spot_y,
228 cursor->header.unique, cursor->data_size);
229 break;
230 case QXL_CURSOR_MOVE:
231 fprintf(stderr, " +%d+%d", cmd->u.position.x, cmd->u.position.y);
232 break;
234 return 0;
237 int qxl_log_command(PCIQXLDevice *qxl, const char *ring, QXLCommandExt *ext)
239 bool compat = ext->flags & QXL_COMMAND_FLAG_COMPAT;
240 void *data;
241 int ret;
243 if (!qxl->cmdlog) {
244 return 0;
246 fprintf(stderr, "%" PRId64 " qxl-%d/%s:", qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
247 qxl->id, ring);
248 fprintf(stderr, " cmd @ 0x%" PRIx64 " %s%s", ext->cmd.data,
249 qxl_name(qxl_type, ext->cmd.type),
250 compat ? "(compat)" : "");
252 data = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id);
253 if (!data) {
254 return 1;
256 switch (ext->cmd.type) {
257 case QXL_CMD_DRAW:
258 if (!compat) {
259 ret = qxl_log_cmd_draw(qxl, data, ext->group_id);
260 } else {
261 ret = qxl_log_cmd_draw_compat(qxl, data, ext->group_id);
263 if (ret) {
264 return ret;
266 break;
267 case QXL_CMD_SURFACE:
268 qxl_log_cmd_surface(qxl, data);
269 break;
270 case QXL_CMD_CURSOR:
271 qxl_log_cmd_cursor(qxl, data, ext->group_id);
272 break;
274 fprintf(stderr, "\n");
275 return 0;