Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cache.cpp

Go to the documentation of this file.
00001 /*
00002    rdesktop: A Remote Desktop Protocol client.
00003    Cache routines
00004    Copyright (C) Matthew Chapman 1999-2002
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "rdesktop.h"
00022 
00023 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
00024 
00025 
00026 /* BITMAP CACHE */
00027 static HBITMAP bmpcache[3][600];
00028 
00029 /* Retrieve a bitmap from the cache */
00030 HBITMAP
00031 cache_get_bitmap(uint8 cache_id, uint16 cache_idx)
00032 {
00033         HBITMAP bitmap;
00034 
00035         if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
00036         {
00037                 bitmap = bmpcache[cache_id][cache_idx];
00038                 if (bitmap != NULL)
00039                         return bitmap;
00040         }
00041 
00042         error("get bitmap %d:%d\n", cache_id, cache_idx);
00043         return NULL;
00044 }
00045 
00046 /* Store a bitmap in the cache */
00047 void
00048 cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap)
00049 {
00050         HBITMAP old;
00051 
00052         if ((cache_id < NUM_ELEMENTS(bmpcache)) && (cache_idx < NUM_ELEMENTS(bmpcache[0])))
00053         {
00054                 old = bmpcache[cache_id][cache_idx];
00055                 if (old != NULL)
00056                         ui_destroy_bitmap(old);
00057 
00058                 bmpcache[cache_id][cache_idx] = bitmap;
00059         }
00060         else
00061         {
00062                 error("put bitmap %d:%d\n", cache_id, cache_idx);
00063         }
00064 }
00065 
00066 
00067 /* FONT CACHE */
00068 static FONTGLYPH fontcache[12][256];
00069 
00070 /* Retrieve a glyph from the font cache */
00071 FONTGLYPH *
00072 cache_get_font(uint8 font, uint16 character)
00073 {
00074         FONTGLYPH *glyph;
00075 
00076         if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
00077         {
00078                 glyph = &fontcache[font][character];
00079                 if (glyph->pixmap != NULL)
00080                         return glyph;
00081         }
00082 
00083         error("get font %d:%d\n", font, character);
00084         return NULL;
00085 }
00086 
00087 /* Store a glyph in the font cache */
00088 void
00089 cache_put_font(uint8 font, uint16 character, uint16 offset,
00090                uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap)
00091 {
00092         FONTGLYPH *glyph;
00093 
00094         if ((font < NUM_ELEMENTS(fontcache)) && (character < NUM_ELEMENTS(fontcache[0])))
00095         {
00096                 glyph = &fontcache[font][character];
00097                 if (glyph->pixmap != NULL)
00098                         ui_destroy_glyph(glyph->pixmap);
00099 
00100                 glyph->offset = offset;
00101                 glyph->baseline = baseline;
00102                 glyph->width = width;
00103                 glyph->height = height;
00104                 glyph->pixmap = pixmap;
00105         }
00106         else
00107         {
00108                 error("put font %d:%d\n", font, character);
00109         }
00110 }
00111 
00112 
00113 /* TEXT CACHE */
00114 static DATABLOB textcache[256];
00115 
00116 /* Retrieve a text item from the cache */
00117 DATABLOB *
00118 cache_get_text(uint8 cache_id)
00119 {
00120         DATABLOB *text;
00121 
00122         if (cache_id < NUM_ELEMENTS(textcache))
00123         {
00124                 text = &textcache[cache_id];
00125                 if (text->data != NULL)
00126                         return text;
00127         }
00128 
00129         error("get text %d\n", cache_id);
00130         return NULL;
00131 }
00132 
00133 /* Store a text item in the cache */
00134 void
00135 cache_put_text(uint8 cache_id, void *data, int length)
00136 {
00137         DATABLOB *text;
00138 
00139         if (cache_id < NUM_ELEMENTS(textcache))
00140         {
00141                 text = &textcache[cache_id];
00142                 if (text->data != NULL)
00143                         xfree(text->data);
00144 
00145                 text->data = xmalloc(length);
00146                 text->size = length;
00147                 memcpy(text->data, data, length);
00148         }
00149         else
00150         {
00151                 error("put text %d\n", cache_id);
00152         }
00153 }
00154 
00155 
00156 /* DESKTOP CACHE */
00157 static uint8 deskcache[0x38400];
00158 
00159 /* Retrieve desktop data from the cache */
00160 uint8 *
00161 cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel)
00162 {
00163         int length = cx * cy * bytes_per_pixel;
00164 
00165         if ((offset + length) <= sizeof(deskcache))
00166         {
00167                 return &deskcache[offset];
00168         }
00169 
00170         error("get desktop %d:%d\n", offset, length);
00171         return NULL;
00172 }
00173 
00174 /* Store desktop data in the cache */
00175 void
00176 cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 * data)
00177 {
00178         int length = cx * cy * bytes_per_pixel;
00179 
00180         if ((offset + length) <= sizeof(deskcache))
00181         {
00182                 cx *= bytes_per_pixel;
00183                 while (cy--)
00184                 {
00185                         memcpy(&deskcache[offset], data, cx);
00186                         data += scanline;
00187                         offset += cx;
00188                 }
00189         }
00190         else
00191         {
00192                 error("put desktop %d:%d\n", offset, length);
00193         }
00194 }
00195 
00196 
00197 /* CURSOR CACHE */
00198 static HCURSOR cursorcache[0x20];
00199 
00200 /* Retrieve cursor from cache */
00201 HCURSOR
00202 cache_get_cursor(uint16 cache_idx)
00203 {
00204         HCURSOR cursor;
00205 
00206         if (cache_idx < NUM_ELEMENTS(cursorcache))
00207         {
00208                 cursor = cursorcache[cache_idx];
00209                 if (cursor != NULL)
00210                         return cursor;
00211         }
00212 
00213         error("get cursor %d\n", cache_idx);
00214         return NULL;
00215 }
00216 
00217 /* Store cursor in cache */
00218 void
00219 cache_put_cursor(uint16 cache_idx, HCURSOR cursor)
00220 {
00221         HCURSOR old;
00222 
00223         if (cache_idx < NUM_ELEMENTS(cursorcache))
00224         {
00225                 old = cursorcache[cache_idx];
00226                 if (old != NULL)
00227                         ui_destroy_cursor(old);
00228 
00229                 cursorcache[cache_idx] = cursor;
00230         }
00231         else
00232         {
00233                 error("put cursor %d\n", cache_idx);
00234         }
00235 }

Generated on Sat Nov 5 16:17:41 2005 for OPIE by  doxygen 1.4.2