commit 226ac956036dc030f1524f3bb20e42f185f6443f
parent c253a007474851748a4c7e17176d8ee462468e11
Author: Michael Forney <mforney@mforney.org>
Date: Mon, 13 Jan 2014 14:37:50 -0800
Add drawable_initialize convenience function
Diffstat:
4 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/drawable.c b/drawable.c
@@ -60,6 +60,18 @@ void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
}
}
+void drawable_initialize(struct wld_drawable * drawable,
+ const struct wld_drawable_impl * impl,
+ uint32_t width, uint32_t height,
+ uint32_t format, uint32_t pitch)
+{
+ *((const struct wld_drawable_impl **) &drawable->impl) = impl;
+ drawable->width = width;
+ drawable->height = height;
+ drawable->format = format;
+ drawable->pitch = pitch;
+}
+
EXPORT
void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
int32_t x, int32_t y, uint32_t width, uint32_t height)
diff --git a/intel.c b/intel.c
@@ -96,10 +96,8 @@ static struct intel_drawable * new_drawable(struct intel_context * context,
if (!(intel = malloc(sizeof *intel)))
return NULL;
- intel->base.impl = &drawable_impl.base;
- intel->base.width = width;
- intel->base.height = height;
- intel->base.format = format;
+ drawable_initialize(&intel->base, &drawable_impl.base,
+ width, height, format, 0);
intel->context = context;
intel->virtual = NULL;
diff --git a/pixman.c b/pixman.c
@@ -68,12 +68,8 @@ bool pixman_initialize_drawable
uint32_t width, uint32_t height,
void * data, uint32_t pitch, uint32_t format)
{
- drawable->base.impl = &drawable_impl;
- drawable->base.width = width;
- drawable->base.height = height;
- drawable->base.format = format;
- drawable->base.pitch = pitch;
-
+ drawable_initialize(&drawable->base, &drawable_impl,
+ width, height, format, pitch);
drawable->context = (void *) context;
drawable->image = pixman_image_create_bits(format_wld_to_pixman(format),
width, height,
@@ -90,12 +86,11 @@ struct wld_drawable * new_drawable(struct pixman_context * context,
if (!(drawable = malloc(sizeof *drawable)))
return NULL;
- drawable->base.impl = &drawable_impl;
- drawable->base.width = pixman_image_get_width(image);
- drawable->base.height = pixman_image_get_height(image);
- drawable->base.format = format_pixman_to_wld
- (pixman_image_get_format(image));
- drawable->base.pitch = pixman_image_get_stride(image);
+ drawable_initialize(&drawable->base, &drawable_impl,
+ pixman_image_get_width(image),
+ pixman_image_get_height(image),
+ format_pixman_to_wld(pixman_image_get_format(image)),
+ pixman_image_get_stride(image));
drawable->context = context;
drawable->image = image;
diff --git a/wld-private.h b/wld-private.h
@@ -180,5 +180,10 @@ void default_copy_region(struct wld_drawable * src, struct wld_drawable * dst,
void context_initialize(struct wld_context * context,
const struct wld_context_impl * impl);
+void drawable_initialize(struct wld_drawable * drawable,
+ const struct wld_drawable_impl * impl,
+ uint32_t width, uint32_t height,
+ uint32_t format, uint32_t pitch);
+
#endif