summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/cursor.cpp18
-rw-r--r--client/cursor_channel.cpp6
-rw-r--r--client/glz_decoder_config.h4
-rw-r--r--client/utils.h5
-rw-r--r--client/windows/red_pixmap.cpp2
-rw-r--r--client/x11/red_pixmap.cpp2
-rw-r--r--common/canvas_base.c23
-rw-r--r--common/canvas_utils.c14
-rw-r--r--common/glc.c4
-rw-r--r--common/lines.c17
-rw-r--r--common/lz_config.h10
-rw-r--r--common/pixman_utils.c9
-rw-r--r--common/quic.c6
-rw-r--r--common/rect.h4
-rw-r--r--common/region.c7
-rw-r--r--server/glz_encoder_config.h4
-rw-r--r--server/red_common.h23
-rw-r--r--server/red_tunnel_worker.c36
-rw-r--r--server/red_worker.c113
-rw-r--r--server/reds.c4
-rw-r--r--server/snd_worker.c16
-rw-r--r--tools/bitmap_to_c.c7
-rw-r--r--tools/icon_to_c.c13
23 files changed, 128 insertions, 219 deletions
diff --git a/client/cursor.cpp b/client/cursor.cpp
index 7babdb90..60dc1dd7 100644
--- a/client/cursor.cpp
+++ b/client/cursor.cpp
@@ -34,29 +34,29 @@ CursorData::CursorData(SpiceCursor& cursor, int data_size)
expected_size = (_header.width << 2) * _header.height;
break;
case SPICE_CURSOR_TYPE_MONO:
- expected_size = (ALIGN(_header.width, 8) >> 2) * _header.height;
+ expected_size = (SPICE_ALIGN(_header.width, 8) >> 2) * _header.height;
break;
case SPICE_CURSOR_TYPE_COLOR4:
- expected_size = (ALIGN(_header.width, 2) >> 1) * _header.height;
- expected_size += (ALIGN(_header.width, 8) >> 3) * _header.height;
+ expected_size = (SPICE_ALIGN(_header.width, 2) >> 1) * _header.height;
+ expected_size += (SPICE_ALIGN(_header.width, 8) >> 3) * _header.height;
expected_size += 16 * sizeof(uint32_t);
break;
case SPICE_CURSOR_TYPE_COLOR8:
expected_size = _header.width * _header.height;
- expected_size += (ALIGN(_header.width, 8) >> 3) * _header.height;
+ expected_size += (SPICE_ALIGN(_header.width, 8) >> 3) * _header.height;
expected_size += 256 * sizeof(uint32_t);
break;
case SPICE_CURSOR_TYPE_COLOR16:
expected_size = (_header.width << 1) * _header.height;
- expected_size += (ALIGN(_header.width, 8) >> 3) * _header.height;
+ expected_size += (SPICE_ALIGN(_header.width, 8) >> 3) * _header.height;
break;
case SPICE_CURSOR_TYPE_COLOR24:
expected_size = (_header.width * 3) * _header.height;
- expected_size += (ALIGN(_header.width, 8) >> 3) * _header.height;
+ expected_size += (SPICE_ALIGN(_header.width, 8) >> 3) * _header.height;
break;
case SPICE_CURSOR_TYPE_COLOR32:
expected_size = (_header.width << 2) * _header.height;
- expected_size += (ALIGN(_header.width, 8) >> 3) * _header.height;
+ expected_size += (SPICE_ALIGN(_header.width, 8) >> 3) * _header.height;
break;
}
@@ -92,10 +92,10 @@ int LocalCursor::get_size_bits(const SpiceCursorHeader& header, int& size)
size = (header.width << 2) * header.height;
return 32;
case SPICE_CURSOR_TYPE_MONO:
- size = (ALIGN(header.width, 8) >> 3) * header.height;
+ size = (SPICE_ALIGN(header.width, 8) >> 3) * header.height;
return 1;
case SPICE_CURSOR_TYPE_COLOR4:
- size = (ALIGN(header.width, 2) >> 1) * header.height;
+ size = (SPICE_ALIGN(header.width, 2) >> 1) * header.height;
return 4;
case SPICE_CURSOR_TYPE_COLOR8:
size = header.width * header.height;
diff --git a/client/cursor_channel.cpp b/client/cursor_channel.cpp
index 0909f5c6..63b76980 100644
--- a/client/cursor_channel.cpp
+++ b/client/cursor_channel.cpp
@@ -137,7 +137,7 @@ MonoCursor::MonoCursor(const SpiceCursorHeader& header, const uint8_t* data)
int dest_stride = _pixmap->get_stride();
uint8_t *dest_line = _pixmap->get_data();
- int src_stride = ALIGN(header.width, 8) >> 3;
+ int src_stride = SPICE_ALIGN(header.width, 8) >> 3;
const uint8_t* src_line = data;
const uint8_t* end_line = src_line + _pixmap->get_height() * src_stride;
@@ -188,7 +188,7 @@ ColorCursor::ColorCursor(const SpiceCursorHeader& header)
void ColorCursor::init_pixels(const SpiceCursorHeader& header, const uint8_t* pixels,
const uint8_t *and_mask)
{
- int mask_stride = ALIGN(header.width, 8) / 8;
+ int mask_stride = SPICE_ALIGN(header.width, 8) / 8;
int invers_stride = _invers->get_stride();
int pixmap_stride = _pixmap->get_stride();
uint8_t *_pixmap_line = _pixmap->get_data();
@@ -266,7 +266,7 @@ class ColorCursor4: public ColorCursor {
public:
ColorCursor4(const SpiceCursorHeader& header, const uint8_t* data)
: ColorCursor(header)
- , _src_stride (ALIGN(header.width, 2) >> 1)
+ , _src_stride (SPICE_ALIGN(header.width, 2) >> 1)
, _palette ((uint32_t*)(data + _src_stride * header.height))
{
init_pixels(header, data, (uint8_t*)(_palette + 16));
diff --git a/client/glz_decoder_config.h b/client/glz_decoder_config.h
index 3e820a5f..57358b23 100644
--- a/client/glz_decoder_config.h
+++ b/client/glz_decoder_config.h
@@ -26,9 +26,7 @@
#include <stdio.h>
#include <spice/types.h>
-
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
+#include <spice/macros.h>
class GlzException: public std::exception {
public:
diff --git a/client/utils.h b/client/utils.h
index 6ed3eea2..6145fb5d 100644
--- a/client/utils.h
+++ b/client/utils.h
@@ -20,10 +20,7 @@
#include "common.h"
#include <spice/error_codes.h>
-
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
+#include <spice/macros.h>
class Exception: public std::exception {
public:
diff --git a/client/windows/red_pixmap.cpp b/client/windows/red_pixmap.cpp
index bd9d7e41..6d65b46b 100644
--- a/client/windows/red_pixmap.cpp
+++ b/client/windows/red_pixmap.cpp
@@ -25,7 +25,7 @@ RedPixmap::RedPixmap(int width, int height, RedPixmap::Format format,
: _format (format)
, _width (width)
, _height (height)
- , _stride (ALIGN(width * (_format == RedPixmap::A1 ? 1: 32), 32) / 8)
+ , _stride (SPICE_ALIGN(width * (_format == RedPixmap::A1 ? 1: 32), 32) / 8)
, _top_bottom (top_bottom)
, _data (NULL)
{
diff --git a/client/x11/red_pixmap.cpp b/client/x11/red_pixmap.cpp
index 85a45515..8452596d 100644
--- a/client/x11/red_pixmap.cpp
+++ b/client/x11/red_pixmap.cpp
@@ -25,7 +25,7 @@ RedPixmap::RedPixmap(int width, int height, RedPixmap::Format format,
: _format (format)
, _width (width)
, _height (height)
- , _stride (ALIGN(width * (_format == RedPixmap::A1 ? 1 : 32), 32) / 8)
+ , _stride (SPICE_ALIGN(width * (_format == RedPixmap::A1 ? 1 : 32), 32) / 8)
, _top_bottom (top_bottom)
, _data (NULL)
{
diff --git a/common/canvas_base.c b/common/canvas_base.c
index 01df479b..cbe37fe5 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -23,6 +23,7 @@
#include <math.h>
#include <spice/draw.h>
+#include <spice/macros.h>
#include "quic.h"
#include "lz.h"
#include "canvas_base.h"
@@ -71,18 +72,6 @@
#define DBG(level, format, ...) printf("%s: debug: " format "\n", __FUNCTION__, ## __VA_ARGS__);
#endif
-#ifndef ALIGN
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-#endif
-
-#ifndef MIN
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#endif
-
-#ifndef MAX
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
-#endif
-
#define ROUND(_x) ((int)floor((_x) + 0.5))
#ifdef WIN32
@@ -1148,7 +1137,7 @@ static pixman_image_t *canvas_get_bitmap_mask(CanvasBase *canvas, SpiceBitmap* b
src_stride = bitmap->stride;
end_line = src_line + (bitmap->y * src_stride);
access_test(canvas, src_line, end_line - src_line);
- line_size = ALIGN(bitmap->x, 8) >> 3;
+ line_size = SPICE_ALIGN(bitmap->x, 8) >> 3;
dest_stride = pixman_image_get_stride(surface);
dest_line = (uint8_t *)pixman_image_get_data(surface);
@@ -1243,7 +1232,7 @@ static inline pixman_image_t *canvas_A1_invers(pixman_image_t *src_surf)
uint8_t *src_line = (uint8_t *)pixman_image_get_data(src_surf);
int src_stride = pixman_image_get_stride(src_surf);
uint8_t *end_line = src_line + (height * src_stride);
- int line_size = ALIGN(width, 8) >> 3;
+ int line_size = SPICE_ALIGN(width, 8) >> 3;
uint8_t *dest_line = (uint8_t *)pixman_image_get_data(invers);
int dest_stride = pixman_image_get_stride(invers);
@@ -1382,7 +1371,7 @@ static pixman_image_t *canvas_get_mask(CanvasBase *canvas, SpiceQMask *mask, int
static inline SpiceRasterGlyph *canvas_next_raster_glyph(const SpiceRasterGlyph *glyph, int bpp)
{
return (SpiceRasterGlyph *)((uint8_t *)(glyph + 1) +
- (ALIGN(glyph->width * bpp, 8) * glyph->height >> 3));
+ (SPICE_ALIGN(glyph->width * bpp, 8) * glyph->height >> 3));
}
static inline void canvas_raster_glyph_box(const SpiceRasterGlyph *glyph, SpiceRect *r)
@@ -1472,7 +1461,7 @@ static void canvas_put_glyph_bits(SpiceRasterGlyph *glyph, int bpp, uint8_t *des
width = glyph_box.right - glyph_box.left;
switch (bpp) {
case 1: {
- int src_stride = ALIGN(width, 8) >> 3;
+ int src_stride = SPICE_ALIGN(width, 8) >> 3;
int i;
src += src_stride * (lines);
@@ -1485,7 +1474,7 @@ static void canvas_put_glyph_bits(SpiceRasterGlyph *glyph, int bpp, uint8_t *des
}
case 4: {
uint8_t *end;
- int src_stride = ALIGN(width * 4, 8) >> 3;
+ int src_stride = SPICE_ALIGN(width * 4, 8) >> 3;
src += src_stride * lines;
dest += glyph_box.left;
diff --git a/common/canvas_utils.c b/common/canvas_utils.c
index 89ebe121..2ab8f0b6 100644
--- a/common/canvas_utils.c
+++ b/common/canvas_utils.c
@@ -18,6 +18,8 @@
#include "canvas_utils.h"
+#include <spice/macros.h>
+
#ifdef __GNUC__
#include <stdlib.h>
#include <stdio.h>
@@ -42,10 +44,6 @@ extern int gdi_handlers;
}
#endif
-#ifndef ALIGN
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-#endif
-
static void release_data(pixman_image_t *image, void *release_data)
{
PixmanData *data = (PixmanData *)release_data;
@@ -154,11 +152,11 @@ pixman_image_t * surface_create(pixman_format_code_t format, int width, int heig
break;
case PIXMAN_a8:
bitmap_info.inf.bmiHeader.biBitCount = 8;
- nstride = ALIGN(width, 4);
+ nstride = SPICE_ALIGN(width, 4);
break;
case PIXMAN_a1:
bitmap_info.inf.bmiHeader.biBitCount = 1;
- nstride = ALIGN(width, 32) / 8;
+ nstride = SPICE_ALIGN(width, 32) / 8;
break;
default:
CANVAS_ERROR("invalid format");
@@ -208,10 +206,10 @@ pixman_image_t * surface_create(pixman_format_code_t format, int width, int heig
stride = width * 4;
break;
case PIXMAN_a8:
- stride = ALIGN(width, 4);
+ stride = SPICE_ALIGN(width, 4);
break;
case PIXMAN_a1:
- stride = ALIGN(width, 32) / 8;
+ stride = SPICE_ALIGN(width, 32) / 8;
break;
default:
CANVAS_ERROR("invalid format");
diff --git a/common/glc.c b/common/glc.c
index 090dc03a..770da320 100644
--- a/common/glc.c
+++ b/common/glc.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
+#include <spice/macros.h>
#include <GL/gl.h>
#include <GL/glu.h>
@@ -37,9 +38,6 @@
#include "glc.h"
#include "gl_utils.h"
-#define TRUE 1
-#define FALSE 0
-
#define ASSERT(x) if (!(x)) {printf("%s: assert failed %s\n", __FUNCTION__, #x); abort();}
#define WARN_ONCE(x) { \
diff --git a/common/lines.c b/common/lines.c
index e02f3d67..5c07744c 100644
--- a/common/lines.c
+++ b/common/lines.c
@@ -48,6 +48,7 @@ SOFTWARE.
#include <stdio.h>
+#include <spice/macros.h>
#ifdef _XOPEN_SOURCE
#include <math.h>
#else
@@ -57,22 +58,6 @@ SOFTWARE.
#endif
#include "lines.h"
-#ifndef FALSE
-# define FALSE 0
-#endif
-
-#ifndef TRUE
-# define TRUE 1
-#endif
-
-#ifndef MIN
-# define MIN(a, b) ((a < b) ? a : b)
-#endif
-
-#ifndef MAX
-# define MAX(a, b) ((a > b) ? a : b)
-#endif
-
#define xalloc(i) malloc(i)
#define xrealloc(a,b) realloc(a,b)
#define xfree(i) free(i)
diff --git a/common/lz_config.h b/common/lz_config.h
index 4db6dc36..439f413c 100644
--- a/common/lz_config.h
+++ b/common/lz_config.h
@@ -22,15 +22,7 @@
#define __LZ_CONFIG_H
#include <spice/types.h>
-
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
+#include <spice/macros.h>
#ifdef __GNUC__
diff --git a/common/pixman_utils.c b/common/pixman_utils.c
index 7aff30b4..05ac03d7 100644
--- a/common/pixman_utils.c
+++ b/common/pixman_utils.c
@@ -17,19 +17,12 @@
*/
#include "pixman_utils.h"
+#include <spice/macros.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#ifndef FALSE
-# define FALSE 0
-#endif
-
-#ifndef TRUE
-# define TRUE 1
-#endif
-
#ifndef ASSERT
#define ASSERT(x) if (!(x)) { \
printf("%s: ASSERT %s failed\n", __FUNCTION__, #x); \
diff --git a/common/quic.c b/common/quic.c
index 507c4504..e9fef5b5 100644
--- a/common/quic.c
+++ b/common/quic.c
@@ -20,6 +20,7 @@
// http://sun.iinf.polsl.gliwice.pl/~rstaros/sfalic/index.html
#include "quic.h"
+#include <spice/macros.h>
//#define DEBUG
@@ -36,8 +37,6 @@
#define QUIC_VERSION_MINOR 1U
#define QUIC_VERSION ((QUIC_VERSION_MAJOR << 16) | (QUIC_VERSION_MAJOR & 0xffff))
-#define ABS(a) ((a) >= 0 ? (a) : -(a))
-
#ifdef DEBUG
#define ASSERT(usr, x) \
@@ -49,9 +48,6 @@
#endif
-#define FALSE 0
-#define TRUE 1
-
typedef uint8_t BYTE;
/* maximum number of codes in family */
diff --git a/common/rect.h b/common/rect.h
index 43e7f21a..1627be6a 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -20,9 +20,7 @@
#define _H_RECT
#include <spice/draw.h>
-
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
+#include <spice/macros.h>
static inline void rect_sect(SpiceRect* r, const SpiceRect* bounds)
{
diff --git a/common/region.c b/common/region.c
index 06b76d56..7edcb5a1 100644
--- a/common/region.c
+++ b/common/region.c
@@ -19,16 +19,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <spice/macros.h>
#include "region.h"
#include "rect.h"
-#define FALSE 0
-#define TRUE 1
-
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
-
#define ASSERT(x) if (!(x)) { \
printf("%s: ASSERT %s failed\n", __FUNCTION__, #x); \
abort(); \
diff --git a/server/glz_encoder_config.h b/server/glz_encoder_config.h
index a2b9b580..938949bc 100644
--- a/server/glz_encoder_config.h
+++ b/server/glz_encoder_config.h
@@ -18,6 +18,7 @@
#ifndef _H_GLZ_ENCODER_CONFIG
#define _H_GLZ_ENCODER_CONFIG
+#include <spice/macros.h>
#include "lz_common.h"
typedef void GlzUsrImageContext;
@@ -56,9 +57,6 @@ struct GlzEncoderUsrContext {
#define INLINE inline
-#define FALSE 0
-#define TRUE 1
-
#endif
diff --git a/server/red_common.h b/server/red_common.h
index 6a43dc3a..4a847483 100644
--- a/server/red_common.h
+++ b/server/red_common.h
@@ -22,21 +22,7 @@
#include <openssl/ssl.h>
#include <spice/protocol.h>
-
-#ifndef MIN
-#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
-#endif
-#ifndef MAX
-#define MAX(x, y) (((x) >= (y)) ? (x) : (y))
-#endif
-
-#ifndef ABS
-#define ABS(a) ((a) >= 0 ? (a) : -(a))
-#endif
-
-#ifndef ALIGN
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-#endif
+#include <spice/macros.h>
#define ASSERT(x) if (!(x)) { \
printf("%s: ASSERT %s failed\n", __FUNCTION__, #x); \
@@ -53,9 +39,6 @@
abort(); \
}
-#define TRUE 1
-#define FALSE 0
-
#define red_error(format, ...) { \
printf("%s: " format "\n", __FUNCTION__, ## __VA_ARGS__ ); \
abort(); \
@@ -79,10 +62,6 @@
} \
}
-#define OFFSETOF(type, member) ((unsigned long)&((type *)0)->member)
-#define CONTAINEROF(ptr, type, member) \
- ((type *)((uint8_t *)(ptr) - OFFSETOF(type, member)))
-
typedef enum {
IMAGE_COMPRESS_INVALID,
IMAGE_COMPRESS_AUTO_GLZ,
diff --git a/server/red_tunnel_worker.c b/server/red_tunnel_worker.c
index 9a8c11ef..f3374de6 100644
--- a/server/red_tunnel_worker.c
+++ b/server/red_tunnel_worker.c
@@ -1678,9 +1678,9 @@ static void tunnel_channel_release_msg_rcv_buf(RedChannel *channel, SpiceDataHea
{
TunnelChannel *tunnel_channel = (TunnelChannel *)channel;
if (msg_header->type == SPICE_MSGC_TUNNEL_SOCKET_DATA) {
- ASSERT(!(CONTAINEROF(msg, RedSocketRawRcvBuf, buf)->base.usr_opaque));
+ ASSERT(!(SPICE_CONTAINEROF(msg, RedSocketRawRcvBuf, buf)->base.usr_opaque));
__tunnel_worker_free_socket_rcv_buf(tunnel_channel->worker,
- CONTAINEROF(msg, RedSocketRawRcvBuf, buf));
+ SPICE_CONTAINEROF(msg, RedSocketRawRcvBuf, buf));
}
}
@@ -2324,7 +2324,7 @@ static int tunnel_channel_handle_message(RedChannel *channel, SpiceDataHeader *h
}
return tunnel_channel_handle_socket_receive_data(tunnel_channel, sckt,
- CONTAINEROF(msg, RedSocketRawRcvBuf, buf),
+ SPICE_CONTAINEROF(msg, RedSocketRawRcvBuf, buf),
header->size - sizeof(SpiceMsgcTunnelSocketData));
}
case SPICE_MSGC_TUNNEL_SOCKET_FIN:
@@ -2591,7 +2591,7 @@ static void tunnel_channel_send_init(TunnelChannel *channel, PipeItem *item)
static void tunnel_channel_send_service_ip_map(TunnelChannel *channel, PipeItem *item)
{
- TunnelService *service = CONTAINEROF(item, TunnelService, pipe_item);
+ TunnelService *service = SPICE_CONTAINEROF(item, TunnelService, pipe_item);
channel->send_data.u.service_ip.service_id = service->id;
channel->send_data.u.service_ip.virtual_ip.type = SPICE_TUNNEL_IP_TYPE_IPv4;
@@ -2605,8 +2605,8 @@ static void tunnel_channel_send_service_ip_map(TunnelChannel *channel, PipeItem
static void tunnel_channel_send_socket_open(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, status_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
channel->send_data.u.socket_open.connection_id = sckt->connection_id;
channel->send_data.u.socket_open.service_id = sckt->far_service->id;
@@ -2626,8 +2626,8 @@ static void tunnel_channel_send_socket_open(TunnelChannel *channel, PipeItem *it
static void tunnel_channel_send_socket_fin(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, status_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
ASSERT(!sckt->out_data.ready_chunks_queue.head);
@@ -2652,8 +2652,8 @@ static void tunnel_channel_send_socket_fin(TunnelChannel *channel, PipeItem *ite
static void tunnel_channel_send_socket_close(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, status_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
// can happen when it is a forced close
if (sckt->out_data.ready_chunks_queue.head) {
@@ -2684,8 +2684,8 @@ static void tunnel_channel_send_socket_close(TunnelChannel *channel, PipeItem *i
static void tunnel_channel_send_socket_closed_ack(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, status_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, status_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
channel->send_data.u.socket_close_ack.connection_id = sckt->connection_id;
@@ -2709,8 +2709,8 @@ static void tunnel_channel_send_socket_closed_ack(TunnelChannel *channel, PipeIt
static void tunnel_channel_send_socket_token(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, token_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, token_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
/* notice that the num of tokens sent can be > SOCKET_TOKENS_TO_SEND, since
the sending is performed after the pipe item was pushed */
@@ -2736,8 +2736,8 @@ static void tunnel_channel_send_socket_token(TunnelChannel *channel, PipeItem *i
static void tunnel_channel_send_socket_out_data(TunnelChannel *channel, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, data_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, data_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
ReadyTunneledChunk *chunk;
uint32_t total_push_size = 0;
uint32_t pushed_bufs_num = 0;
@@ -2792,8 +2792,8 @@ static void tunnel_channel_send_socket_out_data(TunnelChannel *channel, PipeItem
static void tunnel_worker_release_socket_out_data(TunnelWorker *worker, PipeItem *item)
{
- RedSocketOutData *sckt_out_data = CONTAINEROF(item, RedSocketOutData, data_pipe_item);
- RedSocket *sckt = CONTAINEROF(sckt_out_data, RedSocket, out_data);
+ RedSocketOutData *sckt_out_data = SPICE_CONTAINEROF(item, RedSocketOutData, data_pipe_item);
+ RedSocket *sckt = SPICE_CONTAINEROF(sckt_out_data, RedSocket, out_data);
ASSERT(sckt_out_data->ready_chunks_queue.head);
diff --git a/server/red_worker.c b/server/red_worker.c
index e8c986f6..1b8cd84d 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -1180,7 +1180,7 @@ static void cb_validate_virt(void *opaque, unsigned long virt, unsigned long fro
static void *op_get_virt_preload_group(SpiceVirtMapping *mapping, unsigned long addr, uint32_t add_size)
{
- RedWorker *worker = CONTAINEROF(mapping, RedWorker, preload_group_virt_mapping);
+ RedWorker *worker = SPICE_CONTAINEROF(mapping, RedWorker, preload_group_virt_mapping);
return (void *)get_virt(worker, addr, add_size,
worker->preload_group_id);
}
@@ -1188,7 +1188,7 @@ static void *op_get_virt_preload_group(SpiceVirtMapping *mapping, unsigned long
static void op_validate_virt_preload_group(SpiceVirtMapping *mapping, unsigned long virt,
unsigned long from_addr, uint32_t add_size)
{
- RedWorker *worker = CONTAINEROF(mapping, RedWorker, preload_group_virt_mapping);
+ RedWorker *worker = SPICE_CONTAINEROF(mapping, RedWorker, preload_group_virt_mapping);
int slot_id = get_memslot_id(worker, from_addr);
validate_virt(worker, virt, slot_id, add_size,
worker->preload_group_id);
@@ -1406,7 +1406,7 @@ static void red_pipe_clear(RedChannel *channel)
ring_remove(&item->link);
switch (item->type) {
case PIPE_ITEM_TYPE_DRAW:
- release_drawable(channel->worker, CONTAINEROF(item, Drawable, pipe_item));
+ release_drawable(channel->worker, SPICE_CONTAINEROF(item, Drawable, pipe_item));
break;
case PIPE_ITEM_TYPE_CURSOR:
red_release_cursor(channel->worker, (CursorItem *)item);
@@ -1432,14 +1432,14 @@ static void red_pipe_clear(RedChannel *channel)
break;
case PIPE_ITEM_TYPE_STREAM_CREATE:
red_display_release_stream((DisplayChannel *)channel,
- CONTAINEROF(item, StreamAgent, create_item));
+ SPICE_CONTAINEROF(item, StreamAgent, create_item));
break;
case PIPE_ITEM_TYPE_STREAM_CLIP:
red_display_release_stream_clip((DisplayChannel *)channel, (StreamClipItem*)item);
break;
case PIPE_ITEM_TYPE_STREAM_DESTROY:
red_display_release_stream((DisplayChannel *)channel,
- CONTAINEROF(item, StreamAgent, destroy_item));
+ SPICE_CONTAINEROF(item, StreamAgent, destroy_item));
break;
}
}
@@ -1655,14 +1655,14 @@ static inline void current_remove(RedWorker *worker, TreeItem *item)
if (now->type == TREE_ITEM_TYPE_DRAWABLE) {
ring_item = now->siblings_link.prev;
- remove_drawable(worker, CONTAINEROF(now, Drawable, tree_item));
+ remove_drawable(worker, SPICE_CONTAINEROF(now, Drawable, tree_item));
} else {
Container *container = (Container *)now;
ASSERT(now->type == TREE_ITEM_TYPE_CONTAINER);
if ((ring_item = ring_get_head(&container->items))) {
- now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
continue;
}
ring_item = now->siblings_link.prev;
@@ -1673,7 +1673,7 @@ static inline void current_remove(RedWorker *worker, TreeItem *item)
}
if ((ring_item = ring_next(&container->items, ring_item))) {
- now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
} else {
now = (TreeItem *)container;
}
@@ -1692,7 +1692,7 @@ static void current_tree_for_each(RedWorker *worker, void (*f)(TreeItem *, void
top_ring = ring;
for (;;) {
- TreeItem *now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ TreeItem *now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
f(now, data);
@@ -1723,7 +1723,7 @@ static void red_current_clear(RedWorker *worker)
RingItem *ring_item;
while ((ring_item = ring_get_head(&worker->current))) {
- TreeItem *now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ TreeItem *now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
current_remove(worker, now);
}
}
@@ -1753,7 +1753,7 @@ static void print_rgn(const char* prefix, const QRegion* rgn)
static void print_draw_item(const char* prefix, const DrawItem *draw_item)
{
const TreeItem *base = &draw_item->base;
- const Drawable *drawable = CONTAINEROF(draw_item, Drawable, tree_item);
+ const Drawable *drawable = SPICE_CONTAINEROF(draw_item, Drawable, tree_item);
printf("TEST: %s: draw id %u container %u effect %u",
prefix,
base->id, base->container ? base->container->base.id : 0,
@@ -1889,7 +1889,7 @@ static inline void __exclude_region(RedWorker *worker, TreeItem *item, QRegion *
}
} else {
if (frame_candidate) {
- Drawable *drawable = CONTAINEROF(draw, Drawable, tree_item);
+ Drawable *drawable = SPICE_CONTAINEROF(draw, Drawable, tree_item);
red_stream_maintenance(worker, frame_candidate, drawable);
}
region_exclude(&draw->base.rgn, &and_rgn);
@@ -1938,7 +1938,7 @@ static void exclude_region(RedWorker *worker, Ring *ring, RingItem *ring_item, Q
top_ring = ring;
for (;;) {
- TreeItem *now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ TreeItem *now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
Container *container = now->container;
ASSERT(!region_is_empty(&now->rgn));
@@ -2001,7 +2001,7 @@ static void exclude_region(RedWorker *worker, Ring *ring, RingItem *ring_item, Q
top_ring = ring;
for (;;) {
- TreeItem *now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ TreeItem *now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
Container *container = now->container;
ASSERT(!region_is_empty(&now->rgn));
@@ -2394,7 +2394,7 @@ static void red_detach_streams_behind(RedWorker *worker, QRegion *region)
DisplayChannel *channel = worker->display_channel;
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
item = ring_next(ring, item);
if (channel) {
@@ -2420,7 +2420,7 @@ static void red_stop_streams_behind(RedWorker *worker, QRegion *region)
RingItem *item = ring_get_head(ring);
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
stream->refs++;
if (stream->current && region_intersects(region, &stream->current->tree_item.base.rgn)) {
red_stop_stream_gracefully(worker, stream);
@@ -2446,7 +2446,7 @@ static void red_streams_update_clip(RedWorker *worker, Drawable *drawable)
item = ring_get_head(ring);
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
StreamAgent *agent;
item = ring_next(ring, item);
@@ -2476,7 +2476,7 @@ static inline unsigned int red_get_streams_timout(RedWorker *worker)
while ((item = ring_next(ring, item))) {
Stream *stream;
- stream = CONTAINEROF(item, Stream, link);
+ stream = SPICE_CONTAINEROF(item, Stream, link);
#ifdef STREAM_TRACE
red_time_t delta = (stream->last_time + RED_STREAM_TIMOUT) - now;
@@ -2507,7 +2507,7 @@ static inline void red_handle_streams_timout(RedWorker *worker)
red_time_t now = timespec_to_red_time(&time);
item = ring_get_head(ring);
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
#ifdef STREAM_TRACE
item = ring_next(ring, item);
if (now >= (stream->last_time + RED_STREAM_TIMOUT)) {
@@ -2628,8 +2628,8 @@ static void red_create_stream(RedWorker *worker, Drawable *drawable)
ASSERT(drawable->qxl_drawable->type == QXL_DRAW_COPY);
src_rect = &drawable->qxl_drawable->u.copy.src_area;
- stream_width = ALIGN(src_rect->right - src_rect->left, 2);
- stream_height = ALIGN(src_rect->bottom - src_rect->top, 2);
+ stream_width = SPICE_ALIGN(src_rect->right - src_rect->left, 2);
+ stream_height = SPICE_ALIGN(src_rect->bottom - src_rect->top, 2);
if (!(av_ctx = red_init_video_encoder(stream_width, stream_height))) {
goto error_1;
@@ -2699,7 +2699,7 @@ static void red_disply_start_streams(DisplayChannel *display_channel)
RingItem *item = ring;
while ((item = ring_next(ring, item))) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
red_dispaly_create_stream(display_channel, stream);
}
}
@@ -2850,8 +2850,8 @@ static void reset_rate(StreamAgent *stream_agent)
return;
}
- int stream_width = ALIGN(stream->width, 2);
- int stream_height = ALIGN(stream->height, 2);
+ int stream_width = SPICE_ALIGN(stream->width, 2);
+ int stream_height = SPICE_ALIGN(stream->height, 2);
new_ctx = red_init_video_encoder(stream_width, stream_height);
if (!new_ctx) {
@@ -3030,8 +3030,8 @@ static inline int red_current_add_equal(RedWorker *worker, DrawItem *item, TreeI
return FALSE;
}
- drawable = CONTAINEROF(item, Drawable, tree_item);
- other_drawable = CONTAINEROF(other_draw_item, Drawable, tree_item);
+ drawable = SPICE_CONTAINEROF(item, Drawable, tree_item);
+ other_drawable = SPICE_CONTAINEROF(other_draw_item, Drawable, tree_item);
if (item->effect == QXL_EFFECT_OPAQUE) {
int add_after = !!other_drawable->stream;
@@ -3091,7 +3091,7 @@ static inline void red_use_stream_trace(RedWorker *worker, Drawable *drawable)
item = ring_get_head(ring);
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
if (!stream->current && __red_is_next_stream_frame(worker,
drawable,
stream->width,
@@ -3124,7 +3124,7 @@ static void red_reset_stream_trace(RedWorker *worker)
RingItem *item = ring_get_head(ring);
while (item) {
- Stream *stream = CONTAINEROF(item, Stream, link);
+ Stream *stream = SPICE_CONTAINEROF(item, Stream, link);
item = ring_next(ring, item);
if (!stream->current) {
red_stop_stream(worker, stream);
@@ -3157,7 +3157,7 @@ static inline int red_current_add(RedWorker *worker, Drawable *drawable)
now = ring_next(ring, ring);
while (now) {
- TreeItem *sibling = CONTAINEROF(now, TreeItem, siblings_link);
+ TreeItem *sibling = SPICE_CONTAINEROF(now, TreeItem, siblings_link);
int test_res;
if (!region_bounds_intersects(&item->base.rgn, &sibling->rgn)) {
@@ -3295,7 +3295,7 @@ static inline int red_current_add(RedWorker *worker, Drawable *drawable)
now = ring_next(ring, ring);
while (now) {
- TreeItem *sibling = CONTAINEROF(now, TreeItem, siblings_link);
+ TreeItem *sibling = SPICE_CONTAINEROF(now, TreeItem, siblings_link);
int test_res;
if (!region_bounds_intersects(&item->base.rgn, &sibling->rgn)) {
@@ -3592,7 +3592,7 @@ static void free_one_drawable(RedWorker *worker, int force_glz_free)
Container *container;
ASSERT(ring_item);
- drawable = CONTAINEROF(ring_item, Drawable, list_link);
+ drawable = SPICE_CONTAINEROF(ring_item, Drawable, list_link);
if (drawable->red_glz_drawable && force_glz_free) {
ASSERT(worker->display_channel);
red_display_free_glz_drawable(worker->display_channel, drawable->red_glz_drawable);
@@ -3655,8 +3655,9 @@ static inline void red_process_drawable(RedWorker *worker, QXLDrawable *drawable
if (drawable->clip.type == SPICE_CLIP_TYPE_RECTS) {
QRegion rgn;
- region_init(&rgn);
- add_clip_rects(worker, &rgn, drawable->clip.data + OFFSETOF(QXLClipRects, chunk), group_id);
+ region_init(&
+ rgn);
+ add_clip_rects(worker, &rgn, drawable->clip.data + SPICE_OFFSETOF(QXLClipRects, chunk), group_id);
region_and(&item->tree_item.base.rgn, &rgn);
region_destroy(&rgn);
} else if (drawable->clip.type == SPICE_CLIP_TYPE_PATH) {
@@ -4314,11 +4315,11 @@ static inline void __red_collect_for_update(RedWorker *worker, Ring *ring, RingI
Ring *top_ring = ring;
for (;;) {
- TreeItem *now = CONTAINEROF(ring_item, TreeItem, siblings_link);
+ TreeItem *now = SPICE_CONTAINEROF(ring_item, TreeItem, siblings_link);
Container *container = now->container;
if (region_intersects(rgn, &now->rgn)) {
if (IS_DRAW_ITEM(now)) {
- Drawable *drawable = CONTAINEROF(now, Drawable, tree_item);
+ Drawable *drawable = SPICE_CONTAINEROF(now, Drawable, tree_item);
ring_add(items, &drawable->collect_link);
region_or(rgn, &now->rgn);
@@ -4326,7 +4327,7 @@ static inline void __red_collect_for_update(RedWorker *worker, Ring *ring, RingI
region_or(rgn, &drawable->tree_item.shadow->base.rgn);
}
} else if (now->type == TREE_ITEM_TYPE_SHADOW) {
- Drawable *owner = CONTAINEROF(((Shadow *)now)->owner, Drawable, tree_item);
+ Drawable *owner = SPICE_CONTAINEROF(((Shadow *)now)->owner, Drawable, tree_item);
if (!ring_item_is_linked(&owner->collect_link)) {
region_or(rgn, &now->rgn);
region_or(rgn, &owner->tree_item.base.rgn);
@@ -4375,7 +4376,7 @@ static void red_update_area(RedWorker *worker, const SpiceRect *area)
region_destroy(&rgn);
while ((ring_item = ring_get_head(&items))) {
- Drawable *drawable = CONTAINEROF(ring_item, Drawable, collect_link);
+ Drawable *drawable = SPICE_CONTAINEROF(ring_item, Drawable, collect_link);
Container *container;
ring_remove(ring_item);
@@ -4400,7 +4401,7 @@ static void red_update_area(RedWorker *worker, const SpiceRect *area)
region_init(&rgn);
region_add(&rgn, area);
while ((ring_item = ring_next(ring, ring_item))) {
- now = CONTAINEROF(ring_item, Drawable, list_link);
+ now = SPICE_CONTAINEROF(ring_item, Drawable, list_link);
if (region_intersects(&rgn, &now->tree_item.base.rgn)) {
last = now;
break;
@@ -4417,7 +4418,7 @@ static void red_update_area(RedWorker *worker, const SpiceRect *area)
Container *container;
ring_item = ring_get_tail(&worker->current_list);
- now = CONTAINEROF(ring_item, Drawable, list_link);
+ now = SPICE_CONTAINEROF(ring_item, Drawable, list_link);
red_draw_drawable(worker, now);
container = now->tree_item.base.container;
current_remove_drawable(worker, now);
@@ -4974,7 +4975,7 @@ static void red_display_handle_glz_drawables_to_free(DisplayChannel* channel)
pthread_mutex_lock(&channel->glz_drawables_inst_to_free_lock);
while ((ring_link = ring_get_head(&channel->glz_drawables_inst_to_free))) {
- GlzDrawableInstanceItem *drawable_instance = CONTAINEROF(ring_link,
+ GlzDrawableInstanceItem *drawable_instance = SPICE_CONTAINEROF(ring_link,
GlzDrawableInstanceItem,
free_link);
red_display_free_glz_drawable_instance(channel, drawable_instance);
@@ -4997,7 +4998,7 @@ static void red_display_free_glz_drawable(DisplayChannel *channel, RedGlzDrawabl
/* Last instance: red_display_free_glz_drawable_instance will free the drawable */
cont = FALSE;
}
- GlzDrawableInstanceItem *instance = CONTAINEROF(head_instance,
+ GlzDrawableInstanceItem *instance = SPICE_CONTAINEROF(head_instance,
GlzDrawableInstanceItem,
glz_link);
if (!ring_item_is_linked(&instance->free_link)) {
@@ -5028,7 +5029,7 @@ static void red_display_clear_glz_drawables(DisplayChannel *channel)
pthread_rwlock_wrlock(&channel->glz_dict->encode_lock);
while ((ring_link = ring_get_head(&channel->glz_drawables))) {
- RedGlzDrawable *drawable = CONTAINEROF(ring_link, RedGlzDrawable, link);
+ RedGlzDrawable *drawable = SPICE_CONTAINEROF(ring_link, RedGlzDrawable, link);
// no need to lock the to_free list, since we assured no other thread is encoding and
// thus not other thread access the to_free list of the channel
red_display_free_glz_drawable(channel, drawable);
@@ -5051,7 +5052,7 @@ static int red_display_free_some_independent_glz_drawables(DisplayChannel *chann
RingItem *ring_link = ring_get_head(&channel->glz_drawables);
while ((n < RED_RELEASE_BUNCH_SIZE) && (ring_link != NULL)) {
- RedGlzDrawable *glz_drawable = CONTAINEROF(ring_link, RedGlzDrawable, link);
+ RedGlzDrawable *glz_drawable = SPICE_CONTAINEROF(ring_link, RedGlzDrawable, link);
ring_link = ring_next(&channel->glz_drawables, ring_link);
if (!glz_drawable->drawable) {
red_display_free_glz_drawable(channel, glz_drawable);
@@ -5324,7 +5325,7 @@ static void glz_usr_free_image(GlzEncoderUsrContext *usr, GlzUsrImageContext *im
GlzData *lz_data = (GlzData *)usr;
GlzDrawableInstanceItem *glz_drawable_instance = (GlzDrawableInstanceItem *)image;
DisplayChannel *drawable_channel = glz_drawable_instance->red_glz_drawable->display_channel;
- DisplayChannel *this_channel = CONTAINEROF(lz_data, DisplayChannel, glz_data);
+ DisplayChannel *this_channel = SPICE_CONTAINEROF(lz_data, DisplayChannel, glz_data);
if (this_channel == drawable_channel) {
red_display_free_glz_drawable_instance(drawable_channel, glz_drawable_instance);
} else {
@@ -5524,12 +5525,12 @@ static inline int _stride_is_extra(SpiceBitmap *bitmap)
return (bitmap->x < bitmap->stride);
case SPICE_BITMAP_FMT_4BIT_BE:
case SPICE_BITMAP_FMT_4BIT_LE: {
- int bytes_width = ALIGN(bitmap->x, 2) >> 1;
+ int bytes_width = SPICE_ALIGN(bitmap->x, 2) >> 1;
return bytes_width < bitmap->stride;
}
case SPICE_BITMAP_FMT_1BIT_BE:
case SPICE_BITMAP_FMT_1BIT_LE: {
- int bytes_width = ALIGN(bitmap->x, 8) >> 3;
+ int bytes_width = SPICE_ALIGN(bitmap->x, 8) >> 3;
return bytes_width < bitmap->stride;
}
default:
@@ -6993,8 +6994,8 @@ static void red_display_send_stream_start(DisplayChannel *display_channel, Strea
stream_create->src_width = stream->width;
stream_create->src_height = stream->height;
- stream_create->stream_width = ALIGN(stream_create->src_width, 2);
- stream_create->stream_height = ALIGN(stream_create->src_height, 2);
+ stream_create->stream_width = SPICE_ALIGN(stream_create->src_width, 2);
+ stream_create->stream_height = SPICE_ALIGN(stream_create->src_height, 2);
stream_create->dest = stream->dest_area;
add_buf(channel, BUF_TYPE_RAW, stream_create, sizeof(*stream_create), 0, 0);
@@ -7178,7 +7179,7 @@ static void display_channel_push(RedWorker *worker)
red_display_reset_send_data(display_channel);
switch (pipe_item->type) {
case PIPE_ITEM_TYPE_DRAW: {
- Drawable *drawable = CONTAINEROF(pipe_item, Drawable, pipe_item);
+ Drawable *drawable = SPICE_CONTAINEROF(pipe_item, Drawable, pipe_item);
send_qxl_drawable(display_channel, drawable);
release_drawable(worker, drawable);
break;
@@ -7188,7 +7189,7 @@ static void display_channel_push(RedWorker *worker)
free(pipe_item);
break;
case PIPE_ITEM_TYPE_STREAM_CREATE: {
- StreamAgent *agent = CONTAINEROF(pipe_item, StreamAgent, create_item);
+ StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, create_item);
red_display_send_stream_start(display_channel, agent);
red_display_release_stream(display_channel, agent);
break;
@@ -7200,7 +7201,7 @@ static void display_channel_push(RedWorker *worker)
break;
}
case PIPE_ITEM_TYPE_STREAM_DESTROY: {
- StreamAgent *agent = CONTAINEROF(pipe_item, StreamAgent, destroy_item);
+ StreamAgent *agent = SPICE_CONTAINEROF(pipe_item, StreamAgent, destroy_item);
red_display_send_stream_end(display_channel, agent);
red_display_release_stream(display_channel, agent);
break;
@@ -7329,7 +7330,7 @@ static void __show_tree_call(TreeItem *item, void *data)
switch (item->type) {
case TREE_ITEM_TYPE_DRAWABLE: {
- Drawable *drawable = CONTAINEROF(item, Drawable, tree_item);
+ Drawable *drawable = SPICE_CONTAINEROF(item, Drawable, tree_item);
const int max_indent = 200;
char indent_str[max_indent + 1];
int indent_str_len;
@@ -8163,7 +8164,7 @@ static void display_channel_hold_item(void *item)
switch (((PipeItem *)item)->type) {
case PIPE_ITEM_TYPE_DRAW:
case PIPE_ITEM_TYPE_STREAM_CREATE:
- CONTAINEROF(item, Drawable, pipe_item)->refs++;
+ SPICE_CONTAINEROF(item, Drawable, pipe_item)->refs++;
break;
case PIPE_ITEM_TYPE_STREAM_CLIP:
((StreamClipItem *)item)->refs++;
@@ -8185,7 +8186,7 @@ static void display_channel_release_item(RedChannel *channel, void *item)
switch (((PipeItem *)item)->type) {
case PIPE_ITEM_TYPE_DRAW:
case PIPE_ITEM_TYPE_STREAM_CREATE:
- release_drawable(channel->worker, CONTAINEROF(item, Drawable, pipe_item));
+ release_drawable(channel->worker, SPICE_CONTAINEROF(item, Drawable, pipe_item));
break;
case PIPE_ITEM_TYPE_STREAM_CLIP:
red_display_release_stream_clip((DisplayChannel *)channel, (StreamClipItem *)item);
@@ -8689,7 +8690,7 @@ static void inline red_create_mem_slots(RedWorker *worker)
static void handle_dev_input(EventListener *listener, uint32_t events)
{
- RedWorker *worker = CONTAINEROF(listener, RedWorker, dev_listener);
+ RedWorker *worker = SPICE_CONTAINEROF(listener, RedWorker, dev_listener);
RedWorkeMessage message;
read_message(worker->channel, &message);
@@ -9054,7 +9055,7 @@ static void dump_palette(FILE *f, SpicePalette* plt)
static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width, int row_size)
{
int i;
- int copy_bytes_size = ALIGN(n_pixel_bits * width, 8) / 8;
+ int copy_bytes_size = SPICE_ALIGN(n_pixel_bits * width, 8) / 8;
fwrite(line, 1, copy_bytes_size, f);
if (row_size > copy_bytes_size) {
diff --git a/server/reds.c b/server/reds.c
index 7b8d15b3..3375bf1c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1766,7 +1766,7 @@ static int main_channel_restore_vdi_wqueue(MainMigrateData *data, uint8_t *pos,
if (inf->port == VDP_SERVER_PORT) {
VDInternalBuf *buf;
- if (inf->len > sizeof(*buf) - OFFSETOF(VDInternalBuf, header)) {
+ if (inf->len > sizeof(*buf) - SPICE_OFFSETOF(VDInternalBuf, header)) {
red_printf("bad buffer len");
reds_disconnect();
return FALSE;
@@ -1786,7 +1786,7 @@ static int main_channel_restore_vdi_wqueue(MainMigrateData *data, uint8_t *pos,
VDAgentExtBuf *buf;
state->num_tokens--;
- if (inf->len > sizeof(*buf) - OFFSETOF(VDAgentExtBuf, buf)) {
+ if (inf->len > sizeof(*buf) - SPICE_OFFSETOF(VDAgentExtBuf, buf)) {
red_printf("bad buffer len");
reds_disconnect();
return FALSE;
diff --git a/server/snd_worker.c b/server/snd_worker.c
index 3046bd1b..d9e5b625 100644
--- a/server/snd_worker.c
+++ b/server/snd_worker.c
@@ -842,7 +842,7 @@ static void snd_set_command(SndChannel *channel, uint32_t command)
static void snd_playback_start(PlaybackPlug *plug)
{
- PlaybackChannel *playback_channel = CONTAINEROF(plug, PlaybackChannel, plug);
+ PlaybackChannel *playback_channel = SPICE_CONTAINEROF(plug, PlaybackChannel, plug);
ASSERT(!playback_channel->base.active);
reds_desable_mm_timer();
@@ -857,7 +857,7 @@ static void snd_playback_start(PlaybackPlug *plug)
static void snd_playback_stop(PlaybackPlug *plug)
{
- PlaybackChannel *playback_channel = CONTAINEROF(plug, PlaybackChannel, plug);
+ PlaybackChannel *playback_channel = SPICE_CONTAINEROF(plug, PlaybackChannel, plug);
ASSERT(playback_channel->base.active);
reds_enable_mm_timer();
@@ -880,7 +880,7 @@ static void snd_playback_stop(PlaybackPlug *plug)
static void snd_playback_get_frame(PlaybackPlug *plug, uint32_t **frame, uint32_t *num_samples)
{
- PlaybackChannel *playback_channel = CONTAINEROF(plug, PlaybackChannel, plug);
+ PlaybackChannel *playback_channel = SPICE_CONTAINEROF(plug, PlaybackChannel, plug);
ASSERT(playback_channel->base.active);
if (!playback_channel->free_frames) {
@@ -896,7 +896,7 @@ static void snd_playback_get_frame(PlaybackPlug *plug, uint32_t **frame, uint32_
static void snd_playback_put_frame(PlaybackPlug *plug, uint32_t *samples)
{
- PlaybackChannel *playback_channel = CONTAINEROF(plug, PlaybackChannel, plug);
+ PlaybackChannel *playback_channel = SPICE_CONTAINEROF(plug, PlaybackChannel, plug);
AudioFrame *frame;
ASSERT(playback_channel->base.active);
@@ -904,7 +904,7 @@ static void snd_playback_put_frame(PlaybackPlug *plug, uint32_t *samples)
if (playback_channel->pending_frame) {
snd_playback_free_frame(playback_channel, playback_channel->pending_frame);
}
- frame = CONTAINEROF(samples, AudioFrame, samples);
+ frame = SPICE_CONTAINEROF(samples, AudioFrame, samples);
frame->time = reds_get_mm_time();
red_dispatcher_set_mm_time(frame->time);
playback_channel->pending_frame = frame;
@@ -1015,7 +1015,7 @@ static void snd_record_migrate(Channel *channel)
static void snd_record_start(RecordPlug *plug)
{
- RecordChannel *record_channel = CONTAINEROF(plug, RecordChannel, plug);
+ RecordChannel *record_channel = SPICE_CONTAINEROF(plug, RecordChannel, plug);
ASSERT(!record_channel->base.active);
record_channel->base.active = TRUE;
@@ -1031,7 +1031,7 @@ static void snd_record_start(RecordPlug *plug)
static void snd_record_stop(RecordPlug *plug)
{
- RecordChannel *record_channel = CONTAINEROF(plug, RecordChannel, plug);
+ RecordChannel *record_channel = SPICE_CONTAINEROF(plug, RecordChannel, plug);
ASSERT(record_channel->base.active);
record_channel->base.active = FALSE;
@@ -1045,7 +1045,7 @@ static void snd_record_stop(RecordPlug *plug)
static uint32_t snd_record_read(RecordPlug *plug, uint32_t num_samples, uint32_t *samples)
{
- RecordChannel *record_channel = CONTAINEROF(plug, RecordChannel, plug);
+ RecordChannel *record_channel = SPICE_CONTAINEROF(plug, RecordChannel, plug);
uint32_t read_pos;
uint32_t now;
uint32_t len;
diff --git a/tools/bitmap_to_c.c b/tools/bitmap_to_c.c
index e9cd4db2..c4e1df10 100644
--- a/tools/bitmap_to_c.c
+++ b/tools/bitmap_to_c.c
@@ -24,12 +24,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
+#include <spice/macros.h>
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-#define TRUE 1
-#define FALSE 0
-
#define TAB " "
#define ERROR(str) printf("%s: error: %s\n", prog_name, str); exit(-1);
@@ -143,7 +140,7 @@ static Pixmap *init_bitmap(size_t input_size, uint8_t *buf)
if (file_header->header.bpp == 32) {
stride = file_header->header.width * sizeof(uint32_t);
} else if (file_header->header.bpp == 24) {
- stride = ALIGN(file_header->header.width * 3, 4);
+ stride = SPICE_ALIGN(file_header->header.width * 3, 4);
} else {
ERROR("unsupported bpp");
return NULL;
diff --git a/tools/icon_to_c.c b/tools/icon_to_c.c
index 6fd96fd0..d58995c9 100644
--- a/tools/icon_to_c.c
+++ b/tools/icon_to_c.c
@@ -24,17 +24,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
-
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-#define TRUE 1
-#define FALSE 0
+#include <spice/macros.h>
#define TAB " "
#define ERROR(str) printf("%s: error: %s\n", prog_name, str); exit(-1);
-#define ALIGN(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
-
static char *prog_name = NULL;
static size_t read_input(const char *file_name, uint8_t** out_buf)
@@ -166,7 +161,7 @@ static Icon *init_icon(uint8_t *buf, size_t buf_size)
}
if (!bitmap->image_size) {
- bitmap->image_size = ALIGN(bitmap->bpp * bitmap->width, 32) / 8 * bitmap->height;
+ bitmap->image_size = SPICE_ALIGN(bitmap->bpp * bitmap->width, 32) / 8 * bitmap->height;
}
if (bitmap->compression || bitmap->horizontal_resolution || bitmap->vertical_resolution ||
@@ -179,7 +174,7 @@ static Icon *init_icon(uint8_t *buf, size_t buf_size)
}
int pixmap_size = bitmap->width * sizeof(uint32_t) * ico->height;
- int mask_size = ALIGN(bitmap->width, 8) / 8 * ico->height;
+ int mask_size = SPICE_ALIGN(bitmap->width, 8) / 8 * ico->height;
Icon* icon = malloc(sizeof(*icon) + pixmap_size + mask_size);
icon->width = ico->width;
icon->height = ico->height;
@@ -223,7 +218,7 @@ static int icon_to_c_struct(const Icon *icon, const char *dest_file, const char
}
uint32_t pixmap_stride = icon->width * sizeof(uint32_t);
uint32_t pixmap_size = pixmap_stride * icon->height;
- uint32_t mask_stride = ALIGN(icon->width, 8) / 8;
+ uint32_t mask_stride = SPICE_ALIGN(icon->width, 8) / 8;
uint32_t mask_size = mask_stride * icon->height;
fprintf(f, "static const struct {\n"
TAB "uint32_t width;\n"