~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/chips/ct_accel.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/ct_accel.c,v 1.40 2002/11/25 14:04:58 eich Exp $ */
 
2
/*
 
3
 * Copyright 1996, 1997, 1998 by David Bateman <dbateman@ee.uts.edu.au>
 
4
 *   Modified 1997, 1998 by Nozomi Ytow
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of the authors not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  The authors makes no representations
 
13
 * about the suitability of this software for any purpose.  It is provided
 
14
 * "as is" without express or implied warranty.
 
15
 *
 
16
 * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
 
 
25
/*
 
26
 * When monochrome tiles/stipples are cached on the HiQV chipsets the
 
27
 * pitch of the monochrome data is the displayWidth. The HiQV manuals
 
28
 * state that the source pitch is ignored with monochrome data, and so
 
29
 * "offically" there the XAA cached monochrome data can't be used. But
 
30
 * it appears that by not setting the monochrome source alignment in
 
31
 * BR03, the monochrome source pitch is forced to the displayWidth!!
 
32
 *
 
33
 * To enable the use of this undocumented feature, uncomment the define
 
34
 * below.
 
35
 */
 
36
#define UNDOCUMENTED_FEATURE
 
37
 
 
38
/* All drivers should typically include these */
 
39
#include "xf86.h"
 
40
#include "xf86_OSproc.h"
 
41
#include "xf86_ansic.h"
 
42
#include "compiler.h"
 
43
 
 
44
/* Drivers that need to access the PCI config space directly need this */
 
45
#include "xf86Pci.h"
 
46
 
 
47
/* Drivers for PCI hardware need this */
 
48
#include "xf86PciInfo.h"
 
49
 
 
50
/* Drivers that use XAA need this */
 
51
#include "xf86fbman.h"
 
52
 
 
53
/* Our driver specific include file */
 
54
#include "ct_driver.h"
 
55
 
 
56
#if !defined(UNIXCPP) || defined(ANSICPP)
 
57
#define CATNAME(prefix,subname) prefix##subname
 
58
#else
 
59
#define CATNAME(prefix,subname) prefix/**/subname
 
60
#endif
 
61
 
 
62
#ifdef CHIPS_MMIO
 
63
#ifdef CHIPS_HIQV
 
64
#include "ct_BltHiQV.h"
 
65
#define CTNAME(subname) CATNAME(CHIPSHiQV,subname)
 
66
#else
 
67
#include "ct_BlitMM.h"
 
68
#define CTNAME(subname) CATNAME(CHIPSMMIO,subname)
 
69
#endif
 
70
#else
 
71
#include "ct_Blitter.h"
 
72
#define CTNAME(subname) CATNAME(CHIPS,subname)
 
73
#endif
 
74
 
 
75
#ifdef DEBUG
 
76
# define DEBUG_P(x) ErrorF(x"\n");
 
77
#elif defined X_DEBUG
 
78
# define DEBUG_P(x) snprintf(CTNAME(accel_debug),1024,x"\n");
 
79
#else
 
80
# define DEBUG_P(x) /**/
 
81
#endif
 
82
 
 
83
#ifdef X_DEBUG
 
84
static char CTNAME(accel_debug)[1024];
 
85
#endif
 
86
 
 
87
#ifdef CHIPS_HIQV
 
88
static void CTNAME(DepthChange)(ScrnInfoPtr pScrn, int depth);
 
89
#endif
 
90
static void CTNAME(8SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
91
                                int rop, unsigned int planemask);
 
92
static void CTNAME(16SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
93
                                int rop, unsigned int planemask);
 
94
static void CTNAME(24SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
95
                                int rop, unsigned int planemask);
 
96
static void CTNAME(SubsequentSolidFillRect)(ScrnInfoPtr pScrn,
 
97
                                        int x, int y, int w, int h);
 
98
#ifndef CHIPS_HIQV
 
99
static void CTNAME(24SubsequentSolidFillRect)(ScrnInfoPtr pScrn,
 
100
                                        int x, int y, int w, int h);
 
101
#else
 
102
static void CTNAME(32SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
103
                                int rop, unsigned int planemask);
 
104
static void CTNAME(32SubsequentSolidFillRect)(ScrnInfoPtr pScrn,
 
105
                                        int x, int y, int w, int h);
 
106
#endif
 
107
static void CTNAME(SetupForScreenToScreenCopy)(ScrnInfoPtr pScrn, int xdir,
 
108
                                int ydir, int rop, unsigned int planemask,
 
109
                                int trans);
 
110
static void CTNAME(SubsequentScreenToScreenCopy)(ScrnInfoPtr pScrn,
 
111
                                int srcX, int srcY, int dstX, int dstY,
 
112
                                int w, int h);
 
113
static void CTNAME(SetupForCPUToScreenColorExpandFill)(ScrnInfoPtr pScrn, int fg,
 
114
                                int bg, int rop, unsigned int planemask);
 
115
static void CTNAME(SubsequentCPUToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
116
                                int x, int y, int w, int h, int skipleft);
 
117
#ifndef CHIPS_HIQV
 
118
static XAACacheInfoPtr CTNAME(CacheMonoStipple)(ScrnInfoPtr pScrn,
 
119
                                PixmapPtr pPix);
 
120
#endif
 
121
#if !defined(CHIPS_HIQV) || defined(UNDOCUMENTED_FEATURE)
 
122
static void CTNAME(SetupForScreenToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
123
                                int fg, int bg, int rop, 
 
124
                                unsigned int planemask);
 
125
static void CTNAME(SubsequentScreenToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
126
                                int x, int y, int w, int h,
 
127
                                int srcx, int srcy, int skipleft);
 
128
#endif
 
129
static void CTNAME(SetupForMono8x8PatternFill)(ScrnInfoPtr pScrn,
 
130
                                int patx, int paty, int fg, int bg,
 
131
                                int rop, unsigned int planemask);
 
132
static void CTNAME(SubsequentMono8x8PatternFillRect)(ScrnInfoPtr pScrn,
 
133
                                int patx, int paty,
 
134
                                int x, int y, int w, int h );
 
135
static void CTNAME(SetupForColor8x8PatternFill)(ScrnInfoPtr pScrn,
 
136
                                int patx, int paty, int rop,
 
137
                                unsigned int planemask, int trans);
 
138
static void CTNAME(SubsequentColor8x8PatternFillRect)(ScrnInfoPtr pScrn,
 
139
                                int patx, int paty,
 
140
                                int x, int y, int w, int h );
 
141
#ifndef CHIPS_HIQV
 
142
static void CTNAME(SetupForImageWrite)(ScrnInfoPtr pScrn, int rop,
 
143
                                unsigned int planemask,
 
144
                                int transparency_color, int bpp, int depth);
 
145
static void CTNAME(SubsequentImageWriteRect)(ScrnInfoPtr pScrn,
 
146
                                int x, int y, int w, int h, int skipleft);
 
147
#else
 
148
static void  CTNAME(WritePixmap)(ScrnInfoPtr pScrn, int x, int y, int w, int h,
 
149
                unsigned char *src, int srcwidth, int rop,
 
150
                unsigned int planemask, int trans, int bpp, int depth);
 
151
#if 0
 
152
static void  CTNAME(ReadPixmap)(ScrnInfoPtr pScrn, int x, int y, int w, int h,
 
153
                unsigned char *dst, int dstwidth, int bpp, int depth);
 
154
#endif
 
155
#endif
 
156
 
 
157
 
 
158
Bool 
 
159
CTNAME(AccelInit)(ScreenPtr pScreen)
 
160
{
 
161
    XAAInfoRecPtr infoPtr;
 
162
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
163
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
164
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
165
 
 
166
    DEBUG_P("AccelInit");
 
167
    cPtr->AccelInfoRec = infoPtr = XAACreateInfoRec();
 
168
    if(!infoPtr) return FALSE;
 
169
 
 
170
    /*
 
171
     * Setup some global variables
 
172
     */
 
173
    cAcl->BytesPerPixel = pScrn->bitsPerPixel >> 3;
 
174
    cAcl->BitsPerPixel = pScrn->bitsPerPixel;
 
175
    cAcl->PitchInBytes = pScrn->displayWidth * cAcl->BytesPerPixel;
 
176
    cAcl->planemask = -1;
 
177
    cAcl->bgColor = -1;
 
178
    cAcl->fgColor = -1;
 
179
    cAcl->FbOffset = 0;
 
180
    
 
181
    /*
 
182
     * Set up the main acceleration flags.
 
183
     */
 
184
    if (cAcl->CacheEnd > cAcl->CacheStart) infoPtr->Flags = PIXMAP_CACHE;
 
185
 
 
186
    if (cPtr->Flags & ChipsLinearSupport)
 
187
        infoPtr->Flags |= OFFSCREEN_PIXMAPS | LINEAR_FRAMEBUFFER;
 
188
 
 
189
    infoPtr->PixmapCacheFlags |= DO_NOT_BLIT_STIPPLES;
 
190
 
 
191
    /*
 
192
     * The following line installs a "Sync" function, that waits for
 
193
     * all coprocessor operations to complete.
 
194
     */
 
195
    infoPtr->Sync = CTNAME(Sync);
 
196
 
 
197
    /* 
 
198
     * Setup a Screen to Screen copy (BitBLT) primitive
 
199
     */  
 
200
#ifndef CHIPS_HIQV
 
201
    infoPtr->ScreenToScreenCopyFlags = NO_TRANSPARENCY;
 
202
    if (cAcl->BitsPerPixel == 24)
 
203
        infoPtr->ScreenToScreenCopyFlags |= NO_PLANEMASK;
 
204
#else
 
205
    infoPtr->ScreenToScreenCopyFlags = 0;
 
206
    if ((cAcl->BitsPerPixel == 24) || (cAcl->BitsPerPixel == 32))
 
207
        infoPtr->ScreenToScreenCopyFlags |= NO_PLANEMASK;
 
208
 
 
209
    /* A Chips and Technologies application notes says that some
 
210
     * 65550 have a bug that prevents 16bpp transparency. It probably
 
211
     * applies to 24 bpp as well (Someone with a 65550 care to check?).
 
212
     * Selection of this controlled in Probe.
 
213
     */
 
214
    if (!(cPtr->Flags & ChipsColorTransparency))
 
215
        infoPtr->ScreenToScreenCopyFlags |= NO_TRANSPARENCY;
 
216
#endif
 
217
 
 
218
    infoPtr->SetupForScreenToScreenCopy = CTNAME(SetupForScreenToScreenCopy);
 
219
    infoPtr->SubsequentScreenToScreenCopy =
 
220
                CTNAME(SubsequentScreenToScreenCopy);
 
221
 
 
222
    /*
 
223
     * Install the low-level functions for drawing solid filled rectangles.
 
224
     */
 
225
    infoPtr->SolidFillFlags |= NO_PLANEMASK;
 
226
    switch (cAcl->BitsPerPixel) {
 
227
    case 8 :
 
228
        infoPtr->SetupForSolidFill = CTNAME(8SetupForSolidFill);
 
229
        infoPtr->SubsequentSolidFillRect = CTNAME(SubsequentSolidFillRect);
 
230
        break;
 
231
    case 16 :
 
232
        infoPtr->SetupForSolidFill = CTNAME(16SetupForSolidFill);
 
233
        infoPtr->SubsequentSolidFillRect = CTNAME(SubsequentSolidFillRect);
 
234
        break;
 
235
    case 24 :
 
236
        infoPtr->SetupForSolidFill = CTNAME(24SetupForSolidFill);
 
237
#ifdef CHIPS_HIQV
 
238
        infoPtr->SubsequentSolidFillRect = CTNAME(SubsequentSolidFillRect);
 
239
#else
 
240
        /*
 
241
         * The version of this function here uses three different
 
242
         * algorithms in an attempt to maximise performance. One
 
243
         * for RGB_EQUAL, another for !RGB_EQUAL && GXCOPY_ONLY
 
244
         * and yet another for !RGB_EQUAL && !GXCOPY_ONLY. The
 
245
         * first two versions use the 8bpp engine for the fill,
 
246
         * whilst the second uses a framebuffer routine to create
 
247
         * one scanline of the fill in off screen memory which is
 
248
         * then used by a CopyArea function with a complex ROP.
 
249
         */
 
250
        infoPtr->SubsequentSolidFillRect = CTNAME(24SubsequentSolidFillRect);
 
251
        if (cAcl->ScratchAddress < 0)
 
252
            infoPtr->ScreenToScreenCopyFlags |= GXCOPY_ONLY;
 
253
#endif
 
254
        break;
 
255
#ifdef CHIPS_HIQV
 
256
    case 32:
 
257
        if (cAcl->ScratchAddress > 0) {
 
258
            infoPtr->SetupForSolidFill = CTNAME(32SetupForSolidFill);
 
259
            infoPtr->SubsequentSolidFillRect =
 
260
                CTNAME(32SubsequentSolidFillRect);
 
261
        }
 
262
        break;
 
263
#endif
 
264
    }
 
265
 
 
266
#ifdef CHIPS_HIQV
 
267
    /* At 32bpp we can't use the other acceleration */
 
268
    if (cAcl->BitsPerPixel == 32) goto chips_imagewrite;
 
269
#endif
 
270
 
 
271
    /*
 
272
     * Setup the functions that perform monochrome colour expansion
 
273
     */
 
274
 
 
275
#ifdef CHIPS_HIQV 
 
276
    infoPtr->CPUToScreenColorExpandFillFlags =
 
277
        BIT_ORDER_IN_BYTE_MSBFIRST | CPU_TRANSFER_PAD_QWORD |
 
278
        LEFT_EDGE_CLIPPING | LEFT_EDGE_CLIPPING_NEGATIVE_X |
 
279
        ROP_NEEDS_SOURCE;
 
280
#ifdef UNDOCUMENTED_FEATURE
 
281
    infoPtr->ScreenToScreenColorExpandFillFlags = BIT_ORDER_IN_BYTE_MSBFIRST
 
282
        | LEFT_EDGE_CLIPPING;
 
283
#endif        
 
284
    if (cAcl->BitsPerPixel == 24) {
 
285
        infoPtr->CPUToScreenColorExpandFillFlags |= NO_PLANEMASK;
 
286
#ifdef UNDOCUMENTED_FEATURE
 
287
        infoPtr->ScreenToScreenColorExpandFillFlags |= NO_PLANEMASK;
 
288
#endif
 
289
    }
 
290
    /* The ct65550 has problems with transparency which leads to video
 
291
     * corruption unless disabled.
 
292
     */
 
293
    if (!(cPtr->Flags & ChipsColorTransparency)) {
 
294
        infoPtr->CPUToScreenColorExpandFillFlags |= NO_TRANSPARENCY;
 
295
#ifdef UNDOCUMENTED_FEATURE
 
296
        infoPtr->ScreenToScreenColorExpandFillFlags |= NO_TRANSPARENCY;
 
297
#endif
 
298
    }
 
299
#else
 
300
    infoPtr->CPUToScreenColorExpandFillFlags =
 
301
        BIT_ORDER_IN_BYTE_MSBFIRST | CPU_TRANSFER_PAD_DWORD |
 
302
        ROP_NEEDS_SOURCE;
 
303
    infoPtr->ScreenToScreenColorExpandFillFlags = BIT_ORDER_IN_BYTE_MSBFIRST;
 
304
    infoPtr->CacheColorExpandDensity = 8;
 
305
 
 
306
    if (cAcl->BitsPerPixel == 24)
 
307
        infoPtr->CPUToScreenColorExpandFillFlags |= TRIPLE_BITS_24BPP |
 
308
            RGB_EQUAL | NO_PLANEMASK;
 
309
#endif
 
310
 
 
311
    infoPtr->SetupForCPUToScreenColorExpandFill =
 
312
                CTNAME(SetupForCPUToScreenColorExpandFill);
 
313
    infoPtr->SubsequentCPUToScreenColorExpandFill =
 
314
                CTNAME(SubsequentCPUToScreenColorExpandFill);
 
315
 
 
316
#ifndef CHIPS_HIQV 
 
317
    if (cAcl->BitsPerPixel != 24) {
 
318
#endif
 
319
#if !defined(CHIPS_HIQV) || defined(UNDOCUMENTED_FEATURE)
 
320
        infoPtr->SetupForScreenToScreenColorExpandFill = 
 
321
                CTNAME(SetupForScreenToScreenColorExpandFill);
 
322
        infoPtr->SubsequentScreenToScreenColorExpandFill = 
 
323
                CTNAME(SubsequentScreenToScreenColorExpandFill);
 
324
#endif
 
325
#ifndef CHIPS_HIQV 
 
326
        infoPtr->CacheMonoStipple = CTNAME(CacheMonoStipple);
 
327
    }
 
328
#endif    
 
329
 
 
330
    infoPtr->ColorExpandBase = (unsigned char *)cAcl->BltDataWindow;
 
331
    infoPtr->ColorExpandRange = 64 * 1024;
 
332
 
 
333
    /* Mono 8x8 pattern fills */
 
334
    infoPtr->Mono8x8PatternFillFlags = NO_PLANEMASK | 
 
335
        BIT_ORDER_IN_BYTE_MSBFIRST | HARDWARE_PATTERN_SCREEN_ORIGIN;
 
336
 
 
337
#ifdef CHIPS_HIQV
 
338
    infoPtr->SetupForMono8x8PatternFill =
 
339
        CTNAME(SetupForMono8x8PatternFill);
 
340
    infoPtr->SubsequentMono8x8PatternFillRect =
 
341
        CTNAME(SubsequentMono8x8PatternFillRect);
 
342
    if (cAcl->BitsPerPixel == 24)
 
343
      infoPtr->MonoPatternPitch = 8;            /* Need 8 byte alignment */
 
344
#else
 
345
    if (cAcl->BitsPerPixel != 24) {
 
346
        infoPtr->SetupForMono8x8PatternFill =
 
347
            CTNAME(SetupForMono8x8PatternFill);
 
348
        infoPtr->SubsequentMono8x8PatternFillRect =
 
349
            CTNAME(SubsequentMono8x8PatternFillRect);
 
350
    }
 
351
#endif
 
352
 
 
353
    /* Color 8x8 pattern fills, must have a displayWidth divisible by 64 */
 
354
    if (!(pScrn->displayWidth % 64)) {
 
355
#ifdef CHIPS_HIQV
 
356
        infoPtr->Color8x8PatternFillFlags = NO_PLANEMASK | 
 
357
            HARDWARE_PATTERN_SCREEN_ORIGIN;
 
358
        if (!(cPtr->Flags & ChipsColorTransparency))
 
359
            infoPtr->Color8x8PatternFillFlags |= NO_TRANSPARENCY;
 
360
#else
 
361
        infoPtr->Color8x8PatternFillFlags = NO_PLANEMASK | 
 
362
            HARDWARE_PATTERN_SCREEN_ORIGIN | NO_TRANSPARENCY;
 
363
#endif
 
364
 
 
365
        if (cAcl->BitsPerPixel != 24) {
 
366
            infoPtr->SetupForColor8x8PatternFill =
 
367
                CTNAME(SetupForColor8x8PatternFill);
 
368
            infoPtr->SubsequentColor8x8PatternFillRect =
 
369
                CTNAME(SubsequentColor8x8PatternFillRect);
 
370
        }
 
371
    }
 
372
 
 
373
#ifdef CHIPS_HIQV
 
374
chips_imagewrite:
 
375
#endif
 
376
 
 
377
    /* Setup for the Image Write functions */
 
378
#ifdef CHIPS_HIQV
 
379
    infoPtr->WritePixmapFlags = CPU_TRANSFER_PAD_QWORD | LEFT_EDGE_CLIPPING 
 
380
        | LEFT_EDGE_CLIPPING_NEGATIVE_X | ROP_NEEDS_SOURCE;
 
381
 
 
382
    if (!(cPtr->Flags & ChipsColorTransparency))
 
383
        infoPtr->WritePixmapFlags |= NO_TRANSPARENCY;
 
384
    if ((cAcl->BitsPerPixel == 24) || (cAcl->BitsPerPixel == 32))
 
385
        infoPtr->WritePixmapFlags |= NO_PLANEMASK;
 
386
 
 
387
    infoPtr->WritePixmap = CTNAME(WritePixmap);
 
388
#if 0 /* Not used by XAA as yet, but coming soon */
 
389
    if (cPtr->Flags & ChipsImageReadSupport) {
 
390
        infoPtr->ReadPixmapFlags = CPU_TRANSFER_PAD_QWORD | ROP_NEEDS_SOURCE;
 
391
        infoPtr->ReadPixmap = CTNAME(ReadPixmap);
 
392
    }
 
393
#endif
 
394
 
 
395
#else
 
396
    infoPtr->SetupForImageWrite = CTNAME(SetupForImageWrite);
 
397
    infoPtr->SubsequentImageWriteRect = CTNAME(SubsequentImageWriteRect);
 
398
    infoPtr->ImageWriteBase = (unsigned char *)cAcl->BltDataWindow;
 
399
    infoPtr->ImageWriteRange = 64 * 1024;
 
400
    infoPtr->ImageWriteFlags = NO_TRANSPARENCY | CPU_TRANSFER_PAD_DWORD
 
401
        | ROP_NEEDS_SOURCE;
 
402
    if ((cAcl->BitsPerPixel == 24) || (cAcl->BitsPerPixel == 32))
 
403
        infoPtr->ImageWriteFlags |= NO_PLANEMASK;
 
404
#endif
 
405
 
 
406
 
 
407
#ifdef CHIPS_HIQV
 
408
    if (XAAInit(pScreen, infoPtr)) {
 
409
        if (cPtr->Flags & ChipsOverlay8plus16)      
 
410
            return(XAAInitDualFramebufferOverlay(pScreen,
 
411
                                                 CTNAME(DepthChange)));
 
412
        else
 
413
            return TRUE;
 
414
    } else
 
415
        return FALSE;
 
416
#else
 
417
    return(XAAInit(pScreen, infoPtr));
 
418
#endif
 
419
}
 
420
 
 
421
#ifdef CHIPS_HIQV
 
422
void
 
423
CTNAME(DepthChange)(ScrnInfoPtr pScrn, int depth)
 
424
{
 
425
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
426
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
427
    unsigned char mode;
 
428
 
 
429
    DEBUG_P("DepthChange");
 
430
    switch (depth) {
 
431
    case 8 :
 
432
        cPtr->AccelInfoRec->SetupForSolidFill = CTNAME(8SetupForSolidFill);
 
433
        mode = 0x00;                            /* BitBLT engine to 8bpp  */
 
434
        cAcl->BytesPerPixel = 1;
 
435
        cAcl->FbOffset = 0;
 
436
        cAcl->BitsPerPixel = 8;
 
437
        break;
 
438
    default :
 
439
        cPtr->AccelInfoRec->SetupForSolidFill = CTNAME(16SetupForSolidFill);
 
440
        mode = 0x10;                            /* BitBLT engine to 16bpp */
 
441
        cAcl->BytesPerPixel = 2;
 
442
        cAcl->FbOffset = cPtr->FbOffset16;
 
443
        cAcl->BitsPerPixel = 16;
 
444
        break;
 
445
    }
 
446
    cAcl->PitchInBytes = pScrn->displayWidth * cAcl->BytesPerPixel;
 
447
    ctBLTWAIT;
 
448
    cPtr->writeXR(cPtr, 0x20, mode);            /* Change BitBLT engine mode */
 
449
}
 
450
#endif
 
451
 
 
452
void
 
453
CTNAME(Sync)(ScrnInfoPtr pScrn)
 
454
{
 
455
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
456
    DEBUG_P("sync");
 
457
    ctBLTWAIT;
 
458
}
 
459
 
 
460
static void
 
461
CTNAME(8SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
462
                                int rop, unsigned int planemask)
 
463
{
 
464
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
465
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
466
 
 
467
    DEBUG_P("8SetupForSolidFill");
 
468
    ctBLTWAIT;
 
469
    ctSETBGCOLOR8(color);
 
470
    ctSETFGCOLOR8(color);
 
471
    ctSETROP(ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
472
             ctPATSOLID | ctPATMONO);
 
473
    ctSETPITCH(0, cAcl->PitchInBytes);
 
474
}
 
475
 
 
476
static void
 
477
CTNAME(16SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
478
                                int rop, unsigned int planemask)
 
479
{
 
480
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
481
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
482
 
 
483
    DEBUG_P("16SetupForSolidFill");
 
484
    ctBLTWAIT;
 
485
    ctSETBGCOLOR16(color);
 
486
    ctSETFGCOLOR16(color);
 
487
    ctSETROP(ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
488
             ctPATSOLID | ctPATMONO);
 
489
    ctSETPITCH(0, cAcl->PitchInBytes);
 
490
}
 
491
 
 
492
#ifdef CHIPS_HIQV
 
493
static void
 
494
CTNAME(24SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
495
                                int rop, unsigned int planemask)
 
496
{
 
497
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
498
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
499
 
 
500
    DEBUG_P("24SetupForSolidFill");
 
501
    ctBLTWAIT;
 
502
    ctSETBGCOLOR24(color);
 
503
    ctSETFGCOLOR24(color);
 
504
    ctSETROP(ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
505
             ctPATSOLID | ctPATMONO);
 
506
    ctSETPITCH(0, cAcl->PitchInBytes);
 
507
}
 
508
 
 
509
static void
 
510
CTNAME(32SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
511
                                int rop, unsigned int planemask)
 
512
{
 
513
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
514
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
515
 
 
516
    DEBUG_P("32SetupForSolidFill");
 
517
    ctBLTWAIT;
 
518
    memset((unsigned char *)cPtr->FbBase + cAcl->ScratchAddress, 0xAA, 8);
 
519
    ctSETFGCOLOR16((color & 0xFFFF));
 
520
    ctSETBGCOLOR16(((color >> 16) & 0xFFFF));
 
521
    ctSETROP(ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
522
      ctPATMONO);
 
523
    ctSETPATSRCADDR(cAcl->ScratchAddress);
 
524
    ctSETPITCH(1, cAcl->PitchInBytes);
 
525
}
 
526
 
 
527
static void
 
528
CTNAME(32SubsequentSolidFillRect)(ScrnInfoPtr pScrn, int x, int y, int w,
 
529
                                  int h)
 
530
{
 
531
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
532
 
 
533
    unsigned int destaddr;
 
534
    destaddr = (y * pScrn->displayWidth + x) << 2;
 
535
    w <<= 2;
 
536
    DEBUG_P("32SubsequentSolidFillRect");
 
537
    ctBLTWAIT;
 
538
    ctSETDSTADDR(destaddr);
 
539
    ctSETHEIGHTWIDTHGO(h, w);
 
540
}
 
541
#else
 
542
 
 
543
static void
 
544
CTNAME(24SetupForSolidFill)(ScrnInfoPtr pScrn, int color,
 
545
                                int rop, unsigned int planemask)
 
546
{
 
547
    unsigned char pixel1, pixel2, pixel3;
 
548
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
549
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
550
 
 
551
    DEBUG_P("24SetupForSolidFill");
 
552
    cAcl->rgb24equal = (((((color & 0xFF) == ((color & 0xFF00) >> 8)) && 
 
553
                       ((color & 0xFF) == ((color & 0xFF0000) >> 16)))) ||
 
554
                       /* Check the rop for paranoid reasons */
 
555
                       (rop == GXclear) || (rop == GXnoop) ||
 
556
                       (rop == GXinvert) || (rop == GXset));
 
557
    if (cAcl->rgb24equal) {
 
558
        cAcl->CommandFlags = ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM |
 
559
                 ctLEFT2RIGHT | ctPATSOLID | ctPATMONO;
 
560
        ctBLTWAIT;
 
561
        ctSETFGCOLOR8(color&0xFF);
 
562
        ctSETBGCOLOR8(color&0xFF);
 
563
        ctSETPITCH(0, cAcl->PitchInBytes);
 
564
    } else {
 
565
        cAcl->rop24bpp = rop;
 
566
        if (rop == GXcopy) {
 
567
            pixel3 = color & 0xFF;
 
568
            pixel2 = (color >> 8) & 0xFF;
 
569
            pixel1 = (color >> 16) & 0xFF;
 
570
            cAcl->fgpixel = pixel1;
 
571
            cAcl->bgpixel = pixel2;
 
572
            cAcl->fillindex = 0;
 
573
            cAcl->fastfill = FALSE;
 
574
 
 
575
            /* Test for the special case where two of the byte of the 
 
576
             * 24bpp colour are the same. This can double the speed
 
577
             */
 
578
            if (pixel1 == pixel2) {
 
579
                cAcl->fgpixel = pixel3;
 
580
                cAcl->bgpixel = pixel1;
 
581
                cAcl->fastfill = TRUE;
 
582
                cAcl->fillindex = 1;
 
583
            } else if (pixel1 == pixel3) { 
 
584
                cAcl->fgpixel = pixel2;
 
585
                cAcl->bgpixel = pixel1;
 
586
                cAcl->fastfill = TRUE;
 
587
                cAcl->fillindex = 2;
 
588
            } else if (pixel2 == pixel3) { 
 
589
                cAcl->fastfill = TRUE;
 
590
            } else {
 
591
                cAcl->xorpixel = pixel2 ^ pixel3;
 
592
            }
 
593
 
 
594
            cAcl->CommandFlags = ctSRCMONO | ctSRCSYSTEM | ctTOP2BOTTOM | 
 
595
                     ctLEFT2RIGHT;
 
596
            ctBLTWAIT;
 
597
            if (cAcl->fastfill) { 
 
598
                ctSETFGCOLOR8(cAcl->fgpixel);
 
599
            }
 
600
            ctSETBGCOLOR8(cAcl->bgpixel);
 
601
            ctSETSRCADDR(0);
 
602
            ctSETPITCH(0, cAcl->PitchInBytes);
 
603
        } else {
 
604
            if (cAcl->color24bpp != color) {
 
605
                cAcl->color24bpp = color;
 
606
                cAcl->width24bpp = 0;
 
607
            }
 
608
            cAcl->rop24bpp = rop;
 
609
            ctBLTWAIT;
 
610
            ctSETROP(ctTOP2BOTTOM | ctLEFT2RIGHT | ChipsAluConv[rop & 0xF]);
 
611
            ctSETPITCH(cAcl->PitchInBytes, cAcl->PitchInBytes);
 
612
        }
 
613
    }
 
614
}
 
615
 
 
616
static void
 
617
CTNAME(24SubsequentSolidFillRect)(ScrnInfoPtr pScrn, int x, int y, int w,
 
618
                                  int h)
 
619
{
 
620
    static unsigned int dwords[3] = { 0x24499224, 0x92244992, 0x49922449};
 
621
    int srcaddr, destaddr, line, i;
 
622
    register int width;
 
623
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
624
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
625
 
 
626
    DEBUG_P("24SubsequentSolidFillRect");
 
627
    if (cAcl->rgb24equal) {
 
628
        destaddr = y * pScrn->displayWidth + x;
 
629
        destaddr += destaddr << 1;
 
630
        ctBLTWAIT;
 
631
        ctSETROP(cAcl->CommandFlags);
 
632
        ctSETDSTADDR(destaddr);
 
633
        ctSETHEIGHTWIDTHGO(h, (w + (w << 1)));
 
634
    } else {
 
635
        if (cAcl->rop24bpp == GXcopy ) {
 
636
            unsigned int *base = (unsigned int *)cAcl->BltDataWindow;
 
637
            destaddr = y * cAcl->PitchInBytes + x * 3;
 
638
            w *= 3;
 
639
            width = ((w  + 31) & ~31) >> 5;
 
640
            
 
641
            ctBLTWAIT;
 
642
            ctSETDSTADDR(destaddr);
 
643
 
 
644
            if (!cAcl->fastfill) ctSETFGCOLOR8(cAcl->fgpixel);
 
645
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[GXcopy & 0xF]);
 
646
            ctSETDSTADDR(destaddr);
 
647
            if (cAcl->fastfill) {
 
648
                ctSETHEIGHTWIDTHGO(h, w);
 
649
                line = 0;
 
650
                while (line < h) {
 
651
                    base = (unsigned int *)cAcl->BltDataWindow;
 
652
                    for (i = 0; i < width; i++) {
 
653
                        *base++ = dwords[((cAcl->fillindex + i) % 3)];
 
654
                    }
 
655
                    line++;
 
656
                }
 
657
            } else {
 
658
                ctSETHEIGHTWIDTHGO(1, w);
 
659
                i = 0;
 
660
                while(i < width){
 
661
                    *base++ = dwords[(i++ % 3)];
 
662
                }
 
663
                for(line = 0; (h >> line ) > 1; line++){;}
 
664
                i = 0;
 
665
                ctBLTWAIT;
 
666
                ctSETFGCOLOR8(cAcl->xorpixel);
 
667
                ctSETROP(cAcl->CommandFlags | ChipsAluConv[GXxor & 0xF] |
 
668
                         ctBGTRANSPARENT);
 
669
                ctSETDSTADDR(destaddr);
 
670
                ctSETHEIGHTWIDTHGO(1, w);
 
671
                base = (unsigned int *)cAcl->BltDataWindow;
 
672
                while(i < width) {
 
673
                    *base++ = dwords[((++i) % 3)];
 
674
                }
 
675
                srcaddr = destaddr;
 
676
                if(line){
 
677
                    i = 0;
 
678
                    ctBLTWAIT;
 
679
                    ctSETROP(ctTOP2BOTTOM | ctLEFT2RIGHT |
 
680
                             ChipsAluConv[GXcopy & 0xF]);
 
681
                    ctSETPITCH(cAcl->PitchInBytes, cAcl->PitchInBytes);
 
682
                    ctSETSRCADDR(srcaddr);
 
683
            
 
684
                    while(i < line){
 
685
                        destaddr = srcaddr + (cAcl->PitchInBytes << i);
 
686
                        ctBLTWAIT;
 
687
                        ctSETDSTADDR(destaddr);
 
688
                        ctSETHEIGHTWIDTHGO((1 << i), w);
 
689
                        i++;
 
690
                    }
 
691
 
 
692
                    if((1 <<  line)  < h){
 
693
                        destaddr = srcaddr + (cAcl->PitchInBytes << line);
 
694
                        ctBLTWAIT;
 
695
                        ctSETDSTADDR(destaddr);
 
696
                        ctSETHEIGHTWIDTHGO(h-(1 << line), w);
 
697
                    }
 
698
 
 
699
                    ctBLTWAIT;
 
700
                    ctSETROP(ctSRCMONO | ctSRCSYSTEM | ctTOP2BOTTOM |
 
701
                             ctLEFT2RIGHT | ChipsAluConv[GXcopy & 0xF]);
 
702
                    ctSETSRCADDR(0);
 
703
                    ctSETPITCH(0, cAcl->PitchInBytes);
 
704
                }
 
705
            }
 
706
        } else {
 
707
            register unsigned char *base;
 
708
            if (cAcl->width24bpp < w) {
 
709
                base = (unsigned char *)cPtr->FbBase + cAcl->ScratchAddress + 
 
710
                    ((3 * cAcl->width24bpp + 3) & ~0x3);
 
711
                width = w - cAcl->width24bpp;
 
712
                ctBLTWAIT;
 
713
                /* Load of a single scanline into framebuffer */
 
714
                while (width > 0) {
 
715
                    *(unsigned int *)base = cAcl->color24bpp |
 
716
                      (cAcl->color24bpp << 24);
 
717
                    *(unsigned int *)(base + 4) = (cAcl->color24bpp >> 8) |
 
718
                      (cAcl->color24bpp << 16);
 
719
                    *(unsigned int *)(base + 8) = (cAcl->color24bpp >> 16) |
 
720
                      (cAcl->color24bpp << 8);
 
721
                    base += 12;
 
722
                    width -= 4;
 
723
                }
 
724
                cAcl->width24bpp = w - width;
 
725
            }
 
726
            line = 0;
 
727
            destaddr = 3 * (y * pScrn->displayWidth + x);
 
728
            w *= cAcl->BytesPerPixel;
 
729
            while (line < h) {
 
730
                ctBLTWAIT;
 
731
                ctSETSRCADDR(cAcl->ScratchAddress);
 
732
                ctSETDSTADDR(destaddr);
 
733
                ctSETHEIGHTWIDTHGO(1, w);
 
734
                destaddr += (3 * pScrn->displayWidth);
 
735
                line++;
 
736
            }
 
737
        }
 
738
    }
 
739
}
 
740
#endif
 
741
 
 
742
static void
 
743
CTNAME(SubsequentSolidFillRect)(ScrnInfoPtr pScrn, int x, int y, int w,
 
744
                                  int h)
 
745
{
 
746
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
747
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
748
    int destaddr;
 
749
 
 
750
    DEBUG_P("SubsequentSolidFillRect");
 
751
    destaddr = (y * pScrn->displayWidth + x) * cAcl->BytesPerPixel;
 
752
#ifdef CHIPS_HIQV
 
753
    destaddr += cAcl->FbOffset;
 
754
#endif
 
755
    w *= cAcl->BytesPerPixel;
 
756
    ctBLTWAIT;
 
757
    ctSETDSTADDR(destaddr);
 
758
    ctSETHEIGHTWIDTHGO(h, w);
 
759
}
 
760
 
 
761
/*
 
762
 * Screen-to-screen BitBLT.
 
763
 *
 
764
 */
 
765
 
 
766
static void
 
767
CTNAME(SetupForScreenToScreenCopy)(ScrnInfoPtr pScrn, int xdir, int ydir,
 
768
                                int rop, unsigned int planemask, int trans)
 
769
{
 
770
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
771
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
772
 
 
773
    DEBUG_P("SetupForScreenToScreenCopy");
 
774
    cAcl->CommandFlags = 0;
 
775
    
 
776
    /* Set up the blit direction. */
 
777
    if (ydir < 0)
 
778
        cAcl->CommandFlags |= ctBOTTOM2TOP;
 
779
    else
 
780
        cAcl->CommandFlags |= ctTOP2BOTTOM;
 
781
    if (xdir < 0)
 
782
        cAcl->CommandFlags |= ctRIGHT2LEFT;
 
783
    else
 
784
        cAcl->CommandFlags |= ctLEFT2RIGHT;
 
785
#ifdef CHIPS_HIQV
 
786
    if (trans != -1) {
 
787
        cAcl->CommandFlags |= ctCOLORTRANSENABLE | ctCOLORTRANSROP |
 
788
            ctCOLORTRANSNEQUAL;
 
789
        ctBLTWAIT;
 
790
        /* BR03[0x27] sometimes set after reset, so must ensure it is zero */
 
791
        ctSETMONOCTL(ctDWORDALIGN);
 
792
        switch (cAcl->BitsPerPixel) {
 
793
        case 8:
 
794
            ctSETBGCOLOR8(trans);
 
795
            break;
 
796
        case 16:
 
797
            ctSETBGCOLOR16(trans);
 
798
            break;
 
799
        case 24:
 
800
            ctSETBGCOLOR24(trans);
 
801
            break;
 
802
        }
 
803
    } else
 
804
#endif
 
805
    ctBLTWAIT;
 
806
    switch (cAcl->BitsPerPixel) {
 
807
#if 0
 
808
    case 8:
 
809
        if ((planemask & 0xFF) == 0xFF) {
 
810
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
811
        } else {
 
812
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
813
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
814
            ctWRITEPLANEMASK8(planemask, cAcl->ScratchAddress);
 
815
        }
 
816
        break;
 
817
    case 16:
 
818
        if ((planemask & 0xFFFF) == 0xFFFF) {
 
819
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
820
        } else {
 
821
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
822
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
823
            ctWRITEPLANEMASK16(planemask, cAcl->ScratchAddress);
 
824
        }
 
825
        break;
 
826
#endif
 
827
    default:
 
828
        ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
829
        break;
 
830
    }
 
831
    ctSETPITCH(cAcl->PitchInBytes, cAcl->PitchInBytes);
 
832
}
 
833
 
 
834
static void
 
835
CTNAME(SubsequentScreenToScreenCopy)(ScrnInfoPtr pScrn, int srcX, int srcY,
 
836
                                int dstX, int dstY, int w, int h)
 
837
 
838
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
839
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
840
    unsigned int srcaddr, destaddr;
 
841
 
 
842
    DEBUG_P("SubsequentScreenToScreenCopy");
 
843
#ifdef CHIPS_HIQV
 
844
    if (cAcl->CommandFlags & ctBOTTOM2TOP) {
 
845
        srcaddr = (srcY + h - 1) * pScrn->displayWidth;
 
846
        destaddr = (dstY + h - 1) * pScrn->displayWidth;
 
847
    } else {
 
848
        srcaddr = srcY * pScrn->displayWidth;
 
849
        destaddr = dstY * pScrn->displayWidth;
 
850
    }
 
851
    if (cAcl->CommandFlags & ctRIGHT2LEFT) {
 
852
        srcaddr = ( srcaddr + srcX + w ) * cAcl->BytesPerPixel - 1 ;
 
853
        destaddr = ( destaddr + dstX + w ) * cAcl->BytesPerPixel - 1;
 
854
    } else {
 
855
        srcaddr = (srcaddr + srcX) * cAcl->BytesPerPixel;
 
856
        destaddr = (destaddr + dstX) * cAcl->BytesPerPixel;
 
857
    }
 
858
    srcaddr += cAcl->FbOffset;
 
859
    destaddr += cAcl->FbOffset;
 
860
#else
 
861
    if (cAcl->CommandFlags & ctTOP2BOTTOM) {
 
862
        srcaddr = srcY * pScrn->displayWidth;
 
863
        destaddr = dstY * pScrn->displayWidth;
 
864
    } else {
 
865
        srcaddr = (srcY + h - 1) * pScrn->displayWidth;
 
866
        destaddr = (dstY + h - 1) * pScrn->displayWidth;
 
867
    }
 
868
    if (cAcl->CommandFlags & ctLEFT2RIGHT) {
 
869
        srcaddr = (srcaddr + srcX) * cAcl->BytesPerPixel;
 
870
        destaddr = (destaddr + dstX) * cAcl->BytesPerPixel;
 
871
    } else {
 
872
        srcaddr = ( srcaddr + srcX + w ) * cAcl->BytesPerPixel - 1 ;
 
873
        destaddr = ( destaddr + dstX + w ) * cAcl->BytesPerPixel - 1;
 
874
    }
 
875
#endif
 
876
    w *= cAcl->BytesPerPixel;
 
877
    ctBLTWAIT;
 
878
    ctSETSRCADDR(srcaddr);
 
879
    ctSETDSTADDR(destaddr);
 
880
    ctSETHEIGHTWIDTHGO(h, w);
 
881
}
 
882
 
 
883
 
 
884
static void 
 
885
CTNAME(SetupForCPUToScreenColorExpandFill)(ScrnInfoPtr pScrn, int fg,
 
886
                                int bg, int rop, unsigned int planemask)
 
887
{
 
888
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
889
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
890
 
 
891
    DEBUG_P("SetupForCPUToScreenColorExpandFill");
 
892
    ctBLTWAIT;
 
893
    cAcl->CommandFlags = 0;
 
894
    if (bg == -1) {
 
895
        cAcl->CommandFlags |= ctBGTRANSPARENT;  /* Background = Destination */
 
896
        switch (cAcl->BitsPerPixel) {
 
897
        case 8:
 
898
            ctSETFGCOLOR8(fg);
 
899
            break;
 
900
        case 16:
 
901
            ctSETFGCOLOR16(fg);
 
902
            break;
 
903
        case 24:
 
904
#ifdef CHIPS_HIQV
 
905
            ctSETFGCOLOR24(fg);
 
906
#else
 
907
            ctSETFGCOLOR8(fg);
 
908
#endif
 
909
            break;
 
910
        }
 
911
    }
 
912
    else {
 
913
        switch (cAcl->BitsPerPixel) {
 
914
        case 8:
 
915
            ctSETBGCOLOR8(bg);
 
916
            ctSETFGCOLOR8(fg);
 
917
            break;
 
918
        case 16:
 
919
            ctSETBGCOLOR16(bg);
 
920
            ctSETFGCOLOR16(fg);
 
921
            break;
 
922
        case 24:
 
923
#ifdef CHIPS_HIQV
 
924
            ctSETBGCOLOR24(bg);
 
925
            ctSETFGCOLOR24(fg);
 
926
#else
 
927
            ctSETBGCOLOR8(bg);
 
928
            ctSETFGCOLOR8(fg);
 
929
#endif
 
930
            break;
 
931
        }
 
932
    }
 
933
   
 
934
#ifdef CHIPS_HIQV
 
935
    ctSETMONOCTL(ctDWORDALIGN);
 
936
#endif
 
937
 
 
938
    ctSETSRCADDR(0);
 
939
 
 
940
    switch (cAcl->BitsPerPixel) {
 
941
    case 8:
 
942
        if ((planemask & 0xFF) == 0xFF) {
 
943
            ctSETROP(ctSRCSYSTEM | ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
944
                    ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
945
        } else {
 
946
            ctSETROP(ctSRCSYSTEM | ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
947
                    ChipsAluConv3[rop & 0xF] | cAcl->CommandFlags);
 
948
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
949
            ctWRITEPLANEMASK8(planemask, cAcl->ScratchAddress);
 
950
        }
 
951
        break;
 
952
    case 16:
 
953
        if ((planemask & 0xFFFF) == 0xFFFF) {
 
954
            ctSETROP(ctSRCSYSTEM | ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
955
                    ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
956
        } else {
 
957
            ctSETROP(ctSRCSYSTEM | ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
958
                    ChipsAluConv3[rop & 0xF] | cAcl->CommandFlags);
 
959
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
960
            ctWRITEPLANEMASK16(planemask, cAcl->ScratchAddress);
 
961
        }
 
962
        break;
 
963
    default:
 
964
        ctSETROP(ctSRCSYSTEM | ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT |
 
965
                 ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
966
        break;
 
967
    }
 
968
    ctSETPITCH(0, cAcl->PitchInBytes);
 
969
}
 
970
 
 
971
static void
 
972
CTNAME(SubsequentCPUToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
973
                                int x, int y, int w, int h, int skipleft)
 
974
{
 
975
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
976
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
977
    int destaddr;
 
978
 
 
979
    DEBUG_P("SubsequentCPUToScreenColorExpandFill");
 
980
    destaddr = (y * pScrn->displayWidth + x + skipleft) * 
 
981
               cAcl->BytesPerPixel;
 
982
#ifdef CHIPS_HIQV
 
983
    destaddr += cAcl->FbOffset;
 
984
#endif
 
985
    w = (w - skipleft) * cAcl->BytesPerPixel;
 
986
    ctBLTWAIT;
 
987
    ctSETDSTADDR(destaddr);
 
988
#ifdef CHIPS_HIQV
 
989
    ctSETMONOCTL(ctDWORDALIGN | ctCLIPLEFT(skipleft));
 
990
#endif
 
991
    ctSETHEIGHTWIDTHGO(h, w);
 
992
}
 
993
 
 
994
#if !defined(CHIPS_HIQV) || defined(UNDOCUMENTED_FEATURE)
 
995
static void
 
996
CTNAME(SetupForScreenToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
997
                                int fg, int bg, int rop, 
 
998
                                unsigned int planemask)
 
999
{
 
1000
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1001
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1002
 
 
1003
    DEBUG_P("SetupForScreenToScreenColorExpandFill");
 
1004
    cAcl->CommandFlags = 0;
 
1005
    ctBLTWAIT;
 
1006
    if (bg == -1) {
 
1007
        cAcl->CommandFlags |= ctBGTRANSPARENT;  /* Background = Destination */
 
1008
        switch (cAcl->BitsPerPixel) {
 
1009
        case 8:
 
1010
            ctSETFGCOLOR8(fg);
 
1011
            break;
 
1012
        case 16:
 
1013
            ctSETFGCOLOR16(fg);
 
1014
            break;
 
1015
        case 24:
 
1016
#ifdef CHIPS_HIQV
 
1017
            ctSETFGCOLOR24(fg);
 
1018
#else
 
1019
            ctSETFGCOLOR8(fg);
 
1020
#endif
 
1021
            break;
 
1022
        }
 
1023
    }
 
1024
    else {
 
1025
        switch (cAcl->BitsPerPixel) {
 
1026
        case 8:
 
1027
            ctSETBGCOLOR8(bg);
 
1028
            ctSETFGCOLOR8(fg);
 
1029
            break;
 
1030
        case 16:
 
1031
            ctSETBGCOLOR16(bg);
 
1032
            ctSETFGCOLOR16(fg);
 
1033
            break;
 
1034
        case 24:
 
1035
#ifdef CHIPS_HIQV
 
1036
            ctSETBGCOLOR24(bg);
 
1037
            ctSETFGCOLOR24(fg);
 
1038
#else
 
1039
            ctSETBGCOLOR8(bg);
 
1040
            ctSETFGCOLOR8(fg);
 
1041
#endif
 
1042
            break;
 
1043
        }
 
1044
    }
 
1045
 
 
1046
    switch (cAcl->BitsPerPixel) {
 
1047
    case 8:
 
1048
        if ((planemask & 0xFF) == 0xFF) {
 
1049
            ctSETROP(ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1050
                 ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
1051
        } else {
 
1052
            ctSETROP(ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1053
                    ChipsAluConv3[rop & 0xF] | cAcl->CommandFlags);
 
1054
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1055
            ctWRITEPLANEMASK8(planemask, cAcl->ScratchAddress);
 
1056
        }
 
1057
        break;
 
1058
    case 16:
 
1059
        if ((planemask & 0xFFFF) == 0xFFFF) {
 
1060
            ctSETROP(ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1061
                 ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
1062
        } else {
 
1063
            ctSETROP(ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1064
                    ChipsAluConv3[rop & 0xF] | cAcl->CommandFlags);
 
1065
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1066
            ctWRITEPLANEMASK16(planemask, cAcl->ScratchAddress);
 
1067
        }
 
1068
        break;
 
1069
    default:
 
1070
        ctSETROP(ctSRCMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1071
                 ChipsAluConv[rop & 0xF] | cAcl->CommandFlags);
 
1072
        break;
 
1073
    }
 
1074
    ctSETPITCH(cAcl->PitchInBytes, cAcl->PitchInBytes);
 
1075
}
 
1076
#endif
 
1077
#ifndef CHIPS_HIQV
 
1078
/*
 
1079
 * The non-HiQV chips don't have left-edge clippling of monochrome sources.
 
1080
 * However you can have the monochrome source starting on a byte boundary.
 
1081
 * Hence have 8 rotated copies of the monochrome source to simulate left
 
1082
 * edge clipping with these chips. This requires the XAACacheMonoStipple
 
1083
 * function to be replaced, if we are to use ScreenToScreenColorExpand.
 
1084
 */
 
1085
 
 
1086
static XAACacheInfoPtr
 
1087
CTNAME(CacheMonoStipple)(ScrnInfoPtr pScrn, PixmapPtr pPix)
 
1088
{
 
1089
    int w = pPix->drawable.width;
 
1090
    int h = pPix->drawable.height;
 
1091
    XAAInfoRecPtr infoRec = (CHIPSPTR(pScrn))->AccelInfoRec;
 
1092
    XAAPixmapCachePrivatePtr pCachePriv = 
 
1093
        (XAAPixmapCachePrivatePtr)infoRec->PixmapCachePrivate;
 
1094
    XAACacheInfoPtr pCache, cacheRoot = NULL;
 
1095
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1096
    int i, j, max = 0, funcNo, pad, dwords, bpp = cAcl->BitsPerPixel;
 
1097
    int *current;
 
1098
    StippleScanlineProcPtr StippleFunc;
 
1099
    unsigned char *data, *srcPtr, *dstPtr;
 
1100
 
 
1101
    DEBUG_P("CacheMonoStipple");
 
1102
    if((h <= 128) && (w <= 128 * bpp / 8)) {
 
1103
        if(pCachePriv->Info128) {
 
1104
            cacheRoot = pCachePriv->Info128; 
 
1105
            max = pCachePriv->Num128x128;
 
1106
            current = &pCachePriv->Current128;
 
1107
        } else {     
 
1108
            cacheRoot = pCachePriv->InfoPartial;
 
1109
            max = pCachePriv->NumPartial;
 
1110
            current = &pCachePriv->CurrentPartial;
 
1111
        }
 
1112
    } else if((h <= 256) && (w <= 256 * bpp / 8)){
 
1113
        cacheRoot = pCachePriv->Info256;      
 
1114
        max = pCachePriv->Num256x256;
 
1115
        current = &pCachePriv->Current256;
 
1116
    } else if((h <= 512) && (w <= 512 * bpp / 8)){
 
1117
        cacheRoot = pCachePriv->Info512;      
 
1118
        max = pCachePriv->Num512x512;
 
1119
        current = &pCachePriv->Current512;
 
1120
    } else { /* something's wrong */ 
 
1121
        ErrorF("Something's wrong in XAACacheMonoStipple()\n");
 
1122
        return pCachePriv->Info128; 
 
1123
    }
 
1124
 
 
1125
    pCache = cacheRoot;
 
1126
 
 
1127
    /* lets look for it */
 
1128
    for(i = 0; i < max; i++, pCache++) {
 
1129
        if((pCache->serialNumber == pPix->drawable.serialNumber) &&
 
1130
            (pCache->fg == -1) && (pCache->bg == -1)) {
 
1131
            pCache->trans_color = -1;
 
1132
            dwords = 
 
1133
            cAcl->SlotWidth = ((pCache->w * bpp) >> 5) >> 1;
 
1134
            return pCache;
 
1135
        }
 
1136
    }
 
1137
 
 
1138
    pCache = &cacheRoot[(*current)++];
 
1139
    if(*current >= max) *current = 0;
 
1140
 
 
1141
    pCache->serialNumber = pPix->drawable.serialNumber;
 
1142
    pCache->trans_color = pCache->bg = pCache->fg = -1;
 
1143
    pCache->orig_w = w;  pCache->orig_h = h;
 
1144
 
 
1145
    if(w <= 32) {
 
1146
        if(w & (w - 1)) funcNo = 1;
 
1147
        else            funcNo = 0;
 
1148
    } else              funcNo = 2;
 
1149
 
 
1150
    pad = (((pCache->w * bpp) + 31) >> 5) << 2;
 
1151
    dstPtr = data = (unsigned char*)ALLOCATE_LOCAL(pad * pCache->h);
 
1152
    srcPtr = (unsigned char*)pPix->devPrivate.ptr;
 
1153
    StippleFunc = XAAStippleScanlineFuncMSBFirst[funcNo];
 
1154
    
 
1155
    dwords = ((pCache->w * bpp) >> 5) >> 3;
 
1156
    cAcl->SlotWidth = dwords << 2;
 
1157
    
 
1158
    for(i = 0; i < h; i++) {
 
1159
        for(j = 0; j < 8; j++) {
 
1160
            (*StippleFunc)((CARD32*)dstPtr + j * dwords,
 
1161
                           (CARD32*)srcPtr, j, w, dwords);
 
1162
        }
 
1163
        srcPtr += pPix->devKind;
 
1164
        dstPtr += pad;
 
1165
    }
 
1166
 
 
1167
    while((h<<1) <= pCache->h) {
 
1168
        memcpy(data + (pad * h), data, pad * h);
 
1169
        h <<= 1;
 
1170
    }
 
1171
 
 
1172
    if(h < pCache->h)   
 
1173
        memcpy(data + (pad * h), data, pad * (pCache->h - h));
 
1174
 
 
1175
    (*infoRec->WritePixmapToCache)(
 
1176
        pScrn, pCache->x, pCache->y, pCache->w, pCache->h, data,
 
1177
        pad, bpp, pScrn->depth);
 
1178
 
 
1179
    DEALLOCATE_LOCAL(data);
 
1180
 
 
1181
    return pCache;
 
1182
}
 
1183
#endif
 
1184
#if !defined(CHIPS_HIQV) || defined(UNDOCUMENTED_FEATURE)
 
1185
static void
 
1186
CTNAME(SubsequentScreenToScreenColorExpandFill)(ScrnInfoPtr pScrn,
 
1187
                                int x, int y, int w, int h,
 
1188
                                int srcx, int srcy, int skipleft)
 
1189
{
 
1190
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1191
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1192
    int srcaddr, destaddr;
 
1193
 
 
1194
    DEBUG_P("SubsequentScreenToScreenColorExpandFill");
 
1195
#ifdef CHIPS_HIQV
 
1196
    srcaddr = (srcy * pScrn->displayWidth + srcx) * cAcl->BytesPerPixel
 
1197
                + ((skipleft & ~0x3F) >> 3);
 
1198
    if ( y < pScrn->virtualY)
 
1199
        srcaddr += cAcl->FbOffset;
 
1200
    else
 
1201
        srcaddr += cPtr->FbOffset16;
 
1202
#else
 
1203
    srcaddr = (srcy * pScrn->displayWidth + srcx) * cAcl->BytesPerPixel
 
1204
                + ((skipleft &  0x07) * cAcl->SlotWidth) 
 
1205
                + ((skipleft & ~0x07) >> 3);
 
1206
#endif
 
1207
    destaddr = (y * pScrn->displayWidth + x) * cAcl->BytesPerPixel;
 
1208
#ifdef CHIPS_HIQV
 
1209
    destaddr += cAcl->FbOffset;
 
1210
#endif
 
1211
    w *= cAcl->BytesPerPixel;
 
1212
    ctBLTWAIT;
 
1213
#ifdef CHIPS_HIQV
 
1214
    if ((y >= pScrn->virtualY) && (cPtr->Flags & ChipsOverlay8plus16) &&
 
1215
            (pScrn->depth == 8))
 
1216
        ctSETPITCH(cAcl->PitchInBytes << 1, cAcl->PitchInBytes);
 
1217
#endif
 
1218
    ctSETSRCADDR(srcaddr);
 
1219
    ctSETDSTADDR(destaddr);
 
1220
#ifdef CHIPS_HIQV
 
1221
    ctSETMONOCTL(ctCLIPLEFT(skipleft & 0x3F));
 
1222
#endif
 
1223
    ctSETHEIGHTWIDTHGO(h, w);
 
1224
}
 
1225
#endif
 
1226
static void
 
1227
CTNAME(SetupForColor8x8PatternFill)(ScrnInfoPtr pScrn, int patx, int paty, 
 
1228
                                    int rop, unsigned int planemask,
 
1229
                                    int trans)
 
1230
{
 
1231
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1232
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1233
    unsigned int patternaddr;
 
1234
 
 
1235
    DEBUG_P("SetupForColor8x8PatternFill");
 
1236
    cAcl->CommandFlags = ChipsAluConv2[rop & 0xF] | ctTOP2BOTTOM |
 
1237
                ctLEFT2RIGHT;
 
1238
    patternaddr = (paty * pScrn->displayWidth + 
 
1239
                   (patx & ~0x3F)) * cAcl->BytesPerPixel;
 
1240
    cAcl->patternyrot = (patx & 0x3F) >> 3;
 
1241
#ifdef CHIPS_HIQV
 
1242
    if (cPtr->Flags & ChipsOverlay8plus16)
 
1243
        patternaddr += cPtr->FbOffset16;
 
1244
#endif
 
1245
 
 
1246
    ctBLTWAIT;
 
1247
    ctSETPATSRCADDR(patternaddr);
 
1248
#ifdef CHIPS_HIQV
 
1249
    if (trans != -1) {
 
1250
        cAcl->CommandFlags |= ctCOLORTRANSENABLE | ctCOLORTRANSROP |
 
1251
            ctCOLORTRANSNEQUAL;
 
1252
        ctSETMONOCTL(ctDWORDALIGN);
 
1253
        switch (cAcl->BitsPerPixel) {
 
1254
        case 8:
 
1255
            ctSETBGCOLOR8(trans);
 
1256
            break;
 
1257
        case 16:
 
1258
            ctSETBGCOLOR16(trans);
 
1259
            break;
 
1260
        case 24:
 
1261
            ctSETBGCOLOR24(trans);
 
1262
            break;
 
1263
        }
 
1264
    } else
 
1265
#endif
 
1266
    ctSETPITCH(8 * cAcl->BytesPerPixel, cAcl->PitchInBytes);
 
1267
}
 
1268
 
 
1269
static void 
 
1270
CTNAME(SubsequentColor8x8PatternFillRect)(ScrnInfoPtr pScrn, int patx, int paty,
 
1271
                                 int x, int y, int w, int h)
 
1272
{
 
1273
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1274
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1275
    unsigned int destaddr;
 
1276
 
 
1277
    DEBUG_P("SubsequentColor8x8PatternFillRect");
 
1278
    destaddr = (y * pScrn->displayWidth + x) * cAcl->BytesPerPixel;
 
1279
#ifdef CHIPS_HIQV
 
1280
    destaddr += cAcl->FbOffset;
 
1281
#endif
 
1282
    w *= cAcl->BytesPerPixel;
 
1283
    ctBLTWAIT;
 
1284
    ctSETDSTADDR(destaddr);
 
1285
#ifdef CHIPS_HIQV
 
1286
    ctSETROP(cAcl->CommandFlags | (((y + cAcl->patternyrot) & 0x7) << 20));
 
1287
#else
 
1288
    ctSETROP(cAcl->CommandFlags | (((y + cAcl->patternyrot) & 0x7) << 16));
 
1289
#endif
 
1290
    ctSETHEIGHTWIDTHGO(h, w);
 
1291
}
 
1292
 
 
1293
static void
 
1294
CTNAME(SetupForMono8x8PatternFill)(ScrnInfoPtr pScrn, int patx, int paty, 
 
1295
                                int fg, int bg, int rop,
 
1296
                                unsigned int planemask)
 
1297
{
 
1298
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1299
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1300
    unsigned int patternaddr;
 
1301
 
 
1302
    DEBUG_P("SetupForMono8x8PatternFill");
 
1303
    cAcl->CommandFlags = ctPATMONO | ctTOP2BOTTOM | ctLEFT2RIGHT | 
 
1304
        ChipsAluConv2[rop & 0xF];
 
1305
 
 
1306
#ifdef CHIPS_HIQV
 
1307
    patternaddr = paty * pScrn->displayWidth + patx;
 
1308
    if (cPtr->Flags & ChipsOverlay8plus16)
 
1309
        patternaddr = patternaddr * 2 + cPtr->FbOffset16;
 
1310
    else
 
1311
        patternaddr *= cAcl->BytesPerPixel;
 
1312
#else
 
1313
    patternaddr = (paty * pScrn->displayWidth + patx) * cAcl->BytesPerPixel;
 
1314
#endif
 
1315
    ctBLTWAIT;
 
1316
    ctSETPATSRCADDR(patternaddr);
 
1317
    if (bg == -1) {
 
1318
        cAcl->CommandFlags |= ctBGTRANSPARENT;  /* Background = Destination */
 
1319
        switch (cAcl->BitsPerPixel) {
 
1320
        case 8:
 
1321
            ctSETFGCOLOR8(fg);
 
1322
            break;
 
1323
        case 16:
 
1324
            ctSETFGCOLOR16(fg);
 
1325
            break;
 
1326
        case 24:
 
1327
            ctSETFGCOLOR24(fg);
 
1328
            break;
 
1329
        }
 
1330
    }
 
1331
    else {
 
1332
        switch (cAcl->BitsPerPixel) {
 
1333
        case 8:
 
1334
            ctSETBGCOLOR8(bg);
 
1335
            ctSETFGCOLOR8(fg);
 
1336
            break;
 
1337
        case 16:
 
1338
            ctSETBGCOLOR16(bg);
 
1339
            ctSETFGCOLOR16(fg);
 
1340
            break;
 
1341
        case 24:
 
1342
            ctSETBGCOLOR24(bg);
 
1343
            ctSETFGCOLOR24(fg);
 
1344
            break;
 
1345
        }
 
1346
    }
 
1347
#ifdef CHIPS_HIQV
 
1348
    ctSETMONOCTL(ctDWORDALIGN);
 
1349
#endif
 
1350
    ctSETPITCH(1,cAcl->PitchInBytes);
 
1351
}
 
1352
 
 
1353
static void
 
1354
CTNAME(SubsequentMono8x8PatternFillRect)(ScrnInfoPtr pScrn, int patx, 
 
1355
                                int paty, int x, int y, int w, int h )
 
1356
{
 
1357
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1358
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1359
    int destaddr;
 
1360
    DEBUG_P("SubsequentMono8x8PatternFillRect");
 
1361
    destaddr = (y * pScrn->displayWidth + x) * cAcl->BytesPerPixel;
 
1362
#ifdef CHIPS_HIQV
 
1363
    destaddr += cAcl->FbOffset;
 
1364
#endif
 
1365
    w *= cAcl->BytesPerPixel;
 
1366
 
 
1367
    ctBLTWAIT;
 
1368
    ctSETDSTADDR(destaddr);
 
1369
#ifdef CHIPS_HIQV
 
1370
    ctSETROP(cAcl->CommandFlags | ((y & 0x7) << 20));
 
1371
#else
 
1372
    ctSETROP(cAcl->CommandFlags | ((y & 0x7) << 16));
 
1373
#endif
 
1374
    ctSETHEIGHTWIDTHGO(h, w);
 
1375
}
 
1376
 
 
1377
#ifndef CHIPS_HIQV
 
1378
static void
 
1379
CTNAME(SetupForImageWrite)(ScrnInfoPtr pScrn, int rop, unsigned int planemask,
 
1380
                                int transparency_color, int bpp, int depth)
 
1381
{
 
1382
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1383
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1384
 
 
1385
    DEBUG_P("SetupForImageWrite");
 
1386
    cAcl->CommandFlags = ctSRCSYSTEM | ctTOP2BOTTOM | ctLEFT2RIGHT;
 
1387
    ctBLTWAIT;
 
1388
 
 
1389
    switch (cAcl->BitsPerPixel) {
 
1390
    case 8:
 
1391
        if ((planemask & 0xFF) == 0xFF) {
 
1392
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1393
        } else {
 
1394
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
1395
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1396
            ctWRITEPLANEMASK8(planemask, cAcl->ScratchAddress);
 
1397
        }
 
1398
        break;
 
1399
    case 16:
 
1400
        if ((planemask & 0xFFFF) == 0xFFFF) {
 
1401
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1402
        } else {
 
1403
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
1404
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1405
            ctWRITEPLANEMASK16(planemask, cAcl->ScratchAddress);
 
1406
        }
 
1407
        break;
 
1408
    default:
 
1409
        ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1410
        break;
 
1411
    }
 
1412
    ctSETSRCADDR(0);
 
1413
}
 
1414
 
 
1415
static void
 
1416
CTNAME(SubsequentImageWriteRect)(ScrnInfoPtr pScrn, int x, int y, int w, int h,
 
1417
                                int skipleft)
 
1418
{
 
1419
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1420
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1421
    int destaddr = (y * pScrn->displayWidth + x) * cAcl->BytesPerPixel;
 
1422
    DEBUG_P("SubsequentImageWriteRect");
 
1423
    w *= cAcl->BytesPerPixel;
 
1424
    ctBLTWAIT;
 
1425
    ctSETPITCH(((w + 3) & ~0x3), cAcl->PitchInBytes);
 
1426
    ctSETDSTADDR(destaddr);
 
1427
    ctSETHEIGHTWIDTHGO(h, w);
 
1428
}
 
1429
 
 
1430
#else 
 
1431
/*
 
1432
 * Copyright 1997
 
1433
 * Digital Equipment Corporation. All rights reserved.
 
1434
 * This software is furnished under license and may be used and copied only in 
 
1435
 * accordance with the following terms and conditions.  Subject to these 
 
1436
 * conditions, you may download, copy, install, use, modify and distribute 
 
1437
 * this software in source and/or binary form. No title or ownership is 
 
1438
 * transferred hereby.
 
1439
 * 1) Any source code used, modified or distributed must reproduce and retain 
 
1440
 *    this copyright notice and list of conditions as they appear in the 
 
1441
 *    source file.
 
1442
 *
 
1443
 * 2) No right is granted to use any trade name, trademark, or logo of Digital 
 
1444
 *    Equipment Corporation. Neither the "Digital Equipment Corporation" name 
 
1445
 *    nor any trademark or logo of Digital Equipment Corporation may be used 
 
1446
 *    to endorse or promote products derived from this software without the 
 
1447
 *    prior written permission of Digital Equipment Corporation.
 
1448
 *
 
1449
 * 3) This software is provided "AS-IS" and any express or implied warranties,
 
1450
 *    including but not limited to, any implied warranties of merchantability,
 
1451
 *    fitness for a particular purpose, or non-infringement are disclaimed. In
 
1452
 *    no event shall DIGITAL be liable for any damages whatsoever, and in 
 
1453
 *    particular, DIGITAL shall not be liable for special, indirect, 
 
1454
 *    consequential, or incidental damages or damages for lost profits, loss 
 
1455
 *    of revenue or loss of use, whether such damages arise in contract, 
 
1456
 *    negligence, tort, under statute, in equity, at law or otherwise, even if
 
1457
 *    advised of the possibility of such damage. 
 
1458
 */
 
1459
 
 
1460
/* The code below comes from the idea supplied by the people at DEC, like
 
1461
 * the copyright above says. But its had to go through a large evolution
 
1462
 * to fit it into the new design for XFree86 4.0
 
1463
 */
 
1464
 
 
1465
static void
 
1466
MoveDWORDS(register CARD32* dest, register CARD32* src, register int dwords )
 
1467
{
 
1468
     while(dwords & ~0x03) {
 
1469
        *dest = *src;
 
1470
        *(dest + 1) = *(src + 1);
 
1471
        *(dest + 2) = *(src + 2);
 
1472
        *(dest + 3) = *(src + 3);
 
1473
        src += 4;
 
1474
        dest += 4;
 
1475
        dwords -= 4;
 
1476
     }  
 
1477
     switch(dwords){
 
1478
     case 1:
 
1479
       *dest = *src;
 
1480
       break;
 
1481
     case 2:
 
1482
       *dest = *src;
 
1483
       *(dest + 1) = *(src + 1);
 
1484
       break;
 
1485
     case 3:
 
1486
       *dest = *src;
 
1487
       *(dest + 1) = *(src + 1);
 
1488
       *(dest + 2) = *(src + 2);
 
1489
       break;
 
1490
     }
 
1491
}
 
1492
 
 
1493
static __inline__ void 
 
1494
MoveDataFromCPU(unsigned char *src, unsigned char *dest, int srcwidth,
 
1495
         int window, int h, int dwords)
 
1496
{
 
1497
    if(srcwidth == (dwords << 2)) {
 
1498
        int decrement = window / dwords;
 
1499
        while(h > decrement) {
 
1500
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords * decrement);
 
1501
            src += (srcwidth * decrement);
 
1502
            h -= decrement;
 
1503
        }
 
1504
        if(h) {
 
1505
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords * h);
 
1506
        }
 
1507
    } else {
 
1508
        while(h--) {
 
1509
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords);
 
1510
            src += srcwidth;
 
1511
        }
 
1512
    }
 
1513
}
 
1514
 
 
1515
static __inline__ void 
 
1516
MoveDataToCPU(unsigned char *src, unsigned char *dest, int dstwidth,
 
1517
         int window, int h, int dwords)
 
1518
{
 
1519
    if(dstwidth == (dwords << 2)) {
 
1520
        int decrement = window / dwords;
 
1521
        while(h > decrement) {
 
1522
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords * decrement);
 
1523
            dest += (dstwidth * decrement);
 
1524
            h -= decrement;
 
1525
        }
 
1526
        if(h) {
 
1527
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords * h);
 
1528
        }
 
1529
    } else {
 
1530
        while(h--) {
 
1531
            MoveDWORDS((CARD32*)dest, (CARD32*)src, dwords);
 
1532
            dest += dstwidth;
 
1533
        }
 
1534
    }
 
1535
}
 
1536
 
 
1537
static void 
 
1538
CTNAME(WritePixmap)(ScrnInfoPtr pScrn, int x, int y, int w, int h,
 
1539
                unsigned char *src, int srcwidth, int rop,
 
1540
                unsigned int planemask, int trans, int bpp, int depth)
 
1541
{
 
1542
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1543
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1544
    unsigned int bytesPerLine;
 
1545
    unsigned int byteWidthSrc;
 
1546
    unsigned int destpitch;
 
1547
    int dwords; 
 
1548
    int skipleft;
 
1549
    int destaddr;
 
1550
    
 
1551
    DEBUG_P("WritePixmap");
 
1552
#ifdef DEBUG
 
1553
    ErrorF("WritePixmap x %d, y %d, w %d, h %d, src 0x%X, srcwidth %d, rop 0x%X, planemask 0x%X, trans 0x%X, bpp %d, depth %d\n", x, y, w, h, src, srcwidth, rop, planemask, trans, bpp, depth);
 
1554
#endif
 
1555
    bytesPerLine = w * (bpp >> 3);
 
1556
    byteWidthSrc = ((srcwidth * (bpp >> 3) + 3L) & ~0x3L);
 
1557
    cAcl->CommandFlags = ctSRCSYSTEM | ctLEFT2RIGHT | ctTOP2BOTTOM;
 
1558
    skipleft = (unsigned long)src & 0x7;
 
1559
    src = (unsigned char *)((unsigned long)src & ~0x7L);
 
1560
    dwords = (((skipleft  + bytesPerLine + 0x7) & ~0x7)) >> 2;
 
1561
    destaddr = (y * pScrn->displayWidth + x) * (bpp >> 3);
 
1562
    destpitch = pScrn->displayWidth * (bpp >> 3);
 
1563
    if ((y >= pScrn->virtualY) && (cPtr->Flags & ChipsOverlay8plus16))
 
1564
        destaddr += cPtr->FbOffset16;
 
1565
    else
 
1566
        destaddr += cAcl->FbOffset;
 
1567
 
 
1568
    ctBLTWAIT;
 
1569
 
 
1570
    if (trans != -1) {
 
1571
        cAcl->CommandFlags |= ctCOLORTRANSENABLE | ctCOLORTRANSROP |
 
1572
            ctCOLORTRANSNEQUAL;
 
1573
        ctSETMONOCTL(ctDWORDALIGN);
 
1574
        switch (cAcl->BitsPerPixel) {
 
1575
        case 8:
 
1576
            ctSETBGCOLOR8(trans);
 
1577
            break;
 
1578
        case 16:
 
1579
            ctSETBGCOLOR16(trans);
 
1580
            break;
 
1581
        case 24:
 
1582
            ctSETBGCOLOR24(trans);
 
1583
            break;
 
1584
        }
 
1585
    }
 
1586
    
 
1587
    switch (cAcl->BitsPerPixel) {
 
1588
    case 8:
 
1589
        if ((planemask & 0xFF) == 0xFF) {
 
1590
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1591
        } else {
 
1592
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
1593
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1594
            ctWRITEPLANEMASK8(planemask, cAcl->ScratchAddress);
 
1595
        }
 
1596
        break;
 
1597
    case 16:
 
1598
        if ((planemask & 0xFFFF) == 0xFFFF) {
 
1599
            ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1600
        } else {
 
1601
            ctSETROP(cAcl->CommandFlags | ChipsAluConv3[rop & 0xF]);
 
1602
            ctSETPATSRCADDR(cAcl->ScratchAddress);
 
1603
            ctWRITEPLANEMASK16(planemask, cAcl->ScratchAddress);
 
1604
        }
 
1605
        break;
 
1606
    default:
 
1607
        ctSETROP(cAcl->CommandFlags | ChipsAluConv[rop & 0xF]);
 
1608
        break;
 
1609
    }
 
1610
 
 
1611
    /*
 
1612
     *
 
1613
     *  CT6555X requires quad-word padding, but XAA provides double-word
 
1614
     *  padding. If the width of a region to be transferred happens to be 
 
1615
     *  quad-word aligned, the transfer is straightforward.  If the 
 
1616
     *  region is double-word aligned, a pair of contiguous scanlines 
 
1617
     *  is quad-word aligned.  In latter case, we can use interleaved 
 
1618
     *  transfer twice.  It is faster than transfer line by line.
 
1619
     *
 
1620
     */
 
1621
 
 
1622
    ctSETSRCADDR(skipleft);
 
1623
    ctSETDSTADDR(destaddr);
 
1624
 
 
1625
    if ((byteWidthSrc & 0x7) == 0) {  /* quad-word aligned */
 
1626
 
 
1627
        ctSETPITCH(byteWidthSrc, destpitch);
 
1628
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1629
 
 
1630
        MoveDataFromCPU((unsigned char *)src,
 
1631
                (unsigned char *)cAcl->BltDataWindow,
 
1632
                srcwidth, 16384, h, dwords);
 
1633
 
 
1634
    } else {
 
1635
        unsigned int vert = h;
 
1636
 
 
1637
        h = (vert + 1) >> 1;
 
1638
 
 
1639
        ctSETPITCH(byteWidthSrc << 1, destpitch << 1);
 
1640
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1641
 
 
1642
        MoveDataFromCPU((unsigned char *)src,
 
1643
                (unsigned char *)cAcl->BltDataWindow,
 
1644
                srcwidth<<1, 16384, h, dwords);
 
1645
 
 
1646
        h = vert  >> 1;
 
1647
        src += srcwidth;
 
1648
        y++;
 
1649
 
 
1650
        destaddr = (y * pScrn->displayWidth + x) * (bpp >> 3);
 
1651
        if ((y >= pScrn->virtualY) && (cPtr->Flags & ChipsOverlay8plus16))
 
1652
            destaddr += cPtr->FbOffset16;
 
1653
        else
 
1654
            destaddr += cAcl->FbOffset;
 
1655
 
 
1656
        ctBLTWAIT;
 
1657
        ctSETDSTADDR(destaddr);
 
1658
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1659
 
 
1660
        MoveDataFromCPU((unsigned char *)src,
 
1661
                (unsigned char *)cAcl->BltDataWindow,
 
1662
                srcwidth<<1, 16384, h, dwords);
 
1663
    }
 
1664
 
 
1665
    cPtr->AccelInfoRec->NeedToSync = TRUE;
 
1666
}
 
1667
 
 
1668
#if 0
 
1669
static void 
 
1670
CTNAME(ReadPixmap)(ScrnInfoPtr pScrn, int x, int y, int w, int h,
 
1671
                unsigned char *dst, int dstwidth, int bpp, int depth)
 
1672
{
 
1673
    CHIPSPtr cPtr = CHIPSPTR(pScrn);
 
1674
    CHIPSACLPtr cAcl = CHIPSACLPTR(pScrn);
 
1675
    unsigned int bytesPerLine;
 
1676
    unsigned int byteWidthDst;
 
1677
    unsigned int srcpitch;
 
1678
    int dwords; 
 
1679
    int srcaddr;
 
1680
 
 
1681
    DEBUG_P("ReadPixmap");
 
1682
    bytesPerLine = w * (bpp >> 3);
 
1683
    byteWidthDst = ((dstwidth * (bpp >> 3) + 3L) & ~0x3L);
 
1684
    dwords = (((bytesPerLine + 0x7) & ~0x7)) >> 2;
 
1685
    srcaddr = (y * pScrn->displayWidth + x) * (bpp >> 3);
 
1686
    srcpitch = pScrn->displayWidth * (bpp >> 3);
 
1687
    if ((y >= pScrn->virtualY) && (cPtr->Flags & ChipsOverlay8plus16))
 
1688
        srcaddr += cPtr->FbOffset16;
 
1689
    else
 
1690
        srcaddr += cAcl->FbOffset;
 
1691
 
 
1692
    ctBLTWAIT;
 
1693
    ctSETROP( ctDSTSYSTEM | ctLEFT2RIGHT | ctTOP2BOTTOM | 
 
1694
              ChipsAluConv[GXcopy & 0xF]);
 
1695
    ctSETDSTADDR(0);
 
1696
    ctSETSRCADDR(srcaddr);
 
1697
 
 
1698
    if ((byteWidthDst & 0x7) == 0) {  /* quad-word aligned */
 
1699
 
 
1700
        ctSETPITCH(srcpitch, byteWidthDst);
 
1701
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1702
 
 
1703
        MoveDataToCPU((unsigned char *)cAcl->BltDataWindow,
 
1704
                 (unsigned char *)dst, dstwidth, 16384, h, dwords);
 
1705
 
 
1706
    } else {
 
1707
        unsigned int vert = h;
 
1708
 
 
1709
        h = (vert + 1) >> 1;
 
1710
 
 
1711
        ctSETPITCH(srcpitch << 1, byteWidthDst << 1);
 
1712
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1713
 
 
1714
        MoveDataToCPU((unsigned char *)cAcl->BltDataWindow,
 
1715
                 (unsigned char *)dst, dstwidth<<1, 16384, h, dwords);
 
1716
 
 
1717
        h = vert  >> 1;
 
1718
        dst += dstwidth;
 
1719
        y++;
 
1720
        srcaddr = (y * pScrn->displayWidth + x) * (bpp >> 3);
 
1721
        if ((y >= pScrn->virtualY) && (cPtr->Flags & ChipsOverlay8plus16))
 
1722
            srcaddr += cPtr->FbOffset16;
 
1723
        else
 
1724
            srcaddr += cAcl->FbOffset;
 
1725
        ctBLTWAIT;
 
1726
        ctSETSRCADDR(srcaddr);
 
1727
        ctSETHEIGHTWIDTHGO(h, bytesPerLine);
 
1728
 
 
1729
        MoveDataToCPU((unsigned char *)cAcl->BltDataWindow,
 
1730
                 (unsigned char *)dst, dstwidth<<1, 16384, h, dwords);
 
1731
    }
 
1732
 
 
1733
    cPtr->AccelInfoRec->NeedToSync = TRUE;
 
1734
}
 
1735
#endif /* ReadPixmap */
 
1736
 
 
1737
#endif