From b6cdb521a172cd4c25c94c3578e6c5da52d914f2 Mon Sep 17 00:00:00 2001 From: bjarni Date: Sun, 19 Feb 2006 10:21:01 +0000 Subject: (svn r3618) -Codechange: [OSX] reduce the time spend in the cocoa video driver by caching global vars in local vars, the CPU keeps them in registers when looping all pixels on screen this reduce reading from RAM, which is much slower (Tron wrote this after I detected that those loops used a lot of time) Note: since the reduced time is waiting for the RAM, the actual CPU usage is not reduced. This means that it's only detectable while fast forwarding and other situations when OTTD wants to use more than 100% of the CPU time --- video/cocoa_v.m | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'video') diff --git a/video/cocoa_v.m b/video/cocoa_v.m index b288b9109..0daffd8f1 100644 --- a/video/cocoa_v.m +++ b/video/cocoa_v.m @@ -984,30 +984,36 @@ static void QZ_UpdateWindowPalette(uint start, uint count) _cocoa_video_data.num_dirty_rects = MAX_DIRTY_RECTS; } -static inline void QZ_WindowBlitIndexedPixelsToView32(int left, int top, int right, int bottom) -{ - int x, y; +static inline void QZ_WindowBlitIndexedPixelsToView32(uint left, uint top, uint right, uint bottom) +{ + const uint32* pal = _cocoa_video_data.palette32; + const uint8* src = _cocoa_video_data.pixels; + uint32* dst = (uint32*)_cocoa_video_data.realpixels; + uint width = _cocoa_video_data.width; + uint pitch = _cocoa_video_data.pitch / 4; + uint x; + uint y; for (y = top; y < bottom; y++) { - const uint8* src = _cocoa_video_data.pixels + y * _cocoa_video_data.width + left; - uint32* trg = (uint32*)_cocoa_video_data.realpixels + y * _cocoa_video_data.pitch / 4 + left; - - for (x = left; x < right; x++, trg++, src++) { - *trg = _cocoa_video_data.palette32[*src]; + for (x = left; x < right; x++) { + dst[y * pitch + x] = pal[src[y * width + x]]; } } } -static inline void QZ_WindowBlitIndexedPixelsToView16(int left, int top, int right, int bottom) +static inline void QZ_WindowBlitIndexedPixelsToView16(uint left, uint top, uint right, uint bottom) { - int x, y; + const uint16* pal = _cocoa_video_data.palette16; + const uint8* src = _cocoa_video_data.pixels; + uint16* dst = (uint16*)_cocoa_video_data.realpixels; + uint width = _cocoa_video_data.width; + uint pitch = _cocoa_video_data.pitch / 2; + uint x; + uint y; for (y = top; y < bottom; y++) { - const uint8* src = _cocoa_video_data.pixels + y * _cocoa_video_data.width + left; - uint16* trg = (uint16*)_cocoa_video_data.realpixels + y * _cocoa_video_data.pitch / 2 + left; - - for (x = left; x < right; x++, trg++, src++) { - *trg = _cocoa_video_data.palette16[*src]; + for (x = left; x < right; x++) { + dst[y * pitch + x] = pal[src[y * width + x]]; } } } @@ -1458,16 +1464,21 @@ static void QZ_WaitForVerticalBlank(void) static void QZ_DrawScreen(void) { + const uint8* src; + uint8* dst; + uint height; + uint width; + uint pitch; uint y; QZ_WaitForVerticalBlank(); - for (y = 0; y < _cocoa_video_data.height; y++) { - const uint8* src = _cocoa_video_data.pixels + y * _cocoa_video_data.width; - uint8* dst = (uint8*)_cocoa_video_data.realpixels + y * _cocoa_video_data.pitch; - - memcpy(dst, src, _cocoa_video_data.width); - } + src = _cocoa_video_data.pixels; + dst = (uint8*)_cocoa_video_data.realpixels; + height = _cocoa_video_data.height; + width = _cocoa_video_data.width; + pitch = _cocoa_video_data.pitch; + for (y = 0; y < height; y++) memcpy(dst + y * pitch, src + y * width, width); } static int QZ_ListFullscreenModes(OTTDPoint* mode_list, int max_modes) -- cgit v1.2.3-70-g09d2