summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2010-04-21 13:06:07 +0200
committerAlexander Larsson <alexl@redhat.com>2010-04-23 16:36:35 +0200
commitd2a2f18b6e1b77bb6a04121455385d7e23e77168 (patch)
tree6a2f19b99df6da23dddedc4db173d26281407ad7
parent4200c66cd7012287f03f1f5314cafae6e2a46027 (diff)
downloadspice-d2a2f18b6e1b77bb6a04121455385d7e23e77168.tar.gz
spice-d2a2f18b6e1b77bb6a04121455385d7e23e77168.tar.xz
spice-d2a2f18b6e1b77bb6a04121455385d7e23e77168.zip
X11 client: Add helper for XImage construction
-rw-r--r--client/x11/platform.cpp47
-rw-r--r--client/x11/x_platform.h4
2 files changed, 47 insertions, 4 deletions
diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index bda5e87d..33817e29 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -255,10 +255,51 @@ err1:
return NULL;
}
+XImage *XPlatform::create_x_image(RedDrawable::Format format,
+ int width, int height, int depth,
+ Visual *visual,
+ XShmSegmentInfo **shminfo_out)
+{
+ XImage *image;
+ uint8_t *data;
+ size_t stride;
+
+ *shminfo_out = NULL;
+
+ if (XPlatform::is_x_shm_avail()) {
+ image = XPlatform::create_x_shm_image(format, width, height,
+ depth, visual,
+ shminfo_out);
+ }
+
+ if (image != NULL) {
+ return image;
+ }
+
+ stride = SPICE_ALIGN(width * RedDrawable::format_to_bpp (format), 32) / 8;
+ /* Must use malloc here, not new, because XDestroyImage will free() it */
+ data = (uint8_t *)malloc(height * stride);
+ if (data == NULL) {
+ THROW("Out of memory");
+ }
+
+ if (format == RedDrawable::A1) {
+ image = XCreateImage(XPlatform::get_display(),
+ NULL, 1, XYBitmap,
+ 0, (char *)data, width, height, 32, stride);
+ } else {
+ image = XCreateImage(XPlatform::get_display(),
+ visual, depth, ZPixmap,
+ 0, (char *)data, width, height, 32, stride);
+ }
+
+ return image;
+}
+
+
void XPlatform::free_x_image(XImage *image,
- XShmSegmentInfo *shminfo)
+ XShmSegmentInfo *shminfo)
{
- char *data = image->data;
if (shminfo) {
XShmDetach(XPlatform::get_display(), shminfo);
}
@@ -269,8 +310,6 @@ void XPlatform::free_x_image(XImage *image,
XSync(XPlatform::get_display(), False);
shmdt(shminfo->shmaddr);
delete shminfo;
- } else {
- delete[] data;
}
}
diff --git a/client/x11/x_platform.h b/client/x11/x_platform.h
index c4f24259..57c2f26f 100644
--- a/client/x11/x_platform.h
+++ b/client/x11/x_platform.h
@@ -41,6 +41,10 @@ public:
int width, int height, int depth,
Visual *visual,
XShmSegmentInfo **shminfo_out);
+ static XImage *create_x_image(RedDrawable::Format format,
+ int width, int height, int depth,
+ Visual *visual,
+ XShmSegmentInfo **shminfo_out);
static void free_x_image(XImage *image,
XShmSegmentInfo *shminfo);
};