2011-05-25 14:27:10 -04:00
|
|
|
#include <cogl/cogl.h>
|
2012-03-20 09:21:18 -04:00
|
|
|
#include <cogl/cogl-wayland-server.h>
|
2011-05-25 14:27:10 -04:00
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
2013-03-20 12:53:23 -04:00
|
|
|
#include <stdlib.h>
|
2011-05-25 14:27:10 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
typedef struct _CoglandCompositor CoglandCompositor;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-12-19 08:42:52 -05:00
|
|
|
int x1, y1, x2, y2;
|
|
|
|
} CoglandRegion;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2013-06-28 12:57:54 -04:00
|
|
|
struct wl_resource *resource;
|
2012-12-19 08:42:52 -05:00
|
|
|
CoglandRegion region;
|
|
|
|
} CoglandSharedRegion;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2013-06-27 09:22:41 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct wl_resource *resource;
|
|
|
|
struct wl_signal destroy_signal;
|
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct wl_shm_buffer *shm_buffer;
|
|
|
|
struct wl_buffer *legacy_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t width, height;
|
|
|
|
uint32_t busy_count;
|
|
|
|
} CoglandBuffer;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglandBuffer *buffer;
|
|
|
|
struct wl_listener destroy_listener;
|
|
|
|
} CoglandBufferReference;
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglandCompositor *compositor;
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
struct wl_resource *resource;
|
2011-05-25 14:27:10 -04:00
|
|
|
int x;
|
|
|
|
int y;
|
2013-06-27 09:22:41 -04:00
|
|
|
CoglandBufferReference buffer_ref;
|
2012-12-19 08:42:52 -05:00
|
|
|
CoglTexture2D *texture;
|
2011-12-12 14:31:01 -05:00
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool has_shell_surface;
|
2012-12-19 08:42:52 -05:00
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
struct wl_signal destroy_signal;
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
/* All the pending state, that wl_surface.commit will apply. */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
/* wl_surface.attach */
|
2013-05-02 12:56:38 -04:00
|
|
|
CoglBool newly_attached;
|
2013-06-27 09:22:41 -04:00
|
|
|
CoglandBuffer *buffer;
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_listener buffer_destroy_listener;
|
|
|
|
int32_t sx;
|
|
|
|
int32_t sy;
|
|
|
|
|
|
|
|
/* wl_surface.damage */
|
|
|
|
CoglandRegion damage;
|
|
|
|
|
|
|
|
/* wl_surface.frame */
|
|
|
|
struct wl_list frame_callback_list;
|
|
|
|
} pending;
|
2011-05-25 14:27:10 -04:00
|
|
|
} CoglandSurface;
|
|
|
|
|
2011-12-12 14:31:01 -05:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglandSurface *surface;
|
2013-06-28 12:57:54 -04:00
|
|
|
struct wl_resource *resource;
|
2011-12-12 14:31:01 -05:00
|
|
|
struct wl_listener surface_destroy_listener;
|
|
|
|
} CoglandShellSurface;
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t flags;
|
2011-05-25 14:27:10 -04:00
|
|
|
int width;
|
|
|
|
int height;
|
2011-12-01 17:58:17 -05:00
|
|
|
int refresh;
|
|
|
|
} CoglandMode;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct wl_object wayland_output;
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
int32_t x;
|
|
|
|
int32_t y;
|
|
|
|
int32_t width_mm;
|
|
|
|
int32_t height_mm;
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
CoglOnscreen *onscreen;
|
2011-12-01 17:58:17 -05:00
|
|
|
|
|
|
|
GList *modes;
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
} CoglandOutput;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
GPollFD pfd;
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_display *display;
|
2011-05-25 14:27:10 -04:00
|
|
|
} WaylandEventSource;
|
|
|
|
|
|
|
|
struct _CoglandCompositor
|
|
|
|
{
|
|
|
|
struct wl_display *wayland_display;
|
|
|
|
struct wl_event_loop *wayland_loop;
|
|
|
|
|
|
|
|
CoglContext *cogl_context;
|
|
|
|
|
|
|
|
int virtual_width;
|
|
|
|
int virtual_height;
|
|
|
|
GList *outputs;
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_list frame_callbacks;
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
CoglPrimitive *triangle;
|
2012-01-07 21:59:04 -05:00
|
|
|
CoglPipeline *triangle_pipeline;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
|
|
|
GSource *wayland_event_source;
|
|
|
|
|
|
|
|
GList *surfaces;
|
2013-03-22 09:57:58 -04:00
|
|
|
|
|
|
|
unsigned int redraw_idle;
|
2011-05-25 14:27:10 -04:00
|
|
|
};
|
|
|
|
|
2013-03-20 12:53:23 -04:00
|
|
|
static CoglBool option_multiple_outputs = FALSE;
|
|
|
|
|
|
|
|
static GOptionEntry
|
|
|
|
options[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"multiple", 'm', 0, G_OPTION_ARG_NONE, &option_multiple_outputs,
|
|
|
|
"Split the compositor into four outputs", NULL
|
|
|
|
},
|
|
|
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
process_arguments (int *argc, char ***argv,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GOptionContext *context;
|
|
|
|
CoglBool ret;
|
|
|
|
GOptionGroup *group;
|
|
|
|
|
|
|
|
group = g_option_group_new (NULL, /* name */
|
|
|
|
NULL, /* description */
|
|
|
|
NULL, /* help_description */
|
|
|
|
NULL, /* user_data */
|
|
|
|
NULL /* destroy notify */);
|
|
|
|
g_option_group_add_entries (group, options);
|
|
|
|
context = g_option_context_new ("- An example Wayland compositor using Cogl");
|
|
|
|
g_option_context_set_main_group (context, group);
|
|
|
|
ret = g_option_context_parse (context, argc, argv, error);
|
|
|
|
g_option_context_free (context);
|
|
|
|
|
|
|
|
if (ret && *argc > 1)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
|
|
|
|
"Unknown option '%s'", (* argv)[1]);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static uint32_t
|
2011-05-25 14:27:10 -04:00
|
|
|
get_time (void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
}
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
region_init (CoglandRegion *region)
|
|
|
|
{
|
|
|
|
memset (region, 0, sizeof (*region));
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
region_is_empty (const CoglandRegion *region)
|
|
|
|
{
|
|
|
|
return region->x1 == region->x2 || region->y1 == region->y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
region_add (CoglandRegion *region,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h)
|
|
|
|
{
|
|
|
|
if (region_is_empty (region))
|
|
|
|
{
|
|
|
|
region->x1 = x;
|
|
|
|
region->y1 = y;
|
|
|
|
region->x2 = x + w;
|
|
|
|
region->y2 = y + h;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (x < region->x1)
|
|
|
|
region->x1 = x;
|
|
|
|
if (y < region->y1)
|
|
|
|
region->y1 = y;
|
|
|
|
if (x + w > region->x2)
|
|
|
|
region->x2 = x + w;
|
|
|
|
if (y + h > region->y2)
|
|
|
|
region->y2 = y + h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
region_subtract (CoglandRegion *region,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int w,
|
|
|
|
int h)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-05-25 14:27:10 -04:00
|
|
|
wayland_event_source_prepare (GSource *base, int *timeout)
|
|
|
|
{
|
2013-03-22 09:23:42 -04:00
|
|
|
WaylandEventSource *source = (WaylandEventSource *)base;
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
*timeout = -1;
|
|
|
|
|
2013-03-22 09:23:42 -04:00
|
|
|
wl_display_flush_clients (source->display);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-05-25 14:27:10 -04:00
|
|
|
wayland_event_source_check (GSource *base)
|
|
|
|
{
|
|
|
|
WaylandEventSource *source = (WaylandEventSource *)base;
|
2012-12-19 08:42:52 -05:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
return source->pfd.revents;
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static CoglBool
|
2011-05-25 14:27:10 -04:00
|
|
|
wayland_event_source_dispatch (GSource *base,
|
|
|
|
GSourceFunc callback,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
WaylandEventSource *source = (WaylandEventSource *)base;
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop (source->display);
|
|
|
|
|
|
|
|
wl_event_loop_dispatch (loop, 0);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs wayland_event_source_funcs =
|
|
|
|
{
|
|
|
|
wayland_event_source_prepare,
|
|
|
|
wayland_event_source_check,
|
|
|
|
wayland_event_source_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2012-03-06 13:21:28 -05:00
|
|
|
static GSource *
|
2012-12-19 08:42:52 -05:00
|
|
|
wayland_event_source_new (struct wl_display *display)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
|
|
|
WaylandEventSource *source;
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_event_loop *loop =
|
|
|
|
wl_display_get_event_loop (display);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
|
|
|
source = (WaylandEventSource *) g_source_new (&wayland_event_source_funcs,
|
|
|
|
sizeof (WaylandEventSource));
|
2012-12-19 08:42:52 -05:00
|
|
|
source->display = display;
|
2011-05-25 14:27:10 -04:00
|
|
|
source->pfd.fd = wl_event_loop_get_fd (loop);
|
|
|
|
source->pfd.events = G_IO_IN | G_IO_ERR;
|
|
|
|
g_source_add_poll (&source->source, &source->pfd);
|
|
|
|
|
|
|
|
return &source->source;
|
|
|
|
}
|
|
|
|
|
2013-06-27 09:22:41 -04:00
|
|
|
static void
|
|
|
|
cogland_buffer_destroy_handler (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglandBuffer *buffer = wl_container_of (listener, buffer, destroy_listener);
|
|
|
|
|
|
|
|
wl_signal_emit (&buffer->destroy_signal, buffer);
|
|
|
|
g_slice_free (CoglandBuffer, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CoglandBuffer *
|
|
|
|
cogland_buffer_from_resource (struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
CoglandBuffer *buffer;
|
|
|
|
struct wl_listener *listener;
|
|
|
|
|
|
|
|
listener = wl_resource_get_destroy_listener (resource,
|
|
|
|
cogland_buffer_destroy_handler);
|
|
|
|
|
|
|
|
if (listener)
|
|
|
|
{
|
|
|
|
buffer = wl_container_of (listener, buffer, destroy_listener);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer = g_slice_new0 (CoglandBuffer);
|
|
|
|
|
|
|
|
buffer->resource = resource;
|
|
|
|
wl_signal_init (&buffer->destroy_signal);
|
|
|
|
buffer->destroy_listener.notify = cogland_buffer_destroy_handler;
|
|
|
|
wl_resource_add_destroy_listener (resource, &buffer->destroy_listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_buffer_reference_handle_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglandBufferReference *ref =
|
|
|
|
wl_container_of (listener, ref, destroy_listener);
|
|
|
|
|
|
|
|
g_assert (data == ref->buffer);
|
|
|
|
|
|
|
|
ref->buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_buffer_reference (CoglandBufferReference *ref,
|
|
|
|
CoglandBuffer *buffer)
|
|
|
|
{
|
|
|
|
if (ref->buffer && buffer != ref->buffer)
|
|
|
|
{
|
|
|
|
ref->buffer->busy_count--;
|
|
|
|
|
|
|
|
if (ref->buffer->busy_count == 0)
|
|
|
|
{
|
|
|
|
g_assert (wl_resource_get_client (ref->buffer->resource));
|
|
|
|
wl_resource_queue_event (ref->buffer->resource, WL_BUFFER_RELEASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove (&ref->destroy_listener.link);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer && buffer != ref->buffer)
|
|
|
|
{
|
|
|
|
buffer->busy_count++;
|
|
|
|
wl_signal_add (&buffer->destroy_signal, &ref->destroy_listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
ref->buffer = buffer;
|
|
|
|
ref->destroy_listener.notify = cogland_buffer_reference_handle_destroy;
|
|
|
|
}
|
|
|
|
|
2013-03-22 09:57:58 -04:00
|
|
|
typedef struct _CoglandFrameCallback
|
|
|
|
{
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
/* Pointer back to the compositor */
|
|
|
|
CoglandCompositor *compositor;
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
struct wl_resource *resource;
|
2013-03-22 09:57:58 -04:00
|
|
|
} CoglandFrameCallback;
|
|
|
|
|
|
|
|
static CoglBool
|
|
|
|
paint_cb (void *user_data)
|
|
|
|
{
|
|
|
|
CoglandCompositor *compositor = user_data;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = compositor->outputs; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglandOutput *output = l->data;
|
2013-10-09 08:31:12 -04:00
|
|
|
CoglFramebuffer *fb = output->onscreen;
|
2013-03-22 09:57:58 -04:00
|
|
|
GList *l2;
|
|
|
|
|
|
|
|
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
|
|
|
|
|
2013-07-09 18:47:29 -04:00
|
|
|
cogl_primitive_draw (compositor->triangle,
|
|
|
|
fb, compositor->triangle_pipeline);
|
2013-03-22 09:57:58 -04:00
|
|
|
|
|
|
|
for (l2 = compositor->surfaces; l2; l2 = l2->next)
|
|
|
|
{
|
|
|
|
CoglandSurface *surface = l2->data;
|
|
|
|
|
|
|
|
if (surface->texture)
|
|
|
|
{
|
|
|
|
CoglTexture2D *texture = surface->texture;
|
2013-10-09 08:31:12 -04:00
|
|
|
CoglPipeline *pipeline =
|
|
|
|
cogl_pipeline_new (compositor->cogl_context);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, texture);
|
|
|
|
cogl_framebuffer_draw_rectangle (fb, pipeline, -1, 1, 1, -1);
|
|
|
|
cogl_object_unref (pipeline);
|
2013-03-22 09:57:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cogl_onscreen_swap_buffers (COGL_ONSCREEN (fb));
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!wl_list_empty (&compositor->frame_callbacks))
|
|
|
|
{
|
|
|
|
CoglandFrameCallback *callback =
|
|
|
|
wl_container_of (compositor->frame_callbacks.next, callback, link);
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
wl_callback_send_done (callback->resource, get_time ());
|
|
|
|
wl_resource_destroy (callback->resource);
|
2013-03-22 09:57:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
compositor->redraw_idle = 0;
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_queue_redraw (CoglandCompositor *compositor)
|
|
|
|
{
|
|
|
|
if (compositor->redraw_idle == 0)
|
|
|
|
compositor->redraw_idle = g_idle_add (paint_cb, compositor);
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
static void
|
2013-04-11 11:41:17 -04:00
|
|
|
surface_damaged (CoglandSurface *surface,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-06-27 09:22:41 -04:00
|
|
|
if (surface->buffer_ref.buffer &&
|
|
|
|
surface->texture)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-06-27 09:22:41 -04:00
|
|
|
struct wl_shm_buffer *shm_buffer =
|
|
|
|
wl_shm_buffer_get (surface->buffer_ref.buffer->resource);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2013-06-27 09:22:41 -04:00
|
|
|
if (shm_buffer)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
2013-06-27 09:22:41 -04:00
|
|
|
CoglPixelFormat format;
|
|
|
|
int stride = wl_shm_buffer_get_stride (shm_buffer);
|
|
|
|
const uint8_t *data = wl_shm_buffer_get_data (shm_buffer);
|
|
|
|
|
|
|
|
switch (wl_shm_buffer_get_format (shm_buffer))
|
|
|
|
{
|
2011-12-01 17:58:17 -05:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2013-06-27 09:22:41 -04:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
break;
|
2011-12-01 17:58:17 -05:00
|
|
|
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2013-06-27 09:22:41 -04:00
|
|
|
case WL_SHM_FORMAT_ARGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
|
|
|
|
break;
|
|
|
|
case WL_SHM_FORMAT_XRGB8888:
|
|
|
|
format = COGL_PIXEL_FORMAT_BGRA_8888;
|
|
|
|
break;
|
2011-12-01 17:58:17 -05:00
|
|
|
#endif
|
2013-06-27 09:22:41 -04:00
|
|
|
default:
|
|
|
|
g_warn_if_reached ();
|
|
|
|
format = COGL_PIXEL_FORMAT_ARGB_8888;
|
|
|
|
}
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_texture_set_region (surface->texture,
|
2013-06-27 09:22:41 -04:00
|
|
|
x, y, /* src_x/y */
|
|
|
|
x, y, /* dst_x/y */
|
|
|
|
width, height, /* dst_width/height */
|
|
|
|
width, height, /* width/height */
|
|
|
|
format,
|
|
|
|
stride,
|
|
|
|
data);
|
|
|
|
}
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
2013-04-11 11:41:17 -04:00
|
|
|
|
|
|
|
cogland_queue_redraw (surface->compositor);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_surface_destroy (struct wl_client *wayland_client,
|
2011-12-01 17:58:17 -05:00
|
|
|
struct wl_resource *wayland_resource)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_resource_destroy (wayland_resource);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
cogland_surface_attach (struct wl_client *wayland_client,
|
|
|
|
struct wl_resource *wayland_surface_resource,
|
|
|
|
struct wl_resource *wayland_buffer_resource,
|
|
|
|
int32_t sx, int32_t sy)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface =
|
|
|
|
wl_resource_get_user_data (wayland_surface_resource);
|
2013-06-27 09:22:41 -04:00
|
|
|
CoglandBuffer *buffer;
|
|
|
|
|
|
|
|
if (wayland_buffer_resource)
|
|
|
|
buffer = cogland_buffer_from_resource (wayland_buffer_resource);
|
|
|
|
else
|
|
|
|
buffer = NULL;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
/* Attach without commit in between does not went wl_buffer.release */
|
|
|
|
if (surface->pending.buffer)
|
|
|
|
wl_list_remove (&surface->pending.buffer_destroy_listener.link);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
surface->pending.sx = sx;
|
|
|
|
surface->pending.sy = sy;
|
|
|
|
surface->pending.buffer = buffer;
|
2013-05-02 12:56:38 -04:00
|
|
|
surface->pending.newly_attached = TRUE;
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
if (buffer)
|
2013-06-27 09:22:41 -04:00
|
|
|
wl_signal_add (&buffer->destroy_signal,
|
2012-12-19 08:42:52 -05:00
|
|
|
&surface->pending.buffer_destroy_listener);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 17:58:17 -05:00
|
|
|
cogland_surface_damage (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface = wl_resource_get_user_data (resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
region_add (&surface->pending.damage, x, y, width, height);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 17:58:17 -05:00
|
|
|
destroy_frame_callback (struct wl_resource *callback_resource)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-06-28 12:57:54 -04:00
|
|
|
CoglandFrameCallback *callback =
|
|
|
|
wl_resource_get_user_data (callback_resource);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_list_remove (&callback->link);
|
2011-12-01 17:58:17 -05:00
|
|
|
g_slice_free (CoglandFrameCallback, callback);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 17:58:17 -05:00
|
|
|
cogland_surface_frame (struct wl_client *client,
|
|
|
|
struct wl_resource *surface_resource,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t callback_id)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2011-12-01 17:58:17 -05:00
|
|
|
CoglandFrameCallback *callback;
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface = wl_resource_get_user_data (surface_resource);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
|
|
|
callback = g_slice_new0 (CoglandFrameCallback);
|
2011-12-13 12:38:36 -05:00
|
|
|
callback->compositor = surface->compositor;
|
2013-06-28 12:57:54 -04:00
|
|
|
callback->resource = wl_client_add_object (client,
|
|
|
|
&wl_callback_interface,
|
|
|
|
NULL, /* no implementation */
|
|
|
|
callback_id,
|
|
|
|
callback);
|
|
|
|
wl_resource_set_destructor (callback->resource, destroy_frame_callback);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_list_insert (surface->pending.frame_callback_list.prev, &callback->link);
|
|
|
|
}
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
cogland_surface_set_opaque_region (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *region)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_surface_set_input_region (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *region)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_surface_commit (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface = wl_resource_get_user_data (resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
CoglandCompositor *compositor = surface->compositor;
|
|
|
|
|
|
|
|
/* wl_surface.attach */
|
2013-05-02 12:56:38 -04:00
|
|
|
if (surface->pending.newly_attached &&
|
2013-06-27 09:22:41 -04:00
|
|
|
surface->buffer_ref.buffer != surface->pending.buffer)
|
2012-12-19 08:42:52 -05:00
|
|
|
{
|
|
|
|
CoglError *error = NULL;
|
|
|
|
|
2013-06-27 09:22:41 -04:00
|
|
|
if (surface->texture)
|
|
|
|
{
|
|
|
|
cogl_object_unref (surface->texture);
|
|
|
|
surface->texture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogland_buffer_reference (&surface->buffer_ref, surface->pending.buffer);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
if (surface->pending.buffer)
|
|
|
|
{
|
2013-06-27 09:22:41 -04:00
|
|
|
struct wl_resource *buffer_resource =
|
|
|
|
surface->pending.buffer->resource;
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
surface->texture =
|
|
|
|
cogl_wayland_texture_2d_new_from_buffer (compositor->cogl_context,
|
2013-06-27 09:22:41 -04:00
|
|
|
buffer_resource,
|
2012-12-19 08:42:52 -05:00
|
|
|
&error);
|
|
|
|
|
|
|
|
if (!surface->texture)
|
|
|
|
{
|
|
|
|
g_error ("Failed to create texture_2d from wayland buffer: %s",
|
|
|
|
error->message);
|
|
|
|
cogl_error_free (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-11 07:40:51 -04:00
|
|
|
if (surface->pending.buffer)
|
|
|
|
{
|
|
|
|
wl_list_remove (&surface->pending.buffer_destroy_listener.link);
|
|
|
|
surface->pending.buffer = NULL;
|
|
|
|
}
|
2012-12-19 08:42:52 -05:00
|
|
|
surface->pending.sx = 0;
|
|
|
|
surface->pending.sy = 0;
|
2013-05-02 12:56:38 -04:00
|
|
|
surface->pending.newly_attached = FALSE;
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
/* wl_surface.damage */
|
2013-06-27 09:22:41 -04:00
|
|
|
if (surface->buffer_ref.buffer &&
|
2012-12-19 08:42:52 -05:00
|
|
|
surface->texture &&
|
|
|
|
!region_is_empty (&surface->pending.damage))
|
|
|
|
{
|
|
|
|
CoglandRegion *region = &surface->pending.damage;
|
2013-10-09 08:31:12 -04:00
|
|
|
CoglTexture *texture = surface->texture;
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
if (region->x2 > cogl_texture_get_width (texture))
|
|
|
|
region->x2 = cogl_texture_get_width (texture);
|
|
|
|
if (region->y2 > cogl_texture_get_height (texture))
|
|
|
|
region->y2 = cogl_texture_get_height (texture);
|
|
|
|
if (region->x1 < 0)
|
|
|
|
region->x1 = 0;
|
|
|
|
if (region->y1 < 0)
|
|
|
|
region->y1 = 0;
|
|
|
|
|
2013-04-11 11:41:17 -04:00
|
|
|
surface_damaged (surface,
|
|
|
|
region->x1,
|
|
|
|
region->y1,
|
|
|
|
region->x2 - region->x1,
|
|
|
|
region->y2 - region->y1);
|
2012-12-19 08:42:52 -05:00
|
|
|
}
|
|
|
|
region_init (&surface->pending.damage);
|
|
|
|
|
|
|
|
/* wl_surface.frame */
|
|
|
|
wl_list_insert_list (&compositor->frame_callbacks,
|
|
|
|
&surface->pending.frame_callback_list);
|
|
|
|
wl_list_init (&surface->pending.frame_callback_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_surface_set_buffer_transform (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t transform)
|
|
|
|
{
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const struct wl_surface_interface cogland_surface_interface = {
|
|
|
|
cogland_surface_destroy,
|
2012-12-19 08:42:52 -05:00
|
|
|
cogland_surface_attach,
|
2011-12-01 17:58:17 -05:00
|
|
|
cogland_surface_damage,
|
2012-12-19 08:42:52 -05:00
|
|
|
cogland_surface_frame,
|
|
|
|
cogland_surface_set_opaque_region,
|
|
|
|
cogland_surface_set_input_region,
|
|
|
|
cogland_surface_commit,
|
|
|
|
cogland_surface_set_buffer_transform
|
2011-05-25 14:27:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_surface_free (CoglandSurface *surface)
|
|
|
|
{
|
|
|
|
CoglandCompositor *compositor = surface->compositor;
|
2012-12-19 08:42:52 -05:00
|
|
|
CoglandFrameCallback *cb, *next;
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
wl_signal_emit (&surface->destroy_signal, &surface->resource);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
compositor->surfaces = g_list_remove (compositor->surfaces, surface);
|
2013-06-27 09:22:41 -04:00
|
|
|
|
|
|
|
cogland_buffer_reference (&surface->buffer_ref, NULL);
|
|
|
|
if (surface->texture)
|
|
|
|
cogl_object_unref (surface->texture);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
2013-04-11 07:40:51 -04:00
|
|
|
if (surface->pending.buffer)
|
|
|
|
wl_list_remove (&surface->pending.buffer_destroy_listener.link);
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_list_for_each_safe (cb, next,
|
|
|
|
&surface->pending.frame_callback_list, link)
|
2013-06-28 12:57:54 -04:00
|
|
|
wl_resource_destroy (cb->resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
g_slice_free (CoglandSurface, surface);
|
2013-06-27 09:22:41 -04:00
|
|
|
|
|
|
|
cogland_queue_redraw (compositor);
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
2013-06-27 09:22:41 -04:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
static void
|
2011-12-01 17:58:17 -05:00
|
|
|
cogland_surface_resource_destroy_cb (struct wl_resource *resource)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface = wl_resource_get_user_data (resource);
|
2011-05-25 14:27:10 -04:00
|
|
|
cogland_surface_free (surface);
|
|
|
|
}
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
surface_handle_pending_buffer_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglandSurface *surface =
|
|
|
|
wl_container_of (listener, surface, pending.buffer_destroy_listener);
|
|
|
|
|
|
|
|
surface->pending.buffer = NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
static void
|
|
|
|
cogland_compositor_create_surface (struct wl_client *wayland_client,
|
2011-12-01 17:58:17 -05:00
|
|
|
struct wl_resource *wayland_compositor_resource,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t id)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandCompositor *compositor =
|
|
|
|
wl_resource_get_user_data (wayland_compositor_resource);
|
2011-05-25 14:27:10 -04:00
|
|
|
CoglandSurface *surface = g_slice_new0 (CoglandSurface);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
surface->compositor = compositor;
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
wl_signal_init (&surface->destroy_signal);
|
|
|
|
|
|
|
|
surface->resource = wl_client_add_object (wayland_client,
|
|
|
|
&wl_surface_interface,
|
|
|
|
&cogland_surface_interface,
|
|
|
|
id,
|
|
|
|
surface);
|
|
|
|
wl_resource_set_destructor (surface->resource,
|
|
|
|
cogland_surface_resource_destroy_cb);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
surface->pending.buffer_destroy_listener.notify =
|
|
|
|
surface_handle_pending_buffer_destroy;
|
|
|
|
wl_list_init (&surface->pending.frame_callback_list);
|
|
|
|
region_init (&surface->pending.damage);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
compositor->surfaces = g_list_prepend (compositor->surfaces,
|
|
|
|
surface);
|
|
|
|
}
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
cogland_region_destroy (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
|
|
|
{
|
|
|
|
wl_resource_destroy (resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_region_add (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSharedRegion *shared_region = wl_resource_get_user_data (resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
region_add (&shared_region->region, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_region_subtract (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
int32_t width,
|
|
|
|
int32_t height)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSharedRegion *shared_region = wl_resource_get_user_data (resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
region_subtract (&shared_region->region, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct wl_region_interface cogland_region_interface = {
|
|
|
|
cogland_region_destroy,
|
|
|
|
cogland_region_add,
|
|
|
|
cogland_region_subtract
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_region_resource_destroy_cb (struct wl_resource *resource)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSharedRegion *region = wl_resource_get_user_data (resource);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
g_slice_free (CoglandSharedRegion, region);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cogland_compositor_create_region (struct wl_client *wayland_client,
|
|
|
|
struct wl_resource *compositor_resource,
|
|
|
|
uint32_t id)
|
|
|
|
{
|
|
|
|
CoglandSharedRegion *region = g_slice_new0 (CoglandSharedRegion);
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
region->resource = wl_client_add_object (wayland_client,
|
|
|
|
&wl_region_interface,
|
|
|
|
&cogland_region_interface,
|
|
|
|
id,
|
|
|
|
region);
|
|
|
|
wl_resource_set_destructor (region->resource,
|
|
|
|
cogland_region_resource_destroy_cb);
|
2012-12-19 08:42:52 -05:00
|
|
|
|
|
|
|
region_init (®ion->region);
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
static void
|
2011-12-01 17:58:17 -05:00
|
|
|
bind_output (struct wl_client *client,
|
|
|
|
void *data,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
CoglandOutput *output = data;
|
|
|
|
struct wl_resource *resource =
|
|
|
|
wl_client_add_object (client, &wl_output_interface, NULL, id, data);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
wl_resource_post_event (resource,
|
|
|
|
WL_OUTPUT_GEOMETRY,
|
|
|
|
output->x, output->y,
|
|
|
|
output->width_mm,
|
|
|
|
output->height_mm,
|
|
|
|
0, /* subpixel: unknown */
|
|
|
|
"unknown", /* make */
|
|
|
|
"unknown"); /* model */
|
|
|
|
|
|
|
|
for (l = output->modes; l; l = l->next)
|
|
|
|
{
|
|
|
|
CoglandMode *mode = l->data;
|
|
|
|
wl_resource_post_event (resource,
|
|
|
|
WL_OUTPUT_MODE,
|
|
|
|
mode->flags,
|
|
|
|
mode->width,
|
|
|
|
mode->height,
|
|
|
|
mode->refresh);
|
|
|
|
}
|
2011-05-25 14:27:10 -04:00
|
|
|
}
|
|
|
|
|
2013-05-14 08:41:29 -04:00
|
|
|
static void
|
|
|
|
dirty_cb (CoglOnscreen *onscreen,
|
|
|
|
const CoglOnscreenDirtyInfo *info,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
CoglandCompositor *compositor = user_data;
|
|
|
|
|
|
|
|
cogland_queue_redraw (compositor);
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
static void
|
|
|
|
cogland_compositor_create_output (CoglandCompositor *compositor,
|
|
|
|
int x,
|
|
|
|
int y,
|
2011-12-01 17:58:17 -05:00
|
|
|
int width_mm,
|
|
|
|
int height_mm)
|
2011-05-25 14:27:10 -04:00
|
|
|
{
|
|
|
|
CoglandOutput *output = g_slice_new0 (CoglandOutput);
|
|
|
|
CoglFramebuffer *fb;
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError *error = NULL;
|
2011-12-01 17:58:17 -05:00
|
|
|
CoglandMode *mode;
|
|
|
|
|
|
|
|
output->x = x;
|
|
|
|
output->y = y;
|
|
|
|
output->width_mm = width_mm;
|
|
|
|
output->height_mm = height_mm;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
|
|
|
output->wayland_output.interface = &wl_output_interface;
|
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
wl_display_add_global (compositor->wayland_display,
|
|
|
|
&wl_output_interface,
|
|
|
|
output,
|
|
|
|
bind_output);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
|
|
|
output->onscreen = cogl_onscreen_new (compositor->cogl_context,
|
2011-12-01 17:58:17 -05:00
|
|
|
width_mm, height_mm);
|
2011-05-25 14:27:10 -04:00
|
|
|
/* Eventually there will be an implicit allocate on first use so this
|
|
|
|
* will become optional... */
|
2013-10-09 08:31:12 -04:00
|
|
|
fb = output->onscreen;
|
2011-05-25 14:27:10 -04:00
|
|
|
if (!cogl_framebuffer_allocate (fb, &error))
|
|
|
|
g_error ("Failed to allocate framebuffer: %s\n", error->message);
|
|
|
|
|
2013-05-14 08:41:29 -04:00
|
|
|
cogl_onscreen_add_dirty_callback (output->onscreen,
|
|
|
|
dirty_cb,
|
|
|
|
compositor,
|
|
|
|
NULL /* destroy */);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
cogl_onscreen_show (output->onscreen);
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_framebuffer_set_viewport (fb,
|
|
|
|
-x, -y,
|
2013-03-22 17:18:53 -04:00
|
|
|
compositor->virtual_width,
|
|
|
|
compositor->virtual_height);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
mode = g_slice_new0 (CoglandMode);
|
|
|
|
mode->flags = 0;
|
|
|
|
mode->width = width_mm;
|
|
|
|
mode->height = height_mm;
|
|
|
|
mode->refresh = 60;
|
|
|
|
|
|
|
|
output->modes = g_list_prepend (output->modes, mode);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
compositor->outputs = g_list_prepend (compositor->outputs, output);
|
|
|
|
}
|
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
const static struct wl_compositor_interface cogland_compositor_interface =
|
|
|
|
{
|
|
|
|
cogland_compositor_create_surface,
|
2012-12-19 08:42:52 -05:00
|
|
|
cogland_compositor_create_region
|
2011-12-01 17:58:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
compositor_bind (struct wl_client *client,
|
2011-12-12 13:08:10 -05:00
|
|
|
void *data,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
CoglandCompositor *compositor = data;
|
|
|
|
|
|
|
|
wl_client_add_object (client, &wl_compositor_interface,
|
|
|
|
&cogland_compositor_interface, id, compositor);
|
|
|
|
}
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
static void
|
|
|
|
shell_surface_pong (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
static void
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_move (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_resource *seat,
|
|
|
|
uint32_t serial)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_resize (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_resource *seat,
|
|
|
|
uint32_t serial,
|
2011-12-12 14:31:01 -05:00
|
|
|
uint32_t edges)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_set_toplevel (struct wl_client *client,
|
|
|
|
struct wl_resource *resource)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_set_transient (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *parent,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
uint32_t flags)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_set_fullscreen (struct wl_client *client,
|
2012-12-19 08:42:52 -05:00
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t method,
|
|
|
|
uint32_t framerate,
|
|
|
|
struct wl_resource *output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_set_popup (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *seat,
|
|
|
|
uint32_t serial,
|
|
|
|
struct wl_resource *parent,
|
|
|
|
int32_t x,
|
|
|
|
int32_t y,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_set_maximized (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
struct wl_resource *output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_set_title (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *title)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_surface_set_class (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
const char *class_)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:31:01 -05:00
|
|
|
static const struct wl_shell_surface_interface cogl_shell_surface_interface =
|
|
|
|
{
|
2012-12-19 08:42:52 -05:00
|
|
|
shell_surface_pong,
|
2011-12-12 14:31:01 -05:00
|
|
|
shell_surface_move,
|
|
|
|
shell_surface_resize,
|
|
|
|
shell_surface_set_toplevel,
|
|
|
|
shell_surface_set_transient,
|
2012-12-19 08:42:52 -05:00
|
|
|
shell_surface_set_fullscreen,
|
|
|
|
shell_surface_set_popup,
|
|
|
|
shell_surface_set_maximized,
|
|
|
|
shell_surface_set_title,
|
|
|
|
shell_surface_set_class
|
2011-12-12 14:31:01 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2013-06-28 12:57:54 -04:00
|
|
|
destroy_shell_surface (CoglandShellSurface *shell_surface)
|
2011-12-12 14:31:01 -05:00
|
|
|
{
|
|
|
|
/* In case cleaning up a dead client destroys shell_surface first */
|
|
|
|
if (shell_surface->surface)
|
|
|
|
{
|
|
|
|
wl_list_remove (&shell_surface->surface_destroy_listener.link);
|
|
|
|
shell_surface->surface->has_shell_surface = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (shell_surface);
|
|
|
|
}
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
static void
|
|
|
|
destroy_shell_surface_cb (struct wl_resource *resource)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
destroy_shell_surface (wl_resource_get_user_data (resource));
|
2013-06-28 12:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_handle_surface_destroy (struct wl_listener *listener,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
CoglandShellSurface *shell_surface =
|
|
|
|
wl_container_of (listener, shell_surface, surface_destroy_listener);
|
|
|
|
|
|
|
|
shell_surface->surface->has_shell_surface = FALSE;
|
|
|
|
shell_surface->surface = NULL;
|
|
|
|
|
|
|
|
if (shell_surface->resource)
|
|
|
|
wl_resource_destroy (shell_surface->resource);
|
|
|
|
else
|
|
|
|
destroy_shell_surface (shell_surface);
|
|
|
|
}
|
|
|
|
|
2011-12-12 14:31:01 -05:00
|
|
|
static void
|
|
|
|
get_shell_surface (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
uint32_t id,
|
|
|
|
struct wl_resource *surface_resource)
|
|
|
|
{
|
2013-07-02 10:16:36 -04:00
|
|
|
CoglandSurface *surface = wl_resource_get_user_data (surface_resource);
|
2013-04-11 07:43:53 -04:00
|
|
|
CoglandShellSurface *shell_surface;
|
2011-12-12 14:31:01 -05:00
|
|
|
|
|
|
|
if (surface->has_shell_surface)
|
|
|
|
{
|
|
|
|
wl_resource_post_error (surface_resource,
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
"wl_shell::get_shell_surface already requested");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-11 07:43:53 -04:00
|
|
|
shell_surface = g_new0 (CoglandShellSurface, 1);
|
2011-12-12 14:31:01 -05:00
|
|
|
|
|
|
|
shell_surface->surface = surface;
|
2013-06-28 12:57:54 -04:00
|
|
|
shell_surface->surface_destroy_listener.notify =
|
|
|
|
shell_handle_surface_destroy;
|
|
|
|
wl_signal_add (&surface->destroy_signal,
|
2012-12-19 08:42:52 -05:00
|
|
|
&shell_surface->surface_destroy_listener);
|
2011-12-12 14:31:01 -05:00
|
|
|
|
|
|
|
surface->has_shell_surface = TRUE;
|
|
|
|
|
2013-06-28 12:57:54 -04:00
|
|
|
shell_surface->resource = wl_client_add_object (client,
|
|
|
|
&wl_shell_surface_interface,
|
|
|
|
&cogl_shell_surface_interface,
|
|
|
|
id,
|
|
|
|
shell_surface);
|
|
|
|
wl_resource_set_destructor (shell_surface->resource,
|
|
|
|
destroy_shell_surface_cb);
|
2011-12-12 14:31:01 -05:00
|
|
|
}
|
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
static const struct wl_shell_interface cogland_shell_interface =
|
|
|
|
{
|
2011-12-12 14:31:01 -05:00
|
|
|
get_shell_surface
|
2011-12-01 17:58:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_shell (struct wl_client *client,
|
|
|
|
void *data,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint32_t version,
|
|
|
|
uint32_t id)
|
2011-12-01 17:58:17 -05:00
|
|
|
{
|
|
|
|
wl_client_add_object (client, &wl_shell_interface,
|
|
|
|
&cogland_shell_interface, id, data);
|
|
|
|
}
|
|
|
|
|
2013-04-11 12:02:05 -04:00
|
|
|
static CoglContext *
|
|
|
|
create_cogl_context (CoglandCompositor *compositor,
|
|
|
|
CoglBool use_egl_constraint,
|
|
|
|
CoglError **error)
|
|
|
|
{
|
|
|
|
CoglRenderer *renderer = renderer = cogl_renderer_new ();
|
|
|
|
CoglDisplay *display;
|
|
|
|
CoglContext *context;
|
|
|
|
|
|
|
|
if (use_egl_constraint)
|
|
|
|
cogl_renderer_add_constraint (renderer, COGL_RENDERER_CONSTRAINT_USES_EGL);
|
|
|
|
|
|
|
|
if (!cogl_renderer_connect (renderer, error))
|
|
|
|
{
|
|
|
|
cogl_object_unref (renderer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
display = cogl_display_new (renderer, NULL);
|
|
|
|
cogl_wayland_display_set_compositor_display (display,
|
|
|
|
compositor->wayland_display);
|
|
|
|
|
|
|
|
context = cogl_context_new (display, error);
|
|
|
|
|
|
|
|
cogl_object_unref (renderer);
|
|
|
|
cogl_object_unref (display);
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
CoglandCompositor compositor;
|
|
|
|
GMainLoop *loop;
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError *error = NULL;
|
2013-03-20 12:53:23 -04:00
|
|
|
GError *gerror = NULL;
|
2011-05-25 14:27:10 -04:00
|
|
|
CoglVertexP2C4 triangle_vertices[] = {
|
2013-04-19 12:55:29 -04:00
|
|
|
{0, 0.7, 0xff, 0x00, 0x00, 0xff},
|
2011-05-25 14:27:10 -04:00
|
|
|
{-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
|
|
|
|
{0.7, -0.7, 0x00, 0x00, 0xff, 0xff}
|
|
|
|
};
|
2011-12-19 10:40:55 -05:00
|
|
|
GSource *cogl_source;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2013-03-20 12:53:23 -04:00
|
|
|
if (!process_arguments (&argc, &argv, &gerror))
|
|
|
|
{
|
|
|
|
fprintf (stderr, "%s\n", gerror->message);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
memset (&compositor, 0, sizeof (compositor));
|
|
|
|
|
|
|
|
compositor.wayland_display = wl_display_create ();
|
|
|
|
if (compositor.wayland_display == NULL)
|
|
|
|
g_error ("failed to create wayland display");
|
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_list_init (&compositor.frame_callbacks);
|
2011-12-01 17:58:17 -05:00
|
|
|
|
|
|
|
if (!wl_display_add_global (compositor.wayland_display,
|
|
|
|
&wl_compositor_interface,
|
2011-12-12 13:08:10 -05:00
|
|
|
&compositor,
|
2011-12-01 17:58:17 -05:00
|
|
|
compositor_bind))
|
|
|
|
g_error ("Failed to register wayland compositor object");
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2012-12-19 08:42:52 -05:00
|
|
|
wl_display_init_shm (compositor.wayland_display);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
compositor.wayland_loop =
|
|
|
|
wl_display_get_event_loop (compositor.wayland_display);
|
|
|
|
compositor.wayland_event_source =
|
2012-12-19 08:42:52 -05:00
|
|
|
wayland_event_source_new (compositor.wayland_display);
|
2011-05-25 14:27:10 -04:00
|
|
|
g_source_attach (compositor.wayland_event_source, NULL);
|
|
|
|
|
2013-04-11 12:02:05 -04:00
|
|
|
/* We want Cogl to use an EGL renderer because otherwise it won't
|
|
|
|
* set up the wl_drm object and only SHM buffers will work. */
|
|
|
|
compositor.cogl_context =
|
|
|
|
create_cogl_context (&compositor,
|
|
|
|
TRUE /* use EGL constraint */,
|
|
|
|
&error);
|
|
|
|
if (compositor.cogl_context == NULL)
|
|
|
|
{
|
|
|
|
/* If we couldn't get an EGL context then try any type of
|
|
|
|
* context */
|
|
|
|
cogl_error_free (error);
|
|
|
|
error = NULL;
|
|
|
|
|
|
|
|
compositor.cogl_context =
|
|
|
|
create_cogl_context (&compositor,
|
|
|
|
FALSE, /* don't set EGL constraint */
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (compositor.cogl_context)
|
|
|
|
g_warning ("Failed to create context with EGL constraint, "
|
|
|
|
"falling back");
|
|
|
|
else
|
|
|
|
g_error ("Failed to create a Cogl context: %s\n", error->message);
|
|
|
|
}
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2013-03-21 10:00:03 -04:00
|
|
|
compositor.virtual_width = 800;
|
|
|
|
compositor.virtual_height = 600;
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2013-03-20 12:53:23 -04:00
|
|
|
if (option_multiple_outputs)
|
|
|
|
{
|
2013-03-21 10:00:03 -04:00
|
|
|
int hw = compositor.virtual_width / 2;
|
|
|
|
int hh = compositor.virtual_height / 2;
|
2013-03-20 12:53:23 -04:00
|
|
|
/* Emulate compositing with multiple monitors... */
|
2013-03-21 10:00:03 -04:00
|
|
|
cogland_compositor_create_output (&compositor, 0, 0, hw, hh);
|
|
|
|
cogland_compositor_create_output (&compositor, hw, 0, hw, hh);
|
|
|
|
cogland_compositor_create_output (&compositor, 0, hh, hw, hh);
|
|
|
|
cogland_compositor_create_output (&compositor, hw, hh, hw, hh);
|
2013-03-20 12:53:23 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-21 10:00:03 -04:00
|
|
|
cogland_compositor_create_output (&compositor,
|
|
|
|
0, 0,
|
|
|
|
compositor.virtual_width,
|
|
|
|
compositor.virtual_height);
|
2013-03-20 12:53:23 -04:00
|
|
|
}
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2011-12-01 17:58:17 -05:00
|
|
|
if (wl_display_add_global (compositor.wayland_display, &wl_shell_interface,
|
|
|
|
&compositor, bind_shell) == NULL)
|
|
|
|
g_error ("Failed to register a global shell object");
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
if (wl_display_add_socket (compositor.wayland_display, "wayland-0"))
|
|
|
|
g_error ("Failed to create socket");
|
|
|
|
|
2012-02-06 12:08:58 -05:00
|
|
|
compositor.triangle = cogl_primitive_new_p2c4 (compositor.cogl_context,
|
|
|
|
COGL_VERTICES_MODE_TRIANGLES,
|
2011-05-25 14:27:10 -04:00
|
|
|
3, triangle_vertices);
|
2012-02-18 11:03:10 -05:00
|
|
|
compositor.triangle_pipeline = cogl_pipeline_new (compositor.cogl_context);
|
2011-05-25 14:27:10 -04:00
|
|
|
|
2011-12-19 10:40:55 -05:00
|
|
|
cogl_source = cogl_glib_source_new (compositor.cogl_context,
|
|
|
|
G_PRIORITY_DEFAULT);
|
|
|
|
|
|
|
|
g_source_attach (cogl_source, NULL);
|
|
|
|
|
2011-05-25 14:27:10 -04:00
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|