2009-08-16 18:23:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: wps_parser.c 19880 2009-01-29 20:49:43Z mcuelenaere $
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
* Copyright (C) 2009 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "screen_access.h"
|
|
|
|
|
|
|
|
/* skin buffer management.
|
|
|
|
* This module is used to allocate space in a single global skin buffer for
|
|
|
|
* tokens for both/all screens.
|
|
|
|
*
|
|
|
|
* This is mostly just copy/paste from firmware/buffer.c
|
2009-08-16 19:15:17 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* MAIN_ and REMOTE_BUFFER are just for reasonable size calibration,
|
|
|
|
* both screens can use the whole buffer as they need; it's not split
|
|
|
|
* between screens
|
2009-08-19 04:19:08 +00:00
|
|
|
*
|
|
|
|
* Buffer can be allocated from either "end" of the global buffer.
|
|
|
|
* items with unknown sizes get allocated from the start (0->) (data)
|
|
|
|
* items with known sizes get allocated from the end (<-buf_size) (tokens)
|
|
|
|
* After loading 2 skins the buffer will look like this:
|
|
|
|
* |tokens skin1|images skin2|---SPACE---|data skin2|data skin1|
|
|
|
|
* Make sure to never start allocating from the beginning before letting us know
|
|
|
|
* how much was used. and RESPECT THE buf_free RETURN VALUES!
|
|
|
|
*
|
2009-08-16 18:23:00 +00:00
|
|
|
*/
|
|
|
|
|
2009-08-16 19:15:17 +00:00
|
|
|
|
|
|
|
#define MAIN_BUFFER ((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \
|
|
|
|
+ (2*LCD_HEIGHT*LCD_WIDTH/8))
|
|
|
|
|
|
|
|
#if (NB_SCREENS > 1)
|
|
|
|
#define REMOTE_BUFFER ((LCD_REMOTE_HEIGHT*LCD_REMOTE_WIDTH*LCD_REMOTE_DEPTH/8) \
|
|
|
|
+ (2*LCD_REMOTE_HEIGHT*LCD_REMOTE_WIDTH/8))
|
|
|
|
#else
|
|
|
|
#define REMOTE_BUFFER 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define SKIN_BUFFER_SIZE (MAIN_BUFFER + REMOTE_BUFFER)
|
|
|
|
|
|
|
|
|
2009-08-19 04:19:08 +00:00
|
|
|
static unsigned char buffer[SKIN_BUFFER_SIZE];
|
|
|
|
static unsigned char *buffer_front = NULL; /* start of the free space,
|
|
|
|
increases with allocation*/
|
|
|
|
static unsigned char *buffer_back = NULL; /* end of the free space
|
|
|
|
decreases with allocation */
|
2009-08-16 19:15:17 +00:00
|
|
|
static size_t buf_size = SKIN_BUFFER_SIZE;
|
2009-08-16 18:23:00 +00:00
|
|
|
|
|
|
|
void skin_buffer_init(void)
|
|
|
|
{
|
|
|
|
#if 0 /* this will go in again later probably */
|
2009-08-19 04:19:08 +00:00
|
|
|
if (buffer == NULL)
|
2009-08-16 18:23:00 +00:00
|
|
|
{
|
2009-08-16 19:15:17 +00:00
|
|
|
buf_size = SKIN_BUFFER_SIZE;/* global_settings.skin_buf_size */
|
2009-08-16 18:23:00 +00:00
|
|
|
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer = buffer_alloc(buf_size);
|
|
|
|
buffer_front = buffer;
|
|
|
|
buffer_back = bufer + buf_size;
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* reset the buffer.... */
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer_front = buffer;
|
|
|
|
buffer_back = buffer + buf_size;
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the number of bytes currently being used */
|
|
|
|
size_t skin_buffer_usage(void)
|
|
|
|
{
|
2009-08-19 04:19:08 +00:00
|
|
|
return buf_size - (buffer_back-buffer_front);
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 04:19:08 +00:00
|
|
|
size_t skin_buffer_freespace(void)
|
|
|
|
{
|
|
|
|
return buffer_back-buffer_front;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate size bytes from the buffer
|
|
|
|
* allocates from the back end (data end)
|
|
|
|
*/
|
2009-08-16 18:23:00 +00:00
|
|
|
void* skin_buffer_alloc(size_t size)
|
|
|
|
{
|
2009-08-19 04:19:08 +00:00
|
|
|
if (skin_buffer_freespace() <= size)
|
2009-08-16 18:23:00 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer_back -= size;
|
2009-08-16 18:23:00 +00:00
|
|
|
/* 32-bit aligned */
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer_back = (void *)(((unsigned long)buffer_back) & ~3);
|
|
|
|
return buffer_back;
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a pointer to the skin buffer and the count of how much is free
|
|
|
|
* used to do your own buffer management.
|
|
|
|
* Any memory used will be overwritten next time wps_buffer_alloc()
|
|
|
|
* is called unless skin_buffer_increment() is called first
|
2009-08-19 04:19:08 +00:00
|
|
|
*
|
|
|
|
* This is from the start of the buffer, it is YOUR responsility to make
|
|
|
|
* sure you dont ever use more then *freespace, and bear in mind this will only
|
|
|
|
* be valid untill skin_buffer_alloc() is next called...
|
|
|
|
* so call skin_buffer_increment() and skin_buffer_freespace() regularly
|
2009-08-16 18:23:00 +00:00
|
|
|
*/
|
|
|
|
void* skin_buffer_grab(size_t *freespace)
|
|
|
|
{
|
|
|
|
*freespace = buf_size - skin_buffer_usage();
|
2009-08-19 04:19:08 +00:00
|
|
|
return buffer_front;
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Use after skin_buffer_grab() to specify how much buffer was used */
|
2009-08-19 04:19:08 +00:00
|
|
|
void skin_buffer_increment(size_t used, bool align)
|
2009-08-16 18:23:00 +00:00
|
|
|
{
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer_front += used;
|
|
|
|
if (align)
|
|
|
|
{
|
|
|
|
/* 32-bit aligned */
|
|
|
|
buffer_front = (void *)(((unsigned long)buffer_front + 3) & ~3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free previously skin_buffer_increment()'ed space. This just moves the pointer
|
|
|
|
* back 'used' bytes so make sure you actually want to do this */
|
|
|
|
void skin_buffer_free_from_front(size_t used)
|
|
|
|
{
|
|
|
|
buffer_front -= used;
|
2009-08-16 18:23:00 +00:00
|
|
|
/* 32-bit aligned */
|
2009-08-19 04:19:08 +00:00
|
|
|
buffer_front = (void *)(((unsigned long)buffer_front + 3) & ~3);
|
2009-08-16 18:23:00 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 04:19:08 +00:00
|
|
|
|