1706f2543SmrgScaled Window Support in DMX
2706f2543Smrg
3706f2543SmrgKevin E. Martin
4706f2543Smrg
5706f2543SmrgRickard E. Faith
6706f2543Smrg
7706f2543Smrg   15 October 2003 (created 19 September 2003)
8706f2543Smrg
9706f2543Smrg   This document investigates the possibility of adding scaled
10706f2543Smrg   window support to the DMX X server, thereby allowing a window
11706f2543Smrg   or some selected part of the logical DMX area to be displayed
12706f2543Smrg   using a scaling factor. For example, this might allow the
13706f2543Smrg   contents of a window to be magnified for easier viewing. In
14706f2543Smrg   particular, scaling for the VNC client is explored. Copyright
15706f2543Smrg   2003 by Red Hat, Inc., Raleigh, North Carolina
16706f2543Smrg     __________________________________________________________
17706f2543Smrg
18706f2543Smrg   Table of Contents
19706f2543Smrg
20706f2543Smrg   Introduction
21706f2543Smrg
22706f2543Smrg        DMX
23706f2543Smrg        Problem Statement
24706f2543Smrg        Task
25706f2543Smrg
26706f2543Smrg   Previous Work
27706f2543Smrg
28706f2543Smrg        VNC
29706f2543Smrg        The X Video Extension
30706f2543Smrg
31706f2543Smrg   Possible Solutions
32706f2543Smrg
33706f2543Smrg        VNC-like Scaling
34706f2543Smrg        Application-transparent Scaling for DMX
35706f2543Smrg        XCreateScaledWindow API
36706f2543Smrg
37706f2543Smrg   Conclusion and Recommendations
38706f2543Smrg
39706f2543SmrgIntroduction
40706f2543Smrg
41706f2543SmrgDMX
42706f2543Smrg
43706f2543Smrg   The DMX X server (Xdmx) is a proxy server that is designed to
44706f2543Smrg   allow X servers on multiple machines to be combined into a
45706f2543Smrg   single multi-headed X server. Combined with Xinerama, these
46706f2543Smrg   heads can appear as a single very high-resolution screen.
47706f2543Smrg   Typical applications include the creation of a video wall with
48706f2543Smrg   16 1280x1024 displays arranged in a rectangle, for a total
49706f2543Smrg   resolution of of 5120x4096.
50706f2543Smrg
51706f2543SmrgProblem Statement
52706f2543Smrg
53706f2543Smrg   Applications displayed on a physically large video wall that
54706f2543Smrg   provides high pixel-resolution may be difficult to see,
55706f2543Smrg   especially if the application is designed for use on a typical
56706f2543Smrg   desktop computer with a relatively small display located close
57706f2543Smrg   to the human operator. The goal of this paper is to describe
58706f2543Smrg   and discuss solutions to this problem.
59706f2543Smrg
60706f2543Smrg   The original driving problem for this work is to provide
61706f2543Smrg   scaling for the vncviewer application when displayed using DMX
62706f2543Smrg   (VNC scaling is currently available only with the Windows
63706f2543Smrg   client, and there is no plan to extend that capability to other
64706f2543Smrg   clients). While this specific problem will be addressed in this
65706f2543Smrg   paper, the general solution space will also be explored, since
66706f2543Smrg   this may lead to a good solution not only for vncviewer but
67706f2543Smrg   also for other applications.
68706f2543Smrg
69706f2543SmrgTask
70706f2543Smrg
71706f2543Smrg   For reference, here is the original description of the task
72706f2543Smrg   this paper addresses:
73706f2543Smrg     * Scaled window support (for VNC)
74706f2543Smrg          + Investigate possibility of implementing a "scaled
75706f2543Smrg            window" extension:
76706f2543Smrg               o Add XCreateScaledWindow call that could be used
77706f2543Smrg                 in place of XCreateWindow
78706f2543Smrg               o All primitives drawn to scaled window would be
79706f2543Smrg                 scaled by appropriate (integral?) scaling factor
80706f2543Smrg          + Alternate approach: special case VNC support
81706f2543Smrg
82706f2543SmrgPrevious Work
83706f2543Smrg
84706f2543Smrg   This section reviews relevant previous work.
85706f2543Smrg
86706f2543SmrgVNC
87706f2543Smrg
88706f2543SmrgScaling under VNC
89706f2543Smrg
90706f2543Smrg   When using the vncviewer program for Windows, it is possible to
91706f2543Smrg   specify a scaling factor (as numerator and denominator). When
92706f2543Smrg   scaling is in effect, the viewer software uses StretchBlt
93706f2543Smrg   (instead of BitBlt) to display the pixels for the user. When
94706f2543Smrg   this call is made, the viewer already has received all of the
95706f2543Smrg   pixel information (at full unscaled resolution).
96706f2543Smrg
97706f2543Smrg   The scaling in VNC is primitive. It does not conserve
98706f2543Smrg   bandwidth, it does not treat textual information differently
99706f2543Smrg   (i.e., by using a suitably scaled font), and it does not
100706f2543Smrg   provide any anti-aliasing other than that provided by the
101706f2543Smrg   underlying (Windows-only) system library.
102706f2543Smrg
103706f2543SmrgThe X Video Extension
104706f2543Smrg
105706f2543Smrg   The X Video Extension is a widely-available extension to the
106706f2543Smrg   X11 protocol that provides support for streaming video.
107706f2543Smrg   Integral to this support is the ability to arbitrarily scale
108706f2543Smrg   the output. In version 2.2 of the X Video specification,
109706f2543Smrg   support for scaled still images was provided, using both shared
110706f2543Smrg   memory and traditional transport. The API for this support uses
111706f2543Smrg   calls that are quite similar to XCreateWindow, XPutImage, and
112706f2543Smrg   XShmPutImage. Currently, most of the drivers implemented in
113706f2543Smrg   XFree86 only support data in various YUV formats. However,
114706f2543Smrg   several modern video adaptors support RGB as well.
115706f2543Smrg
116706f2543Smrg   Note, though, that the target output for this scaling is an
117706f2543Smrg   overlay plane -- so X Video provides functionality that is
118706f2543Smrg   fundamentally different from that provided by the Windows
119706f2543Smrg   StrechBlt call.
120706f2543Smrg
121706f2543SmrgPossible Solutions
122706f2543Smrg
123706f2543Smrg   This section briefly discusses possible solutions, including
124706f2543Smrg   major advantages and disadvantages from both the implementation
125706f2543Smrg   and the end-user programmer standpoint.
126706f2543Smrg
127706f2543SmrgVNC-like Scaling
128706f2543Smrg
129706f2543SmrgSoftware Scaling
130706f2543Smrg
131706f2543Smrg   The vncviewer application could be modified to provide software
132706f2543Smrg   scaling. This is not a general solution, but it does solve one
133706f2543Smrg   of the goals of this work.
134706f2543Smrg
135706f2543Smrg   A prototype of this solution was implemented and a patch
136706f2543Smrg   against vnc-3.3.7-unixsrc is available in the dmx/external
137706f2543Smrg   directory. Because of limited time available for this work, all
138706f2543Smrg   of the edge cases were not considered and the solution works
139706f2543Smrg   well mainly for integer scaling.
140706f2543Smrg
141706f2543Smrg   Currently, vncviewer writes to the X display with XPutImage,
142706f2543Smrg   XCopyArea, and XFillRectangle. All instances of these calls
143706f2543Smrg   have to be aware of scaling and must round correctly. In the
144706f2543Smrg   prototype solution, rounding is incorrect and can cause
145706f2543Smrg   artifacts.
146706f2543Smrg
147706f2543Smrg   A better solution would be to cache all updates to the desktop
148706f2543Smrg   image in vncviewer and only send the damaged area to the X
149706f2543Smrg   display with XPutImage. This would allow the damaged area to be
150706f2543Smrg   computed so that rounding errors do not create artifacts. This
151706f2543Smrg   method is probably similar to what is used in the Window
152706f2543Smrg   client. (The whole VNC suite is being re-written in C++ and the
153706f2543Smrg   forthcoming version 4 has not been evaluated.)
154706f2543Smrg
155706f2543SmrgScaling with the X Video Extension
156706f2543Smrg
157706f2543Smrg   The scaling in the Windows vncviewer application makes use of a
158706f2543Smrg   scaled blit that is supplied by the underlying system library.
159706f2543Smrg   Several video cards currently provide support for a scaled
160706f2543Smrg   blit, and some X servers (including XFree86) expose this
161706f2543Smrg   capability to applications via the XvPutImage interface of the
162706f2543Smrg   X Video Extension. The capability exposed by XvPutImage results
163706f2543Smrg   in the scaled image being drawn to an overlay plane. Most video
164706f2543Smrg   cards also provide support for a scaled blit into the normal
165706f2543Smrg   output planes, but this is not exposed via XvPutImage.
166706f2543Smrg
167706f2543Smrg   The vncviewer program could be modified to use the X Video
168706f2543Smrg   Extension to provide scaling under X11 that is similar to the
169706f2543Smrg   scaling currently provided under Windows. Unfortunately, Xdmx
170706f2543Smrg   does not currently export the X Video Extension, so this would
171706f2543Smrg   not provide an immediate solution usable with DMX.
172706f2543Smrg
173706f2543Smrg   A very early-stage proof-of-concept prototype was implemented
174706f2543Smrg   and a preliminary patch against vnc-3.3.7-unixsrc is available
175706f2543Smrg   in the dmx/external directory. This prototype was implemented
176706f2543Smrg   to better understand the problems that must be solved to make
177706f2543Smrg   this solution viable:
178706f2543Smrg     * As noted under the software scaling section above,
179706f2543Smrg       vncviewer writes to the X display with several different
180706f2543Smrg       calls. These calls write to the normal output planes and
181706f2543Smrg       are compatible with XvPutImage, which writes to an overlay
182706f2543Smrg       plane. To eliminate artifacts caused by this problem,
183706f2543Smrg       vncviewer should be modified so that a cached copy of the
184706f2543Smrg       desktop is available, either as a client-side image or a
185706f2543Smrg       server-side off-screen pixmap, so that XvPutImage would be
186706f2543Smrg       the only method for writing to the X display.
187706f2543Smrg     * Although several modern graphics adaptors support hardware
188706f2543Smrg       scaling using an RGB format (e.g., ATI Radeon, nVidia,
189706f2543Smrg       etc.), XFree86 drivers typically only implement YUV
190706f2543Smrg       formats. YUV generally compress the pixel information in
191706f2543Smrg       some way. For example, two commonly implemented formats,
192706f2543Smrg       YUY2 and UYVY provide intensity information for every RGB
193706f2543Smrg       pixel, but only provide chroma and luminance information
194706f2543Smrg       for pairs of horizontal pixels. Since VNC uses
195706f2543Smrg       pixel-resolution for communicating updates on the wire,
196706f2543Smrg       additional artifacts are introduced (because there may not
197706f2543Smrg       be enough information from the wire to update a pair of
198706f2543Smrg       pixels).
199706f2543Smrg       Further, the well-known problem with YUV encoding is even
200706f2543Smrg       more evident when the image is a desktop instead of a
201706f2543Smrg       movie. For example, consider a 1-pixel-wide vertical window
202706f2543Smrg       border. If the border changes in color but not intensity
203706f2543Smrg       (e.g., because a window manager uses color to indicate
204706f2543Smrg       focus), there may or may not be a change in the YUY2 image,
205706f2543Smrg       depending on the algorithm used for RGB to YUV conversion
206706f2543Smrg       and on how the border pixel is ordered in the pair of
207706f2543Smrg       pixels used by the algorithm.
208706f2543Smrg       Many of these artifacts could be eliminated if vncviewer
209706f2543Smrg       cached a complete RGB image of the desktop, and only did
210706f2543Smrg       the conversion to YUV for properly aligned areas of damage.
211706f2543Smrg       The remaining artifacts could be eliminated if an RGB
212706f2543Smrg       format was used with X Video (which may require the
213706f2543Smrg       extension of existing XFree86 drivers to support RGB).
214706f2543Smrg     * Most modern video cards support exactly one overlay plane
215706f2543Smrg       that is suitable for use with X Video. Therefore, only one
216706f2543Smrg       application can use X Video at any given time. This is a
217706f2543Smrg       severe limitation in a desktop environment.
218706f2543Smrg
219706f2543SmrgImplementing the X Video Extension for DMX
220706f2543Smrg
221706f2543Smrg   The user-level API for X Video is fairly simple, but the
222706f2543Smrg   underlying support required for the full specification is
223706f2543Smrg   large. However, since the API provides a method to query
224706f2543Smrg   supported capabilities, a usable subset of X Video can be
225706f2543Smrg   implemented that would support XvPutImage and little else. This
226706f2543Smrg   would require support for the following:
227706f2543Smrg     * X Video Extension API calls, including the following:
228706f2543Smrg          + XvQueryExtension
229706f2543Smrg          + XvQueryAdaptors
230706f2543Smrg          + XvQueryPortAttributes
231706f2543Smrg          + XvFreeAdaptorInfo
232706f2543Smrg          + XvListImageFormats
233706f2543Smrg          + XvGrabPort
234706f2543Smrg          + XvCreateImage
235706f2543Smrg          + XvPutImage
236706f2543Smrg          + XvShmCreateImage
237706f2543Smrg          + XvShmPutImage
238706f2543Smrg     * Support for querying back-end X Video Extension
239706f2543Smrg       capabilities.
240706f2543Smrg     * Support for sending the image to the back-ends. Because X
241706f2543Smrg       Video requires sending full images, there may be a
242706f2543Smrg       trade-off between bandwidth limitations and additional
243706f2543Smrg       complexity to divide the image up such that is scales
244706f2543Smrg       properly.
245706f2543Smrg     * Possible support for a software fall-back. For example, if
246706f2543Smrg       all of the back-ends do not support the X Video Extension,
247706f2543Smrg       software scaling can be implemented such that the image is
248706f2543Smrg       sent to the back-end with XPutImage. This pathway would
249706f2543Smrg       have poor performance.
250706f2543Smrg
251706f2543SmrgSupporting RGB formats for the X Video Extension
252706f2543Smrg
253706f2543Smrg   Assuming an XFree86 driver already supports the X Video
254706f2543Smrg   Extension, and assuming the target hardware supports an RGB
255706f2543Smrg   format, then adding support for that format is relatively
256706f2543Smrg   simple and straightforward.
257706f2543Smrg
258706f2543SmrgScaling with an XPutImageScaled Extension
259706f2543Smrg
260706f2543Smrg   Instead of (or in addition to) implementing the X Video
261706f2543Smrg   Extension in DMX, one obvious solution would be to implement a
262706f2543Smrg   new extension that provides access to hardware-assisted scaled
263706f2543Smrg   blits, similar to the StretchBlt call available under Windows.
264706f2543Smrg   This call would scale RGB images and would not use the overlay
265706f2543Smrg   plane (unlike the X Video Extension).
266706f2543Smrg
267706f2543Smrg   This approach has many of the same advantages and disadvantages
268706f2543Smrg   as the XCopyAreaScaled Extension, discussed in the next
269706f2543Smrg   section. Discussion of XPutImageScaled is deferred in favor of
270706f2543Smrg   XCopyAreaScaled for the following reasons:
271706f2543Smrg     * XPutImageScaled can be emulated with XCopyAreaScaled by
272706f2543Smrg       first using XPutImage to copy the image to an off-screen
273706f2543Smrg       pixmap, and then calling XCopyAreaScaled between that
274706f2543Smrg       off-screen pixmap and the target drawable.
275706f2543Smrg     * Since XCopyAreaScaled would copy between two areas of
276706f2543Smrg       on-screen or off-screen memory, it has additional uses and
277706f2543Smrg       can be viewed as efficiently providing a superset of
278706f2543Smrg       XPutImageScaled functionality.
279706f2543Smrg
280706f2543SmrgScaling with an XCopyAreaScaled Extension
281706f2543Smrg
282706f2543Smrg   As noted in the previous section, because XCopyAreaScaled
283706f2543Smrg   provides a superset of the functionality provided by
284706f2543Smrg   XPutImageScaled, we will consider this extension instead.
285706f2543Smrg
286706f2543Smrg   First, XCopyAreaScaled would provide for RGB scaling between
287706f2543Smrg   pixmaps (i.e., on-screen or off-screen areas of memory that
288706f2543Smrg   reside on the video card). Unlike the X Video Extension, which
289706f2543Smrg   writes into an overlay plane, XCopyAreaScaled would write into
290706f2543Smrg   the non-overlay areas of the screen. Key points to consider are
291706f2543Smrg   as follows:
292706f2543Smrg     * Because different planes are involved, the two scaling
293706f2543Smrg       operations are usually implemented in hardware differently,
294706f2543Smrg       so an XCopyAreaScaled extension could be added in a manner
295706f2543Smrg       that would neither conflict with nor interact with the X
296706f2543Smrg       Video extension in any way.
297706f2543Smrg     * The XCopyAreaScaled extension provides new functionality
298706f2543Smrg       that the X Video Extension does not provide. Based on
299706f2543Smrg       anecdotal feedback, we believe that many people outside the
300706f2543Smrg       DMX and VNC communities would be excited about this
301706f2543Smrg       extension.
302706f2543Smrg     * The main drawback to this extension is that it is new and
303706f2543Smrg       needs to be implemented at the driver level in XFree86 for
304706f2543Smrg       each video card to be supported. At the present time, it is
305706f2543Smrg       more likely that the X Video Extension will be implemented
306706f2543Smrg       for a particular piece hardware because the X Video
307706f2543Smrg       extension has multimedia uses. However, over time, we would
308706f2543Smrg       expect the XCopyAreaScaled extension to be implemented
309706f2543Smrg       along with the X Video extension, especially if it becomes
310706f2543Smrg       popular.
311706f2543Smrg     * Another drawback is that not all modern cards provide
312706f2543Smrg       support for a simple scaled blit operation. However, these
313706f2543Smrg       cards usually do provide a 3D pipeline which could be used
314706f2543Smrg       to provide this functionality in a manner that is
315706f2543Smrg       transparent to the client application that is using the
316706f2543Smrg       XCopyAreaScaled extension. However, this implementation
317706f2543Smrg       pathway would make this extension somewhat more difficult
318706f2543Smrg       to implement on certain cards.
319706f2543Smrg
320706f2543SmrgScaling with OpenGL
321706f2543Smrg
322706f2543Smrg   Another general solution to the scaling problem is to use the
323706f2543Smrg   texture scaling found in all 3D hardware. This ability is
324706f2543Smrg   already exposed through OpenGL and can be exploited by clients
325706f2543Smrg   without X server modification (i.e., other than the ability to
326706f2543Smrg   support OpenGL). An application using OpenGL would transmit the
327706f2543Smrg   non-scaled image to the X server as a texture, and would then
328706f2543Smrg   display a single non-transformed rect using that texture. This
329706f2543Smrg   also works around the single overlay problem with the X Video
330706f2543Smrg   Extension as well as the need to implement additional scaled
331706f2543Smrg   primitive extensions.
332706f2543Smrg
333706f2543Smrg   The downside is that most OpenGL implementations require power
334706f2543Smrg   of 2 texture sizes and this can be very wasteful of memory if,
335706f2543Smrg   for example, the application needs to scale a 1025x1025 image,
336706f2543Smrg   which would require a 2048x2048 texture area (even a 640x480
337706f2543Smrg   image would require a 1024x512 texture). Another downside is
338706f2543Smrg   that some OpenGL implementations have a limited about of
339706f2543Smrg   texture memory and cannot handle textures that are very large.
340706f2543Smrg   For example, they might limit the texture size to 1024x1024.
341706f2543Smrg
342706f2543SmrgApplication-transparent Scaling for DMX
343706f2543Smrg
344706f2543SmrgBack-end Scaling Without Disconnect/Reconnect
345706f2543Smrg
346706f2543Smrg   VNC does scaling on the client side (in the vncviewer
347706f2543Smrg   application). Implementing a similar solution for DMX would
348706f2543Smrg   require support in the back-end X servers and, therefore, is
349706f2543Smrg   not a general solution.
350706f2543Smrg
351706f2543Smrg   XFree86 already implements some support for "scaling" that
352706f2543Smrg   could be used with DMX: if, in the XF86Config file, multiple
353706f2543Smrg   Modes are listed in the Display Subsection of the Screen
354706f2543Smrg   Section, then pressing Ctrl-Alt-Plus and Ctrl-Alt-Minus can be
355706f2543Smrg   used to iterate through the listed modes. The display
356706f2543Smrg   dimensions will change to the dimensions in the Modes line, but
357706f2543Smrg   the logical dimensions of the X server (i.e., the dimensions
358706f2543Smrg   that Xdmx knows about) will not change.
359706f2543Smrg
360706f2543Smrg   Further, the dimensions of the XFree86 display are under
361706f2543Smrg   software control (via the XFree86-VidModeExtension), so the
362706f2543Smrg   Xdmx server could change the screen dimensions on a per-display
363706f2543Smrg   basis, thereby scaling the information on part of that display.
364706f2543Smrg
365706f2543Smrg   However, this scaling appears to have limited use. For example,
366706f2543Smrg   assume a 4 by 4 display wall consisting of 16 1280x1024
367706f2543Smrg   displays. If all of the back-end servers were simultaneously
368706f2543Smrg   configured to display 640x480, the left hand corner of each
369706f2543Smrg   display would be magnified, but the composite result would be
370706f2543Smrg   unreadable. Magnifying one display at a time could be usable,
371706f2543Smrg   but could have limited utility, since the result would still be
372706f2543Smrg   no larger than a single display.
373706f2543Smrg
374706f2543SmrgBack-end Scaling With Disconnect/Reconnect
375706f2543Smrg
376706f2543Smrg   Disconnect and reconnect features are not currently supported
377706f2543Smrg   in DMX, but are scheduled to be implemented in the future.
378706f2543Smrg   These features, combined with the XFree86-VidModeExtension
379706f2543Smrg   Extension, would allow an application to do the following:
380706f2543Smrg     * Disconnect a specific back-end server (via the DMX
381706f2543Smrg       Extension),
382706f2543Smrg     * reconfigure the XFree86 back-end server resolution, and
383706f2543Smrg     * reconnect the back-end server to DMX -- at a new origin
384706f2543Smrg       with the new screen resolution.
385706f2543Smrg
386706f2543Smrg   For example, consider a display wall consisting of 16 1280x1024
387706f2543Smrg   displays with a total resolution of 5120x4096. All of the
388706f2543Smrg   screens could be disconnected, repositioned, and reconnected
389706f2543Smrg   each at a resolution of 640x480. The total resolution of the
390706f2543Smrg   display wall would be 2560x1920, allowing a view of a selected
391706f2543Smrg   area approximately one-fourth of the size of the DMX display.
392706f2543Smrg   This change would be completely application independent
393706f2543Smrg   (except, perhaps, for a DMX-aware window manager). When work at
394706f2543Smrg   the increased resolution was completed, the back-end servers
395706f2543Smrg   could be disconnected, reconfigured, and reconnected for the
396706f2543Smrg   original 5120x4096 view.
397706f2543Smrg
398706f2543Smrg   Support for this type of scaling can be implemented in a
399706f2543Smrg   DMX-aware X11 client assuming the DMX server support arbitrary
400706f2543Smrg   disconnect and reconnect semantics. Because this application
401706f2543Smrg   cannot be written before disconnect/reconnect is implemented,
402706f2543Smrg   this solution will not be discussed further in this paper.
403706f2543Smrg
404706f2543SmrgServer-side Scaling
405706f2543Smrg
406706f2543Smrg   In earlier versions of DMX, a frame buffer was maintained on
407706f2543Smrg   the server side, and XPutImage was used to move the information
408706f2543Smrg   from the server to the client (similar to some early VNC
409706f2543Smrg   implementations). The use of a server-side frame buffer would
410706f2543Smrg   allow the server to do scaling, but is not a recommended
411706f2543Smrg   solution because of overall performance issues and server-side
412706f2543Smrg   memory issues (i.e., the frame buffer would be very large for
413706f2543Smrg   large display walls).
414706f2543Smrg
415706f2543Smrg   Exploration of this path is not recommended.
416706f2543Smrg
417706f2543SmrgXCreateScaledWindow API
418706f2543Smrg
419706f2543Smrg   The implementation of X Video Extension in DMX, and the use of
420706f2543Smrg   XvPutImage by applications requiring scaling requires
421706f2543Smrg   significant changes in DMX Further, XvPutImage is, essentially
422706f2543Smrg   a scaled blit, and it is only useful for applications which are
423706f2543Smrg   already using (or can be modified to use) XPutImage. Therefore,
424706f2543Smrg   a more general API will be discussed as another possibility.
425706f2543Smrg
426706f2543Smrg   X applications typically create windows with the XCreateWindow
427706f2543Smrg   call. A new extension could provide an XCreateScaledWindow call
428706f2543Smrg   that could be used in place of the XCreateWindow call and be
429706f2543Smrg   otherwise transparent to the application. This would allow
430706f2543Smrg   applications, even those that do not depend on XPutImage, to
431706f2543Smrg   take advantage of window scaling. In this section we describe
432706f2543Smrg   how the call would work, what transparency it provides, and how
433706f2543Smrg   to solve the potential problems that transparency creates.
434706f2543Smrg
435706f2543SmrgXCreateWindow
436706f2543Smrg
437706f2543Smrg   The XCreateWindow call takes width and height as parameters. An
438706f2543Smrg   XCreateScaledWindow call could take all the same parameters,
439706f2543Smrg   with the addition of a scaling factor.
440706f2543Smrg
441706f2543SmrgXSetWindowAttributes
442706f2543Smrg
443706f2543Smrg   An X11 window has several attributes that would have to be
444706f2543Smrg   scaled:
445706f2543Smrg     * Background and border pixmaps
446706f2543Smrg     * Border width
447706f2543Smrg     * Cursor
448706f2543Smrg
449706f2543SmrgXGetWindowAttributes, XGetGeometry
450706f2543Smrg
451706f2543Smrg   For transparency, calls that query the window attributes should
452706f2543Smrg   return unscaled information. This suggests that all unscaled
453706f2543Smrg   pixmaps and window attributes should be cached.
454706f2543Smrg
455706f2543Smrg   Unfortunately, a window manager requires the scaled geometry to
456706f2543Smrg   properly decorate the window. The X server can probably
457706f2543Smrg   determine which client is acting as the window manager (e.g.,
458706f2543Smrg   because that client will select events that are used
459706f2543Smrg   exclusively by the window manager). However, other Scaled
460706f2543Smrg   Window Extension aware clients may also need to determine the
461706f2543Smrg   scaled geometry. Therefore, at least two additional extension
462706f2543Smrg   calls should be implemented: XGetScaledWindowAttributes and
463706f2543Smrg   XGetScaledGeometry.
464706f2543Smrg
465706f2543SmrgPopup and Child window positions
466706f2543Smrg
467706f2543Smrg   Some applications may position popup and child windows based on
468706f2543Smrg   an unscaled notion of the main window geometry. In this case,
469706f2543Smrg   additional modifications to the client would be required.
470706f2543Smrg
471706f2543SmrgEvents
472706f2543Smrg
473706f2543Smrg   Most events (e.g., for mouse motion) return information about
474706f2543Smrg   the coordinates at which the even occurred. These coordinates
475706f2543Smrg   would have to be modified so that unscaled values were
476706f2543Smrg   presented to the client.
477706f2543Smrg
478706f2543SmrgImplementation
479706f2543Smrg
480706f2543Smrg   There are many implementation issues, some of which are similar
481706f2543Smrg   to the issues involved in implementing the X Video Extension
482706f2543Smrg   for DMX. The window contents must be scaled, either by
483706f2543Smrg   performing all operations to a frame buffer and then writing
484706f2543Smrg   the image to the display (perhaps using hardware scaling
485706f2543Smrg   support), or by modifying all of the various drawing operations
486706f2543Smrg   to perform scaling. Because of the complexity involved, the
487706f2543Smrg   frame buffer option is recommended.
488706f2543Smrg
489706f2543SmrgConclusion and Recommendations
490706f2543Smrg
491706f2543Smrg   We recommend a three phase implementation strategy, based on
492706f2543Smrg   how an application could be written to take advantage of
493706f2543Smrg   scaling:
494706f2543Smrg    1. The XCopyAreaScaled extension should be implemented, since
495706f2543Smrg       this is the ideal solution for applications like VNC, and
496706f2543Smrg       since making use of this extension will require minimal
497706f2543Smrg       changes to applications that already use XPutImage or
498706f2543Smrg       XCopyArea.
499706f2543Smrg       The initial implementation work would include the design of
500706f2543Smrg       the X protocol extension, writing this up in the usual
501706f2543Smrg       format for extension documentation, implementation of the
502706f2543Smrg       protocol transport pieces in XFree86, implementation of a
503706f2543Smrg       software fall-back in XFree86 and DMX, one example hardware
504706f2543Smrg       implementation for XFree86, and implementation of support
505706f2543Smrg       for this extension in DMX.
506706f2543Smrg       We suggest implementing the extension first on the ATI
507706f2543Smrg       Radeon cards. However, since these cards do not provide a
508706f2543Smrg       2D scaled blit primitive, the implementation would have to
509706f2543Smrg       make use of the 3D texture engine to emulate a scaled blit.
510706f2543Smrg       This is recommended, since other modern graphics cards also
511706f2543Smrg       do not provide a simple 2D scaled blit operation and an
512706f2543Smrg       example of the more difficult implementation pathway would
513706f2543Smrg       be helpful to others.
514706f2543Smrg    2. Until XCopyAreaScaled is widely supported, applications
515706f2543Smrg       that require scaling will have to fall back to another
516706f2543Smrg       scaling method. We suggest OpenGL as the first fall-back
517706f2543Smrg       method because it is widely available and supported by DMX.
518706f2543Smrg       A project centered around OpenGL-based scaling would
519706f2543Smrg       implement this scaling in VNC as an example. This work
520706f2543Smrg       would include re-writing the vncviewer rendering engine to
521706f2543Smrg       cache a master copy of the desktop image for all
522706f2543Smrg       operations.
523706f2543Smrg    3. Since OpenGL is not implemented everywhere, and may not
524706f2543Smrg       provide hardware-assisted performance in every
525706f2543Smrg       implementation, an application that requires scaling should
526706f2543Smrg       also fall back to using the X Video Extension.
527706f2543Smrg       This project would add support for the X Video Extension to
528706f2543Smrg       DMX and would add support to VNC to take advantage of this
529706f2543Smrg       extension without introducing artifacts. This would require
530706f2543Smrg       modifying the vncviewer rendering engine to cache a master
531706f2543Smrg       copy of the desktop image for all operations. This project
532706f2543Smrg       should also add support for the RGB format to at least one
533706f2543Smrg       XFree86 driver (e.g., ATI Radeon).
534706f2543Smrg       The X Video Extension is one of the few popular extensions
535706f2543Smrg       that DMX does not support. We recommend implementing the X
536706f2543Smrg       Video Extension even if scaling is the specific goal of
537706f2543Smrg       that work.
538706f2543Smrg
539706f2543Smrg   We do not recommend implementation of the XCreateScaledWindow
540706f2543Smrg   extension because of the complexity involved. We do not
541706f2543Smrg   recommend implementation of the XPutImageScaled extension
542706f2543Smrg   because it requires the same amount of work as the
543706f2543Smrg   XCopyAreaScaled extension, but provides less functionality.
544706f2543Smrg   Further, server-side scaling with a large frame buffer is not
545706f2543Smrg   recommended because of the performance implications.
546706f2543Smrg
547706f2543Smrg   The back-end scaling, especially with disconnect/reconnect
548706f2543Smrg   support should be explored in the future after
549706f2543Smrg   disconnect/reconnect is implemented, but not at the present
550706f2543Smrg   time.
551