]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/qte/qte-2.3.10/c7x0-w100-accel.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / qte / qte-2.3.10 / c7x0-w100-accel.patch
1 ATI IMAGEON (W100) Accelerated support
2 Manuel Teira <manuel.teira@telefonica.net>
3
4 #
5 # Patch managed by http://www.holgerschurig.de/patcher.html
6 #
7
8 --- qt-2.3.10/configure~w100
9 +++ qt-2.3.10/configure
10 @@ -325,6 +325,9 @@
11     -accel-matrox)
12         QWS_ACCEL_MATROX=y
13         ;;
14 +   -accel-w100)
15 +       QWS_ACCEL_W100=y
16 +       ;;
17     -qvfb)
18         QWS_QVFB=y
19         ;;
20 @@ -726,6 +729,10 @@
21  then
22      QT_CXX="$QT_CXX -DQT_NO_QWS_MATROX"
23  fi
24 +if [ -z "$QWS_ACCEL_W100" -a -n "$EMB" ]
25 +then
26 +    QT_CXX="$QT_CXX -DQT_NO_QWS_W100"
27 +fi
28  if [ -z "$QWS_VNC" -a -n "$EMB" ]
29  then
30      QT_CXX="$QT_CXX -DQT_NO_QWS_VNC"
31 @@ -1338,6 +1345,7 @@
32      -accel-voodoo3 ..... Enable Voodoo3 acceleration.
33      -accel-mach64 ...... Enable Mach64 acceleration.
34      -accel-matrox ...... Enable Matrox MGA acceleration.
35 +    -accel-w100 ........ Enable ATI Imageon w100 acceleration (experimental).
36      -qvfb .............. Enable X11-based Qt Virtual Frame Buffer.
37      -vnc ............... Enable VNC server (requires network module).
38  
39 @@ -1462,6 +1470,7 @@
40  [ "x$JPEG" = "xyes" ] && QT_LIBS="${QT_LIBS} -ljpeg"
41  [ "x$MNG" = "xyes" ] && QT_LIBS="${QT_LIBS} -lmng -ljpeg" # assume JNG support
42  [ "x$NAS_SOUND" = "xyes" ] && QT_LIBS="${QT_LIBS} -laudio -lXt" # Xt junk in audio library
43 +[ "x$QWS_ACCEL_W100" = "xy" ] && QT_LIBS="${QT_LIBS} -laticore" # Aticore W100 support
44  QT_LIBS="$L_FLAGS $R_FLAGS $QT_LIBS $l_FLAGS"
45  
46  
47 --- qt-2.3.10/src/kernel/qgfxraster_qws.cpp~w100
48 +++ qt-2.3.10/src/kernel/qgfxraster_qws.cpp
49 @@ -2673,7 +2673,6 @@
50      }
51  #endif
52      // Bresenham algorithm from Graphics Gems
53 -
54      int ax=QABS(dx)*2;
55      int ay=QABS(dy)*2;
56      int sy=dy>0 ? 1 : -1;
57 @@ -5945,6 +5944,10 @@
58  # include "qgfxmatrox_qws.cpp"
59  #endif
60  
61 +#if !defined(QT_NO_QWS_W100)
62 +# include "qgfxw100_qws.cpp"
63 +#endif
64 +
65  #if !defined(QT_NO_QWS_VFB)
66  # include "qgfxvfb_qws.cpp"
67  #endif
68 @@ -5999,6 +6002,9 @@
69  #if !defined(QT_NO_QWS_MATROX)
70      { "Matrox", qt_get_screen_matrox, 1 },
71  #endif
72 +#if !defined(QT_NO_QWS_W100)
73 +    { "W100", qt_get_screen_w100, 1 },
74 +#endif
75  #if !defined(QT_NO_QWS_TRANSFORMED)
76      { "Transformed", qt_get_screen_transformed, 0 },
77  #endif
78 @@ -6039,6 +6045,8 @@
79             qt_screen = driverTable[i].qt_get_screen( display_id );
80             if ( qt_screen ) {
81                 if ( qt_screen->connect( spec ) ) {
82 +                 printf( "[%d]:Connected to screen '%s'\n", 
83 +                         getpid(), driverTable[i].name );
84                     return qt_screen;
85                 } else {
86                     delete qt_screen;
87 --- /dev/null
88 +++ qt-2.3.10/src/3rdparty/kernel/aticore/aticore.h
89 @@ -0,0 +1,574 @@
90 +/*
91 + * AtiCore 2D acceleration API
92 + *
93 + */
94 +
95 +#include <inttypes.h>
96 +#include <sys/types.h>
97 +
98 +#ifndef __W100API_H__
99 +#define __W100API_H__
100 +
101 +#ifdef __cplusplus
102 +extern "C" {
103 +#endif
104 +
105 +#define SolidRop_GXclear       0x00    /* 0 */
106 +#define SolidRop_GXand         0xa0    /* src AND dst */
107 +#define        SolidRop_GXandReverse   0x50    /* src AND NOT dst */
108 +#define        SolidRop_GXcopy         0xf0    /* src */
109 +#define SolidRop_GXandInverted 0x0a    /* NOT src AND dst */
110 +#define        SolidRop_GXnoop         0xaa    /* dst */
111 +#define        SolidRop_GXxor          0x5a    /* src XOR dst */
112 +#define        SolidRop_GXor           0xfa    /* src OR dst */
113 +#define        SolidRop_GXnor          0x05    /* NOT src AND NOT dst */
114 +#define        SolidRop_GXequiv        0xa5    /* NOT src XOR dst */
115 +#define        SolidRop_GXinvert       0x55    /* NOT dst */
116 +#define        SolidRop_GXorReverse    0xf5    /* src OR NOT dst */
117 +#define        SolidRop_GXcopyInverted 0x0f    /* NOT src */
118 +#define        SolidRop_GXorInverted   0xaf    /* NOT src OR dst */
119 +#define        SolidRop_GXnand         0x5f    /* NOT src OR NOT dst */
120 +#define        SolidRop_GXset          0xff    /* 1 */
121 +
122 +#define        BltRop_GXclear          0x00    /* 0 */
123 +#define        BltRop_GXand            0x88    /* src AND dst */
124 +#define        BltRop_GXandReverse     0x44    /* src AND NOT dst */
125 +#define        BltRop_GXcopy           0xcc    /* src */
126 +#define        BltRop_GXandInverted    0x22    /* NOT src AND dst */
127 +#define        BltRop_GXnoop           0xaa    /* dst */
128 +#define        BltRop_GXxor            0x66    /* src XOR dst */
129 +#define        BltRop_GXor             0xee    /* src OR dst */
130 +#define        BltRop_GXnor            0x11    /* NOT src AND NOT dst */
131 +#define        BltRop_GXequiv          0x99    /* NOT src XOR dst */
132 +#define        BltRop_GXinvert         0x55    /* NOT dst */
133 +#define        BltRop_GXorReverse      0xdd    /* src OR NOT dst */
134 +#define        BltRop_GXcopyInverted   0x33    /* NOT src */
135 +#define        BltRop_GXorInverted     0xbb    /* NOT src OR dst */
136 +#define        BltRop_GXnand           0x77    /* NOT src OR NOT dst */
137 +#define        BltRop_GXset            0xff    /* 1 */
138 +
139 +#define DSTTYPE_8BPP            2   //8bpp
140 +#define DSTTYPE_16BPP_1555     3   //16 bpp aRGB 1555
141 +#define DSTTYPE_16BPP_444      5   //16 bpp aRGB 4444
142 +
143 +#define SRCTYPE_1BPP_OPA        0       //mono (expanded to frgd, bkgd)
144 +#define SRCTYPE_1BPP_TRA        1       //mono (expanded to frgd, leave_alone)
145 +#define SRCTYPE_EQU_DST         3       //color (same as DST)
146 +#define SRCTYPE_SOLID_COLOR_BLT 4       //solid color for Blt (use frgd)
147 +#define SRCTYPE_4BPP            5       //4 bpp
148 +#define SRCTYPE_12BPP_PACKED    6       //12 bpp packed
149 +  
150 +#define ROP3_SRCCOPY           0xcc
151 +#define ROP3_PATCOPY           0xf0
152 +  
153 +#define OVLTYPE_YUV420          7
154 +#define OVLTYPE_RGB565          8
155 +
156 +#define DP_BRUSH_8x8MONOOPA     0 //8x8 mono pattern (expanded to frgd, bkgd )
157 +#define DP_BRUSH_8x8MONOTRA     1 //8x8 mono pattern (expanded to frgd, leave alone )
158 +#define DP_PEN_32x1MONOOPA      6 //32x1 mono pattern (expanded to frgd, bkgd)
159 +#define DP_PEN_32x1MONOTRA      7 //32x1 mono pattern (expanded to frgd, leave alone)
160 +#define DP_BRUSH_8x8COLOR       10 //8x8 color pattern
161 +#define DP_BRUSH_SOLIDCOLOR     13 //solid color pattern (frgd)
162 +#define DB_BRUSH_NONE           15 //No brush used
163 +
164 +  typedef struct {
165 +    int16_t XCoord;
166 +    int16_t YCoord;
167 +  } ATI_POINT;
168 +  
169 +  typedef struct {
170 +    int16_t XCoord;
171 +    int16_t YCoord;
172 +    int16_t Width;
173 +    int16_t Height;
174 +  } ATI_RECT;
175 +  
176 +  typedef struct {
177 +    int16_t X_Top_Left;                  // x coordinate of top left corner
178 +    int16_t Y_Top_Left;                  // y coordinate of top left corner
179 +    int16_t X_Bottom_Right;              // x coordinate of bottom right corner
180 +    int16_t Y_Bottom_Right;              // y coordinate of bottom right corner
181 +  } ATI_CLIPRECT;
182 +  
183 +  typedef struct {
184 +    uint32_t Count; 
185 +    uint8_t ScaleXFactor;
186 +    uint8_t ScaleYFactor;
187 +    uint8_t BlendOn;
188 +    uint8_t dummy1;
189 +  } ATI_STRETCH;
190 +  
191 +  typedef struct {
192 +    uint32_t *lpSrcBitmap;                /* ¥µ¡¼¥Õ¥§¥¹¤Î¥ª¥Õ¥»¥Ã¥È */
193 +    uint16_t XCoord;                      /* +4  ³ÎÄê:¥µ¡¼¥Õ¥§¥¹Æâ¤ÎxºÂɸ */
194 +    uint16_t YCoord;                      /* +6  ³ÎÄê:¥µ¡¼¥Õ¥§¥¹Æâ¤ÎyºÂɸ */
195 +    uint16_t SrcPitch;                    /* +8  ³ÎÄê: */
196 +    uint16_t SrcHeight;                   /* +10 ³ÎÄê: */
197 +    uint16_t OverlayWidth;                /* ¥ª¡¼¥Ð¥ì¥¤¤ÎÉý(Src¤È°ã¤¦Ãͤˤ·¤Æ¤â¡¢Æ°Åª¤Ë³ÈÂç½Ì¾®¤µ¤ì¤¿¤ê¤Ï¤·¤Ê¤¤¡¢°ÕÌ£¤¢¤ó¤Î¡©) */
198 +    uint16_t OverlayHeight;
199 +    uint32_t lpOverlayKey;                /* +16 ³ÎÄê:Ææ(¥«¥é¡¼¥­¡¼¡©) */
200 +    uint8_t OverlayFormat;               /* +20 ³ÎÄê */
201 +    uint8_t dummy1;
202 +    uint16_t dummy2;
203 +  } ATI_OVERLAYPROP;                      /* 24bytes? */
204 +  
205 +  typedef struct {
206 +    int HInvert;
207 +    int VInvert;
208 +  } ATI_EXTVIDEOPROP;
209 +  
210 +  typedef struct {
211 +    ATI_EXTVIDEOPROP ExtVideoProp;
212 +  } ATI_UNKNOWN1;
213 +  
214 +  typedef struct {
215 +    unsigned long clr_cmp_fcn_src   :3;
216 +    unsigned long                   :5;
217 +    unsigned long clr_cmp_fcn_dst   :3;
218 +    unsigned long                   :13;
219 +    unsigned long clr_cmp_src       :2;
220 +    unsigned long                   :6;
221 +  } clr_cmp_cntl_t;
222 +
223 +  typedef struct {
224 +    uint16_t x;
225 +    uint16_t y;
226 +    uint16_t w;
227 +    uint16_t h;
228 +    clr_cmp_cntl_t cmp_cntl;
229 +    unsigned long tcolour;
230 +  } transbitblt_t;
231 +
232 +  typedef struct {
233 +    uint32_t dummy1;
234 +    uint32_t dummy2;
235 +    uint8_t HExpansion;                   /* +8  ³ÎÄê */
236 +    uint8_t VExpansion;                   /* +9  ³ÎÄê */
237 +    uint8_t dummy3;
238 +    uint8_t dummy4;
239 +    uint8_t RConversion;                  /* +12 ³ÎÄê */
240 +    uint8_t dummy5;
241 +    uint8_t dummy6;
242 +    uint8_t dummy7;
243 +    ATI_UNKNOWN1 x;
244 +  } ATI_EXTENDEDOVERLAYPROP;              /* 16byte? */
245 +  
246 +  /**
247 +   * AtiCore initialization.
248 +   * Sets up the shared memory area
249 +   * @return 1:success, 0:fail
250 +   */
251 +  int AtiCore_ProcessAttach( void );
252 +  
253 +  /**
254 +   * AtiCore finish.
255 +   *
256 +   * @return 1:success, 0:fail
257 +   */
258 +  int AtiCore_ProcessDetach( void );
259 +
260 +  
261 +  /**
262 +   * Allocates a surface on the internal RAM.
263 +   * Perhaps there's a way to indicate to allocate on the 
264 +   * internal RAM?
265 +   * @arg handle Reference to the returned surface handle
266 +   * @arg offset Returned offset of this surface on the video memory
267 +   * @arg size   Size (bytes) to be reserved (16 multiple)
268 +   * @arg direction 
269 +   * @return 1:success, 0:fail
270 +   */
271 +  int AtiCore_AllocateSurface( uint16_t *handle, uint32_t *offset,
272 +                              uint32_t size, uint32_t direction );
273 +  
274 +  /**
275 +   * Deallocates a given surface.
276 +   * @arg handle Handle to the allocated surface 
277 +   * (As returned by AllocateSurface)
278 +   * @return 1:success, 0:fail
279 +   */
280 +  int AtiCore_DestroySurface( uint16_t handle );
281 +
282 +  /**
283 +   * Sets the kind of Raster Operation.
284 +   * @param rop Raster operation to be performed
285 +   * @return 1:success, 0:fail
286 +   */
287 +  int AtiCore_SetRopOperation( uint32_t rop );
288 +  
289 +  /**
290 +   * Sets the destination type for raster operation.
291 +   * @param dsttype
292 +   * @return 1:success, 0:fail
293 +   */
294 +  int AtiCore_SetDstType( uint32_t dsttype );
295 +  
296 +  /**
297 +   * Sets the source type for raster operation.
298 +   * @param srctype
299 +   * @return 1:success, 0:fail
300 +   */
301 +  int AtiCore_SetSrcType( uint32_t srctype );
302 +  
303 +  /**
304 +   * Sets Source clipping rectangle.
305 +   * @param cliprect Rectangle to perform clipping.
306 +   * @return 1:success, 0:fail
307 +   */ 
308 +  int AtiCore_SetSrcClippingRect( ATI_CLIPRECT *cliprect );
309 +  
310 +  /**
311 +   * Sets Destination clipping rectangle.
312 +   * @param cliprect Rectangle to perform clipping.
313 +   * @return 1:success, 0:fail
314 +   */ 
315 +  int AtiCore_SetDstClippingRect(ATI_CLIPRECT *cliprect);
316 +  
317 +  /**
318 +   * Sets pitch and offset for source in a raster operation.
319 +   * @param pitch Pitch (line width) of source
320 +   * @param offset Offset of source
321 +   * @return 1:success, 0:fail
322 +   */
323 +  int AtiCore_SetSrcPitchOffset( int pitch, int offset );
324 +  
325 +  /**
326 +   * Sets pitch and offset destination source in a raster operation.
327 +   * @param pitch Pitch (line width) of destination
328 +   * @param offset Offset of destination (memory offset)
329 +   * @return 1:success, 0:fail
330 +   */
331 +  int AtiCore_SetDstPitchOffset( int pitch, int offset );
332 +  
333 +  /**
334 +   * Performs a BitBlt with source rotation.
335 +   * @param flags Rotation degree
336 +   * @param dstRect Rectangle for destination Bitblitting
337 +   * @param srcRect Rectangle for origin bitblitting
338 +   * @test Tested with specified flags parameter
339 +   */
340 +  int AtiCore_BitBltFilpRotate( int flags,
341 +                               ATI_RECT *dstRect, 
342 +                               ATI_RECT *srcRect);
343 +  
344 +  /**
345 +   * Performs a BitBlt with source stretching.
346 +   * @param option Unknown
347 +   * @param point Unknown
348 +   * @param srcRect Source blitting surface
349 +   * @test Untested
350 +   */
351 +  int AtiCore_StretchBlt( ATI_STRETCH *option,
352 +                         ATI_POINT *point, 
353 +                         ATI_RECT *srcRect);
354 +  
355 +  /**
356 +   * Waits for the FIFO to be idle at least msecs.
357 +   * @param msecs Maximum time to wait for FIFO to idle
358 +   * @return 1:success, 0:fail
359 +   * @test Untested
360 +   */
361 +  int AtiCore_WaitComplete( int msec );
362 +
363 +  /**
364 +   * Allocates a new overlay handle.
365 +   * @param   handle overlay
366 +   * @return  1:success, 0:fail
367 +   * @test Yes
368 +   */
369 +  int AtiCore_AllocOverlay( uint16_t *handle );
370 +
371 +  /**
372 +   * Deallocates a overlay handle.
373 +   * @param  handle overlay
374 +   * @return 1:success, 0:fail
375 +   * @test Yes
376 +   */
377 +  int AtiCore_ReleaseOverlay( uint16_t handle );
378 +
379 +  /**
380 +   * Sets up an overlay given a handle an a set of properties.
381 +   * @param handle Allocated handle to setup the overlay.
382 +   * @param props Overlay properties struct
383 +   * @return 1:success, 0:fail
384 +   */
385 +  int AtiCore_SetupOverlay( uint16_t handle, ATI_OVERLAYPROP *props );
386 +
387 +  /**
388 +   * Sets up extended overlay features.
389 +   * @param handle Allocated handle to an overlay
390 +   * @param props Extended overlay properties
391 +   * @return 1:success, 0:fail
392 +   */
393 +  int AtiCore_SetupOverlayExtended( uint16_t handle, 
394 +                                   ATI_EXTENDEDOVERLAYPROP *props );
395 +
396 +  /**
397 +   * Enable/Disable an overlayed surface.
398 +   * @param   handle Overlay to be enabled/disabled
399 +   * @param   enable 1: Enable, 0: Disable
400 +   * @return  1:success, 0:fail
401 +   * @test Tested
402 +   */
403 +  int AtiCore_SetOverlayOnOff( uint16_t handle, int enable );
404 +
405 +  /**
406 +   * Sets up the overlay position for a given handle.
407 +   * @param handle Overlay Handle
408 +   * @param x X Coordinate (Seems to be a bug with x < 4 )
409 +   * @param y Y Coordinate
410 +   * @return 1:success, 0:fail
411 +   */
412 +  int AtiCore_SetOverlayPos( uint16_t handle, 
413 +                            uint16_t x, 
414 +                            uint16_t y );
415 +
416 +  /**
417 +   * Translates between physical/virtual addresses.
418 +   * @param offset VRAM offset to be translated
419 +   * @param viraddr Virtual address for VRAM
420 +   * @return 1:success,0:fail
421 +   */
422 +  int AtiCore_SetupMemoryTransfer( uint32_t offset, 
423 +                                  uint32_t *viraddr );
424 +
425 +  /**
426 +   * Related with the previous one. It seems to be necesary to be called
427 +   * but I'm not sure of its function.
428 +   * @return 1:success, 0:fail
429 +   */
430 +  int AtiCore_TerminateMemoryTransfer( void );
431 +
432 +  /**
433 +   * Returns the frontbuffer pitch and offset.
434 +   * @param pitch Return value for the frontbuffer pitch (width)
435 +   * @param offset Return value for the frontbuffer offset
436 +   * @return 1:success, 0:fail
437 +   */
438 +  int AtiCore_GetFrontBufferPitchOffset( uint32_t *pitch, 
439 +                                        uint32_t *offset );
440 +
441 +  /**
442 +   * Changes display brighness ?
443 +   * @param  brightness  -64...63
444 +   * @return 1:success, 0:fail
445 +   */
446 +  int AtiCore_SetDisplayBrightness( int brightness );
447 +
448 +  /**
449 +   * Returns the amount of available internal/external memory.
450 +   * @param  internal Pointer to return internal memory size
451 +   * @param  external Pointer to return external memory size
452 +   * @return 1:success, 0:fail
453 +   */
454 +  int GetAvailableVideoMem( uint32_t *internal, 
455 +                           uint32_t *external );
456 +
457 +/**
458 + *
459 + * 
460 + *
461
462 + {
463 +    (uint32_t) 0
464 +    (uint32_t) 0
465 +    (uint16_t) 480
466 +    (uint16_t) 640
467 +    (uint16_t) 480
468 +    (uint16_t) 640
469 +    (uint32_t) 5
470 + */
471 +
472 +  typedef struct {
473 +    uint32_t   dummy1;
474 +    ATI_RECT   Size;
475 +    uint16_t   Width;
476 +    uint16_t   Height;
477 +    uint32_t   Flag;
478 +  } ATI_GRAPHICWINDOW;
479
480 + int AtiCore_SetupGraphicWindow(void* );
481 +
482 +  /**
483 +   * It seems to be necessary after AtiCore_ProcessAttach
484 +   * @param mode: 0xaaab for portrait, 0xaaaa for landscape
485 +   * @return 1:success, 0:fail
486 +   */
487 +  int AtiCore_ProcessAttachSpecialMode( int mode );
488 +
489 +  /**
490 +   * Detach from the special mode. Whatever it means.
491 +   * @return 1:success, 0:fail
492 +   */
493 +  int AtiCore_ProcessDetachSpecialMode( void );
494 +
495 +  /**
496 +   * Sets up the position of the Graphic viewport ?
497 +   * @param x X coordinate
498 +   * @param y Y coordinate
499 +   * @return 1:success, 0:fail
500 +   */
501 +  int AtiCore_SetGraphicWindowPos( int x, int y );
502 +
503 +  /**
504 +   * Get the graphic viewport position.
505 +   * @param x Pointer to xcoord placeholder
506 +   * @param y Pointer to ycoord placeholder
507 +   * @return 1:success, 0:fail
508 +   */
509 +  int AtiCore_GetGraphicWindowPos( int *x, int *y );
510 +
511 +  /**
512 +   * Sets up the frontbuffer position.
513 +   * @param offset VRAM offset to be used.
514 +   * @param x X Coordinate?
515 +   * @param y Y Coordinate?
516 +   * @return 1:success, 0:fail
517 +   */
518 +  int AtiCore_SetFrontBuffer( int offset, int x, int y );
519 +
520 +  /**
521 +   * Enable/Disable the frontbuffer?
522 +   * @param enable 1 enables/ 0 disables
523 +   * @return 1:success, 0:fail
524 +   */
525 +  int AtiCore_SetGraphicWindowOnOff( int enable );
526 +
527 +  /*
528 +   * Sets the foreground color.
529 +   * @param colour Color in 565 format (perhaps depends on the source format)
530 +   * @return 1:success, 0:fail
531 +   */
532 +  int AtiCore_SetFrgColour( int colour );
533 +
534 +  /*
535 +   * Sets the background colour.
536 +   * @param colour Colour in 565 format (perhaps depends on the source format)
537 +   * @return 1:success, 0:fail
538 +   */
539 +  int AtiCore_SetBkgColour( int colour );
540 +  
541 +  /**
542 +   * Changes the painting brush
543 +   * @param btype Type of brush to use
544 +   *        4: Uses the pattern
545 +   *        6: SolidLine
546 +   * @param pattern Pointer to a 32 bit pattern
547 +   * @return 1:success, 0:fail
548 +   * @test Some values for btype produces a kind of antialiasing line
549 +   */
550 +  int AtiCore_BrushType( int btype, unsigned int *pattern );
551 +
552 +  /**
553 +   * Performs a rectangle paint.
554 +   * @param nrects Number of rectangles to be painted
555 +   * @param rects Array of rectangles to be painted
556 +   * @return 1:success, 0:fail
557 +   * @test Tested with nrects==1
558 +   */
559 +  int AtiCore_PaintRect( int nrects , 
560 +                        ATI_RECT rects[] );
561 +
562 +  /**
563 +   * Draws a set of lines.
564 +   * @param npoints Number of points in the polyline set
565 +   * @param points  Pointer to an array of ATI_POINT
566 +   * @return 1:success, 0:fail
567 +   */
568 +  int AtiCore_Polyline( int npoints, ATI_POINT points[] );
569 +
570 +  int AtiCore_GetPitchOffsetProperty( void *, void *);
571 +
572 +  int AtiCore_CursorOnOff( int, int );
573 +
574 +  /**
575 +   * Performs a BitBlt ROP operation.
576 +   * @param unk Unknown (Always set to 1)
577 +   * @param dstrect Bounding destination rect
578 +   * @param srcrect Bounding source rect
579 +   * @return 1:success, 0:fail
580 +   */
581 +  int AtiCore_BitBlt( int unk, 
582 +                     ATI_RECT *dstrect, 
583 +                     ATI_RECT *srcrect );
584 +
585 +  /**
586 +   * Performs a Transparent BitBlt ROP operation.
587 +   * @param dstrect Transparent DstRect bitblt argument
588 +   * @param srcrect Transparent SrcRect bitblt argument
589 +   * @return 1:success, 0:fail
590 +   * @test Doesn't work. It sets to zero CLR_CMP_CNTL and CLR_CMP_MSK
591 +   */
592 +  int AtiCore_TransBitBlt( transbitblt_t *dstrect,
593 +                          transbitblt_t *srcrect );
594 +
595 +  int AtiCore_WakeUpCall( void );
596 +
597 +  /**
598 +   * Draws a set of pixels
599 +   * @param npoints Number of points to draw
600 +   * @param points Pointer to an array of ATI_POINT
601 +   * @return 1:success, 0:fail
602 +   */
603 +  int AtiCore_DrawPixel( int npoints, ATI_POINT *points );
604 +
605 +  int AtiCore_SetSysClk( unsigned short in0 );
606 +  int AtiCore_SetFastSysClk( unsigned short in0 );
607 +  int AtiCore_SetSlowSysClk( unsigned short in0 );
608 +
609 +  int AtiCore_GetCursorPos( unsigned long in0,
610 +                           unsigned short *x,
611 +                           unsigned short *y );
612 +  
613 +
614 +
615 +/* ================================================================ */
616 +/* from libqte.so.2.3.2 */
617 +/*
618 +AtiCore_AlphaBlend
619 +
620 +AtiCore_Flush
621 +AtiCore_GammaCorrection
622 +AtiCore_GetCRC
623 +AtiCore_GetCursorPos
624 +AtiCore_GetDeviceInfo
625 +AtiCore_GetGPIO_Data
626 +AtiCore_GetGraphicExtended
627 +AtiCore_GetGraphicWindowPos
628 +AtiCore_GetLargestVideoMemBlock
629 +AtiCore_GetLastError
630 +AtiCore_GetMultiCRC
631 +AtiCore_GetOverlayPos
632 +AtiCore_Host
633 +AtiCore_LoadCursorBitMap
634 +AtiCore_PolyScanline
635 +AtiCore_ProcessAttachMinimal(void)?
636 +AtiCore_ProcessDetachMinimal(void)?
637 +AtiCore_ProcessDetachSpecialMode
638 +AtiCore_ReadCfgReg
639 +AtiCore_ReadMem(int, int)?
640 +AtiCore_ReadReg(int, int)?
641 +AtiCore_ScanlineShading
642 +AtiCore_SetApertures
643 +AtiCore_SetBytePixelOrder
644 +AtiCore_SetCursorPos
645 +AtiCore_SetDisplayParameters
646 +AtiCore_SetDriverBehaviour
647 +AtiCore_SetGPIO_Data
648 +AtiCore_SetOverlayPosUsingGraphicWindowXY
649 +AtiCore_SetPartialCursor
650 +AtiCore_SetupGraphicExtended
651 +AtiCore_SetupPM4
652 +AtiCore_SmallText
653 +AtiCore_SubmitPM4Packet
654 +AtiCore_WriteCfgReg
655 +AtiCore_WriteMem
656 +AtiCore_WriteReg
657 + */
658 +
659 +#ifdef __cplusplus
660 +}
661 +#endif
662 +
663 +#endif
664 --- /dev/null
665 +++ qt-2.3.10/src/kernel/qgfxw100_qws.cpp
666 @@ -0,0 +1,2709 @@
667 + /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil -*- */
668 +/***************************************************************************
669 +
670 +** Imageon driver for qte using libAticore
671 +** Manuel Teira( 2005 )
672 +** BUGS
673 +*  - Enable again internal memory surfaces.
674 +****************************************************************************/
675 +#include <unistd.h>
676 +#include <stdio.h>
677 +#include <stdlib.h>
678 +#include <errno.h>
679 +#include <string.h>
680 +#include <dirent.h>
681 +#include <fcntl.h>
682 +#include <sys/types.h>
683 +#include <sys/mman.h>
684 +#include <sys/time.h>
685 +#include <time.h>
686 +
687 +#include <sys/ipc.h>
688 +#include <sys/shm.h>
689 +
690 +#include <qapplication.h>
691 +
692 +#ifndef __sparc__
693 +#include <sys/io.h>
694 +#endif
695 +
696 +#include "qgfxraster_qws.h"
697 +#include "qgfxlinuxfb_qws.h"
698 +#include <aticore/aticore.h>
699 +
700 +#include <stdarg.h>
701 +
702 +class W100Driver {
703 +public:
704 +
705 +    typedef enum Loglevel {
706 +        ERROR = 0,
707 +        WARNING,
708 +        INFO
709 +    };
710 +
711 +    typedef enum Opcodes {
712 +        DRAWLINE = 0,
713 +        DRAWPOINT,
714 +        DRAWPOINTS,
715 +        FILLRECT,
716 +        SCROLL,
717 +        BITBLT,
718 +        POLYLINE,
719 +        EOO
720 +    };
721 +
722 +    typedef enum Retcodes {
723 +        codOK,
724 +        codError
725 +    };
726 +        
727 +
728 +    typedef struct Opcode {
729 +        QString str;
730 +        int index;
731 +        bool accelerated;
732 +        int hits;
733 +        int misses;
734 +    };
735 +
736 +    static Opcode lOpcodes[];
737 +
738 +    static QString level2str( int level )
739 +    {
740 +        switch( level ) {
741 +        case ERROR:
742 +            return QString( "ERROR" );
743 +            break;
744 +        case WARNING:
745 +            return QString( "WARNING" );
746 +            break;
747 +        case INFO:
748 +            return QString( "INFO" );
749 +            break;
750 +        default:
751 +            return QString( "UNKNOWN" );
752 +            break;
753 +        }
754 +    }
755 +
756 +    W100Driver():
757 +        m_loglevel( 0 ),
758 +        m_logenabled( 0 ),
759 +        m_logcount( 0 ),
760 +        m_attached( false )
761 +    {
762 +        m_pid = getpid();
763 +        m_loglevel = 0;
764 +        char *var;
765 +        if ( var = getenv( "W100_DEBUG" ) ) {
766 +            if ( strtol( var, 0, 0 ) == 1 ) {
767 +                m_logenabled = 1;
768 +            }
769 +        }
770 +
771 +        if ( m_logenabled ) {
772 +            if ( var = getenv( "W100_DEBUGLEVEL" ) ) {
773 +                if ( ( m_loglevel = strtol( var, 0, 0 ) ) < 0 ) {
774 +                    m_loglevel = 0;
775 +                }
776 +            }
777 +
778 +            QString path( "/mnt/card/w100/w100debug.log" );
779 +            if ( var = getenv( "W100_DEBUGPATH" ) ) {
780 +                path = QString( var ) + "/w100debug.log";
781 +            } 
782 +            m_logfile = fopen( path.latin1(), "a" );
783 +            if ( m_logfile == NULL ) m_logenabled = 0;
784 +        }
785 +
786 +        Opcode *opcodePtr = lOpcodes;
787 +        while ( opcodePtr->index != EOO ) {
788 +            QString varName = "W100_ACCEL_" + opcodePtr->str;
789 +            char *varPtr;
790 +            if ( ( varPtr = getenv( varName.latin1() ) )  ) {
791 +                if ( ( strtol( varPtr, NULL, 0 ) == 0 ) ||
792 +                     ( strcmp( varPtr, "false" ) == 0 ) )  {
793 +                    opcodePtr->accelerated = false;
794 +                }
795 +            }
796 +            opcodePtr++;
797 +        }
798 +    }
799 +
800 +    ~W100Driver()
801 +    {
802 +        //Dump statistics about any opcode
803 +        Opcode *opcodePtr = lOpcodes;
804 +        while ( opcodePtr->index != EOO ) {
805 +            log( WARNING, "Opcode %s. Accelerated=%s. Hits=%d. Misses=%d",
806 +                 opcodePtr->str.latin1(),
807 +                 opcodePtr->accelerated ? "true" : "false",
808 +                 opcodePtr->hits,
809 +                 opcodePtr->misses );
810 +            opcodePtr++;
811 +        }
812 +        if ( m_logenabled && m_logfile ) {
813 +            fclose( m_logfile );
814 +        }
815 +    }
816 +
817 +    bool accelerated( int opcode )
818 +    {
819 +        if ( !m_attached ) {
820 +            log( WARNING, "Asking for accelerated '%s' when not attached",
821 +                 lOpcodes[opcode].str.latin1() );
822 +            return false;
823 +        }
824 +        if ( opcode < EOO ) {
825 +            if ( lOpcodes[opcode].accelerated ) {
826 +                return true;
827 +            } else {
828 +                log( WARNING, "Not accelerated '%s'",
829 +                     lOpcodes[opcode].str.latin1() );
830 +                return false;
831 +            }
832 +        }
833 +        return false;
834 +    }
835 +
836 +    void addHit( int opcode )
837 +    {
838 +        lOpcodes[opcode].hits++;
839 +    }
840 +
841 +    void addMiss( int opcode )
842 +    {
843 +        lOpcodes[opcode].misses++;
844 +    }
845 +
846 +    void log( int level, const char *fmt, ... )
847 +    {
848 +        if ( m_logenabled && ( level <= m_loglevel ) ) {
849 +            timeval tv;
850 +            char buffer[1024];
851 +            va_list ap;
852 +            va_start( ap, fmt );
853 +            vsnprintf( buffer, 1023, fmt, ap );
854 +            va_end( ap );
855 +            gettimeofday( &tv, NULL );
856 +            fprintf( m_logfile, "(%010u.%06u)%d:%d:%s:%s\n", 
857 +                     tv.tv_sec, tv.tv_usec,
858 +                     m_logcount++, 
859 +                     m_pid,
860 +                     level2str( level ).latin1(), 
861 +                     buffer );
862 +            fflush( m_logfile );
863 +        }
864 +    }
865 +
866 +    bool attached( void ) const
867 +    {
868 +        return m_attached;
869 +    }
870 +
871 +    int processAttach( void )
872 +    {
873 +        if ( !m_attached ) {
874 +            if ( AtiCore_ProcessAttach() ) {
875 +                log( WARNING, "Process attached succesfully" );
876 +                m_attached = true;
877 +                return codOK;
878 +            } else {
879 +                log( WARNING, "Error attaching process" );
880 +            }
881 +        } else {
882 +            log( WARNING, "Process already attached" );
883 +        }
884 +        return codError;
885 +    }
886 +
887 +    int processDetach( void )
888 +    {
889 +        if ( m_attached ) {
890 +            if ( AtiCore_ProcessDetach() ) {
891 +                log( WARNING, "Process detached succesfully" );
892 +                m_attached = false;
893 +                return codOK;
894 +            } else {
895 +                log( WARNING, "Error detaching process" );
896 +            }
897 +        } else {
898 +            log( WARNING, "Trying to detach while not attached" );
899 +        }
900 +        return codError;
901 +    }
902 +
903 +    int allocateSurface( uint16_t *handle, uint32_t *offset,
904 +                              uint32_t size, uint32_t direction )
905 +    {
906 +        if ( m_attached ) {
907 +            if ( AtiCore_AllocateSurface( handle, offset, 
908 +                                          size, direction ) ) {
909 +                return codOK;
910 +            } else {
911 +                log( ERROR, "Error in allocateSurface" );
912 +            }
913 +        } else {
914 +            log( WARNING, "Trying to allocateSurface while not attached" );
915 +        }
916 +        return codError;
917 +    }
918 +
919 +    int destroySurface( uint16_t handle )
920 +    {
921 +        if ( m_attached ) {
922 +            if ( AtiCore_DestroySurface( handle ) ) {
923 +                return codOK;
924 +            } else {
925 +                log( ERROR, "Error in destroySurface" );
926 +            }
927 +        } else {
928 +            log( WARNING, "Trying to destroySurface while not attached" );
929 +        }
930 +        return codError;
931 +    }
932 +
933 +    int drawPixel( int npoints, ATI_POINT *points )
934 +    {
935 +        if ( m_attached ) {
936 +            if ( AtiCore_DrawPixel( npoints, points ) ) {
937 +                return codOK;
938 +            } else {
939 +                log( ERROR, "Error in drawPixel" );
940 +            }
941 +        } else {
942 +            log( WARNING, "Trying to drawPixel while not attached" );
943 +        }
944 +        return codError;
945 +    }
946 +
947 +    int setRopOperation( uint32_t rop )
948 +    {
949 +        if ( m_attached ) {
950 +            if ( AtiCore_SetRopOperation( rop ) ) {
951 +                return codOK;
952 +            } else {
953 +                log( ERROR, "Error in setRopOperation" );
954 +            }
955 +        } else {
956 +            log( WARNING, "Trying to setRopOperation while not attached" );
957 +        }
958 +        return codError;
959 +    }
960 +
961 +    int setDstType( uint32_t dtype )
962 +    {
963 +        if ( m_attached ) {
964 +            if ( AtiCore_SetDstType( dtype ) ) {
965 +                return codOK;
966 +            } else {
967 +                log( ERROR, "Error in setDstType" );
968 +            }
969 +        } else {
970 +            log( WARNING, "Trying to setDstType while not attached" );
971 +        }
972 +        return codError;
973 +    }
974 +
975 +    int setSrcType( uint32_t stype )
976 +    {
977 +        if ( m_attached ) {
978 +            if ( AtiCore_SetSrcType( stype ) ) {
979 +                return codOK;
980 +            } else {
981 +                log( ERROR, "Error in setSrcType" );
982 +            }
983 +        } else {
984 +            log( WARNING, "Trying to setSrcType while not attached" );
985 +        }
986 +        return codError;
987 +    }
988 +
989 +    int setSrcClippingRect( ATI_CLIPRECT *cliprect )
990 +    {
991 +        if ( m_attached ) {
992 +            if ( AtiCore_SetSrcClippingRect( cliprect ) ) {
993 +                return codOK;
994 +            } else {
995 +                log( ERROR, "Error in setSrcClippingRect" );
996 +            }
997 +        } else {
998 +            log( WARNING, "Trying to setSrcClippingRect while not attached" );
999 +        }
1000 +        return codError;
1001 +    }
1002 +
1003 +    int setDstClippingRect( ATI_CLIPRECT *cliprect )
1004 +    {
1005 +        if ( m_attached ) {
1006 +            if ( AtiCore_SetDstClippingRect( cliprect ) ) {
1007 +                return codOK;
1008 +            } else {
1009 +                log( ERROR, "Error in setDstClippingRect" );
1010 +            }
1011 +        } else {
1012 +            log( WARNING, "Trying to setDstClippingRect while not attached" );
1013 +        }
1014 +        return codError;
1015 +    }
1016 +
1017 +    int setSrcPitchOffset( int pitch, int offset )
1018 +    {
1019 +        if ( m_attached ) {
1020 +            if ( AtiCore_SetSrcPitchOffset( pitch, offset ) ) {
1021 +                return codOK;
1022 +            } else {
1023 +                log( ERROR, "Error in setSrcPitchOffset" );
1024 +            }
1025 +        } else {
1026 +            log( WARNING, "Trying to setSrcPitchOffset while not attached" );
1027 +        }
1028 +        return codError;
1029 +    }
1030 +
1031 +    int setDstPitchOffset( int pitch, int offset )
1032 +    {
1033 +        if ( m_attached ) {
1034 +            if ( AtiCore_SetDstPitchOffset( pitch, offset ) ) {
1035 +                return codOK;
1036 +            } else {
1037 +                log( ERROR, "Error in setDstPitchOffset" );
1038 +            }
1039 +        } else {
1040 +            log( WARNING, "Trying to setDstPitchOffset while not attached" );
1041 +        }
1042 +        return codError;
1043 +    }
1044 +
1045 +    int bitBltFlipRotate( int rot, 
1046 +                          ATI_RECT *dstRect,
1047 +                          ATI_RECT *srcRect )
1048 +    {
1049 +        if ( m_attached ) {
1050 +            if ( AtiCore_BitBltFilpRotate( rot, dstRect, srcRect ) ) {
1051 +                return codOK;
1052 +            } else {
1053 +                log( ERROR, "Error in bitBltFlipRotate" );
1054 +            }
1055 +        } else {
1056 +            log( WARNING, "Trying to bitBltFlipRotate while not attached" );
1057 +        }
1058 +        return codError;
1059 +    }
1060 +
1061 +    int stretchBlt( ATI_STRETCH *option,
1062 +                    ATI_POINT *point,
1063 +                    ATI_RECT *srcRect )
1064 +    {
1065 +        if ( m_attached ) {
1066 +            if ( AtiCore_StretchBlt( option, point, srcRect ) ) {
1067 +                return codOK;
1068 +            } else {
1069 +                log( ERROR, "Error in stretchBlt" );
1070 +            }
1071 +        } else {
1072 +            log( WARNING, "Trying to stretchBlt while not attached" );
1073 +        }
1074 +        return codError;
1075 +    }
1076 +
1077 +    int waitComplete( int msec )
1078 +    {
1079 +        if ( m_attached ) {
1080 +            if ( AtiCore_WaitComplete( msec ) ) {
1081 +                return codOK;
1082 +            } else {
1083 +                log( ERROR, "Error in waitComplete" );
1084 +            }
1085 +        } else {
1086 +            log( WARNING, "Trying to waitComplete while not attached" );
1087 +        }
1088 +        return codError;
1089 +    }
1090 +
1091 +    int allocOverlay( uint16_t *handle ) 
1092 +    {
1093 +        if ( m_attached ) {
1094 +            if ( AtiCore_AllocOverlay( handle ) ) {
1095 +                return codOK;
1096 +            } else {
1097 +                log( ERROR, "Error in allocOverlay" );
1098 +            }
1099 +        } else {
1100 +            log( WARNING, "Trying to allocOverlay while not attached" );
1101 +        }
1102 +        return codError;
1103 +    }
1104 +
1105 +    int releaseOverlay( uint16_t handle )
1106 +    {
1107 +        if ( m_attached ) {
1108 +            if ( AtiCore_ReleaseOverlay( handle ) ) {
1109 +                return codOK;
1110 +            } else {
1111 +                log( ERROR, "Error in releaseOverlay" );
1112 +            }
1113 +        } else {
1114 +            log( WARNING, "Trying to releaseOverlay while not attached" );
1115 +        }
1116 +        return codError;
1117 +    }
1118 +
1119 +    int setupOverlay( uint16_t handle, ATI_OVERLAYPROP *prop )
1120 +    {
1121 +        if ( m_attached ) {
1122 +            if ( AtiCore_SetupOverlay( handle, prop ) ) {
1123 +                return codOK;
1124 +            } else {
1125 +                log( ERROR, "Error in setupOverlay" );
1126 +            }
1127 +        } else {
1128 +            log( WARNING, "Trying to setupOverlay while not attached" );
1129 +        }
1130 +        return codError;
1131 +    }
1132 +
1133 +    int setupOverlayExtended( uint16_t handle, 
1134 +                                   ATI_EXTENDEDOVERLAYPROP *prop )
1135 +    {
1136 +        if ( m_attached ) {
1137 +            if ( AtiCore_SetupOverlayExtended( handle, prop ) ) {
1138 +                return codOK;
1139 +            } else {
1140 +                log( ERROR, "Error in setupOverlayExtended" );
1141 +            }
1142 +        } else {
1143 +            log( WARNING, "Trying to setupOverlayExtended while not attached" );
1144 +        }
1145 +        return codError;
1146 +    }
1147 +
1148 +    int setOverlayOnOff( uint16_t handle, int isShow )
1149 +    {
1150 +        if ( m_attached ) {
1151 +            if ( AtiCore_SetOverlayOnOff( handle, isShow ) ) {
1152 +                return codOK;
1153 +            } else {
1154 +                log( ERROR, "Error in setOverlayOnOff" );
1155 +            }
1156 +        } else {
1157 +            log( WARNING, "Trying to setOverlayOnOff while not attached" );
1158 +        }
1159 +        return codError;
1160 +    }
1161 +
1162 +    int setOverlayPos( uint16_t handle, uint16_t x, uint16_t y )
1163 +    {
1164 +        if ( m_attached ) {
1165 +            if ( AtiCore_SetOverlayPos( handle, x, y ) ) {
1166 +                return codOK;
1167 +            } else {
1168 +                log( ERROR, "Error in setOverlayPos" );
1169 +            }
1170 +        } else {
1171 +            log( WARNING, "Trying to setOverlayPos while not attached" );
1172 +        }
1173 +        return codError;
1174 +    }
1175 +
1176 +    int setupMemoryTransfer( uint32_t offset, uint32_t *regdata )
1177 +    {
1178 +        if ( m_attached ) {
1179 +            if ( AtiCore_SetupMemoryTransfer( offset, regdata ) ) {
1180 +                return codOK;
1181 +            } else {
1182 +                log( ERROR, "Error in setupMemoryTransfer" );
1183 +            }
1184 +        } else {
1185 +            log( WARNING, "Trying to setupMemoryTransfer while not attached" );
1186 +        }
1187 +        return codError;
1188 +    }
1189 +
1190 +    int terminateMemoryTransfer( void )
1191 +    {
1192 +        if ( m_attached ) {
1193 +            if ( AtiCore_TerminateMemoryTransfer() ) {
1194 +                return codOK;
1195 +            } else {
1196 +                log( ERROR, "Error in terminateMemoryTransfer" );
1197 +            }
1198 +        } else {
1199 +            log( WARNING, "Trying to terminateMemoryTransfer while not attached" );
1200 +        }
1201 +        return codError;
1202 +    }
1203 +
1204 +    int getFrontBufferPitchOffset( uint32_t *pitch, uint32_t *offset )
1205 +    {
1206 +        if ( m_attached ) {
1207 +            if ( AtiCore_GetFrontBufferPitchOffset( pitch, offset ) ) {
1208 +                return codOK;
1209 +            } else {
1210 +                log( ERROR, "Error in getFrontBufferPitchOffset" );
1211 +            }
1212 +        } else {
1213 +            log( WARNING, "Trying to getFrontBufferPitchOffset while not attached" );
1214 +        }
1215 +        return codError;
1216 +    }
1217 +
1218 +    int setDisplayBrightness( int bri )
1219 +    {
1220 +        if ( m_attached ) {
1221 +            if ( AtiCore_SetDisplayBrightness( bri ) ) {
1222 +                return codOK;
1223 +            } else {
1224 +                log( ERROR, "Error in setDisplayBrightness" );
1225 +            }
1226 +        } else {
1227 +            log( WARNING, "Trying to setDisplayBrighness while not attached" );
1228 +        }
1229 +        return codError;
1230 +    }
1231 +
1232 +    int getAvailableVideoMem( uint32_t *internal, uint32_t *external )
1233 +    {
1234 +        if ( m_attached ) {
1235 +            if ( GetAvailableVideoMem( internal, external ) ) {
1236 +                return codOK;
1237 +            } else {
1238 +                log( ERROR, "Error in getAvailableVideoMem" );
1239 +            }
1240 +        } else {
1241 +            log( WARNING, "Trying to getAvailableVideoMem while not attached" );
1242 +        }
1243 +        return codError;
1244 +    }
1245 +
1246 +    int setupGraphicWindow( ATI_GRAPHICWINDOW *win )
1247 +    {
1248 +        if ( m_attached ) {
1249 +            if ( AtiCore_SetupGraphicWindow( ( void * ) win ) ) {
1250 +                return codOK;
1251 +            } else {
1252 +                log( ERROR, "Error in setupGraphicWindow" );
1253 +            }
1254 +        } else {
1255 +            log( WARNING, "Trying to setupGraphicWindow while not attached" );
1256 +        }
1257 +        return codError;
1258 +    }
1259 +
1260 +    int processAttachSpecialMode( int mode )
1261 +    {
1262 +        if ( m_attached ) {
1263 +            if ( AtiCore_ProcessAttachSpecialMode( mode ) ) {
1264 +                return codOK;
1265 +            } else {
1266 +                log( ERROR, "Error in processAttachSpecialMode" );
1267 +            }
1268 +        } else {
1269 +            log( WARNING, "Trying to processAttachSpecialMode while not attached" );
1270 +        }
1271 +        return codError;
1272 +    }
1273 +
1274 +    int processDetachSpecialMode( void )
1275 +    {
1276 +        if ( m_attached ) {
1277 +            if ( AtiCore_ProcessDetachSpecialMode() ) {
1278 +                return codOK;
1279 +            } else {
1280 +                log( ERROR, "Error in processDetachSpecialMode" );
1281 +            }
1282 +        } else {
1283 +            log( WARNING, "Trying to processDetachSpecialMode while not attached" );
1284 +        }
1285 +        return codError;
1286 +    }
1287 +
1288 +    int setGraphicWindowPos( int x, int y )
1289 +    {
1290 +        if ( m_attached ) {
1291 +            if ( AtiCore_SetGraphicWindowPos( x, y ) ) {
1292 +                return codOK;
1293 +            } else {
1294 +                log( ERROR, "Error in setGraphicWindowPos" );
1295 +            }
1296 +        } else {
1297 +            log( WARNING, "Trying to setGraphicWindow while not attached" );
1298 +        }
1299 +        return codError;
1300 +    }
1301 +
1302 +    int setFrontBuffer( int offset, int a, int b )
1303 +    {
1304 +        if ( m_attached ) {
1305 +            if ( AtiCore_SetFrontBuffer( offset, a, b ) ) {
1306 +                return codOK;
1307 +            } else {
1308 +                log( ERROR, "Error in setFrontBuffer" );
1309 +            }
1310 +        } else {
1311 +            log( WARNING, "Trying to setFrontBuffer while not attached" );
1312 +        }
1313 +        return codError;
1314 +    }
1315 +
1316 +    int setGraphicWindowOnOff( int val )
1317 +    {
1318 +        if ( m_attached ) {
1319 +            if ( AtiCore_SetGraphicWindowOnOff( val ) ) {
1320 +                return codOK;
1321 +            } else {
1322 +                log( ERROR, "Error in setGraphicWindowOnOff" );
1323 +            }
1324 +        } else {
1325 +            log( WARNING, "Trying to setGraphicWindowOnOff while not attached" );
1326 +        }
1327 +    }
1328 +
1329 +    static unsigned long ccolor( unsigned int rgb )
1330 +    {
1331 +        unsigned char r = ( rgb & 0xff0000 ) >> 19;
1332 +        unsigned char g = ( rgb & 0xff00 ) >> 10;
1333 +        unsigned char b = ( rgb & 0xff ) >> 3;
1334 +        return ( ( ( ( unsigned short )0x1f & r ) << 11 ) |
1335 +                 ( ( ( unsigned short )0x3f & g ) << 5 ) |
1336 +                 ( ( ( unsigned short )0x1f & b ) )  ); 
1337 +    }
1338 +
1339 +    int setFrgColour( int val )
1340 +    {
1341 +        if ( m_attached ) {
1342 +            if ( AtiCore_SetFrgColour( ccolor( val ) ) ) {
1343 +                return codOK;
1344 +            } else {
1345 +                log( ERROR, "Error in setFrgColour" );
1346 +            }
1347 +        } else {
1348 +            log( WARNING, "Trying to setFrgColour while not attached" );
1349 +        }
1350 +        return codError;
1351 +    }
1352 +
1353 +    int brushType( int type, unsigned int pattern )
1354 +    {
1355 +        if ( m_attached ) {
1356 +            if ( AtiCore_BrushType( type, &pattern ) ) {
1357 +                return codOK;
1358 +            } else {
1359 +                log( ERROR, "Error in brushType" );
1360 +            }
1361 +        } else {
1362 +            log( WARNING, "Trying to brushType while not attached" );
1363 +        }
1364 +        return codError;
1365 +    }
1366 +
1367 +    int paintRect( int flags, ATI_RECT *rect )
1368 +    {
1369 +        if ( m_attached ) {
1370 +            if ( AtiCore_PaintRect( flags, rect ) ) {
1371 +                return codOK;
1372 +            } else {
1373 +                log( ERROR, "Error in paintRect" );
1374 +            }
1375 +        } else {
1376 +            log( WARNING, "Trying to paintRect while not attached" );
1377 +        }
1378 +        return codError;
1379 +    }
1380 +
1381 +    int polyline( int npoints, ATI_POINT *points )
1382 +    {
1383 +        if ( m_attached ) {
1384 +            if ( AtiCore_Polyline( npoints, points ) ) {
1385 +                return codOK;
1386 +            } else {
1387 +                log( ERROR, "Error in polyline" );
1388 +            }
1389 +        } else {
1390 +            log( WARNING, "Trying to polyline while not attached" );
1391 +        }
1392 +        return codError;
1393 +    }
1394 +
1395 +    int getPitchOffsetProperty( void *pitch, void *offset )
1396 +    {
1397 +        if ( m_attached ) {
1398 +            if ( AtiCore_GetPitchOffsetProperty( pitch, offset ) ) {
1399 +                return codOK;
1400 +            } else {
1401 +                log( ERROR, "Error in getPitchOffsetProperty" );
1402 +            }
1403 +        } else {
1404 +            log( WARNING, "Trying to getPitchOffsetProperty while not attached" );
1405 +        }
1406 +        return codError;
1407 +    }
1408 +
1409 +    int cursorOnOff( int a, int b )
1410 +    {
1411 +        if ( m_attached ) {
1412 +            if ( AtiCore_CursorOnOff( a, b ) ) {
1413 +                return codOK;
1414 +            } else {
1415 +                log( ERROR, "Error in cursorOnOff" );
1416 +            }
1417 +        } else {
1418 +            log( WARNING, "Trying to cursorOnOff while not attached" );
1419 +        }
1420 +        return codError;
1421 +    }
1422 +
1423 +    int bitBlt( int flags, ATI_RECT *dst, ATI_RECT *src )
1424 +    {
1425 +        if ( m_attached ) {
1426 +            if ( AtiCore_BitBlt( flags, dst, src ) ) {
1427 +                return codOK;
1428 +            } else {
1429 +                log( ERROR, "Error in bitBlt" );
1430 +            }
1431 +        } else {
1432 +            log( WARNING, "Trying to bitBlt while not attached" );
1433 +        }
1434 +        return codError;
1435 +    }
1436 +
1437 +    int wakeUpCall( void )
1438 +    {
1439 +        if ( m_attached ) {
1440 +            if ( AtiCore_WakeUpCall() ) {
1441 +                return codOK;
1442 +            } else {
1443 +                log( ERROR, "Error in wakeUpCall" );
1444 +            }
1445 +        } else {
1446 +            log( WARNING, "Trying to wakeupCall while not attached" );
1447 +        }
1448 +        return codError;
1449 +    }
1450 +
1451 +private:
1452 +    FILE *m_logfile;
1453 +    int m_loglevel;
1454 +    bool m_logenabled;
1455 +    bool m_attached;
1456 +    int m_pid;
1457 +    int m_logcount;
1458 +};
1459 +
1460 +W100Driver::Opcode W100Driver::lOpcodes[] = {
1461 +    { "DRAWLINE",   W100Driver::DRAWLINE,   true, 0, 0 },
1462 +    { "DRAWPOINT",  W100Driver::DRAWPOINT,  true, 0, 0 },
1463 +    { "DRAWPOINTS", W100Driver::DRAWPOINTS, true, 0, 0 },
1464 +    { "FILLRECT",   W100Driver::FILLRECT,   true, 0, 0 },
1465 +    { "SCROLL",     W100Driver::SCROLL,     true, 0, 0 },
1466 +    { "BITBLT",     W100Driver::BITBLT,     true, 0, 0 },
1467 +    { "POLYLINE",   W100Driver::POLYLINE,   true, 0, 0 },
1468 +    { ""      ,     W100Driver::EOO,        false, 0, 0 }
1469 +};
1470 +
1471 +W100Driver driver;
1472 +
1473 +class QW100Screen;
1474 +static QW100Screen *qt_w100_screen = 0;
1475 +
1476 +class QW100Screen : public QLinuxFbScreen {
1477 +public:
1478 +    class HWSurface {
1479 +    public:
1480 +        HWSurface( void ):
1481 +            m_handle( 0 ),
1482 +            m_offset( 0 ),
1483 +            m_addr( 0 ),
1484 +            m_size( 0 ),
1485 +            m_internal( false ),
1486 +            m_clientid( -1 ) {};
1487 +        HWSurface( unsigned short handle,
1488 +                   uint32_t sOffset,
1489 +                   unsigned char *localAddr, 
1490 +                   int amount,
1491 +                   bool internal,
1492 +                   int clientid ):
1493 +            m_handle( handle ),
1494 +            m_offset( sOffset ),
1495 +            m_addr( localAddr ),
1496 +            m_size( amount ),
1497 +            m_internal( internal ),
1498 +            m_clientid( clientid ) {};
1499 +        HWSurface( uint32_t sOffset, 
1500 +                   unsigned char *localAddr,
1501 +                   bool internal,
1502 +                   int amount ):
1503 +            m_handle( 0 ),
1504 +            m_offset( sOffset ),
1505 +            m_addr( localAddr ),
1506 +            m_size( amount ),
1507 +            m_internal( internal ),
1508 +            m_clientid( -1 ) {};
1509 +        bool operator!=( HWSurface &other ) {
1510 +            return( m_offset == other.getSOffset() );
1511 +        };
1512 +        HWSurface &operator=( const HWSurface &c ) {
1513 +            m_handle = c.getHandle();
1514 +            m_offset = c.getSOffset();
1515 +            m_addr = c.getAddr();
1516 +            m_size = c.getSize();
1517 +            m_clientid= c.getCId();
1518 +            m_internal = c.internal();
1519 +            return( *this );
1520 +        };
1521 +        unsigned short getHandle( void ) const { return m_handle; };
1522 +        uint32_t getSOffset( void ) const { return m_offset; };
1523 +        unsigned char *getAddr( void ) const { return m_addr; };
1524 +        unsigned int getSize( void ) const { return m_size; };
1525 +        int getCId( void ) const { return m_clientid; };
1526 +        bool internal( void ) const { return m_internal; };
1527 +
1528 +    private:
1529 +        unsigned short m_handle;
1530 +        uint32_t m_offset;
1531 +        unsigned char *m_addr;
1532 +        int m_size;
1533 +        bool m_internal;
1534 +        int m_clientid;
1535 +    };
1536 +    
1537 +    QW100Screen( int display_id );
1538 +    virtual ~QW100Screen();
1539 +    virtual bool connect( const QString &spec );
1540 +    virtual void disconnect( void );
1541 +    virtual bool initDevice();
1542 +    virtual void shutdownDevice();
1543 +    virtual void restore();
1544 +    virtual bool useOffscreen() { return true; }
1545 +    virtual QGfx * createGfx( unsigned char *, int, int, int, int);
1546 +    virtual uchar *cache( int amount, int optim );
1547 +    virtual void uncache( uchar *c );
1548 +    virtual bool onCard( unsigned char *p ) const;
1549 +    virtual bool onCard( unsigned char *p, ulong& offset ) const;
1550 +    QMap< uchar*, HWSurface > *getPSurfaceMap( void ) const;
1551 +    void clearCache( int clientId );
1552 +
1553 +    // Suspend/resume hooks
1554 +    virtual void prepareToSuspend();
1555 +    virtual void prepareToResume();
1556 +    // Rotation stuff
1557 +    enum Transformation { None, Rot90, Rot180, Rot270 };
1558 +    void setTransformation( Transformation t );
1559 +    Transformation transformation() const;
1560 +    virtual bool isTransformed() const { return trans != None; };
1561 +    virtual QSize mapToDevice( const QSize & ) const;
1562 +    virtual QSize mapFromDevice( const QSize & ) const;
1563 +    virtual QPoint mapToDevice( const QPoint &, const QSize & ) const;
1564 +    virtual QPoint mapFromDevice( const QPoint &, const QSize & ) const;
1565 +    virtual QRect mapToDevice( const QRect &, const QSize & ) const;
1566 +    virtual QRect mapFromDevice( const QRect &, const QSize & ) const;
1567 +    virtual QImage mapToDevice( const QImage & ) const;
1568 +    virtual QImage mapFromDevice( const QImage & ) const;
1569 +    virtual QRegion mapToDevice( const QRegion &, const QSize & ) const;
1570 +    virtual QRegion mapFromDevice( const QRegion &, const QSize & ) const;
1571 +    virtual int transformOrientation() const;
1572 +
1573 +protected:
1574 +    bool w100init();
1575 +    void w100shutdown();
1576 +    Transformation trans;
1577 +    static Transformation getTransSpec( const QString &dspec );
1578 +    static void clearCache( QScreen *instance, int clientId );
1579 +    QMap< uchar*, HWSurface > surfaceMap;
1580 +    int vramoffset;
1581 +    bool m_isServer;
1582 +    virtual int pixmapLinestepAlignment() { return 128; }
1583 +};
1584 +
1585 +template <const int depth, const int type>
1586 +class QGfxW100 : public QGfxRaster<depth,type> {
1587 +
1588 +public:
1589 +    QGfxW100( unsigned char *b, int w, int h );
1590 +    virtual void drawLine( int, int, int, int);
1591 +    virtual void fillRect( int, int, int, int);
1592 +    virtual void blt( int, int, int, int, int, int );
1593 +    virtual void sync();
1594 +    virtual void setOffset( int x, int y );
1595 +    virtual void setPen( const QPen & p );
1596 +  
1597 +    virtual void drawPolyline( const QPointArray &, int, int );
1598 +    virtual void drawPolygon( const QPointArray &, bool, int, int );
1599 +    virtual void drawPoint( int, int );
1600 +    virtual void drawPoints( const QPointArray &, int, int );
1601 +    virtual void scroll( int, int, int, int, int, int );
1602 +    virtual void tiledBlt( int rx, int ry, int w, int h );
1603 +
1604 +    inline int tx( int x, int y ) {
1605 +        switch ( qt_w100_screen->transformation() ) {
1606 +        case QW100Screen::Rot90:
1607 +            return y - this->xoffs + this->yoffs;
1608 +        case QW100Screen::Rot180:
1609 +            return ( this->width - x - 1) - this->xoffs - this->xoffs;
1610 +        case QW100Screen::Rot270:
1611 +            return ( this->height - y - 1) - this->xoffs - this->yoffs;
1612 +        default:
1613 +            return x;
1614 +        }
1615 +    }
1616 +    inline int ty( int x, int y ) {
1617 +        switch ( qt_w100_screen->transformation() ) {
1618 +        case QW100Screen::Rot90:
1619 +            return (this->width - x - 1) - this->yoffs - this->xoffs;
1620 +        case QW100Screen::Rot180:
1621 +            return (this->height - y - 1) - this->yoffs - this->yoffs;
1622 +        case QW100Screen::Rot270:
1623 +            return x - this->yoffs + this->xoffs;
1624 +        default:
1625 +            return y;
1626 +        }
1627 +    }
1628 +
1629 +protected:
1630 +    bool checkDest( bool setsrc = false );
1631 +    bool checkSourceDest();
1632 +    virtual void setSourceWidgetOffset( int x, int y );
1633 +    void processSpans( int n, QPoint* point, int* width );
1634 +    bool inDraw;
1635 +
1636 +    virtual void dDrawLine( int, int, int, int);
1637 +    virtual void dFillRect( int, int, int, int);
1638 +    virtual void dBlt( int, int, int, int, int, int );
1639 +    void dDrawPolyline( const QPointArray &, int, int );
1640 +    void dDrawPolygon( const QPointArray &, bool, int, int );
1641 +    void dDrawPoint( int, int );
1642 +    void dDrawPoints( const QPointArray &, int, int );
1643 +    void dScroll( int, int, int, int, int, int );
1644 +    void dTiledBlt( int rx, int ry, int w, int h );
1645 +};
1646 +
1647 +template<const int depth,const int type>
1648 +QGfxW100<depth,type>::QGfxW100( unsigned char * b, int w, int h )
1649 +    : QGfxRaster<depth,type>(b, w, h),
1650 +      inDraw( false )
1651 +{
1652 +}
1653 +
1654 +template<const int depth,const int type>
1655 +inline void QGfxW100<depth,type>::setOffset( int x, int y )
1656 +{
1657 +    QGfxRaster<depth,type>::setOffset( x, y );
1658 +}
1659 +
1660 +namespace {
1661 +    QString penStyleStr( const QPen &pen ) 
1662 +    {
1663 +        QString res;
1664 +        switch( pen.style() ) {
1665 +        case Qt::NoPen:
1666 +            res = "NoPen";
1667 +            break;
1668 +        case Qt::SolidLine:
1669 +            res = "SolidLine";
1670 +            break;
1671 +        case Qt::DashLine:
1672 +            res = "DashLine";
1673 +            break;
1674 +        case Qt::DotLine:
1675 +            res = "DotLine";
1676 +            break;
1677 +        case Qt::DashDotLine:
1678 +            res = "DashDotLine";
1679 +            break;
1680 +        case Qt::DashDotDotLine:
1681 +            res = "DashDotDotLine";
1682 +            break;
1683 +        default:
1684 +            res = "Unknown";
1685 +        }
1686 +        return res;
1687 +    }
1688 +}
1689 +
1690 +template<const int depth, const int type>
1691 +inline void QGfxW100<depth,type>::setPen( const QPen &p )
1692 +{
1693 +    QGfxRaster<depth,type>::setPen( p );
1694 +}
1695 +
1696 +template<const int depth,const int type>
1697 +inline bool QGfxW100<depth,type>::checkSourceDest()
1698 +{
1699 +    if ( !checkDest() ) {
1700 +        return FALSE;
1701 +    }
1702 +
1703 +    int sourcepixelpitch;
1704 +    ulong src_buffer_offset;
1705 +    if ( this->srctype == this->SourcePen ) {
1706 +        src_buffer_offset = -1;
1707 +        return FALSE;
1708 +    } else {
1709 +        if ( !qt_screen->onCard( this->srcbits, src_buffer_offset ) ) {
1710 +            return FALSE;
1711 +        }
1712 +        sourcepixelpitch = ( this->srclinestep * 8 ) / this->srcdepth;
1713 +        driver.setSrcPitchOffset( sourcepixelpitch,
1714 +                                       src_buffer_offset );
1715 +    }
1716 +    return TRUE;
1717 +}
1718 +
1719 +template< const int depth, const int type>
1720 +inline bool QGfxW100<depth, type>::checkDest( bool setsrc )
1721 +{
1722 +    //Main framebuffer should be registered as a hardware surface
1723 +    ulong buffer_offset;
1724 +    if ( !qt_screen->onCard( this->buffer, buffer_offset ) ) {
1725 +        return FALSE;
1726 +    }
1727 +    int pixelstep = ( this->linestep() * 8 ) / depth;
1728 +    driver.setDstPitchOffset( pixelstep, buffer_offset );
1729 +    if ( setsrc ) {
1730 +        driver.setSrcPitchOffset( pixelstep, buffer_offset );
1731 +    }
1732 +    return TRUE;
1733 +}
1734 +
1735 +template<const int depth,const int type>
1736 +void QGfxW100<depth,type>::drawLine( int x1, int y1, int x2, int y2 )
1737 +{
1738 +    if ( inDraw ) {
1739 +        dDrawLine( x1, y1, x2, y2 );
1740 +    } else {
1741 +        inDraw = true;
1742 +        dDrawLine( tx(x1,y1), ty(x1,y1),
1743 +                   tx(x2,y2), ty(x2,y2) );
1744 +        inDraw = false;
1745 +    }
1746 +}
1747 +
1748 +template<const int depth,const int type>
1749 +void QGfxW100<depth,type>::dDrawLine( int x1, int y1, int x2, int y2 )
1750 +{
1751 +    if ( ( this->ncliprect < 1) || 
1752 +         ( this->cpen.style() == this->NoPen ) ) {
1753 +        return;
1754 +    }
1755 +
1756 +    if ( depth != 16 || 
1757 +         !driver.accelerated( W100Driver::DRAWLINE ) ) {
1758 +        driver.addMiss( W100Driver::DRAWLINE );
1759 +        QGfxRaster<depth,type>::drawLine( x1, y1, x2, y2 );
1760 +        return;
1761 +    }
1762 +
1763 +    // Only handle 'normal' lines
1764 +    if ( ( this->cpen.style() != this->SolidLine ) || 
1765 +         ( this->myrop != this->CopyROP ) ||
1766 +         ( this->cpen.width() > 1 ) ||
1767 +         ( this->dashedLines ) ) {
1768 +        driver.addMiss( W100Driver::DRAWLINE );
1769 +        QGfxRaster<depth,type>::drawLine( x1, y1, x2, y2);
1770 +        return;
1771 +    }
1772 +
1773 +    // Stop anyone else trying to access optype/lastop/the graphics engine
1774 +    // to avoid synchronization problems with other processes
1775 +    QWSDisplay::grab( true );
1776 +    if ( !checkDest() ) {
1777 +        QWSDisplay::ungrab();
1778 +        driver.addMiss( W100Driver::DRAWLINE );
1779 +        QGfxRaster<depth,type>::drawLine( x1, y1, x2, y2 );
1780 +        return;
1781 +    }
1782 +
1783 +
1784 +    // Note that the last operation used the 2d engine
1785 +    ( *optype ) = 1;
1786 +
1787 +    // Add the offset of the gfx - used to make the origin the right
1788 +    // place for windows
1789 +    x1 += this->xoffs;
1790 +    y1 += this->yoffs;
1791 +    x2 += this->xoffs;
1792 +    y2 += this->yoffs;
1793 +
1794 +    QRect boundRect( x1 < x2 ? x1: x2,
1795 +                     y1 < y2 ? y1 : y2, 
1796 +                     QABS( x2 - x1 ) + 1,
1797 +                     QABS( y2 - y1 ) + 1 );
1798 +
1799 +    GFX_START( boundRect );
1800 +
1801 +    // The clip region is defined as a series of rectangles
1802 +    // We repeatedly set up the hardware clip rectangle to one of
1803 +    // these rectangles and re-draw the line - an alternative approach
1804 +    // would be to clip to the rectangle in software
1805 +    
1806 +    driver.setDstType( DSTTYPE_16BPP_1555 );
1807 +    driver.setSrcType( SRCTYPE_EQU_DST );
1808 +    driver.setRopOperation( ROP3_PATCOPY );
1809 +    driver.brushType( 6, 0 );
1810 +    driver.setFrgColour( this->cpen.color().rgb() );
1811 +    driver.addHit( W100Driver::DRAWLINE );
1812 +
1813 +    //The imageon seems not to write on the edge of the clip
1814 +    //for the polyline op. 
1815 +    //We are using a three points array repeating the last point
1816 +    //to get the last single point painted.
1817 +    ATI_POINT points[3];
1818 +    points[0].XCoord = x1;
1819 +    points[0].YCoord = y1;
1820 +    points[1].XCoord = x2;
1821 +    points[1].YCoord = y2;
1822 +    points[2].XCoord = x2;
1823 +    points[2].YCoord = y2;
1824 +    for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
1825 +        if ( boundRect.intersects( this->cliprect[loopc] ) ) {
1826 +            ATI_CLIPRECT clip;
1827 +            clip.X_Top_Left = this->cliprect[loopc].x();
1828 +            clip.Y_Top_Left = this->cliprect[loopc].y();
1829 +            clip.X_Bottom_Right = this->cliprect[loopc].right() + 1;
1830 +            clip.Y_Bottom_Right = this->cliprect[loopc].bottom() + 1;
1831 +            driver.setDstClippingRect( &clip );
1832 +            driver.polyline( 3, points );
1833 +        }
1834 +    }
1835 +
1836 +    // Software mouse cursor stuff
1837 +    GFX_END;
1838 +
1839 +    // Release display again - not doing so will cause Qt/Embedded applications
1840 +    // to deadlock
1841 +    QWSDisplay::ungrab();
1842 +}
1843 +
1844 +template< const int depth, const int type >
1845 +void QGfxW100< depth, type>::drawPolyline( const QPointArray &a, 
1846 +                                           int index, 
1847 +                                           int npoints )
1848 +{
1849 +    if ( inDraw ) {
1850 +        dDrawPolyline( a, index, npoints );
1851 +    } else {
1852 +        inDraw = true;
1853 +        QPointArray na( npoints );
1854 +    
1855 +        for ( int i = 0; i < npoints; i++ ) {
1856 +            int x, y;
1857 +            a.point( i+index, &x, &y );
1858 +            na.setPoint( i, tx(x,y), ty(x,y) );
1859 +        }
1860 +    
1861 +        dDrawPolyline( na, 0, npoints );
1862 +        inDraw = false;
1863 +    }
1864 +}
1865 +
1866 +template< const int depth, const int type >
1867 +void QGfxW100< depth, type>::dDrawPolyline( const QPointArray &a, 
1868 +                                            int index, 
1869 +                                            int npoints )
1870 +{
1871 +    if ( ( this->ncliprect < 1 ) || 
1872 +         ( npoints < 1 ) ||
1873 +         ( this->cpen.style() == this->NoPen ) ) {
1874 +        return;
1875 +    }
1876 +
1877 +    if ( depth != 16 ||
1878 +         !driver.accelerated( W100Driver::POLYLINE ) ) {
1879 +        driver.addMiss( W100Driver::POLYLINE );
1880 +        QGfxRaster<depth,type>::drawPolyline( a, index, npoints );
1881 +        return;
1882 +    }
1883 +
1884 +    if ( this->cpen.style() != this->SolidLine ||
1885 +         this->myrop != this->CopyROP ) {
1886 +        driver.addMiss( W100Driver::POLYLINE );
1887 +        QGfxRaster<depth,type>::drawPolyline( a, index, npoints );
1888 +        return;
1889 +    }
1890 +
1891 +    QWSDisplay::grab( TRUE );
1892 +    if ( !checkDest() ) {
1893 +        QWSDisplay::ungrab();
1894 +        driver.addMiss( W100Driver::POLYLINE );
1895 +        QGfxRaster<depth,type>::drawPolyline( a, index, npoints );
1896 +        return;
1897 +    }
1898 +
1899 +    ( *optype ) = 1;
1900 +
1901 +    driver.setDstType( DSTTYPE_16BPP_1555 );
1902 +    driver.setSrcType( SRCTYPE_EQU_DST );
1903 +    driver.setRopOperation( ROP3_PATCOPY );
1904 +    driver.brushType( 6, 0 );
1905 +    driver.setFrgColour( this->cpen.color().rgb() );
1906 +
1907 +    driver.addHit( W100Driver::POLYLINE );
1908 +
1909 +    ATI_POINT *points = new ATI_POINT[ npoints + 1 ];
1910 +
1911 +    for ( int i = 0; i < npoints; i++ ) {
1912 +        points[i].XCoord = a[i+index].x() + this->xoffs;
1913 +        points[i].YCoord = a[i+index].y() + this->yoffs;
1914 +    }
1915 +    //Hack to get the last point of the last line painted
1916 +    points[ npoints ] = points[ npoints - 1 ];
1917 +
1918 +
1919 +    GFX_START( clipbounds );
1920 +    driver.setFrgColour( this->cpen.color().rgb() );
1921 +    driver.setRopOperation( ROP3_PATCOPY );
1922 +    for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
1923 +        ATI_CLIPRECT clip;
1924 +        clip.X_Top_Left = this->cliprect[loopc].x();
1925 +        clip.Y_Top_Left = this->cliprect[loopc].y();
1926 +        clip.X_Bottom_Right = this->cliprect[loopc].right() + 1;
1927 +        clip.Y_Bottom_Right = this->cliprect[loopc].bottom() + 1;
1928 +        driver.setDstClippingRect( &clip );
1929 +        driver.polyline( npoints + 1, points );
1930 +    }
1931 +    GFX_END;
1932 +
1933 +    delete [] points;
1934 +    
1935 +    QWSDisplay::ungrab();
1936 +}
1937 +
1938 +
1939 +template< const int depth, const int type >
1940 +void QGfxW100< depth, type>::drawPolygon( const QPointArray &a, 
1941 +                                          bool w, int index, 
1942 +                                          int npoints )
1943 +{
1944 +    if ( inDraw  || this->cpen.style()==this->NoPen || this->patternedbrush ) {
1945 +        //slowpath
1946 +        dDrawPolygon( a, w, index, npoints );
1947 +    } else {
1948 +        inDraw = TRUE;
1949 +        QPointArray na( npoints );
1950 +
1951 +        for ( int i = 0; i < npoints; i++ ) {
1952 +            int x,y;
1953 +            a.point( i+index, &x, &y );
1954 +            na.setPoint( i, tx(x,y), ty(x,y) );
1955 +        }
1956 +        dDrawPolygon( na, w, 0, npoints );
1957 +        inDraw = FALSE;
1958 +    }
1959 +}
1960 +
1961 +template< const int depth, const int type >
1962 +void QGfxW100< depth, type>::dDrawPolygon( const QPointArray &a, bool w, int index, int npoints )
1963 +{
1964 +    QGfxRaster<depth,type>::drawPolygon( a, w, index, npoints );
1965 +}
1966 +
1967 +template< const int depth, const int type >
1968 +void QGfxW100< depth, type>::drawPoint( int x, int y )
1969 +{
1970 +    dDrawPoint( tx( x, y ), ty( x, y ) );
1971 +}
1972 +
1973 +template< const int depth, const int type >
1974 +void QGfxW100< depth, type>::dDrawPoint( int x, int y )
1975 +{
1976 +
1977 +    if ( this->ncliprect < 1 ) {
1978 +        return;
1979 +    }
1980 +
1981 +    if ( depth != 16 ||
1982 +         !driver.accelerated( W100Driver::DRAWPOINT) ) {
1983 +        driver.addMiss( W100Driver::DRAWPOINT );
1984 +        QGfxRaster<depth,type>::drawPoint( x, y );
1985 +        return;
1986 +    }
1987 +
1988 +    if ( this->cpen.style() != this->SolidLine ||
1989 +         this->myrop != this->CopyROP ) {
1990 +        driver.addMiss( W100Driver::DRAWPOINT );
1991 +        QGfxRaster<depth,type>::drawPoint( x, y );
1992 +        return;
1993 +    }
1994 +
1995 +    QWSDisplay::grab( TRUE );
1996 +    if ( !checkDest() ) {
1997 +        QWSDisplay::ungrab();
1998 +        driver.addMiss( W100Driver::DRAWPOINT );
1999 +        QGfxRaster<depth,type>::drawPoint( x, y );
2000 +        return;
2001 +    }
2002 +
2003 +    driver.addHit( W100Driver::DRAWPOINT );
2004 +    ( *optype ) = 1;
2005 +  
2006 +    ATI_POINT point;
2007 +    point.XCoord = x + this->xoffs;
2008 +    point.YCoord = y + this->yoffs;
2009 +
2010 +    GFX_START( clipbounds );
2011 +    driver.setFrgColour( this->cpen.color().rgb() );
2012 +    driver.setRopOperation( ROP3_PATCOPY );
2013 +    for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
2014 +        ATI_CLIPRECT clip;
2015 +        clip.X_Top_Left = this->cliprect[loopc].x();
2016 +        clip.Y_Top_Left = this->cliprect[loopc].y();
2017 +        clip.X_Bottom_Right = this->cliprect[loopc].right() + 1;
2018 +        clip.Y_Bottom_Right = this->cliprect[loopc].bottom() + 1;
2019 +        driver.setDstClippingRect( &clip );
2020 +        driver.drawPixel( 1, &point );
2021 +    }
2022 +    GFX_END;
2023 +    QWSDisplay::ungrab();
2024 +}
2025 +
2026 +template< const int depth, const int type >
2027 +void QGfxW100< depth, type>::drawPoints( const QPointArray &a, 
2028 +                                         int index, 
2029 +                                         int npoints )
2030 +{
2031 +    QPointArray na( npoints );
2032 +
2033 +    for ( int i = 0; i < npoints; i++ ) {
2034 +        int x, y;
2035 +        a.point( i+index, &x, &y );
2036 +        na.setPoint( i, tx( x, y ), ty( x, y ) );
2037 +    }
2038 +
2039 +    dDrawPoints( na, 0, npoints );
2040 +}
2041 +
2042 +template< const int depth, const int type >
2043 +void QGfxW100< depth, type>::dDrawPoints( const QPointArray &a, 
2044 +                                          int index, 
2045 +                                          int npoints )
2046 +{
2047 +    if ( ( this->ncliprect < 1 ) || ( npoints < 1 ) ) {
2048 +        return;
2049 +    }
2050 +
2051 +    if ( depth != 16 ||
2052 +         !driver.accelerated( W100Driver::DRAWPOINTS ) ) {
2053 +        driver.addMiss( W100Driver::DRAWPOINTS );
2054 +        QGfxRaster<depth,type>::drawPoints( a, index, npoints );
2055 +        return;
2056 +    }
2057 +
2058 +    if ( this->cpen.style() != this->SolidLine ||
2059 +         this->myrop != this->CopyROP ) {
2060 +        driver.addMiss( W100Driver::DRAWPOINTS );
2061 +        QGfxRaster<depth,type>::drawPoints( a, index, npoints );
2062 +        return;
2063 +    }
2064 +
2065 +    QWSDisplay::grab( TRUE );
2066 +    if ( !checkDest() ) {
2067 +        QWSDisplay::ungrab();
2068 +        driver.addMiss( W100Driver::DRAWPOINTS );
2069 +        QGfxRaster<depth,type>::drawPoints( a, index, npoints );
2070 +        return;
2071 +    }
2072 +
2073 +    driver.addHit( W100Driver::DRAWPOINTS );
2074 +    ( *optype ) = 1;
2075 +  
2076 +    ATI_POINT *points = new ATI_POINT[ npoints ];
2077 +    for ( int i = 0; i < npoints; i++ ) {
2078 +        points[i].XCoord = a[i+index].x() + this->xoffs;
2079 +        points[i].YCoord = a[i+index].y() + this->yoffs;
2080 +    }
2081 +
2082 +    GFX_START( clipbounds );
2083 +    driver.setFrgColour( this->cpen.color().rgb() );
2084 +    driver.setRopOperation( ROP3_PATCOPY );
2085 +    for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
2086 +        ATI_CLIPRECT clip;
2087 +        clip.X_Top_Left = this->cliprect[loopc].x();
2088 +        clip.Y_Top_Left = this->cliprect[loopc].y();
2089 +        clip.X_Bottom_Right = this->cliprect[loopc].right() + 1;
2090 +        clip.Y_Bottom_Right = this->cliprect[loopc].bottom() + 1;
2091 +        driver.setDstClippingRect( &clip );
2092 +        driver.drawPixel( npoints, points );
2093 +    }
2094 +    GFX_END;
2095 +
2096 +    delete [] points;
2097 +    QWSDisplay::ungrab();
2098 +}
2099 +
2100 +template <const int depth, const int type>
2101 +void QGfxW100<depth,type>::scroll( int x, int y, int w, int h, int sx, int sy )
2102 +{
2103 +    if ( w == 0 || h == 0 )
2104 +        return;
2105 +    QRect r;
2106 +    QRect s;
2107 +    if ( inDraw ) {
2108 +        r = QRect( x, y, w, h );
2109 +        s = QRect( sx, sy, w, h );
2110 +    } else {
2111 +        r.setCoords( tx(x,y), ty(x,y), tx(x+w-1,y+h-1), ty(x+w-1,y+h-1) );
2112 +        s.setCoords( tx(sx,sy), ty(sx,sy), tx(sx+w-1,sy+h-1), ty(sx+w-1,sy+h-1) );
2113 +        r = r.normalize();
2114 +        s = s.normalize();
2115 +    }
2116 +    dScroll( r.x(), r.y(), r.width(), r.height(), s.x(), s.y() );
2117 +}
2118 +
2119 +
2120 +template< const int depth, const int type >
2121 +void QGfxW100< depth, type>::dScroll( int rx, int ry,
2122 +                                      int w, int h, 
2123 +                                      int sx, int sy )
2124 +{
2125 +    if ( depth != 16 ||
2126 +         !driver.accelerated( W100Driver::SCROLL ) ) {
2127 +        driver.addMiss( W100Driver::SCROLL );
2128 +        QGfxRaster<depth,type>::scroll( rx, ry, w, h, sx, sy );
2129 +        return;
2130 +    }
2131 +
2132 +    if ( this->ncliprect < 1 ) return;
2133 +
2134 +    if ( ( w < 1 )  || ( h < 1 ) ) return;
2135 +
2136 +    int dy = sy - ry;
2137 +    int dx = sx - rx;
2138 +
2139 +    if ( dx == 0 && dy == 0 ) return;
2140 +
2141 +
2142 +    QWSDisplay::grab( TRUE );
2143 +
2144 +    if ( checkDest( true ) ) {
2145 +
2146 +        rx += this->xoffs;
2147 +        sx += this->xoffs;
2148 +        ry += this->yoffs;
2149 +        sy += this->yoffs;
2150 +
2151 +        QRect boundRect(  QMIN( rx , sx  ),
2152 +                          QMIN( ry , sy  ),
2153 +                          w + QABS( dx ) + 1,
2154 +                          h + QABS( dy ) + 1 );
2155 +        GFX_START( boundRect );
2156 +        ( *optype ) = 1;
2157 +
2158 +
2159 +        //if ( driver.lastOp() != W100Driver::SCROLL ) {
2160 +        driver.setRopOperation( ROP3_SRCCOPY );
2161 +        driver.setDstType( DSTTYPE_16BPP_1555 );
2162 +        driver.setSrcType( SRCTYPE_EQU_DST );
2163 +        //}
2164 +
2165 +        driver.addHit( W100Driver::SCROLL );
2166 +
2167 +        ATI_RECT srcrect, dstrect;
2168 +
2169 +        srcrect.XCoord = sx;
2170 +        srcrect.YCoord = sy;
2171 +        srcrect.Width = w;
2172 +        srcrect.Height = h;
2173 +        dstrect.XCoord = rx;
2174 +        dstrect.YCoord = ry;
2175 +        dstrect.Width = w;
2176 +        dstrect.Height = h;
2177 +        for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
2178 +            if ( boundRect.intersects( this->cliprect[loopc] ) ) {
2179 +                ATI_CLIPRECT clip;
2180 +                clip.X_Top_Left     = this->cliprect[ loopc ].x();
2181 +                clip.Y_Top_Left     = this->cliprect[ loopc ].y();
2182 +                clip.X_Bottom_Right = this->cliprect[ loopc ].right() + 1;
2183 +                clip.Y_Bottom_Right = this->cliprect[ loopc ].bottom() + 1;
2184 +                driver.setDstClippingRect( &clip );
2185 +                driver.bitBlt( 1, &dstrect, &srcrect );
2186 +            }
2187 +        }
2188 +        GFX_END;
2189 +        QWSDisplay::ungrab();
2190 +
2191 +    } else {
2192 +        QWSDisplay::ungrab();
2193 +        // software fallback
2194 +        driver.addMiss( W100Driver::SCROLL );
2195 +        QGfxRaster<depth,type>::scroll( rx, ry, w, h, sx, sy );
2196 +    }
2197 +}
2198 +
2199 +template< const int depth, const int type >
2200 +void QGfxW100< depth, type>::fillRect( int x, int y, int w, int h )
2201 +{
2202 +    if ( w == 0 || h == 0 )
2203 +        return;
2204 +    QRect r( x, y, w, h );
2205 +    r.setCoords( tx( x, y ), ty( x, y ), 
2206 +                 tx( x + w - 1, y + h - 1 ), ty( x + w - 1, y + h - 1 ) );
2207 +    r = r.normalize();
2208 +    inDraw = TRUE;
2209 +    dFillRect( r.x(), r.y(), r.width(), r.height() );
2210 +    inDraw = FALSE;
2211 +}
2212 +  
2213 +template< const int depth, const int type >
2214 +void QGfxW100< depth, type>::dFillRect( int rx, int ry, int w, int h )
2215 +{
2216 +    if ( w <= 0 || h <= 0 || this->ncliprect < 1 ) return;
2217 +
2218 +    if ( depth != 16 ||
2219 +         !driver.accelerated( W100Driver::FILLRECT ) ) {
2220 +        driver.addMiss( W100Driver::FILLRECT );
2221 +        QGfxRaster<depth,type>::fillRect( rx, ry, w, h );
2222 +        return;
2223 +    }
2224 +
2225 +    if ( ( this->cbrush.style() != this->NoBrush ) && 
2226 +         ( this->cbrush.style() != this->SolidPattern ) ) {
2227 +        driver.addMiss( W100Driver::FILLRECT );
2228 +        QGfxRaster<depth,type>::fillRect( rx, ry, w, h );
2229 +        return;
2230 +    }
2231 +
2232 +    if ( !checkDest() || ( this->myrop != this->CopyROP ) ) {
2233 +        driver.addMiss( W100Driver::FILLRECT );
2234 +        QGfxRaster<depth,type>::fillRect( rx, ry, w, h );
2235 +        return;
2236 +    }
2237 +
2238 +    QWSDisplay::grab( TRUE );
2239 +    rx += this->xoffs;
2240 +    ry += this->yoffs;
2241 +
2242 +    QRect boundRect( rx, ry, w + 1, h + 1 );
2243 +    GFX_START( boundRect );
2244 +
2245 +    ( *optype ) = 1;
2246 +
2247 +    driver.setDstType( DSTTYPE_16BPP_1555 );
2248 +    driver.setSrcType( SRCTYPE_EQU_DST );
2249 +    driver.setRopOperation( ROP3_PATCOPY );
2250 +    driver.brushType( 6, 0 );
2251 +    driver.setFrgColour( this->cbrush.color().rgb() );
2252 +
2253 +    driver.addHit( W100Driver::FILLRECT );
2254 +
2255 +    if ( this->cbrush.style() != this->NoBrush ) {
2256 +        //Using all the cliprects
2257 +        for ( int loopc = 0; loopc < this->ncliprect; loopc++ ) {
2258 +            if ( boundRect.intersects( this->cliprect[loopc] ) ) {
2259 +                ATI_CLIPRECT clip;
2260 +                ATI_RECT rect;
2261 +
2262 +                clip.X_Top_Left     = this->cliprect[ loopc ].x();
2263 +                clip.Y_Top_Left     = this->cliprect[ loopc ].y();
2264 +                clip.X_Bottom_Right = this->cliprect[ loopc ].right() + 1;
2265 +                clip.Y_Bottom_Right = this->cliprect[ loopc ].bottom() + 1;
2266 +
2267 +                driver.setDstClippingRect( &clip );
2268 +                rect.XCoord = rx;
2269 +                rect.YCoord = ry;
2270 +                rect.Width  = w;
2271 +                rect.Height = h;
2272 +                driver.paintRect( 1, &rect );
2273 +            }
2274 +        }
2275 +    }
2276 +    GFX_END;
2277 +      
2278 +    QWSDisplay::ungrab();
2279 +}
2280 +
2281 +template <const int depth, const int type>
2282 +void QGfxW100<depth,type>::blt( int x, int y, int w, int h, int sx, int sy )
2283 +{
2284 +    if ( w == 0 || h == 0 )
2285 +        return;
2286 +    QRect r;
2287 +    int rsx;
2288 +    int rsy;
2289 +    if ( inDraw ) {
2290 +        r = QRect( x, y, w, h );
2291 +        rsx = sx;
2292 +        rsy = sy;
2293 +    } else {
2294 +        r.setCoords( tx(x,y), ty(x,y), tx(x+w-1,y+h-1), ty(x+w-1,y+h-1) );
2295 +        r = r.normalize();
2296 +        switch ( qt_w100_screen->transformation() ) {
2297 +        case QW100Screen::Rot90:
2298 +            rsx = sy;
2299 +            rsy = this->srcwidth - sx - w;
2300 +            break;
2301 +        case QW100Screen::Rot180:
2302 +            rsx = this->srcwidth - sx - w;
2303 +            rsy = this->srcheight - sy - h;
2304 +            break;
2305 +        case QW100Screen::Rot270:
2306 +            rsx = this->srcheight - sy - h;
2307 +            rsy = sx;
2308 +            break;
2309 +        default:
2310 +            rsx = sx;
2311 +            rsy = sy;
2312 +            break;
2313 +        }
2314 +    }
2315 +    dBlt( r.x(), r.y(), r.width(), r.height(), rsx, rsy );
2316 +}
2317 +
2318 +template< const int depth, const int type >
2319 +inline void QGfxW100< depth, type>::dBlt( int rx, int ry, 
2320 +                                          int w, int h,
2321 +                                          int sx, int sy )
2322 +{
2323 +    if ( !w || !h || this->ncliprect < 1 ) {
2324 +        return;
2325 +    }
2326 +
2327 +    if ( depth != 16 ||
2328 +         !driver.accelerated( W100Driver::BITBLT ) ) {
2329 +        driver.addMiss( W100Driver::BITBLT );
2330 +        QGfxRaster<depth,type>::blt( rx, ry, w, h, sx, sy );
2331 +        return;
2332 +    }
2333 +
2334 +    if ( this->alphatype == this->BigEndianMask ||
2335 +         this->alphatype == this->LittleEndianMask ||
2336 +         this->alphatype == this->SeparateAlpha ||
2337 +         this->srctype == this->SourcePen ||
2338 +         ( this->myrop != this->CopyROP ) ) {
2339 +        driver.addMiss( W100Driver::BITBLT );
2340 +        QGfxRaster<depth,type>::blt( rx, ry, w, h, sx, sy );
2341 +        return;
2342 +    }
2343 +
2344 +    if ( ( this->srcdepth != 16 ) || this->alphatype != this->IgnoreAlpha ) {
2345 +        driver.addMiss( W100Driver::BITBLT );
2346 +        QGfxRaster<depth,type>::blt( rx, ry, w, h, sx, sy );
2347 +        return;
2348 +    }
2349 +
2350 +    QWSDisplay::grab( TRUE );
2351 +
2352 +    if ( checkSourceDest() ) {
2353 +        QRect boundRect( rx + this->xoffs, ry + this->yoffs,
2354 +                         w + 1, h + 1 );
2355 +        GFX_START( boundRect );
2356 +        ( *optype ) = 1;
2357 +
2358 +        driver.setRopOperation( ROP3_SRCCOPY );
2359 +        driver.setDstType( DSTTYPE_16BPP_1555 );
2360 +        driver.setSrcType( SRCTYPE_EQU_DST );
2361 +
2362 +        driver.addHit( W100Driver::BITBLT );
2363 +
2364 +        ATI_RECT rect1;
2365 +        ATI_RECT rect2;
2366 +       
2367 +        rx += this->xoffs;
2368 +        ry += this->yoffs;
2369 +
2370 +        rect1.XCoord = this->srcwidgetoffs.x() + sx;
2371 +        rect1.YCoord = this->srcwidgetoffs.y() + sy;
2372 +        rect1.Width  = w;
2373 +        rect1.Height = h;
2374 +        rect2.XCoord = rx;
2375 +        rect2.YCoord = ry;
2376 +        rect2.Width = w;
2377 +        rect2.Height = h;
2378 +        for(int loopc = 0; loopc < this->ncliprect; loopc++ ) {
2379 +            if ( boundRect.intersects( this->cliprect[loopc] ) ) {
2380 +                ATI_CLIPRECT clip;
2381 +                clip.X_Top_Left     = this->cliprect[ loopc ].x();
2382 +                clip.Y_Top_Left     = this->cliprect[ loopc ].y();
2383 +                clip.X_Bottom_Right = this->cliprect[ loopc ].right() + 1;
2384 +                clip.Y_Bottom_Right = this->cliprect[ loopc ].bottom() + 1;
2385 +                driver.setDstClippingRect( &clip );
2386 +                driver.bitBlt( 1, &rect2, &rect1 );
2387 +            }
2388 +        }
2389 +        GFX_END;
2390 +      
2391 +        QWSDisplay::ungrab();
2392 +        return;
2393 +    } else {
2394 +        QWSDisplay::ungrab();
2395 +        driver.addMiss( W100Driver::BITBLT );
2396 +        QGfxRaster<depth,type>::blt( rx, ry, 
2397 +                                     w, h, sx, sy );
2398 +    }
2399 +}
2400 +
2401 +
2402 +template <const int depth, const int type>
2403 +void QGfxW100<depth,type>::tiledBlt( int rx,int ry,int w,int h )
2404 +{
2405 +    if ( w <= 0 || h <= 0 )
2406 +        return;
2407 +    QRect r;
2408 +    if ( inDraw ) {
2409 +        r = QRect(rx,ry,w,h);
2410 +    } else {
2411 +        r.setCoords( tx(rx,ry), ty(rx,ry), tx(rx+w-1,ry+h-1), ty(rx+w-1,ry+h-1) );
2412 +        r = r.normalize();
2413 +    }
2414 +
2415 +    inDraw = TRUE;
2416 +
2417 +    QPoint oldBrushOffs = this->brushoffs;
2418 +    int brx, bry;
2419 +    switch ( qt_w100_screen->transformation() ) {
2420 +    case QW100Screen::Rot90:
2421 +        brx = this->brushoffs.y();
2422 +        bry = this->srcwidth - this->brushoffs.x() - w;
2423 +        break;
2424 +    case QW100Screen::Rot180:
2425 +        brx = this->srcwidth - this->brushoffs.x() - w;
2426 +        bry = this->srcheight - this->brushoffs.y() - h;
2427 +        break;
2428 +    case QW100Screen::Rot270:
2429 +        brx = this->srcheight - this->brushoffs.y() - h;
2430 +        bry = this->brushoffs.x();
2431 +        break;
2432 +    default:
2433 +        brx = this->brushoffs.x();
2434 +        bry = this->brushoffs.y();
2435 +        break;
2436 +    }
2437 +    this->brushoffs = QPoint( brx, bry );
2438 +
2439 +    int oldsw = this->srcwidth;
2440 +    int oldsh = this->srcheight;
2441 +    QSize s = qt_screen->mapToDevice( QSize(this->srcwidth,this->srcheight) );
2442 +    this->srcwidth = s.width();
2443 +    this->srcheight = s.height();
2444 +
2445 +    dTiledBlt( r.x(), r.y(), r.width(), r.height() );
2446 +
2447 +    this->srcwidth = oldsw;
2448 +    this->srcheight = oldsh;
2449 +    this->brushoffs = oldBrushOffs;
2450 +    inDraw = FALSE;
2451 +}
2452 +
2453 +
2454 +template <const int depth, const int type>
2455 +void QGfxW100<depth,type>::dTiledBlt( int rx,int ry, int w,int h )
2456 +{
2457 +    if ( this->srcwidth == 0 || this->srcheight == 0 )
2458 +        return;
2459 +    QGfxRaster<depth,type>::tiledBlt( rx, ry, w, h );
2460 +}
2461 +
2462 +template<const int depth,const int type>
2463 +void QGfxW100<depth,type>::sync()
2464 +{
2465 +    driver.waitComplete( -1 );
2466 +}
2467 +
2468 +template <const int depth, const int type>
2469 +void QGfxW100<depth,type>::setSourceWidgetOffset(int x, int y)
2470 +{
2471 +    if ( this->srcbits == this->buffer ) {
2472 +        switch ( qt_w100_screen->transformation() ) {
2473 +        case QW100Screen::Rot90:
2474 +            this->srcwidgetoffs = QPoint( y, this->width - x - this->srcwidth );
2475 +            break;
2476 +        case QW100Screen::Rot180:
2477 +            this->srcwidgetoffs = QPoint( this->width - x - this->srcwidth, this->height - y - this->srcheight );
2478 +            break;
2479 +        case QW100Screen::Rot270:
2480 +            this->srcwidgetoffs = QPoint( this->height - y - this->srcheight, x );
2481 +            break;
2482 +        default:
2483 +            this->srcwidgetoffs = QPoint( x, y );
2484 +            break;
2485 +        }
2486 +    } else {
2487 +        this->srcwidgetoffs = QPoint( x, y );
2488 +    }
2489 +}
2490 +
2491 +template <const int depth, const int type>
2492 +void QGfxW100<depth,type>::processSpans( int n, QPoint* point, int* width )
2493 +{
2494 +    if ( inDraw || 
2495 +         this->patternedbrush && 
2496 +         this->srcwidth != 0 && 
2497 +         this->srcheight != 0 ) {
2498 +        //in the patternedbrush case, we let blt do the transformation
2499 +        // so we leave inDraw false.
2500 +        QGfxRaster<depth,type>::processSpans( n, point, width );
2501 +    } else {
2502 +        inDraw = true;
2503 +        while (n--) {
2504 +            if ( *width > 0 ) {
2505 +                int x=tx(point->x(),point->y())+this->xoffs;
2506 +                int y=ty(point->x(),point->y())+this->yoffs;
2507 +
2508 +                switch( qt_w100_screen->transformation() ) {
2509 +                case QW100Screen::Rot90:
2510 +                    this->vline( x, y-(*width-1), y );
2511 +                    break;
2512 +                case QW100Screen::Rot180:
2513 +                    this->hline( x - (*width-1), x, y );
2514 +                    break;
2515 +                case QW100Screen::Rot270:
2516 +                    this->vline( x, y, y+*width-1 );
2517 +                    break;
2518 +                default:
2519 +                    this->hline( x, x+*width-1, y );
2520 +                    break;
2521 +                }
2522 +            }
2523 +            point++;
2524 +            width++;
2525 +        }
2526 +        inDraw = false;
2527 +    }
2528 +}
2529 +
2530 +QW100Screen::QW100Screen( int display_id )
2531 +    :QLinuxFbScreen( display_id ),
2532 +     vramoffset( 0 ),
2533 +     m_isServer( false )
2534 +{
2535 +    qt_w100_screen = this;
2536 +    vramoffset = 0;
2537 +    clearCacheFunc = &clearCache;
2538 +    trans = None;
2539 +}
2540 +
2541 +static const char *trans2str( QW100Screen::Transformation t )
2542 +{
2543 +    switch( t ) {
2544 +    case QW100Screen::None:
2545 +        return "None";
2546 +        break;
2547 +    case QW100Screen::Rot90:
2548 +        return "Rot90";
2549 +        break;
2550 +    case QW100Screen::Rot180:
2551 +        return "Rot180";
2552 +        break;
2553 +    case QW100Screen::Rot270:
2554 +        return "Rot270";
2555 +        break;
2556 +    default:
2557 +        return "Unknown";
2558 +        break;
2559 +    }
2560 +}
2561 +
2562 +QW100Screen::Transformation QW100Screen::getTransSpec( const QString &dspec )
2563 +{
2564 +    Transformation mytrans = None;
2565 +    if ( dspec.find( ":Rot270" ) >= 0 ) {
2566 +        mytrans = Rot270;
2567 +    } else if ( dspec.find( ":Rot180" ) >= 0 ) {
2568 +        mytrans = Rot180;
2569 +    } else if ( dspec.find( ":Rot90" ) >= 0 ) {
2570 +        mytrans = Rot90;
2571 +    }
2572 +    return mytrans;
2573 +}
2574 +
2575 +bool QW100Screen::connect( const QString &displaySpec )
2576 +{
2577 +    driver.log( W100Driver::WARNING, "QW100Screen::connect('%s')",
2578 +                 displaySpec.latin1() );
2579 +    trans = getTransSpec( displaySpec );
2580 +
2581 +    if ( QLinuxFbScreen::connect( displaySpec ) ) {
2582 +        vramoffset = ( w == 320 ) ? 0 : 0x0f000000;
2583 +        if ( driver.processAttach() == W100Driver::codOK ) {
2584 +            driver.processAttachSpecialMode( ( w == 480 ) ? 0xaaab : 0xaaaa );
2585 +            surfaceMap.clear();
2586 +            surfaceMap.insert( 0, HWSurface( vramoffset, 
2587 +                                             data , false, 
2588 +                                             w*h*d/8 ) );
2589 +            canaccel = true;
2590 +            QSize s = mapFromDevice( QSize( w, h ) );
2591 +            w = s.width();
2592 +            h = s.height();
2593 +            return true;
2594 +        }
2595 +    }
2596 +    return false;
2597 +}
2598 +
2599 +void QW100Screen::disconnect( void )
2600 +{
2601 +    driver.log( W100Driver::WARNING, "QW100Screen::disconnect()" );
2602 +    driver.processDetachSpecialMode();
2603 +    driver.processDetach();
2604 +    QLinuxFbScreen::disconnect();
2605 +    printf( "[%d]QW100Screen disconnected with %d surfaces\n", 
2606 +            getpid(), surfaceMap.count() );
2607 +    surfaceMap.clear();
2608 +}
2609 +
2610 +void QW100Screen::prepareToSuspend( void )
2611 +{
2612 +
2613 +    driver.log( W100Driver::WARNING,
2614 +                 "QW100Screen::prepareToSuspend. Server = %s",
2615 +                 m_isServer ? "true" : "false" );
2616 +
2617 +    QWSDisplay::grab( true );
2618 +    driver.waitComplete( -1 );
2619 +
2620 +    if ( !driver.attached() ) {
2621 +        driver.log( W100Driver::ERROR, "Driver was not attached. " );
2622 +    } else {
2623 +        driver.processDetachSpecialMode();
2624 +        driver.processDetach();
2625 +    }
2626 +    QWSDisplay::ungrab();
2627 +
2628 +    driver.log( W100Driver::WARNING, "prepareToSuspend done" );
2629 +
2630 +}
2631 +
2632 +void QW100Screen::prepareToResume( void )
2633 +{
2634 +
2635 +    driver.log( W100Driver::WARNING,
2636 +                 "QW100Screen::prepareToResume. Server = %s",
2637 +                 m_isServer ? "true": "false" );
2638 +
2639 +    driver.processAttach();
2640 +    driver.processAttachSpecialMode( ( w == 480 ) ? 0xaaab : 0xaaaa );
2641 +    if ( m_isServer ) {
2642 +        QWSDisplay::grab( true );
2643 +        w100init();
2644 +        QWSDisplay::ungrab();
2645 +        driver.log( W100Driver::WARNING, "W100 restarted" );
2646 +    }
2647 +    driver.log( W100Driver::WARNING, "prepareToResume done" );
2648 +
2649 +}
2650 +
2651 +QW100Screen::~QW100Screen()
2652 +{
2653 +}
2654 +
2655 +bool QW100Screen::w100init()
2656 +{
2657 +    driver.log( W100Driver::WARNING,
2658 +                 "QW100Screen::w100init(%dx%d)", dw, dh );
2659 +    ATI_GRAPHICWINDOW win;
2660 +    ATI_CLIPRECT      clip;
2661 +    uint16_t          overlay;
2662 +
2663 +    win.dummy1 = 0;
2664 +    win.Size.XCoord = 0;
2665 +    win.Size.YCoord = 0;
2666 +    win.Size.Width = dw;
2667 +    win.Size.Height = dh;
2668 +    win.Width = dw > dh ? dh : dw;
2669 +    win.Height = dw > dh ? dw : dh;
2670 +    win.Flag = DSTTYPE_16BPP_444;
2671 +
2672 +    driver.waitComplete( -1 );
2673 +    driver.setGraphicWindowOnOff( 0 );    
2674 +
2675 +    driver.setupGraphicWindow( &win );
2676 +    driver.setGraphicWindowPos( 0, 0 );
2677 +
2678 +    driver.setFrontBuffer( vramoffset, 0, 0 );
2679 +    driver.setDstPitchOffset( dw, vramoffset );
2680 +    driver.setDstType( DSTTYPE_16BPP_444 );
2681 +    driver.setSrcPitchOffset( dw, vramoffset );
2682 +    driver.setSrcType( SRCTYPE_SOLID_COLOR_BLT );
2683 +    clip.X_Top_Left = 0;
2684 +    clip.Y_Top_Left = 0;
2685 +    clip.X_Bottom_Right = dw;
2686 +    clip.Y_Bottom_Right = dh;
2687 +    driver.setDstClippingRect( &clip );
2688 +    
2689 +    clip.X_Top_Left = 0xE000;
2690 +    clip.Y_Top_Left = 0xE000;
2691 +    clip.X_Bottom_Right = 0x1FFF;
2692 +    clip.Y_Bottom_Right = 0x1FFF;
2693 +    
2694 +    driver.setSrcClippingRect( &clip );
2695 +
2696 +    driver.setRopOperation( ROP3_SRCCOPY );
2697 +    driver.setGraphicWindowOnOff( 1 );
2698 +    driver.allocOverlay( &overlay );
2699 +    driver.setOverlayOnOff( overlay, 0 );
2700 +    driver.releaseOverlay( overlay );
2701 +    driver.setDstPitchOffset( dw, vramoffset );
2702 +    driver.setDstClippingRect( NULL );
2703 +    for ( int i = 0; i < dw * dh ; i++ ) {
2704 +        *( data + i ) = 0;
2705 +    }
2706 +    driver.waitComplete( -1 );
2707 +    return true;
2708 +}
2709 +
2710 +void QW100Screen::w100shutdown()
2711 +{
2712 +}
2713 +
2714 +bool QW100Screen::initDevice()
2715 +{
2716 +    QWSDisplay::grab( true );
2717 +    driver.log( W100Driver::WARNING, "initDevice( dw=%d, dh=%d )",
2718 +                 dw, dh );
2719 +    m_isServer = true;
2720 +
2721 +    if ( !w100init() ) {
2722 +        QWSDisplay::ungrab();
2723 +        return false;
2724 +    }
2725 +
2726 +    if ( QLinuxFbScreen::initDevice() ) {
2727 +        //HACK
2728 +        //Some sprite corruption seems to be avoided
2729 +        //reserving some upper memory on the offscreen framebuffer memory
2730 +        QLinuxFbScreen::cache( 65535 * 2, 0 );
2731 +        QWSDisplay::ungrab();
2732 +        return true;
2733 +    }
2734 +    QWSDisplay::ungrab();
2735 +    return false;
2736 +}
2737 +
2738 +void QW100Screen::shutdownDevice()
2739 +{
2740 +    driver.log( W100Driver::WARNING, "Shutting down device" );
2741 +    QLinuxFbScreen::shutdownDevice();
2742 +}
2743 +
2744 +void QW100Screen::restore()
2745 +{
2746 +    driver.log( W100Driver::WARNING, "Restoring W100..." );
2747 +    QLinuxFbScreen::restore();
2748 +    driver.log( W100Driver::WARNING, "Restoring done" );
2749 +}
2750 +
2751 +
2752 +QGfx *QW100Screen::createGfx( unsigned char *b,
2753 +                              int w, int h, int d, int linestep )
2754 +{
2755 +    //We need ALL the gfx created to be QGfxW100 to allow software
2756 +    //drawing syncing after hardware operations
2757 +    QGfx * ret=0;
2758 +    if ( false ) {
2759 +#ifndef QT_NO_QWS_DEPTH_1
2760 +    } else if ( d == 1 ) {
2761 +        ret = new QGfxW100<1,0>( b, w, h );
2762 +#endif
2763 +#ifndef QT_NO_QWS_DEPTH_4
2764 +    } else if ( d == 4 ) {
2765 +        ret = new QGfxW100<4,0>( b, w, h );
2766 +#endif
2767 +#ifndef QT_NO_QWS_DEPTH_8
2768 +    } else if ( d == 8 ) {
2769 +        ret = new QGfxW100<8,0>( b, w, h );
2770 +#endif
2771 +#ifndef QT_NO_QWS_DEPTH_16    
2772 +    } else if  ( d == 16 ) {
2773 +        ret = new QGfxW100<16,0>( b, w, h );
2774 +#endif
2775 +#ifndef QT_NO_QWS_DEPTH_24
2776 +    } else if ( d == 24 ) {
2777 +        ret = new QGfxW100<24,0>( b, w, h );
2778 +#endif
2779 +#ifndef QT_NO_QWS_DEPTH_32
2780 +    } else if ( d == 32 ) {
2781 +        ret = new QGfxW100<32,0>( b, w, h );
2782 +#endif
2783 +    } else {
2784 +        qFatal( "Unsupported depth %d\n", d );
2785 +        ret = 0;
2786 +    }
2787 +
2788 +    ret->setLineStep( linestep );
2789 +    return ret;
2790 +}
2791 +
2792 +
2793 +uchar *QW100Screen::cache( int amount, int optim )
2794 +{
2795 +    unsigned short hSurface = 0;
2796 +    uint32_t surfaceOffset = 0;
2797 +    uchar* localAddr = 0;
2798 +    bool internal = false;
2799 +
2800 +    /* The size must have 0xF bit zeroed (16 multiple)*/
2801 +    /* Perhaps this is not needed anymore, after setting
2802 +     * QW100Screen::pixmapLinestepAlignment to 128
2803 +     */
2804 +    amount = ( amount & 0x0F ) ? ( amount | 0x10 ) & ~0x0F : amount;
2805 +
2806 +    /* Experimenting memory corruption with the
2807 +     * internal AtiCore memory allocation routines
2808 +     * disabled for now
2809 +     */
2810 +#if 1
2811 +    if ( !( localAddr = QLinuxFbScreen::cache( amount, optim ) ) ) {
2812 +        return( 0 );
2813 +    }
2814 +    surfaceOffset = vramoffset + ( uint32_t ) localAddr - ( uint32_t )data;
2815 +
2816 +#else
2817 +    int retcode = 0;
2818 +    qt_fbdpy->grab( true );
2819 +    retcode = driver.allocateSurface( &hSurface,
2820 +                                           &surfaceOffset,
2821 +                                           amount, 1 );
2822 +    qt_fbdpy->ungrab();
2823 +    if ( retcode ) {
2824 +        internal = true;
2825 +        driver.setupMemoryTransfer( surfaceOffset, 
2826 +                                         (uint32_t*) &localAddr );
2827 +        driver.terminateMemoryTransfer();
2828 +    } else {
2829 +        // Try to use the offscreen framebuffer memory
2830 +        // to allocate the surface. Use the qgfxlinuxfb routines
2831 +        if ( !( localAddr = QLinuxFbScreen::cache( amount, optim ) ) ) {
2832 +            return( 0 );
2833 +        }
2834 +        //Distance between physical vram start and surface should be
2835 +        //the same than distance between logical addresses
2836 +        surfaceOffset = vramoffset + ( uint32_t ) localAddr - ( uint32_t ) data;
2837 +    }
2838 +#endif
2839 +    
2840 +    HWSurface surface( hSurface, surfaceOffset,
2841 +                       localAddr, amount, 
2842 +                       internal,
2843 +                       qws_client_id );
2844 +    surfaceMap.insert( surface.getAddr(), surface );
2845 +    return( ( uchar* ) localAddr );
2846 +}
2847 +
2848 +void QW100Screen::uncache( uchar *c )
2849 +{
2850 +    QMap< uchar*, HWSurface >::Iterator itr;
2851 +    if ( ( itr = surfaceMap.find( c ) ) != surfaceMap.end() ) {
2852 +        driver.waitComplete( -1 );
2853 +        if ( itr.data().internal() ) {
2854 +            qt_fbdpy->grab( true );
2855 +            driver.destroySurface( itr.data().getHandle() );
2856 +            qt_fbdpy->ungrab();
2857 +        } else {
2858 +            QLinuxFbScreen::uncache( c );
2859 +        }
2860 +        surfaceMap.remove( itr );
2861 +    }
2862 +}
2863 +
2864 +bool QW100Screen::onCard( uchar *p ) const
2865 +{
2866 +    QMap< uchar*, HWSurface >::ConstIterator itr = surfaceMap.begin();
2867 +    for ( ; itr != surfaceMap.end(); itr++ ) {
2868 +        uchar *begin;
2869 +        if ( ( begin = itr.data().getAddr() ) <= p ) {
2870 +            if ( ( itr.data().getSize() + begin ) >= p ) {
2871 +                return TRUE;
2872 +            }
2873 +        }
2874 +    }
2875 +    return FALSE;
2876 +}
2877 +
2878 +bool QW100Screen::onCard( unsigned char *p, ulong& offset ) const
2879 +{
2880 +    QMap< uchar*, HWSurface >::ConstIterator itr;
2881 +    for ( itr = surfaceMap.begin(); itr != surfaceMap.end(); itr++ ) {
2882 +        uchar *begin;
2883 +        if ( ( begin = itr.data().getAddr() ) <= p ) {
2884 +            if ( ( itr.data().getSize() + begin ) >= p ) {
2885 +                offset = itr.data().getSOffset() + ( p - begin );
2886 +                return TRUE;
2887 +            }
2888 +        }
2889 +    }
2890 +    return FALSE;
2891 +}
2892 +
2893 +QMap< uchar*, QW100Screen::HWSurface > 
2894 +*QW100Screen::getPSurfaceMap( void ) const
2895 +{
2896 +    return ( QMap<uchar*,HWSurface> *) &surfaceMap;
2897 +}
2898 +
2899 +void QW100Screen::clearCache( int clientId )
2900 +{
2901 +    printf( "[%d] CLEARING CACHE FOR %d\n", getpid(), clientId );
2902 +    driver.log( W100Driver::WARNING, "Cleaning cache for '%d'", clientId );
2903 +    QMap< uchar*, HWSurface >::Iterator itr = surfaceMap.begin();
2904 +    while ( itr != surfaceMap.end() ) {
2905 +        if ( itr.data().getCId() == clientId ) {
2906 +            if ( itr.data().internal() ) {
2907 +                qt_fbdpy->grab();
2908 +                driver.destroySurface( itr.data().getHandle() );
2909 +                qt_fbdpy->ungrab();
2910 +            }
2911 +            surfaceMap.remove( itr );
2912 +        }
2913 +        itr++;
2914 +    }
2915 +    QLinuxFbScreen::clearCache( this, clientId );
2916 +}
2917 +
2918 +void QW100Screen::clearCache( QScreen *instance, int clientId )
2919 +{
2920 +    QW100Screen *screen = reinterpret_cast<QW100Screen *> ( instance );
2921 +    screen->clearCache( clientId );
2922 +}
2923 +
2924 +void QW100Screen::setTransformation( Transformation t )
2925 +{
2926 +    qt_fbdpy->grab( true );
2927 +    trans = t;
2928 +  
2929 +    QSize s = mapFromDevice( QSize( dw,dh ) );
2930 +    w = s.width();
2931 +    h = s.height();
2932 +    qt_fbdpy->ungrab();
2933 +}
2934 +
2935 +QW100Screen::Transformation QW100Screen::transformation( void ) const
2936 +{
2937 +    return trans;
2938 +}
2939 +
2940 +QSize QW100Screen::mapToDevice( const QSize &s ) const
2941 +{
2942 +    if ( trans == Rot90 || trans == Rot270 ) {
2943 +        return QSize( s.height(), s.width() );
2944 +    }
2945 +
2946 +    return s;
2947 +}
2948 +
2949 +QSize QW100Screen::mapFromDevice( const QSize &s ) const
2950 +{
2951 +    if ( trans == Rot90 || trans == Rot270 ) {
2952 +        return QSize( s.height(), s.width() );
2953 +    }
2954 +
2955 +    return s;
2956 +}
2957 +
2958 +QPoint QW100Screen::mapToDevice( const QPoint &p, const QSize &s ) const
2959 +{
2960 +    QPoint rp( p );
2961 +
2962 +    switch ( trans ) {
2963 +       case Rot90:
2964 +           rp.setX( p.y() );
2965 +           rp.setY( s.width() - p.x() - 1 );
2966 +           break;
2967 +       case Rot180:
2968 +           rp.setX( s.width() - p.x() - 1 );
2969 +           rp.setY( s.height() - p.y() - 1 );
2970 +           break;
2971 +       case Rot270:
2972 +           rp.setX( s.height() - p.y() - 1 );
2973 +           rp.setY( p.x() );
2974 +           break;
2975 +       default:
2976 +           break;
2977 +    }
2978 +
2979 +    return rp;
2980 +}
2981 +
2982 +QPoint QW100Screen::mapFromDevice( const QPoint &p, const QSize &s ) const
2983 +{
2984 +    QPoint rp( p );
2985 +
2986 +    switch ( trans ) {
2987 +       case Rot90:
2988 +           rp.setX( s.height() - p.y() - 1 );
2989 +           rp.setY( p.x() );
2990 +           break;
2991 +       case Rot180:
2992 +           rp.setX( s.width() - p.x() - 1 );
2993 +           rp.setY( s.height() - p.y() - 1 );
2994 +           break;
2995 +       case Rot270:
2996 +           rp.setX( p.y() );
2997 +           rp.setY( s.width() - p.x() - 1 );
2998 +           break;
2999 +       default:
3000 +           break;
3001 +    }
3002 +
3003 +    return rp;
3004 +}
3005 +
3006 +QRect QW100Screen::mapToDevice( const QRect &r, const QSize &s ) const
3007 +{
3008 +    QRect tr;
3009 +    switch ( trans ) {
3010 +       case Rot90:
3011 +           tr.setCoords( r.y(), s.width() - r.x() - 1,
3012 +                      r.bottom(), s.width() - r.right() - 1 );
3013 +           break;
3014 +       case Rot180:
3015 +           tr.setCoords( s.width() - r.x() - 1, s.height() - r.y() - 1,
3016 +                      s.width() - r.right() - 1, s.height() - r.bottom() - 1 );
3017 +           break;
3018 +       case Rot270:
3019 +           tr.setCoords( s.height() - r.y() - 1, r.x(),
3020 +                      s.height() - r.bottom() - 1, r.right() );
3021 +           break;
3022 +       default:
3023 +           tr = r;
3024 +           break;
3025 +    }
3026 +
3027 +    return tr.normalize();
3028 +}
3029 +
3030 +QRect QW100Screen::mapFromDevice( const QRect &r, const QSize &s ) const
3031 +{
3032 +    QRect tr;
3033 +    switch ( trans ) {
3034 +       case Rot90:
3035 +           tr.setCoords( s.height() - r.y() - 1, r.x(),
3036 +                      s.height() - r.bottom() - 1, r.right() );
3037 +           break;
3038 +       case Rot180:
3039 +           tr.setCoords( s.width() - r.x() - 1, s.height() - r.y() - 1,
3040 +                      s.width() - r.right() - 1, s.height() - r.bottom() - 1 );
3041 +           break;
3042 +       case Rot270:
3043 +           tr.setCoords( r.y(), s.width() - r.x() - 1,
3044 +                      r.bottom(), s.width() - r.right() - 1 );
3045 +           break;
3046 +       default:
3047 +           tr = r;
3048 +           break;
3049 +    }
3050 +
3051 +    return tr.normalize();
3052 +}
3053 +
3054 +template<class T>
3055 +static inline void rotateLoopTemplate( uchar *src, int srcBytesPerLine,
3056 +                                       uchar *dst, int dstBytesPerLine, 
3057 +                                       int width, int height,
3058 +                                       QW100Screen::Transformation trans, 
3059 +                                       bool mapToDevice )
3060 +{
3061 +    int dstXAdd = 0;
3062 +    int dstYAdd = 0;
3063 +    int dstXOfs = 0;
3064 +    int dstYOfs = 0;
3065 +    int srcYAdd = srcBytesPerLine - width * sizeof(T);
3066 +
3067 +    if ( !mapToDevice ) {
3068 +        if ( trans == QW100Screen::Rot90 )
3069 +            trans = QW100Screen::Rot270;
3070 +        else if ( trans == QW100Screen::Rot270 )
3071 +            trans = QW100Screen::Rot90;
3072 +    }
3073 +
3074 +    switch ( trans ) {
3075 +       case QW100Screen::Rot90:
3076 +           dstXOfs = 0;
3077 +           dstYOfs = width - 1;
3078 +           dstXAdd = -dstBytesPerLine;
3079 +           dstYAdd = 1 * sizeof(T) + width * dstBytesPerLine;
3080 +           break;
3081 +       case QW100Screen::Rot270:
3082 +           dstXOfs = height - 1;
3083 +           dstYOfs = 0;
3084 +           dstXAdd = dstBytesPerLine;
3085 +           dstYAdd = -1 * sizeof(T) - width * dstBytesPerLine;
3086 +           break;
3087 +       default:
3088 +           dstXOfs = width - 1;
3089 +           dstYOfs = height - 1;
3090 +           dstXAdd = -1 * sizeof(T);
3091 +           dstYAdd = -dstBytesPerLine + width * sizeof(T);
3092 +           break;
3093 +    };
3094 +
3095 +    T *dstPtr = (T *)(dst + dstYOfs * dstBytesPerLine) + dstXOfs;
3096 +    T *srcPtr = (T *)src;
3097 +    for ( int y = 0; y < height; y++ ) {
3098 +        for ( int x = 0; x < width; x++ ) {
3099 +            *dstPtr = *srcPtr++;
3100 +            dstPtr = (T *)((uchar*)dstPtr + dstXAdd); // add dstXAdd number of bytes
3101 +        }
3102 +        srcPtr = (T *)((uchar*)srcPtr + srcYAdd); // add srcYAdd number of bytes
3103 +        dstPtr = (T *)((uchar*)dstPtr + dstYAdd); // add dstYAdd number of bytes
3104 +    }
3105 +}
3106 +
3107 +QImage QW100Screen::mapToDevice( const QImage &img ) const
3108 +{
3109 +    if ( img.isNull() || trans == None )
3110 +        return img;
3111 +
3112 +    int iw = img.width();
3113 +    int ih = img.height();
3114 +    int w = iw;
3115 +    int h = ih;
3116 +    if ( trans == Rot90 || trans == Rot270 ) {
3117 +        w = ih;
3118 +        h = iw;
3119 +    }
3120 +
3121 +    QImage rimg( w, h, img.depth(), img.numColors(), img.bitOrder() );
3122 +
3123 +    for ( int i = 0; i < img.numColors(); i++ ) {
3124 +        rimg.colorTable()[i] = img.colorTable()[i];
3125 +    }
3126 +
3127 +    // Optimized image rotation code for nice bit depths
3128 +    int d = img.depth();
3129 +    if ( d == 8 || d == 16 || d == 32 ) {
3130 +        int srcBytesPerLine = img.bytesPerLine();
3131 +        int dstBytesPerLine = rimg.bytesPerLine();
3132 +        uchar *srcBits = img.bits();
3133 +        uchar *dstBits = rimg.bits();
3134 +        switch ( d ) {
3135 +           case 8:
3136 +            rotateLoopTemplate<uchar>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, TRUE );
3137 +            break;
3138 +           case 16:
3139 +            rotateLoopTemplate<ushort>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, TRUE );
3140 +            break;
3141 +           case 32:
3142 +            rotateLoopTemplate<uint>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, TRUE );
3143 +            break;
3144 +        }
3145 +        rimg.setAlphaBuffer( img.hasAlphaBuffer() );
3146 +        rimg.setOffset( img.offset() );
3147 +        return rimg;
3148 +    }
3149 +
3150 +    // Slower fall back code for image rotation for 1-bit and other depths
3151 +#define ROTATE_LOOP( X, Y, VAL ) \
3152 +                   for ( int y = 0; y < ih; y++ ) { \
3153 +                       for ( int x = 0; x < iw; x++ ) { \
3154 +                           rimg.setPixel( X, Y, VAL ); \
3155 +                       } \
3156 +                   } \
3157 +                   break;
3158 +
3159 +    if ( img.depth() > 8 ) {
3160 +        switch ( trans ) {
3161 +           case Rot90:
3162 +            ROTATE_LOOP( y, iw - x - 1, img.pixel(x, y) )
3163 +                case Rot270:
3164 +                ROTATE_LOOP( ih - y - 1, x, img.pixel(x, y) );
3165 +           default:
3166 +            ROTATE_LOOP( iw - x - 1, ih - y - 1, img.pixel(x, y) );
3167 +        }
3168 +    } else {
3169 +        switch ( trans ) {
3170 +           case Rot90:
3171 +            ROTATE_LOOP( y, iw - x - 1, img.pixelIndex(x, y) );
3172 +           case Rot270:
3173 +            ROTATE_LOOP( ih - y - 1, x, img.pixelIndex(x, y) );
3174 +           default:
3175 +            ROTATE_LOOP( iw - x - 1, ih - y - 1, img.pixelIndex(x, y) );
3176 +        }
3177 +    }
3178 +
3179 +#undef ROTATE_LOOP
3180 +
3181 +    rimg.setAlphaBuffer( img.hasAlphaBuffer() );
3182 +    rimg.setOffset( img.offset() );
3183 +
3184 +    return rimg;
3185 +}
3186 +
3187 +QImage QW100Screen::mapFromDevice( const QImage &img ) const
3188 +{
3189 +    if ( img.isNull() || trans == None )
3190 +        return img;
3191 +
3192 +    int iw = img.width();
3193 +    int ih = img.height();
3194 +    int w = iw;
3195 +    int h = ih;
3196 +    if ( trans == Rot90 || trans == Rot270 ) {
3197 +        w = ih;
3198 +        h = iw;
3199 +    }
3200 +
3201 +    QImage rimg( w, h, img.depth(), img.numColors(), img.bitOrder() );
3202 +
3203 +    for ( int i = 0; i < img.numColors(); i++ ) {
3204 +        rimg.colorTable()[i] = img.colorTable()[i];
3205 +    }
3206 +
3207 +    // Optimized image rotation code for nice bit depths
3208 +    int d = img.depth();
3209 +    if ( d == 8 || d == 16 || d == 32 ) {
3210 +        int srcBytesPerLine = img.bytesPerLine();
3211 +        int dstBytesPerLine = rimg.bytesPerLine();
3212 +        uchar *srcBits = img.bits();
3213 +        uchar *dstBits = rimg.bits();
3214 +        switch ( d ) {
3215 +           case 8:
3216 +            rotateLoopTemplate<uchar>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, FALSE );
3217 +            break;
3218 +           case 16:
3219 +            rotateLoopTemplate<ushort>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, FALSE );
3220 +            break;
3221 +           case 32:
3222 +            rotateLoopTemplate<uint>( srcBits, srcBytesPerLine, dstBits, dstBytesPerLine, iw, ih, trans, FALSE );
3223 +            break;
3224 +        }
3225 +        rimg.setAlphaBuffer( img.hasAlphaBuffer() );
3226 +        rimg.setOffset( img.offset() );
3227 +        return rimg;
3228 +    }
3229 +
3230 +    // Slower fall back code for image rotation for 1-bit and other depths
3231 +#define ROTATE_LOOP( X, Y, VAL ) \
3232 +                   for ( int y = 0; y < ih; y++ ) { \
3233 +                       for ( int x = 0; x < iw; x++ ) { \
3234 +                           rimg.setPixel( X, Y, VAL ); \
3235 +                       } \
3236 +                   } \
3237 +                   break;
3238 +
3239 +    if ( img.depth() > 8 ) {
3240 +        switch ( trans ) {
3241 +           case Rot90:
3242 +            ROTATE_LOOP( ih - y - 1, x, img.pixel(x, y) );
3243 +           case Rot270:
3244 +            ROTATE_LOOP( y, iw - x - 1, img.pixel(x, y) )
3245 +                default:
3246 +            ROTATE_LOOP( iw - x - 1, ih - y - 1, img.pixel(x, y) );
3247 +        }
3248 +    } else {
3249 +        switch ( trans ) {
3250 +           case Rot90:
3251 +            ROTATE_LOOP( ih - y - 1, x, img.pixelIndex(x, y) );
3252 +           case Rot270:
3253 +            ROTATE_LOOP( y, iw - x - 1, img.pixelIndex(x, y) );
3254 +           default:
3255 +            ROTATE_LOOP( iw - x - 1, ih - y - 1, img.pixelIndex(x, y) );
3256 +        }
3257 +    }
3258 +
3259 +#undef ROTATE_LOOP
3260 +
3261 +    rimg.setAlphaBuffer( img.hasAlphaBuffer() );
3262 +    rimg.setOffset( img.offset() );
3263 +
3264 +    return rimg;
3265 +}
3266 +
3267 +QRegion QW100Screen::mapToDevice( const QRegion &rgn, const QSize &s ) const
3268 +{
3269 +    if ( trans == None )
3270 +        return rgn;
3271 +
3272 +    QRegion trgn;
3273 +    QArray<QRect> a = rgn.rects();
3274 +    QRect tr;
3275 +    const QRect *r = a.data();
3276 +
3277 +    int w = s.width();
3278 +    int h = s.height();
3279 +    int size = a.size();
3280 +
3281 +    switch ( trans ) {
3282 +       case Rot270:
3283 +           for ( int i = 0; i < size; i++, r++ ) {
3284 +            tr.setCoords( h - r->y() - 1, r->x(),
3285 +                          h - r->bottom() - 1, r->right() );
3286 +            trgn |= tr.normalize();
3287 +           }
3288 +           break;
3289 +       case Rot90:
3290 +           for ( int i = 0; i < size; i++, r++ ) {
3291 +            tr.setCoords( r->y(), w - r->x() - 1,
3292 +                          r->bottom(), w - r->right() - 1 );
3293 +            trgn |= tr.normalize();
3294 +           }
3295 +           break;
3296 +       case Rot180:
3297 +           for ( int i = 0; i < size; i++, r++ ) {
3298 +            tr.setCoords( w - r->x() - 1, h - r->y() - 1,
3299 +                          w - r->right() - 1, h - r->bottom() - 1 );
3300 +            trgn |= tr.normalize();
3301 +           }
3302 +           break;
3303 +       default:
3304 +           break;
3305 +    }
3306 +    return trgn;
3307 +}
3308 +
3309 +QRegion QW100Screen::mapFromDevice( const QRegion &rgn, const QSize &s ) const
3310 +{
3311 +    if ( trans == None )
3312 +        return rgn;
3313 +
3314 +    QRegion trgn;
3315 +    QArray<QRect> a = rgn.rects();
3316 +    const QRect *r = a.data();
3317 +    QRect tr;
3318 +
3319 +    int w = s.width();
3320 +    int h = s.height();
3321 +    int size = a.size();
3322 +
3323 +    switch ( trans ) {
3324 +       case Rot270:
3325 +           for ( int i = 0; i < size; i++, r++ ) {
3326 +            tr.setCoords( r->y(), w - r->x() - 1,
3327 +                          r->bottom(), w - r->right() - 1 );
3328 +            trgn |= tr.normalize();
3329 +           }
3330 +           break;
3331 +       case Rot90:
3332 +           for ( int i = 0; i < size; i++, r++ ) {
3333 +            tr.setCoords( h - r->y() - 1, r->x(),
3334 +                          h - r->bottom() - 1, r->right() );
3335 +            trgn |= tr.normalize();
3336 +           }
3337 +           break;
3338 +       case Rot180:
3339 +           for ( int i = 0; i < size; i++, r++ ) {
3340 +            tr.setCoords( w - r->x() - 1, h - r->y() - 1,
3341 +                          w - r->right() - 1, h - r->bottom() - 1 );
3342 +            trgn |= tr.normalize();
3343 +           }
3344 +           break;
3345 +       default:
3346 +           break;
3347 +    }
3348 +
3349 +    return trgn;
3350 +}
3351 +
3352 +/*!
3353 +  0 = none
3354 +  1..3 = rotates 90..270
3355 +  4..7 = mirrored 0..3
3356 +*/
3357 +int QW100Screen::transformOrientation() const
3358 +{
3359 +    return (int)trans;
3360 +}
3361 +
3362 +
3363 +void qws_w100Transformation( int t )
3364 +{
3365 +    if ( qt_w100_screen ) {
3366 +        qt_w100_screen->setTransformation( static_cast<QW100Screen::Transformation>( t ) );
3367 +    }
3368 +}
3369 +
3370 +extern bool qws_accel;
3371 +
3372 +extern "C" QScreen * qt_get_screen_w100( int display_id )
3373 +{
3374 +    return( new QW100Screen( display_id ) );
3375 +}
3376 --- qt-2.3.10/src/kernel/qapplication_qws.cpp~w100
3377 +++ qt-2.3.10/src/kernel/qapplication_qws.cpp
3378 @@ -1450,16 +1450,25 @@
3379  extern void qws_clearLoadedFonts();
3380  #endif
3381  
3382 +#ifndef QT_NO_QWS_W100
3383 +extern void qws_w100Transformation( int t );
3384 +#endif
3385 +
3386  void QWSDisplay::setTransformation( int t )
3387  {
3388 -#ifndef QT_NO_QWS_TRANSFORMED
3389 +#if !defined(QT_NO_QWS_TRANSFORMED) || !defined(QT_NO_QWS_W100)
3390      QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
3391         QSize(qt_screen->width(), qt_screen->height()) );
3392  
3393      QPixmapCache::clear();
3394      qws_clearLoadedFonts();
3395      qws_mapPixmaps( TRUE );
3396 +#ifndef QT_NO_QWS_TRANSFORMED
3397      qws_setScreenTransformation( t );
3398 +#endif
3399 +#ifndef QT_NO_QWS_W100
3400 +    qws_w100Transformation( t );
3401 +#endif
3402      qws_mapPixmaps( FALSE );
3403  
3404      if ( qt_fbdpy->d->directServerConnection() ) {