diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 8a41a5cd32..3c79e3b152 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -212,12 +212,10 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel case BM_BLACK_REMAP: - do { - *dst++ = Colour(0, 0, 0); - *anim++ = 0; - src_px++; - src_n++; - } while (--n != 0); + memset_colour(dst, _black_colour, n); + memset(anim, 0, n * sizeof(*anim)); + src_px += n; + src_n += n; break; case BM_TRANSPARENT: diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 602777fb4a..01c15b9604 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -11,6 +11,7 @@ #include "../zoom_func.h" #include "../settings_type.h" #include "32bpp_optimized.hpp" +#include "common.hpp" #include "../safeguards.h" @@ -181,12 +182,9 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL break; case BM_BLACK_REMAP: - do { - *dst = Colour(0, 0, 0); - dst++; - src_px++; - src_n++; - } while (--n != 0); + memset_colour(dst, _black_colour, n); + src_px += n; + src_n += n; break; case BM_TRANSPARENT: diff --git a/src/blitter/40bpp_anim.cpp b/src/blitter/40bpp_anim.cpp index db8e56d7c1..7fd2b70982 100644 --- a/src/blitter/40bpp_anim.cpp +++ b/src/blitter/40bpp_anim.cpp @@ -22,9 +22,6 @@ /** Instantiation of the 40bpp with animation blitter factory. */ static FBlitter_40bppAnim iFBlitter_40bppAnim; -/** Cached black value. */ -static const Colour _black_colour(0, 0, 0); - void Blitter_40bppAnim::SetPixel(void *video, int x, int y, uint8 colour) { @@ -58,7 +55,7 @@ void Blitter_40bppAnim::SetRect(void *video, int x, int y, const uint8 *colours, Colour *dst = (Colour *)video + x + y * _screen.pitch; uint8 *dstanim = ((uint32 *)dst - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer(); do { - memset((uint32 *)dst, _black_colour.data, width * sizeof(uint32)); + memset_colour(dst, _black_colour, width); memcpy(dstanim, colours, width * sizeof(uint8)); dst += _screen.pitch; dstanim += _screen.pitch; @@ -96,15 +93,9 @@ void Blitter_40bppAnim::DrawRect(void *video, int width, int height, uint8 colou uint8 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + VideoDriver::GetInstance()->GetAnimBuffer(); do { - Colour *dst = (Colour *)video; - uint8 *anim = anim_line; + memset_colour((Colour *)video, _black_colour, width); + memset(anim_line, colour, width); - for (int i = width; i > 0; i--) { - *dst = _black_colour; - *anim = colour; - dst++; - anim++; - } video = (uint32 *)video + _screen.pitch; anim_line += _screen.pitch; } while (--height); diff --git a/src/blitter/common.hpp b/src/blitter/common.hpp index cd3b6276a4..df002081f3 100644 --- a/src/blitter/common.hpp +++ b/src/blitter/common.hpp @@ -14,6 +14,14 @@ #include "../core/math_func.hpp" #include +#include + +#ifdef __APPLE__ +#include +#endif + +/** Cached black value. */ +static const Colour _black_colour(0, 0, 0); template void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width, int screen_height, int width, int dash, SetPixelT set_pixel) @@ -192,4 +200,25 @@ void Blitter::DrawLineGeneric(int x1, int y1, int x2, int y2, int screen_width, } } +inline void memset_uint32(uint32 *s, uint32 c, size_t n) +{ +#ifdef __APPLE__ + memset_pattern4(static_cast(s), static_cast(&c), n * sizeof(uint32)); +#else + if constexpr (sizeof(wchar_t) == sizeof(uint32)) { + wmemset((wchar_t *)s, (wchar_t)c, n); + } else { + for (; n > 0; n--) { + *s = c; + s++; + } + } +#endif +} + +inline void memset_colour(Colour *s, Colour c, size_t n) +{ + memset_uint32((uint32 *)s, c.data, n); +} + #endif /* BLITTER_COMMON_HPP */