src/video/SDL_stretch.c
changeset 7037 3fedf1f25b94
parent 6885 700f1b25f77f
child 7208 414ad123be9b
equal deleted inserted replaced
7036:8c891504e325 7037:3fedf1f25b94
   100     case 4:
   100     case 4:
   101         load = LOAD_WORD;
   101         load = LOAD_WORD;
   102         store = STORE_WORD;
   102         store = STORE_WORD;
   103         break;
   103         break;
   104     default:
   104     default:
   105         SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp);
   105         return SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp);
   106         return (-1);
       
   107     }
   106     }
   108 #ifdef HAVE_MPROTECT
   107 #ifdef HAVE_MPROTECT
   109     /* Make the code writeable */
   108     /* Make the code writeable */
   110     if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) {
   109     if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) {
   111         SDL_SetError("Couldn't make copy buffer writeable");
   110         return SDL_SetError("Couldn't make copy buffer writeable");
   112         return (-1);
       
   113     }
   111     }
   114 #endif
   112 #endif
   115     pos = 0x10000;
   113     pos = 0x10000;
   116     inc = (src_w << 16) / dst_w;
   114     inc = (src_w << 16) / dst_w;
   117     eip = copy_row;
   115     eip = copy_row;
   139     *eip++ = RETURN;
   137     *eip++ = RETURN;
   140 
   138 
   141 #ifdef HAVE_MPROTECT
   139 #ifdef HAVE_MPROTECT
   142     /* Make the code executable but not writeable */
   140     /* Make the code executable but not writeable */
   143     if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
   141     if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {
   144         SDL_SetError("Couldn't make copy buffer executable");
   142         return SDL_SetError("Couldn't make copy buffer executable");
   145         return (-1);
       
   146     }
   143     }
   147 #endif
   144 #endif
   148     last.status = 0;
   145     last.status = 0;
   149     return (0);
   146     return (0);
   150 }
   147 }
   222 #endif
   219 #endif
   223 #endif /* USE_ASM_STRETCH */
   220 #endif /* USE_ASM_STRETCH */
   224     const int bpp = dst->format->BytesPerPixel;
   221     const int bpp = dst->format->BytesPerPixel;
   225 
   222 
   226     if (src->format->BitsPerPixel != dst->format->BitsPerPixel) {
   223     if (src->format->BitsPerPixel != dst->format->BitsPerPixel) {
   227         SDL_SetError("Only works with same format surfaces");
   224         return SDL_SetError("Only works with same format surfaces");
   228         return (-1);
       
   229     }
   225     }
   230 
   226 
   231     /* Verify the blit rectangles */
   227     /* Verify the blit rectangles */
   232     if (srcrect) {
   228     if (srcrect) {
   233         if ((srcrect->x < 0) || (srcrect->y < 0) ||
   229         if ((srcrect->x < 0) || (srcrect->y < 0) ||
   234             ((srcrect->x + srcrect->w) > src->w) ||
   230             ((srcrect->x + srcrect->w) > src->w) ||
   235             ((srcrect->y + srcrect->h) > src->h)) {
   231             ((srcrect->y + srcrect->h) > src->h)) {
   236             SDL_SetError("Invalid source blit rectangle");
   232             return SDL_SetError("Invalid source blit rectangle");
   237             return (-1);
       
   238         }
   233         }
   239     } else {
   234     } else {
   240         full_src.x = 0;
   235         full_src.x = 0;
   241         full_src.y = 0;
   236         full_src.y = 0;
   242         full_src.w = src->w;
   237         full_src.w = src->w;
   245     }
   240     }
   246     if (dstrect) {
   241     if (dstrect) {
   247         if ((dstrect->x < 0) || (dstrect->y < 0) ||
   242         if ((dstrect->x < 0) || (dstrect->y < 0) ||
   248             ((dstrect->x + dstrect->w) > dst->w) ||
   243             ((dstrect->x + dstrect->w) > dst->w) ||
   249             ((dstrect->y + dstrect->h) > dst->h)) {
   244             ((dstrect->y + dstrect->h) > dst->h)) {
   250             SDL_SetError("Invalid destination blit rectangle");
   245             return SDL_SetError("Invalid destination blit rectangle");
   251             return (-1);
       
   252         }
   246         }
   253     } else {
   247     } else {
   254         full_dst.x = 0;
   248         full_dst.x = 0;
   255         full_dst.y = 0;
   249         full_dst.y = 0;
   256         full_dst.w = dst->w;
   250         full_dst.w = dst->w;
   260 
   254 
   261     /* Lock the destination if it's in hardware */
   255     /* Lock the destination if it's in hardware */
   262     dst_locked = 0;
   256     dst_locked = 0;
   263     if (SDL_MUSTLOCK(dst)) {
   257     if (SDL_MUSTLOCK(dst)) {
   264         if (SDL_LockSurface(dst) < 0) {
   258         if (SDL_LockSurface(dst) < 0) {
   265             SDL_SetError("Unable to lock destination surface");
   259             return SDL_SetError("Unable to lock destination surface");
   266             return (-1);
       
   267         }
   260         }
   268         dst_locked = 1;
   261         dst_locked = 1;
   269     }
   262     }
   270     /* Lock the source if it's in hardware */
   263     /* Lock the source if it's in hardware */
   271     src_locked = 0;
   264     src_locked = 0;
   272     if (SDL_MUSTLOCK(src)) {
   265     if (SDL_MUSTLOCK(src)) {
   273         if (SDL_LockSurface(src) < 0) {
   266         if (SDL_LockSurface(src) < 0) {
   274             if (dst_locked) {
   267             if (dst_locked) {
   275                 SDL_UnlockSurface(dst);
   268                 SDL_UnlockSurface(dst);
   276             }
   269             }
   277             SDL_SetError("Unable to lock source surface");
   270             return SDL_SetError("Unable to lock source surface");
   278             return (-1);
       
   279         }
   271         }
   280         src_locked = 1;
   272         src_locked = 1;
   281     }
   273     }
   282 
   274 
   283     /* Set up the data... */
   275     /* Set up the data... */