VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/vrdptext.c@ 7392

Last change on this file since 7392 was 7392, checked in by vboxsync, 17 years ago

OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/** @file
2 *
3 * VirtualBox Windows NT/2000/XP guest video driver
4 *
5 * VRDP text cache/orders.
6 */
7
8/*
9 * Copyright (C) 2006-2007 innotek GmbH
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License as published by the Free Software Foundation,
15 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
16 * distribution. VirtualBox OSE is distributed in the hope that it will
17 * be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "driver.h"
21#include <VBox/VRDPOrders.h>
22#include <iprt/crc64.h>
23
24/*
25 * The client's glyph cache theoretically consists of 10 caches:
26 * cache index: 0 1 2 3 4 5 6 7 8 9
27 * glyph size (max): 0x4 0x4 0x8 0x8 0x10 0x20 0x40 0x80 0x100 0x800
28 * glyphs: 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0xfe 0x40
29 *
30 * Glyph size is the size of the 1 BPP glyph bitmap bytes rounded up to 32 bit dword:
31 * glyph size = (((w + 7) / 8) * h + 3) & ~3
32 *
33 * Following simplifications are used:
34 * * Cache index 9 is not used, such huge glyphs (~40x40 pixel) are unlikely,
35 * (especially for raster fonts) so without it all caches contain up to 0xfe
36 * characters.
37 * * Maximum string length is 0xfe, so a string can always
38 * be placed in the cache, even if the string consists of
39 * all different characters.
40 *
41 * The driver always sends glyphs to the host.
42 * The host maintains the glyph cache. Performance issues:
43 * - increased the CPU load to copy glyph info.
44 * + eliminates the driver side of the cache.
45 * + lets the host to optimize memory usage.
46 *
47 * Therefore, on a textout the driver must send to the host
48 * The string attributes:
49 * - number of glyphs;
50 * - flags: HORIZONTAL, VERTICAL, CHAR_INC_EQUAL_BM_BASE, ... (1);
51 * - glyph increment for monospaced font (== 0 for not monospaced font) or a flag fMonospaced;
52 * - the bounding box of the string background (prclOpaque or the pstro->rclBkGround);
53 * - the foreground and background colors;
54 * - the mix (two ROP2);
55 * - ... (1).
56 * The glyph information for each glyph in the string:
57 * - unique glyph handle 64 bit for use of crc64;
58 * - the glyph bitmap coordinates on the screen;
59 * - width, height of the glyph;
60 * - the glyph origin in the bitmap (2);
61 * - the 1BPP glyph bitmap;
62 * - whether it is a 'space' character (3);
63 * - ... (1).
64 *
65 * Remarks:
66 * (1) to be defined;
67 * (2) might be not necessary;
68 * (3) it seems to be not necessary to know the codepoint value,
69 * strings are considered to be a set of bitmaps from
70 * the cache space. But reporting that the glyph actually
71 * represents a 'space' character might allow some optimizations.
72 *
73 * The VRDPORDERTEXT consists of the string info and glyph infos.
74 *
75 */
76
77static BOOL vboxReportGlyph (GLYPHPOS *pGlyphPos, uint8_t **ppu8Ptr, uint8_t *pu8End)
78{
79 uint32_t cbOrder;
80 uint32_t cbBitmap;
81
82 VRDPORDERGLYPH *pOrder = (VRDPORDERGLYPH *)*ppu8Ptr;
83
84 GLYPHBITS *pgb = pGlyphPos->pgdf->pgb;
85
86 /* BYTE-aligned 1BPP bitmap of the glyph. The array includes padding at the end to DWORD-align. */
87 cbBitmap = (pgb->sizlBitmap.cx + 7) / 8; /* Line size in bytes. */
88 cbBitmap *= pgb->sizlBitmap.cy; /* Size of bitmap. */
89 cbBitmap = (cbBitmap + 3) & ~3; /* DWORD align. */
90
91 cbOrder = (uint8_t *)&pOrder->au8Bitmap - (uint8_t *)pOrder;
92
93 cbOrder += cbBitmap;
94
95 if (*ppu8Ptr + cbOrder > pu8End)
96 {
97 return FALSE;
98 }
99
100 pOrder->o32NextGlyph = cbOrder;
101
102 pOrder->u64Handle = RTCrc64Start ();
103 pOrder->u64Handle = RTCrc64Process(pOrder->u64Handle, pgb->aj, cbBitmap);
104 pOrder->u64Handle = RTCrc64Process(pOrder->u64Handle, &pgb->ptlOrigin, sizeof (pgb->ptlOrigin));
105 pOrder->u64Handle = RTCrc64Finish(pOrder->u64Handle);
106
107 pOrder->x = (int16_t)pGlyphPos->ptl.x;
108 pOrder->y = (int16_t)pGlyphPos->ptl.y;
109
110 pOrder->w = (uint16_t)pgb->sizlBitmap.cx;
111 pOrder->h = (uint16_t)pgb->sizlBitmap.cy;
112
113 pOrder->xOrigin = (int16_t)pgb->ptlOrigin.x;
114 pOrder->yOrigin = (int16_t)pgb->ptlOrigin.y;
115
116 /* 1BPP bitmap. Rows are byte aligned. Size is (((w + 7)/8) * h + 3) & ~3. */
117 memcpy (pOrder->au8Bitmap, pgb->aj, cbBitmap);
118
119 *ppu8Ptr += cbOrder;
120
121 return TRUE;
122}
123
124static uint32_t vboxSizeofTextOrder (ULONG cGlyphs, ULONG cbMaxGlyph)
125{
126 uint32_t cb = sizeof (VRDPORDERTEXT);
127
128 cb += cGlyphs * (sizeof (VRDPORDERGLYPH) + cbMaxGlyph);
129
130 return cb;
131}
132
133BOOL vboxReportText (PPDEV ppdev,
134 VRDPCLIPRECTS *pClipRects,
135 STROBJ *pstro,
136 FONTOBJ *pfo,
137 RECTL *prclOpaque,
138 ULONG ulForeRGB,
139 ULONG ulBackRGB
140 )
141{
142 FONTINFO fi;
143 uint32_t cbOrderMax;
144 VRDPORDERTEXT *pOrder;
145 BOOL fResult;
146 uint8_t *pu8GlyphPtr;
147 uint8_t *pu8GlyphEnd;
148
149 DISPDBG((1, "VRDP::vrdpReportText: ppdev %p, pClipRects %p, pstro %p, pfo %p, prclOpaque %p, ulForeRGB %x, ulBackRGB %x\n",
150 ppdev, pClipRects, pstro, pfo, prclOpaque, ulForeRGB, ulBackRGB));
151
152 if (pstro->ulCharInc > 0xFF)
153 {
154 return FALSE;
155 }
156
157 if ( (pstro->flAccel & SO_VERTICAL) != 0
158 || (pstro->flAccel & SO_REVERSED) != 0)
159 {
160 /* Do not support (yet) the vertical and right to left strings.
161 * @todo implement and test.
162 */
163 return FALSE;
164 }
165
166 memset (&fi, 0, sizeof (fi));
167
168 FONTOBJ_vGetInfo (pfo, sizeof (fi), &fi);
169
170 if ( fi.cjMaxGlyph1 == 0
171 || fi.cjMaxGlyph1 > VRDP_TEXT_MAX_GLYPH_SIZE)
172 {
173 /* No 1BPP bitmaps or the bitmap is larger than the cache supports. */
174 DISPDBG((1, "VRDP::vrdpReportText: fi.cjMaxGlyph1 = %x. Return FALSE\n", fi.cjMaxGlyph1));
175 return FALSE;
176 }
177
178 cbOrderMax = vboxSizeofTextOrder (pstro->cGlyphs, fi.cjMaxGlyph1);
179
180 DISPDBG((1, "VRDP::vrdpReportText: pstro->cGlyphs = %d, fi.cjMaxGlyph1 = 0x%x, cbOrderMax = 0x%x.\n", pstro->cGlyphs, fi.cjMaxGlyph1, cbOrderMax));
181
182 pOrder = (VRDPORDERTEXT *)EngAllocMem (0, cbOrderMax, ALLOC_TAG);
183
184 if (!pOrder)
185 {
186 DISPDBG((1, "VRDP::vrdpReportText: pOrder = %x. Return FALSE\n", pOrder));
187 return FALSE;
188 }
189
190 pu8GlyphPtr = (uint8_t *)&pOrder[1]; /* Follows the order header. */
191 pu8GlyphEnd = (uint8_t *)pOrder + cbOrderMax;
192
193 pOrder->xBkGround = (int16_t)pstro->rclBkGround.left;
194 pOrder->yBkGround = (int16_t)pstro->rclBkGround.top;
195 pOrder->wBkGround = (uint16_t)(pstro->rclBkGround.right - pstro->rclBkGround.left);
196 pOrder->hBkGround = (uint16_t)(pstro->rclBkGround.bottom - pstro->rclBkGround.top);
197
198 if (prclOpaque)
199 {
200 pOrder->xOpaque = (int16_t)prclOpaque->left;
201 pOrder->yOpaque = (int16_t)prclOpaque->top;
202 pOrder->wOpaque = (uint16_t)(prclOpaque->right - prclOpaque->left);
203 pOrder->hOpaque = (uint16_t)(prclOpaque->bottom - prclOpaque->top);
204 }
205 else
206 {
207 pOrder->xOpaque = 0;
208 pOrder->yOpaque = 0;
209 pOrder->wOpaque = 0;
210 pOrder->hOpaque = 0;
211 }
212
213 pOrder->u16MaxGlyph = (uint16_t)fi.cjMaxGlyph1;
214
215 pOrder->u8Glyphs = (uint8_t)pstro->cGlyphs;
216
217 pOrder->u8Flags = (uint8_t)pstro->flAccel;
218
219 pOrder->u8CharInc = (uint8_t)pstro->ulCharInc;
220
221 pOrder->u32FgRGB = ulForeRGB;
222 pOrder->u32BgRGB = ulBackRGB;
223
224 DISPDBG((1, "VRDP::vrdpReportText: pstro->pgp %p.\n", pstro->pgp));
225
226 /* Enumerate glyphs. */
227 STROBJ_vEnumStart (pstro);
228
229 fResult = TRUE;
230
231 for (;;)
232 {
233 ULONG i;
234 ULONG cGlyphs = 0;
235 GLYPHPOS *pGlyphPos = NULL;
236
237 BOOL fMore = STROBJ_bEnum (pstro, &cGlyphs, &pGlyphPos);
238
239 DISPDBG((1, "VRDP::vrdpReportText: cGlyphs %d.\n", cGlyphs));
240
241 for (i = 0; i < cGlyphs; i++)
242 {
243 fResult = vboxReportGlyph (&pGlyphPos[i], &pu8GlyphPtr, pu8GlyphEnd);
244
245 if (!fResult)
246 {
247 break;
248 }
249 }
250
251 if (!fMore || !fResult)
252 {
253 break;
254 }
255 }
256
257 DISPDBG((1, "VRDP::vrdpReportText: fResult %d.\n", fResult));
258
259 if (fResult)
260 {
261 pOrder->cbOrder = pu8GlyphPtr - (uint8_t *)pOrder;
262
263 vrdpReportOrderGeneric (ppdev, pClipRects, pOrder, pOrder->cbOrder, VRDP_ORDER_TEXT);
264 }
265
266 EngFreeMem (pOrder);
267
268 return fResult;
269}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette