mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(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
This commit is contained in:
parent
55461bd2ec
commit
92c37bd5ea
@ -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)
|
||||
static inline void QZ_WindowBlitIndexedPixelsToView32(uint left, uint top, uint right, uint bottom)
|
||||
{
|
||||
int x, y;
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user