win32u: Move the window surface color bits to the common struct.

This commit is contained in:
Rémi Bernon 2024-05-29 23:54:17 +02:00 committed by Alexandre Julliard
parent cd780fe609
commit 3c7dc5f132
6 changed files with 49 additions and 54 deletions

View file

@ -113,7 +113,6 @@ struct window_surface dummy_surface =
struct offscreen_window_surface
{
struct window_surface header;
char *bits;
BITMAPINFO info;
};
@ -129,7 +128,7 @@ static void *offscreen_window_surface_get_bitmap_info( struct window_surface *ba
{
struct offscreen_window_surface *impl = impl_from_window_surface( base );
info->bmiHeader = impl->info.bmiHeader;
return impl->bits;
return base->color_bits;
}
static void offscreen_window_surface_set_clip( struct window_surface *base, const RECT *rects, UINT count )
@ -182,7 +181,7 @@ void create_offscreen_window_surface( HWND hwnd, const RECT *visible_rect, struc
if (!(impl = calloc(1, offsetof( struct offscreen_window_surface, info.bmiColors[0] ) + size))) return;
window_surface_init( &impl->header, &offscreen_window_surface_funcs, hwnd, &surface_rect );
impl->bits = (char *)&impl->info.bmiColors[0];
impl->header.color_bits = (char *)&impl->info.bmiColors[0];
impl->info.bmiHeader.biSize = sizeof( impl->info );
impl->info.bmiHeader.biWidth = surface_rect.right;
impl->info.bmiHeader.biHeight = surface_rect.bottom;

View file

@ -575,7 +575,6 @@ struct android_window_surface
RECT *clip_rects;
BYTE alpha;
COLORREF color_key;
void *bits;
BITMAPINFO info; /* variable size, must be last */
};
@ -643,7 +642,7 @@ static void *android_surface_get_bitmap_info( struct window_surface *window_surf
struct android_window_surface *surface = get_android_surface( window_surface );
memcpy( info, &surface->info, get_dib_info_size( &surface->info, DIB_RGB_COLORS ));
return surface->bits;
return window_surface->color_bits;
}
/***********************************************************************
@ -688,7 +687,7 @@ static BOOL android_surface_flush( struct window_surface *window_surface, const
locked.bottom = rc.bottom;
intersect_rect( &locked, &locked, rect );
src = (DWORD *)surface->bits + (locked.top - rect->top) * surface->info.bmiHeader.biWidth +
src = (DWORD *)window_surface->color_bits + (locked.top - rect->top) * surface->info.bmiHeader.biWidth +
(locked.left - rect->left);
dst = (DWORD *)buffer.bits + locked.top * buffer.stride + locked.left;
width = min( locked.right - locked.left, buffer.stride );
@ -733,11 +732,11 @@ static void android_surface_destroy( struct window_surface *window_surface )
{
struct android_window_surface *surface = get_android_surface( window_surface );
TRACE( "freeing %p bits %p\n", surface, surface->bits );
TRACE( "freeing %p bits %p\n", surface, window_surface->color_bits );
free( surface->clip_rects );
release_ioctl_window( surface->window );
free( surface->bits );
free( window_surface->color_bits );
free( surface );
}
@ -797,11 +796,11 @@ static struct window_surface *create_surface( HWND hwnd, const RECT *rect,
surface->alpha = alpha;
set_color_key( surface, color_key );
if (!(surface->bits = malloc( surface->info.bmiHeader.biSizeImage )))
if (!(surface->header.color_bits = malloc( surface->info.bmiHeader.biSizeImage )))
goto failed;
TRACE( "created %p hwnd %p %s bits %p-%p\n", surface, hwnd, wine_dbgstr_rect(rect),
surface->bits, (char *)surface->bits + surface->info.bmiHeader.biSizeImage );
TRACE( "created %p hwnd %p %s color_bits %p-%p\n", surface, hwnd, wine_dbgstr_rect(rect),
surface->header.color_bits, (char *)surface->header.color_bits + surface->info.bmiHeader.biSizeImage );
return &surface->header;

View file

@ -65,7 +65,6 @@ struct macdrv_window_surface
struct window_surface header;
macdrv_window window;
BOOL use_alpha;
BYTE *bits;
BITMAPINFO info; /* variable size, must be last */
};
@ -80,7 +79,7 @@ static void *macdrv_surface_get_bitmap_info(struct window_surface *window_surfac
struct macdrv_window_surface *surface = get_mac_surface(window_surface);
memcpy(info, &surface->info, get_dib_info_size(&surface->info, DIB_RGB_COLORS));
return surface->bits;
return window_surface->color_bits;
}
/***********************************************************************
@ -107,8 +106,8 @@ static void macdrv_surface_destroy(struct window_surface *window_surface)
{
struct macdrv_window_surface *surface = get_mac_surface(window_surface);
TRACE("freeing %p bits %p\n", surface, surface->bits);
free(surface->bits);
TRACE("freeing %p bits %p\n", surface, window_surface->color_bits);
free(window_surface->color_bits);
free(surface);
}
@ -158,13 +157,13 @@ struct window_surface *create_surface(HWND hwnd, macdrv_window window, const REC
surface->window = window;
if (old_surface) surface->header.bounds = old_surface->bounds;
surface->use_alpha = use_alpha;
surface->bits = malloc(surface->info.bmiHeader.biSizeImage);
if (!surface->bits) goto failed;
surface->header.color_bits = malloc(surface->info.bmiHeader.biSizeImage);
if (!surface->header.color_bits) goto failed;
window_background = macdrv_window_background_color();
memset_pattern4(surface->bits, &window_background, surface->info.bmiHeader.biSizeImage);
memset_pattern4(surface->header.color_bits, &window_background, surface->info.bmiHeader.biSizeImage);
TRACE("created %p for %p %s bits %p-%p\n", surface, window, wine_dbgstr_rect(rect),
surface->bits, surface->bits + surface->info.bmiHeader.biSizeImage);
TRACE("created %p for %p %s color_bits %p-%p\n", surface, window, wine_dbgstr_rect(rect),
surface->header.color_bits, (char *)surface->header.color_bits + surface->info.bmiHeader.biSizeImage);
return &surface->header;
@ -229,12 +228,12 @@ CGImageRef macdrv_get_surface_display_image(struct window_surface *window_surfac
if (copy_data)
{
CFDataRef data = CFDataCreate(NULL, (UInt8*)surface->bits + offset, size);
CFDataRef data = CFDataCreate(NULL, (UInt8 *)window_surface->color_bits + offset, size);
provider = CGDataProviderCreateWithCFData(data);
CFRelease(data);
}
else
provider = CGDataProviderCreateWithData(NULL, surface->bits + offset, size, NULL);
provider = CGDataProviderCreateWithData(NULL, (UInt8 *)window_surface->color_bits + offset, size, NULL);
alphaInfo = surface->use_alpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
cgimage = CGImageCreate(CGRectGetWidth(visrect), CGRectGetHeight(visrect),

View file

@ -45,7 +45,6 @@ struct wayland_window_surface
struct window_surface header;
struct wayland_surface *wayland_surface;
struct wayland_buffer_queue *wayland_buffer_queue;
void *bits;
BITMAPINFO info;
};
@ -220,7 +219,7 @@ static void *wayland_window_surface_get_bitmap_info(struct window_surface *windo
/* We don't store any additional information at the end of our BITMAPINFO, so
* just copy the structure itself. */
memcpy(info, &surface->info, sizeof(*info));
return surface->bits;
return window_surface->color_bits;
}
/***********************************************************************
@ -308,17 +307,15 @@ static void copy_pixel_region(char *src_pixels, RECT *src_rect,
}
/**********************************************************************
* wayland_window_surface_copy_to_buffer
* wayland_shm_buffer_copy_data
*/
static void wayland_window_surface_copy_to_buffer(struct wayland_window_surface *wws,
struct wayland_shm_buffer *buffer,
HRGN region)
static void wayland_shm_buffer_copy_data(struct wayland_shm_buffer *buffer,
char *bits, RECT *rect,
HRGN region)
{
RECT wws_rect = {0, 0, wws->info.bmiHeader.biWidth,
abs(wws->info.bmiHeader.biHeight)};
RECT buffer_rect = {0, 0, buffer->width, buffer->height};
TRACE("wws=%p buffer=%p\n", wws, buffer);
copy_pixel_region(wws->bits, &wws_rect, buffer->map_data, &buffer_rect, region);
TRACE("buffer=%p bits=%p rect=%s\n", buffer, bits, wine_dbgstr_rect(rect));
copy_pixel_region(bits, rect, buffer->map_data, &buffer_rect, region);
}
static void wayland_shm_buffer_copy(struct wayland_shm_buffer *src,
@ -396,7 +393,8 @@ static BOOL wayland_window_surface_flush(struct window_surface *window_surface,
copy_from_window_region = shm_buffer->damage_region;
}
wayland_window_surface_copy_to_buffer(wws, shm_buffer, copy_from_window_region);
wayland_shm_buffer_copy_data(shm_buffer, window_surface->color_bits,
&window_surface->rect, copy_from_window_region);
pthread_mutex_lock(&wws->wayland_surface->mutex);
if (wayland_surface_reconfigure(wws->wayland_surface))
@ -437,7 +435,7 @@ static void wayland_window_surface_destroy(struct window_surface *window_surface
if (wws->wayland_buffer_queue)
wayland_buffer_queue_destroy(wws->wayland_buffer_queue);
free(wws->bits);
free(window_surface->color_bits);
free(wws);
}
@ -473,11 +471,11 @@ struct window_surface *wayland_window_surface_create(HWND hwnd, const RECT *rect
wws->info.bmiHeader.biPlanes = 1;
wws->info.bmiHeader.biSizeImage = width * height * 4;
if (!(wws->bits = malloc(wws->info.bmiHeader.biSizeImage)))
if (!(wws->header.color_bits = malloc(wws->info.bmiHeader.biSizeImage)))
goto failed;
TRACE("created %p hwnd %p %s bits [%p,%p)\n", wws, hwnd, wine_dbgstr_rect(rect),
wws->bits, (char *)wws->bits + wws->info.bmiHeader.biSizeImage);
TRACE("created %p hwnd %p %s color_bits [%p,%p)\n", wws, hwnd, wine_dbgstr_rect(rect),
wws->header.color_bits, (char *)wws->header.color_bits + wws->info.bmiHeader.biSizeImage);
return &wws->header;

View file

@ -1581,7 +1581,6 @@ struct x11drv_window_surface
BOOL is_argb;
DWORD alpha_bits;
COLORREF color_key;
void *bits;
#ifdef HAVE_LIBXXSHM
XShmSegmentInfo shminfo;
#endif
@ -1627,7 +1626,7 @@ static inline void add_row( HRGN rgn, RGNDATA *data, int x, int y, int len )
/***********************************************************************
* update_surface_region
*/
static void update_surface_region( struct x11drv_window_surface *surface )
static void update_surface_region( struct x11drv_window_surface *surface, const void *color_bits )
{
#ifdef HAVE_LIBXSHAPE
char buffer[4096];
@ -1657,7 +1656,7 @@ static void update_surface_region( struct x11drv_window_surface *surface )
{
case 16:
{
WORD *bits = surface->bits;
const WORD *bits = color_bits;
int stride = (width + 1) & ~1;
UINT mask = masks[0] | masks[1] | masks[2];
@ -1676,7 +1675,7 @@ static void update_surface_region( struct x11drv_window_surface *surface )
}
case 24:
{
BYTE *bits = surface->bits;
const BYTE *bits = color_bits;
int stride = (width * 3 + 3) & ~3;
for (y = surface->header.rect.top; y < surface->header.rect.bottom; y++, bits += stride)
@ -1702,7 +1701,7 @@ static void update_surface_region( struct x11drv_window_surface *surface )
}
case 32:
{
DWORD *bits = surface->bits;
const DWORD *bits = color_bits;
if (info->bmiHeader.biCompression == BI_RGB)
{
@ -1833,7 +1832,7 @@ static void *x11drv_surface_get_bitmap_info( struct window_surface *window_surfa
struct x11drv_window_surface *surface = get_x11_surface( window_surface );
memcpy( info, &surface->info, get_dib_info_size( &surface->info, DIB_RGB_COLORS ));
return surface->bits;
return window_surface->color_bits;
}
static XRectangle *xrectangles_from_rects( const RECT *rects, UINT count )
@ -1879,10 +1878,10 @@ static void x11drv_surface_set_clip( struct window_surface *window_surface, cons
static BOOL x11drv_surface_flush( struct window_surface *window_surface, const RECT *rect, const RECT *dirty )
{
struct x11drv_window_surface *surface = get_x11_surface( window_surface );
unsigned char *src = surface->bits;
unsigned char *src = window_surface->color_bits;
unsigned char *dst = (unsigned char *)surface->image->data;
if (surface->is_argb || surface->color_key != CLR_INVALID) update_surface_region( surface );
if (surface->is_argb || surface->color_key != CLR_INVALID) update_surface_region( surface, window_surface->color_bits );
if (src != dst)
{
@ -1926,11 +1925,11 @@ static void x11drv_surface_destroy( struct window_surface *window_surface )
{
struct x11drv_window_surface *surface = get_x11_surface( window_surface );
TRACE( "freeing %p bits %p\n", surface, surface->bits );
TRACE( "freeing %p bits %p\n", surface, window_surface->color_bits );
if (surface->gc) XFreeGC( gdi_display, surface->gc );
if (surface->image)
{
if (surface->image->data != surface->bits) free( surface->bits );
if (surface->image->data != window_surface->color_bits) free( window_surface->color_bits );
#ifdef HAVE_LIBXXSHM
if (surface->shminfo.shmid != -1)
{
@ -2004,13 +2003,13 @@ struct window_surface *create_surface( HWND hwnd, Window window, const XVisualIn
if (surface->byteswap || format->bits_per_pixel == 4 || format->bits_per_pixel == 8)
{
/* allocate separate surface bits if byte swapping or palette mapping is required */
if (!(surface->bits = calloc( 1, surface->info.bmiHeader.biSizeImage )))
if (!(surface->header.color_bits = calloc( 1, surface->info.bmiHeader.biSizeImage )))
goto failed;
}
else surface->bits = surface->image->data;
else surface->header.color_bits = surface->image->data;
TRACE( "created %p for %lx %s bits %p-%p image %p\n", surface, window, wine_dbgstr_rect(rect),
surface->bits, (char *)surface->bits + surface->info.bmiHeader.biSizeImage,
TRACE( "created %p for %lx %s color_bits %p-%p image %p\n", surface, window, wine_dbgstr_rect(rect),
surface->header.color_bits, (char *)surface->header.color_bits + surface->info.bmiHeader.biSizeImage,
surface->image->data );
return &surface->header;
@ -2033,7 +2032,7 @@ void set_surface_color_key( struct window_surface *window_surface, COLORREF colo
window_surface_lock( window_surface );
prev = surface->color_key;
set_color_key( surface, color_key );
if (surface->color_key != prev) update_surface_region( surface );
if (surface->color_key != prev) update_surface_region( surface, window_surface->color_bits );
window_surface_unlock( window_surface );
}

View file

@ -225,10 +225,11 @@ struct window_surface
HWND hwnd; /* window the surface was created for */
RECT rect; /* constant, no locking needed */
pthread_mutex_t mutex;
RECT bounds; /* dirty area rect, requires locking */
pthread_mutex_t mutex; /* mutex needed for any field below */
RECT bounds; /* dirty area rectangle */
HRGN clip_region; /* visible region of the surface, fully visible if 0 */
DWORD draw_start_ticks; /* start ticks of fresh draw */
void *color_bits; /* pixel bits of the surface color */
/* driver-specific fields here */
};