2011-05-05 18:34:38 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
|
|
|
static const ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
|
|
|
|
|
|
|
|
#ifdef COGL_HAS_XLIB
|
|
|
|
|
|
|
|
#include <clutter/x11/clutter-x11.h>
|
|
|
|
#include <cogl/cogl-texture-pixmap-x11.h>
|
|
|
|
|
|
|
|
#define PIXMAP_WIDTH 512
|
|
|
|
#define PIXMAP_HEIGHT 256
|
|
|
|
#define GRID_SQUARE_SIZE 16
|
|
|
|
|
|
|
|
/* Coordinates of a square that we'll update */
|
|
|
|
#define PIXMAP_CHANGE_X 1
|
|
|
|
#define PIXMAP_CHANGE_Y 1
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
ClutterActor *stage;
|
|
|
|
CoglHandle tfp;
|
|
|
|
Pixmap pixmap;
|
|
|
|
unsigned int frame_count;
|
|
|
|
Display *display;
|
|
|
|
} TestState;
|
|
|
|
|
|
|
|
static Pixmap
|
|
|
|
create_pixmap (TestState *state)
|
|
|
|
{
|
|
|
|
Pixmap pixmap;
|
|
|
|
XGCValues gc_values = { 0, };
|
|
|
|
GC black_gc, white_gc;
|
|
|
|
int screen = DefaultScreen (state->display);
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
pixmap = XCreatePixmap (state->display,
|
|
|
|
DefaultRootWindow (state->display),
|
|
|
|
PIXMAP_WIDTH, PIXMAP_HEIGHT,
|
|
|
|
DefaultDepth (state->display, screen));
|
|
|
|
|
|
|
|
gc_values.foreground = BlackPixel (state->display, screen);
|
|
|
|
black_gc = XCreateGC (state->display, pixmap, GCForeground, &gc_values);
|
|
|
|
gc_values.foreground = WhitePixel (state->display, screen);
|
|
|
|
white_gc = XCreateGC (state->display, pixmap, GCForeground, &gc_values);
|
|
|
|
|
|
|
|
/* Draw a grid of alternative black and white rectangles to the
|
|
|
|
pixmap */
|
|
|
|
for (y = 0; y < PIXMAP_HEIGHT / GRID_SQUARE_SIZE; y++)
|
|
|
|
for (x = 0; x < PIXMAP_WIDTH / GRID_SQUARE_SIZE; x++)
|
|
|
|
XFillRectangle (state->display, pixmap,
|
|
|
|
((x ^ y) & 1) ? black_gc : white_gc,
|
|
|
|
x * GRID_SQUARE_SIZE,
|
|
|
|
y * GRID_SQUARE_SIZE,
|
|
|
|
GRID_SQUARE_SIZE,
|
|
|
|
GRID_SQUARE_SIZE);
|
|
|
|
|
|
|
|
XFreeGC (state->display, black_gc);
|
|
|
|
XFreeGC (state->display, white_gc);
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_pixmap (TestState *state)
|
|
|
|
{
|
|
|
|
XGCValues gc_values = { 0, };
|
|
|
|
GC black_gc;
|
|
|
|
int screen = DefaultScreen (state->display);
|
|
|
|
|
|
|
|
gc_values.foreground = BlackPixel (state->display, screen);
|
|
|
|
black_gc = XCreateGC (state->display, state->pixmap,
|
|
|
|
GCForeground, &gc_values);
|
|
|
|
|
|
|
|
/* Fill in one the rectangles with black */
|
|
|
|
XFillRectangle (state->display, state->pixmap,
|
|
|
|
black_gc,
|
|
|
|
PIXMAP_CHANGE_X * GRID_SQUARE_SIZE,
|
|
|
|
PIXMAP_CHANGE_Y * GRID_SQUARE_SIZE,
|
|
|
|
GRID_SQUARE_SIZE, GRID_SQUARE_SIZE);
|
|
|
|
|
|
|
|
XFreeGC (state->display, black_gc);
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
2011-05-05 18:34:38 -04:00
|
|
|
check_paint (TestState *state, int x, int y, int scale)
|
|
|
|
{
|
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
|
|
|
uint8_t *data, *p, update_value = 0;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
p = data = g_malloc (PIXMAP_WIDTH * PIXMAP_HEIGHT * 4);
|
|
|
|
|
|
|
|
cogl_read_pixels (x, y, PIXMAP_WIDTH / scale, PIXMAP_HEIGHT / scale,
|
|
|
|
COGL_READ_PIXELS_COLOR_BUFFER,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
data);
|
|
|
|
|
|
|
|
for (y = 0; y < PIXMAP_HEIGHT / scale; y++)
|
|
|
|
for (x = 0; x < PIXMAP_WIDTH / scale; x++)
|
|
|
|
{
|
|
|
|
int grid_x = x * scale / GRID_SQUARE_SIZE;
|
|
|
|
int grid_y = y * scale / GRID_SQUARE_SIZE;
|
|
|
|
|
|
|
|
/* If this is the updatable square then we'll let it be either
|
|
|
|
color but we'll return which one it was */
|
|
|
|
if (grid_x == PIXMAP_CHANGE_X && grid_y == PIXMAP_CHANGE_Y)
|
|
|
|
{
|
|
|
|
if (x % (GRID_SQUARE_SIZE / scale) == 0 &&
|
|
|
|
y % (GRID_SQUARE_SIZE / scale) == 0)
|
|
|
|
update_value = *p;
|
|
|
|
else
|
|
|
|
g_assert_cmpint (p[0], ==, update_value);
|
|
|
|
|
|
|
|
g_assert (p[1] == update_value);
|
|
|
|
g_assert (p[2] == update_value);
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
uint8_t value = ((grid_x ^ grid_y) & 1) ? 0x00 : 0xff;
|
2011-05-05 18:34:38 -04:00
|
|
|
g_assert_cmpint (*(p++), ==, value);
|
|
|
|
g_assert_cmpint (*(p++), ==, value);
|
|
|
|
g_assert_cmpint (*(p++), ==, value);
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return update_value == 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We skip these frames first */
|
|
|
|
#define FRAME_COUNT_BASE 5
|
|
|
|
/* First paint the tfp with no mipmaps */
|
|
|
|
#define FRAME_COUNT_NORMAL 6
|
|
|
|
/* Then use mipmaps */
|
|
|
|
#define FRAME_COUNT_MIPMAP 7
|
|
|
|
/* After this frame will start waiting for the pixmap to change */
|
|
|
|
#define FRAME_COUNT_UPDATED 8
|
|
|
|
|
|
|
|
static void
|
2019-11-13 16:21:58 -05:00
|
|
|
on_paint (ClutterActor *actor,
|
|
|
|
ClutterPaintContext *paint_context,
|
|
|
|
TestState *state)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
CoglHandle material;
|
|
|
|
|
|
|
|
material = cogl_material_new ();
|
|
|
|
cogl_material_set_layer (material, 0, state->tfp);
|
|
|
|
if (state->frame_count == FRAME_COUNT_MIPMAP)
|
|
|
|
{
|
|
|
|
const CoglMaterialFilter min_filter =
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST_MIPMAP_NEAREST;
|
|
|
|
cogl_material_set_layer_filters (material, 0,
|
|
|
|
min_filter,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cogl_material_set_layer_filters (material, 0,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST,
|
|
|
|
COGL_MATERIAL_FILTER_NEAREST);
|
|
|
|
cogl_set_source (material);
|
|
|
|
|
|
|
|
cogl_rectangle (0, 0, PIXMAP_WIDTH, PIXMAP_HEIGHT);
|
|
|
|
|
|
|
|
cogl_rectangle (0, PIXMAP_HEIGHT,
|
|
|
|
PIXMAP_WIDTH / 4, PIXMAP_HEIGHT * 5 / 4);
|
|
|
|
|
|
|
|
if (state->frame_count >= 5)
|
|
|
|
{
|
2018-11-24 07:04:47 -05:00
|
|
|
gboolean big_updated, small_updated;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
big_updated = check_paint (state, 0, 0, 1);
|
|
|
|
small_updated = check_paint (state, 0, PIXMAP_HEIGHT, 4);
|
|
|
|
|
|
|
|
g_assert (big_updated == small_updated);
|
|
|
|
|
|
|
|
if (state->frame_count < FRAME_COUNT_UPDATED)
|
|
|
|
g_assert (big_updated == FALSE);
|
|
|
|
else if (state->frame_count == FRAME_COUNT_UPDATED)
|
|
|
|
/* Change the pixmap and keep drawing until it updates */
|
|
|
|
update_pixmap (state);
|
|
|
|
else if (big_updated)
|
|
|
|
/* If we successfully got the update then the test is over */
|
|
|
|
clutter_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
state->frame_count++;
|
|
|
|
}
|
|
|
|
|
2018-11-24 07:04:47 -05:00
|
|
|
static gboolean
|
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
|
|
|
queue_redraw (void *stage)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* COGL_HAS_XLIB */
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_texture_pixmap_x11 (TestUtilsGTestFixture *fixture,
|
2011-05-05 18:34:38 -04:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
#ifdef COGL_HAS_XLIB
|
|
|
|
|
|
|
|
TestState state;
|
|
|
|
unsigned int idle_handler;
|
2019-11-15 19:25:52 -05:00
|
|
|
unsigned long paint_handler;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
state.frame_count = 0;
|
|
|
|
state.stage = clutter_stage_get_default ();
|
|
|
|
|
|
|
|
state.display = clutter_x11_get_default_display ();
|
|
|
|
|
|
|
|
state.pixmap = create_pixmap (&state);
|
|
|
|
state.tfp = cogl_texture_pixmap_x11_new (state.pixmap, TRUE);
|
|
|
|
|
2020-06-26 15:43:45 -04:00
|
|
|
clutter_actor_set_background_color (CLUTTER_ACTOR (state.stage), &stage_color);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
paint_handler = g_signal_connect_after (state.stage, "paint",
|
|
|
|
G_CALLBACK (on_paint), &state);
|
|
|
|
|
|
|
|
idle_handler = g_idle_add (queue_redraw, state.stage);
|
|
|
|
|
2020-06-26 14:23:46 -04:00
|
|
|
clutter_actor_show (state.stage);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2019-11-15 19:25:52 -05:00
|
|
|
g_clear_signal_handler (&paint_handler, state.stage);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2019-11-21 18:25:30 -05:00
|
|
|
g_clear_handle_id (&idle_handler, g_source_remove);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
XFreePixmap (state.display, state.pixmap);
|
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("OK\n");
|
|
|
|
|
|
|
|
#else /* COGL_HAS_XLIB */
|
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("Skipping\n");
|
|
|
|
|
|
|
|
#endif /* COGL_HAS_XLIB */
|
|
|
|
}
|
|
|
|
|