src/SDL12_compat.c
changeset 36 d71bb358e954
parent 35 365748d8ff6c
child 37 43520e2731a7
     1.1 --- a/src/SDL12_compat.c	Sun Apr 14 00:11:20 2013 -0400
     1.2 +++ b/src/SDL12_compat.c	Sun Apr 14 00:12:35 2013 -0400
     1.3 @@ -2104,484 +2104,6 @@
     1.4      return SDL_GetWindowWMInfo(VideoWindow20, info);
     1.5  }
     1.6  
     1.7 -#if 0
     1.8 -void
     1.9 -SDL_MoveCursor(int x, int y)
    1.10 -{
    1.11 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.12 -
    1.13 -    /* Erase and update the current mouse position */
    1.14 -    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
    1.15 -        /* Erase and redraw mouse cursor in new position */
    1.16 -        SDL_LockCursor();
    1.17 -        SDL_EraseCursor(VideoSurface);
    1.18 -        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
    1.19 -        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
    1.20 -        SDL_DrawCursor(VideoSurface);
    1.21 -        SDL_UnlockCursor();
    1.22 -    } else if (_this->MoveWMCursor) {
    1.23 -        _this->MoveWMCursor(_this, x, y);
    1.24 -    }
    1.25 -}
    1.26 -
    1.27 -/* Keep track of the current cursor colors */
    1.28 -static int palette_changed = 1;
    1.29 -static Uint8 pixels8[2];
    1.30 -
    1.31 -void
    1.32 -SDL_CursorPaletteChanged(void)
    1.33 -{
    1.34 -    palette_changed = 1;
    1.35 -}
    1.36 -
    1.37 -void
    1.38 -SDL_MouseRect(SDL_Rect * area)
    1.39 -{
    1.40 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.41 -    int clip_diff;
    1.42 -
    1.43 -    *area = SDL_cursor->area;
    1.44 -    if (area->x < 0) {
    1.45 -        area->w += area->x;
    1.46 -        area->x = 0;
    1.47 -    }
    1.48 -    if (area->y < 0) {
    1.49 -        area->h += area->y;
    1.50 -        area->y = 0;
    1.51 -    }
    1.52 -    clip_diff = (area->x + area->w) - VideoSurface->w;
    1.53 -    if (clip_diff > 0) {
    1.54 -        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
    1.55 -    }
    1.56 -    clip_diff = (area->y + area->h) - VideoSurface->h;
    1.57 -    if (clip_diff > 0) {
    1.58 -        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
    1.59 -    }
    1.60 -}
    1.61 -
    1.62 -static void
    1.63 -SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
    1.64 -{
    1.65 -    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
    1.66 -    int i, w, h;
    1.67 -    Uint8 *data, datab;
    1.68 -    Uint8 *mask, maskb;
    1.69 -
    1.70 -    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
    1.71 -    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
    1.72 -    switch (screen->format->BytesPerPixel) {
    1.73 -
    1.74 -    case 1:
    1.75 -        {
    1.76 -            Uint8 *dst;
    1.77 -            int dstskip;
    1.78 -
    1.79 -            if (palette_changed) {
    1.80 -                pixels8[0] =
    1.81 -                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
    1.82 -                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
    1.83 -                palette_changed = 0;
    1.84 -            }
    1.85 -            dst = (Uint8 *) screen->pixels +
    1.86 -                (SDL_cursor->area.y + area->y) * screen->pitch +
    1.87 -                SDL_cursor->area.x;
    1.88 -            dstskip = screen->pitch - area->w;
    1.89 -
    1.90 -            for (h = area->h; h; h--) {
    1.91 -                for (w = area->w / 8; w; w--) {
    1.92 -                    maskb = *mask++;
    1.93 -                    datab = *data++;
    1.94 -                    for (i = 0; i < 8; ++i) {
    1.95 -                        if (maskb & 0x80) {
    1.96 -                            *dst = pixels8[datab >> 7];
    1.97 -                        }
    1.98 -                        maskb <<= 1;
    1.99 -                        datab <<= 1;
   1.100 -                        dst++;
   1.101 -                    }
   1.102 -                }
   1.103 -                dst += dstskip;
   1.104 -            }
   1.105 -        }
   1.106 -        break;
   1.107 -
   1.108 -    case 2:
   1.109 -        {
   1.110 -            Uint16 *dst;
   1.111 -            int dstskip;
   1.112 -
   1.113 -            dst = (Uint16 *) screen->pixels +
   1.114 -                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
   1.115 -                SDL_cursor->area.x;
   1.116 -            dstskip = (screen->pitch / 2) - area->w;
   1.117 -
   1.118 -            for (h = area->h; h; h--) {
   1.119 -                for (w = area->w / 8; w; w--) {
   1.120 -                    maskb = *mask++;
   1.121 -                    datab = *data++;
   1.122 -                    for (i = 0; i < 8; ++i) {
   1.123 -                        if (maskb & 0x80) {
   1.124 -                            *dst = (Uint16) pixels[datab >> 7];
   1.125 -                        }
   1.126 -                        maskb <<= 1;
   1.127 -                        datab <<= 1;
   1.128 -                        dst++;
   1.129 -                    }
   1.130 -                }
   1.131 -                dst += dstskip;
   1.132 -            }
   1.133 -        }
   1.134 -        break;
   1.135 -
   1.136 -    case 3:
   1.137 -        {
   1.138 -            Uint8 *dst;
   1.139 -            int dstskip;
   1.140 -
   1.141 -            dst = (Uint8 *) screen->pixels +
   1.142 -                (SDL_cursor->area.y + area->y) * screen->pitch +
   1.143 -                SDL_cursor->area.x * 3;
   1.144 -            dstskip = screen->pitch - area->w * 3;
   1.145 -
   1.146 -            for (h = area->h; h; h--) {
   1.147 -                for (w = area->w / 8; w; w--) {
   1.148 -                    maskb = *mask++;
   1.149 -                    datab = *data++;
   1.150 -                    for (i = 0; i < 8; ++i) {
   1.151 -                        if (maskb & 0x80) {
   1.152 -                            SDL_memset(dst, pixels[datab >> 7], 3);
   1.153 -                        }
   1.154 -                        maskb <<= 1;
   1.155 -                        datab <<= 1;
   1.156 -                        dst += 3;
   1.157 -                    }
   1.158 -                }
   1.159 -                dst += dstskip;
   1.160 -            }
   1.161 -        }
   1.162 -        break;
   1.163 -
   1.164 -    case 4:
   1.165 -        {
   1.166 -            Uint32 *dst;
   1.167 -            int dstskip;
   1.168 -
   1.169 -            dst = (Uint32 *) screen->pixels +
   1.170 -                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
   1.171 -                SDL_cursor->area.x;
   1.172 -            dstskip = (screen->pitch / 4) - area->w;
   1.173 -
   1.174 -            for (h = area->h; h; h--) {
   1.175 -                for (w = area->w / 8; w; w--) {
   1.176 -                    maskb = *mask++;
   1.177 -                    datab = *data++;
   1.178 -                    for (i = 0; i < 8; ++i) {
   1.179 -                        if (maskb & 0x80) {
   1.180 -                            *dst = pixels[datab >> 7];
   1.181 -                        }
   1.182 -                        maskb <<= 1;
   1.183 -                        datab <<= 1;
   1.184 -                        dst++;
   1.185 -                    }
   1.186 -                }
   1.187 -                dst += dstskip;
   1.188 -            }
   1.189 -        }
   1.190 -        break;
   1.191 -    }
   1.192 -}
   1.193 -
   1.194 -static void
   1.195 -SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
   1.196 -{
   1.197 -    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
   1.198 -    int h;
   1.199 -    int x, minx, maxx;
   1.200 -    Uint8 *data, datab = 0;
   1.201 -    Uint8 *mask, maskb = 0;
   1.202 -    Uint8 *dst;
   1.203 -    int dstbpp, dstskip;
   1.204 -
   1.205 -    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
   1.206 -    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
   1.207 -    dstbpp = screen->format->BytesPerPixel;
   1.208 -    dst = (Uint8 *) screen->pixels +
   1.209 -        (SDL_cursor->area.y + area->y) * screen->pitch +
   1.210 -        SDL_cursor->area.x * dstbpp;
   1.211 -    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
   1.212 -
   1.213 -    minx = area->x;
   1.214 -    maxx = area->x + area->w;
   1.215 -    if (screen->format->BytesPerPixel == 1) {
   1.216 -        if (palette_changed) {
   1.217 -            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
   1.218 -            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
   1.219 -            palette_changed = 0;
   1.220 -        }
   1.221 -        for (h = area->h; h; h--) {
   1.222 -            for (x = 0; x < SDL_cursor->area.w; ++x) {
   1.223 -                if ((x % 8) == 0) {
   1.224 -                    maskb = *mask++;
   1.225 -                    datab = *data++;
   1.226 -                }
   1.227 -                if ((x >= minx) && (x < maxx)) {
   1.228 -                    if (maskb & 0x80) {
   1.229 -                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
   1.230 -                    }
   1.231 -                }
   1.232 -                maskb <<= 1;
   1.233 -                datab <<= 1;
   1.234 -                dst += dstbpp;
   1.235 -            }
   1.236 -            dst += dstskip;
   1.237 -        }
   1.238 -    } else {
   1.239 -        for (h = area->h; h; h--) {
   1.240 -            for (x = 0; x < SDL_cursor->area.w; ++x) {
   1.241 -                if ((x % 8) == 0) {
   1.242 -                    maskb = *mask++;
   1.243 -                    datab = *data++;
   1.244 -                }
   1.245 -                if ((x >= minx) && (x < maxx)) {
   1.246 -                    if (maskb & 0x80) {
   1.247 -                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
   1.248 -                    }
   1.249 -                }
   1.250 -                maskb <<= 1;
   1.251 -                datab <<= 1;
   1.252 -                dst += dstbpp;
   1.253 -            }
   1.254 -            dst += dstskip;
   1.255 -        }
   1.256 -    }
   1.257 -}
   1.258 -
   1.259 -/* This handles the ugly work of converting the saved cursor background from
   1.260 -   the pixel format of the shadow surface to that of the video surface.
   1.261 -   This is only necessary when blitting from a shadow surface of a different
   1.262 -   pixel format than the video surface, and using a software rendered cursor.
   1.263 -*/
   1.264 -static void
   1.265 -SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
   1.266 -{
   1.267 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.268 -    SDL_BlitInfo info;
   1.269 -    SDL_loblit RunBlit;
   1.270 -
   1.271 -    /* Make sure we can steal the blit mapping */
   1.272 -    if (screen->map->dst != VideoSurface) {
   1.273 -        return;
   1.274 -    }
   1.275 -
   1.276 -    /* Set up the blit information */
   1.277 -    info.s_pixels = SDL_cursor->save[1];
   1.278 -    info.s_width = w;
   1.279 -    info.s_height = h;
   1.280 -    info.s_skip = 0;
   1.281 -    info.d_pixels = SDL_cursor->save[0];
   1.282 -    info.d_width = w;
   1.283 -    info.d_height = h;
   1.284 -    info.d_skip = 0;
   1.285 -    info.aux_data = screen->map->sw_data->aux_data;
   1.286 -    info.src = screen->format;
   1.287 -    info.table = screen->map->table;
   1.288 -    info.dst = VideoSurface->format;
   1.289 -    RunBlit = screen->map->sw_data->blit;
   1.290 -
   1.291 -    /* Run the actual software blit */
   1.292 -    RunBlit(&info);
   1.293 -}
   1.294 -
   1.295 -void
   1.296 -SDL_DrawCursorNoLock(SDL_Surface * screen)
   1.297 -{
   1.298 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.299 -    SDL_Rect area;
   1.300 -
   1.301 -    /* Get the mouse rectangle, clipped to the screen */
   1.302 -    SDL_MouseRect(&area);
   1.303 -    if ((area.w == 0) || (area.h == 0)) {
   1.304 -        return;
   1.305 -    }
   1.306 -
   1.307 -    /* Copy mouse background */
   1.308 -    {
   1.309 -        int w, h, screenbpp;
   1.310 -        Uint8 *src, *dst;
   1.311 -
   1.312 -        /* Set up the copy pointers */
   1.313 -        screenbpp = screen->format->BytesPerPixel;
   1.314 -        if ((screen == VideoSurface) ||
   1.315 -            FORMAT_EQUAL(screen->format, VideoSurface->format)) {
   1.316 -            dst = SDL_cursor->save[0];
   1.317 -        } else {
   1.318 -            dst = SDL_cursor->save[1];
   1.319 -        }
   1.320 -        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
   1.321 -            area.x * screenbpp;
   1.322 -
   1.323 -        /* Perform the copy */
   1.324 -        w = area.w * screenbpp;
   1.325 -        h = area.h;
   1.326 -        while (h--) {
   1.327 -            SDL_memcpy(dst, src, w);
   1.328 -            dst += w;
   1.329 -            src += screen->pitch;
   1.330 -        }
   1.331 -    }
   1.332 -
   1.333 -    /* Draw the mouse cursor */
   1.334 -    area.x -= SDL_cursor->area.x;
   1.335 -    area.y -= SDL_cursor->area.y;
   1.336 -    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
   1.337 -        SDL_DrawCursorFast(screen, &area);
   1.338 -    } else {
   1.339 -        SDL_DrawCursorSlow(screen, &area);
   1.340 -    }
   1.341 -}
   1.342 -
   1.343 -void
   1.344 -SDL_DrawCursor(SDL_Surface * screen)
   1.345 -{
   1.346 -    /* Lock the screen if necessary */
   1.347 -    if (screen == NULL) {
   1.348 -        return;
   1.349 -    }
   1.350 -    if (SDL_MUSTLOCK(screen)) {
   1.351 -        if (SDL_LockSurface(screen) < 0) {
   1.352 -            return;
   1.353 -        }
   1.354 -    }
   1.355 -
   1.356 -    SDL_DrawCursorNoLock(screen);
   1.357 -
   1.358 -    /* Unlock the screen and update if necessary */
   1.359 -    if (SDL_MUSTLOCK(screen)) {
   1.360 -        SDL_UnlockSurface(screen);
   1.361 -    }
   1.362 -    if (screen->flags & SDL_SCREEN_SURFACE) {
   1.363 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.364 -        SDL_Window *window;
   1.365 -        SDL_Rect area;
   1.366 -
   1.367 -        window = SDL_GetWindowFromSurface(screen);
   1.368 -        if (!window) {
   1.369 -            return;
   1.370 -        }
   1.371 -
   1.372 -        SDL_MouseRect(&area);
   1.373 -
   1.374 -        if (_this->UpdateWindowSurface) {
   1.375 -            _this->UpdateWindowSurface(_this, window, 1, &area);
   1.376 -        }
   1.377 -    }
   1.378 -}
   1.379 -
   1.380 -void
   1.381 -SDL_EraseCursorNoLock(SDL_Surface * screen)
   1.382 -{
   1.383 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.384 -    SDL_Window *window;
   1.385 -    SDL_Rect area;
   1.386 -
   1.387 -    /* Get the window associated with the surface */
   1.388 -    window = SDL_GetWindowFromSurface(screen);
   1.389 -    if (!window || !window->surface) {
   1.390 -        return;
   1.391 -    }
   1.392 -
   1.393 -    /* Get the mouse rectangle, clipped to the screen */
   1.394 -    SDL_MouseRect(&area);
   1.395 -    if ((area.w == 0) || (area.h == 0)) {
   1.396 -        return;
   1.397 -    }
   1.398 -
   1.399 -    /* Copy mouse background */
   1.400 -    {
   1.401 -        int w, h, screenbpp;
   1.402 -        Uint8 *src, *dst;
   1.403 -
   1.404 -        /* Set up the copy pointers */
   1.405 -        screenbpp = screen->format->BytesPerPixel;
   1.406 -        if ((screen->flags & SDL_SCREEN_SURFACE) ||
   1.407 -            FORMAT_EQUAL(screen->format, window->surface->format)) {
   1.408 -            src = SDL_cursor->save[0];
   1.409 -        } else {
   1.410 -            src = SDL_cursor->save[1];
   1.411 -        }
   1.412 -        dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
   1.413 -            area.x * screenbpp;
   1.414 -
   1.415 -        /* Perform the copy */
   1.416 -        w = area.w * screenbpp;
   1.417 -        h = area.h;
   1.418 -        while (h--) {
   1.419 -            SDL_memcpy(dst, src, w);
   1.420 -            src += w;
   1.421 -            dst += screen->pitch;
   1.422 -        }
   1.423 -
   1.424 -        /* Perform pixel conversion on cursor background */
   1.425 -        if (src > SDL_cursor->save[1]) {
   1.426 -            SDL_ConvertCursorSave(screen, area.w, area.h);
   1.427 -        }
   1.428 -    }
   1.429 -}
   1.430 -
   1.431 -void
   1.432 -SDL_EraseCursor(SDL_Surface * screen)
   1.433 -{
   1.434 -    /* Lock the screen if necessary */
   1.435 -    if (screen == NULL) {
   1.436 -        return;
   1.437 -    }
   1.438 -    if (SDL_MUSTLOCK(screen)) {
   1.439 -        if (SDL_LockSurface(screen) < 0) {
   1.440 -            return;
   1.441 -        }
   1.442 -    }
   1.443 -
   1.444 -    SDL_EraseCursorNoLock(screen);
   1.445 -
   1.446 -    /* Unlock the screen and update if necessary */
   1.447 -    if (SDL_MUSTLOCK(screen)) {
   1.448 -        SDL_UnlockSurface(screen);
   1.449 -    }
   1.450 -    if (screen->flags & SDL_SCREEN_SURFACE) {
   1.451 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.452 -        SDL_Window *window;
   1.453 -        SDL_Rect area;
   1.454 -
   1.455 -        window = SDL_GetWindowFromSurface(screen);
   1.456 -        if (!window) {
   1.457 -            return;
   1.458 -        }
   1.459 -
   1.460 -        SDL_MouseRect(&area);
   1.461 -
   1.462 -        if (_this->UpdateWindowSurface) {
   1.463 -            _this->UpdateWindowSurface(_this, window, 1, &area);
   1.464 -        }
   1.465 -    }
   1.466 -}
   1.467 -
   1.468 -/* Reset the cursor on video mode change
   1.469 -   FIXME:  Keep track of all cursors, and reset them all.
   1.470 - */
   1.471 -void
   1.472 -SDL_ResetCursor(void)
   1.473 -{
   1.474 -    int savelen;
   1.475 -
   1.476 -    if (SDL_cursor) {
   1.477 -        savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
   1.478 -        SDL_cursor->area.x = 0;
   1.479 -        SDL_cursor->area.y = 0;
   1.480 -        SDL_memset(SDL_cursor->save[0], 0, savelen);
   1.481 -    }
   1.482 -}
   1.483 -#endif
   1.484 -
   1.485  struct private_yuvhwdata
   1.486  {
   1.487      SDL_SW_YUVTexture *texture;