CVS: rdesktop cache.c,1.22,1.23 orders.c,1.41,1.42 proto.h,1.69,1.70 pstcache.c,1.3,1.4 rdp.c,1.73,1.74 types.h,1.23,1.24

Jeroen Meijer <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5839

Modified Files:
	cache.c orders.c proto.h pstcache.c rdp.c types.h 
Log Message:
optimise persistent bitmap caching and hopefully improve the terminology

Index: cache.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/cache.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** cache.c	6 Mar 2005 21:11:04 -0000	1.22
--- cache.c	8 Mar 2005 00:23:01 -0000	1.23
***************
*** 3,6 ****
--- 3,7 ----
     Cache routines
     Copyright (C) Matthew Chapman 1999-2005
+    Copyright (C) Jeroen Meijer 2005
  
     This program is free software; you can redistribute it and/or modify
***************
*** 21,87 ****
  #include "rdesktop.h"
  
  #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
- #define TOUCH(id, idx) (g_bmpcache[id][idx].usage = ++g_stamp)
  #define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0)
  
! extern int g_pstcache_fd[];
! extern BOOL g_use_rdp5;
! 
! uint32 g_stamp;
  
! static int g_num_bitmaps_in_memory[3];
  
! /* BITMAP CACHE */
! static BMPCACHEENTRY g_bmpcache[3][0xa00];
  static HBITMAP g_volatile_bc[3];
  
! /* Remove the least-recently used bitmap from the cache */
  void
! cache_remove_lru_bitmap(uint8 cache_id)
  {
! 	uint32 i;
! 	uint16 cache_idx = 0;
! 	uint32 m = 0xffffffff;
! 	BMPCACHEENTRY *pbce;
  
! 	for (i = 0; i < NUM_ELEMENTS(g_bmpcache[cache_id]); i++)
  	{
! 		if (g_bmpcache[cache_id][i].bitmap && g_bmpcache[cache_id][i].usage < m)
  		{
! 			cache_idx = i;
! 			m = g_bmpcache[cache_id][i].usage;
  		}
  	}
  
! 	pbce = &g_bmpcache[cache_id][cache_idx];
! 	ui_destroy_bitmap(pbce->bitmap);
! 	--g_num_bitmaps_in_memory[cache_id];
! 	pbce->bitmap = 0;
! 	pbce->usage = 0;
  }
  
  /* Retrieve a bitmap from the cache */
  HBITMAP
! cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
  {
! 	HBITMAP *pbitmap;
! 
! 	if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
  	{
! 		pbitmap = &g_bmpcache[cache_id][cache_idx].bitmap;
! 		if ((*pbitmap != 0) || pstcache_load_bitmap(cache_id, cache_idx))
  		{
! 			if (IS_PERSISTENT(cache_id))
! 				TOUCH(cache_id, cache_idx);
  
! 			return *pbitmap;
  		}
  	}
! 	else if ((cache_id < NUM_ELEMENTS(g_volatile_bc)) && (cache_idx == 0x7fff))
  	{
! 		return g_volatile_bc[cache_id];
  	}
  
! 	error("get bitmap %d:%d\n", cache_id, cache_idx);
  	return NULL;
  }
--- 22,213 ----
  #include "rdesktop.h"
  
+ /* BITMAP CACHE */
+ extern int g_pstcache_fd[];
+ 
  #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
  #define IS_PERSISTENT(id) (g_pstcache_fd[id] > 0)
+ #define TO_TOP -1
+ #define NOT_SET -1
+ #define IS_SET(idx) (idx >= 0)
  
! /*
!  * TODO: Test for optimal value of BUMP_COUNT. TO_TOP gives lowest cpu utilisation but using
!  * a positive value will hopefully result in less frequently used bitmaps having a greater chance
!  * of being evicted from the cache, and therby reducing the need to load bitmaps from disk.
!  * (Jeroen)
!  */
! #define BUMP_COUNT 40
  
! struct bmpcache_entry
! {
! 	HBITMAP bitmap;
! 	sint16 previous;
! 	sint16 next;
! };
  
! static struct bmpcache_entry g_bmpcache[3][0xa00];
  static HBITMAP g_volatile_bc[3];
  
! static int g_bmpcache_lru[3] = { NOT_SET, NOT_SET, NOT_SET };
! static int g_bmpcache_mru[3] = { NOT_SET, NOT_SET, NOT_SET };
! static int g_bmpcache_count[3];
! 
! /* Setup the bitmap cache lru/mru linked list */
  void
! cache_rebuild_bmpcache_linked_list(uint8 id, sint16 * idx, int count)
  {
! 	int n = count, c = 0;
! 	sint16 n_idx;
  
! 	/* find top, skip evicted bitmaps */
! 	while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
! 	if (n < 0)
  	{
! 		g_bmpcache_mru[id] = g_bmpcache_lru[id] = NOT_SET;
! 		return;
! 	}
! 
! 	g_bmpcache_mru[id] = idx[n];
! 	g_bmpcache[id][idx[n]].next = NOT_SET;
! 	n_idx = idx[n];
! 	c++;
! 
! 	/* link list */
! 	while (n >= 0)
! 	{
! 		/* skip evicted bitmaps */
! 		while (--n >= 0 && g_bmpcache[id][idx[n]].bitmap == NULL);
! 
! 		if (n < 0)
! 			break;
! 
! 		g_bmpcache[id][n_idx].previous = idx[n];
! 		g_bmpcache[id][idx[n]].next = n_idx;
! 		n_idx = idx[n];
! 		c++;
! 	}
! 
! 	g_bmpcache[id][n_idx].previous = NOT_SET;
! 	g_bmpcache_lru[id] = n_idx;
! 
! 	if (c != g_bmpcache_count[id])
! 	{
! 		error("Oops. %d in bitmap cache linked list, %d in ui cache...\n", c,
! 		      g_bmpcache_count[id]);
! 		exit(1);
! 	}
! }
! 
! /* Move a bitmap to a new position in the linked list. */
! void
! cache_bump_bitmap(uint8 id, uint16 idx, int bump)
! {
! 	int p_idx, n_idx, n;
! 
! 	if (!IS_PERSISTENT(id))
! 		return;
! 
! 	if (g_bmpcache_mru[id] == idx)
! 		return;
! 
! 	DEBUG_RDP5(("bump bitmap: id=%d, idx=%d, bump=%d\n", id, idx, bump));
! 
! 	n_idx = g_bmpcache[id][idx].next;
! 	p_idx = g_bmpcache[id][idx].previous;
! 
! 	if (IS_SET(n_idx))
! 	{
! 		/* remove */
! 		--g_bmpcache_count[id];
! 		if (IS_SET(p_idx))
! 			g_bmpcache[id][p_idx].next = n_idx;
! 		else
! 			g_bmpcache_lru[id] = n_idx;
! 		if (IS_SET(n_idx))
! 			g_bmpcache[id][n_idx].previous = p_idx;
! 		else
! 			g_bmpcache_mru[id] = p_idx;
! 	}
! 	else
! 	{
! 		p_idx = NOT_SET;
! 		n_idx = g_bmpcache_lru[id];
! 	}
! 
! 	if (bump >= 0)
! 	{
! 		for (n = 0; n < bump && IS_SET(n_idx); n++)
  		{
! 			p_idx = n_idx;
! 			n_idx = g_bmpcache[id][p_idx].next;
  		}
  	}
+ 	else
+ 	{
+ 		p_idx = g_bmpcache_mru[id];
+ 		n_idx = NOT_SET;
+ 	}
  
! 	/* insert */
! 	++g_bmpcache_count[id];
! 	g_bmpcache[id][idx].previous = p_idx;
! 	g_bmpcache[id][idx].next = n_idx;
! 
! 	if (p_idx >= 0)
! 		g_bmpcache[id][p_idx].next = idx;
! 	else
! 		g_bmpcache_lru[id] = idx;
! 
! 	if (n_idx >= 0)
! 		g_bmpcache[id][n_idx].previous = idx;
! 	else
! 		g_bmpcache_mru[id] = idx;
! }
! 
! /* Evict the least-recently used bitmap from the cache */
! void
! cache_evict_bitmap(uint8 id)
! {
! 	uint16 idx;
! 	int n_idx;
! 
! 	if (!IS_PERSISTENT(id))
! 		return;
! 
! 	idx = g_bmpcache_lru[id];
! 	n_idx = g_bmpcache[id][idx].next;
! 	DEBUG_RDP5(("evict bitmap: id=%d idx=%d n_idx=%d bmp=0x%x\n", id, idx, n_idx,
! 		    g_bmpcache[id][idx].bitmap));
! 
! 	ui_destroy_bitmap(g_bmpcache[id][idx].bitmap);
! 	--g_bmpcache_count[id];
! 	g_bmpcache[id][idx].bitmap = 0;
! 
! 	g_bmpcache_lru[id] = n_idx;
! 	g_bmpcache[id][n_idx].previous = NOT_SET;
! 
! 	pstcache_touch_bitmap(id, idx, 0);
  }
  
  /* Retrieve a bitmap from the cache */
  HBITMAP
! cache_get_bitmap(uint8 id, uint16 idx)
  {
! 	if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
  	{
! 		if (g_bmpcache[id][idx].bitmap || pstcache_load_bitmap(id, idx))
  		{
! 			if (IS_PERSISTENT(id))
! 				cache_bump_bitmap(id, idx, BUMP_COUNT);
  
! 			return g_bmpcache[id][idx].bitmap;
  		}
  	}
! 	else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
  	{
! 		return g_volatile_bc[id];
  	}
  
! 	error("get bitmap %d:%d\n", id, idx);
  	return NULL;
  }
***************
*** 89,122 ****
  /* Store a bitmap in the cache */
  void
! cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap, uint32 stamp)
  {
  	HBITMAP old;
  
! 	if ((cache_id < NUM_ELEMENTS(g_bmpcache)) && (cache_idx < NUM_ELEMENTS(g_bmpcache[0])))
  	{
! 		old = g_bmpcache[cache_id][cache_idx].bitmap;
  		if (old != NULL)
- 		{
  			ui_destroy_bitmap(old);
! 		}
! 		else if (g_use_rdp5)
  		{
! 			if (++g_num_bitmaps_in_memory[cache_id] > BMPCACHE2_C2_CELLS)
! 				cache_remove_lru_bitmap(cache_id);
! 		}
  
! 		g_bmpcache[cache_id][cache_idx].bitmap = bitmap;
! 		g_bmpcache[cache_id][cache_idx].usage = stamp;
  	}
! 	else if ((cache_id < NUM_ELEMENTS(g_volatile_bc)) && (cache_idx == 0x7fff))
  	{
! 		old = g_volatile_bc[cache_id];
  		if (old != NULL)
  			ui_destroy_bitmap(old);
! 		g_volatile_bc[cache_id] = bitmap;
  	}
  	else
  	{
! 		error("put bitmap %d:%d\n", cache_id, cache_idx);
  	}
  }
--- 215,249 ----
  /* Store a bitmap in the cache */
  void
! cache_put_bitmap(uint8 id, uint16 idx, HBITMAP bitmap)
  {
  	HBITMAP old;
  
! 	if ((id < NUM_ELEMENTS(g_bmpcache)) && (idx < NUM_ELEMENTS(g_bmpcache[0])))
  	{
! 		old = g_bmpcache[id][idx].bitmap;
  		if (old != NULL)
  			ui_destroy_bitmap(old);
! 		g_bmpcache[id][idx].bitmap = bitmap;
! 
! 		if (IS_PERSISTENT(id))
  		{
! 			if (old == NULL)
! 				g_bmpcache[id][idx].previous = g_bmpcache[id][idx].next = NOT_SET;
  
! 			cache_bump_bitmap(id, idx, TO_TOP);
! 			if (g_bmpcache_count[id] > BMPCACHE2_C2_CELLS)
! 				cache_evict_bitmap(id);
! 		}
  	}
! 	else if ((id < NUM_ELEMENTS(g_volatile_bc)) && (idx == 0x7fff))
  	{
! 		old = g_volatile_bc[id];
  		if (old != NULL)
  			ui_destroy_bitmap(old);
! 		g_volatile_bc[id] = bitmap;
  	}
  	else
  	{
! 		error("put bitmap %d:%d\n", id, idx);
  	}
  }
***************
*** 126,135 ****
  cache_save_state(void)
  {
! 	uint32 id, idx;
  
  	for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++)
  		if (IS_PERSISTENT(id))
! 			for (idx = 0; idx < NUM_ELEMENTS(g_bmpcache[id]); idx++)
! 				pstcache_touch_bitmap(id, idx, g_bmpcache[id][idx].usage);
  }
  
--- 253,271 ----
  cache_save_state(void)
  {
! 	uint32 id = 0, t = 0;
! 	int idx;
  
  	for (id = 0; id < NUM_ELEMENTS(g_bmpcache); id++)
  		if (IS_PERSISTENT(id))
! 		{
! 			DEBUG_RDP5(("Saving cache state for bitmap cache %d...", id));
! 			idx = g_bmpcache_lru[id];
! 			while (idx >= 0)
! 			{
! 				pstcache_touch_bitmap(id, idx, ++t);
! 				idx = g_bmpcache[id][idx].next;
! 			}
! 			DEBUG_RDP5((" %d stamps written.\n", t));
! 		}
  }
  

Index: orders.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/orders.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** orders.c	6 Mar 2005 21:11:17 -0000	1.41
--- orders.c	8 Mar 2005 00:23:02 -0000	1.42
***************
*** 689,693 ****
  	bitmap = ui_create_bitmap(width, height, inverted);
  	xfree(inverted);
! 	cache_put_bitmap(cache_id, cache_idx, bitmap, 0);
  }
  
--- 689,693 ----
  	bitmap = ui_create_bitmap(width, height, inverted);
  	xfree(inverted);
! 	cache_put_bitmap(cache_id, cache_idx, bitmap);
  }
  
***************
*** 738,742 ****
  	{
  		bitmap = ui_create_bitmap(width, height, bmpdata);
! 		cache_put_bitmap(cache_id, cache_idx, bitmap, 0);
  	}
  	else
--- 738,742 ----
  	{
  		bitmap = ui_create_bitmap(width, height, bmpdata);
! 		cache_put_bitmap(cache_id, cache_idx, bitmap);
  	}
  	else
***************
*** 815,822 ****
  	if (bitmap)
  	{
! 		cache_put_bitmap(cache_id, cache_idx, bitmap, 0);
  		if (flags & PERSIST)
! 			pstcache_put_bitmap(cache_id, cache_idx, bitmap_id, width, height,
! 					    width * height * Bpp, bmpdata);
  	}
  	else
--- 815,822 ----
  	if (bitmap)
  	{
! 		cache_put_bitmap(cache_id, cache_idx, bitmap);
  		if (flags & PERSIST)
! 			pstcache_save_bitmap(cache_id, cache_idx, bitmap_id, width, height,
! 					     width * height * Bpp, bmpdata);
  	}
  	else

Index: proto.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/proto.h,v
retrieving revision 1.69
retrieving revision 1.70
diff -C2 -d -r1.69 -r1.70
*** proto.h	3 Nov 2004 13:56:44 -0000	1.69
--- proto.h	8 Mar 2005 00:23:02 -0000	1.70
***************
*** 2,7 ****
  BOOL bitmap_decompress(uint8 * output, int width, int height, uint8 * input, int size, int Bpp);
  /* cache.c */
  HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx);
! void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap, uint32 stamp);
  void cache_save_state(void);
  FONTGLYPH *cache_get_font(uint8 font, uint16 character);
--- 2,8 ----
  BOOL bitmap_decompress(uint8 * output, int width, int height, uint8 * input, int size, int Bpp);
  /* cache.c */
+ void cache_rebuild_bmpcache_linked_list(uint8 cache_id, sint16 * cache_idx, int count);
  HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx);
! void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap);
  void cache_save_state(void);
  FONTGLYPH *cache_get_font(uint8 font, uint16 character);
***************
*** 67,73 ****
  void pstcache_touch_bitmap(uint8 id, uint16 idx, uint32 stamp);
  BOOL pstcache_load_bitmap(uint8 id, uint16 idx);
! BOOL pstcache_put_bitmap(uint8 id, uint16 idx, uint8 * bmp_id, uint16 wd,
! 			 uint16 ht, uint16 len, uint8 * data);
! int pstcache_enumerate(uint8 id, uint8 * list);
  BOOL pstcache_init(uint8 id);
  /* rdesktop.c */
--- 68,74 ----
  void pstcache_touch_bitmap(uint8 id, uint16 idx, uint32 stamp);
  BOOL pstcache_load_bitmap(uint8 id, uint16 idx);
! BOOL pstcache_save_bitmap(uint8 id, uint16 idx, uint8 * hash_key, uint16 wd,
! 			  uint16 ht, uint16 len, uint8 * data);
! int pstcache_enumerate(uint8 id, HASH_KEY * keylist);
  BOOL pstcache_init(uint8 id);
  /* rdesktop.c */

Index: pstcache.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/pstcache.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pstcache.c	25 Dec 2004 13:37:08 -0000	1.3
--- pstcache.c	8 Mar 2005 00:23:02 -0000	1.4
***************
*** 2,6 ****
     rdesktop: A Remote Desktop Protocol client.
     Persistent Bitmap Cache routines
!    Copyright (C) Jeroen Meijer 2004
  
     This program is free software; you can redistribute it and/or modify
--- 2,6 ----
     rdesktop: A Remote Desktop Protocol client.
     Persistent Bitmap Cache routines
!    Copyright (C) Jeroen Meijer 2004-2005
  
     This program is free software; you can redistribute it and/or modify
***************
*** 26,30 ****
  
  extern int g_server_bpp;
- extern uint32 g_stamp;
  extern BOOL g_bitmap_cache;
  extern BOOL g_bitmap_cache_persist_enable;
--- 26,29 ----
***************
*** 34,41 ****
  int g_pstcache_Bpp;
  BOOL g_pstcache_enumerated = False;
! uint8 zero_id[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  
  
! /* Update usage info for a bitmap */
  void
  pstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)
--- 33,40 ----
  int g_pstcache_Bpp;
  BOOL g_pstcache_enumerated = False;
! uint8 zero_key[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  
  
! /* Update mru stamp/index for a bitmap */
  void
  pstcache_touch_bitmap(uint8 cache_id, uint16 cache_idx, uint32 stamp)
***************
*** 72,79 ****
  	rd_read_file(fd, celldata, cellhdr.length);
  
- 	DEBUG(("Loading bitmap from disk (%d:%d)\n", cache_id, cache_idx));
- 
  	bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);
! 	cache_put_bitmap(cache_id, cache_idx, bitmap, cellhdr.stamp);
  
  	xfree(celldata);
--- 71,77 ----
  	rd_read_file(fd, celldata, cellhdr.length);
  
  	bitmap = ui_create_bitmap(cellhdr.width, cellhdr.height, celldata);
! 	DEBUG(("Load bitmap from disk: id=%d, idx=%d, bmp=0x%x)\n", cache_id, cache_idx, bitmap));
! 	cache_put_bitmap(cache_id, cache_idx, bitmap);
  
  	xfree(celldata);
***************
*** 83,88 ****
  /* Store a bitmap in the persistent cache */
  BOOL
! pstcache_put_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * bitmap_id,
! 		    uint16 width, uint16 height, uint16 length, uint8 * data)
  {
  	int fd;
--- 81,86 ----
  /* Store a bitmap in the persistent cache */
  BOOL
! pstcache_save_bitmap(uint8 cache_id, uint16 cache_idx, uint8 * key,
! 		     uint16 width, uint16 height, uint16 length, uint8 * data)
  {
  	int fd;
***************
*** 92,96 ****
  		return False;
  
! 	memcpy(cellhdr.bitmap_id, bitmap_id, sizeof(BITMAP_ID));
  	cellhdr.width = width;
  	cellhdr.height = height;
--- 90,94 ----
  		return False;
  
! 	memcpy(cellhdr.key, key, sizeof(HASH_KEY));
  	cellhdr.width = width;
  	cellhdr.height = height;
***************
*** 106,117 ****
  }
  
! /* list the bitmaps from the persistent cache file */
  int
! pstcache_enumerate(uint8 cache_id, uint8 * idlist)
  {
! 	int fd, n, c = 0;
  	CELLHEADER cellhdr;
  
! 	if (!(g_bitmap_cache && g_bitmap_cache_persist_enable && IS_PERSISTENT(cache_id)))
  		return 0;
  
--- 104,117 ----
  }
  
! /* List the bitmap keys from the persistent cache file */
  int
! pstcache_enumerate(uint8 id, HASH_KEY * keylist)
  {
! 	int fd, idx, n;
! 	sint16 mru_idx[0xa00];
! 	uint32 mru_stamp[0xa00];
  	CELLHEADER cellhdr;
  
! 	if (!(g_bitmap_cache && g_bitmap_cache_persist_enable && IS_PERSISTENT(id)))
  		return 0;
  
***************
*** 120,148 ****
  		return 0;
  
! 	DEBUG(("pstcache enumeration... "));
! 	for (n = 0; n < BMPCACHE2_NUM_PSTCELLS; n++)
  	{
! 		fd = g_pstcache_fd[cache_id];
! 		rd_lseek_file(fd, n * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
  		if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)
  			break;
  
! 		if (memcmp(cellhdr.bitmap_id, zero_id, sizeof(BITMAP_ID)) != 0)
  		{
! 			memcpy(idlist + n * sizeof(BITMAP_ID), cellhdr.bitmap_id,
! 			       sizeof(BITMAP_ID));
  
! 			if (cellhdr.stamp)
! 			{
! 				/* Pre-caching is not possible with 8bpp because a colourmap
! 				 * is needed to load them */
! 				if (g_bitmap_cache_precache && (g_server_bpp > 8))
! 				{
! 					if (pstcache_load_bitmap(cache_id, n))
! 						c++;
! 				}
  
! 				g_stamp = MAX(g_stamp, cellhdr.stamp);
  			}
  		}
  		else
--- 120,148 ----
  		return 0;
  
! 	DEBUG_RDP5(("Persistent bitmap cache enumeration... "));
! 	for (idx = 0; idx < BMPCACHE2_NUM_PSTCELLS; idx++)
  	{
! 		fd = g_pstcache_fd[id];
! 		rd_lseek_file(fd, idx * (g_pstcache_Bpp * MAX_CELL_SIZE + sizeof(CELLHEADER)));
  		if (rd_read_file(fd, &cellhdr, sizeof(CELLHEADER)) <= 0)
  			break;
  
! 		if (memcmp(cellhdr.key, zero_key, sizeof(HASH_KEY)) != 0)
  		{
! 			memcpy(keylist[idx], cellhdr.key, sizeof(HASH_KEY));
  
! 			/* Pre-cache (not possible for 8bpp because 8bpp needs a colourmap) */
! 			if (g_bitmap_cache_precache && cellhdr.stamp && g_server_bpp > 8)
! 				pstcache_load_bitmap(id, idx);
  
! 			/* Sort by stamp */
! 			for (n = idx; n > 0 && cellhdr.stamp < mru_stamp[n - 1]; n--)
! 			{
! 				mru_idx[n] = mru_idx[n - 1];
! 				mru_stamp[n] = mru_stamp[n - 1];
  			}
+ 
+ 			mru_idx[n] = idx;
+ 			mru_stamp[n] = cellhdr.stamp;
  		}
  		else
***************
*** 152,158 ****
  	}
  
! 	DEBUG(("%d bitmaps in persistent cache, %d bitmaps loaded in memory\n", n, c));
  	g_pstcache_enumerated = True;
! 	return n;
  }
  
--- 152,160 ----
  	}
  
! 	DEBUG_RDP5(("%d cached bitmaps.\n", idx));
! 
! 	cache_rebuild_bmpcache_linked_list(id, mru_idx, idx);
  	g_pstcache_enumerated = True;
! 	return idx;
  }
  

Index: rdp.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdp.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -C2 -d -r1.73 -r1.74
*** rdp.c	6 Mar 2005 21:11:17 -0000	1.73
--- rdp.c	8 Mar 2005 00:23:02 -0000	1.74
***************
*** 387,406 ****
  {
  	STREAM s;
! 	uint8 idlist[BMPCACHE2_NUM_PSTCELLS * sizeof(BITMAP_ID)];
! 	uint32 nids, offset, count, flags;
  
  	offset = 0;
! 	nids = pstcache_enumerate(2, idlist);
  
! 	while (offset < nids)
  	{
! 		count = MIN(nids - offset, 169);
  
! 		s = rdp_init_data(24 + count * sizeof(BITMAP_ID));
  
  		flags = 0;
  		if (offset == 0)
  			flags |= PDU_FLAG_FIRST;
! 		if (nids - offset <= 169)
  			flags |= PDU_FLAG_LAST;
  
--- 387,406 ----
  {
  	STREAM s;
! 	HASH_KEY keylist[BMPCACHE2_NUM_PSTCELLS];
! 	uint32 num_keys, offset, count, flags;
  
  	offset = 0;
! 	num_keys = pstcache_enumerate(2, keylist);
  
! 	while (offset < num_keys)
  	{
! 		count = MIN(num_keys - offset, 169);
  
! 		s = rdp_init_data(24 + count * sizeof(HASH_KEY));
  
  		flags = 0;
  		if (offset == 0)
  			flags |= PDU_FLAG_FIRST;
! 		if (num_keys - offset <= 169)
  			flags |= PDU_FLAG_LAST;
  
***************
*** 412,421 ****
  		out_uint16_le(s, 0);
  		out_uint16_le(s, 0);
! 		out_uint16_le(s, nids);
  		out_uint32_le(s, 0);
  		out_uint32_le(s, flags);
  
  		/* list */
! 		out_uint8a(s, idlist + offset * sizeof(BITMAP_ID), count * sizeof(BITMAP_ID));
  
  		s_mark_end(s);
--- 412,421 ----
  		out_uint16_le(s, 0);
  		out_uint16_le(s, 0);
! 		out_uint16_le(s, num_keys);
  		out_uint32_le(s, 0);
  		out_uint32_le(s, flags);
  
  		/* list */
! 		out_uint8a(s, keylist[offset], count * sizeof(HASH_KEY));
  
  		s_mark_end(s);

Index: types.h
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/types.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** types.h	6 Mar 2005 21:11:17 -0000	1.23
--- types.h	8 Mar 2005 00:23:02 -0000	1.24
***************
*** 120,139 ****
  VCHANNEL;
  
- typedef struct _BMPCACHEENTRY
- {
- 	HBITMAP bitmap;
- 	uint32 usage;
- 
- }
- BMPCACHEENTRY;
- 
  /* PSTCACHE */
! 
! typedef uint8 BITMAP_ID[8];
  
  /* Header for an entry in the persistent bitmap cache file */
  typedef struct _PSTCACHE_CELLHEADER
  {
! 	BITMAP_ID bitmap_id;
  	uint8 width, height;
  	uint16 length;
--- 120,130 ----
  VCHANNEL;
  
  /* PSTCACHE */
! typedef uint8 HASH_KEY[8];
  
  /* Header for an entry in the persistent bitmap cache file */
  typedef struct _PSTCACHE_CELLHEADER
  {
! 	HASH_KEY key;
  	uint8 width, height;
  	uint16 length;



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.