optimized display update region
This commit is contained in:
@@ -36,6 +36,11 @@ DisplaySDL::~DisplaySDL() {
|
||||
}
|
||||
|
||||
void DisplaySDL::updateWindow() const {
|
||||
if(miTopDirtyScanline > miBottomDirtyScanline) {
|
||||
// No changes since the last update
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Surface *pSurface = SDL_GetWindowSurface(mpWindow);
|
||||
SDL_LockSurface(pSurface);
|
||||
|
||||
@@ -48,10 +53,15 @@ void DisplaySDL::updateWindow() const {
|
||||
lx = -1;
|
||||
ly = -1;
|
||||
for(sy = 0; sy < pSurface->h; sy++) {
|
||||
// Map SDL surface coordinates to Chocochip8 Framebuffer coordinates
|
||||
fy = sy * (double(chocochip8::gcHeight) / pSurface->h);
|
||||
if(fy < miTopDirtyScanline || miBottomDirtyScanline < fy) {
|
||||
// Skip scanlines that haven't changed since the last update
|
||||
continue;
|
||||
}
|
||||
|
||||
for(sx = 0; sx < pSurface->w; sx++) {
|
||||
// Map SDL surface coordinates to Chocochip8 Framebuffer coordinates
|
||||
fx = sx * (double(chocochip8::gcWidth) / pSurface->w);
|
||||
fy = sy * (double(chocochip8::gcHeight) / pSurface->h);
|
||||
|
||||
// Reuse color if this screen pixel maps to the same ChocoChip8 pixel as the last
|
||||
if(fx != lx || fy != ly) {
|
||||
@@ -72,6 +82,8 @@ void DisplaySDL::updateWindow() const {
|
||||
}
|
||||
}
|
||||
|
||||
miTopDirtyScanline = chocochip8::gcHeight - 1;
|
||||
miBottomDirtyScanline = 0;
|
||||
SDL_UnlockSurface(pSurface);
|
||||
SDL_UpdateWindowSurface(mpWindow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user