src/render/SDL_render.c
changeset 5288 d4381f3b0d1e
parent 5270 7aba0406c273
child 5289 1916a9e9714d
equal deleted inserted replaced
5287:d1823573d005 5288:d4381f3b0d1e
    25 
    25 
    26 #include "SDL_hints.h"
    26 #include "SDL_hints.h"
    27 #include "SDL_log.h"
    27 #include "SDL_log.h"
    28 #include "SDL_render.h"
    28 #include "SDL_render.h"
    29 #include "SDL_sysrender.h"
    29 #include "SDL_sysrender.h"
    30 #include "../video/SDL_pixels_c.h"
       
    31 #include "software/SDL_render_sw_c.h"
    30 #include "software/SDL_render_sw_c.h"
    32 
    31 
    33 
    32 
    34 #define CHECK_RENDERER_MAGIC(renderer, retval) \
    33 #define CHECK_RENDERER_MAGIC(renderer, retval) \
    35     if (!renderer || renderer->magic != &renderer_magic) { \
    34     if (!renderer || renderer->magic != &renderer_magic) { \
   304 {
   303 {
   305     const SDL_PixelFormat *fmt;
   304     const SDL_PixelFormat *fmt;
   306     SDL_bool needAlpha;
   305     SDL_bool needAlpha;
   307     Uint32 i;
   306     Uint32 i;
   308     Uint32 format;
   307     Uint32 format;
   309     int bpp;
       
   310     Uint32 Rmask, Gmask, Bmask, Amask;
       
   311     SDL_Texture *texture;
   308     SDL_Texture *texture;
   312 
   309 
   313     CHECK_RENDERER_MAGIC(renderer, NULL);
   310     CHECK_RENDERER_MAGIC(renderer, NULL);
   314 
   311 
   315     if (!surface) {
   312     if (!surface) {
   331             format = renderer->info.texture_formats[i];
   328             format = renderer->info.texture_formats[i];
   332             break;
   329             break;
   333         }
   330         }
   334     }
   331     }
   335 
   332 
   336     if (!SDL_PixelFormatEnumToMasks(format, &bpp,
       
   337                                     &Rmask, &Gmask, &Bmask, &Amask)) {
       
   338         SDL_SetError("Unknown pixel format");
       
   339         return NULL;
       
   340     }
       
   341 
       
   342     texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
   333     texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
   343                                 surface->w, surface->h);
   334                                 surface->w, surface->h);
   344     if (!texture) {
   335     if (!texture) {
   345         return NULL;
   336         return NULL;
   346     }
   337     }
   347 
   338 
   348     if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
   339     if (format == surface->format->format) {
   349         && Bmask == fmt->Bmask && Amask == fmt->Amask) {
       
   350         if (SDL_MUSTLOCK(surface)) {
   340         if (SDL_MUSTLOCK(surface)) {
   351             SDL_LockSurface(surface);
   341             SDL_LockSurface(surface);
   352             SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
   342             SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
   353             SDL_UnlockSurface(surface);
   343             SDL_UnlockSurface(surface);
   354         } else {
   344         } else {
   357     } else {
   347     } else {
   358         SDL_PixelFormat dst_fmt;
   348         SDL_PixelFormat dst_fmt;
   359         SDL_Surface *temp = NULL;
   349         SDL_Surface *temp = NULL;
   360 
   350 
   361         /* Set up a destination surface for the texture update */
   351         /* Set up a destination surface for the texture update */
   362         SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask);
   352         SDL_InitFormat(&dst_fmt, format);
   363         temp = SDL_ConvertSurface(surface, &dst_fmt, 0);
   353         temp = SDL_ConvertSurface(surface, &dst_fmt, 0);
   364         if (temp) {
   354         if (temp) {
   365             SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
   355             SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
   366             SDL_FreeSurface(temp);
   356             SDL_FreeSurface(temp);
   367         } else {
   357         } else {