neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

commit 47c94eb1cb105f0c96e3565bf61473c9e68ffb21
parent 0aea28076e617c793e038b3de7971b7d9089e3df
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 31 Dec 2013 12:04:39 -0800

Move interface prototypes and struct declarations to interface/

Diffstat:
Mdumb.c | 79+++++++++++++++++++++++++++++++------------------------------------------------
Mintel.c | 136+++++++++++++++++++++++++------------------------------------------------------
Ainterface/drawable.h | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainterface/drm.h | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainterface/drm_drawable.h | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpixman-private.h | 2+-
Mpixman.c | 90++++++++++++++++++++++++++-----------------------------------------------------
Mwayland.c | 90+++++++++++++++++++++++++++++++++----------------------------------------------
Mwld-private.h | 8++++++++
9 files changed, 344 insertions(+), 257 deletions(-)

diff --git a/dumb.c b/dumb.c @@ -44,45 +44,25 @@ struct dumb_drawable uint32_t handle; }; -/* DRM implementation */ -static bool dumb_device_supported(uint32_t vendor_id, uint32_t device_id); -static struct dumb_context * dumb_create_context(int drm_fd); -static void dumb_destroy_context(struct dumb_context * context); -static struct wld_drawable * dumb_create_drawable - (struct dumb_context * context, uint32_t width, uint32_t height, - uint32_t format); -static struct wld_drawable * dumb_import - (struct dumb_context * context, uint32_t width, uint32_t height, - uint32_t format, int prime_fd, unsigned long pitch); -static struct wld_drawable * dumb_import_gem - (struct dumb_context * context, uint32_t width, uint32_t height, - uint32_t format, uint32_t gem_name, unsigned long pitch); +#define DRM_DRIVER_NAME dumb +#include "interface/drm.h" /* DRM drawable */ -static int dumb_export(struct wld_drawable * drawable); -static uint32_t dumb_get_handle(struct wld_drawable * drawable); +static int drawable_export(struct wld_drawable * drawable); +static uint32_t drawable_get_handle(struct wld_drawable * drawable); -static struct drm_draw_interface dumb_draw = { - .export = &dumb_export, - .get_handle = &dumb_get_handle -}; -static bool dumb_draw_initialized; - -const struct wld_drm_interface dumb_drm = { - .device_supported = &dumb_device_supported, - .create_context = (drm_create_context_func_t) &dumb_create_context, - .destroy_context = (drm_destroy_context_func_t) &dumb_destroy_context, - .create_drawable = (drm_create_drawable_func_t) &dumb_create_drawable, - .import = (drm_import_func_t) &dumb_import, - .import_gem = (drm_import_gem_func_t) &dumb_import_gem, +static struct drm_draw_interface draw_interface = { + .export = &drawable_export, + .get_handle = &drawable_get_handle }; +static bool draw_initialized; -bool dumb_device_supported(uint32_t vendor_id, uint32_t device_id) +bool drm_device_supported(uint32_t vendor_id, uint32_t device_id) { return true; } -struct dumb_context * dumb_create_context(int drm_fd) +void * drm_create_context(int drm_fd) { struct dumb_context * context; @@ -94,10 +74,10 @@ struct dumb_context * dumb_create_context(int drm_fd) context->fd = drm_fd; - if (!dumb_draw_initialized) + if (!draw_initialized) { - dumb_draw.base = pixman_draw; - dumb_draw_initialized = true; + draw_interface.base = *pixman_draw; + draw_initialized = true; } return context; @@ -108,8 +88,10 @@ struct dumb_context * dumb_create_context(int drm_fd) return NULL; } -void dumb_destroy_context(struct dumb_context * context) +void drm_destroy_context(void * base) { + struct dumb_context * context = base; + wld_pixman_destroy_context(context->pixman); free(context); } @@ -145,7 +127,7 @@ static struct wld_drawable * new_drawable(struct dumb_context * context, goto error2; } - drawable->pixman.base.interface = (struct wld_draw_interface *) &dumb_draw; + drawable->pixman.base.interface = &draw_interface.base; drawable->context = context; drawable->handle = handle; @@ -159,10 +141,11 @@ static struct wld_drawable * new_drawable(struct dumb_context * context, return NULL; } -struct wld_drawable * dumb_create_drawable - (struct dumb_context * context, uint32_t width, uint32_t height, - uint32_t format) +struct wld_drawable * drm_create_drawable(void * base, + uint32_t width, uint32_t height, + uint32_t format) { + struct dumb_context * context = base; struct wld_drawable * drawable; struct drm_mode_create_dumb create_dumb_arg = { .height = height, .width = width, @@ -195,11 +178,11 @@ struct wld_drawable * dumb_create_drawable return NULL; } -struct wld_drawable * dumb_import(struct dumb_context * context, - uint32_t width, uint32_t height, - uint32_t format, - int prime_fd, unsigned long pitch) +struct wld_drawable * drm_import(void * base, uint32_t width, uint32_t height, + uint32_t format, int prime_fd, + unsigned long pitch) { + struct dumb_context * context = base; int ret; uint32_t handle; @@ -214,17 +197,17 @@ struct wld_drawable * dumb_import(struct dumb_context * context, return NULL; } -struct wld_drawable * dumb_import_gem(struct dumb_context * context, - uint32_t width, uint32_t height, - uint32_t format, - uint32_t gem_name, unsigned long pitch) +struct wld_drawable * drm_import_gem(void * context, + uint32_t width, uint32_t height, + uint32_t format, + uint32_t gem_name, unsigned long pitch) { DEBUG("dumb: import_gem is not supported\n"); return NULL; } -static int dumb_export(struct wld_drawable * drawable) +static int drawable_export(struct wld_drawable * drawable) { struct dumb_drawable * dumb = (void *) drawable; int prime_fd, ret; @@ -238,7 +221,7 @@ static int dumb_export(struct wld_drawable * drawable) return prime_fd; } -static uint32_t dumb_get_handle(struct wld_drawable * drawable) +static uint32_t drawable_get_handle(struct wld_drawable * drawable) { struct dumb_drawable * dumb = (void *) drawable; diff --git a/intel.c b/intel.c @@ -44,74 +44,16 @@ struct intel_drawable pixman_image_t * virtual; }; -/* Drawable implementation */ -static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, - int32_t x, int32_t y, - uint32_t width, uint32_t height); -static void intel_copy_rectangle(struct wld_drawable * src, - struct wld_drawable * dst, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height); -static void intel_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents); -static void intel_write(struct wld_drawable * drawable, - const void * data, size_t size); -static pixman_image_t * intel_map(struct wld_drawable * drawable); -static void intel_flush(struct wld_drawable * drawable); -static void intel_destroy(struct wld_drawable * drawable); - -static int intel_export(struct wld_drawable * drawable); -static uint32_t intel_get_handle(struct wld_drawable * drawable); - -/* DRM implementation */ -static bool intel_device_supported(uint32_t vendor_id, uint32_t device_id); -static struct intel_context * intel_create_context(int drm_fd); -static void intel_destroy_context(struct intel_context * context); -static struct wld_drawable * intel_create_drawable - (struct intel_context * context, uint32_t width, uint32_t height, - uint32_t format); -static struct wld_drawable * intel_import - (struct intel_context * context, uint32_t width, uint32_t height, - uint32_t format, int prime_fd, unsigned long pitch); -static struct wld_drawable * intel_import_gem - (struct intel_context * context, uint32_t width, uint32_t height, - uint32_t format, uint32_t gem_name, unsigned long pitch); - -const static struct drm_draw_interface intel_draw = { - .base = { - .fill_rectangle = &intel_fill_rectangle, - .fill_region = &default_fill_region, - .copy_rectangle = &intel_copy_rectangle, - .copy_region = &default_copy_region, - .draw_text_utf8 = &intel_draw_text_utf8, - .write = &intel_write, - .map = &intel_map, - .flush = &intel_flush, - .destroy = &intel_destroy - }, - .export = &intel_export, - .get_handle = &intel_get_handle -}; - -const struct wld_drm_interface intel_drm = { - .device_supported = &intel_device_supported, - .create_context = (drm_create_context_func_t) &intel_create_context, - .destroy_context = (drm_destroy_context_func_t) &intel_destroy_context, - .create_drawable = (drm_create_drawable_func_t) &intel_create_drawable, - .import = (drm_import_func_t) &intel_import, - .import_gem = (drm_import_gem_func_t) &intel_import_gem, -}; +#define DRM_DRIVER_NAME intel +#include "interface/drm.h" +#include "interface/drm_drawable.h" -bool intel_device_supported(uint32_t vendor_id, uint32_t device_id) +bool drm_device_supported(uint32_t vendor_id, uint32_t device_id) { return vendor_id == 0x8086; } -struct intel_context * intel_create_context(int drm_fd) +void * drm_create_context(int drm_fd) { struct intel_context * context; @@ -140,8 +82,10 @@ struct intel_context * intel_create_context(int drm_fd) return NULL; } -void intel_destroy_context(struct intel_context * context) +void drm_destroy_context(void * base) { + struct intel_context * context = base; + intel_batch_destroy(context->batch); drm_intel_bufmgr_destroy(context->bufmgr); free(context); @@ -156,7 +100,7 @@ static struct intel_drawable * new_drawable(struct intel_context * context, if (!(intel = malloc(sizeof *intel))) return NULL; - intel->base.interface = (struct wld_draw_interface *) &intel_draw; + intel->base.interface = &draw_interface.base; intel->base.width = width; intel->base.height = height; intel->base.format = format; @@ -166,10 +110,11 @@ static struct intel_drawable * new_drawable(struct intel_context * context, return intel; } -struct wld_drawable * intel_create_drawable - (struct intel_context * context, uint32_t width, uint32_t height, - uint32_t format) +struct wld_drawable * drm_create_drawable(void * base, + uint32_t width, uint32_t height, + uint32_t format) { + struct intel_context * context = base; struct intel_drawable * intel; uint32_t tiling_mode = width >= 128 ? I915_TILING_X : I915_TILING_NONE; @@ -183,11 +128,12 @@ struct wld_drawable * intel_create_drawable return &intel->base; } -struct wld_drawable * intel_import(struct intel_context * context, - uint32_t width, uint32_t height, - uint32_t format, - int prime_fd, unsigned long pitch) +struct wld_drawable * drm_import(void * base, + uint32_t width, uint32_t height, + uint32_t format, + int prime_fd, unsigned long pitch) { + struct intel_context * context = base; struct intel_drawable * intel; uint32_t size = width * height * 4; @@ -201,11 +147,12 @@ struct wld_drawable * intel_import(struct intel_context * context, return &intel->base; } -struct wld_drawable * intel_import_gem(struct intel_context * context, - uint32_t width, uint32_t height, - uint32_t format, - uint32_t gem_name, unsigned long pitch) +struct wld_drawable * drm_import_gem(void * base, + uint32_t width, uint32_t height, + uint32_t format, + uint32_t gem_name, unsigned long pitch) { + struct intel_context * context = base; struct intel_drawable * intel; if (!(intel = new_drawable(context, width, height, format))) @@ -218,8 +165,9 @@ struct wld_drawable * intel_import_gem(struct intel_context * context, return &intel->base; } -void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, - int32_t x, int32_t y, uint32_t width, uint32_t height) +void drawable_fill_rectangle(struct wld_drawable * drawable, uint32_t color, + int32_t x, int32_t y, + uint32_t width, uint32_t height) { struct intel_drawable * intel = (void *) drawable; @@ -227,11 +175,11 @@ void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color, x, y, x + width, y + height, color); } -void intel_copy_rectangle(struct wld_drawable * src_drawable, - struct wld_drawable * dst_drawable, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height) +void drawable_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) { struct intel_drawable * src = (void *) src_drawable; struct intel_drawable * dst = (void *) dst_drawable; @@ -241,11 +189,11 @@ void intel_copy_rectangle(struct wld_drawable * src_drawable, dst->bo, dst->base.pitch, dst_x, dst_y, width, height); } -void intel_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents) +void drawable_draw_text_utf8(struct wld_drawable * drawable, + struct font * font, uint32_t color, + int32_t x, int32_t y, + const char * text, int32_t length, + struct wld_extents * extents) { struct intel_drawable * intel = (void *) drawable; int ret; @@ -309,7 +257,7 @@ void intel_draw_text_utf8(struct wld_drawable * drawable, extents->advance = origin_x - x; } -void intel_write(struct wld_drawable * drawable, const void * data, size_t size) +void drawable_write(struct wld_drawable * drawable, const void * data, size_t size) { struct intel_drawable * intel = (void *) drawable; @@ -324,7 +272,7 @@ static void destroy_virtual(pixman_image_t * image, void * data) intel->virtual = NULL; } -pixman_image_t * intel_map(struct wld_drawable * drawable) +pixman_image_t * drawable_map(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; @@ -344,21 +292,21 @@ pixman_image_t * intel_map(struct wld_drawable * drawable) return intel->virtual; } -void intel_flush(struct wld_drawable * drawable) +void drawable_flush(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; intel_batch_flush(intel->context->batch); } -void intel_destroy(struct wld_drawable * drawable) +void drawable_destroy(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; drm_intel_bo_unreference(intel->bo); free(intel); } -int intel_export(struct wld_drawable * drawable) +int drawable_export(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; int prime_fd; @@ -368,7 +316,7 @@ int intel_export(struct wld_drawable * drawable) return prime_fd; } -uint32_t intel_get_handle(struct wld_drawable * drawable) +uint32_t drawable_get_handle(struct wld_drawable * drawable) { struct intel_drawable * intel = (void *) drawable; diff --git a/interface/drawable.h b/interface/drawable.h @@ -0,0 +1,67 @@ +/* wld: interface/drawable.h + * + * Copyright (c) 2013 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +static void drawable_fill_rectangle(struct wld_drawable * drawable, + uint32_t color, int32_t x, int32_t y, + uint32_t width, uint32_t height); +static void drawable_copy_rectangle(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); +#ifdef DRAWABLE_IMPLEMENTS_REGION +static void drawable_fill_region(struct wld_drawable * drawable, uint32_t color, + pixman_region32_t * region); +static void drawable_copy_region(struct wld_drawable * src, + struct wld_drawable * drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); +#endif +static void drawable_draw_text_utf8(struct wld_drawable * drawable, + struct font * font, uint32_t color, + int32_t x, int32_t y, + const char * text, int32_t length, + struct wld_extents * extents); +static void drawable_write(struct wld_drawable * drawable, + const void * data, size_t size); +static pixman_image_t * drawable_map(struct wld_drawable * drawable); +static void drawable_flush(struct wld_drawable * drawable); +static void drawable_destroy(struct wld_drawable * drawable); + +static const struct wld_draw_interface draw_interface = { + .fill_rectangle = &drawable_fill_rectangle, + .copy_rectangle = &drawable_copy_rectangle, +#ifdef DRAWABLE_IMPLEMENTS_REGION + .fill_region = &drawable_fill_region, + .copy_region = &drawable_copy_region, +#else + .fill_region = &default_fill_region, + .copy_region = &default_copy_region, +#endif + .draw_text_utf8 = &drawable_draw_text_utf8, + .write = &drawable_write, + .map = &drawable_map, + .flush = &drawable_flush, + .destroy = &drawable_destroy +}; + diff --git a/interface/drm.h b/interface/drm.h @@ -0,0 +1,55 @@ +/* wld: interface/drm.h + * + * Copyright (c) 2013 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef DRM_DRIVER_NAME +# error "You must define DRM_DRIVER_NAME before including interface/drm.h" +#endif + +/* DRM implementation */ +static bool drm_device_supported(uint32_t vendor_id, uint32_t device_id); +static void * drm_create_context(int drm_fd); +static void drm_destroy_context(void * context); +static struct wld_drawable * drm_create_drawable + (void * context, uint32_t width, uint32_t height, uint32_t format); +static struct wld_drawable * drm_import(void * context, + uint32_t width, uint32_t height, + uint32_t format, int prime_fd, + unsigned long pitch); +static struct wld_drawable * drm_import_gem(void * context, + uint32_t width, uint32_t height, + uint32_t format, uint32_t gem_name, + unsigned long pitch); + +#define EXPAND(f, x) f(x) +#define VAR(name) name ## _drm +const struct wld_drm_interface EXPAND(VAR, DRM_DRIVER_NAME) = { + .device_supported = &drm_device_supported, + .create_context = &drm_create_context, + .destroy_context = &drm_destroy_context, + .create_drawable = &drm_create_drawable, + .import = &drm_import, + .import_gem = &drm_import_gem, +}; +#undef VAR +#undef EXPAND + diff --git a/interface/drm_drawable.h b/interface/drm_drawable.h @@ -0,0 +1,74 @@ +/* wld: interface/drm_drawable.h + * + * Copyright (c) 2013 Michael Forney + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +static void drawable_fill_rectangle(struct wld_drawable * drawable, + uint32_t color, int32_t x, int32_t y, + uint32_t width, uint32_t height); +static void drawable_copy_rectangle(struct wld_drawable * src, + struct wld_drawable * dst, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height); +#ifdef DRAWABLE_IMPLEMENTS_REGION +static void drawable_fill_region(struct wld_drawable * drawable, uint32_t color, + pixman_region32_t * region); +static void drawable_copy_region(struct wld_drawable * src, + struct wld_drawable * drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y); +#endif +static void drawable_draw_text_utf8(struct wld_drawable * drawable, + struct font * font, uint32_t color, + int32_t x, int32_t y, + const char * text, int32_t length, + struct wld_extents * extents); +static void drawable_write(struct wld_drawable * drawable, + const void * data, size_t size); +static pixman_image_t * drawable_map(struct wld_drawable * drawable); +static void drawable_flush(struct wld_drawable * drawable); +static void drawable_destroy(struct wld_drawable * drawable); + +static int drawable_export(struct wld_drawable * drawable); +static uint32_t drawable_get_handle(struct wld_drawable * drawable); + +static const struct drm_draw_interface draw_interface = { + .base = { + .fill_rectangle = &drawable_fill_rectangle, + .copy_rectangle = &drawable_copy_rectangle, +#ifdef DRAWABLE_IMPLEMENTS_REGION + .fill_region = &drawable_fill_region, + .copy_region = &drawable_copy_region, +#else + .fill_region = &default_fill_region, + .copy_region = &default_copy_region, +#endif + .draw_text_utf8 = &drawable_draw_text_utf8, + .write = &drawable_write, + .map = &drawable_map, + .flush = &drawable_flush, + .destroy = &drawable_destroy + }, + .export = &drawable_export, + .get_handle = &drawable_get_handle +}; + diff --git a/pixman-private.h b/pixman-private.h @@ -35,7 +35,7 @@ struct pixman_drawable struct wld_pixman_context * context; }; -extern const struct wld_draw_interface pixman_draw; +extern const struct wld_draw_interface * const pixman_draw; bool pixman_initialize_drawable (struct wld_pixman_context * context, struct pixman_drawable * drawable, diff --git a/pixman.c b/pixman.c @@ -37,42 +37,10 @@ struct wld_pixman_context pixman_glyph_cache_t * glyph_cache; }; -static void pixman_fill_rectangle(struct wld_drawable * drawable, - uint32_t color, int32_t x, int32_t y, - uint32_t width, uint32_t height); -static void pixman_fill_region(struct wld_drawable * drawable, uint32_t color, - pixman_region32_t * region); -static void pixman_copy_rectangle(struct wld_drawable * src, - struct wld_drawable * dst, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height); -static void pixman_copy_region(struct wld_drawable * src, - struct wld_drawable * dst, - pixman_region32_t * region, - int32_t dst_x, int32_t dst_y); -static void pixman_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents); -static void pixman_write(struct wld_drawable * drawable, - const void * data, size_t size); -static pixman_image_t * pixman_map(struct wld_drawable * drawable); -static void pixman_flush(struct wld_drawable * drawable); -static void pixman_destroy(struct wld_drawable * drawable); - -const struct wld_draw_interface pixman_draw = { - .fill_rectangle = &pixman_fill_rectangle, - .fill_region = &pixman_fill_region, - .copy_rectangle = &pixman_copy_rectangle, - .copy_region = &pixman_copy_region, - .draw_text_utf8 = &pixman_draw_text_utf8, - .write = &pixman_write, - .map = &pixman_map, - .flush = &pixman_flush, - .destroy = &pixman_destroy -}; +#define DRAWABLE_IMPLEMENTS_REGION +#include "interface/drawable.h" + +const struct wld_draw_interface * const pixman_draw = &draw_interface; EXPORT struct wld_pixman_context * wld_pixman_create_context() @@ -105,7 +73,7 @@ bool pixman_initialize_drawable uint32_t width, uint32_t height, void * data, uint32_t pitch, uint32_t format) { - drawable->base.interface = &pixman_draw; + drawable->base.interface = &draw_interface; drawable->base.width = width; drawable->base.height = height; drawable->base.format = format; @@ -145,9 +113,9 @@ struct wld_drawable * wld_pixman_create_drawable return NULL; } -void pixman_fill_rectangle(struct wld_drawable * drawable, uint32_t color, - int32_t x, int32_t y, - uint32_t width, uint32_t height) +void drawable_fill_rectangle(struct wld_drawable * drawable, uint32_t color, + int32_t x, int32_t y, + uint32_t width, uint32_t height) { struct pixman_drawable * pixman = (void *) drawable; pixman_color_t pixman_color = PIXMAN_COLOR(color); @@ -157,8 +125,8 @@ void pixman_fill_rectangle(struct wld_drawable * drawable, uint32_t color, 1, &box); } -void pixman_fill_region(struct wld_drawable * drawable, uint32_t color, - pixman_region32_t * region) +void drawable_fill_region(struct wld_drawable * drawable, uint32_t color, + pixman_region32_t * region) { struct pixman_drawable * pixman = (void *) drawable; pixman_color_t pixman_color = PIXMAN_COLOR(color); @@ -170,11 +138,11 @@ void pixman_fill_region(struct wld_drawable * drawable, uint32_t color, num_boxes, boxes); } -void pixman_copy_rectangle(struct wld_drawable * src_drawable, - struct wld_drawable * dst_drawable, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height) +void drawable_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) { struct pixman_drawable * src = (void *) src_drawable; struct pixman_drawable * dst = (void *) dst_drawable; @@ -183,10 +151,10 @@ void pixman_copy_rectangle(struct wld_drawable * src_drawable, src_x, src_y, 0, 0, dst_x, dst_y, width, height); } -void pixman_copy_region(struct wld_drawable * src_drawable, - struct wld_drawable * dst_drawable, - pixman_region32_t * region, - int32_t dst_x, int32_t dst_y) +void drawable_copy_region(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y) { struct pixman_drawable * src = (void *) src_drawable; struct pixman_drawable * dst = (void *) dst_drawable; @@ -210,11 +178,11 @@ static inline uint8_t reverse(uint8_t byte) return byte; } -void pixman_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents) +void drawable_draw_text_utf8(struct wld_drawable * drawable, + struct font * font, uint32_t color, + int32_t x, int32_t y, + const char * text, int32_t length, + struct wld_extents * extents) { struct pixman_drawable * pixman = (void *) drawable; int ret; @@ -303,26 +271,26 @@ void pixman_draw_text_utf8(struct wld_drawable * drawable, extents->advance = origin_x; } -void pixman_write(struct wld_drawable * drawable, - const void * data, size_t size) +void drawable_write(struct wld_drawable * drawable, + const void * data, size_t size) { struct pixman_drawable * pixman = (void *) drawable; memcpy(pixman_image_get_data(pixman->image), data, size); } -pixman_image_t * pixman_map(struct wld_drawable * drawable) +pixman_image_t * drawable_map(struct wld_drawable * drawable) { struct pixman_drawable * pixman = (void *) drawable; return pixman_image_ref(pixman->image); } -void pixman_flush(struct wld_drawable * drawable) +void drawable_flush(struct wld_drawable * drawable) { } -void pixman_destroy(struct wld_drawable * drawable) +void drawable_destroy(struct wld_drawable * drawable) { struct pixman_drawable * pixman = (void *) drawable; diff --git a/wayland.c b/wayland.c @@ -61,27 +61,8 @@ static void sync_done(void * data, struct wl_callback * callback, static void buffer_release(void * data, struct wl_buffer * buffer); -static void wayland_fill_rectangle(struct wld_drawable * drawable, - uint32_t color, int32_t x, int32_t y, - uint32_t width, uint32_t height); -static void wayland_fill_region(struct wld_drawable * drawable, uint32_t color, - pixman_region32_t * region); -static void wayland_copy_rectangle(struct wld_drawable * src, - struct wld_drawable * dst, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height); -static void wayland_copy_region(struct wld_drawable * src, - struct wld_drawable * dst, - pixman_region32_t * region, - int32_t dst_x, int32_t dst_y); -static void wayland_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents); -static void wayland_flush(struct wld_drawable * drawable); -static void wayland_destroy(struct wld_drawable * drawable); +#define DRAWABLE_IMPLEMENTS_REGION +#include "interface/drawable.h" const struct wl_callback_listener sync_listener = { .done = &sync_done @@ -91,16 +72,6 @@ const struct wl_buffer_listener buffer_listener = { .release = &buffer_release }; -const struct wld_draw_interface wayland_draw = { - .fill_rectangle = &wayland_fill_rectangle, - .fill_region = &wayland_fill_region, - .copy_rectangle = &wayland_copy_rectangle, - .copy_region = &wayland_copy_region, - .draw_text_utf8 = &wayland_draw_text_utf8, - .flush = &wayland_flush, - .destroy = &wayland_destroy -}; - const static struct wld_wayland_interface * interfaces[] = { #if WITH_WAYLAND_DRM [WLD_DRM] = &wayland_drm_interface, @@ -228,7 +199,7 @@ struct wld_drawable * wld_wayland_create_drawable wayland->surface = surface; wayland->damage_tracking = damage_flags; - wayland->base.interface = &wayland_draw; + wayland->base.interface = &draw_interface; wayland->base.width = width; wayland->base.height = height; @@ -326,9 +297,9 @@ static void begin(struct wayland_drawable * wayland) } } -void wayland_fill_rectangle(struct wld_drawable * drawable, uint32_t color, - int32_t x, int32_t y, - uint32_t width, uint32_t height) +void drawable_fill_rectangle(struct wld_drawable * drawable, uint32_t color, + int32_t x, int32_t y, + uint32_t width, uint32_t height) { struct wayland_drawable * wayland = (void *) drawable; @@ -343,8 +314,8 @@ void wayland_fill_rectangle(struct wld_drawable * drawable, uint32_t color, } } -void wayland_fill_region(struct wld_drawable * drawable, uint32_t color, - pixman_region32_t * region) +void drawable_fill_region(struct wld_drawable * drawable, uint32_t color, + pixman_region32_t * region) { struct wayland_drawable * wayland = (void *) drawable; @@ -358,28 +329,28 @@ void wayland_fill_region(struct wld_drawable * drawable, uint32_t color, } } -void wayland_copy_rectangle(struct wld_drawable * src_drawable, - struct wld_drawable * dst_drawable, - int32_t src_x, int32_t src_y, - int32_t dst_x, int32_t dst_y, - uint32_t width, uint32_t height) +void drawable_copy_rectangle(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + int32_t src_x, int32_t src_y, + int32_t dst_x, int32_t dst_y, + uint32_t width, uint32_t height) { fprintf(stderr, "wayland: Copy rectangle is not implemented\n"); } -void wayland_copy_region(struct wld_drawable * src_drawable, - struct wld_drawable * dst_drawable, - pixman_region32_t * region, - int32_t dst_x, int32_t dst_y) +void drawable_copy_region(struct wld_drawable * src_drawable, + struct wld_drawable * dst_drawable, + pixman_region32_t * region, + int32_t dst_x, int32_t dst_y) { fprintf(stderr, "wayland: Copy region is not implemented\n"); } -void wayland_draw_text_utf8(struct wld_drawable * drawable, - struct font * font, uint32_t color, - int32_t x, int32_t y, - const char * text, int32_t length, - struct wld_extents * extents) +void drawable_draw_text_utf8(struct wld_drawable * drawable, + struct font * font, uint32_t color, + int32_t x, int32_t y, + const char * text, int32_t length, + struct wld_extents * extents) { struct wld_extents extents0; struct wayland_drawable * wayland = (void *) drawable; @@ -400,7 +371,20 @@ void wayland_draw_text_utf8(struct wld_drawable * drawable, } } -void wayland_flush(struct wld_drawable * drawable) +void drawable_write(struct wld_drawable * drawable, + const void * data, size_t size) +{ + fprintf(stderr, "wayland: Write is not implemented\n"); +} + +pixman_image_t * drawable_map(struct wld_drawable * drawable) +{ + fprintf(stderr, "wayland: Map is not implemented\n"); + + return NULL; +} + +void drawable_flush(struct wld_drawable * drawable) { struct wayland_drawable * wayland = (void *) drawable; @@ -431,7 +415,7 @@ void wayland_flush(struct wld_drawable * drawable) wayland->front_buffer ^= 1; } -void wayland_destroy(struct wld_drawable * drawable) +void drawable_destroy(struct wld_drawable * drawable) { struct wayland_drawable * wayland = (void *) drawable; diff --git a/wld-private.h b/wld-private.h @@ -26,6 +26,7 @@ #include "wld.h" +#include <assert.h> #include <stdbool.h> #include <stdint.h> #include <ft2build.h> @@ -45,6 +46,13 @@ #endif #define EXPORT __attribute__((visibility("default"))) +#define IMPL(name, type) \ + static inline struct name ## _ ## type * name ## _ ## type \ + (struct wld_ ## type * type) \ + { \ + assert(type->impl == &type ## _impl); \ + return (struct name ## _ ## type *) type; \ + } struct wld_font_context {