diff options
-rw-r--r-- | backends/platform/sdl/graphics.cpp | 4 | ||||
-rw-r--r-- | common/util.h | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index b4bf48d808..bf4a1e7794 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -793,7 +793,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert(h > 0 && y + h <= _videoMode.screenHeight); assert(w > 0 && x + w <= _videoMode.screenWidth); - if (((long)src & 3) == 0 && pitch == _videoMode.screenWidth && x == 0 && y == 0 && + if (IS_ALIGNED(src, 4) && pitch == _videoMode.screenWidth && x == 0 && y == 0 && w == _videoMode.screenWidth && h == _videoMode.screenHeight && _modeFlags & DF_WANT_RECT_OPTIM) { /* Special, optimized case for full screen updates. * It tries to determine what areas were actually changed, @@ -997,7 +997,7 @@ void OSystem_SDL::makeChecksums(const byte *buf) { void OSystem_SDL::addDirtyRgnAuto(const byte *buf) { assert(buf); - assert(((long)buf & 3) == 0); + assert(IS_ALIGNED(buf, 4)); /* generate a table of the checksums */ makeChecksums(buf); diff --git a/common/util.h b/common/util.h index 18f1b70c52..3b2a705d6c 100644 --- a/common/util.h +++ b/common/util.h @@ -28,6 +28,15 @@ #include "common/scummsys.h" #include "common/str.h" + +/** + * Check whether a given pointer is aligned correctly. + * Note that 'alignment' must be a power of two! + */ +#define IS_ALIGNED(value, alignment) \ + ((((size_t)value) & ((alignment) - 1)) == 0) + + #ifdef MIN #undef MIN #endif @@ -47,6 +56,9 @@ template<typename T> inline T CLIP (T v, T amin, T amax) */ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } +/** + * Macro which determines the number of entries in a fixed size array. + */ #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) |