Moved helper macro to a discrete include file.

To help reduce code duplication and also 'kitchen-sink' includes
the ARRAY_LENGTH macro was moved to a stand-alone file and
referenced from the sources consuming it. Other macros will be
added in subsequent passes.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
This commit is contained in:
Jon Cruz 2015-06-15 15:37:08 -07:00 committed by Bryce Harrington
parent 4678bab13c
commit 35b2eaa989
37 changed files with 83 additions and 19 deletions

View File

@ -189,6 +189,7 @@ westoninclude_HEADERS = \
src/timeline-object.h \
shared/matrix.h \
shared/config-parser.h \
shared/helpers.h \
shared/zalloc.h \
shared/platform.h

View File

@ -35,10 +35,9 @@
#include <wayland-client.h>
#include "window.h"
#include "shared/helpers.h"
#include "shared/matrix.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
/* Our points for the calibration must be not be on a line */
static const struct {
float x_ratio, y_ratio;

View File

@ -41,6 +41,7 @@
#include "window.h"
#include "shared/cairo-util.h"
#include "shared/helpers.h"
struct dnd_drag;

View File

@ -36,6 +36,7 @@
#include <pango/pangocairo.h>
#include "shared/helpers.h"
#include "window.h"
#include "text-client-protocol.h"

View File

@ -38,6 +38,7 @@
#include <cairo.h>
#include "shared/helpers.h"
#include "window.h"
/** window title */

View File

@ -35,6 +35,7 @@
#include <wayland-cursor.h>
#include "shared/cairo-util.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "ivi-application-client-protocol.h"
#include "ivi-hmi-controller-client-protocol.h"
@ -175,7 +176,6 @@ mem_alloc(size_t size, char *file, int32_t line)
}
#define MEM_ALLOC(s) mem_alloc((s),__FILE__,__LINE__)
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
/*****************************************************************************
* Event Handler

View File

@ -46,6 +46,7 @@
#define WL_HIDE_DEPRECATED
#include <wayland-server.h>
#include "shared/helpers.h"
#include "window.h"
#define MIN(x,y) (((x) < (y)) ? (x) : (y))

View File

@ -36,11 +36,10 @@
#include <time.h>
#include <wayland-client.h>
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "presentation_timing-client-protocol.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
enum run_mode {
RUN_MODE_FEEDBACK,
RUN_MODE_FEEDBACK_IDLE,

View File

@ -33,10 +33,9 @@
#include <sys/mman.h>
#include <wayland-client.h>
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
struct seat {
struct touch *touch;
struct wl_seat *seat;

View File

@ -32,6 +32,7 @@
#include <linux/input.h>
#include <cairo.h>
#include "shared/helpers.h"
#include "window.h"
struct stacking {

View File

@ -41,6 +41,7 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include "shared/helpers.h"
#include "window.h"
#if 0

View File

@ -44,6 +44,7 @@
#include <wayland-client.h>
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "window.h"
static int option_fullscreen;

View File

@ -32,11 +32,10 @@
#include <wayland-client.h>
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "presentation_timing-client-protocol.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
typedef void (*print_info_t)(void *info);

View File

@ -67,6 +67,7 @@ typedef void *EGLContext;
#include <linux/input.h>
#include <wayland-client.h>
#include "shared/cairo-util.h"
#include "shared/helpers.h"
#include "xdg-shell-client-protocol.h"
#include "text-cursor-position-client-protocol.h"
#include "workspaces-client-protocol.h"

View File

@ -33,8 +33,6 @@
#include "shared/zalloc.h"
#include "shared/platform.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

View File

@ -37,6 +37,7 @@
#include "desktop-shell-client-protocol.h"
#include "window.h"
#include "shared/helpers.h"
extern struct wscreensaver_plugin glmatrix_screensaver;

View File

@ -45,6 +45,7 @@
#include "ivi-application-server-protocol.h"
#include "ivi-layout-export.h"
#include "ivi-layout-private.h"
#include "shared/helpers.h"
/* Representation of ivi_surface protocol object. */
struct ivi_shell_surface

View File

@ -35,11 +35,10 @@
#include <cairo.h>
#include "cairo-util.h"
#include "shared/helpers.h"
#include "image-loader.h"
#include "config-parser.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
void
surface_flush_device(cairo_surface_t *surface)
{

48
shared/helpers.h Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright © 2015 Samsung Electronics Co., Ltd
*
* 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 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 WESTON_HELPERS_H
#define WESTON_HELPERS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @file
* Simple misc helper macros.
*/
/**
* Compile-time computation of number of items in a hardcoded array.
*
* @param a the array being measured.
* @return the number of items hardcoded into the array.
*/
#ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#endif
#ifdef __cplusplus
}
#endif
#endif /* WESTON_HELPERS_H */

View File

@ -34,10 +34,9 @@
#include <png.h>
#include <pixman.h>
#include "shared/helpers.h"
#include "image-loader.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#ifdef HAVE_WEBP
#include <webp/decode.h>
#endif

View File

@ -46,6 +46,7 @@
#include <gbm.h>
#include <libudev.h>
#include "shared/helpers.h"
#include "libbacklight.h"
#include "compositor.h"
#include "gl-renderer.h"

View File

@ -42,6 +42,7 @@
#include <libudev.h>
#include "shared/helpers.h"
#include "compositor.h"
#include "launcher-util.h"
#include "pixman-renderer.h"

View File

@ -31,6 +31,7 @@
#include <sys/time.h>
#include <stdbool.h>
#include "shared/helpers.h"
#include "compositor.h"
#include "pixman-renderer.h"
#include "presentation_timing-server-protocol.h"

View File

@ -65,6 +65,7 @@
#include <freerdp/locale/keyboard.h>
#include <winpr/input.h>
#include "shared/helpers.h"
#include "compositor.h"
#include "pixman-renderer.h"

View File

@ -46,6 +46,7 @@
# include "rpi-bcm-stubs.h"
#endif
#include "shared/helpers.h"
#include "compositor.h"
#include "rpi-renderer.h"
#include "launcher-util.h"

View File

@ -42,6 +42,7 @@
#include "compositor.h"
#include "gl-renderer.h"
#include "pixman-renderer.h"
#include "shared/helpers.h"
#include "shared/image-loader.h"
#include "shared/os-compatibility.h"
#include "shared/cairo-util.h"

View File

@ -53,6 +53,7 @@
#include "gl-renderer.h"
#include "pixman-renderer.h"
#include "shared/config-parser.h"
#include "shared/helpers.h"
#include "shared/image-loader.h"
#include "presentation_timing-server-protocol.h"

View File

@ -61,6 +61,7 @@
#include "compositor.h"
#include "scaler-server-protocol.h"
#include "presentation_timing-server-protocol.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "git-version.h"
#include "version.h"

View File

@ -49,8 +49,6 @@ extern "C" {
#define MIN(x,y) (((x) < (y)) ? (x) : (y))
#endif
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

View File

@ -40,6 +40,7 @@
#include "gl-renderer.h"
#include "vertex-clipping.h"
#include "shared/helpers.h"
#include "weston-egl-ext.h"
struct gl_shader {

View File

@ -34,6 +34,7 @@
#include <fcntl.h>
#include <limits.h>
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "compositor.h"

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include "shared/helpers.h"
#include "weston-test-client-helper.h"
#include "ivi-application-client-protocol.h"
#include "ivi-test.h"

View File

@ -31,6 +31,7 @@
#include <assert.h>
#include <time.h>
#include "shared/helpers.h"
#include "weston-test-client-helper.h"
#include "presentation_timing-client-protocol.h"

View File

@ -30,6 +30,7 @@
#include "weston-test-runner.h"
#include "shared/helpers.h"
#include "src/vertex-clipping.h"
#define BOUNDING_BOX_TOP_Y 100.0f

View File

@ -31,6 +31,8 @@
#include <stdlib.h>
#include "shared/helpers.h"
#ifdef NDEBUG
#error "Tests must not be built with NDEBUG defined, they rely on assert()."
#endif
@ -44,8 +46,6 @@ struct weston_test {
int must_fail;
} __attribute__ ((aligned (32)));
#define ARRAY_LENGTH(a) ((int) (sizeof (a) / sizeof (a)[0]))
#define TEST_BEGIN(name, arg) \
static void name(arg)

View File

@ -31,6 +31,7 @@
#include <fcntl.h>
#include "xwayland.h"
#include "shared/helpers.h"
static int
writable_callback(int fd, uint32_t mask, void *data)

View File

@ -42,6 +42,7 @@
#include "cairo-util.h"
#include "compositor.h"
#include "hash.h"
#include "shared/helpers.h"
struct wm_size_hints {
uint32_t flags;