src/video/SDL_rect.c
changeset 5156 307ccc9c135e
parent 5154 fb424691cfc7
child 5262 b530ef003506
equal deleted inserted replaced
5155:f3ebd1950442 5156:307ccc9c135e
   337     *X2 = x2;
   337     *X2 = x2;
   338     *Y2 = y2;
   338     *Y2 = y2;
   339     return SDL_TRUE;
   339     return SDL_TRUE;
   340 }
   340 }
   341 
   341 
   342 void
       
   343 SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect)
       
   344 {
       
   345     SDL_DirtyRect *dirty;
       
   346 
       
   347     /* FIXME: At what point is this optimization too expensive? */
       
   348     for (dirty = list->list; dirty; dirty = dirty->next) {
       
   349         if (SDL_HasIntersection(&dirty->rect, rect)) {
       
   350             SDL_UnionRect(&dirty->rect, rect, &dirty->rect);
       
   351             return;
       
   352         }
       
   353     }
       
   354 
       
   355     if (list->free) {
       
   356         dirty = list->free;
       
   357         list->free = dirty->next;
       
   358     } else {
       
   359         dirty = (SDL_DirtyRect *) SDL_malloc(sizeof(*dirty));
       
   360         if (!dirty) {
       
   361             return;
       
   362         }
       
   363     }
       
   364     dirty->rect = *rect;
       
   365     dirty->next = list->list;
       
   366     list->list = dirty;
       
   367 }
       
   368 
       
   369 void
       
   370 SDL_ClearDirtyRects(SDL_DirtyRectList * list)
       
   371 {
       
   372     SDL_DirtyRect *prev, *curr;
       
   373 
       
   374     /* Skip to the end of the free list */
       
   375     prev = NULL;
       
   376     for (curr = list->free; curr; curr = curr->next) {
       
   377         prev = curr;
       
   378     }
       
   379 
       
   380     /* Add the list entries to the end */
       
   381     if (prev) {
       
   382         prev->next = list->list;
       
   383     } else {
       
   384         list->free = list->list;
       
   385     }
       
   386     list->list = NULL;
       
   387 }
       
   388 
       
   389 void
       
   390 SDL_FreeDirtyRects(SDL_DirtyRectList * list)
       
   391 {
       
   392     while (list->list) {
       
   393         SDL_DirtyRect *elem = list->list;
       
   394         list->list = elem->next;
       
   395         SDL_free(elem);
       
   396     }
       
   397     while (list->free) {
       
   398         SDL_DirtyRect *elem = list->free;
       
   399         list->free = elem->next;
       
   400         SDL_free(elem);
       
   401     }
       
   402 }
       
   403 
       
   404 /* vi: set ts=4 sw=4 expandtab: */
   342 /* vi: set ts=4 sw=4 expandtab: */