From 17257b9620a78dc115fadbcfa9a891e5392f09ab Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 23 May 2018 09:55:04 +0100 Subject: Add: 32bpp SSE2 blitter palette animator (#6795) Create a new blitter mode: 32bpp-sse2-anim, which is 32bpp-anim + this. 32bpp-sse2-anim is now used by default where 32bpp-anim would have been. Also use this with the 32bpp-sse4-anim blitter. See issue #6469. --- src/blitter/32bpp_anim.cpp | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/blitter/32bpp_anim.cpp') diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 532ad23cc..578d85f18 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -22,7 +22,7 @@ static FBlitter_32bppAnim iFBlitter_32bppAnim; Blitter_32bppAnim::~Blitter_32bppAnim() { - free(this->anim_buf); + free(this->anim_alloc); } template @@ -39,8 +39,7 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel } Colour *dst = (Colour *)bp->dst + bp->top * bp->pitch + bp->left; - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'bp->dst' into an 'anim_buf' offset below. - uint16 *anim = this->anim_buf + ((uint32 *)bp->dst - (uint32 *)_screen.dst_ptr) + bp->top * this->anim_buf_pitch + bp->left; + uint16 *anim = this->anim_buf + this->ScreenToAnimOffset((uint32 *)bp->dst) + bp->top * this->anim_buf_pitch + bp->left; const byte *remap = bp->remap; // store so we don't have to access it via bp everytime @@ -280,8 +279,7 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height, } Colour *udst = (Colour *)dst; - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'dst' into an 'anim_buf' offset below. - uint16 *anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr); + uint16 *anim = this->anim_buf + this->ScreenToAnimOffset((uint32 *)dst); if (pal == PALETTE_TO_TRANSPARENT) { do { @@ -319,8 +317,8 @@ void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 colour) /* Set the colour in the anim-buffer too, if we are rendering to the screen */ if (_screen_disable_anim) return; - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'video' into an 'anim_buf' offset below. - this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8); + + this->anim_buf[this->ScreenToAnimOffset((uint32 *)video) + x + y * this->anim_buf_pitch] = colour | (DEFAULT_BRIGHTNESS << 8); } void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colour) @@ -332,8 +330,7 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colou } Colour colour32 = LookupColourInPalette(colour); - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'video' into an 'anim_buf' offset below. - uint16 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; + uint16 *anim_line = this->ScreenToAnimOffset((uint32 *)video) + this->anim_buf; do { Colour *dst = (Colour *)video; @@ -357,8 +354,7 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch); Colour *dst = (Colour *)video; const uint32 *usrc = (const uint32 *)src; - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'video' into an 'anim_buf' offset below. - uint16 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; + uint16 *anim_line = this->ScreenToAnimOffset((uint32 *)video) + this->anim_buf; for (; height > 0; height--) { /* We need to keep those for palette animation. */ @@ -401,8 +397,7 @@ void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, in if (this->anim_buf == NULL) return; - assert(_screen.pitch == this->anim_buf_pitch); // precondition for translating 'video' into an 'anim_buf' offset below. - const uint16 *anim_line = ((const uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; + const uint16 *anim_line = this->ScreenToAnimOffset((const uint32 *)video) + this->anim_buf; for (; height > 0; height--) { memcpy(udst, src, width * sizeof(uint32)); @@ -485,18 +480,22 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette) Colour *dst = (Colour *)_screen.dst_ptr; /* Let's walk the anim buffer and try to find the pixels */ + const int width = this->anim_buf_width; + const int pitch_offset = _screen.pitch - width; + const int anim_pitch_offset = this->anim_buf_pitch - width; for (int y = this->anim_buf_height; y != 0 ; y--) { - for (int x = this->anim_buf_width; x != 0 ; x--) { - uint colour = GB(*anim, 0, 8); + for (int x = width; x != 0 ; x--) { + uint16 value = *anim; + uint8 colour = GB(value, 0, 8); if (colour >= PALETTE_ANIM_START) { /* Update this pixel */ - *dst = this->AdjustBrightness(LookupColourInPalette(colour), GB(*anim, 8, 8)); + *dst = this->AdjustBrightness(LookupColourInPalette(colour), GB(value, 8, 8)); } dst++; anim++; } - dst += _screen.pitch - this->anim_buf_width; - anim += this->anim_buf_pitch - this->anim_buf_width; + dst += pitch_offset; + anim += anim_pitch_offset; } /* Make sure the backend redraws the whole screen */ @@ -513,10 +512,13 @@ void Blitter_32bppAnim::PostResize() if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height || _screen.pitch != this->anim_buf_pitch) { /* The size of the screen changed; we can assume we can wipe all data from our buffer */ - free(this->anim_buf); + free(this->anim_alloc); this->anim_buf_width = _screen.width; this->anim_buf_height = _screen.height; - this->anim_buf_pitch = _screen.pitch; - this->anim_buf = CallocT(this->anim_buf_height * this->anim_buf_pitch); + this->anim_buf_pitch = (_screen.width + 7) & ~7; + this->anim_alloc = CallocT(this->anim_buf_pitch * this->anim_buf_height + 8); + + /* align buffer to next 16 byte boundary */ + this->anim_buf = reinterpret_cast((reinterpret_cast(this->anim_alloc) + 0xF) & (~0xF)); } } -- cgit v1.2.3-54-g00ecf