remove use of offset fields in GAL_Surface; initialize pixels_off to 0

This commit is contained in:
Vincent Wei
2020-03-20 19:12:15 +08:00
parent e8150805ff
commit 8c102fcafd
6 changed files with 33 additions and 15 deletions
+4 -4
View File
@@ -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;
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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;
+19 -1
View File
@@ -57,6 +57,10 @@
#include "memops.h"
#include "leaks.h"
#ifdef _MGRM_PROCESSES
#include <sys/mman.h> /* 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);
+5 -5
View File
@@ -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;