@ -103,7 +103,7 @@ move_client(struct client *client, int x, int y)
/* The attach here is necessary because commit() will call configure
/* The attach here is necessary because commit() will call configure
* only on surfaces newly attached , and the one that sets the surface
* only on surfaces newly attached , and the one that sets the surface
* position is the configure . */
* position is the configure . */
wl_surface_attach ( surface - > wl_surface , surface - > wl_ buffer, 0 , 0 ) ;
wl_surface_attach ( surface - > wl_surface , surface - > buffer - > proxy , 0 , 0 ) ;
wl_surface_damage ( surface - > wl_surface , 0 , 0 , surface - > width ,
wl_surface_damage ( surface - > wl_surface , 0 , 0 , surface - > width ,
surface - > height ) ;
surface - > height ) ;
@ -447,6 +447,41 @@ create_shm_buffer(struct client *client, int width, int height, void **pixels)
return buffer ;
return buffer ;
}
}
struct buffer *
create_shm_buffer_a8r8g8b8 ( struct client * client , int width , int height )
{
struct buffer * buf ;
void * pixels ;
buf = xzalloc ( sizeof * buf ) ;
buf - > proxy = create_shm_buffer ( client , width , height , & pixels ) ;
buf - > image = pixman_image_create_bits ( PIXMAN_a8r8g8b8 , width , height ,
pixels , width * 4 ) ;
buf - > len = width * height * 4 ;
assert ( buf - > proxy ) ;
assert ( buf - > image ) ;
return buf ;
}
void
buffer_destroy ( struct buffer * buf )
{
void * pixels ;
pixels = pixman_image_get_data ( buf - > image ) ;
if ( buf - > proxy ) {
wl_buffer_destroy ( buf - > proxy ) ;
assert ( munmap ( pixels , buf - > len ) = = 0 ) ;
}
assert ( pixman_image_unref ( buf - > image ) ) ;
free ( buf ) ;
}
static void
static void
shm_format ( void * data , struct wl_shm * wl_shm , uint32_t format )
shm_format ( void * data , struct wl_shm * wl_shm , uint32_t format )
{
{
@ -845,6 +880,8 @@ create_client_and_test_surface(int x, int y, int width, int height)
{
{
struct client * client ;
struct client * client ;
struct surface * surface ;
struct surface * surface ;
pixman_color_t color = { 16384 , 16384 , 16384 , 16384 } ; /* uint16_t */
pixman_image_t * solid ;
client = create_client ( ) ;
client = create_client ( ) ;
@ -862,10 +899,18 @@ create_client_and_test_surface(int x, int y, int width, int height)
surface - > width = width ;
surface - > width = width ;
surface - > height = height ;
surface - > height = height ;
surface - > wl_buffer = create_shm_buffer ( client , width , height ,
surface - > buffer = create_shm_buffer_a8r8g8b8 ( client , width , height ) ;
& surface - > data ) ;
solid = pixman_image_create_solid_fill ( & color ) ;
memset ( surface - > data , 64 , width * height * 4 ) ;
pixman_image_composite32 ( PIXMAN_OP_SRC ,
solid , /* src */
NULL , /* mask */
surface - > buffer - > image , /* dst */
0 , 0 , /* src x,y */
0 , 0 , /* mask x,y */
0 , 0 , /* dst x,y */
width , height ) ;
pixman_image_unref ( solid ) ;
move_client ( client , x , y ) ;
move_client ( client , x , y ) ;
@ -927,7 +972,7 @@ check_surfaces_geometry(const struct surface *a, const struct surface *b)
printf ( " Undefined surfaces \n " ) ;
printf ( " Undefined surfaces \n " ) ;
return false ;
return false ;
}
}
else if ( a - > data = = NULL | | b - > data = = NULL ) {
else if ( a - > buffer = = NULL | | b - > buffer = = NULL ) {
printf ( " Undefined data \n " ) ;
printf ( " Undefined data \n " ) ;
return false ;
return false ;
}
}
@ -950,11 +995,16 @@ bool
check_surfaces_equal ( const struct surface * a , const struct surface * b )
check_surfaces_equal ( const struct surface * a , const struct surface * b )
{
{
int bpp = 4 ; /* Assumes ARGB */
int bpp = 4 ; /* Assumes ARGB */
void * data_a ;
void * data_b ;
if ( ! check_surfaces_geometry ( a , b ) )
if ( ! check_surfaces_geometry ( a , b ) )
return false ;
return false ;
return ( memcmp ( a - > data , b - > data , bpp * a - > width * a - > height ) = = 0 ) ;
data_a = pixman_image_get_data ( a - > buffer - > image ) ;
data_b = pixman_image_get_data ( b - > buffer - > image ) ;
return ( memcmp ( data_a , data_b , bpp * a - > width * a - > height ) = = 0 ) ;
}
}
/**
/**
@ -972,6 +1022,8 @@ check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, c
int x0 , y0 , x1 , y1 ;
int x0 , y0 , x1 , y1 ;
void * p , * q ;
void * p , * q ;
int bpp = 4 ; /* Assumes ARGB */
int bpp = 4 ; /* Assumes ARGB */
void * data_a ;
void * data_b ;
if ( ! check_surfaces_geometry ( a , b ) | | clip_rect = = NULL )
if ( ! check_surfaces_geometry ( a , b ) | | clip_rect = = NULL )
return false ;
return false ;
@ -991,10 +1043,13 @@ check_surfaces_match_in_clip(const struct surface *a, const struct surface *b, c
return true ;
return true ;
}
}
data_a = pixman_image_get_data ( a - > buffer - > image ) ;
data_b = pixman_image_get_data ( b - > buffer - > image ) ;
printf ( " Bytewise comparison inside clip \n " ) ;
printf ( " Bytewise comparison inside clip \n " ) ;
for ( i = y0 ; i < y1 ; i + + ) {
for ( i = y0 ; i < y1 ; i + + ) {
p = a - > data + i * a - > width * bpp + x0 * bpp ;
p = data_ a + i * a - > width * bpp + x0 * bpp ;
q = b - > data + i * b - > width * bpp + x0 * bpp ;
q = data_b + i * b - > width * bpp + x0 * bpp ;
if ( memcmp ( p , q , ( x1 - x0 ) * bpp ) ! = 0 ) {
if ( memcmp ( p , q , ( x1 - x0 ) * bpp ) ! = 0 ) {
/* Dump the bad row */
/* Dump the bad row */
printf ( " Mismatched image on row %d \n " , i ) ;
printf ( " Mismatched image on row %d \n " , i ) ;
@ -1025,8 +1080,10 @@ write_surface_as_png(const struct surface *weston_surface, const char *fname)
cairo_status_t status ;
cairo_status_t status ;
int bpp = 4 ; /* Assume ARGB */
int bpp = 4 ; /* Assume ARGB */
int stride = bpp * weston_surface - > width ;
int stride = bpp * weston_surface - > width ;
void * pixels ;
cairo_surface = cairo_image_surface_create_for_data ( weston_surface - > data ,
pixels = pixman_image_get_data ( weston_surface - > buffer - > image ) ;
cairo_surface = cairo_image_surface_create_for_data ( pixels ,
CAIRO_FORMAT_ARGB32 ,
CAIRO_FORMAT_ARGB32 ,
weston_surface - > width ,
weston_surface - > width ,
weston_surface - > height ,
weston_surface - > height ,
@ -1091,14 +1148,15 @@ load_surface_from_png(const char *fname)
/* Allocate new buffer for our weston reference, and copy the data from
/* Allocate new buffer for our weston reference, and copy the data from
the cairo surface so we can destroy it */
the cairo surface so we can destroy it */
reference - > data = zalloc ( source_data_size ) ;
if ( reference - > data = = NULL ) {
reference - > buffer = xzalloc ( sizeof * reference - > buffer ) ;
perror ( " zalloc reference data " ) ;
reference - > buffer - > image = pixman_image_create_bits ( PIXMAN_a8r8g8b8 ,
cairo_surface_destroy ( reference_cairo_surface ) ;
reference - > width ,
free ( reference ) ;
reference - > height ,
return NULL ;
NULL , 0 ) ;
}
assert ( reference - > buffer - > image ) ;
memcpy ( reference - > data ,
memcpy ( pixman_image_get_data ( reference - > buffer - > image ) ,
cairo_image_surface_get_data ( reference_cairo_surface ) ,
cairo_image_surface_get_data ( reference_cairo_surface ) ,
source_data_size ) ;
source_data_size ) ;
@ -1123,10 +1181,10 @@ create_screenshot_surface(struct client *client)
screenshot = zalloc ( sizeof * screenshot ) ;
screenshot = zalloc ( sizeof * screenshot ) ;
if ( screenshot = = NULL )
if ( screenshot = = NULL )
return NULL ;
return NULL ;
screenshot - > wl_buffer = create_shm_buffer ( client ,
client - > output - > width ,
screenshot - > buffer = create_shm_buffer_a8r8g8b8 ( client ,
client - > output - > height ,
client - > output - > width ,
& screenshot - > data ) ;
client - > output - > height ) ;
screenshot - > height = client - > output - > height ;
screenshot - > height = client - > output - > height ;
screenshot - > width = client - > output - > width ;
screenshot - > width = client - > output - > width ;
@ -1153,7 +1211,7 @@ capture_screenshot_of_output(struct client *client)
client - > test - > buffer_copy_done = 0 ;
client - > test - > buffer_copy_done = 0 ;
weston_test_capture_screenshot ( client - > test - > weston_test ,
weston_test_capture_screenshot ( client - > test - > weston_test ,
client - > output - > wl_output ,
client - > output - > wl_output ,
screenshot - > wl_ buffer) ;
screenshot - > buffer - > proxy ) ;
while ( client - > test - > buffer_copy_done = = 0 )
while ( client - > test - > buffer_copy_done = = 0 )
if ( wl_display_dispatch ( client - > wl_display ) < 0 )
if ( wl_display_dispatch ( client - > wl_display ) < 0 )
break ;
break ;