/* returns cache id */ int APP_CC xrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap, int hints) { int index; int jndex; int cache_id; int cache_idx; int bmp_size; int e; int Bpp; int crc16; int iig; int found; int cache_entries; int lru_index; struct list16 *ll; struct xrdp_bitmap *lbm; struct xrdp_lru_item *llru; LLOGLN(10, ("xrdp_cache_add_bitmap:")); LLOGLN(10, ("xrdp_cache_add_bitmap: crc16 0x%4.4x", bitmap->crc16)); e = (4 - (bitmap->width % 4)) & 3; found = 0; cache_id = 0; cache_entries = 0; /* client Bpp, bmp_size */ Bpp = (bitmap->bpp + 7) / 8; bmp_size = (bitmap->width + e) * bitmap->height * Bpp; self->bitmap_stamp++; if (bmp_size <= self->cache1_size) { cache_id = 0; cache_entries = self->cache1_entries; } else if (bmp_size <= self->cache2_size) { cache_id = 1; cache_entries = self->cache2_entries; } else if (bmp_size <= self->cache3_size) { cache_id = 2; cache_entries = self->cache3_entries; } else { log_message(LOG_LEVEL_ERROR, "error in xrdp_cache_add_bitmap, " "too big(%d) bpp %d", bmp_size, bitmap->bpp); return 0; } crc16 = bitmap->crc16; ll = &(self->crc16[cache_id][crc16]); for (jndex = 0; jndex < ll->count; jndex++) { cache_idx = list16_get_item(ll, jndex); if (COMPARE_WITH_CRC32 (self->bitmap_items[cache_id][cache_idx].bitmap, bitmap)) { LLOGLN(10, ("found bitmap at %d %d", index, jndex)); found = 1; break; } } if (found) { lru_index = self->bitmap_items[cache_id][cache_idx].lru_index; self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp; xrdp_bitmap_delete(bitmap); /* update lru to end */ xrdp_cache_update_lru(self, cache_id, lru_index); return MAKELONG(cache_idx, cache_id); } /* find lru */ /* check for reset */ if (self->lru_reset[cache_id]) { self->lru_reset[cache_id] = 0; LLOGLN(0, ("xrdp_cache_add_bitmap: reset detected cache_id %d", cache_id)); self->lru_tail[cache_id] = cache_entries - 1; index = self->lru_tail[cache_id]; llru = &(self->bitmap_lrus[cache_id][index]); llru->next = -1; } /* lru is item at head */ lru_index = self->lru_head[cache_id]; cache_idx = lru_index; /* update lru to end */ xrdp_cache_update_lru(self, cache_id, lru_index); LLOGLN(10, ("xrdp_cache_add_bitmap: oldest %d %d", cache_id, cache_idx)); LLOGLN(10, ("adding bitmap at %d %d old ptr %p new ptr %p", cache_id, cache_idx, self->bitmap_items[cache_id][cache_idx].bitmap, bitmap)); /* remove old, about to be deleted, from crc16 list */ lbm = self->bitmap_items[cache_id][cache_idx].bitmap; if (lbm != 0) { crc16 = lbm->crc16; ll = &(self->crc16[cache_id][crc16]); iig = list16_index_of(ll, cache_idx); if (iig == -1) { LLOGLN(0, ("xrdp_cache_add_bitmap: error removing cache_idx")); } LLOGLN(10, ("xrdp_cache_add_bitmap: removing index %d from crc16 %d", iig, crc16)); list16_remove_item(ll, iig); xrdp_bitmap_delete(lbm); } /* set, send bitmap and return */ self->bitmap_items[cache_id][cache_idx].bitmap = bitmap; self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp; self->bitmap_items[cache_id][cache_idx].lru_index = lru_index; /* add to crc16 list */ crc16 = bitmap->crc16; ll = &(self->crc16[cache_id][crc16]); list16_add_item(ll, cache_idx); if (ll->count > 1) { LLOGLN(10, ("xrdp_cache_add_bitmap: count %d", ll->count)); } if (self->use_bitmap_comp) { if (self->bitmap_cache_version & 4) { if (libxrdp_orders_send_bitmap3(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx, hints) == 0) { return MAKELONG(cache_idx, cache_id); } } if (self->bitmap_cache_version & 2) { libxrdp_orders_send_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx, hints); } else if (self->bitmap_cache_version & 1) { libxrdp_orders_send_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } else { if (self->bitmap_cache_version & 2) { libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } else if (self->bitmap_cache_version & 1) { libxrdp_orders_send_raw_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } return MAKELONG(cache_idx, cache_id); }
/* returns cache id */ int APP_CC xrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap, int hints) { int i = 0; int j = 0; int oldest = 0; int cache_id = 0; int cache_idx = 0; int bmp_size = 0; int e = 0; int Bpp = 0; e = bitmap->width % 4; if (e != 0) { e = 4 - e; } Bpp = (bitmap->bpp + 7) / 8; bmp_size = (bitmap->width + e) * bitmap->height * Bpp; self->bitmap_stamp++; /* look for match */ if (bmp_size <= self->cache1_size) { i = 0; for (j = 0; j < self->cache1_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; LLOGLN(10, ("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else if (bmp_size <= self->cache2_size) { i = 1; for (j = 0; j < self->cache2_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; LLOGLN(10, ("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else if (bmp_size <= self->cache3_size) { i = 2; for (j = 0; j < self->cache3_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; LLOGLN(10, ("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else { log_message(LOG_LEVEL_ERROR,"error in xrdp_cache_add_bitmap, too big(%d) bpp %d", bmp_size, bitmap->bpp); } /* look for oldest */ cache_id = 0; cache_idx = 0; oldest = 0x7fffffff; if (bmp_size <= self->cache1_size) { i = 0; for (j = 0; j < self->cache1_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } else if (bmp_size <= self->cache2_size) { i = 1; for (j = 0; j < self->cache2_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } else if (bmp_size <= self->cache3_size) { i = 2; for (j = 0; j < self->cache3_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } LLOGLN(10, ("adding bitmap at %d %d ptr %p", cache_id, cache_idx, self->bitmap_items[cache_id][cache_idx].bitmap)); /* set, send bitmap and return */ xrdp_bitmap_delete(self->bitmap_items[cache_id][cache_idx].bitmap); self->bitmap_items[cache_id][cache_idx].bitmap = bitmap; self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp; if (self->use_bitmap_comp) { if (self->bitmap_cache_version & 4) { if (libxrdp_orders_send_bitmap3(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx, hints) == 0) { return MAKELONG(cache_idx, cache_id); } } if (self->bitmap_cache_version & 2) { libxrdp_orders_send_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx, hints); } else if (self->bitmap_cache_version & 1) { libxrdp_orders_send_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } else { if (self->bitmap_cache_version & 2) { libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } else if (self->bitmap_cache_version & 1) { libxrdp_orders_send_raw_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } return MAKELONG(cache_idx, cache_id); }
/* returns cache id */ int APP_CC xrdp_cache_add_bitmap(struct xrdp_cache* self, struct xrdp_bitmap* bitmap) { int i; int j; int oldest; int cache_id; int cache_idx; int bmp_size; int e; int Bpp; e = bitmap->width % 4; if (e != 0) { e = 4 - e; } Bpp = (bitmap->bpp + 7) / 8; bmp_size = (bitmap->width + e) * bitmap->height * Bpp; self->bitmap_stamp++; /* look for match */ if (bmp_size <= self->cache1_size) { i = 0; for (j = 0; j < self->cache1_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; DEBUG(("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else if (bmp_size <= self->cache2_size) { i = 1; for (j = 0; j < self->cache2_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; DEBUG(("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else if (bmp_size <= self->cache3_size) { i = 2; for (j = 0; j < self->cache3_entries; j++) { #ifdef USE_CRC if (xrdp_bitmap_compare_with_crc(self->bitmap_items[i][j].bitmap, bitmap)) #else if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap)) #endif { self->bitmap_items[i][j].stamp = self->bitmap_stamp; DEBUG(("found bitmap at %d %d", i, j)); xrdp_bitmap_delete(bitmap); return MAKELONG(j, i); } } } else { g_writeln("error in xrdp_cache_add_bitmap, too big(%d)", bmp_size); } /* look for oldest */ cache_id = 0; cache_idx = 0; oldest = 0x7fffffff; if (bmp_size <= self->cache1_size) { i = 0; for (j = 0; j < self->cache1_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } else if (bmp_size <= self->cache2_size) { i = 1; for (j = 0; j < self->cache2_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } else if (bmp_size <= self->cache3_size) { i = 2; for (j = 0; j < self->cache3_entries; j++) { if (self->bitmap_items[i][j].stamp < oldest) { oldest = self->bitmap_items[i][j].stamp; cache_id = i; cache_idx = j; } } } DEBUG(("adding bitmap at %d %d", cache_id, cache_idx)); /* set, send bitmap and return */ xrdp_bitmap_delete(self->bitmap_items[cache_id][cache_idx].bitmap); self->bitmap_items[cache_id][cache_idx].bitmap = bitmap; self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp; if (self->bitmap_cache_version == 0) /* orginal version */ { if (self->use_bitmap_comp) { libxrdp_orders_send_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } else { libxrdp_orders_send_raw_bitmap(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } else { if (self->use_bitmap_comp) { libxrdp_orders_send_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } else { libxrdp_orders_send_raw_bitmap2(self->session, bitmap->width, bitmap->height, bitmap->bpp, bitmap->data, cache_id, cache_idx); } } return MAKELONG(cache_idx, cache_id); }