From 8c102fcafd78dbba551f8192fb087037a0424902 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 20 Mar 2020 19:12:15 +0800 Subject: [PATCH] remove use of offset fields in GAL_Surface; initialize pixels_off to 0 --- src/newgal/RLEaccel.c | 8 ++++---- src/newgal/blit.c | 4 ++-- src/newgal/surface-cursor.c | 2 +- src/newgal/surface-shared.c | 4 ++-- src/newgal/surface.c | 20 +++++++++++++++++++- src/newgal/video.c | 10 +++++----- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/newgal/RLEaccel.c b/src/newgal/RLEaccel.c index b0047ddc..2388ac96 100644 --- a/src/newgal/RLEaccel.c +++ b/src/newgal/RLEaccel.c @@ -476,7 +476,7 @@ int GAL_RLEBlit(GAL_Surface *src, GAL_Rect *srcrect, /* Set up the source and destination pointers */ x = dstrect->x; y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels + dst->offset + dstbuf = (Uint8 *)dst->pixels + y * dst->pitch + x * src->format->BytesPerPixel; srcbuf = (Uint8 *)src->map->sw_data->aux_data; @@ -730,7 +730,7 @@ int GAL_RLEAlphaBlit(GAL_Surface *src, GAL_Rect *srcrect, x = dstrect->x; y = dstrect->y; - dstbuf = (Uint8 *)dst->pixels + dst->offset + dstbuf = (Uint8 *)dst->pixels + y * dst->pitch + x * df->BytesPerPixel; srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat); @@ -1098,7 +1098,7 @@ static int RLEAlphaSurface(GAL_Surface *surface) int x, y; int h = surface->h, w = surface->w; GAL_PixelFormat *sf = surface->format; - Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels + surface->offset); + Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels); Uint8 *lastline = dst; /* end of last non-blank line */ /* opaque counts are 8 or 16 bits, depending on target depth */ @@ -1283,7 +1283,7 @@ static int RLEColorkeySurface(GAL_Surface *surface) } /* Set up the conversion */ - srcbuf = (Uint8 *)surface->pixels+surface->offset; + srcbuf = (Uint8 *)surface->pixels; maxn = bpp == 4 ? 65535 : 255; dst = rlebuf; rgbmask = ~surface->format->Amask; diff --git a/src/newgal/blit.c b/src/newgal/blit.c index 21df9dd9..0fa315bb 100644 --- a/src/newgal/blit.c +++ b/src/newgal/blit.c @@ -77,13 +77,13 @@ static int GAL_SoftBlit(GAL_Surface *src, GAL_Rect *srcrect, GAL_loblit RunBlit; /* Set up the blit information */ - info.s_pixels = (Uint8 *)src->pixels + src->offset + + info.s_pixels = (Uint8 *)src->pixels + (Uint16)srcrect->y*src->pitch + (Uint16)srcrect->x*src->format->BytesPerPixel; info.s_width = srcrect->w; info.s_height = srcrect->h; info.s_skip=src->pitch-info.s_width*src->format->BytesPerPixel; - info.d_pixels = (Uint8 *)dst->pixels + dst->offset + + info.d_pixels = (Uint8 *)dst->pixels + (Uint16)dstrect->y*dst->pitch + (Uint16)dstrect->x*dst->format->BytesPerPixel; info.d_width = dstrect->w; diff --git a/src/newgal/surface-cursor.c b/src/newgal/surface-cursor.c index c8709e69..075accf3 100644 --- a/src/newgal/surface-cursor.c +++ b/src/newgal/surface-cursor.c @@ -97,7 +97,7 @@ GAL_Surface * GAL_CreateCursorSurface (GAL_VideoDevice *video, surface->h = height; surface->pitch = GAL_CalculatePitch (surface); surface->pixels = NULL; - surface->offset = 0; + surface->pixels_off = 0; // for off-screen surface, DPI always be the default value surface->dpi = GDCAP_DPI_DEFAULT; surface->hwdata = NULL; diff --git a/src/newgal/surface-shared.c b/src/newgal/surface-shared.c index bed2e4f0..f9c81006 100644 --- a/src/newgal/surface-shared.c +++ b/src/newgal/surface-shared.c @@ -130,7 +130,7 @@ GAL_Surface * GAL_CreateSharedRGBSurface (GAL_VideoDevice *video, surface->h = height; surface->pitch = GAL_CalculatePitch (surface); surface->pixels = NULL; - surface->offset = 0; + surface->pixels_off = 0; // for off-screen surface, DPI always be the default value surface->dpi = GDCAP_DPI_DEFAULT; surface->hwdata = NULL; @@ -405,7 +405,7 @@ GAL_Surface * GAL_AttachSharedRGBSurface (int fd, size_t map_size, surface->w = hdr->width; surface->h = hdr->height; surface->pitch = hdr->pitch; - surface->offset = 0; + surface->pixels_off = 0; // for off-screen surface, DPI always be the default value surface->dpi = GDCAP_DPI_DEFAULT; surface->map = NULL; diff --git a/src/newgal/surface.c b/src/newgal/surface.c index 17d99e84..ebe1a35c 100644 --- a/src/newgal/surface.c +++ b/src/newgal/surface.c @@ -57,6 +57,10 @@ #include "memops.h" #include "leaks.h" +#ifdef _MGRM_PROCESSES +#include /* for munmap */ +#endif /* _MGRM_PROCESSES */ + /* Public routines */ /* * Create an empty RGB surface of the appropriate depth @@ -132,7 +136,7 @@ GAL_Surface * GAL_CreateRGBSurface (Uint32 flags, surface->h = height; surface->pitch = GAL_CalculatePitch(surface); surface->pixels = NULL; - surface->offset = 0; + surface->pixels_off = 0; // for off-screen surface, DPI always be the default value surface->dpi = GDCAP_DPI_DEFAULT; surface->hwdata = NULL; @@ -1748,6 +1752,20 @@ void GAL_FreeSurface (GAL_Surface *surface) assert (video->FreeHWSurface); video->FreeHWSurface (video, surface); } +#ifdef _MGRM_PROCESSES + else if ((surface->flags & GAL_HWSURFACE) == GAL_SWSURFACE && + (surface->flags & GAL_PREALLOC) == GAL_PREALLOC && + surface->hwdata) { + // This is a surface created in / attached to a named shared memory. + + size_t map_size; + uint8_t* buff; + + map_size = (size_t)surface->hwdata; + buff = surface->pixels - surface->pixels_off; + munmap (buff, map_size); + } +#endif /* _MGRM_PROCESSES */ else if (surface->pixels && ((surface->flags & GAL_PREALLOC) != GAL_PREALLOC)) { free (surface->pixels); diff --git a/src/newgal/video.c b/src/newgal/video.c index a671dbab..61b93900 100644 --- a/src/newgal/video.c +++ b/src/newgal/video.c @@ -586,7 +586,7 @@ GAL_Surface * GAL_SetVideoMode (int width, int height, int bpp, Uint32 flags) /* Clear the surface to black */ video->offset_x = 0; video->offset_y = 0; - mode->offset = 0; + mode->pixels_off = 0; #ifdef _MGRM_PROCESSES if (mgIsServer) { #endif @@ -601,7 +601,7 @@ GAL_Surface * GAL_SetVideoMode (int width, int height, int bpp, Uint32 flags) "NEWGAL: Requested mode: %dx%dx%d, obtained mode %dx%dx%d " "(offset %d)\n", width, height, bpp, - mode->w, mode->h, mode->format->BitsPerPixel, mode->offset); + mode->w, mode->h, mode->format->BitsPerPixel, mode->pixels_off); #endif mode->w = width; mode->h = height; @@ -634,7 +634,7 @@ void GAL_SetVideoModeInfo(GAL_Surface* screen) __mg_current_video->offset_y = 0; __gal_screen->video = __mg_current_video; - __gal_screen->offset = 0; + __gal_screen->pixels_off = 0; GAL_SetClipRect(screen, NULL); } #endif /* _MGSCHEMA_COMPOSITING */ @@ -1245,7 +1245,7 @@ static GAL_Surface *Slave_CreateSurface (GAL_VideoDevice *this, surface->h = 0; surface->pitch = GAL_CalculatePitch(surface); surface->pixels = NULL; - surface->offset = 0; + surface->pixels_off = 0; surface->hwdata = NULL; surface->map = NULL; surface->format_version = 0; @@ -1437,7 +1437,7 @@ static GAL_Surface * Slave_SetVideoMode (GAL_VideoDevice *device, /* Clear the surface to black */ video->offset_x = 0; video->offset_y = 0; - surface->offset = 0; + surface->pixels_off = 0; surface->w = width; surface->h = height;