Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 17th, 2010  |  syntax: None  |  size: 5.28 KB  |  views: 93  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/apps/gui/skin_engine/skin_backdrops.c b/apps/gui/skin_engine/skin_backdrops.c
  2. index 3a000b2..114e55b 100644
  3. --- a/apps/gui/skin_engine/skin_backdrops.c
  4. +++ b/apps/gui/skin_engine/skin_backdrops.c
  5. @@ -27,6 +27,8 @@
  6.  #include "wps_internals.h"
  7.  #include "skin_engine.h"
  8.  #include "skin_buffer.h"
  9. +#include "buffer.h"
  10. +#include "playback.h"
  11.  
  12.  #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1))
  13.  
  14. @@ -37,16 +39,25 @@ static struct skin_backdrop {
  15.      enum screen_type screen;
  16.  } backdrops[NB_BDROPS];
  17.  
  18. -#define NB_BDROPS SKINNABLE_SCREENS_COUNT*NB_SCREENS
  19. +static struct audio_alloced_buffers {
  20. +    char *buffer;
  21. +    enum screen_type screen;
  22. +    bool inuse;
  23. +} buffers[NB_BDROPS];
  24. +static bool first_init = true;
  25.  
  26.  void skin_backdrop_init(void)
  27.  {
  28.      int i;
  29.      for (i=0; i<NB_BDROPS; i++)
  30.      {
  31. +        if (first_init)
  32. +            buffers[i].buffer = NULL;
  33. +        buffers[i].inuse = false;
  34.          backdrops[i].name[0] = '\0';
  35.          backdrops[i].buffer = NULL;
  36.      }
  37. +    first_init = false;
  38.  }
  39.  
  40.  int skin_backdrop_assign(char* backdrop, char *bmpdir,
  41. @@ -91,6 +102,52 @@ int skin_backdrop_assign(char* backdrop, char *bmpdir,
  42.      return -1;
  43.  }
  44.  
  45. +static char* get_buffer(enum screen_type screen)
  46. +{
  47. +    size_t buf_size;
  48. +    int i, found = -1, free = -1;
  49. +#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
  50. +    if (screen == SCREEN_REMOTE)
  51. +        buf_size = REMOTE_LCD_BACKDROP_BYTES;
  52. +    else
  53. +#endif
  54. +        buf_size = LCD_BACKDROP_BYTES;
  55. +    for (i=0; found == -1 && i<NB_BDROPS; i++)
  56. +    {
  57. +        if (!buffers[i].inuse && buffers[i].screen == screen)
  58. +        {
  59. +            free = i;
  60. +            if (buffers[i].buffer)
  61. +                found = i;
  62. +        }
  63. +    }
  64. +    if (found != -1)
  65. +    {
  66. +        buffers[found].inuse = true;
  67. +        return buffers[found].buffer;
  68. +    }
  69. +    else if (free && !audio_status())
  70. +    {
  71. +        size_t temp;
  72. +        char *buf =  audio_get_buffer(true, &temp);
  73. +        if (temp > buf_size)
  74. +        {
  75. +            buf = buffer_alloc(buf_size);
  76. +            buffers[free].buffer = buf;
  77. +            buffers[free].inuse = true;
  78. +            buffers[free].screen = screen;
  79. +        }
  80. +        printf("from audio_buf\n");
  81. +        audio_restore_playback(AUDIO_WANT_PLAYBACK);
  82. +        return buffers[free].buffer;
  83. +    }
  84. +    else
  85. +    {
  86. +        return (char*)skin_buffer_alloc(buf_size);
  87. +    }
  88. +}
  89. +        
  90. +        
  91.  bool skin_backdrops_preload(void)
  92.  {
  93.      bool retval = true;
  94. @@ -100,16 +157,8 @@ bool skin_backdrops_preload(void)
  95.      {
  96.          if (backdrops[i].name[0] && !backdrops[i].buffer)
  97.          {
  98. -            size_t buf_size;
  99.              bool loaded = false;
  100.              enum screen_type screen = backdrops[i].screen;
  101. -#if defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
  102. -            if (screen == SCREEN_REMOTE)
  103. -                buf_size = REMOTE_LCD_BACKDROP_BYTES;
  104. -            else
  105. -#endif
  106. -                buf_size = LCD_BACKDROP_BYTES;
  107. -
  108.              filename = backdrops[i].name;
  109.              if (screen == SCREEN_MAIN && global_settings.backdrop_file[0] &&
  110.                  global_settings.backdrop_file[0] != '-' && filename[0] == '-')
  111. @@ -124,11 +173,14 @@ bool skin_backdrops_preload(void)
  112.              }
  113.              if (*filename && *filename != '-')
  114.              {
  115. -                backdrops[i].buffer = (char*)skin_buffer_alloc(buf_size);
  116. +                backdrops[i].buffer = get_buffer(screen);
  117.                  loaded = backdrops[i].buffer &&
  118.                           screens[screen].backdrop_load(filename, backdrops[i].buffer);
  119.                  if (!loaded)
  120. +                {
  121. +                    printf("%s didnt load\n", filename);
  122.                      retval = false;
  123. +                }
  124.              }
  125.              if (backdrops[i].name[0] == '-' && loaded)
  126.                  backdrops[i].name[2] = '.';
  127. @@ -145,8 +197,36 @@ void skin_backdrop_show(int backdrop_id)
  128.      if (backdrops[backdrop_id].name[0] == '-' &&
  129.          backdrops[backdrop_id].name[2] == '\0')
  130.          screens[screen].backdrop_show(NULL);
  131. -    else if (backdrops[backdrop_id].buffer)
  132. -        screens[screen].backdrop_show(backdrops[backdrop_id].buffer);
  133. +    else if (backdrops[backdrop_id].name[0] && !backdrops[backdrop_id].buffer)
  134. +    {
  135. +        /* No room, so try to swap out another backdrop... */
  136. +        int i=backdrop_id + 1;
  137. +        while (i != backdrop_id)
  138. +        {
  139. +            if (i > NB_BDROPS)
  140. +                i = 0;
  141. +            if (backdrops[i].buffer &&
  142. +                backdrops[i].screen == backdrops[backdrop_id].screen)
  143. +            {
  144. +                break;
  145. +            }
  146. +            i++;
  147. +        }
  148. +        if (i == backdrop_id)
  149. +        {
  150. +            screens[screen].backdrop_show(NULL);
  151. +            return;
  152. +        }
  153. +        backdrops[backdrop_id].buffer = backdrops[i].buffer;
  154. +        backdrops[i].buffer = NULL;
  155. +        if (!screens[screen].backdrop_load(backdrops[i].name,
  156. +                                          backdrops[backdrop_id].buffer))
  157. +        {
  158. +            screens[screen].backdrop_show(NULL);
  159. +            return;
  160. +        }
  161. +    }
  162. +    screens[screen].backdrop_show(backdrops[backdrop_id].buffer);
  163.  }
  164.  
  165.  void skin_backdrop_unload(int backdrop_id)