[Spice-devel] [PATCH 3/8] autotools: correctly build canvas-related code

Christophe Fergeau cfergeau at redhat.com
Thu Apr 21 05:00:17 PDT 2011


spice client and spice server shares code from
common/{gdi,gl,sw}_canvas.[ch]. However, while most of the code is
shared, the server code wants a canvas compiled with
SW_CANVAS_IMAGE_CACHE defined while the client code wants a canvas
compiled with SW_CANVAS_CACHE.

The initial autotools refactoring didn't take that into account,
this is now fixed by this commit. After this commit, the canvas
files from common/ are no longer compiled as part of the
libspice-common.la convenience library. Instead, there are "proxy"
canvas source files in client/ and server/ which #include the
appropriate C files after defining the relevant #define for the
binary that is being built.

To prevent misuse of the canvas c files and headers in common/,
SPICE_CANVAS_INTERNAL must be set when including the canvas headers
from common/ or when building the c files from common/ otherwise
the build will error out.
---
 client/Makefile.am        |    2 +-
 client/application.cpp    |    6 ++++--
 client/canvas.h           |    1 -
 client/glz_decoder.h      |    2 +-
 client/jpeg_decoder.h     |    2 +-
 client/red_canvas_base.h  |   26 ++++++++++++++++++++++++++
 client/red_gdi_canvas.cpp |    6 ++++++
 client/red_gdi_canvas.h   |    4 ++++
 client/red_gl_canvas.cpp  |    6 ++++++
 client/red_gl_canvas.h    |    5 +++++
 client/red_sw_canvas.cpp  |    6 ++++++
 client/red_sw_canvas.h    |    4 ++++
 client/zlib_decoder.h     |    2 +-
 common/Makefile.am        |   20 +++++++-------------
 common/canvas_base.c      |    4 ++++
 common/canvas_base.h      |    3 +++
 common/gdi_canvas.c       |    5 +++++
 common/gdi_canvas.h       |    4 ++++
 common/gl_canvas.c        |    5 ++++-
 common/gl_canvas.h        |    4 ++++
 common/sw_canvas.c        |    4 ++++
 common/sw_canvas.h        |    4 ++++
 server/Makefile.am        |   10 +++++++++-
 server/red_dispatcher.c   |    4 ++--
 server/red_worker.c       |    4 ++--
 server/reds_gl_canvas.c   |   24 ++++++++++++++++++++++++
 server/reds_gl_canvas.h   |   27 +++++++++++++++++++++++++++
 server/reds_sw_canvas.c   |   24 ++++++++++++++++++++++++
 server/reds_sw_canvas.h   |   26 ++++++++++++++++++++++++++
 29 files changed, 218 insertions(+), 26 deletions(-)
 create mode 100644 client/red_canvas_base.h
 create mode 100644 server/reds_gl_canvas.c
 create mode 100644 server/reds_gl_canvas.h
 create mode 100644 server/reds_sw_canvas.c
 create mode 100644 server/reds_sw_canvas.h

diff --git a/client/Makefile.am b/client/Makefile.am
index 627bd8a..2508267 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -77,6 +77,7 @@ spicec_SOURCES =		\
 	process_loop.h		\
 	read_write_mutex.h	\
 	record_channel.cpp	\
+	red_canvas_base.h	\
 	red_channel.cpp		\
 	red_channel.h		\
 	red_client.cpp		\
@@ -208,7 +209,6 @@ endif
 
 
 INCLUDES = \
-	-DSW_CANVAS_CACHE				\
 	-D__STDC_LIMIT_MACROS				\
 	-I$(top_srcdir)/client/x11			\
 	-I$(top_srcdir)/common				\
diff --git a/client/application.cpp b/client/application.cpp
index 292dae6..9e2c7e1 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -31,8 +31,10 @@
 #include "red_gdi_canvas.h"
 #endif
 #include "platform.h"
-#include "sw_canvas.h"
-#include "gl_canvas.h"
+#include "red_sw_canvas.h"
+#ifdef USE_OGL
+#include "red_gl_canvas.h"
+#endif
 #include "quic.h"
 #include "mutex.h"
 #include "cmd_line_parser.h"
diff --git a/client/canvas.h b/client/canvas.h
index 4844c31..0b8f2b6 100644
--- a/client/canvas.h
+++ b/client/canvas.h
@@ -25,7 +25,6 @@
 #include "messages.h"
 #include "cache.hpp"
 #include "shared_cache.hpp"
-#include "canvas_base.h"
 #include "canvas_utils.h"
 #include "glz_decoded_image.h"
 #include "glz_decoder.h"
diff --git a/client/glz_decoder.h b/client/glz_decoder.h
index f046f8c..35b0a3e 100644
--- a/client/glz_decoder.h
+++ b/client/glz_decoder.h
@@ -22,7 +22,7 @@
 #include "lz_common.h"
 #include "glz_decoder_config.h"
 #include "glz_decoder_window.h"
-#include "canvas_base.h"
+#include "red_canvas_base.h"
 
 class GlzDecodeHandler {
 public:
diff --git a/client/jpeg_decoder.h b/client/jpeg_decoder.h
index bd83b2e..34aa336 100644
--- a/client/jpeg_decoder.h
+++ b/client/jpeg_decoder.h
@@ -20,7 +20,7 @@
 #define _H_JPEG_DECODER
 
 #include "common.h"
-#include "canvas_base.h"
+#include "red_canvas_base.h"
 
 #ifdef WIN32
 /* We need some hacks to avoid warnings from the jpeg headers */
diff --git a/client/red_canvas_base.h b/client/red_canvas_base.h
new file mode 100644
index 0000000..bd59109
--- /dev/null
+++ b/client/red_canvas_base.h
@@ -0,0 +1,26 @@
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef _H_RED_CANVAS_BASE
+#define _H_RED_CANVAS_BASE
+
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
+#include "canvas_base.h"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
+#endif
diff --git a/client/red_gdi_canvas.cpp b/client/red_gdi_canvas.cpp
index 72b31df..2e0b453 100644
--- a/client/red_gdi_canvas.cpp
+++ b/client/red_gdi_canvas.cpp
@@ -23,6 +23,12 @@
 #include "region.h"
 #include "red_pixmap_gdi.h"
 
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
+#include "gdi_canvas.c"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
 GDICanvas::GDICanvas(int width, int height, uint32_t format,
 		     PixmapCache& pixmap_cache, PaletteCache& palette_cache,
                      GlzDecoderWindow &glz_decoder_window, CSurfaces &csurfaces)
diff --git a/client/red_gdi_canvas.h b/client/red_gdi_canvas.h
index 643f3c6..76de12b 100644
--- a/client/red_gdi_canvas.h
+++ b/client/red_gdi_canvas.h
@@ -19,7 +19,11 @@
 #define _H_GDICANVAS
 
 #include "canvas.h"
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
 #include "gdi_canvas.h"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
 #include "red_pixmap_gdi.h"
 
 class RedPixmap;
diff --git a/client/red_gl_canvas.cpp b/client/red_gl_canvas.cpp
index d7841b9..db47aaf 100644
--- a/client/red_gl_canvas.cpp
+++ b/client/red_gl_canvas.cpp
@@ -24,6 +24,12 @@
 #include "red_pixmap_gl.h"
 #include <GL/glx.h>
 
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
+#include "gl_canvas.c"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
 GCanvas::GCanvas(int width, int height, uint32_t format, RedWindow *win,
                  RenderType rendertype,
                  PixmapCache& pixmap_cache, PaletteCache& palette_cache,
diff --git a/client/red_gl_canvas.h b/client/red_gl_canvas.h
index 0260958..83e6512 100644
--- a/client/red_gl_canvas.h
+++ b/client/red_gl_canvas.h
@@ -19,8 +19,13 @@
 #define _H_GCANVAS
 
 #include "canvas.h"
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
 #include "sw_canvas.h"
 #include "gl_canvas.h"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
 #include "red_pixmap_gl.h"
 #include "red_window.h"
 
diff --git a/client/red_sw_canvas.cpp b/client/red_sw_canvas.cpp
index b580e61..fec6605 100644
--- a/client/red_sw_canvas.cpp
+++ b/client/red_sw_canvas.cpp
@@ -25,6 +25,12 @@
 #include "region.h"
 #include "red_pixmap_sw.h"
 
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
+#include "sw_canvas.c"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
 SCanvas::SCanvas(bool onscreen,
                  int width, int height, uint32_t format, RedWindow *win,
                  PixmapCache& pixmap_cache, PaletteCache& palette_cache,
diff --git a/client/red_sw_canvas.h b/client/red_sw_canvas.h
index ebac710..2f807c7 100644
--- a/client/red_sw_canvas.h
+++ b/client/red_sw_canvas.h
@@ -20,7 +20,11 @@
 #define _H_CCANVAS
 
 #include "canvas.h"
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_CACHE
 #include "sw_canvas.h"
+#undef SW_CANVAS_CACHE
+#undef SPICE_CANVAS_INTERNAL
 
 class RedPixmap;
 
diff --git a/client/zlib_decoder.h b/client/zlib_decoder.h
index 4444040..c91ed49 100644
--- a/client/zlib_decoder.h
+++ b/client/zlib_decoder.h
@@ -20,7 +20,7 @@
 #define _H_ZLIB_DECODER
 
 #include "common.h"
-#include "canvas_base.h"
+#include "red_canvas_base.h"
 
 #ifndef __GNUC__
 #define ZLIB_WINAPI
diff --git a/common/Makefile.am b/common/Makefile.am
index 0a2f9c1..501a6e1 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -6,7 +6,6 @@ NULL =
 
 noinst_LTLIBRARIES = libspice-common.la
 libspice_common_la_SOURCES =		\
-	canvas_base.h			\
 	canvas_utils.c			\
 	canvas_utils.h			\
 	draw.h				\
@@ -34,21 +33,10 @@ libspice_common_la_SOURCES =		\
 	rop3.c				\
 	rop3.h				\
 	spice_common.h			\
-	sw_canvas.c			\
-	sw_canvas.h			\
-	$(NULL)
-
-if OS_WIN32
-libspice_common_la_SOURCES +=		\
-	gdi_canvas.h			\
-	gdi_canvas.c			\
 	$(NULL)
-endif
 
 if SUPPORT_GL
 libspice_common_la_SOURCES +=		\
-	gl_canvas.h			\
-	gl_canvas.c			\
 	gl_utils.h			\
 	glc.h				\
 	glc.c				\
@@ -58,7 +46,6 @@ libspice_common_la_SOURCES +=		\
 endif
 
 INCLUDES = \
-	-DSW_CANVAS_IMAGE_CACHE		\
 	$(GL_CFLAGS)			\
 	$(PIXMAN_CFLAGS)		\
 	$(PROTOCOL_CFLAGS)		\
@@ -69,6 +56,13 @@ INCLUDES = \
 
 EXTRA_DIST =				\
 	canvas_base.c			\
+	canvas_base.h			\
+	gdi_canvas.c			\
+	gdi_canvas.h			\
+	gl_canvas.c			\
+	gl_canvas.h			\
+	sw_canvas.c			\
+	sw_canvas.h			\
 	lz_compress_tmpl.c		\
 	lz_decompress_tmpl.c		\
 	quic_family_tmpl.c		\
diff --git a/common/canvas_base.c b/common/canvas_base.c
index 4dedfcf..fe650fe 100644
--- a/common/canvas_base.c
+++ b/common/canvas_base.c
@@ -16,6 +16,10 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This file shouldn't be compiled directly"
+#endif
+
 #include <stdarg.h>
 #include <stdlib.h>
 #include <setjmp.h>
diff --git a/common/canvas_base.h b/common/canvas_base.h
index ff0f972..7c5f275 100644
--- a/common/canvas_base.h
+++ b/common/canvas_base.h
@@ -19,6 +19,9 @@
 #ifndef _H_CANVAS_BASE
 #define _H_CANVAS_BASE
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This header shouldn't be included directly"
+#endif
 
 #include "pixman_utils.h"
 #include "lz.h"
diff --git a/common/gdi_canvas.c b/common/gdi_canvas.c
index 360e6bf..27f644c 100644
--- a/common/gdi_canvas.c
+++ b/common/gdi_canvas.c
@@ -16,6 +16,11 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This file shouldn't be compiled directly"
+#endif
+
 #include <windows.h>
 #include <wingdi.h>
 #include "gdi_canvas.h"
diff --git a/common/gdi_canvas.h b/common/gdi_canvas.h
index 86be9e1..af5b229 100644
--- a/common/gdi_canvas.h
+++ b/common/gdi_canvas.h
@@ -19,6 +19,10 @@
 #ifndef _H__GDI_CANVAS
 #define _H__GDI_CANVAS
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This header shouldn't be included directly"
+#endif
+
 #include <stdint.h>
 
 #ifdef __cplusplus
diff --git a/common/gl_canvas.c b/common/gl_canvas.c
index 9867c4f..844fc07 100644
--- a/common/gl_canvas.c
+++ b/common/gl_canvas.c
@@ -16,11 +16,14 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This file shouldn't be compiled directly"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "gl_canvas.h"
 #include "quic.h"
 #include "rop3.h"
 #include "region.h"
diff --git a/common/gl_canvas.h b/common/gl_canvas.h
index 6776379..40b6713 100644
--- a/common/gl_canvas.h
+++ b/common/gl_canvas.h
@@ -20,6 +20,10 @@
 #include "canvas_base.h"
 #include "region.h"
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This header shouldn't be included directly"
+#endif
+
 #ifndef _H__GL_CANVAS
 #define _H__GL_CANVAS
 
diff --git a/common/sw_canvas.c b/common/sw_canvas.c
index 95ec292..e1b13e0 100644
--- a/common/sw_canvas.c
+++ b/common/sw_canvas.c
@@ -16,6 +16,10 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This file shouldn't be compiled directly"
+#endif
+
 #include <math.h>
 #include "sw_canvas.h"
 #define CANVAS_USE_PIXMAN
diff --git a/common/sw_canvas.h b/common/sw_canvas.h
index 5465526..d8d26a9 100644
--- a/common/sw_canvas.h
+++ b/common/sw_canvas.h
@@ -19,6 +19,10 @@
 #ifndef _H__CANVAS
 #define _H__CANVAS
 
+#ifndef SPICE_CANVAS_INTERNAL
+#error "This header shouldn't be included directly"
+#endif
+
 #include <stdint.h>
 
 #include "draw.h"
diff --git a/server/Makefile.am b/server/Makefile.am
index 73a886f..81649a4 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -6,7 +6,6 @@ INCLUDES = \
 	-I$(top_srcdir)				\
 	-I$(top_srcdir)/common			\
 	-DRED_STATISTICS			\
-	-DSW_CANVAS_IMAGE_CACHE			\
 	$(Z_LIBS)				\
 	$(CELT051_CFLAGS)			\
 	$(PIXMAN_CFLAGS)			\
@@ -89,6 +88,8 @@ libspice_server_la_SOURCES =			\
 	red_worker.h				\
 	reds.c					\
 	reds.h					\
+	reds_sw_canvas.c			\
+	reds_sw_canvas.h			\
 	snd_worker.c				\
 	snd_worker.h				\
 	spice-experimental.h			\
@@ -105,6 +106,13 @@ libspice_server_la_SOURCES +=	\
 	$(NULL)
 endif
 
+if SUPPORT_GL
+libspice_server_la_SOURCES +=	\
+	reds_gl_canvas.c	\
+	reds_gl_canvas.h	\
+	$(NULL)
+endif
+
 if SUPPORT_SMARTCARD
 libspice_server_la_SOURCES +=	\
 	smartcard.c		\
diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 0692458..c5cac58 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -28,9 +28,9 @@
 #include "spice.h"
 #include "red_worker.h"
 #include "quic.h"
-#include "sw_canvas.h"
+#include "reds_sw_canvas.h"
 #ifdef USE_OGL
-#include "gl_canvas.h"
+#include "reds_gl_canvas.h"
 #endif // USE_OGL
 #include "reds.h"
 #include "red_dispatcher.h"
diff --git a/server/red_worker.c b/server/red_worker.c
index 49dffb4..8082139 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -36,9 +36,9 @@
 #include "region.h"
 #include <spice/protocol.h>
 #include "red_worker.h"
-#include "sw_canvas.h"
+#include "reds_sw_canvas.h"
 #ifdef USE_OGL
-#include "gl_canvas.h"
+#include "reds_gl_canvas.h"
 #include "ogl_ctx.h"
 #endif /* USE_OGL */
 #include "quic.h"
diff --git a/server/reds_gl_canvas.c b/server/reds_gl_canvas.c
new file mode 100644
index 0000000..4855a20
--- /dev/null
+++ b/server/reds_gl_canvas.c
@@ -0,0 +1,24 @@
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "config.h"
+
+#include "reds_gl_canvas.h"
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_IMAGE_CACHE
+#include "gl_canvas.c"
+#undef SW_CANVAS_IMAGE_CACHE
+#undef SPICE_CANVAS_INTERNAL
diff --git a/server/reds_gl_canvas.h b/server/reds_gl_canvas.h
new file mode 100644
index 0000000..c20cca5
--- /dev/null
+++ b/server/reds_gl_canvas.h
@@ -0,0 +1,27 @@
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _H_REDS_GL_CANVAS
+#define _H_REDS_GL_CANVAS
+
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_IMAGE_CACHE
+#include "gl_canvas.h"
+#undef SW_CANVAS_IMAGE_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
+#endif
diff --git a/server/reds_sw_canvas.c b/server/reds_sw_canvas.c
new file mode 100644
index 0000000..428a9dc
--- /dev/null
+++ b/server/reds_sw_canvas.c
@@ -0,0 +1,24 @@
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "config.h"
+
+#include "reds_sw_canvas.h"
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_IMAGE_CACHE
+#include "sw_canvas.c"
+#undef SW_CANVAS_IMAGE_CACHE
+#undef SPICE_CANVAS_INTERNAL
diff --git a/server/reds_sw_canvas.h b/server/reds_sw_canvas.h
new file mode 100644
index 0000000..00e6156
--- /dev/null
+++ b/server/reds_sw_canvas.h
@@ -0,0 +1,26 @@
+/*
+   Copyright (C) 2011 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef _H_REDS_SW_CANVAS
+#define _H_REDS_SW_CANVAS
+
+#define SPICE_CANVAS_INTERNAL
+#define SW_CANVAS_IMAGE_CACHE
+#include "sw_canvas.h"
+#undef SW_CANVAS_IMAGE_CACHE
+#undef SPICE_CANVAS_INTERNAL
+
+#endif
-- 
1.7.4.4



More information about the Spice-devel mailing list