- /* for doublebuf forcing on apps */
- if (nrects == 1 && rects->x == 0 && rects->y == 0
- && !pdata->app_uses_flip && (this->screen->flags & SDL_DOUBLEBUF)
- && rects->w == this->screen->w && rects->h == this->screen->h)
- {
- this->screen->pixels = osdl_video_flip(pdata);
+ fullscreen_blit =
+ nrects == 1 && rects->x == 0 && rects->y == 0
+ && (rects->w == screen->w || rects->w == 0)
+ && (rects->h == screen->h || rects->h == 0);
+
+ if (screen->flags & SDL_DOUBLEBUF) {
+ if (fullscreen_blit && !pdata->app_uses_flip)
+ screen->pixels = osdl_video_flip(pdata);
+ return;
+ }
+
+ src = screen->pixels;
+ dst = pdata->front_buffer;
+ if (src == dst)
+ return;
+
+ if (fullscreen_blit) {
+ memcpy(dst, src, screen->pitch * screen->h);
+ return;
+ }
+
+ for (i = 0, Bpp = screen->format->BytesPerPixel; i < nrects; i++) {
+ /* this supposedly has no clipping, but we'll do it anyway */
+ x = rects[i].x, y = rects[i].y, w = rects[i].w, h = rects[i].h;
+ if (x < 0)
+ w += x, x = 0;
+ else if (x + w > screen->w)
+ w = screen->w - x;
+ if (w <= 0)
+ continue;
+
+ if (y < 0)
+ h += y, y = 0;
+ else if (y + h > screen->h)
+ h = screen->h - y;
+
+ for (; h > 0; y++, h--)
+ memcpy(dst + y * screen->pitch + x * Bpp,
+ src + y * screen->pitch + x * Bpp,
+ w * Bpp);