Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2289 lines
89 KiB

  1. /****************************************************************************/
  2. // uh.h
  3. //
  4. // Update Handler Class
  5. //
  6. // Copyright (C) 1997-1999 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef _H_UH_
  9. #define _H_UH_
  10. extern "C" {
  11. #include <adcgdata.h>
  12. }
  13. #include "fs.h"
  14. #include "op.h"
  15. #include "or.h"
  16. #include "gh.h"
  17. #include "ih.h"
  18. #include "objs.h"
  19. #include "cd.h"
  20. #ifdef OS_WINCE
  21. #include <ceconfig.h>
  22. #endif
  23. #include "tscerrs.h"
  24. //USE Mem mapped file for bitmap cache
  25. //#define VM_BMPCACHE 1
  26. class CSL;
  27. class COD;
  28. class CUI;
  29. class CCC;
  30. #define TRC_GROUP TRC_GROUP_CORE
  31. #define TRC_FILE "uh"
  32. #define TSC_HR_FILEID TSC_HR_UH_H
  33. typedef struct tagUH_ORDER
  34. {
  35. RECT dstRect;
  36. BYTE orderData[1];
  37. } UH_ORDER, FAR *PUH_ORDER;
  38. typedef UH_ORDER UNALIGNED FAR *PUH_ORDER_UA;
  39. #define UH_ORDER_HEADER_SIZE (FIELDOFFSET(UH_ORDER, orderData))
  40. extern const UINT16 uhWindowsROPs[256];
  41. /****************************************************************************/
  42. /* Number of glyph caches. */
  43. /****************************************************************************/
  44. #define UH_GLC_NUM_CACHES 10
  45. /****************************************************************************/
  46. /* Number of entries in the color table cache. */
  47. /****************************************************************************/
  48. #define UH_COLOR_TABLE_CACHE_ENTRIES 6
  49. /****************************************************************************/
  50. /* Save Bitmap constants */
  51. /****************************************************************************/
  52. #define UH_SAVE_BITMAP_WIDTH 480
  53. #define UH_SAVE_BITMAP_HEIGHT 480
  54. #define UH_SAVE_BITMAP_SIZE ((DCUINT32)UH_SAVE_BITMAP_WIDTH * \
  55. (DCUINT32)UH_SAVE_BITMAP_HEIGHT)
  56. #define UH_SAVE_BITMAP_X_GRANULARITY 1
  57. #define UH_SAVE_BITMAP_Y_GRANULARITY 20
  58. // Cache IDs have a protocol-implicit cell size, starting from 256 and
  59. // increasing in factors of 4. Scale by the bit depth.
  60. #ifdef DC_HICOLOR
  61. #define UH_CellSizeFromCacheID(_id) \
  62. ((TS_BITMAPCACHE_0_CELL_SIZE << (2 * (_id))) * _UH.copyMultiplier)
  63. #define UH_CellSizeFromCacheIDAndMult(_id,mult) \
  64. ((TS_BITMAPCACHE_0_CELL_SIZE << (2 * (_id))) * mult)
  65. #define UH_PropVirtualCacheSizeFromMult(mult) \
  66. (_UH.PropBitmapVirtualCacheSize[mult-1])
  67. #else
  68. #define UH_CellSizeFromCacheID(_id) \
  69. (TS_BITMAPCACHE_0_CELL_SIZE << (2 * (_id)))
  70. #endif
  71. // Tile sizes are also protocol-implied and dependent on the cache ID,
  72. // starting at 16 per side and increasing in powers of two in each dimension.
  73. #define UH_CACHE_0_DIMENSION 16
  74. //
  75. // From wuhint.h
  76. //
  77. #define UH_NUM_8BPP_PAL_ENTRIES 256
  78. #define UH_LOGPALETTE_VERSION 0x300
  79. #define UH_LAST_PAL_ENTRY (UH_NUM_8BPP_PAL_ENTRIES-1)
  80. #define UH_NUM_SYSTEM_COLORS 20
  81. #define UH_COLOR_RGB 0
  82. #define UH_COLOR_PALETTE 1
  83. #define UH_RGB_BLACK RGB(0x00, 0x00, 0x00)
  84. #define UH_RGB_RED RGB(0xFF, 0x00, 0x00)
  85. #define UH_RGB_GREEN RGB(0x00, 0xFF, 0x00)
  86. #define UH_RGB_BLUE RGB(0x00, 0x00, 0xFF)
  87. #define UH_RGB_MAGENTA RGB(0xFF, 0x00, 0xFF)
  88. #define UH_RGB_CYAN RGB(0x00, 0xFF, 0xFF)
  89. #define UH_RGB_YELLOW RGB(0xFF, 0xFF, 0x00)
  90. #define UH_RGB_WHITE RGB(0xFF, 0xFF, 0xFF)
  91. #define UH_BRUSHTYPE_FDIAGONAL 1
  92. #define UH_BRUSHTYPE_DIAGCROSS 2
  93. #define UH_BRUSHTYPE_HORIZONTAL 3
  94. #define UH_BRUSHTYPE_VERTICAL 4
  95. #define WM_RECALC_CELL_SPACING (WM_APP + 100)
  96. /****************************************************************************/
  97. // Size of the decompression buffer used for decompressing screen data.
  98. // This is the maximum decompressed size the server will send.
  99. /****************************************************************************/
  100. #define UH_DECOMPRESSION_BUFFER_LENGTH 32000
  101. /****************************************************************************/
  102. // Min value configurable for the bitmap cache total size.
  103. /****************************************************************************/
  104. #define UH_BMC_LOW_THRESHOLD 150
  105. /****************************************************************************/
  106. /* Max and min values configurable for the glyph cache total size */
  107. /****************************************************************************/
  108. #define UH_GLC_LOW_THRESHOLD 50
  109. #define UH_GLC_HIGH_THRESHOLD 2000
  110. /****************************************************************************/
  111. /* Glyph cache constants. */
  112. /****************************************************************************/
  113. // Warning: data sizes must be a power of 2
  114. #define UH_GLC_CACHE_MAXIMUMCELLSIZE 2048
  115. #define UH_GLC_CACHE_MINIMUMCELLCOUNT 16
  116. #define UH_GLC_CACHE_MAXIMUMCELLCOUNT 254
  117. /****************************************************************************/
  118. /* Frag cache constants. */
  119. /****************************************************************************/
  120. // Warning: data sizes must be a power of 2
  121. #define UH_FGC_CACHE_MAXIMUMCELLSIZE 256
  122. #define UH_FGC_CACHE_MAXIMUMCELLCOUNT 256
  123. /****************************************************************************/
  124. // Offscreen cache constants
  125. /****************************************************************************/
  126. #define UH_OBC_LOW_CACHESIZE 512 // half MB
  127. #define UH_OBC_HIGH_CACHESIZE 7680 // 7.5 MB
  128. #define UH_OBC_LOW_CACHEENTRIES 50
  129. #define UH_OBC_HIGH_CACHEENTRIES 500
  130. #ifdef DRAW_GDIPLUS
  131. #define UH_GDIP_LOW_CACHEENTRIES 2
  132. #define UH_GDIP_HIGH_CACHEENTRIES 20
  133. #endif
  134. #ifdef DC_DEBUG
  135. /****************************************************************************/
  136. /* Bitmap Cache Monitor Window Class name. */
  137. /****************************************************************************/
  138. #define UH_BITMAP_CACHE_MONITOR_CLASS_NAME _T("BitmapCacheMonitorClass")
  139. #define UH_CACHE_WINDOW_BORDER_WIDTH 20
  140. #define UH_CACHE_BLOB_WIDTH 6
  141. #define UH_CACHE_BLOB_HEIGHT 6
  142. #define UH_CACHE_BLOB_SPACING 1
  143. #define UH_INTER_CACHE_SPACING 20
  144. #define UH_CACHE_TEXT_SPACING 5
  145. #define UH_CACHE_BLOB_TOTAL_WIDTH \
  146. (UH_CACHE_BLOB_WIDTH + UH_CACHE_BLOB_SPACING)
  147. #define UH_CACHE_BLOB_TOTAL_HEIGHT \
  148. (UH_CACHE_BLOB_HEIGHT + UH_CACHE_BLOB_SPACING)
  149. #define UH_CACHE_FLASH_PERIOD 1000
  150. #define UH_CACHE_DISPLAY_FONT_NAME _T("Comic Sans MS")
  151. #define UH_CACHE_DISPLAY_FONT_SIZE 16
  152. #define UH_CACHE_DISPLAY_FONT_WEIGHT FW_NORMAL
  153. #define UH_CACHE_MONITOR_UPDATE_PERIOD 200
  154. // Cache monitor entry states. Describes where the cache entry is.
  155. #define UH_CACHE_STATE_UNUSED 0
  156. #define UH_CACHE_STATE_IN_MEMORY 1
  157. #define UH_CACHE_STATE_ON_DISK 2
  158. #define UH_CACHE_NUM_STATES 3
  159. // Cache monitor flash transitions transitions. Describes the temporary state
  160. // of a displayed entry after an event has occurred. Each entry has an
  161. // associated timestamp that determines when the transition flash will end.
  162. // These should be ordered in importance, most important having higher numbers
  163. // -- the more important events supersede other events in use of the timer.
  164. #define UH_CACHE_TRANSITION_NONE 0
  165. #define UH_CACHE_TRANSITION_TOUCHED 1
  166. #define UH_CACHE_TRANSITION_EVICTED 2
  167. #define UH_CACHE_TRANSITION_LOADED_FROM_DISK 3
  168. #define UH_CACHE_TRANSITION_KEY_LOAD_ON_SESSION_START 4
  169. #define UH_CACHE_TRANSITION_SERVER_UPDATE 5
  170. #define UH_CACHE_NUM_TRANSITIONS 6
  171. #endif /* DC_DEBUG */
  172. typedef struct tagUHBITMAPINFOPALINDEX
  173. {
  174. // Set where the palette contains palette indices of 0..255.
  175. BOOL bIdentityPalette;
  176. // The following entries are used directly as a bitmap info header with
  177. // embedded palette when doing blts.
  178. BITMAPINFOHEADER hdr;
  179. UINT16 paletteIndexTable[256];
  180. } UHBITMAPINFOPALINDEX, FAR *PUHBITMAPINFOPALINDEX;
  181. typedef struct tagUHCACHEDCOLORTABLE
  182. {
  183. RGBTRIPLE rgb[256];
  184. } UHCACHEDCOLORTABLE, FAR *PUHCACHEDCOLORTABLE;
  185. /****************************************************************************/
  186. // Bitmap Cache Definitions
  187. /****************************************************************************/
  188. #define CACHE_DIRECTORY_NAME _T("cache\\")
  189. // This value should be 13 for 8.3 file name and \0, additional 2 is for legacy
  190. // purpose. Old cache structure contains cacheId\ as subcache directory name.
  191. // We can remove 2 if we don't need to support Win2000 Beta3.
  192. #define CACHE_FILENAME_LENGTH 15
  193. typedef struct tagUHBITMAPINFO
  194. {
  195. UINT32 Key1, Key2;
  196. UINT16 bitmapWidth;
  197. UINT16 bitmapHeight;
  198. UINT32 bitmapLength;
  199. } UHBITMAPINFO, FAR *PUHBITMAPINFO;
  200. // File Header for bitmap file used in persistent bitmap caching
  201. typedef struct tagUHBITMAPFILEHDR
  202. {
  203. UHBITMAPINFO bmpInfo;
  204. UINT32 bmpVersion : 3;
  205. UINT32 bCompressed : 1;
  206. UINT32 bNoBCHeader : 1; // add new flag to indicate if the compressed
  207. // bitmap data contains BC header or not
  208. UINT32 pad : 27;
  209. } UHBITMAPFILEHDR, FAR *PUHBITMAPFILEHDR;
  210. // Information maintained for each bitmap cache
  211. typedef struct tagUHBITMAPCACHEINFO
  212. {
  213. UINT32 NumVirtualEntries;
  214. UINT32 NumEntries : 31;
  215. UINT32 bSendBitmapKeys : 1;
  216. #ifdef DC_HICOLOR
  217. UINT32 OrigNumEntries;
  218. UINT32 MemLen;
  219. #endif
  220. } UHBITMAPCACHEINFO, FAR *PUHBITMAPCACHEINFO;
  221. #ifdef DC_DEBUG
  222. // Used to hold bitmap cache monitor information in debug builds.
  223. typedef struct {
  224. BYTE ColorTable;
  225. BYTE State : 2;
  226. BYTE FlashTransition : 6;
  227. unsigned UsageCount;
  228. UINT32 EventTime;
  229. } UH_CACHE_MONITOR_ENTRY_DATA;
  230. #endif
  231. // Bitmap cache entry definitions
  232. // The fields in UHBITMAPCACHEENTRYHDR are of explicit length deliberately
  233. // to ensure 16 and 32 bit client match and to help force the cache entry
  234. // header sizes to be powers of two.
  235. typedef struct tagUHBITMAPCACHEENTRYHDR
  236. {
  237. UINT16 bitmapWidth;
  238. UINT16 bitmapHeight;
  239. UINT32 bitmapLength : 31;
  240. UINT32 hasData : 1;
  241. } UHBITMAPCACHEENTRYHDR, FAR *PUHBITMAPCACHEENTRYHDR,
  242. DCHPTR HPUHBITMAPCACHEENTRYHDR;
  243. // bitmap cache file info
  244. typedef struct tagUHCACHEFILEINFO
  245. {
  246. HANDLE hCacheFile;
  247. #ifdef VM_BMPCACHE
  248. LPBYTE pMappedView;
  249. #endif
  250. } UHCACHEFILEINFO, FAR *PUHCACHEFILEINFO;
  251. // Doubly Linked List Node - Used to maintain MRU list
  252. typedef struct tagUHCHAIN
  253. {
  254. UINT32 next;
  255. UINT32 prev;
  256. } UHCHAIN, FAR *PUHCHAIN;
  257. typedef TS_BITMAPCACHE_PERSISTENT_LIST_ENTRY DCHPTR HPTS_BITMAPCACHE_PERSISTENT_LIST_ENTRY;
  258. // Bitmap Virtual Cache Page Table Entry
  259. // We need 3 pad here to make sure the struct size be power of two
  260. // This is required for huge memory allocation in Win16
  261. typedef struct tagUHBITMAPCACHEPTE
  262. {
  263. UHCHAIN mruList;
  264. UINT32 iEntryToMem;
  265. TS_BITMAPCACHE_PERSISTENT_LIST_ENTRY bmpInfo;
  266. } UHBITMAPCACHEPTE, FAR *PUHBITMAPCACHEPTE, DCHPTR HPUHBITMAPCACHEPTE;
  267. // Bitmap Virtual Cache Page Table
  268. typedef struct tagUHBITMAPCACHEPAGETABLE
  269. {
  270. UINT32 MRUHead;
  271. UINT32 MRUTail;
  272. UINT32 FreeMemList;
  273. UHCACHEFILEINFO CacheFileInfo;
  274. HPUHBITMAPCACHEPTE PageEntries;
  275. } UHBITMAPCACHEPAGETABLE, FAR *PUHBITMAPCACHEPAGETABLE;
  276. // Bitmap physical memory caches
  277. typedef struct tagUHBITMAPCACHE
  278. {
  279. UHBITMAPCACHEINFO BCInfo;
  280. HPUHBITMAPCACHEENTRYHDR Header;
  281. BYTE DCHPTR Entries;
  282. UHBITMAPCACHEPAGETABLE PageTable;
  283. } UHBITMAPCACHE;
  284. /****************************************************************************/
  285. /* Brush cache entry definitions */
  286. /****************************************************************************/
  287. typedef struct tagUHBRUSHCACHEHDR
  288. {
  289. BYTE iBitmapFormat;
  290. BYTE cx;
  291. BYTE cy;
  292. BYTE iBytes;
  293. } UHBRUSHCACHEHDR, FAR *PUHBRUSHCACHEHDR;
  294. #define UH_MAX_MONO_BRUSHES 64
  295. #define UH_MONO_BRUSH_SIZE 16
  296. #define UH_COLOR_BRUSH_SIZE 64
  297. #ifdef DC_HICOLOR
  298. #define UH_COLOR_BRUSH_SIZE_16 128
  299. #define UH_COLOR_BRUSH_SIZE_24 192
  300. #endif
  301. typedef struct tagUHMONOBRUSHCACHE
  302. {
  303. UHBRUSHCACHEHDR hdr;
  304. BYTE data[UH_MONO_BRUSH_SIZE];
  305. } UHMONOBRUSHCACHE, FAR *PUHMONOBRUSHCACHE;
  306. typedef struct tagUHCOLORBRUSHINFO
  307. {
  308. BITMAPINFO bmi;
  309. RGBQUAD rgbQuadTable[UH_NUM_8BPP_PAL_ENTRIES - 1];
  310. BYTE bytes[UH_COLOR_BRUSH_SIZE];
  311. HBRUSH hLastBrush;
  312. } UHCOLORBRUSHINFO, *PUHCOLORBRUSHINFO;
  313. #ifdef DC_HICOLOR
  314. // We only need enough color table entries for the red, green blue bit masks
  315. // used in 16bpp sessions.
  316. // Note that we make this big enough to use for 15/16 and 24bpp brushes
  317. typedef struct tagUHHICOLORBRUSHINFO
  318. {
  319. BITMAPINFOHEADER bmiHeader;
  320. RGBQUAD bmiColors[3];
  321. BYTE bytes[UH_COLOR_BRUSH_SIZE_24];
  322. HBRUSH hLastBrush;
  323. } UHHICOLORBRUSHINFO, FAR *PUHHICOLORBRUSHINFO;
  324. #endif
  325. #define UH_MAX_COLOR_BRUSHES 64
  326. #ifdef DC_HICOLOR // Need enough space for a 24bpp brush
  327. typedef struct tagUHCOLORBRUSHCACHE
  328. {
  329. UHBRUSHCACHEHDR hdr;
  330. BYTE data[UH_COLOR_BRUSH_SIZE_24];
  331. } UHCOLORBRUSHCACHE, FAR *PUHCOLORBRUSHCACHE;
  332. #else
  333. typedef struct tagUHCOLORBRUSHCACHE
  334. {
  335. UHBRUSHCACHEHDR hdr;
  336. BYTE data[UH_COLOR_BRUSH_SIZE];
  337. } UHCOLORBRUSHCACHE, FAR *PUHCOLORBRUSHCACHE;
  338. #endif
  339. /****************************************************************************/
  340. /* Glyph cache entry definitions */
  341. /****************************************************************************/
  342. typedef struct tagUHGLYPHCACHEENTRYHDR
  343. {
  344. INT32 x;
  345. INT32 y;
  346. UINT32 cx;
  347. UINT32 cy;
  348. UINT32 unicode;
  349. } UHGLYPHCACHEENTRYHDR, FAR *PUHGLYPHCACHEENTRYHDR,
  350. DCHPTR HPUHGLYPHCACHEENTRYHDR;
  351. typedef struct tagUHGLYPHCACHE
  352. {
  353. HPUHGLYPHCACHEENTRYHDR pHdr;
  354. UINT32 cbEntrySize;
  355. BYTE DCHPTR pData;
  356. UINT32 cbUseCount;
  357. } UHGLYPHCACHE, FAR *PUHGLYPHCACHE, DCHPTR HPUHGLYPHCACHE;
  358. /****************************************************************************/
  359. /* Frag cache entry definitions */
  360. /****************************************************************************/
  361. typedef struct tagUHFRAGCACHEENTRYHDR
  362. {
  363. UINT32 cbFrag;
  364. INT32 cacheId;
  365. } UHFRAGCACHEENTRYHDR, FAR *PUHFRAGCACHEENTRYHDR,
  366. DCHPTR HPUHFRAGCACHEENTRYHDR;
  367. typedef struct tagUHFRAGCACHE
  368. {
  369. HPUHFRAGCACHEENTRYHDR pHdr;
  370. UINT32 cbEntrySize;
  371. BYTE DCHPTR pData;
  372. } UHFRAGCACHE, FAR *PUHFRAGCACHE, DCHPTR HPUHFRAGCACHE;
  373. /****************************************************************************/
  374. // Offscreen bitmap cache
  375. /****************************************************************************/
  376. typedef struct tagUHOFFSCRBITMAPCACHE
  377. {
  378. HBITMAP offscrBitmap;
  379. UINT32 cx;
  380. UINT32 cy;
  381. } UHOFFSCRBITMAPCACHE, FAR *PUHOFFSCRBITMAPCACHE, DCHPTR HPUHOFFSCRBITMAPCACHE;
  382. #ifdef DRAW_NINEGRID
  383. /****************************************************************************/
  384. // DrawNineGrid bitmap cache
  385. /****************************************************************************/
  386. typedef struct tagUHDRAWNINEGRIDBITMAPCACHE
  387. {
  388. HBITMAP drawNineGridBitmap;
  389. UINT32 cx;
  390. UINT32 cy;
  391. UINT32 bitmapBpp;
  392. TS_NINEGRID_BITMAP_INFO dngInfo;
  393. } UHDRAWSTREAMBITMAPCACHE, FAR *PUHDRAWSTREAMBITMAPCACHE;
  394. #ifdef DRAW_GDIPLUS
  395. /****************************************************************************/
  396. // Gdiplus object cache
  397. /****************************************************************************/
  398. typedef struct tagUHGDIPLUSOBJECTCACHE
  399. {
  400. UINT32 CacheSize;
  401. BYTE * CacheData;
  402. } UHGDIPLUSOBJECTCACHE, FAR *PUHGDIPLUSOBJECTCACHE;
  403. typedef struct tagUHGDIPLUSIMAGECACHE
  404. {
  405. UINT32 CacheSize;
  406. UINT16 ChunkNum;
  407. INT16 *CacheDataIndex;
  408. } UHGDIPLUSIMAGECACHE, FAR *PUHGDIPLUSIMAGECACHE;
  409. #endif
  410. typedef BOOL (FNGDI_DRAWSTREAM)(HDC, ULONG, VOID*);
  411. #endif
  412. #define UHROUNDUP(val, granularity) \
  413. ((((val)+((granularity) - 1)) / (granularity)) * (granularity))
  414. #define UH_IS_SYSTEM_COLOR_INDEX(i) \
  415. ((i < (UH_NUM_SYSTEM_COLORS / 2)) || \
  416. (i > (UH_LAST_PAL_ENTRY - (UH_NUM_SYSTEM_COLORS / 2))))
  417. #define UH_TWEAK_COLOR_COMPONENT(colorComponent) \
  418. if ((colorComponent) == 0) \
  419. { \
  420. (colorComponent)++; \
  421. } \
  422. else \
  423. { \
  424. (colorComponent)--; \
  425. }
  426. #define TSRECT16_TO_RECTL(dst, src) \
  427. (dst).left = (src).left; \
  428. (dst).top = (src).top; \
  429. (dst).right = (src).right; \
  430. (dst).bottom = (src).bottom;
  431. #define TSPOINT16_TO_POINTL(dst, src) \
  432. (dst).x = (src).x; \
  433. (dst).y = (src).y;
  434. /****************************************************************************/
  435. // UH_DATA
  436. /****************************************************************************/
  437. typedef struct tagUH_DATA
  438. {
  439. #ifdef DC_LATENCY
  440. unsigned fakeKeypressCount;
  441. #endif /* DC_LATENCY */
  442. HBITMAP hShadowBitmap;
  443. HBITMAP hunusedBitmapForShadowDC;
  444. HBITMAP hSaveScreenBitmap;
  445. HBITMAP hunusedBitmapForSSBDC;
  446. HDC hdcShadowBitmap;
  447. HDC hdcOutputWindow;
  448. HDC hdcDraw;
  449. HDC hdcSaveScreenBitmap;
  450. HDC hdcBrushBitmap;
  451. BOOL usingDIBSection;
  452. BOOL shadowBitmapRequested;
  453. BOOL dedicatedTerminal;
  454. unsigned drawThreshold;
  455. UHBITMAPINFOPALINDEX bitmapInfo;
  456. #ifdef DC_HICOLOR
  457. unsigned DIBFormat;
  458. unsigned copyMultiplier;
  459. unsigned protocolBpp;
  460. unsigned bitmapBpp;
  461. unsigned shadowBitmapBpp;
  462. #endif
  463. BOOL shadowBitmapEnabled;
  464. #ifdef DISABLE_SHADOW_IN_FULLSCREEN
  465. BOOL DontUseShadowBitmap; // True: don't use shadow; False: use shadow
  466. #endif
  467. #ifdef OS_WINCE
  468. BOOL paletteIsFixed;
  469. #endif
  470. HPALETTE hpalDefault;
  471. HPALETTE hpalCurrent;
  472. HWND hwndOutputWindow;
  473. HRGN hrgnUpdate;
  474. HRGN hrgnUpdateRect;
  475. BOOL colorIndicesEnabled;
  476. #ifdef DC_DEBUG
  477. BOOL hatchBitmapPDUData;
  478. BOOL hatchIndexPDUData;
  479. BOOL hatchSSBOrderData;
  480. BOOL hatchMemBltOrderData;
  481. BOOL labelMemBltOrders;
  482. #endif /* DC_DEBUG */
  483. BYTE FAR *bitmapDecompressionBuffer;
  484. unsigned bitmapDecompressionBufferSize;
  485. /************************************************************************/
  486. /* last used resource variables */
  487. /************************************************************************/
  488. COLORREF lastBkColor;
  489. COLORREF lastTextColor;
  490. int lastBkMode;
  491. int lastROP2;
  492. HDC lastHDC;
  493. unsigned lastPenStyle;
  494. unsigned lastPenWidth;
  495. COLORREF lastPenColor;
  496. COLORREF lastForeColor;
  497. unsigned lastLogBrushStyle;
  498. unsigned lastLogBrushHatch;
  499. #if defined (OS_WINCE)
  500. COLORREF lastLogBrushColorRef;
  501. #else
  502. DCCOLOR lastLogBrushColor;
  503. #endif
  504. BYTE lastLogBrushExtra[7];
  505. #ifdef OS_WINCE
  506. HDC hdcMemCached;
  507. HBITMAP hBitmapCacheDIB;
  508. PBYTE hBitmapCacheDIBits;
  509. #endif
  510. COLORREF lastBrushBkColor;
  511. COLORREF lastBrushTextColor;
  512. unsigned lastFillMode;
  513. #ifdef DISABLE_SHADOW_IN_FULLSCREEN
  514. BOOL fIsBBarVisible; // TRUE: visible, FALSE: invisible
  515. RECT rectBBar;
  516. #endif
  517. /************************************************************************/
  518. /* The following variables which describe the current clip rectangle */
  519. /* are only valid if fRectReset is FALSE. If fRectReset is true then */
  520. /* no clipping is in force. */
  521. /************************************************************************/
  522. BOOL rectReset;
  523. int lastLeft;
  524. int lastTop;
  525. int lastRight;
  526. int lastBottom;
  527. #if defined (OS_WINCE)
  528. HDC validClipDC;
  529. HDC validBkColorDC;
  530. HDC validBkModeDC;
  531. HDC validROPDC;
  532. HDC validTextColorDC;
  533. HDC validPenDC;
  534. HDC validBrushDC;
  535. #endif
  536. /************************************************************************/
  537. /* Bitmaps */
  538. /************************************************************************/
  539. HBITMAP bmpPattern;
  540. HBITMAP bmpMonoPattern;
  541. HBITMAP bmpColorPattern;
  542. /************************************************************************/
  543. /* Memblt color table caches */
  544. /************************************************************************/
  545. PUHCACHEDCOLORTABLE pColorTableCache;
  546. PUHBITMAPINFOPALINDEX pMappedColorTableCache;
  547. int maxColorTableId;
  548. /************************************************************************/
  549. /* Glyph caches */
  550. /************************************************************************/
  551. UHGLYPHCACHE glyphCache[UH_GLC_NUM_CACHES];
  552. UHFRAGCACHE fragCache;
  553. unsigned cxGlyphBits;
  554. unsigned cyGlyphBits;
  555. HBITMAP hbmGlyph;
  556. HDC hdcGlyph;
  557. unsigned bmShadowWidth;
  558. unsigned bmShadowHeight;
  559. PBYTE bmShadowBits;
  560. /************************************************************************/
  561. // Bitmap cache entries.
  562. /************************************************************************/
  563. #if ((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  564. // Holds the persistent cache file name
  565. TCHAR PersistCacheFileName[MAX_PATH];
  566. UINT EndPersistCacheDir;
  567. // For locking bitmap cache directory on disk
  568. TCHAR PersistentLockName[MAX_PATH];
  569. HANDLE hPersistentCacheLock;
  570. // These entries are used in setting up bitmap key database and sending
  571. // them to the server.
  572. // bitmapKeyEnumTimerId: ID of timer used to schedule bitmap key enumeration.
  573. // currentBitmapCacheId: currently enumerating keys at bitmap cache Id
  574. // currentBitmapCacheIndex: currently enumerating keys at bitmap cache index
  575. // sendBitmapCacheId: currently we are sending keys at bitmap cache id
  576. // sendBitmapCacheIndex: currently we are sending keys at bitmap cache index
  577. // sendNumBitmapKeys: how many keys we have sent so far
  578. // numKeyEntries: number of keys at each bitmap cache
  579. // totalNumKeyEntries: total number of keys in all caches
  580. // BitmapCacheSizeInUse: total disk space in use for bitmaps
  581. // pBitmapKeyDB: bitmap key database with all keys stored here
  582. // totalNumErrorPDUs: maximum number of error pdus allowed to send to server
  583. // lastTimeErrorPDU: last time sent error pdu for the cache
  584. INT_PTR bitmapKeyEnumTimerId;
  585. USHORT currentBitmapCacheId;
  586. HANDLE currentFileHandle;
  587. USHORT sendBitmapCacheId;
  588. ULONG sendBitmapCacheIndex;
  589. ULONG sendNumBitmapKeys;
  590. ULONG numKeyEntries[TS_BITMAPCACHE_MAX_CELL_CACHES];
  591. ULONG totalNumKeyEntries;
  592. ULONG bitmapCacheSizeInUse;
  593. ULONG totalNumErrorPDUs;
  594. HPTS_BITMAPCACHE_PERSISTENT_LIST_ENTRY pBitmapKeyDB[TS_BITMAPCACHE_MAX_CELL_CACHES];
  595. ULONG maxNumKeyEntries[TS_BITMAPCACHE_MAX_CELL_CACHES];
  596. ULONG lastTimeErrorPDU[TS_BITMAPCACHE_MAX_CELL_CACHES];
  597. ULONG BytesPerCluster;
  598. ULONG NumberOfFreeClusters;
  599. //
  600. // Copy multiplier we are enumerating at
  601. //
  602. ULONG currentCopyMultiplier;
  603. //
  604. // Has the bmp cache memory been allocated
  605. //
  606. BOOL fBmpCacheMemoryAlloced;
  607. #endif // ((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  608. // Property settings from which we determine how to allocate bitmap
  609. // caches at connect time.
  610. ULONG RegBitmapCacheSize;
  611. //
  612. // Virtual Cache size setting is indexed by copy multiplier
  613. //
  614. ULONG PropBitmapVirtualCacheSize[3];
  615. ULONG RegScaleBitmapCachesByBPP;
  616. USHORT RegNumBitmapCaches : 15;
  617. USHORT RegPersistenceActive : 1;
  618. UINT RegBCProportion[TS_BITMAPCACHE_MAX_CELL_CACHES];
  619. ULONG RegBCMaxEntries[TS_BITMAPCACHE_MAX_CELL_CACHES];
  620. UHBITMAPCACHEINFO RegBCInfo[TS_BITMAPCACHE_MAX_CELL_CACHES];
  621. // Specifies the bitmap caching version the server has advertised.
  622. // This is rev1 if no TS_BITMAPCACHE_CAPABILITYSET_HOSTSUPPORT
  623. // capability was sent. Otherwise this version is the one advertised
  624. // in HOSTSUPPORT.
  625. unsigned BitmapCacheVersion;
  626. // The number of cell caches in actual use in this session, and data
  627. // for each cache. We need a copy of the cache attributes here
  628. // because the capabilities could be rev1 or rev2 but we need a
  629. // consistent format to work with.
  630. unsigned NumBitmapCaches;
  631. // Flags:
  632. // bConnected: Used to reduce disconnect work done since it is
  633. // possible to receive more than one call to UH_Disconnected()
  634. // at session end.
  635. // bEnabled : We can be disabled multiple times in a session. Make
  636. // sure we don't do a bunch of extra work.
  637. // bEnabledOnce: Indicates if we have already received a previous
  638. // UH_Enable(). Used to keep from having to do work more than once
  639. // on reconnect.
  640. // bPersistentBitmapKeysSent: Set when we've sent the key PDUs to the
  641. // server.
  642. // bPersistenceActive: Session flag to determine if persistence is
  643. // active.
  644. // bPersistenceDisable: Property setting for persistent flag might
  645. // change after UH_Init. But, if we have this flag on, we won't
  646. // enable persistent caching even the property changed.
  647. // bWarningDisplayed: We only need to display once per session for
  648. // persistent caching failure
  649. // bBitmapKeyEnumComplete: Set when we've done bitmap key enumeration
  650. // on disk
  651. unsigned bConnected : 1;
  652. unsigned bEnabled : 1;
  653. unsigned bEnabledOnce : 1;
  654. unsigned bPersistenceActive : 1;
  655. unsigned bPersistenceDisable : 1;
  656. unsigned bPersistentBitmapKeysSent : 1;
  657. unsigned bWarningDisplayed : 1;
  658. unsigned bBitmapKeyEnumComplete : 1;
  659. unsigned bBitmapKeyEnumerating : 1;
  660. /************************************************************************/
  661. /* Memblt bitmap caches */
  662. /************************************************************************/
  663. UHBITMAPCACHE bitmapCache[TS_BITMAPCACHE_MAX_CELL_CACHES];
  664. /************************************************************************/
  665. // Offscreen bitmap cache
  666. /************************************************************************/
  667. HDC hdcOffscreenBitmap;
  668. HBITMAP hUnusedOffscrBitmap;
  669. unsigned offscrCacheSize;
  670. unsigned offscrCacheEntries;
  671. HPUHOFFSCRBITMAPCACHE offscrBitmapCache;
  672. unsigned sendOffscrCacheErrorPDU;
  673. #ifdef DRAW_NINEGRID
  674. /************************************************************************/
  675. // DrawNineGrid bitmap cache
  676. /************************************************************************/
  677. BYTE *drawNineGridDecompressionBuffer;
  678. unsigned drawNineGridDecompressionBufferSize;
  679. BYTE *drawNineGridAssembleBuffer;
  680. unsigned drawNineGridAssembleBufferOffset;
  681. unsigned drawNineGridAssembleBufferBpp;
  682. unsigned drawNineGridAssembleBufferWidth;
  683. unsigned drawNineGridAssembleBufferHeight;
  684. unsigned drawNineGridAssembleBufferSize;
  685. BOOL drawNineGridAssembleCompressed;
  686. HDC hdcDrawNineGridBitmap;
  687. HBITMAP hUnusedDrawNineGridBitmap;
  688. HRGN hDrawNineGridClipRegion;
  689. unsigned drawNineGridCacheSize;
  690. unsigned drawNineGridCacheEntries;
  691. PUHDRAWSTREAMBITMAPCACHE drawNineGridBitmapCache;
  692. unsigned sendDrawNineGridErrorPDU;
  693. HMODULE hModuleGDI32;
  694. HMODULE hModuleMSIMG32;
  695. FNGDI_DRAWSTREAM *pfnGdiDrawStream;
  696. FNGDI_ALPHABLEND *pfnGdiAlphaBlend;
  697. FNGDI_TRANSPARENTBLT *pfnGdiTransparentBlt;
  698. #endif
  699. #ifdef DRAW_GDIPLUS
  700. // Graw Gdiplus
  701. TSUINT32 ServerGdiplusSupportLevel;
  702. unsigned GdiplusCacheLevel;
  703. BOOL fSendDrawGdiplusErrorPDU;
  704. unsigned DrawGdiplusFailureCount;
  705. #define DRAWGDIPLUSFAILURELIMIT 5
  706. // Buffer to hold Gdiplus order
  707. BYTE *drawGdipBuffer;
  708. BYTE *drawGdipBufferOffset;
  709. ULONG drawGdipBufferSize;
  710. // Buffer to hold Gdiplus cache order
  711. BYTE *drawGdipCacheBuffer;
  712. BYTE *drawGdipCacheBufferOffset;
  713. ULONG drawGdipCacheBufferSize;
  714. // Buffer to hold assembled Gdiplus
  715. BYTE *drawGdipEmfBuffer;
  716. BYTE *drawGdipEmfBufferOffset;
  717. // GdipCache Index data
  718. PUHGDIPLUSOBJECTCACHE GdiplusGraphicsCache;
  719. PUHGDIPLUSOBJECTCACHE GdiplusObjectPenCache;
  720. PUHGDIPLUSOBJECTCACHE GdiplusObjectBrushCache;
  721. PUHGDIPLUSIMAGECACHE GdiplusObjectImageCache;
  722. PUHGDIPLUSOBJECTCACHE GdiplusObjectImageAttributesCache;
  723. // Free list for the image cache chunks
  724. INT16 *GdipImageCacheFreeList;
  725. // Head index of the free list
  726. INT16 GdipImageCacheFreeListHead;
  727. #define GDIP_CACHE_INDEX_DEFAULT -1
  728. INT16 *GdipImageCacheIndex;
  729. // GdipCache actual data
  730. BYTE *GdipGraphicsCacheData;
  731. BYTE *GdipBrushCacheData;
  732. BYTE *GdipPenCacheData;
  733. BYTE *GdipImageAttributesCacheData;
  734. BYTE *GdipImageCacheData;
  735. // Gdiplus CacheEntries
  736. unsigned GdiplusGraphicsCacheEntries;
  737. unsigned GdiplusObjectPenCacheEntries;
  738. unsigned GdiplusObjectBrushCacheEntries;
  739. unsigned GdiplusObjectImageCacheEntries;
  740. unsigned GdiplusObjectImageAttributesCacheEntries;
  741. // Gdiplus CacheChunkSize
  742. unsigned GdiplusGraphicsCacheChunkSize;
  743. unsigned GdiplusObjectBrushCacheChunkSize;
  744. unsigned GdiplusObjectPenCacheChunkSize;
  745. unsigned GdiplusObjectImageAttributesCacheChunkSize;
  746. unsigned GdiplusObjectImageCacheChunkSize;
  747. // Total cache size allowed for Gdiplus image (number of chunks)
  748. unsigned GdiplusObjectImageCacheTotalSize;
  749. // Maximun size for a single Gdiplus image cache (number of chunks)
  750. unsigned GdiplusObjectImageCacheMaxSize;
  751. HMODULE hModuleGDIPlus;
  752. FNGDIPPLAYTSCLIENTRECORD *pfnGdipPlayTSClientRecord;
  753. FNGDIPLUSSTARTUP *pfnGdiplusStartup;
  754. FNGDIPLUSSHUTDOWN *pfnGdiplusShutdown;
  755. ULONG_PTR gpToken;
  756. BOOL gpValid;
  757. BOOL fGdipEnabled;
  758. #endif // DRAW_GDIPLUS
  759. /************************************************************************/
  760. /* Brush caches */
  761. /************************************************************************/
  762. PUHMONOBRUSHCACHE pMonoBrush;
  763. PUHCOLORBRUSHINFO pColorBrushInfo;
  764. #ifdef DC_HICOLOR
  765. PUHHICOLORBRUSHINFO pHiColorBrushInfo;
  766. #endif
  767. PUHCOLORBRUSHCACHE pColorBrush;
  768. RGBQUAD rgbQuadTable[UH_NUM_8BPP_PAL_ENTRIES];
  769. #ifdef DC_DEBUG
  770. //
  771. // Bitmap Cache Monitor data.
  772. //
  773. HWND hwndBitmapCacheMonitor;
  774. UH_CACHE_MONITOR_ENTRY_DATA DCHPTR MonitorEntries[
  775. TS_BITMAPCACHE_MAX_CELL_CACHES];
  776. unsigned numCacheBlobsPerRow;
  777. unsigned yCacheStart[TS_BITMAPCACHE_MAX_CELL_CACHES];
  778. unsigned yDisplayedCacheBitmapStart;
  779. unsigned displayedCacheId;
  780. ULONG displayedCacheEntry;
  781. BOOL showBitmapCacheMonitor;
  782. INT_PTR timerBitmapCacheMonitor;
  783. #endif /* DC_DEBUG */
  784. //
  785. // Disabled bitmap support
  786. //
  787. HBITMAP hbmpDisconnectedBitmap;
  788. HBITMAP hbmpUnusedDisconnectedBitmap;
  789. HDC hdcDisconnected;
  790. #ifdef OS_WINCE
  791. #define MAX_AOT_RECTS 10 //AOT = Always On Top
  792. RECT rcaAOT[MAX_AOT_RECTS];
  793. ULONG ulNumAOTRects;
  794. #endif
  795. } UH_DATA, FAR *PUH_DATA;
  796. //
  797. // Class definition
  798. //
  799. class CUH
  800. {
  801. public:
  802. CUH(CObjs* objs);
  803. ~CUH();
  804. public:
  805. //
  806. // Public data members
  807. //
  808. UH_DATA _UH;
  809. public:
  810. //
  811. // API
  812. //
  813. /****************************************************************************/
  814. /* FUNCTION PROTOTYPES */
  815. /****************************************************************************/
  816. void DCAPI UH_Init();
  817. void DCAPI UH_Term();
  818. DCBOOL DCAPI UH_SetServerFontCount(unsigned);
  819. void DCAPI UH_Enable(ULONG_PTR);
  820. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_Enable);
  821. void DCAPI UH_Disable(ULONG_PTR);
  822. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_Disable);
  823. void DCAPI UH_Disconnect(ULONG_PTR);
  824. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_Disconnect);
  825. void DCAPI UH_SetConnectOptions(ULONG_PTR);
  826. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_SetConnectOptions);
  827. void DCAPI UH_ResetFontMap();
  828. VOID DCAPI UH_BufferAvailable();
  829. VOID DCAPI UH_SendPersistentKeysAndFontList();
  830. VOID DCAPI UH_ClearOneBitmapDiskCache(UINT cacheId,UINT copyMultiplier);
  831. HRESULT DCAPI UH_ProcessOrders(unsigned, BYTE FAR *, DCUINT);
  832. HRESULT DCAPI UH_ProcessBitmapPDU(TS_UPDATE_BITMAP_PDU_DATA UNALIGNED FAR *,
  833. DCUINT);
  834. HRESULT DCAPI UH_ProcessPalettePDU(
  835. TS_UPDATE_PALETTE_PDU_DATA UNALIGNED FAR *, DCUINT);
  836. #ifdef DISABLE_SHADOW_IN_FULLSCREEN
  837. void DCAPI UH_DisableShadowBitmap(ULONG_PTR);
  838. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_DisableShadowBitmap);
  839. void DCAPI UH_EnableShadowBitmap(ULONG_PTR);
  840. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_EnableShadowBitmap);
  841. void DCAPI UH_SetBBarRect(ULONG_PTR pData);
  842. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_SetBBarRect);
  843. void DCAPI UH_SetBBarVisible(ULONG_PTR pData);
  844. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_SetBBarVisible);
  845. #endif
  846. // "Internal" functions required to handle inline functions below.
  847. void DCINTERNAL UHUseSolidPaletteBrush(DCCOLOR);
  848. #ifdef DC_DEBUG
  849. void DCAPI UH_ChangeDebugSettings(ULONG_PTR);
  850. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UH_ChangeDebugSettings);
  851. #endif /* DC_DEBUG */
  852. void DCAPI UH_SetClipRegion(int, int, int, int);
  853. #ifdef DC_DEBUG
  854. HWND UH_GetBitmapCacheMonHwnd() {return _UH.hwndBitmapCacheMonitor;}
  855. #endif
  856. #ifdef DRAW_NINEGRID
  857. HRESULT DCAPI UH_DrawNineGrid(PUH_ORDER, unsigned, RECT*);
  858. #endif
  859. #ifdef DRAW_GDIPLUS
  860. BOOL DCAPI UHDrawGdiplusStartup(ULONG_PTR);
  861. void DCAPI UHDrawGdiplusShutdown(ULONG_PTR);
  862. #endif
  863. /****************************************************************************/
  864. /* INLINE FUNCTIONS */
  865. /* */
  866. /****************************************************************************/
  867. inline void DCINTERNAL UHAddUpdateRegion(PUH_ORDER, HRGN);
  868. /****************************************************************************/
  869. /* Name: UHResetClipRegion */
  870. /* */
  871. /* Purpose: Disables any clipping region in the current output DC. */
  872. /****************************************************************************/
  873. _inline void DCAPI UH_ResetClipRegion()
  874. {
  875. DC_BEGIN_FN("UHResetClipRegion");
  876. #if defined (OS_WINCE)
  877. if ((! _UH.rectReset) || (_UH.validClipDC != _UH.hdcDraw))
  878. #endif
  879. {
  880. SelectClipRgn(_UH.hdcDraw, NULL);
  881. /********************************************************************/
  882. /* Indicate that the region is currently reset. */
  883. /********************************************************************/
  884. _UH.rectReset = TRUE;
  885. #if defined (OS_WINCE)
  886. _UH.validClipDC = _UH.hdcDraw;
  887. #endif
  888. }
  889. DC_END_FN();
  890. }
  891. #ifdef SMART_SIZING
  892. /****************************************************************************/
  893. /* Name: UHClearUpdateRegion */
  894. /* */
  895. /* Purpose: Clears the update region */
  896. /****************************************************************************/
  897. _inline void DCAPI UHClearUpdateRegion()
  898. {
  899. DC_BEGIN_FN("UHClearUpdateRegion");
  900. SetRectRgn(_UH.hrgnUpdate, 0, 0, 0, 0);
  901. _pOp->OP_ClearUpdateRegion();
  902. DC_END_FN();
  903. }
  904. #endif // SMART_SIZING
  905. #ifdef DC_HICOLOR
  906. #define UHGetOffsetIntoCache(iEntry, cacheId) \
  907. (iEntry) * UH_CellSizeFromCacheID((cacheId))
  908. #endif
  909. /****************************************************************************/
  910. /* Name: UH_OnUpdatePDU */
  911. /* */
  912. /* Purpose: Process an Update PDU. */
  913. /* */
  914. /* Params: IN - pUpdatePDU: pointer to Update PDU */
  915. /****************************************************************************/
  916. inline HRESULT DCAPI UH_OnUpdatePDU(
  917. TS_UPDATE_HDR_DATA UNALIGNED FAR *pUpdatePDU,
  918. DCUINT dataLen)
  919. {
  920. DC_BEGIN_FN("UH_OnUpdatePDU");
  921. HRESULT hr = S_OK;
  922. PBYTE pDataEnd = (PBYTE)pUpdatePDU + dataLen;
  923. switch (pUpdatePDU->updateType) {
  924. case TS_UPDATETYPE_ORDERS: {
  925. TS_UPDATE_ORDERS_PDU_DATA UNALIGNED FAR *pHdr;
  926. // SECURITY: 552403
  927. CHECK_READ_N_BYTES(pUpdatePDU, pDataEnd, sizeof(TS_UPDATE_ORDERS_PDU_DATA), hr,
  928. (TB, _T("Bad TS_UPDATE_ORDERS_PDU_DATA; Size %u"), dataLen));
  929. pHdr = (TS_UPDATE_ORDERS_PDU_DATA UNALIGNED FAR *)pUpdatePDU;
  930. TRC_NRM((TB, _T("Order PDU")));
  931. hr = UH_ProcessOrders(pHdr->numberOrders, pHdr->orderList,
  932. dataLen - FIELDOFFSET(TS_UPDATE_ORDERS_PDU_DATA, orderList));
  933. DC_QUIT_ON_FAIL(hr);
  934. break;
  935. }
  936. case TS_UPDATETYPE_BITMAP:
  937. TRC_NRM((TB, _T("Bitmap PDU")));
  938. // SECURITY: 552403
  939. CHECK_READ_N_BYTES(pUpdatePDU, pDataEnd, sizeof(TS_UPDATE_BITMAP_PDU_DATA), hr,
  940. (TB, _T("Bad TS_UPDATE_BITMAP_PDU_DATA; Size %u"), dataLen));
  941. hr = UH_ProcessBitmapPDU((PTS_UPDATE_BITMAP_PDU_DATA)pUpdatePDU,
  942. dataLen);
  943. DC_QUIT_ON_FAIL(hr);
  944. break;
  945. case TS_UPDATETYPE_PALETTE:
  946. TRC_NRM((TB, _T("Palette PDU")));
  947. // SECURITY: 552403
  948. CHECK_READ_N_BYTES(pUpdatePDU, pDataEnd, sizeof(TS_UPDATE_PALETTE_PDU_DATA), hr,
  949. (TB, _T("Bad TS_UPDATE_PALETTE_PDU_DATA; Size %u"), dataLen));
  950. hr = UH_ProcessPalettePDU((PTS_UPDATE_PALETTE_PDU_DATA)pUpdatePDU,
  951. dataLen);
  952. DC_QUIT_ON_FAIL(hr);
  953. break;
  954. case TS_UPDATETYPE_SYNCHRONIZE:
  955. TRC_NRM((TB, _T("Sync PDU")));
  956. break;
  957. default:
  958. TRC_ERR((TB, _T("Unexpected Update PDU type: %u"),
  959. pUpdatePDU->updateType));
  960. DC_QUIT;
  961. break;
  962. }
  963. /************************************************************************/
  964. /* If there are a large number of PDUs arriving, messages flood the */
  965. /* Receive Thread's message queue and it is possible for WM_PAINT */
  966. /* messages to not get processed within a reasonable amount of time */
  967. /* (as they have the lowest priority). We therefore ensure that */
  968. /* any outstanding WM_PAINTs are flushed if they have not been */
  969. /* processed within UH_WORST_CASE_WM_PAINT_PERIOD. */
  970. /* */
  971. /* Note that the normal processing of updates does not involve */
  972. /* WM_PAINT messages - we draw directly to the Output Window. */
  973. /* WM_PAINTs are only generated by resizing or obscuring/revealing */
  974. /* an area of the client window. */
  975. /************************************************************************/
  976. _pOp->OP_MaybeForcePaint();
  977. DC_EXIT_POINT:
  978. DC_END_FN();
  979. return hr;
  980. } /* UH_OnUpdatePDU */
  981. /****************************************************************************/
  982. /* Name: UH_GetShadowBitmapDC */
  983. /* */
  984. /* Purpose: Returns the Shadow Bitmap DC handle. */
  985. /* */
  986. /* Returns: Shadow Bitmap DC handle. */
  987. /****************************************************************************/
  988. inline HDC DCAPI UH_GetShadowBitmapDC()
  989. {
  990. DC_BEGIN_FN("UH_GetShadowBitmapDC");
  991. DC_END_FN();
  992. return _UH.hdcShadowBitmap;
  993. }
  994. /****************************************************************************/
  995. /* Name: UH_GetDisconnectBitmapDC */
  996. /* */
  997. /* Purpose: Returns the Disconnect Bitmap DC handle */
  998. /* */
  999. /* Returns: Disconnect DC handle. */
  1000. /****************************************************************************/
  1001. inline HDC DCAPI UH_GetDisconnectBitmapDC()
  1002. {
  1003. DC_BEGIN_FN("UH_GetShadowBitmapDC");
  1004. DC_END_FN();
  1005. return _UH.hdcDisconnected;
  1006. }
  1007. /****************************************************************************/
  1008. /* Name: UH_GetCurrentOutputDC */
  1009. /* */
  1010. /* Purpose: Returns the DC handle for the current output surface */
  1011. /* (either the Shadow Bitmap or the Output Window). */
  1012. /* */
  1013. /* Returns: Output DC handle. */
  1014. /****************************************************************************/
  1015. inline HDC DCAPI UH_GetCurrentOutputDC()
  1016. {
  1017. DC_BEGIN_FN("UH_GetCurrentOutputDC");
  1018. DC_END_FN();
  1019. return _UH.hdcDraw;
  1020. }
  1021. /****************************************************************************/
  1022. /* Name: UH_ShadowBitmapIsEnabled */
  1023. /* */
  1024. /* Purpose: Returns whether the Shadow Bitmap is currently enabled */
  1025. /* */
  1026. /* Returns: TRUE if Shadow Bitmap is enabled, FALSE otherwise */
  1027. /****************************************************************************/
  1028. inline BOOL DCAPI UH_ShadowBitmapIsEnabled()
  1029. {
  1030. DC_BEGIN_FN("UH_ShadowBitmapIsEnabled");
  1031. DC_END_FN();
  1032. return _UH.shadowBitmapEnabled;
  1033. }
  1034. /****************************************************************************/
  1035. /* Name: UH_GetCurrentPalette */
  1036. /* */
  1037. /* Purpose: Returns the handle of the current palette */
  1038. /* */
  1039. /* Returns: Palette handle */
  1040. /****************************************************************************/
  1041. inline HPALETTE DCAPI UH_GetCurrentPalette()
  1042. {
  1043. DC_BEGIN_FN("UH_GetCurrentPalette");
  1044. DC_END_FN();
  1045. return _UH.hpalCurrent;
  1046. }
  1047. #ifdef OS_WINCE
  1048. #define UHGetColorRef(_color,_type,_uhinst) (_uhinst)->UHGetColorRefCE(_color,_type)
  1049. #endif
  1050. /****************************************************************************/
  1051. // Convert the supplied DCCOLOR into a COLORREF.
  1052. // Macro to force inline.
  1053. /****************************************************************************/
  1054. #ifdef DC_HICOLOR
  1055. #ifndef OS_WINCE
  1056. #define UHGetColorRef(_color, _type, uhinst) \
  1057. (((uhinst)->_UH.protocolBpp == 24) \
  1058. ? \
  1059. RGB(_color.u.rgb.red, _color.u.rgb.green, _color.u.rgb.blue) \
  1060. : \
  1061. (((uhinst)->_UH.protocolBpp == 16) \
  1062. ? \
  1063. RGB((((*((PDCUINT16)&(_color))) >> 8) & 0x00f8) | \
  1064. (((*((PDCUINT16)&(_color))) >> 13) & 0x0007), \
  1065. (((*((PDCUINT16)&(_color))) >> 3) & 0x00fc) | \
  1066. (((*((PDCUINT16)&(_color))) >> 9) & 0x0003), \
  1067. (((*((PDCUINT16)&(_color))) << 3) & 0x00f8) | \
  1068. (((*((PDCUINT16)&(_color))) >> 2) & 0x0007)) \
  1069. : \
  1070. (((uhinst)->_UH.protocolBpp == 15) \
  1071. ? \
  1072. RGB((((*((PDCUINT16)&(_color))) >> 7) & 0x00f8) | \
  1073. (((*((PDCUINT16)&(_color))) >> 12) & 0x0007), \
  1074. (((*((PDCUINT16)&(_color))) >> 2) & 0x00f8) | \
  1075. (((*((PDCUINT16)&(_color))) >> 7) & 0x0007), \
  1076. (((*((PDCUINT16)&(_color))) << 3) & 0x00f8) | \
  1077. (((*((PDCUINT16)&(_color))) >> 2) & 0x0007)) \
  1078. : \
  1079. ((_type) != UH_COLOR_RGB \
  1080. ? \
  1081. ((uhinst)->_UH.colorIndicesEnabled \
  1082. ? \
  1083. DC_PALINDEX((_color).u.index) \
  1084. : \
  1085. PALETTERGB((_color).u.rgb.red, \
  1086. (_color).u.rgb.green, \
  1087. (_color).u.rgb.blue)) \
  1088. : \
  1089. RGB((_color).u.rgb.red, \
  1090. (_color).u.rgb.green, \
  1091. (_color).u.rgb.blue)))) )
  1092. #else
  1093. inline COLORREF UHGetColorRefCE(DCCOLOR color, DCUINT type)
  1094. {
  1095. COLORREF outCol;
  1096. DC_BEGIN_FN("UHGetColorRef");
  1097. if (_UH.protocolBpp == 24)
  1098. {
  1099. outCol = RGB(color.u.rgb.red, color.u.rgb.green, color.u.rgb.blue);
  1100. }
  1101. else if (_UH.protocolBpp == 16)
  1102. {
  1103. outCol = RGB((((*((PDCUINT16)&(color))) & TS_RED_MASK_16BPP) >> 8),
  1104. (((*((PDCUINT16)&(color))) & TS_GREEN_MASK_16BPP)>> 3),
  1105. (((*((PDCUINT16)&(color))) & TS_BLUE_MASK_16BPP) << 3));
  1106. }
  1107. else if (_UH.protocolBpp == 15)
  1108. {
  1109. outCol = RGB((((*((PDCUINT16)&(color))) & TS_RED_MASK_15BPP) >> 7),
  1110. (((*((PDCUINT16)&(color))) & TS_GREEN_MASK_15BPP)>> 2),
  1111. (((*((PDCUINT16)&(color))) & TS_BLUE_MASK_15BPP) << 3));
  1112. }
  1113. else if (type == UH_COLOR_RGB)
  1114. {
  1115. outCol = RGB(color.u.rgb.red, color.u.rgb.green, color.u.rgb.blue);
  1116. }
  1117. else
  1118. {
  1119. if (_UH.colorIndicesEnabled)
  1120. {
  1121. if (g_CEConfig != CE_CONFIG_WBT)
  1122. {
  1123. if (_UH.paletteIsFixed)
  1124. {
  1125. PALETTEENTRY pe;
  1126. GetPaletteEntries(_UH.hpalCurrent, color.u.index, 1, &pe);
  1127. outCol = PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
  1128. }
  1129. else
  1130. {
  1131. outCol = DC_PALINDEX(color.u.index);
  1132. }
  1133. }
  1134. else
  1135. {
  1136. outCol = DC_PALINDEX(color.u.index);
  1137. }
  1138. }
  1139. else
  1140. {
  1141. outCol = PALETTERGB(color.u.rgb.red,
  1142. color.u.rgb.green,
  1143. color.u.rgb.blue);
  1144. }
  1145. }
  1146. TRC_NRM((TB, "Returning rgb %08lx", outCol));
  1147. DC_END_FN();
  1148. return(outCol);
  1149. }
  1150. #endif // OS_WINCE
  1151. #else // not HICOLOR
  1152. #ifndef OS_WINCE
  1153. #define UHGetColorRef(_color, _type, uhinst) \
  1154. ((_type) != UH_COLOR_RGB ? \
  1155. ((uhinst)->_UH.colorIndicesEnabled ? DC_PALINDEX((_color).u.index) : \
  1156. PALETTERGB((_color).u.rgb.red, (_color).u.rgb.green, \
  1157. (_color).u.rgb.blue)) : \
  1158. RGB((_color).u.rgb.red, (_color).u.rgb.green, \
  1159. (_color).u.rgb.blue))
  1160. #else
  1161. _inline COLORREF DCINTERNAL UHGetColorRef(DCCOLOR color, DCUINT type)
  1162. {
  1163. COLORREF outCol;
  1164. DC_BEGIN_FN("UHGetColorRef");
  1165. if (type == UH_COLOR_RGB)
  1166. {
  1167. outCol = RGB(color.u.rgb.red, color.u.rgb.green, color.u.rgb.blue);
  1168. }
  1169. else
  1170. {
  1171. if (_UH.colorIndicesEnabled)
  1172. {
  1173. if (g_CEConfig != CE_CONFIG_WBT)
  1174. {
  1175. if (_UH.paletteIsFixed)
  1176. {
  1177. PALETTEENTRY pe;
  1178. GetPaletteEntries(_UH.hpalCurrent, color.u.index, 1, &pe);
  1179. outCol = PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
  1180. }
  1181. else
  1182. {
  1183. outCol = DC_PALINDEX(color.u.index);
  1184. }
  1185. }
  1186. else
  1187. {
  1188. outCol = DC_PALINDEX(color.u.index);
  1189. }
  1190. }
  1191. else
  1192. {
  1193. outCol = PALETTERGB(color.u.rgb.red,
  1194. color.u.rgb.green,
  1195. color.u.rgb.blue);
  1196. }
  1197. }
  1198. TRC_NRM((TB, _T("Returning rgb %08lx"), outCol));
  1199. DC_END_FN();
  1200. return(outCol);
  1201. }
  1202. #endif // OS_WINCE
  1203. #endif // DC_HICOLOR
  1204. /****************************************************************************/
  1205. /* Name: UHUseBkColor */
  1206. /* */
  1207. /* Purpose: Selects a given background color into the output DC. */
  1208. /* */
  1209. /* Params: IN: color - background color */
  1210. /* IN: colorType - color type */
  1211. /****************************************************************************/
  1212. #if defined (OS_WINCE)
  1213. #define UHUseBkColor(_color, _colorType, uhinst) \
  1214. { \
  1215. COLORREF rgb; \
  1216. \
  1217. rgb = UHGetColorRef((_color), (_colorType), (uhinst)); \
  1218. if ((rgb != (uhinst)->_UH.lastBkColor) || \
  1219. ((uhinst)->_UH.hdcDraw != (uhinst)->_UH.validBkColorDC)) \
  1220. { \
  1221. SetBkColor((uhinst)->_UH.hdcDraw, rgb); \
  1222. (uhinst)->_UH.lastBkColor = rgb; \
  1223. (uhinst)->_UH.validBkColorDC = (uhinst)->_UH.hdcDraw; \
  1224. } \
  1225. }
  1226. #else
  1227. #define UHUseBkColor(_color, _colorType, uhinst) \
  1228. { \
  1229. COLORREF rgb; \
  1230. \
  1231. rgb = UHGetColorRef((_color), (_colorType), (uhinst)); \
  1232. { \
  1233. SetBkColor((uhinst)->_UH.hdcDraw, rgb); \
  1234. (uhinst)->_UH.lastBkColor = rgb; \
  1235. } \
  1236. }
  1237. #endif
  1238. /****************************************************************************/
  1239. /* Name: UHUseTextColor */
  1240. /* */
  1241. /* Purpose: Selects a given text color into the output DC. */
  1242. /* */
  1243. /* Params: IN: color - text color */
  1244. /* IN: colorType - color type */
  1245. /****************************************************************************/
  1246. #if defined (OS_WINCE)
  1247. #define UHUseTextColor(_color, _colorType, uhinst) \
  1248. { \
  1249. COLORREF rgb; \
  1250. \
  1251. rgb = UHGetColorRef((_color), (_colorType), uhinst); \
  1252. if ((rgb != (uhinst)->_UH.lastTextColor) || \
  1253. ((uhinst)->_UH.hdcDraw != (uhinst)->_UH.validTextColorDC)) \
  1254. { \
  1255. SetTextColor((uhinst)->_UH.hdcDraw, rgb); \
  1256. (uhinst)->_UH.lastTextColor = rgb; \
  1257. (uhinst)->_UH.validTextColorDC = (uhinst)->_UH.hdcDraw; \
  1258. } \
  1259. }
  1260. #else
  1261. #define UHUseTextColor(_color, _colorType, uhinst) \
  1262. { \
  1263. COLORREF rgb; \
  1264. \
  1265. rgb = UHGetColorRef((_color), (_colorType), uhinst); \
  1266. { \
  1267. SetTextColor((uhinst)->_UH.hdcDraw, rgb); \
  1268. (uhinst)->_UH.lastTextColor = rgb; \
  1269. } \
  1270. }
  1271. #endif
  1272. /****************************************************************************/
  1273. /* Name: UH_UseBrushEx */
  1274. /* */
  1275. /* Purpose: Creates and selects a given brush into the current output */
  1276. /* DC. */
  1277. /* */
  1278. /* Purpose: Sets given brush origin in the output DC. */
  1279. /* */
  1280. /* Params: IN: x, y - brush origin */
  1281. /* IN: style - brush style */
  1282. /* IN: hatch - brush hatch */
  1283. /* IN: color - brush color */
  1284. /* IN: colorType - type of color */
  1285. /* IN: extra - array of bitmap bits for custom brushes */
  1286. /****************************************************************************/
  1287. inline HRESULT DCAPI UH_UseBrushEx(
  1288. int x,
  1289. int y,
  1290. unsigned style,
  1291. unsigned hatch,
  1292. DCCOLOR color,
  1293. unsigned colorType,
  1294. PBYTE pextra)
  1295. {
  1296. DC_BEGIN_FN("UH_UseBrushEx");
  1297. HRESULT hr = S_OK;
  1298. UHUseBrushOrg(x, y);
  1299. hr = UHUseBrush(style, hatch, color, colorType, pextra);
  1300. DC_EXIT_POINT:
  1301. DC_END_FN();
  1302. return hr;
  1303. }
  1304. /****************************************************************************/
  1305. /* Name: UH_ProcessServerCaps */
  1306. /* */
  1307. /* Purpose: Processes the server's capabilities. Called on sender thread. */
  1308. /* +++NOTE: Called on sender thread. */
  1309. /* */
  1310. /* Returns: Nothing */
  1311. /* */
  1312. /* Params: IN: capsLength - number of bytes pointed to by pCaps */
  1313. /* IN: pCaps - pointer to the combined capabilities */
  1314. /****************************************************************************/
  1315. inline void DCAPI UH_ProcessServerCaps(PTS_ORDER_CAPABILITYSET pOrderCaps)
  1316. {
  1317. DC_BEGIN_FN("UH_ProcessServerCaps");
  1318. TRC_ASSERT(pOrderCaps, (TB,_T("pOrderCaps == NULL in call to UH_ProcessServerCaps")));
  1319. if (pOrderCaps)
  1320. {
  1321. // Look to see if the server will be sending us palette indices
  1322. // rather than RGB values.
  1323. if (_UH.colorIndicesEnabled)
  1324. {
  1325. if (pOrderCaps->orderFlags & TS_ORDERFLAGS_COLORINDEXSUPPORT)
  1326. {
  1327. TRC_NRM((TB, _T("color indices ARE supported")));
  1328. _UH.colorIndicesEnabled = TRUE;
  1329. }
  1330. else
  1331. {
  1332. TRC_NRM((TB, _T("color indices NOT supported")));
  1333. _UH.colorIndicesEnabled = FALSE;
  1334. }
  1335. }
  1336. }
  1337. DC_END_FN();
  1338. } /* UH_ProcessServerCaps */
  1339. /****************************************************************************/
  1340. // UH_ProcessBCHostSupportCaps
  1341. //
  1342. // Processes a TS_BITMAPCACHE_CAPABILITYSET_HOSTSUPPORT sent by the server.
  1343. // These caps are used to determine the bitmap caching protocol sequences
  1344. // to be used.
  1345. // +++NOTE: Called on sender thread.
  1346. /****************************************************************************/
  1347. inline void DCAPI UH_ProcessBCHostSupportCaps(
  1348. TS_BITMAPCACHE_CAPABILITYSET_HOSTSUPPORT *pHostSupport)
  1349. {
  1350. DC_BEGIN_FN("UH_ProcessBCHostSupportCaps");
  1351. if (pHostSupport != NULL &&
  1352. pHostSupport->CacheVersion == TS_BITMAPCACHE_REV2)
  1353. _UH.BitmapCacheVersion = TS_BITMAPCACHE_REV2;
  1354. else
  1355. _UH.BitmapCacheVersion = TS_BITMAPCACHE_REV1;
  1356. TRC_NRM((TB,_T("Received HOSTSUPPORT caps, cache version %u"),
  1357. _UH.BitmapCacheVersion));
  1358. DC_END_FN();
  1359. }
  1360. /**************************************************************************/
  1361. /* Name: UHIsValidGlyphCacheID */
  1362. /**************************************************************************/
  1363. inline HRESULT DCAPI UHIsValidGlyphCacheID(unsigned cacheId)
  1364. {
  1365. return (cacheId < UH_GLC_NUM_CACHES) ? S_OK : E_TSC_CORE_CACHEVALUE;
  1366. }
  1367. /**************************************************************************/
  1368. /* Name: UHIsValidGlyphCacheIDIndex */
  1369. /**************************************************************************/
  1370. HRESULT DCAPI UHIsValidGlyphCacheIDIndex(unsigned cacheId, unsigned cacheIndex);
  1371. /**************************************************************************/
  1372. /* Name: UHIsValidMonoBrushCacheIndex */
  1373. /**************************************************************************/
  1374. inline HRESULT DCAPI UHIsValidMonoBrushCacheIndex(unsigned cacheIndex)
  1375. {
  1376. return cacheIndex < UH_MAX_MONO_BRUSHES ? S_OK : E_TSC_CORE_CACHEVALUE;
  1377. }
  1378. /**************************************************************************/
  1379. /* Name: UHIsValidColorBrushCacheIndex */
  1380. /**************************************************************************/
  1381. inline HRESULT DCAPI UHIsValidColorBrushCacheIndex(unsigned cacheIndex)
  1382. {
  1383. return cacheIndex < UH_MAX_COLOR_BRUSHES ? S_OK : E_TSC_CORE_CACHEVALUE;
  1384. }
  1385. /**************************************************************************/
  1386. /* Name: UHIsValidColorTableCacheIndex */
  1387. /**************************************************************************/
  1388. inline HRESULT DCAPI UHIsValidColorTableCacheIndex(unsigned cacheIndex)
  1389. {
  1390. return cacheIndex < UH_COLOR_TABLE_CACHE_ENTRIES ?
  1391. S_OK : E_TSC_CORE_CACHEVALUE;
  1392. }
  1393. /**************************************************************************/
  1394. /* Name: UHIsValidOffsreenBitmapCacheIndex */
  1395. /**************************************************************************/
  1396. HRESULT DCAPI UHIsValidOffsreenBitmapCacheIndex(unsigned cacheIndex);
  1397. /**************************************************************************/
  1398. /* Name: UHIsValidBitmapCacheID */
  1399. /**************************************************************************/
  1400. inline HRESULT DCAPI UHIsValidBitmapCacheID(unsigned cacheId)
  1401. {
  1402. return cacheId < _UH.NumBitmapCaches ? S_OK : E_TSC_CORE_CACHEVALUE;
  1403. }
  1404. /**************************************************************************/
  1405. /* Name: UHIsValidBitmapCacheIndex */
  1406. /**************************************************************************/
  1407. inline HRESULT DCAPI UHIsValidBitmapCacheIndex(unsigned cacheId,
  1408. unsigned cacheIndex)
  1409. {
  1410. HRESULT hr = UHIsValidBitmapCacheID(cacheId);
  1411. if (SUCCEEDED(hr)) {
  1412. if (BITMAPCACHE_WAITING_LIST_INDEX == cacheIndex) {
  1413. hr = S_OK;
  1414. }
  1415. else if (_UH.bitmapCache[cacheId].BCInfo.bSendBitmapKeys) {
  1416. hr = cacheIndex < _UH.bitmapCache[cacheId].BCInfo.NumVirtualEntries ?
  1417. S_OK : E_TSC_CORE_CACHEVALUE;
  1418. }
  1419. else {
  1420. hr = cacheIndex < _UH.bitmapCache[cacheId].BCInfo.NumEntries ?
  1421. S_OK : E_TSC_CORE_CACHEVALUE;
  1422. }
  1423. }
  1424. return hr;
  1425. }
  1426. /**************************************************************************/
  1427. /* Name: UHIsValidGdipCacheType */
  1428. /**************************************************************************/
  1429. inline HRESULT DCAPI UHIsValidGdipCacheType(TSUINT16 CacheType)
  1430. {
  1431. HRESULT hr;
  1432. switch (CacheType) {
  1433. case GDIP_CACHE_GRAPHICS_DATA:
  1434. case GDIP_CACHE_OBJECT_BRUSH:
  1435. case GDIP_CACHE_OBJECT_PEN:
  1436. case GDIP_CACHE_OBJECT_IMAGE:
  1437. case GDIP_CACHE_OBJECT_IMAGEATTRIBUTES:
  1438. hr = S_OK;
  1439. break;
  1440. default:
  1441. hr = E_TSC_CORE_CACHEVALUE;
  1442. break;
  1443. }
  1444. return hr;
  1445. }
  1446. /**************************************************************************/
  1447. /* Name: UHIsValidGdipCacheTypeID */
  1448. /**************************************************************************/
  1449. inline HRESULT DCAPI UHIsValidGdipCacheTypeID(TSUINT16 CacheType,
  1450. TSUINT16 CacheID)
  1451. {
  1452. HRESULT hr;
  1453. switch (CacheType) {
  1454. case GDIP_CACHE_GRAPHICS_DATA:
  1455. hr = (CacheID < _UH.GdiplusGraphicsCacheEntries) ?
  1456. S_OK : E_TSC_CORE_CACHEVALUE;
  1457. break;
  1458. case GDIP_CACHE_OBJECT_BRUSH:
  1459. hr = (CacheID < _UH.GdiplusObjectBrushCacheEntries) ?
  1460. S_OK : E_TSC_CORE_CACHEVALUE;
  1461. break;
  1462. case GDIP_CACHE_OBJECT_PEN:
  1463. hr = (CacheID < _UH.GdiplusObjectPenCacheEntries) ?
  1464. S_OK : E_TSC_CORE_CACHEVALUE;
  1465. break;
  1466. case GDIP_CACHE_OBJECT_IMAGE:
  1467. hr = (CacheID < _UH.GdiplusObjectImageCacheEntries) ?
  1468. S_OK : E_TSC_CORE_CACHEVALUE;
  1469. break;
  1470. case GDIP_CACHE_OBJECT_IMAGEATTRIBUTES:
  1471. hr = (CacheID < _UH.GdiplusObjectImageAttributesCacheEntries) ?
  1472. S_OK : E_TSC_CORE_CACHEVALUE;
  1473. break;
  1474. default:
  1475. hr = E_TSC_CORE_CACHEVALUE;
  1476. break;
  1477. }
  1478. return hr;
  1479. }
  1480. /**************************************************************************/
  1481. /* Name: UHGdipCacheChunkSize */
  1482. /**************************************************************************/
  1483. inline unsigned DCAPI UHGdipCacheChunkSize(TSUINT16 CacheType)
  1484. {
  1485. unsigned rc;
  1486. switch (CacheType) {
  1487. case GDIP_CACHE_GRAPHICS_DATA:
  1488. rc = _UH.GdiplusGraphicsCacheChunkSize;
  1489. break;
  1490. case GDIP_CACHE_OBJECT_BRUSH:
  1491. rc = _UH.GdiplusObjectBrushCacheChunkSize;
  1492. break;
  1493. case GDIP_CACHE_OBJECT_PEN:
  1494. rc = _UH.GdiplusObjectPenCacheChunkSize;
  1495. break;
  1496. case GDIP_CACHE_OBJECT_IMAGE:
  1497. rc = _UH.GdiplusObjectImageCacheChunkSize;
  1498. break;
  1499. case GDIP_CACHE_OBJECT_IMAGEATTRIBUTES:
  1500. rc = _UH.GdiplusObjectImageAttributesCacheChunkSize;
  1501. break;
  1502. default:
  1503. rc = 0;
  1504. break;
  1505. }
  1506. return rc;
  1507. }
  1508. inline void DCAPI UH_SetServerGdipSupportLevel(
  1509. UINT32 SupportLevel)
  1510. {
  1511. _UH.ServerGdiplusSupportLevel = SupportLevel;
  1512. }
  1513. /**************************************************************************/
  1514. /* Name: UHIsValidNineGridCacheIndex */
  1515. /**************************************************************************/
  1516. inline HRESULT DCAPI UHIsValidNineGridCacheIndex(unsigned cacheIndex)
  1517. {
  1518. return cacheIndex < _UH.drawNineGridCacheEntries ?
  1519. S_OK : E_TSC_CORE_CACHEVALUE;
  1520. }
  1521. /**************************************************************************/
  1522. /* Name: UHIsValidFragmentCacheIndex */
  1523. /**************************************************************************/
  1524. inline HRESULT DCAPI UHIsValidFragmentCacheIndex(unsigned cacheIndex)
  1525. {
  1526. return (cacheIndex < UH_FGC_CACHE_MAXIMUMCELLCOUNT) ?
  1527. S_OK : E_TSC_CORE_CACHEVALUE;
  1528. }
  1529. #ifdef DC_DEBUG
  1530. void DCAPI UH_HatchRect(int, int, int, int, COLORREF, unsigned);
  1531. DCVOID DCAPI UH_HatchOutputRect(DCINT left, DCINT top, DCINT right,
  1532. DCINT bottom, COLORREF color, DCUINT hatchStyle);
  1533. DCVOID DCAPI UH_HatchRectDC(HDC hdc, DCINT left, DCINT top, DCINT right,
  1534. DCINT bottom, COLORREF color, DCUINT hatchStyle);
  1535. #endif
  1536. HRESULT DCAPI UHDrawMemBltOrder(HDC, MEMBLT_COMMON FAR *);
  1537. #ifdef DC_DEBUG
  1538. void DCAPI UHLabelMemBltOrder(int, int, unsigned, unsigned);
  1539. #endif
  1540. void DCAPI UHUsePen(unsigned, unsigned, DCCOLOR, unsigned);
  1541. /****************************************************************************/
  1542. /* Name: UHConvertToWindowsROP */
  1543. /* */
  1544. /* Purpose: Converts a rop index (in the range 0-255) to a 32-bit Windows */
  1545. /* rop code. */
  1546. /* */
  1547. /* Returns: 32-bit rop value. */
  1548. /****************************************************************************/
  1549. inline UINT32 DCAPI UHConvertToWindowsROP(unsigned ropIndex)
  1550. {
  1551. UINT32 rc;
  1552. DC_BEGIN_FN("UHConvertToWindowsROP");
  1553. TRC_ASSERT((ropIndex <= 0xFF), (TB, _T("ropIndex (%u) invalid"), ropIndex));
  1554. /************************************************************************/
  1555. /* Simply take the ROP value from the uhWindowsROPs lookup table and */
  1556. /* place the ropIndex in the upper 16-bits. */
  1557. /************************************************************************/
  1558. rc = (((UINT32)ropIndex) << 16) | (UINT32)(uhWindowsROPs[ropIndex]);
  1559. DC_END_FN();
  1560. return rc;
  1561. }
  1562. HRESULT DCAPI UHUseBrush(unsigned, unsigned, DCCOLOR, unsigned, BYTE [7]);
  1563. void DCAPI UHUseBrushOrg(int, int);
  1564. /****************************************************************************/
  1565. /* Name: UHDrawGlyphOrder */
  1566. /* */
  1567. /* Purpose: Initiates the drawing of a glyph order */
  1568. /****************************************************************************/
  1569. inline HRESULT DCAPI UHDrawGlyphOrder(
  1570. LPINDEX_ORDER pOrder,
  1571. LPVARIABLE_INDEXBYTES pVariableBytes)
  1572. {
  1573. HRESULT hr = S_OK;
  1574. DC_BEGIN_FN("UHDrawGlyphOrder");
  1575. if (pOrder->cacheId >= UH_GLC_NUM_CACHES) {
  1576. TRC_ABORT((TB,_T("Invalid glyph cacheId=%d"), pOrder->cacheId));
  1577. hr = E_TSC_CORE_CACHEVALUE;
  1578. DC_QUIT;
  1579. }
  1580. // The structure is defined with 255 elements
  1581. if (0 >= pVariableBytes->len ||255 < pVariableBytes->len) {
  1582. TRC_ABORT((TB,_T("Invalid glyph order length")));
  1583. hr = E_TSC_CORE_LENGTH;
  1584. DC_QUIT;
  1585. }
  1586. hr = _pGh->GH_GlyphOut(pOrder, pVariableBytes);
  1587. DC_EXIT_POINT:
  1588. DC_END_FN();
  1589. return hr;
  1590. }
  1591. HRESULT DCAPI UHProcessCacheGlyphOrderRev2(BYTE, unsigned, BYTE FAR *,
  1592. unsigned);
  1593. VOID DCINTERNAL UHResetAndRestartEnumeration();
  1594. VOID DCINTERNAL UHSendPersistentBitmapKeyList(ULONG_PTR unusedParm);
  1595. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHSendPersistentBitmapKeyList);
  1596. inline BOOL DCINTERNAL UHReadFromCacheFileForEnum(VOID);
  1597. VOID DCINTERNAL UHEnumerateBitmapKeyList(ULONG_PTR unusedParm);
  1598. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHEnumerateBitmapKeyList);
  1599. BOOL DCINTERNAL UHSendBitmapCacheErrorPDU(ULONG_PTR cacheId);
  1600. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHSendBitmapCacheErrorPDU);
  1601. BOOL DCINTERNAL UHSendOffscrCacheErrorPDU(DCUINT unused);
  1602. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHSendOffscrCacheErrorPDU);
  1603. #ifdef DRAW_NINEGRID
  1604. BOOL DCINTERNAL UHSendDrawNineGridErrorPDU(DCUINT unused);
  1605. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHSendDrawNineGridErrorPDU);
  1606. #endif
  1607. BOOL DCINTERNAL UHReadFromCacheIndexFile(VOID);
  1608. #ifdef DRAW_GDIPLUS
  1609. BOOL DCINTERNAL UHSendDrawGdiplusErrorPDU(DCUINT unused);
  1610. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CUH, UHSendDrawGdiplusErrorPDU);
  1611. #endif
  1612. private:
  1613. //
  1614. // Internal functions (from wuhint.h)
  1615. //
  1616. /****************************************************************************/
  1617. /* FUNCTIONS */
  1618. /****************************************************************************/
  1619. #ifndef OS_WINCE
  1620. inline HRESULT UHSetCurrentCacheFileName(UINT cacheId, UINT copyMultiplier);
  1621. #else
  1622. VOID UHSetCurrentCacheFileName(UINT cacheId, UINT copyMultiplier);
  1623. #endif
  1624. inline BOOL UHGrabPersistentCacheLock();
  1625. inline VOID UHReleasePersistentCacheLock();
  1626. inline HANDLE UHFindFirstFile(const TCHAR *, TCHAR *, long *);
  1627. inline BOOL UHFindNextFile(HANDLE, TCHAR *, long *);
  1628. inline void UHFindClose(HANDLE);
  1629. inline BOOL UHGetDiskFreeSpace(TCHAR *, ULONG *, ULONG *, ULONG *, ULONG *);
  1630. inline DCBOOL DCINTERNAL UHIsHighVGAColor(BYTE, BYTE, BYTE);
  1631. HRESULT DCINTERNAL UHCacheBitmap(UINT, UINT32,
  1632. TS_SECONDARY_ORDER_HEADER *, PUHBITMAPINFO, PBYTE);
  1633. inline VOID DCINTERNAL UHLoadBitmapBits(UINT, UINT32,
  1634. PUHBITMAPCACHEENTRYHDR *, PBYTE *);
  1635. inline VOID DCINTERNAL UHInitBitmapCachePageTable(UINT);
  1636. inline BOOL DCINTERNAL UHAllocBitmapCachePageTable(UINT32, UINT);
  1637. BOOL DCINTERNAL UHCreateCacheDirectory();
  1638. DCBOOL DCINTERNAL UHAllocOneGlyphCache(PUHGLYPHCACHE, DCUINT32);
  1639. DCBOOL DCINTERNAL UHAllocOneFragCache(PUHFRAGCACHE pCache,
  1640. DCUINT32 numEntries);
  1641. void DCINTERNAL GHSetShadowBitmapInfo();
  1642. unsigned DCINTERNAL UHGetANSICodePage();
  1643. void DCINTERNAL UHCommonDisable(BOOL fDisplayDisabledBitmap);
  1644. HRESULT DCINTERNAL UHProcessBitmapRect(TS_BITMAP_DATA UNALIGNED FAR *);
  1645. void DCINTERNAL UHResetDCState();
  1646. HRESULT DCINTERNAL UHProcessCacheBitmapOrder(void *, DCUINT);
  1647. HRESULT DCINTERNAL UHProcessCacheColorTableOrder(
  1648. PTS_CACHE_COLOR_TABLE_ORDER, DCUINT);
  1649. HRESULT DCINTERNAL UHProcessCacheGlyphOrder(PTS_CACHE_GLYPH_ORDER, DCUINT);
  1650. HRESULT DCINTERNAL UHProcessCacheBrushOrder(const TS_CACHE_BRUSH_ORDER *, DCUINT);
  1651. HRESULT DCINTERNAL UHCreateOffscrBitmap(PTS_CREATE_OFFSCR_BITMAP_ORDER,
  1652. DCUINT, unsigned *);
  1653. HRESULT DCINTERNAL UHSwitchBitmapSurface(PTS_SWITCH_SURFACE_ORDER, DCUINT);
  1654. HRESULT DCINTERNAL UHDrawOffscrBitmapBits(HDC hdc, MEMBLT_COMMON FAR *pMB);
  1655. #ifdef DRAW_GDIPLUS
  1656. HRESULT DCINTERNAL UHDrawGdiplusPDUComplete( ULONG, ULONG);
  1657. HRESULT DCINTERNAL UHDrawGdiplusPDUFirst(PTS_DRAW_GDIPLUS_ORDER_FIRST pOrder, DCUINT, unsigned *);
  1658. HRESULT DCINTERNAL UHDrawGdiplusPDUNext(PTS_DRAW_GDIPLUS_ORDER_NEXT pOrder, DCUINT, unsigned *);
  1659. HRESULT DCINTERNAL UHDrawGdiplusPDUEnd(PTS_DRAW_GDIPLUS_ORDER_END pOrder, DCUINT, unsigned *);
  1660. HRESULT DCINTERNAL UHDrawGdiplusCacheData(TSUINT16 CacheType, TSUINT16 CacheID, unsigned cbTotalSize);
  1661. HRESULT DCINTERNAL UHAssembleGdipEmfRecord(unsigned EmfSize, unsigned TotalSize);
  1662. HRESULT DCINTERNAL UHDrawGdiplusCachePDUFirst(PTS_DRAW_GDIPLUS_CACHE_ORDER_FIRST pOrder, DCUINT, unsigned *);
  1663. HRESULT DCINTERNAL UHDrawGdiplusCachePDUNext(PTS_DRAW_GDIPLUS_CACHE_ORDER_NEXT pOrder, DCUINT, unsigned *);
  1664. HRESULT DCINTERNAL UHDrawGdiplusCachePDUEnd(PTS_DRAW_GDIPLUS_CACHE_ORDER_END pOrder, DCUINT, unsigned *);
  1665. BOOL DCINTERNAL UHDrawGdipRemoveImageCacheEntry(TSUINT16 CacheID);
  1666. #endif
  1667. #ifdef DRAW_NINEGRID
  1668. #if 0
  1669. void DCINTERNAL UHCreateDrawStreamBitmap(PTS_CREATE_DRAW_STREAM_ORDER);
  1670. void DCINTERNAL UHDecodeDrawStream(PBYTE streamIn, unsigned streamSize, PBYTE streamOut,
  1671. unsigned *streamOutSize);
  1672. unsigned DCINTERNAL UHDrawStream(PTS_DRAW_STREAM_ORDER pOrder);
  1673. #endif
  1674. HRESULT DCINTERNAL UHCreateNineGridBitmap(PTS_CREATE_NINEGRID_BITMAP_ORDER, DCUINT, unsigned *);
  1675. HRESULT DCINTERNAL CUH::UHCacheStreamBitmapFirstPDU(
  1676. PTS_STREAM_BITMAP_FIRST_PDU pOrder, DCUINT, unsigned *);
  1677. HRESULT DCINTERNAL CUH::UHCacheStreamBitmapNextPDU(
  1678. PTS_STREAM_BITMAP_NEXT_PDU pOrder, DCUINT, unsigned *);
  1679. #endif
  1680. PBYTE DCINTERNAL UHGetMemBltBits(HDC, unsigned, unsigned, unsigned *,
  1681. PUHBITMAPCACHEENTRYHDR *);
  1682. BOOL DCINTERNAL UHDIBCopyBits(HDC, int, int, int, int, int, int, PBYTE,
  1683. UINT, PBITMAPINFO, BOOL);
  1684. void DCINTERNAL UHCalculateColorTableMapping(unsigned);
  1685. BOOL DCINTERNAL UHAllocColorTableCacheMemory();
  1686. DCBOOL DCINTERNAL UHAllocGlyphCacheMemory();
  1687. DCBOOL DCINTERNAL UHAllocBrushCacheMemory();
  1688. DCBOOL DCINTERNAL UHAllocOffscreenCacheMemory();
  1689. #ifdef DRAW_NINEGRID
  1690. DCBOOL DCINTERNAL UHAllocDrawNineGridCacheMemory();
  1691. #endif
  1692. #ifdef DRAW_GDIPLUS
  1693. DCBOOL DCINTERNAL UHAllocDrawGdiplusCacheMemory();
  1694. #endif
  1695. void DCINTERNAL UHReadBitmapCacheSettings();
  1696. void DCINTERNAL UHAllocBitmapCacheMemory();
  1697. void DCINTERNAL UHFreeCacheMemory();
  1698. #if ((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  1699. UINT32 DCINTERNAL UHEvictLRUCacheEntry(UINT cacheId);
  1700. UINT32 DCINTERNAL UHFindFreeCacheEntry(UINT cacheId);
  1701. VOID DCINTERNAL UHTouchMRUCacheEntry(UINT cacheId, UINT32 iEntry);
  1702. #endif //((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  1703. #ifdef DC_HICOLOR
  1704. DCUINT32 DCINTERNAL UHAllocOneBitmapCache(DCUINT32 maxMemToUse,
  1705. DCUINT entrySize,
  1706. HPDCVOID DCPTR ppCacheData,
  1707. HPDCVOID DCPTR ppCacheHdr);
  1708. #else
  1709. DCBOOL DCINTERNAL UHAllocOneBitmapCache(DCUINT32 maxMemToUse,
  1710. DCUINT entrySize,
  1711. HPDCVOID DCPTR ppCacheData,
  1712. HPDCVOID DCPTR ppCacheHdr);
  1713. #endif
  1714. DCBOOL DCINTERNAL UHCreateBitmap(HBITMAP* hBitmap,
  1715. HDC* hdcBitmap,
  1716. HBITMAP* hUnusedBitmap,
  1717. DCSIZE bitmapSize,
  1718. INT nForceBmpBpp=0);
  1719. void DCINTERNAL UHDeleteBitmap(HDC *, HBITMAP *, HBITMAP *);
  1720. #if ((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  1721. BOOL DCINTERNAL UHSavePersistentBitmap(
  1722. #ifndef VM_BMPCACHE
  1723. HANDLE hFile,
  1724. #else
  1725. UINT cacheId,
  1726. #endif
  1727. UINT32 fileNum,
  1728. PDCUINT8 pCompressedBitmapBits,
  1729. UINT noBCHeader,
  1730. PUHBITMAPINFO pBitmapInfo);
  1731. HRESULT DCINTERNAL UHLoadPersistentBitmap(
  1732. HANDLE hFile,
  1733. UINT32 offset,
  1734. UINT cacheId,
  1735. UINT32 cacheIndex,
  1736. PUHBITMAPCACHEPTE pPTE);
  1737. #endif // ((!defined(OS_WINCE)) || (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  1738. void DCINTERNAL UHMaybeCreateShadowBitmap();
  1739. void DCINTERNAL UHMaybeCreateSaveScreenBitmap();
  1740. #ifdef OS_WINCE
  1741. void DCINTERNAL UHGetPaletteCaps();
  1742. #endif
  1743. #ifdef DC_DEBUG
  1744. void DCINTERNAL UHInitBitmapCacheMonitor();
  1745. void DCINTERNAL UHTermBitmapCacheMonitor();
  1746. LRESULT CALLBACK UHBitmapCacheWndProc( HWND hwnd,
  1747. UINT message,
  1748. WPARAM wParam,
  1749. LPARAM lParam );
  1750. static LRESULT CALLBACK UHStaticBitmapCacheWndProc( HWND hwnd,
  1751. UINT message,
  1752. WPARAM wParam,
  1753. LPARAM lParam );
  1754. void DCINTERNAL UHSetMonitorEntryState(unsigned, ULONG, BYTE, BYTE);
  1755. void DCINTERNAL UHCacheDataReceived(unsigned cacheId, ULONG cacheIndex);
  1756. void DCINTERNAL UHCacheEntryUsed(
  1757. unsigned cacheId,
  1758. ULONG cacheEntry,
  1759. unsigned colorTableCacheEntry);
  1760. #define UHCacheEntryEvictedFromMem(_id, _entry) \
  1761. UHSetMonitorEntryState(_id, _entry, UH_CACHE_STATE_ON_DISK, \
  1762. UH_CACHE_TRANSITION_EVICTED)
  1763. #define UHCacheEntryEvictedFromDisk(_id, _entry) \
  1764. UHSetMonitorEntryState(_id, _entry, UH_CACHE_STATE_UNUSED, \
  1765. UH_CACHE_TRANSITION_EVICTED)
  1766. #define UHCacheEntryKeyLoadOnSessionStart(_id, _entry) \
  1767. UHSetMonitorEntryState(_id, _entry, UH_CACHE_STATE_ON_DISK, \
  1768. UH_CACHE_TRANSITION_KEY_LOAD_ON_SESSION_START)
  1769. #define UHCacheEntryLoadedFromDisk(_id, _entry) \
  1770. UHSetMonitorEntryState(_id, _entry, UH_CACHE_STATE_IN_MEMORY, \
  1771. UH_CACHE_TRANSITION_LOADED_FROM_DISK)
  1772. void DCINTERNAL UHGetCacheBlobRect(unsigned, ULONG, LPRECT);
  1773. BOOL DCINTERNAL UHGetCacheBlobFromPoint(LPPOINT, unsigned *, ULONG *);
  1774. void DCINTERNAL UHDisplayCacheEntry(HDC, unsigned, ULONG);
  1775. void DCINTERNAL UHRefreshDisplayedCacheEntry();
  1776. void DCINTERNAL UHEnableBitmapCacheMonitor(void);
  1777. void DCINTERNAL UHDisconnectBitmapCacheMonitor(void);
  1778. #endif /* DC_DEBUG */
  1779. #if ((defined(OS_WINCE)) && (defined(ENABLE_BMP_CACHING_FOR_WINCE)))
  1780. #ifndef _tremove
  1781. #define _tremove DeleteFile
  1782. #endif
  1783. #define WINCE_STORAGE_CARD_DIRECTORY _T("\\Storage Card\\")
  1784. #define WINCE_FILE_SYSTEM_ROOT _T("\\")
  1785. #endif
  1786. /****************************************************************************/
  1787. /* Name: UHUseBkMode */
  1788. /* */
  1789. /* Purpose: Sets given background mode in output DC. */
  1790. /****************************************************************************/
  1791. #if defined (OS_WINCE)
  1792. #define UHUseBkMode(_mode, uhinst) \
  1793. if (((_mode) != (uhinst)->_UH.lastBkMode) || \
  1794. ((uhinst)->_UH.hdcDraw != (uhinst)->_UH.validBkModeDC)) \
  1795. { \
  1796. SetBkMode((uhinst)->_UH.hdcDraw, (_mode)); \
  1797. (uhinst)->_UH.lastBkMode = (_mode); \
  1798. (uhinst)->_UH.validBkModeDC = (uhinst)->_UH.hdcDraw; \
  1799. }
  1800. #else
  1801. #define UHUseBkMode(_mode, uhinst) \
  1802. { \
  1803. SetBkMode((uhinst)->_UH.hdcDraw, (_mode)); \
  1804. (uhinst)->_UH.lastBkMode = (_mode); \
  1805. }
  1806. #endif
  1807. /****************************************************************************/
  1808. /* Name: UHUseROP2 */
  1809. /* */
  1810. /* Purpose: Sets given ROP2 in the output DC. */
  1811. /****************************************************************************/
  1812. #if defined (OS_WINCE)
  1813. #define UHUseROP2(_rop2, uhinst) \
  1814. if (((_rop2) != (uhinst)->_UH.lastROP2) || \
  1815. ((uhinst)->_UH.hdcDraw != (uhinst)->_UH.validROPDC)) \
  1816. { \
  1817. SetROP2((uhinst)->_UH.hdcDraw, (int)(_rop2)); \
  1818. (uhinst)->_UH.lastROP2 = (_rop2); \
  1819. (uhinst)->_UH.validROPDC = (uhinst)->_UH.hdcDraw; \
  1820. }
  1821. #else
  1822. #define UHUseROP2(_rop2, uhinst) \
  1823. { \
  1824. SetROP2((uhinst)->_UH.hdcDraw, (int)(_rop2)); \
  1825. (uhinst)->_UH.lastROP2 = (_rop2); \
  1826. }
  1827. #endif
  1828. /****************************************************************************/
  1829. /* Name: UHUseBrushOrg */
  1830. /* */
  1831. /* Purpose: Sets given brush origin in the output DC. */
  1832. /****************************************************************************/
  1833. /************************************************************************/
  1834. /* JPB: There is a bug in WinNT as follows (as far as I can determine */
  1835. /* from observing the external behavior!)... */
  1836. /* */
  1837. /* When drawing to DIBSections, a particular (unknown) graphics */
  1838. /* operation occasionally modifies the brush origin in the DC state (in */
  1839. /* kernel mode). I don't know what this operation is, and think that */
  1840. /* it probably shouldn't be doing it. But it does. */
  1841. /* */
  1842. /* If this was the only problem, we could handle it by simply setting */
  1843. /* the origin to the desired value before every graphics call. */
  1844. /* However, this doesn't work! It appears that there is a "fastpath" */
  1845. /* check in the GDI that compares the supplied parameters with the */
  1846. /* previously set parameters, and takes an early exit if they are the */
  1847. /* same (i.e. does not update the DC). Therefore if we set the origin */
  1848. /* to (0,0), it gets mangled by the DIBSection code, then we try to */
  1849. /* set it to (0,0) again the actual DC value is NOT updated (i.e. stays */
  1850. /* in the mangled state). */
  1851. /* */
  1852. /* We therefore have to force the new origin to be set correctly in the */
  1853. /* DC by setting it twice: once to a value different from the one we */
  1854. /* want, then once to the actual value. Not pretty, but unfortunately */
  1855. /* seems to be the only way to ensure that the origin is set correctly! */
  1856. /* */
  1857. /* This problem has only been observed when drawing to 8bpp DIBSections */
  1858. /* on 16bpp and 24bpp machines. */
  1859. /************************************************************************/
  1860. /************************************************************************/
  1861. /* For Win9x we need to unrealise and re-select the brush before the */
  1862. /* new origin will take effect (BLAH!). On NT this does nothing. */
  1863. /************************************************************************/
  1864. #define UHUseBrushOrg(_x, _y, uhinst) \
  1865. SetBrushOrgEx((uhinst)->_UH.hdcDraw, (_x) + 1, (_y) + 1, NULL); \
  1866. SetBrushOrgEx((uhinst)->_UH.hdcDraw, (_x), (_y), NULL);
  1867. #ifdef DC_HICOLOR
  1868. /****************************************************************************/
  1869. /* Macro to calculate the number of cache entries that fit in a given space */
  1870. /****************************************************************************/
  1871. #define CALC_NUM_CACHE_ENTRIES(newNumEntries, origNumEntries, memLen, cacheId) \
  1872. { \
  1873. DCUINT32 numEntries = (memLen) / UH_CellSizeFromCacheID((cacheId)); \
  1874. newNumEntries = DC_MIN(numEntries, origNumEntries); \
  1875. }
  1876. #endif
  1877. /****************************************************************************/
  1878. /* Name: UHUseFillMode */
  1879. /* */
  1880. /* Purpose: Sets given fill mode in the output DC. */
  1881. /****************************************************************************/
  1882. #if !defined(OS_WINCE) || defined(OS_WINCE_POLYFILLMODE)
  1883. #define UHUseFillMode(_mode, uhinst) \
  1884. { \
  1885. SetPolyFillMode((uhinst)->_UH.hdcDraw, ((_mode) == ORD_FILLMODE_WINDING) ? \
  1886. WINDING : ALTERNATE); \
  1887. (uhinst)->_UH.lastFillMode = (unsigned)(_mode); \
  1888. }
  1889. #else
  1890. #define UHUseFillMode(_mode, uhinst) \
  1891. (uhinst)->_UH.lastFillMode = (_mode);
  1892. #endif
  1893. BOOL UHCreateDisconnectedBitmap();
  1894. private:
  1895. CGH* _pGh;
  1896. COP* _pOp;
  1897. CSL* _pSl;
  1898. CUT* _pUt;
  1899. CFS* _pFs;
  1900. COD* _pOd;
  1901. CIH* _pIh;
  1902. CCD* _pCd;
  1903. CUI* _pUi;
  1904. CCC* _pCc;
  1905. CCLX* _pClx;
  1906. COR* _pOr;
  1907. private:
  1908. CObjs* _pClientObjects;
  1909. };
  1910. #undef TRC_GROUP
  1911. #undef TRC_FILE
  1912. #undef TSC_HR_FILEID
  1913. #endif // _H_UH_