~ubuntu-branches/ubuntu/precise/xserver-xorg-video-geode-lts-quantal/precise-updates

« back to all changes in this revision

Viewing changes to src/gx_accel.c

  • Committer: Package Import Robot
  • Author(s): Maarten Lankhorst
  • Date: 2012-11-30 20:59:48 UTC
  • Revision ID: package-import@ubuntu.com-20121130205948-8p83molp6tff7m8o
Tags: upstream-2.11.13+git20120726
ImportĀ upstreamĀ versionĀ 2.11.13+git20120726

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2003-2005 Advanced Micro Devices, Inc.
 
2
 *
 
3
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 
4
 * of this software and associated documentation files (the "Software"), to
 
5
 * deal in the Software without restriction, including without limitation the
 
6
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
7
 * sell copies of the Software, and to permit persons to whom the Software is
 
8
 * furnished to do so, subject to the following conditions:
 
9
 *
 
10
 * The above copyright notice and this permission notice shall be included in
 
11
 * all copies or substantial portions of the Software.
 
12
 *
 
13
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
14
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
15
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
17
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
18
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
19
 * IN THE SOFTWARE.
 
20
 *
 
21
 * Neither the name of the Advanced Micro Devices, Inc. nor the names of its
 
22
 * contributors may be used to endorse or promote products derived from this
 
23
 * software without specific prior written permission.
 
24
 * */
 
25
 
 
26
/*
 
27
 * File Contents:   This file is consists of main Xfree acceleration supported
 
28
 *                  routines like solid fill used here.
 
29
 *
 
30
 * Project:         Geode Xfree Frame buffer device driver.
 
31
 * */
 
32
 
 
33
/* #undef OPT_ACCEL */
 
34
 
 
35
/* Xfree86 header files */
 
36
#ifdef HAVE_CONFIG_H
 
37
#include "config.h"
 
38
#endif
 
39
 
 
40
#include "vgaHW.h"
 
41
#include "xf86.h"
 
42
#ifdef HAVE_XAA_H
 
43
#include "xaalocal.h"
 
44
#endif
 
45
#include "xf86fbman.h"
 
46
#include "miline.h"
 
47
#include "xaarop.h"
 
48
#include "servermd.h"
 
49
#include "picture.h"
 
50
#include "xf86.h"
 
51
#include "xf86_OSproc.h"
 
52
#include "xf86Pci.h"
 
53
#include "xf86PciInfo.h"
 
54
#include "geode.h"
 
55
#include "gfx_defs.h"
 
56
#include "gfx_regs.h"
 
57
 
 
58
/* Common macros for blend operations are here */
 
59
 
 
60
#include "geode_blend.h"
 
61
 
 
62
#undef ulong
 
63
typedef unsigned long ulong;
 
64
 
 
65
#undef uint
 
66
typedef unsigned int uint;
 
67
 
 
68
#undef ushort
 
69
typedef unsigned short ushort;
 
70
 
 
71
#undef uchar
 
72
typedef unsigned char uchar;
 
73
 
 
74
#define CALC_FBOFFSET(x, y) \
 
75
                (((ulong)(y) * gu2_pitch + ((ulong)(x) << gu2_xshift)))
 
76
 
 
77
#define FBADDR(x,y)                             \
 
78
                ((unsigned char *)pGeode->FBBase + CALC_FBOFFSET(x, y))
 
79
 
 
80
#define OS_UDELAY 0
 
81
#if OS_UDELAY > 0
 
82
#define OS_USLEEP(usec) usleep(usec);
 
83
#else
 
84
#define OS_USLEEP(usec)
 
85
#endif
 
86
 
 
87
#ifdef OPT_ACCEL
 
88
static unsigned int BPP;
 
89
static unsigned int BLT_MODE, VEC_MODE;
 
90
static unsigned int ACCEL_STRIDE;
 
91
 
 
92
#define GU2_WAIT_PENDING while(READ_GP32(MGP_BLT_STATUS) & MGP_BS_BLT_PENDING)
 
93
#define GU2_WAIT_BUSY    while(READ_GP32(MGP_BLT_STATUS) & MGP_BS_BLT_BUSY)
 
94
#endif
 
95
 
 
96
#define HOOK(fn) localRecPtr->fn = GX##fn
 
97
 
 
98
#define DLOG(l, fmt, args...) ErrorF(fmt, ##args)
 
99
 
 
100
/* static storage declarations */
 
101
 
 
102
typedef struct sGBltBox {
 
103
    ulong x, y;
 
104
    ulong w, h;
 
105
    ulong color;
 
106
    int bpp, transparent;
 
107
} GBltBox;
 
108
 
 
109
#if GX_SCANLINE_SUPPORT
 
110
static GBltBox giwr;
 
111
#endif
 
112
#if GX_CPU2SCREXP_SUPPORT
 
113
static GBltBox gc2s;
 
114
#endif
 
115
#if GX_CLREXP_8X8_PAT_SUPPORT
 
116
static ulong *gc8x8p;
 
117
#endif
 
118
 
 
119
#if GX_DASH_LINE_SUPPORT
 
120
typedef struct sGDashLine {
 
121
    ulong pat[2];
 
122
    int len;
 
123
    int fg;
 
124
    int bg;
 
125
} GDashLine;
 
126
 
 
127
static GDashLine gdln;
 
128
#endif
 
129
 
 
130
static unsigned int gu2_xshift, gu2_yshift;
 
131
static unsigned int gu2_pitch;
 
132
 
 
133
#if XF86XAA
 
134
static XAAInfoRecPtr localRecPtr;
 
135
#endif
 
136
 
 
137
/* pat  0xF0 */
 
138
/* src  0xCC */
 
139
/* dst  0xAA */
 
140
 
 
141
/* (src FUNC dst) */
 
142
 
 
143
static const int SDfn[16] = {
 
144
    0x00, 0x88, 0x44, 0xCC, 0x22, 0xAA, 0x66, 0xEE,
 
145
    0x11, 0x99, 0x55, 0xDD, 0x33, 0xBB, 0x77, 0xFF
 
146
};
 
147
 
 
148
/* ((src FUNC dst) AND pat-mask) OR (dst AND (NOT pat-mask)) */
 
149
 
 
150
static const int SDfn_PM[16] = {
 
151
    0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
 
152
    0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA
 
153
};
 
154
 
 
155
/* (pat FUNC dst) */
 
156
 
 
157
static const int PDfn[16] = {
 
158
    0x00, 0xA0, 0x50, 0xF0, 0x0A, 0xAA, 0x5A, 0xFA,
 
159
    0x05, 0xA5, 0x55, 0xF5, 0x0F, 0xAF, 0x5F, 0xFF
 
160
};
 
161
 
 
162
/* ((pat FUNC dst) AND src-mask) OR (dst AND (NOT src-mask)) */
 
163
 
 
164
static const int PDfn_SM[16] = {
 
165
    0x22, 0xA2, 0x62, 0xE2, 0x2A, 0xAA, 0x6A, 0xEA,
 
166
    0x26, 0xA6, 0x66, 0xE6, 0x2E, 0xAE, 0x6E, 0xEE
 
167
};
 
168
 
 
169
#ifdef OPT_ACCEL
 
170
static inline CARD32
 
171
amd_gx_BppToRasterMode(int bpp)
 
172
{
 
173
    switch (bpp) {
 
174
    case 16:
 
175
        return MGP_RM_BPPFMT_565;
 
176
    case 32:
 
177
        return MGP_RM_BPPFMT_8888;
 
178
    case 8:
 
179
        return MGP_RM_BPPFMT_332;
 
180
    default:
 
181
        return 0;
 
182
    }
 
183
}
 
184
#endif                          /* OPT_ACCEL */
 
185
 
 
186
/*----------------------------------------------------------------------------
 
187
 * GXAccelSync.
 
188
 *
 
189
 * Description  :This function is called to synchronize with the graphics
 
190
 *               engine and it waits the graphic engine is idle.  This is
 
191
 *               required before allowing direct access to the framebuffer.
 
192
 *
 
193
 *    Arg        Type     Comment
 
194
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
195
 *
 
196
 * Returns              :none
 
197
 *---------------------------------------------------------------------------*/
 
198
void
 
199
GXAccelSync(ScrnInfoPtr pScrni)
 
200
{
 
201
    //ErrorF("GXAccelSync()\n");
 
202
#ifndef OPT_ACCEL
 
203
    gfx_wait_until_idle();
 
204
#else
 
205
    GU2_WAIT_BUSY;
 
206
#endif
 
207
}
 
208
 
 
209
#if GX_FILL_RECT_SUPPORT
 
210
/*----------------------------------------------------------------------------
 
211
 * GXSetupForSolidFill.
 
212
 *
 
213
 * Description  :The SetupFor and Subsequent SolidFill(Rect) provide
 
214
 *               filling rectangular areas of the screen with a
 
215
 *               foreground color.
 
216
 *
 
217
 * Parameters.
 
218
 *    Arg        Type     Comment
 
219
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
220
 *   color        int     foreground fill color
 
221
 *    rop         int     unmapped raster op
 
222
 * planemask     uint     -1 (fill) or pattern data
 
223
 *
 
224
 * Returns              :none
 
225
 *--------------------------------------------------------------------------*/
 
226
static void
 
227
GXSetupForSolidFill(ScrnInfoPtr pScrni,
 
228
                    int color, int rop, unsigned int planemask)
 
229
{
 
230
    //ErrorF("GXSetupForSolidFill(%#x,%#x,%#x)\n", color, rop, planemask);
 
231
    rop &= 0x0F;
 
232
#ifndef OPT_ACCEL
 
233
    gfx_set_solid_pattern(planemask);
 
234
    gfx_set_solid_source(color);
 
235
    gfx_set_raster_operation(planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
236
#else
 
237
    {
 
238
        unsigned int ROP = BPP | (planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
239
 
 
240
        BLT_MODE = ((ROP ^ (ROP >> 2)) & 0x33) == 0 ? MGP_BM_SRC_MONO : 0;
 
241
        if (((ROP ^ (ROP >> 1)) & 0x55) != 0)
 
242
            BLT_MODE |= MGP_BM_DST_REQ;
 
243
        GU2_WAIT_PENDING;
 
244
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
245
        WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
246
        WRITE_GP32(MGP_SRC_COLOR_FG, color);
 
247
        WRITE_GP32(MGP_STRIDE, ACCEL_STRIDE);
 
248
    }
 
249
#endif
 
250
}
 
251
 
 
252
/*----------------------------------------------------------------------------
 
253
 * GXSubsequentSolidFillRect.
 
254
 *
 
255
 * Description  :see GXSetupForSolidFill.
 
256
 *
 
257
 * Parameters.
 
258
 *    Arg        Type     Comment
 
259
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
260
 *     x          int     destination x offset
 
261
 *     y          int     destination y offset
 
262
 *     w          int     fill area width (pixels)
 
263
 *     h          int     fill area height (pixels)
 
264
 *
 
265
 * Returns      :none
 
266
 *
 
267
 * Sample application uses:
 
268
 *   - Window backgrounds.
 
269
 *   - pull down highlighting.
 
270
 *   - x11perf: rectangle tests (-rect500).
 
271
 *   - x11perf: fill trapezoid tests (-trap100).
 
272
 *   - x11perf: horizontal line segments (-hseg500).
 
273
 *----------------------------------------------------------------------------*/
 
274
static void
 
275
GXSubsequentSolidFillRect(ScrnInfoPtr pScrni, int x, int y, int w, int h)
 
276
{
 
277
    //ErrorF("GXSubsequentSolidFillRect() at %d,%d %dx%d\n", x, y, w, h);
 
278
#ifndef OPT_ACCEL
 
279
    gfx_pattern_fill(x, y, w, h);
 
280
#else
 
281
    {
 
282
        unsigned int offset = CALC_FBOFFSET(x, y);
 
283
        unsigned int size = (w << 16) | h;
 
284
 
 
285
        GU2_WAIT_PENDING;
 
286
        WRITE_GP32(MGP_DST_OFFSET, offset);
 
287
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
288
        WRITE_GP32(MGP_BLT_MODE, BLT_MODE);
 
289
    }
 
290
#endif
 
291
}
 
292
 
 
293
#endif                          /* if GX_FILL_RECT_SUPPORT */
 
294
 
 
295
#if GX_CLREXP_8X8_PAT_SUPPORT
 
296
/*----------------------------------------------------------------------------
 
297
 * GXSetupForColor8x8PatternFill
 
298
 *
 
299
 * Description  :8x8 color pattern data is 64 pixels of full color data
 
300
 *               stored linearly in offscreen video memory.  These patterns
 
301
 *               are useful as a substitute for 8x8 mono patterns when tiling,
 
302
 *               doing opaque stipples, or regular stipples.
 
303
 *
 
304
 *    Arg        Type     Comment
 
305
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
306
 *    patx        int     x offset to pattern data
 
307
 *    paty        int     y offset to pattern data
 
308
 *    rop         int     unmapped raster operation
 
309
 * planemask     uint     -1 (copy) or pattern data
 
310
 * trans_color    int     -1 (copy) or transparent color (not enabled)
 
311
 *                         trans color only supported on source channel
 
312
 *                         or in monochrome pattern channel
 
313
 *
 
314
 * Returns      :none.
 
315
 *
 
316
 *---------------------------------------------------------------------------*/
 
317
 
 
318
static void
 
319
GXSetupForColor8x8PatternFill(ScrnInfoPtr pScrni, int patx, int paty, int rop,
 
320
                              uint planemask, int trans_color)
 
321
{
 
322
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
323
 
 
324
    //ErrorF("GXSetupForColor8x8PatternFill() pat %#x,%#x rop %#x %#x %#x\n",
 
325
    //    patx, paty, rop, planemask, trans_color);
 
326
    rop &= 0x0F;
 
327
    gc8x8p = (unsigned long *) FBADDR(patx, paty);
 
328
    /* gfx_set_solid_pattern is needed to clear src/pat transparency */
 
329
    gfx_set_solid_pattern(0);
 
330
    gfx_set_raster_operation(planemask == ~0U ? PDfn[rop] :
 
331
                             (gfx_set_solid_source(planemask), PDfn_SM[rop]));
 
332
    gfx2_set_source_stride(pGeode->Pitch);
 
333
    gfx2_set_destination_stride(pGeode->Pitch);
 
334
    if (trans_color == -1)
 
335
        gfx2_set_source_transparency(0, 0);
 
336
    else
 
337
        gfx2_set_source_transparency(trans_color, ~0);
 
338
}
 
339
 
 
340
/*----------------------------------------------------------------------------
 
341
 * GXSubsequentColor8x8PatternFillRect
 
342
 *
 
343
 * Description  :see GXSetupForColor8x8PatternFill.
 
344
 *
 
345
 *    Arg        Type     Comment
 
346
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
347
 *   patx         int     pattern phase x offset
 
348
 *   paty         int     pattern phase y offset
 
349
 *      x         int     destination x offset
 
350
 *      y         int     destination y offset
 
351
 *      w         int     fill area width (pixels)
 
352
 *      h         int     fill area height (pixels)
 
353
 *
 
354
 * Returns      :none
 
355
 *
 
356
 * Sample application uses:
 
357
 *   - Patterned desktops
 
358
 *   - x11perf: stippled rectangle tests (-srect500).
 
359
 *   - x11perf: opaque stippled rectangle tests (-osrect500).
 
360
 *--------------------------------------------------------------------------*/
 
361
static void
 
362
GXSubsequentColor8x8PatternFillRect(ScrnInfoPtr pScrni, int patx, int paty,
 
363
                                    int x, int y, int w, int h)
 
364
{
 
365
    //ErrorF(
 
366
    //    "GXSubsequentColor8x8PatternFillRect() patxy %d,%d at %d,%d %dsx%d\n",
 
367
    //    patx, paty, x, y, w, h);
 
368
    gfx2_set_pattern_origin(patx, paty);
 
369
    gfx2_color_pattern_fill(CALC_FBOFFSET(x, y), w, h, gc8x8p);
 
370
}
 
371
 
 
372
/* GX_CLREXP_8X8_PAT_SUPPORT */
 
373
#endif
 
374
 
 
375
#if GX_MONO_8X8_PAT_SUPPORT
 
376
/*----------------------------------------------------------------------------
 
377
 * GXSetupForMono8x8PatternFill
 
378
 *
 
379
 * Description  :8x8 mono pattern data is 64 bits of color expansion data
 
380
 *               with ones indicating the foreground color and zeros
 
381
 *               indicating the background color.  These patterns are
 
382
 *               useful when tiling, doing opaque stipples, or regular
 
383
 *               stipples.
 
384
 *
 
385
 *    Arg        Type     Comment
 
386
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
387
 *    patx        int     x offset to pattern data
 
388
 *    paty        int     y offset to pattern data
 
389
 *     fg         int     foreground color
 
390
 *     bg         int     -1 (transparent) or background color
 
391
 *    rop         int     unmapped raster operation
 
392
 * planemask     uint     -1 (copy) or pattern data
 
393
 *
 
394
 * Returns      :none.
 
395
 *
 
396
 * Comments     :none.
 
397
 *
 
398
 *--------------------------------------------------------------------------*/
 
399
static void
 
400
GXSetupForMono8x8PatternFill(ScrnInfoPtr pScrni, int patx, int paty,
 
401
                             int fg, int bg, int rop, uint planemask)
 
402
{
 
403
    //ErrorF(
 
404
    //"GXSetupForMono8x8PatternFill() pat %#x,%#x fg %#x bg %#x %#x %#x\n",
 
405
    //patx, paty, fg, bg, rop, planemask);
 
406
    rop &= 0x0F;
 
407
#ifndef OPT_ACCEL
 
408
    gfx_set_mono_pattern(bg, fg, patx, paty, bg == -1 ? 1 : 0);
 
409
    gfx_set_raster_operation(planemask == ~0U ? PDfn[rop] :
 
410
                             (gfx_set_solid_source(planemask), PDfn_SM[rop]));
 
411
#else
 
412
    {
 
413
        unsigned int ROP = BPP |
 
414
            (bg ==
 
415
             -1 ? MGP_RM_PAT_MONO | MGP_RM_PAT_TRANS : MGP_RM_PAT_MONO) |
 
416
            (planemask == ~0U ? PDfn[rop] : PDfn_SM[rop]);
 
417
        BLT_MODE = ((ROP ^ (ROP >> 2)) & 0x33) == 0 ? MGP_BM_SRC_MONO : 0;
 
418
        if (((ROP ^ (ROP >> 1)) & 0x55) != 0)
 
419
            BLT_MODE |= MGP_BM_DST_REQ;
 
420
        GU2_WAIT_PENDING;
 
421
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
422
        WRITE_GP32(MGP_SRC_COLOR_FG, planemask);
 
423
        WRITE_GP32(MGP_PAT_COLOR_0, bg);
 
424
        WRITE_GP32(MGP_PAT_COLOR_1, fg);
 
425
        WRITE_GP32(MGP_PAT_DATA_0, patx);
 
426
        WRITE_GP32(MGP_PAT_DATA_1, paty);
 
427
        WRITE_GP32(MGP_STRIDE, ACCEL_STRIDE);
 
428
    }
 
429
#endif
 
430
}
 
431
 
 
432
/*----------------------------------------------------------------------------
 
433
 * GXSubsequentMono8x8PatternFillRect
 
434
 *
 
435
 * Description  :see GXSetupForMono8x8PatternFill
 
436
 *
 
437
 *    Arg        Type     Comment
 
438
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
439
 *   patx         int     pattern phase x offset
 
440
 *   paty         int     pattern phase y offset
 
441
 *      x         int     destination x offset
 
442
 *      y         int     destination y offset
 
443
 *      w         int     fill area width (pixels)
 
444
 *      h         int     fill area height (pixels)
 
445
 
 
446
 * Returns      :none
 
447
 *
 
448
 * Sample application uses:
 
449
 *   - Patterned desktops
 
450
 *   - x11perf: stippled rectangle tests (-srect500).
 
451
 *   - x11perf: opaque stippled rectangle tests (-osrect500).
 
452
 *--------------------------------------------------------------------------*/
 
453
static void
 
454
GXSubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrni, int patx, int paty,
 
455
                                   int x, int y, int w, int h)
 
456
{
 
457
    DEBUGMSG(1, (0, X_INFO, "%s() pat %#x,%#x at %d,%d %dx%d\n",
 
458
                 __func__, patx, paty, x, y, w, h));
 
459
#ifndef OPT_ACCEL
 
460
    gfx_pattern_fill(x, y, w, h);
 
461
#else
 
462
    {
 
463
        unsigned int offset =
 
464
            CALC_FBOFFSET(x, y) | ((x & 7) << 26) | ((y & 7) << 29);
 
465
        unsigned int size = (w << 16) | h;
 
466
 
 
467
        GU2_WAIT_PENDING;
 
468
        WRITE_GP32(MGP_DST_OFFSET, offset);
 
469
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
470
        WRITE_GP32(MGP_BLT_MODE, BLT_MODE);
 
471
    }
 
472
#endif
 
473
}
 
474
 
 
475
#endif                          /* GX_MONO_8X8_PAT_SUPPORT */
 
476
 
 
477
#if GX_SCR2SCRCPY_SUPPORT
 
478
/*----------------------------------------------------------------------------
 
479
 * GXSetupForScreenToScreenCopy
 
480
 *
 
481
 * Description  :SetupFor and Subsequent ScreenToScreenCopy functions
 
482
 *               provide an interface for copying rectangular areas from
 
483
 *               video memory to video memory.
 
484
 *
 
485
 *    Arg        Type     Comment
 
486
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
487
 *   xdir         int     x copy direction (up/dn)
 
488
 *   ydir         int     y copy direction (up/dn)
 
489
 *    rop         int     unmapped raster operation
 
490
 * planemask     uint     -1 (copy) or pattern data
 
491
 * trans_color    int     -1 (copy) or transparent color
 
492
 *
 
493
 * Returns      :none
 
494
 *---------------------------------------------------------------------------*/
 
495
static void
 
496
GXSetupForScreenToScreenCopy(ScrnInfoPtr pScrni, int xdir, int ydir, int rop,
 
497
                             uint planemask, int trans_color)
 
498
{
 
499
    DEBUGMSG(1, (0, X_INFO, "%s() xd%d yd%d rop %#x %#x %#x\n",
 
500
                 __func__, xdir, ydir, rop, planemask, trans_color));
 
501
    rop &= 0x0F;
 
502
#ifndef OPT_ACCEL
 
503
    {
 
504
        GeodeRec *pGeode = GEODEPTR(pScrni);
 
505
 
 
506
        gfx_set_solid_pattern(planemask);
 
507
        /* transparency is a parameter to set_rop, but set...pattern clears
 
508
         * transparency */
 
509
        if (trans_color == -1)
 
510
            gfx2_set_source_transparency(0, 0);
 
511
        else
 
512
            gfx2_set_source_transparency(trans_color, ~0);
 
513
        gfx_set_raster_operation(planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
514
        gfx2_set_source_stride(pGeode->Pitch);
 
515
        gfx2_set_destination_stride(pGeode->Pitch);
 
516
    }
 
517
#else
 
518
    {
 
519
        unsigned int ROP = BPP | (planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
520
 
 
521
        if (trans_color != -1)
 
522
            ROP |= MGP_RM_SRC_TRANS;
 
523
        BLT_MODE = ((ROP ^ (ROP >> 1)) & 0x55) != 0 ?
 
524
            MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
525
        GU2_WAIT_PENDING;
 
526
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
527
        WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
528
        WRITE_GP32(MGP_SRC_COLOR_FG, trans_color);
 
529
        WRITE_GP32(MGP_SRC_COLOR_BG, ~0);
 
530
        WRITE_GP32(MGP_STRIDE, ACCEL_STRIDE);
 
531
    }
 
532
#endif
 
533
}
 
534
 
 
535
/*----------------------------------------------------------------------------
 
536
 * GXSubsquentScreenToScreenCopy
 
537
 *
 
538
 * Description  :see GXSetupForScreenToScreenCopy.
 
539
 *
 
540
 *    Arg        Type     Comment
 
541
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
542
 *     x1         int     source x offset
 
543
 *     y1         int     source y offset
 
544
 *     x2         int     destination x offset
 
545
 *     y2         int     destination y offset
 
546
 *      w         int     copy area width (pixels)
 
547
 *      h         int     copy area height (pixels)
 
548
 *
 
549
 * Returns      :none
 
550
 *
 
551
 * Sample application uses (non-transparent):
 
552
 *   - Moving windows.
 
553
 *   - x11perf: scroll tests (-scroll500).
 
554
 *   - x11perf: copy from window to window (-copywinwin500).
 
555
 *---------------------------------------------------------------------------*/
 
556
static void
 
557
GXSubsequentScreenToScreenCopy(ScrnInfoPtr pScrni,
 
558
                               int x1, int y1, int x2, int y2, int w, int h)
 
559
{
 
560
    DEBUGMSG(1, (0, X_INFO, "%s() from %d,%d to %d,%d %dx%d\n",
 
561
                 __func__, x1, y1, x2, y2, w, h));
 
562
#ifndef OPT_ACCEL
 
563
    {
 
564
        int flags = 0;
 
565
 
 
566
        if (x2 > x1)
 
567
            flags |= 1;
 
568
        if (y2 > y1)
 
569
            flags |= 2;
 
570
        gfx2_screen_to_screen_blt(CALC_FBOFFSET(x1, y1), CALC_FBOFFSET(x2,
 
571
                                                                       y2), w,
 
572
                                  h, flags);
 
573
    }
 
574
#else
 
575
    {
 
576
        GeodeRec *pGeode = GEODEPTR(pScrni);
 
577
        unsigned int src = CALC_FBOFFSET(x1, y1);
 
578
        unsigned int dst = CALC_FBOFFSET(x2, y2);
 
579
        unsigned int size = (w << 16) | h;
 
580
        unsigned int blt_mode = BLT_MODE;
 
581
 
 
582
        if (x2 > x1) {
 
583
            int n = (w << gu2_xshift) - 1;
 
584
 
 
585
            src += n;
 
586
            dst += n;
 
587
            blt_mode |= MGP_BM_NEG_XDIR;
 
588
        }
 
589
        if (y2 > y1) {
 
590
            int n = (h - 1) * pGeode->Pitch;
 
591
 
 
592
            src += n;
 
593
            dst += n;
 
594
            blt_mode |= MGP_BM_NEG_YDIR;
 
595
        }
 
596
        GU2_WAIT_PENDING;
 
597
        WRITE_GP32(MGP_SRC_OFFSET, src);
 
598
        WRITE_GP32(MGP_DST_OFFSET, dst);
 
599
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
600
        WRITE_GP16(MGP_BLT_MODE, blt_mode);
 
601
    }
 
602
#endif
 
603
}
 
604
 
 
605
#endif                          /* if GX_SCR2SCRCPY_SUPPORT */
 
606
 
 
607
#if GX_SCANLINE_SUPPORT
 
608
/*----------------------------------------------------------------------------
 
609
 * GXSetupForScanlineImageWrite
 
610
 *
 
611
 * Description  :SetupFor/Subsequent ScanlineImageWrite and ImageWriteScanline
 
612
 *               transfer full color pixel data from system memory to video
 
613
 *               memory.  This is useful for dealing with alignment issues and
 
614
 *               performing raster ops on the data.
 
615
 *
 
616
 *    Arg        Type     Comment
 
617
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
618
 *    rop         int     unmapped raster operation
 
619
 * planemask     uint     -1 (copy) or pattern data
 
620
 *    bpp         int     bits per pixel (unused)
 
621
 *  depth         int     color depth (unused)
 
622
 *
 
623
 * Returns      :none
 
624
 *
 
625
 *  x11perf -putimage10
 
626
 *  x11perf -putimage100
 
627
 *  x11perf -putimage500
 
628
 *----------------------------------------------------------------------------
 
629
 */
 
630
static void
 
631
GXSetupForScanlineImageWrite(ScrnInfoPtr pScrni, int rop, uint planemask,
 
632
                             int trans_color, int bpp, int depth)
 
633
{
 
634
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
635
 
 
636
    DEBUGMSG(1, (0, X_INFO, "%s() rop %#x %#x %#x %d %d\n",
 
637
                 __func__, rop, planemask, trans_color, bpp, depth));
 
638
    rop &= 0x0F;
 
639
    /* transparency is a parameter to set_rop, but set...pattern clears
 
640
     * transparency */
 
641
    gfx_set_solid_pattern(planemask);
 
642
    if (trans_color == -1)
 
643
        gfx2_set_source_transparency(0, 0);
 
644
    else
 
645
        gfx2_set_source_transparency(trans_color, ~0);
 
646
    gfx_set_raster_operation(planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
647
    gfx2_set_source_stride(pGeode->Pitch);
 
648
    gfx2_set_destination_stride(pGeode->Pitch);
 
649
}
 
650
 
 
651
/*----------------------------------------------------------------------------
 
652
 * GXSubsequentScanlineImageWriteRect
 
653
 *
 
654
 * Description  : see GXSetupForScanlineImageWrite.
 
655
 *
 
656
 *    Arg        Type     Comment
 
657
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
658
 *      x         int     destination x offset
 
659
 *      y         int     destination y offset
 
660
 *      w         int     copy area width (pixels)
 
661
 *      h         int     copy area height (pixels)
 
662
 * skipleft       int     x margin (pixels) to skip (not enabled)
 
663
 *
 
664
 * Returns      :none
 
665
 *---------------------------------------------------------------------------*/
 
666
static void
 
667
GXSubsequentScanlineImageWriteRect(ScrnInfoPtr pScrni,
 
668
                                   int x, int y, int w, int h, int skipleft)
 
669
{
 
670
    DEBUGMSG(1, (0, X_INFO, "%s() rop %d,%d %dx%d %d\n",
 
671
                 __func__, x, y, w, h, skipleft));
 
672
    giwr.x = x;
 
673
    giwr.y = y;
 
674
    giwr.w = w;
 
675
    giwr.h = h;
 
676
#if !GX_USE_OFFSCRN_MEM
 
677
#if !GX_ONE_LINE_AT_A_TIME
 
678
    GXAccelSync(pScrni);
 
679
#endif
 
680
#endif
 
681
}
 
682
 
 
683
/*----------------------------------------------------------------------------
 
684
 * GXSubsquentImageWriteScanline
 
685
 *
 
686
 * Description  : see GXSetupForScanlineImageWrite.
 
687
 *
 
688
 *    Arg        Type     Comment
 
689
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
690
 *  bufno         int     scanline number in write group
 
691
 *
 
692
 * Returns      :none
 
693
 *
 
694
 * Sample application uses (non-transparent):
 
695
 *   - Moving windows.
 
696
 *   - x11perf: scroll tests (-scroll500).
 
697
 *   - x11perf: copy from window to window (-copywinwin500).
 
698
 *
 
699
 *---------------------------------------------------------------------------*/
 
700
static void
 
701
GXSubsequentImageWriteScanline(ScrnInfoPtr pScrni, int bufno)
 
702
{
 
703
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
704
 
 
705
#if !GX_USE_OFFSCRN_MEM
 
706
    unsigned long offset;
 
707
#endif
 
708
 
 
709
#if GX_ONE_LINE_AT_A_TIME
 
710
    DEBUGMSG(1, (0, X_INFO, "%s() %d\n", __func__, bufno));
 
711
#if !GX_USE_OFFSCRN_MEM
 
712
    offset = pGeode->AccelImageWriteBuffers[bufno] - pGeode->FBBase;
 
713
    gfx2_screen_to_screen_blt(offset, CALC_FBOFFSET(giwr.x, giwr.y), giwr.w,
 
714
                              1, 0);
 
715
#else                           /* if !GX_USE_OFFSCRN_MEM */
 
716
    gfx2_color_bitmap_to_screen_blt(0, 0, CALC_FBOFFSET(giwr.x, giwr.y),
 
717
                                    giwr.w, 1,
 
718
                                    pGeode->AccelImageWriteBuffers[bufno],
 
719
                                    pGeode->Pitch);
 
720
#endif                          /* if !GX_USE_OFFSCRN_MEM */
 
721
    ++giwr.y;
 
722
#else                           /* if GX_ONE_LINE_AT_A_TIME */
 
723
    int blt_height;
 
724
 
 
725
    DEBUGMSG(1, (0, X_INFO, "%s() %d\n", __func__, bufno));
 
726
 
 
727
    if ((blt_height = pGeode->NoOfImgBuffers) > giwr.h)
 
728
        blt_height = giwr.h;
 
729
    if (++bufno < blt_height)
 
730
        return;
 
731
#if !GX_USE_OFFSCRN_MEM
 
732
    offset = pGeode->AccelImageWriteBuffers[0] - pGeode->FBBase;
 
733
    gfx2_screen_to_screen_blt(offset, CALC_FBOFFSET(giwr.x, giwr.y), giwr.w,
 
734
                              blt_height, 0);
 
735
    GXAccelSync(pScrni);
 
736
#else                           /* if !GX_USE_OFFSCRN_MEM */
 
737
    gfx2_color_bitmap_to_screen_blt(0, 0, CALC_FBOFFSET(giwr.x, giwr.y),
 
738
                                    giwr.w, blt_height,
 
739
                                    pGeode->AccelImageWriteBuffers[0],
 
740
                                    pGeode->Pitch);
 
741
#endif                          /* if !GX_USE_OFFSCRN_MEM */
 
742
    giwr.h -= blt_height;
 
743
    giwr.y += blt_height;
 
744
#endif                          /* if GX_ONE_LINE_AT_A_TIME */
 
745
}
 
746
#endif                          /* GX_SCANLINE_SUPPORT */
 
747
 
 
748
#if GX_CPU2SCREXP_SUPPORT
 
749
/*----------------------------------------------------------------------------
 
750
 * GXSetupForScanlineCPUToScreenColorExpandFill
 
751
 *
 
752
 * Description  :SetupFor/Subsequent CPUToScreenColorExpandFill and
 
753
 *               ColorExpandScanline routines provide an interface for
 
754
 *               doing expansion blits from source patterns stored in
 
755
 *               system memory.
 
756
 *
 
757
 *    Arg        Type     Comment
 
758
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
759
 *     fg         int     foreground color
 
760
 *     bg         int     -1 (transparent) or background color
 
761
 *    rop         int     unmapped raster operation
 
762
 * planemask     uint     -1 (copy) or pattern data
 
763
 *
 
764
 * Returns      :none.
 
765
 *---------------------------------------------------------------------------*/
 
766
 
 
767
static void
 
768
GXSetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrni,
 
769
                                             int fg, int bg, int rop,
 
770
                                             uint planemask)
 
771
{
 
772
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
773
    ulong srcpitch;
 
774
 
 
775
    DEBUGMSG(1, (0, X_INFO, "%s() fg %#x bg %#x rop %#x %#x\n",
 
776
                 __func__, fg, bg, rop, planemask));
 
777
    rop &= 0x0F;
 
778
    srcpitch = ((pGeode->Pitch + 31) >> 5) << 2;
 
779
#ifndef OPT_ACCEL
 
780
    gfx_set_solid_pattern(planemask);
 
781
    gfx_set_mono_source(bg, fg, bg == -1 ? 1 : 0);
 
782
    gfx_set_raster_operation(planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
783
    gfx2_set_source_stride(srcpitch);
 
784
    gfx2_set_destination_stride(pGeode->Pitch);
 
785
#else
 
786
    {
 
787
        unsigned int stride = (srcpitch << 16) | pGeode->Pitch;
 
788
        unsigned int ROP = BPP | (planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
789
 
 
790
        if (bg == -1)
 
791
            ROP |= MGP_RM_SRC_TRANS;
 
792
        BLT_MODE = ((ROP ^ (ROP >> 1)) & 0x55) != 0 ?
 
793
            MGP_BM_SRC_MONO | MGP_BM_SRC_FB | MGP_BM_DST_REQ :
 
794
            MGP_BM_SRC_MONO | MGP_BM_SRC_FB;
 
795
        GU2_WAIT_PENDING;
 
796
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
797
        WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
798
        WRITE_GP32(MGP_SRC_COLOR_BG, bg);
 
799
        WRITE_GP32(MGP_SRC_COLOR_FG, fg);
 
800
        WRITE_GP32(MGP_STRIDE, stride);
 
801
    }
 
802
#endif
 
803
}
 
804
 
 
805
/*----------------------------------------------------------------------------
 
806
 * GXSubsequentScanlineCPUToScreenColorExpandFill
 
807
 *
 
808
  Description  :see GXSetupForScanlineCPUToScreenColorExpandFill
 
809
 *
 
810
 * Parameters:
 
811
 *    Arg        Type     Comment
 
812
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
813
 *     x          int     destination x offset
 
814
 *     y          int     destination y offset
 
815
 *     w          int     fill area width (pixels)
 
816
 *     h          int     fill area height (pixels)
 
817
 *
 
818
 * Returns      :none
 
819
 *
 
820
 *---------------------------------------------------------------------------*/
 
821
static void
 
822
GXSubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrni,
 
823
                                               int x, int y, int w, int h,
 
824
                                               int skipleft)
 
825
{
 
826
    DEBUGMSG(1, (0, X_INFO, "%s() %d,%d %dx%d %d\n",
 
827
                 __func__, x, y, w, h, skipleft));
 
828
    gc2s.x = x;
 
829
    gc2s.y = y;
 
830
    gc2s.w = w;
 
831
    gc2s.h = h;
 
832
#ifdef OPT_ACCEL
 
833
    {
 
834
#if GX_ONE_LINE_AT_A_TIME
 
835
        unsigned int size = (gc2s.w << 16) | 1;
 
836
 
 
837
        GU2_WAIT_PENDING;
 
838
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
839
#else
 
840
        GeodeRec *pGeode = GEODEPTR(pScrni);
 
841
        unsigned int src = pGeode->AccelColorExpandBuffers[0] - pGeode->FBBase;
 
842
 
 
843
        GU2_WAIT_PENDING;
 
844
        WRITE_GP32(MGP_SRC_OFFSET, src);
 
845
#endif
 
846
    }
 
847
#endif
 
848
}
 
849
 
 
850
/*----------------------------------------------------------------------------
 
851
 * GXSubsequentColorExpandScanline
 
852
 *
 
853
 * Description  :see GXSetupForScanlineCPUToScreenColorExpandFill
 
854
 *
 
855
 *    Arg        Type     Comment
 
856
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
857
 *  bufno         int     scanline number in write group
 
858
 *
 
859
 * Returns      :none
 
860
 *----------------------------------------------------------------------------
 
861
 */
 
862
static void
 
863
GXSubsequentColorExpandScanline(ScrnInfoPtr pScrni, int bufno)
 
864
{
 
865
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
866
 
 
867
    DEBUGMSG(1, (0, X_INFO, "%s() %d\n", __func__, bufno));
 
868
#ifndef OPT_ACCEL
 
869
    {
 
870
#if GX_ONE_LINE_AT_A_TIME
 
871
        ulong offset = pGeode->AccelColorExpandBuffers[bufno] - pGeode->FBBase;
 
872
 
 
873
        gfx2_mono_expand_blt(offset, 0, 0, CALC_FBOFFSET(gc2s.x, gc2s.y),
 
874
                             gc2s.w, 1, 0);
 
875
        ++gc2s.y;
 
876
#else                           /* if GX_ONE_LINE_AT_A_TIME */
 
877
        ulong srcpitch;
 
878
        int blt_height;
 
879
 
 
880
        if ((blt_height = pGeode->NoOfImgBuffers) > gc2s.h)
 
881
            blt_height = gc2s.h;
 
882
        if (++bufno < blt_height)
 
883
            return;
 
884
 
 
885
        /* convert from bits to dwords */
 
886
        srcpitch = ((pGeode->Pitch + 31) >> 5) << 2;
 
887
        gfx2_mono_bitmap_to_screen_blt(0, 0, CALC_FBOFFSET(gc2s.x, gc2s.y),
 
888
                                       gc2s.w, blt_height,
 
889
                                       pGeode->AccelColorExpandBuffers[0],
 
890
                                       srcpitch);
 
891
        gc2s.h -= blt_height;
 
892
        gc2s.y += blt_height;
 
893
#endif                          /* if GX_ONE_LINE_AT_A_TIME */
 
894
    }
 
895
#else                           /* ifndef OPT_ACCEL */
 
896
    {
 
897
#if GX_ONE_LINE_AT_A_TIME
 
898
        unsigned int src =
 
899
            pGeode->AccelColorExpandBuffers[bufno] - pGeode->FBBase;
 
900
        unsigned int dst = CALC_FBOFFSET(gc2s.x, gc2s.y);
 
901
 
 
902
        ++gc2s.y;
 
903
        GU2_WAIT_PENDING;
 
904
        WRITE_GP32(MGP_SRC_OFFSET, src);
 
905
        WRITE_GP32(MGP_DST_OFFSET, dst);
 
906
        WRITE_GP16(MGP_BLT_MODE, BLT_MODE);
 
907
#else                           /* if GX_ONE_LINE_AT_A_TIME */
 
908
        unsigned int dst, size;
 
909
        int blt_height;
 
910
 
 
911
        GU2_WAIT_BUSY;
 
912
        if ((blt_height = pGeode->NoOfImgBuffers) > gc2s.h)
 
913
            blt_height = gc2s.h;
 
914
        if (++bufno < blt_height)
 
915
            return;
 
916
        dst = CALC_FBOFFSET(gc2s.x, gc2s.y);
 
917
        size = (gc2s.w << 16) | blt_height;
 
918
        gc2s.h -= blt_height;
 
919
        gc2s.y += blt_height;
 
920
        GU2_WAIT_PENDING;
 
921
        WRITE_GP32(MGP_DST_OFFSET, dst);
 
922
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
923
        WRITE_GP16(MGP_BLT_MODE, BLT_MODE);
 
924
#endif                          /* if GX_ONE_LINE_AT_A_TIME */
 
925
    }
 
926
#endif                          /* ifndef OPT_ACCEL */
 
927
}
 
928
#endif                          /* GX_CPU2SCREXP_SUPPORT */
 
929
 
 
930
#if GX_SCR2SCREXP_SUPPORT
 
931
/*----------------------------------------------------------------------------
 
932
 * GXSetupForScreenToScreenColorExpandFill
 
933
 *
 
934
 * Description  :SetupFor/Subsequent ScreenToScreenColorExpandFill and
 
935
 *               ColorExpandScanline routines provide an interface for
 
936
 *               doing expansion blits from source patterns stored in
 
937
 *               video memory.
 
938
 *
 
939
 *    Arg        Type     Comment
 
940
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
941
 *     fg         int     foreground color
 
942
 *     bg         int     -1 (transparent) or background color
 
943
 *    rop         int     unmapped raster operation
 
944
 * planemask     uint     -1 (copy) or pattern data
 
945
 *
 
946
 * Returns      :none.
 
947
 *---------------------------------------------------------------------------*/
 
948
 
 
949
static void
 
950
GXSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrni, int fg, int bg,
 
951
                                        int rop, uint planemask)
 
952
{
 
953
    DEBUGMSG(1, (0, X_INFO, "%s() fg %#x bg %#x rop %#x %#x\n",
 
954
                 __func__, fg, bg, rop, planemask));
 
955
    rop &= 0x0F;
 
956
#ifndef OPT_ACCEL
 
957
    {
 
958
        GeodeRec *pGeode = GEODEPTR(pScrni);
 
959
 
 
960
        gfx_set_solid_pattern(planemask);
 
961
        gfx_set_mono_source(bg, fg, bg == -1 ? 1 : 0);
 
962
        gfx_set_raster_operation(planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
963
        gfx2_set_source_stride(pGeode->Pitch);
 
964
        gfx2_set_destination_stride(pGeode->Pitch);
 
965
    }
 
966
#else
 
967
    {
 
968
        unsigned int ROP = BPP | (planemask == ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
969
 
 
970
        if (bg == -1)
 
971
            ROP |= MGP_RM_SRC_TRANS;
 
972
        BLT_MODE = ((ROP ^ (ROP >> 1)) & 0x55) != 0 ?
 
973
            MGP_BM_SRC_MONO | MGP_BM_SRC_FB | MGP_BM_DST_REQ :
 
974
            MGP_BM_SRC_MONO | MGP_BM_SRC_FB;
 
975
        GU2_WAIT_PENDING;
 
976
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
977
        WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
978
        WRITE_GP32(MGP_SRC_COLOR_BG, bg);
 
979
        WRITE_GP32(MGP_SRC_COLOR_FG, fg);
 
980
        WRITE_GP32(MGP_STRIDE, ACCEL_STRIDE);
 
981
    }
 
982
#endif
 
983
}
 
984
 
 
985
/*----------------------------------------------------------------------------
 
986
 * GXSubsequentScreenToScreenColorExpandFill
 
987
 *
 
988
 * Description  :see GXSetupForScreenToScreenColorExpandFill
 
989
 *
 
990
 * Parameters:
 
991
 *    Arg        Type     Comment
 
992
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
993
 *     x          int     destination x offset
 
994
 *     y          int     destination y offset
 
995
 *     w          int     fill area width (pixels)
 
996
 *     h          int     fill area height (pixels)
 
997
 * offset         int     initial x offset
 
998
 *
 
999
 * Returns      :none
 
1000
 *
 
1001
 *---------------------------------------------------------------------------*/
 
1002
static void
 
1003
GXSubsequentScreenToScreenColorExpandFill(ScrnInfoPtr pScrni,
 
1004
                                          int x, int y, int w, int h, int srcx,
 
1005
                                          int srcy, int offset)
 
1006
{
 
1007
    DEBUGMSG(1, (0, X_INFO, "%s() %d,%d %dx%d %d,%d %d\n",
 
1008
                 __func__, x, y, w, h, srcx, srcy, offset));
 
1009
#ifndef OPT_ACCEL
 
1010
    gfx2_mono_expand_blt(CALC_FBOFFSET(srcx, srcy), offset, 0,
 
1011
                         CALC_FBOFFSET(x, y), w, h, 0);
 
1012
#else
 
1013
    {
 
1014
        unsigned int src = (CALC_FBOFFSET(srcx,
 
1015
                                          srcy) +
 
1016
                            (offset >> 3)) | ((offset & 7) << 26);
 
1017
        unsigned int dst = CALC_FBOFFSET(x, y);
 
1018
        unsigned int size = (w << 16) | h;
 
1019
 
 
1020
        GU2_WAIT_PENDING;
 
1021
        WRITE_GP32(MGP_SRC_OFFSET, src);
 
1022
        WRITE_GP32(MGP_DST_OFFSET, dst);
 
1023
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
1024
        WRITE_GP16(MGP_BLT_MODE, BLT_MODE);
 
1025
    }
 
1026
#endif
 
1027
}
 
1028
#endif                          /* GX_SCR2SCREXP_SUPPORT */
 
1029
 
 
1030
#define VM_MAJOR_DEC 0
 
1031
#define VM_MINOR_DEC 0
 
1032
 
 
1033
static unsigned short vmode[] = {
 
1034
    VM_X_MAJOR | VM_MAJOR_INC | VM_MINOR_INC,
 
1035
    /* !XDECREASING !YDECREASING !YMAJOR */
 
1036
    VM_Y_MAJOR | VM_MAJOR_INC | VM_MINOR_INC,
 
1037
    /* !XDECREASING !YDECREASING  YMAJOR */
 
1038
    VM_X_MAJOR | VM_MAJOR_INC | VM_MINOR_DEC,
 
1039
    /* !XDECREASING  YDECREASING !YMAJOR */
 
1040
    VM_Y_MAJOR | VM_MAJOR_DEC | VM_MINOR_INC,
 
1041
    /* !XDECREASING  YDECREASING  YMAJOR */
 
1042
    VM_X_MAJOR | VM_MAJOR_DEC | VM_MINOR_INC,
 
1043
    /*  XDECREASING !YDECREASING !YMAJOR */
 
1044
    VM_Y_MAJOR | VM_MAJOR_INC | VM_MINOR_DEC,
 
1045
    /*  XDECREASING !YDECREASING  YMAJOR */
 
1046
    VM_X_MAJOR | VM_MAJOR_DEC | VM_MINOR_DEC,
 
1047
    /*  XDECREASING  YDECREASING !YMAJOR */
 
1048
    VM_Y_MAJOR | VM_MAJOR_DEC | VM_MINOR_DEC,
 
1049
    /*  XDECREASING  YDECREASING  YMAJOR */
 
1050
};
 
1051
 
 
1052
#if GX_BRES_LINE_SUPPORT
 
1053
/*----------------------------------------------------------------------------
 
1054
 * GXSetupForSolidLine
 
1055
 *
 
1056
 * Description  :SetupForSolidLine and Subsequent HorVertLine TwoPointLine
 
1057
 *               BresenhamLine provides an interface for drawing thin
 
1058
 *               solid lines.
 
1059
 *
 
1060
 *    Arg        Type     Comment
 
1061
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1062
 *   color        int     foreground fill color
 
1063
 *    rop         int     unmapped raster op
 
1064
 * planemask     uint     -1 (fill) or pattern data (not enabled)
 
1065
 *
 
1066
 * Returns              :none
 
1067
 *---------------------------------------------------------------------------*/
 
1068
static void
 
1069
GXSetupForSolidLine(ScrnInfoPtr pScrni, int color, int rop, uint planemask)
 
1070
{
 
1071
    DEBUGMSG(1, (0, X_INFO, "%s() %#x %#x %#x\n",
 
1072
                 __func__, color, rop, planemask));
 
1073
    rop &= 0x0F;
 
1074
#ifndef OPT_ACCEL
 
1075
    gfx_set_solid_pattern(color);
 
1076
    gfx_set_raster_operation(planemask == ~0U ? PDfn[rop] :
 
1077
                             (gfx_set_solid_source(planemask), PDfn_SM[rop]));
 
1078
#else
 
1079
    {
 
1080
        unsigned int ROP = BPP | (planemask == ~0U ? PDfn[rop] : PDfn_SM[rop]);
 
1081
 
 
1082
        BLT_MODE = ((ROP ^ (ROP >> 2)) & 0x33) == 0 ? MGP_BM_SRC_MONO : 0;
 
1083
        VEC_MODE = ((ROP ^ (ROP >> 1)) & 0x55) != 0 ? ((BLT_MODE |=
 
1084
                                                        MGP_BM_DST_REQ),
 
1085
                                                       MGP_VM_DST_REQ) : 0;
 
1086
        GU2_WAIT_PENDING;
 
1087
        WRITE_GP32(MGP_RASTER_MODE, ROP);
 
1088
        WRITE_GP32(MGP_PAT_COLOR_0, color);
 
1089
        WRITE_GP32(MGP_SRC_COLOR_FG, planemask);
 
1090
        WRITE_GP32(MGP_STRIDE, ACCEL_STRIDE);
 
1091
    }
 
1092
#endif
 
1093
}
 
1094
 
 
1095
/*---------------------------------------------------------------------------
 
1096
 * GXSubsequentSolidBresenhamLine
 
1097
 *
 
1098
 * Description  :see GXSetupForSolidLine
 
1099
 *
 
1100
 *    Arg        Type     Comment
 
1101
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1102
 *     x1         int     destination x offset
 
1103
 *     y1         int     destination y offset
 
1104
 * absmaj         int     Bresenman absolute major
 
1105
 * absmin         int     Bresenman absolute minor
 
1106
 *    err         int     Bresenman initial error term
 
1107
 *    len         int     length of the vector (pixels)
 
1108
 * octant         int     specifies sign and magnitude relationships
 
1109
 *                         used to determine axis of magor rendering
 
1110
 *                         and direction of vector progress.
 
1111
 *
 
1112
 * Returns      :none
 
1113
 *
 
1114
 *   - Window outlines on window move.
 
1115
 *   - x11perf: line segments (-line500).
 
1116
 *   - x11perf: line segments (-seg500).
 
1117
 *---------------------------------------------------------------------------*/
 
1118
static void
 
1119
GXSubsequentSolidBresenhamLine(ScrnInfoPtr pScrni, int x1, int y1,
 
1120
                               int absmaj, int absmin, int err, int len,
 
1121
                               int octant)
 
1122
{
 
1123
    long axial, diagn;
 
1124
 
 
1125
    DEBUGMSG(1, (0, X_INFO, "%s() %d,%d %d %d, %d %d, %d\n",
 
1126
                 __func__, x1, y1, absmaj, absmin, err, len, octant));
 
1127
    if (len <= 0)
 
1128
        return;
 
1129
    axial = absmin;
 
1130
    err += axial;
 
1131
    diagn = absmin - absmaj;
 
1132
#ifndef OPT_ACCEL
 
1133
    gfx_bresenham_line(x1, y1, len, err, axial, diagn, vmode[octant]);
 
1134
#else
 
1135
    {
 
1136
        unsigned int offset = CALC_FBOFFSET(x1, y1);
 
1137
        unsigned int vec_err = (axial << 16) | (unsigned short) diagn;
 
1138
        unsigned int vec_len = (len << 16) | (unsigned short) err;
 
1139
        unsigned int vec_mode = VEC_MODE | vmode[octant];
 
1140
 
 
1141
        GU2_WAIT_PENDING;
 
1142
        WRITE_GP32(MGP_DST_OFFSET, offset);
 
1143
        WRITE_GP32(MGP_VEC_ERR, vec_err);
 
1144
        WRITE_GP32(MGP_VEC_LEN, vec_len);
 
1145
        WRITE_GP32(MGP_VECTOR_MODE, vec_mode);
 
1146
    }
 
1147
#endif
 
1148
}
 
1149
 
 
1150
/*---------------------------------------------------------------------------
 
1151
 * GXSubsequentSolidTwoPointLine
 
1152
 *
 
1153
 * Description  :see GXSetupForSolidLine
 
1154
 *
 
1155
 *    Arg        Type     Comment
 
1156
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1157
 *     x0         int     destination x start offset
 
1158
 *     y0         int     destination y start offset
 
1159
 *     x1         int     destination x end offset
 
1160
 *     y1         int     destination y end offset
 
1161
 *  flags         int     OMIT_LAST, dont draw last pixel (not used)
 
1162
 *
 
1163
 * Returns      :none
 
1164
 *---------------------------------------------------------------------------*/
 
1165
static void
 
1166
GXSubsequentSolidTwoPointLine(ScrnInfoPtr pScrni, int x0, int y0,
 
1167
                              int x1, int y1, int flags)
 
1168
{
 
1169
    long dx, dy, dmaj, dmin, octant, bias;
 
1170
    long axial, diagn, err, len;
 
1171
 
 
1172
    DEBUGMSG(1, (0, X_INFO, "%s() %d,%d %d,%d, %#x\n",
 
1173
                 __func__, x0, y0, x1, y1, flags));
 
1174
 
 
1175
    if ((dx = x1 - x0) < 0)
 
1176
        dx = -dx;
 
1177
    if ((dy = y1 - y0) < 0)
 
1178
        dy = -dy;
 
1179
    if (dy >= dx) {
 
1180
        dmaj = dy;
 
1181
        dmin = dx;
 
1182
        octant = YMAJOR;
 
1183
    }
 
1184
    else {
 
1185
        dmaj = dx;
 
1186
        dmin = dy;
 
1187
        octant = 0;
 
1188
    }
 
1189
    len = dmaj;
 
1190
    if ((flags & OMIT_LAST) == 0)
 
1191
        ++len;
 
1192
    if (len <= 0)
 
1193
        return;
 
1194
    if (x1 < x0)
 
1195
        octant |= XDECREASING;
 
1196
    if (y1 < y0)
 
1197
        octant |= YDECREASING;
 
1198
 
 
1199
    axial = dmin << 1;
 
1200
    bias = miGetZeroLineBias(pScrni->pScreen);
 
1201
    err = axial - dmaj - ((bias >> octant) & 1);
 
1202
    diagn = (dmin - dmaj) << 1;
 
1203
 
 
1204
#ifndef OPT_ACCEL
 
1205
    gfx_bresenham_line(x0, y0, len, err, axial, diagn, vmode[octant]);
 
1206
#else
 
1207
    {
 
1208
        unsigned int offset = CALC_FBOFFSET(x0, y0);
 
1209
        unsigned int vec_err = (axial << 16) | (unsigned short) diagn;
 
1210
        unsigned int vec_len = (len << 16) | (unsigned short) err;
 
1211
        unsigned int vec_mode = VEC_MODE | vmode[octant];
 
1212
 
 
1213
        GU2_WAIT_PENDING;
 
1214
        WRITE_GP32(MGP_DST_OFFSET, offset);
 
1215
        WRITE_GP32(MGP_VEC_ERR, vec_err);
 
1216
        WRITE_GP32(MGP_VEC_LEN, vec_len);
 
1217
        WRITE_GP32(MGP_VECTOR_MODE, vec_mode);
 
1218
    }
 
1219
#endif
 
1220
}
 
1221
 
 
1222
/*---------------------------------------------------------------------------
 
1223
 * GXSubsequentSolidHorVertLine
 
1224
 *
 
1225
 * Description  :see GXSetupForSolidLine
 
1226
 *
 
1227
 *    Arg        Type     Comment
 
1228
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1229
 *     x          int     destination x offset
 
1230
 *     y          int     destination y offset
 
1231
 *    len         int     length of the vector (pixels)
 
1232
 *    dir         int     DEGREES_270 or DEGREES_0 line direction
 
1233
 *
 
1234
 * Sample application uses:
 
1235
 *   - Window outlines on window move.
 
1236
 *   - x11perf: line segments (-hseg500).
 
1237
 *   - x11perf: line segments (-vseg500).
 
1238
 *---------------------------------------------------------------------------
 
1239
 */
 
1240
static void
 
1241
GXSubsequentSolidHorVertLine(ScrnInfoPtr pScrni, int x, int y, int len, int dir)
 
1242
{
 
1243
    DEBUGMSG(1, (0, X_INFO, "%s() %d,%d %d %d\n", __func__, x, y, len, dir));
 
1244
#ifndef OPT_ACCEL
 
1245
    if (dir == DEGREES_0)
 
1246
        gfx_pattern_fill(x, y, len, 1);
 
1247
    else
 
1248
        gfx_pattern_fill(x, y, 1, len);
 
1249
#else
 
1250
    {
 
1251
        unsigned int offset = CALC_FBOFFSET(x, y);
 
1252
        unsigned int size =
 
1253
            dir == DEGREES_0 ? (len << 16) | 1 : (1 << 16) | len;
 
1254
        GU2_WAIT_PENDING;
 
1255
        WRITE_GP32(MGP_DST_OFFSET, offset);
 
1256
        WRITE_GP32(MGP_WID_HEIGHT, size);
 
1257
        WRITE_GP32(MGP_BLT_MODE, BLT_MODE);
 
1258
    }
 
1259
#endif
 
1260
}
 
1261
#endif                          /* GX_BRES_LINE_SUPPORT */
 
1262
 
 
1263
#if GX_DASH_LINE_SUPPORT
 
1264
/*----------------------------------------------------------------------------
 
1265
 * GXSetupForDashedLine
 
1266
 *
 
1267
 * Description  :SetupForDashedLine and Subsequent TwoPointLine
 
1268
 *               BresenhamLine provides an interface for drawing thin
 
1269
 *               dashed lines.
 
1270
 *
 
1271
 *    Arg        Type     Comment
 
1272
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1273
 *     fg         int     foreground fill color
 
1274
 *     bg         int     -1 (transp) or background fill color
 
1275
 *    rop         int     unmapped raster op
 
1276
 * planemask     uint     -1 (fill) or pattern data (not enabled)
 
1277
 *  length        int     pattern length (bits)
 
1278
 * pattern     uchar*     dash pattern mask
 
1279
 *
 
1280
 * Returns              :none
 
1281
 *---------------------------------------------------------------------------*/
 
1282
static void
 
1283
GXSetupForDashedLine(ScrnInfoPtr pScrn, int fg, int bg, int rop,
 
1284
                     unsigned int planemask, int length, unsigned char *pattern)
 
1285
{
 
1286
    int i, l, n, m;
 
1287
    CARD32 pat = *pattern;
 
1288
    CARD32 pat8x8[2];
 
1289
 
 
1290
    if (length <= 0)
 
1291
        return;
 
1292
    i = l = m = 0;
 
1293
    while (i < 2) {
 
1294
        m |= pat >> l;
 
1295
        l += length;
 
1296
        if ((n = l - 32) >= 0) {
 
1297
            pat8x8[i++] = m;
 
1298
            m = pat << (length - n);
 
1299
            l = n;
 
1300
        }
 
1301
    }
 
1302
    gdln.pat[0] = pat8x8[0];
 
1303
    gdln.pat[1] = pat8x8[1];
 
1304
    gdln.len = length;
 
1305
    gdln.fg = fg;
 
1306
    gdln.bg = bg;
 
1307
    rop &= 0x0F;
 
1308
    gfx_set_solid_pattern(0);
 
1309
    gfx_set_raster_operation(planemask == ~0U ? PDfn[rop] :
 
1310
                             (gfx_set_solid_source(planemask), PDfn_SM[rop]));
 
1311
}
 
1312
 
 
1313
/*---------------------------------------------------------------------------
 
1314
 * GXSubsequentDashedBresenhamLine
 
1315
 *
 
1316
 * Description:         This function is used to render a vector using the
 
1317
 *                      specified bresenham parameters.
 
1318
 *
 
1319
 * Parameters:
 
1320
 *              pScrni:         Screen handler pointer having screen information.
 
1321
 *      x1:             Specifies the starting x position
 
1322
 *      y1:             Specifies starting y possition
 
1323
 *      absmaj:         Specfies the Bresenman absolute major.
 
1324
 *              absmin:         Specfies the Bresenman absolute minor.
 
1325
 *              err:            Specifies the bresenham err term.
 
1326
 *              len:            Specifies the length of the vector interms of pixels.
 
1327
 *              octant:         not used in this function,may be added for standard
 
1328
 *                      interface.
 
1329
 *
 
1330
 * Returns:                     none
 
1331
 *
 
1332
 * Comments:            none
 
1333
 *
 
1334
 * Sample application uses:
 
1335
 *   - Window outlines on window move.
 
1336
 *   - x11perf: line segments (-line500).
 
1337
 *   - x11perf: line segments (-seg500).
 
1338
 *----------------------------------------------------------------------------
 
1339
 */
 
1340
static void
 
1341
GXSubsequentDashedBresenhamLine(ScrnInfoPtr pScrni,
 
1342
                                int x1, int y1, int absmaj, int absmin,
 
1343
                                int err, int len, int octant, int phase)
 
1344
{
 
1345
    int i, n;
 
1346
    int axial, diagn;
 
1347
    int trans = (gdln.bg == -1);
 
1348
    unsigned long pat8x8[2];
 
1349
 
 
1350
    //ErrorF("BLine %d, %d, %d, %d, %d, %d, %d\n" x1, y1, absmaj, absmin,
 
1351
    //err, len, octant);
 
1352
 
 
1353
    i = phase >= 32 ? (phase -= 32, 1) : 0;
 
1354
    n = 32 - phase;
 
1355
    pat8x8[0] =
 
1356
        ((gdln.pat[i] >> phase) & ((1UL << n) - 1)) | (gdln.pat[1 - i] << n);
 
1357
    pat8x8[1] =
 
1358
        ((gdln.pat[1 - i] >> phase) & ((1UL << n) - 1)) | (gdln.pat[i] << n);
 
1359
    axial = absmin;
 
1360
    err += axial;
 
1361
    diagn = absmin - absmaj;
 
1362
    gfx_set_mono_pattern(gdln.bg, gdln.fg, pat8x8[0], pat8x8[1], trans);
 
1363
    gfx2_set_pattern_origin(x1, y1);
 
1364
    gfx2_bresenham_line(CALC_FBOFFSET(x1, y1), len, err, axial, diagn,
 
1365
                        vmode[octant]);
 
1366
}
 
1367
 
 
1368
/*---------------------------------------------------------------------------
 
1369
 * GXSubsequentDashedTwoPointLine
 
1370
 *
 
1371
 * Description  :see GXSetupForDashedLine
 
1372
 *
 
1373
 *    Arg        Type     Comment
 
1374
 *  pScrni   ScrnInfoPtr  pointer to Screeen info
 
1375
 *     x0         int     destination x start offset
 
1376
 *     y0         int     destination y start offset
 
1377
 *     x1         int     destination x end offset
 
1378
 *     y1         int     destination y end offset
 
1379
 *  flags         int     OMIT_LAST, dont draw last pixel (not used)
 
1380
 *  phase         int     initial pattern offset at x1,y1
 
1381
 *
 
1382
 * Returns      :none
 
1383
 *---------------------------------------------------------------------------*/
 
1384
static void
 
1385
GXSubsequentDashedTwoPointLine(ScrnInfoPtr pScrni, int x0, int y0,
 
1386
                               int x1, int y1, int flags, int phase)
 
1387
{
 
1388
    int i, n;
 
1389
    long dx, dy, dmaj, dmin, octant, bias;
 
1390
    long axial, diagn, err, len, pat8x8[2];
 
1391
 
 
1392
    //ErrorF("GXSubsequentDashedTwoPointLine() %d,%d %d,%d, %#x %d\n",
 
1393
    //   x0, y0, x1, y1, flags, phase);
 
1394
 
 
1395
    i = phase >= 32 ? (phase -= 32, 1) : 0;
 
1396
    n = 32 - phase;
 
1397
    pat8x8[0] =
 
1398
        ((gdln.pat[i] >> phase) & ((1UL << n) - 1)) | (gdln.pat[1 - i] << n);
 
1399
    pat8x8[1] =
 
1400
        ((gdln.pat[1 - i] >> phase) & ((1UL << n) - 1)) | (gdln.pat[i] << n);
 
1401
 
 
1402
    if ((dx = x1 - x0) < 0)
 
1403
        dx = -dx;
 
1404
    if ((dy = y1 - y0) < 0)
 
1405
        dy = -dy;
 
1406
    if (dy >= dx) {
 
1407
        dmaj = dy;
 
1408
        dmin = dx;
 
1409
        octant = YMAJOR;
 
1410
    }
 
1411
    else {
 
1412
        dmaj = dx;
 
1413
        dmin = dy;
 
1414
        octant = 0;
 
1415
    }
 
1416
    len = dmaj;
 
1417
    if ((flags & OMIT_LAST) == 0)
 
1418
        ++len;
 
1419
    if (len <= 0)
 
1420
        return;
 
1421
    if (x1 < x0)
 
1422
        octant |= XDECREASING;
 
1423
    if (y1 < y0)
 
1424
        octant |= YDECREASING;
 
1425
 
 
1426
    axial = dmin << 1;
 
1427
    bias = miGetZeroLineBias(pScrni->pScreen);
 
1428
    err = axial - dmaj - ((bias >> octant) & 1);
 
1429
    diagn = (dmin - dmaj) << 1;
 
1430
 
 
1431
    gfx2_set_pattern_origin(x0, y0);
 
1432
    gfx2_bresenham_line(CALC_FBOFFSET(x0, y0), len, err, axial, diagn,
 
1433
                        vmode[octant]);
 
1434
 
 
1435
}
 
1436
#endif                          /* GX_DASH_LINE_SUPPORT */
 
1437
 
 
1438
#if GX_WRITE_PIXMAP_SUPPORT
 
1439
static void
 
1440
GXWritePixmap(ScrnInfoPtr pScrni, int x, int y, int w, int h,
 
1441
              unsigned char *src, int srcwidth, int rop, unsigned int planemask,
 
1442
              int trans, int bpp, int depth)
 
1443
{
 
1444
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
1445
 
 
1446
    //ErrorF("GXWritePixmap() %d,%d %dx%d, s%#x sp%d %#x %#x %#x %d %d\n",
 
1447
    //    x, y, w, h, src, srcwidth, rop, planemask, trans, bpp, depth);
 
1448
 
 
1449
    if (bpp == pScrni->bitsPerPixel) {
 
1450
        rop &= 0x0F;
 
1451
        if (rop == GXcopy && trans == -1) {
 
1452
            gfx_wait_until_idle();
 
1453
            geode_memory_to_screen_blt((unsigned long) src,
 
1454
                                       (unsigned long) FBADDR(x, y), srcwidth,
 
1455
                                       pGeode->Pitch, w, h, bpp);
 
1456
        }
 
1457
        else {
 
1458
            gfx_set_solid_pattern(planemask);
 
1459
            gfx_set_raster_operation(planemask ==
 
1460
                                     ~0U ? SDfn[rop] : SDfn_PM[rop]);
 
1461
            if (trans != -1)
 
1462
                gfx_color_bitmap_to_screen_xblt(0, 0, x, y, w, h, src,
 
1463
                                                srcwidth, trans);
 
1464
            else
 
1465
                gfx_color_bitmap_to_screen_blt(0, 0, x, y, w, h, src, srcwidth);
 
1466
            SET_SYNC_FLAG(pGeode->AccelInfoRec);
 
1467
        }
 
1468
    }
 
1469
    else
 
1470
        pGeode->WritePixmap(pScrni, x, y, w, h, src, srcwidth, rop, planemask,
 
1471
                            trans, bpp, depth);
 
1472
}
 
1473
#endif                          /* if GX_WRITE_PIXMAP_SUPPORT */
 
1474
 
 
1475
#if XF86EXA
 
1476
 
 
1477
static void
 
1478
amd_gx_exa_WaitMarker(ScreenPtr pScreen, int Marker)
 
1479
{
 
1480
    GU2_WAIT_BUSY;
 
1481
}
 
1482
 
 
1483
static void
 
1484
amd_gx_exa_Done(PixmapPtr p)
 
1485
{
 
1486
}
 
1487
 
 
1488
static Bool
 
1489
amd_gx_exa_UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h,
 
1490
                          char *src, int src_pitch)
 
1491
{
 
1492
    char *dst = pDst->devPrivate.ptr;
 
1493
    int dst_pitch = exaGetPixmapPitch(pDst);
 
1494
    int bpp = pDst->drawable.bitsPerPixel;
 
1495
 
 
1496
    dst += y * dst_pitch + x * (bpp >> 3);
 
1497
    GU2_WAIT_BUSY;
 
1498
    geode_memory_to_screen_blt((unsigned long) src, (unsigned long) dst,
 
1499
                               src_pitch, dst_pitch, w, h, bpp);
 
1500
    return TRUE;
 
1501
}
 
1502
 
 
1503
static Bool
 
1504
amd_gx_exa_DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
 
1505
                              char *dst, int dst_pitch)
 
1506
{
 
1507
    char *src = pSrc->devPrivate.ptr;
 
1508
    int src_pitch = exaGetPixmapPitch(pSrc);
 
1509
    int bpp = pSrc->drawable.bitsPerPixel;
 
1510
 
 
1511
    src += (y * src_pitch) + (x * (bpp >> 3));
 
1512
    GU2_WAIT_BUSY;
 
1513
    geode_memory_to_screen_blt((unsigned long) src, (unsigned long) dst,
 
1514
                               src_pitch, dst_pitch, w, h, bpp);
 
1515
    return TRUE;
 
1516
}
 
1517
 
 
1518
/* Solid */
 
1519
 
 
1520
static Bool
 
1521
amd_gx_exa_PrepareSolid(PixmapPtr pxMap, int alu, Pixel planemask, Pixel fg)
 
1522
{
 
1523
    int dstPitch = exaGetPixmapPitch(pxMap);
 
1524
    unsigned int ROP = amd_gx_BppToRasterMode(pxMap->drawable.bitsPerPixel)
 
1525
        | (planemask == ~0U ? SDfn[alu] : SDfn_PM[alu]);
 
1526
 
 
1527
    //  FIXME: this should go away -- workaround for the blockparty icon corruption
 
1528
    //if (pxMap->drawable.bitsPerPixel == 32)
 
1529
    //  return FALSE;
 
1530
 
 
1531
    BLT_MODE = ((ROP ^ (ROP >> 2)) & 0x33) == 0 ? MGP_BM_SRC_MONO : 0;
 
1532
    if (((ROP ^ (ROP >> 1)) & 0x55) != 0)
 
1533
        BLT_MODE |= MGP_BM_DST_REQ;
 
1534
    //ErrorF("amd_gx_exa_PrepareSolid(%#x,%#x,%#x - ROP=%x,BLT_MODE=%x)\n", alu, planemask, fg, ROP, BLT_MODE);
 
1535
    GU2_WAIT_PENDING;
 
1536
    WRITE_GP32(MGP_RASTER_MODE, ROP);
 
1537
    WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
1538
    WRITE_GP32(MGP_SRC_COLOR_FG, fg);
 
1539
    WRITE_GP32(MGP_STRIDE, dstPitch);
 
1540
    return TRUE;
 
1541
}
 
1542
 
 
1543
static void
 
1544
amd_gx_exa_Solid(PixmapPtr pxMap, int x1, int y1, int x2, int y2)
 
1545
{
 
1546
    int bpp = (pxMap->drawable.bitsPerPixel + 7) / 8;
 
1547
    int pitch = exaGetPixmapPitch(pxMap);
 
1548
    unsigned int offset = exaGetPixmapOffset(pxMap) + pitch * y1 + bpp * x1;
 
1549
    unsigned int size = ((x2 - x1) << 16) | (y2 - y1);
 
1550
 
 
1551
    //ErrorF("amd_gx_exa_Solid() at %d,%d %d,%d - offset=%d, bpp=%d\n", x1, y1, x2, y2, offset, bpp);
 
1552
 
 
1553
    GU2_WAIT_PENDING;
 
1554
    WRITE_GP32(MGP_DST_OFFSET, offset);
 
1555
    WRITE_GP32(MGP_WID_HEIGHT, size);
 
1556
    WRITE_GP32(MGP_BLT_MODE, BLT_MODE);
 
1557
}
 
1558
 
 
1559
/* Copy */
 
1560
 
 
1561
static Bool
 
1562
amd_gx_exa_PrepareCopy(PixmapPtr pxSrc, PixmapPtr pxDst, int dx, int dy,
 
1563
                       int alu, Pixel planemask)
 
1564
{
 
1565
    GeodeRec *pGeode = GEODEPTR_FROM_PIXMAP(pxDst);
 
1566
    int dstPitch = exaGetPixmapPitch(pxDst);
 
1567
    unsigned int ROP;
 
1568
 
 
1569
    /* Punt if the color formats aren't the same */
 
1570
 
 
1571
    if (pxSrc->drawable.bitsPerPixel != pxDst->drawable.bitsPerPixel)
 
1572
        return FALSE;
 
1573
 
 
1574
    //ErrorF("amd_gx_exa_PrepareCopy() dx%d dy%d alu %#x %#x\n",
 
1575
    //  dx, dy, alu, planemask);
 
1576
 
 
1577
    pGeode->cpySrcOffset = exaGetPixmapOffset(pxSrc);
 
1578
    pGeode->cpySrcPitch = exaGetPixmapPitch(pxSrc);
 
1579
    pGeode->cpySrcBpp = (pxSrc->drawable.bitsPerPixel + 7) / 8;
 
1580
    pGeode->cpyDx = dx;
 
1581
    pGeode->cpyDy = dy;
 
1582
    ROP = amd_gx_BppToRasterMode(pxSrc->drawable.bitsPerPixel) |
 
1583
        (planemask == ~0U ? SDfn[alu] : SDfn_PM[alu]);
 
1584
 
 
1585
    BLT_MODE = ((ROP ^ (ROP >> 1)) & 0x55) != 0 ?
 
1586
        MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1587
    GU2_WAIT_PENDING;
 
1588
    WRITE_GP32(MGP_RASTER_MODE, ROP);
 
1589
    WRITE_GP32(MGP_PAT_COLOR_0, planemask);
 
1590
    WRITE_GP32(MGP_SRC_COLOR_FG, ~0);
 
1591
    WRITE_GP32(MGP_SRC_COLOR_BG, ~0);
 
1592
    WRITE_GP32(MGP_STRIDE, (pGeode->cpySrcPitch << 16) | dstPitch);
 
1593
    return TRUE;
 
1594
}
 
1595
 
 
1596
static void
 
1597
amd_gx_exa_Copy(PixmapPtr pxDst, int srcX, int srcY, int dstX, int dstY,
 
1598
                int w, int h)
 
1599
{
 
1600
    GeodeRec *pGeode = GEODEPTR_FROM_PIXMAP(pxDst);
 
1601
    int dstBpp = (pxDst->drawable.bitsPerPixel + 7) / 8;
 
1602
    int dstPitch = exaGetPixmapPitch(pxDst);
 
1603
    unsigned int srcOffset =
 
1604
        pGeode->cpySrcOffset + (pGeode->cpySrcPitch * srcY) +
 
1605
        (pGeode->cpySrcBpp * srcX);
 
1606
    unsigned int dstOffset =
 
1607
        exaGetPixmapOffset(pxDst) + (dstPitch * dstY) + (dstBpp * dstX);
 
1608
    unsigned int size = (w << 16) | h;
 
1609
    unsigned int blt_mode = BLT_MODE;
 
1610
 
 
1611
    //ErrorF("amd_gx_exa_Copy() from %d,%d to %d,%d %dx%d\n", srcX, srcY,
 
1612
    //   dstX, dstY, w, h);
 
1613
 
 
1614
    if (pGeode->cpyDx < 0) {
 
1615
        srcOffset += w * pGeode->cpySrcBpp - 1;
 
1616
        dstOffset += w * dstBpp - 1;
 
1617
        blt_mode |= MGP_BM_NEG_XDIR;
 
1618
    }
 
1619
    if (pGeode->cpyDy < 0) {
 
1620
        srcOffset += (h - 1) * pGeode->cpySrcPitch;
 
1621
        dstOffset += (h - 1) * dstPitch;
 
1622
        blt_mode |= MGP_BM_NEG_YDIR;
 
1623
    }
 
1624
    GU2_WAIT_PENDING;
 
1625
    WRITE_GP32(MGP_SRC_OFFSET, srcOffset);
 
1626
    WRITE_GP32(MGP_DST_OFFSET, dstOffset);
 
1627
    WRITE_GP32(MGP_WID_HEIGHT, size);
 
1628
    WRITE_GP16(MGP_BLT_MODE, blt_mode);
 
1629
}
 
1630
 
 
1631
/* A=SRC, B=DST */
 
1632
#define SRC_DST 0
 
1633
/* B=SRC, A=DST */
 
1634
#define DST_SRC MGP_RM_DEST_FROM_CHAN_A
 
1635
/* A*alpha + B*0         */
 
1636
#define Aa_B0   MGP_RM_ALPHA_TIMES_A
 
1637
/* A*0     + B*(1-alpha) */
 
1638
#define A0_B1a  MGP_RM_BETA_TIMES_B
 
1639
/* A*1     + B*(1-alpha) */
 
1640
#define A1_B1a  MGP_RM_A_PLUS_BETA_B
 
1641
/* A*alpha + B*(1-alpha) */
 
1642
#define Aa_B1a  MGP_RM_ALPHA_A_PLUS_BETA_B
 
1643
/* alpha from A */
 
1644
#define a_A MGP_RM_SELECT_ALPHA_A
 
1645
/* alpha from B */
 
1646
#define a_B MGP_RM_SELECT_ALPHA_B
 
1647
/* alpha from const */
 
1648
#define a_C MGP_RM_SELECT_ALPHA_R
 
1649
/* alpha = 1 */
 
1650
#define a_1 MGP_RM_SELECT_ALPHA_1
 
1651
 
 
1652
#define MGP_RM_ALPHA_TO_ARGB (MGP_RM_ALPHA_TO_ALPHA | MGP_RM_ALPHA_TO_RGB)
 
1653
#define gxPictOpMAX PictOpAdd   /* highest accelerated op */
 
1654
 
 
1655
unsigned int amd_gx_exa_alpha_ops[] =
 
1656
/*    A   B      OP     AS           const = 0 */
 
1657
{
 
1658
    (SRC_DST | Aa_B0 | a_C), 0, /* clear    (src*0) */
 
1659
    (SRC_DST | Aa_B0 | a_1), 0, /* src      (src*1) */
 
1660
    (DST_SRC | Aa_B0 | a_1), 0, /* dst      (dst*1) */
 
1661
    (SRC_DST | A1_B1a | a_A), 0,        /* src-over (src*1 + dst(1-A)) */
 
1662
    (DST_SRC | A1_B1a | a_A), 0,        /* dst-over (dst*1 + src(1-B)) */
 
1663
    (SRC_DST | Aa_B0 | a_B), 0, /* src-in   (src*B) */
 
1664
    (DST_SRC | Aa_B0 | a_B), 0, /* dst-in   (dst*A) */
 
1665
    (DST_SRC | A0_B1a | a_A), 0,        /* src-out  (src*(1-B)) */
 
1666
    (SRC_DST | A0_B1a | a_A), 0,        /* dst-out  (dst*(1-A)) */
 
1667
/* pass1 (SRC=dst DST=scr=src), pass2 (SRC=src, DST=dst) */
 
1668
    (DST_SRC | Aa_B0 | a_B),    /* srcatop  (src*B) */
 
1669
    (SRC_DST | A0_B1a | a_A),   /*                  + (dst(1-A)) */
 
1670
    (SRC_DST | Aa_B0 | a_B),    /* dstatop  (dst*A) */
 
1671
    (DST_SRC | A0_B1a | a_A),   /*                  + (src(1-B) */
 
1672
    (SRC_DST | A0_B1a | a_A),   /* xor      (src*(1-B) */
 
1673
    (SRC_DST | A0_B1a | a_A),   /*                  + (dst(1-A) */
 
1674
    (SRC_DST | A1_B1a | a_C), 0,        /* add      (src*1 + dst*1) */
 
1675
};
 
1676
 
 
1677
typedef struct {
 
1678
    int exa_fmt;
 
1679
    int bpp;
 
1680
    int gx_fmt;
 
1681
    int alpha_bits;
 
1682
} amd_gx_exa_fmt_t;
 
1683
 
 
1684
amd_gx_exa_fmt_t amd_gx_exa_fmts[] = {
 
1685
    {PICT_a8r8g8b8, 32, MGP_RM_BPPFMT_8888, 8},
 
1686
    {PICT_x8r8g8b8, 32, MGP_RM_BPPFMT_8888, 0},
 
1687
    {PICT_a4r4g4b4, 16, MGP_RM_BPPFMT_4444, 4},
 
1688
    {PICT_a1r5g5b5, 16, MGP_RM_BPPFMT_1555, 1},
 
1689
    {PICT_r5g6b5, 16, MGP_RM_BPPFMT_565, 0},
 
1690
    {PICT_r3g3b2, 8, MGP_RM_BPPFMT_332, 0},
 
1691
};
 
1692
 
 
1693
static amd_gx_exa_fmt_t *
 
1694
amd_gx_exa_check_format(PicturePtr p)
 
1695
{
 
1696
    int i;
 
1697
    int bpp = p->pDrawable ? p->pDrawable->bitsPerPixel : 0;
 
1698
    amd_gx_exa_fmt_t *fp = &amd_gx_exa_fmts[0];
 
1699
 
 
1700
    for (i = sizeof(amd_gx_exa_fmts) / sizeof(amd_gx_exa_fmts[0]); --i >= 0;
 
1701
         ++fp) {
 
1702
        if (fp->bpp < bpp)
 
1703
            return NULL;
 
1704
        if (fp->bpp != bpp)
 
1705
            continue;
 
1706
        if (fp->exa_fmt == p->format)
 
1707
            break;
 
1708
    }
 
1709
    return i < 0 ? NULL : fp;
 
1710
}
 
1711
 
 
1712
/* Composite */
 
1713
 
 
1714
static Bool
 
1715
amd_gx_exa_CheckComposite(int op, PicturePtr pSrc, PicturePtr pMsk,
 
1716
                          PicturePtr pDst)
 
1717
{
 
1718
    GeodeRec *pGeode = GEODEPTR_FROM_PICTURE(pDst);
 
1719
 
 
1720
    if (op > gxPictOpMAX)
 
1721
        return FALSE;
 
1722
    if (pMsk)
 
1723
        return FALSE;
 
1724
    if (usesPasses(op) && pGeode->exaBfrSz == 0)
 
1725
        return FALSE;
 
1726
    if (pSrc->filter != PictFilterNearest &&
 
1727
        pSrc->filter != PictFilterFast &&
 
1728
        pSrc->filter != PictFilterGood && pSrc->filter != PictFilterBest)
 
1729
        return FALSE;
 
1730
    if (pSrc->repeat)
 
1731
        return FALSE;
 
1732
    if (pSrc->transform)
 
1733
        return FALSE;
 
1734
    return TRUE;
 
1735
}
 
1736
 
 
1737
static Bool
 
1738
amd_gx_exa_PrepareComposite(int op, PicturePtr pSrc, PicturePtr pMsk,
 
1739
                            PicturePtr pDst, PixmapPtr pxSrc, PixmapPtr pxMsk,
 
1740
                            PixmapPtr pxDst)
 
1741
{
 
1742
    int srcPitch;
 
1743
 
 
1744
    GeodeRec *pGeode = GEODEPTR_FROM_PIXMAP(pxDst);
 
1745
    amd_gx_exa_fmt_t *sfp, *dfp;
 
1746
 
 
1747
    //ErrorF("amd_gx_exa_PrepareComposite()\n");
 
1748
 
 
1749
    if ((sfp = amd_gx_exa_check_format(pSrc)) == NULL)
 
1750
        return FALSE;
 
1751
    if (sfp->alpha_bits == 0 && usesSrcAlpha(op))
 
1752
        return FALSE;
 
1753
    if ((dfp = amd_gx_exa_check_format(pDst)) == NULL)
 
1754
        return FALSE;
 
1755
    if (dfp->alpha_bits == 0 && usesDstAlpha(op))
 
1756
        return FALSE;
 
1757
    if (sfp->gx_fmt != dfp->gx_fmt)
 
1758
        return FALSE;
 
1759
    srcPitch = exaGetPixmapPitch(pxSrc);
 
1760
    if (usesPasses(op) && srcPitch > pGeode->exaBfrSz)
 
1761
        return FALSE;
 
1762
    pGeode->cmpSrcPitch = srcPitch;
 
1763
    pGeode->cmpOp = op;
 
1764
    pGeode->cmpSrcOffset = exaGetPixmapOffset(pxSrc);
 
1765
    pGeode->cmpSrcBpp = (pxSrc->drawable.bitsPerPixel + 7) / 8;
 
1766
    pGeode->cmpSrcFmt = sfp->gx_fmt;
 
1767
    pGeode->cmpDstFmt = dfp->gx_fmt | (dfp->alpha_bits == 0 ?
 
1768
                                       MGP_RM_ALPHA_TO_RGB :
 
1769
                                       MGP_RM_ALPHA_TO_ARGB);
 
1770
    return TRUE;
 
1771
}
 
1772
 
 
1773
static void
 
1774
amd_gx_exa_Composite(PixmapPtr pxDst, int srcX, int srcY, int maskX,
 
1775
                     int maskY, int dstX, int dstY, int width, int height)
 
1776
{
 
1777
    int op, current_line, max_lines, lines, pass, scratchPitch;
 
1778
    unsigned int srcOffset, srcOfs = 0, srcPitch, srcPch = 0, srcBpp;
 
1779
    unsigned int dstOffset, dstOfs = 0, dstPitch, dstPch = 0, dstBpp;
 
1780
    unsigned int sizes, strides, blt_mode = 0, rop = 0;
 
1781
    GeodeRec *pGeode = GEODEPTR_FROM_PIXMAP(pxDst);
 
1782
 
 
1783
    //ErrorF("amd_gx_exa_Composite() from %d,%d to %d,%d %dx%d\n",
 
1784
    //    srcX, srcY, dstX, dstY, width, height);
 
1785
 
 
1786
    op = pGeode->cmpOp;
 
1787
    if (usesPasses(op)) {
 
1788
        int cacheLineSz = 32;
 
1789
        int cachelines =
 
1790
            (width * pGeode->cmpSrcBpp + cacheLineSz - 1) / cacheLineSz;
 
1791
        scratchPitch = cachelines * cacheLineSz;
 
1792
        if (scratchPitch > pGeode->cmpSrcPitch)
 
1793
            scratchPitch = pGeode->cmpSrcPitch;
 
1794
        max_lines = pGeode->exaBfrSz / scratchPitch;
 
1795
    }
 
1796
    else {
 
1797
        scratchPitch = 0;
 
1798
        max_lines = height;
 
1799
    }
 
1800
 
 
1801
    dstBpp = (pxDst->drawable.bitsPerPixel + 7) / 8;
 
1802
    dstPitch = exaGetPixmapPitch(pxDst);
 
1803
    dstOffset = exaGetPixmapOffset(pxDst) + dstPitch * dstY + dstBpp * dstX;
 
1804
    srcBpp = pGeode->cmpSrcBpp;
 
1805
    srcPitch = pGeode->cmpSrcPitch;
 
1806
    srcOffset = pGeode->cmpSrcOffset + srcPitch * srcY + srcBpp * srcX;
 
1807
 
 
1808
    current_line = pass = 0;
 
1809
    while (current_line < height) {
 
1810
        if (usesPasses(op)) {
 
1811
            lines = height - current_line;
 
1812
            if (lines > max_lines)
 
1813
                lines = max_lines;
 
1814
            switch (pass) {
 
1815
            case 0:            /* copy src to scratch */
 
1816
                srcPch = srcPitch;
 
1817
                srcOfs = srcOffset + current_line * srcPch;
 
1818
                dstPch = scratchPitch;
 
1819
                dstOfs = pGeode->exaBfrOffset;
 
1820
                rop = pGeode->cmpSrcFmt | MGP_RM_ALPHA_TO_ARGB;
 
1821
                rop |= amd_gx_exa_alpha_ops[PictOpSrc * 2];
 
1822
                blt_mode = usesChanB0(PictOpSrc) ?
 
1823
                    MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1824
                ++pass;
 
1825
                break;
 
1826
            case 1:            /* pass1 */
 
1827
                srcPch = dstPitch;
 
1828
                srcOfs = dstOffset + current_line * srcPch;
 
1829
                dstPch = scratchPitch;
 
1830
                dstOfs = pGeode->exaBfrOffset;
 
1831
                rop = pGeode->cmpSrcFmt | MGP_RM_ALPHA_TO_ARGB;
 
1832
                rop |= amd_gx_exa_alpha_ops[op * 2];
 
1833
                blt_mode = usesChanB1(op) ?
 
1834
                    MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1835
                ++pass;
 
1836
                break;
 
1837
            case 2:            /* pass2 */
 
1838
                srcPch = srcPitch;
 
1839
                srcOfs = srcOffset + current_line * srcPch;
 
1840
                dstPch = dstPitch;
 
1841
                dstOfs = dstOffset + current_line * dstPch;
 
1842
                rop = pGeode->cmpSrcFmt | MGP_RM_ALPHA_TO_ARGB;
 
1843
                rop |= amd_gx_exa_alpha_ops[op * 2 + 1];
 
1844
                blt_mode = usesChanB2(op) ?
 
1845
                    MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1846
                ++pass;
 
1847
                break;
 
1848
            case 3:            /* add */
 
1849
                srcPch = scratchPitch;
 
1850
                srcOfs = pGeode->exaBfrOffset;
 
1851
                dstPch = dstPitch;
 
1852
                dstOfs = dstOffset + current_line * dstPch;
 
1853
                rop = pGeode->cmpDstFmt;
 
1854
                rop |= amd_gx_exa_alpha_ops[PictOpAdd * 2];
 
1855
                blt_mode = usesChanB0(PictOpAdd) ?
 
1856
                    MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1857
                current_line += lines;
 
1858
                pass = 0;
 
1859
                break;
 
1860
            }
 
1861
            strides = (srcPch << 16) | dstPch;
 
1862
        }
 
1863
        else {                  /* not multi pass */
 
1864
            srcOfs = srcOffset;
 
1865
            dstOfs = dstOffset;
 
1866
            current_line = lines = height;
 
1867
            strides = (srcPitch << 16) | dstPitch;
 
1868
            rop = pGeode->cmpDstFmt | amd_gx_exa_alpha_ops[op * 2];
 
1869
            blt_mode = usesChanB0(op) ?
 
1870
                MGP_BM_SRC_FB | MGP_BM_DST_REQ : MGP_BM_SRC_FB;
 
1871
        }
 
1872
        sizes = (width << 16) | lines;
 
1873
        if (srcOfs < dstOfs) {
 
1874
            srcOfs += (lines - 1) * srcPitch + width * srcBpp - 1;
 
1875
            dstOfs += (lines - 1) * dstPitch + width * dstBpp - 1;
 
1876
            blt_mode |= MGP_BM_NEG_XDIR | MGP_BM_NEG_YDIR;
 
1877
        }
 
1878
        GU2_WAIT_PENDING;
 
1879
        WRITE_GP32(MGP_RASTER_MODE, rop);
 
1880
        WRITE_GP32(MGP_SRC_OFFSET, srcOfs);
 
1881
        WRITE_GP32(MGP_DST_OFFSET, dstOfs);
 
1882
        WRITE_GP32(MGP_WID_HEIGHT, sizes);
 
1883
        WRITE_GP32(MGP_STRIDE, strides);
 
1884
        WRITE_GP16(MGP_BLT_MODE, blt_mode);
 
1885
    }
 
1886
}
 
1887
#endif                          /* #if XF86EXA */
 
1888
 
 
1889
/*----------------------------------------------------------------------------
 
1890
 * GXAccelInit.
 
1891
 *
 
1892
 * Description: This function sets up the supported acceleration routines and
 
1893
 *              appropriate flags.
 
1894
 *
 
1895
 * Parameters:
 
1896
 *      pScrn:  Screeen pointer structure.
 
1897
 *
 
1898
 * Returns:             TRUE on success and FALSE on Failure
 
1899
 *
 
1900
 * Comments:    This function is called in GXScreenInit in
 
1901
 *              geode_driver.c to set  * the acceleration.
 
1902
 *----------------------------------------------------------------------------
 
1903
 */
 
1904
Bool
 
1905
GXAccelInit(ScreenPtr pScrn)
 
1906
{
 
1907
    ScrnInfoPtr pScrni = xf86ScreenToScrn(pScrn);
 
1908
    GeodeRec *pGeode = GEODEPTR(pScrni);
 
1909
 
 
1910
#if XF86EXA
 
1911
    ExaDriverPtr pExa = pGeode->pExa;
 
1912
#endif
 
1913
 
 
1914
    gu2_xshift = pScrni->bitsPerPixel >> 4;
 
1915
 
 
1916
    /* XXX - fixme - this will change - we'll need to update it */
 
1917
 
 
1918
    gu2_pitch = pGeode->Pitch;
 
1919
 
 
1920
    switch (pGeode->Pitch) {
 
1921
    case 1024:
 
1922
        gu2_yshift = 10;
 
1923
        break;
 
1924
    case 2048:
 
1925
        gu2_yshift = 11;
 
1926
        break;
 
1927
    case 4096:
 
1928
        gu2_yshift = 12;
 
1929
        break;
 
1930
    default:
 
1931
        gu2_yshift = 13;
 
1932
        break;
 
1933
    }
 
1934
 
 
1935
#ifdef OPT_ACCEL
 
1936
    ACCEL_STRIDE = (pGeode->Pitch << 16) | pGeode->Pitch;
 
1937
    BPP = amd_gx_BppToRasterMode(pScrni->bitsPerPixel);
 
1938
#endif
 
1939
 
 
1940
#if XF86EXA
 
1941
    if (pExa && pGeode->useEXA) {
 
1942
        pExa->exa_major = EXA_VERSION_MAJOR;
 
1943
        pExa->exa_minor = EXA_VERSION_MINOR;
 
1944
 
 
1945
        /* Sync */
 
1946
        pExa->WaitMarker = amd_gx_exa_WaitMarker;
 
1947
        /* UploadToScreen */
 
1948
        pExa->UploadToScreen = amd_gx_exa_UploadToScreen;
 
1949
        pExa->DownloadFromScreen = amd_gx_exa_DownloadFromScreen;
 
1950
 
 
1951
        /* Solid fill */
 
1952
        pExa->PrepareSolid = amd_gx_exa_PrepareSolid;
 
1953
        pExa->Solid = amd_gx_exa_Solid;
 
1954
        pExa->DoneSolid = amd_gx_exa_Done;
 
1955
 
 
1956
        /* Copy */
 
1957
        pExa->PrepareCopy = amd_gx_exa_PrepareCopy;
 
1958
        pExa->Copy = amd_gx_exa_Copy;
 
1959
        pExa->DoneCopy = amd_gx_exa_Done;
 
1960
 
 
1961
        /* Composite */
 
1962
        pExa->CheckComposite = amd_gx_exa_CheckComposite;
 
1963
        pExa->PrepareComposite = amd_gx_exa_PrepareComposite;
 
1964
        pExa->Composite = amd_gx_exa_Composite;
 
1965
        pExa->DoneComposite = amd_gx_exa_Done;
 
1966
 
 
1967
        return exaDriverInit(pScrn, pGeode->pExa);
 
1968
    }
 
1969
#endif
 
1970
 
 
1971
#if XF86XAA
 
1972
 
 
1973
    /* Getting the pointer for acceleration Inforecord */
 
1974
    pGeode->AccelInfoRec = localRecPtr = XAACreateInfoRec();
 
1975
    if (!pGeode->AccelInfoRec)
 
1976
        return FALSE;
 
1977
 
 
1978
    /* SET ACCELERATION FLAGS */
 
1979
    localRecPtr->Flags = PIXMAP_CACHE | OFFSCREEN_PIXMAPS | LINEAR_FRAMEBUFFER;
 
1980
 
 
1981
    /* HOOK SYNCRONIZARION ROUTINE */
 
1982
    localRecPtr->Sync = GXAccelSync;
 
1983
 
 
1984
#if GX_FILL_RECT_SUPPORT
 
1985
    /* HOOK FILLED RECTANGLES */
 
1986
    HOOK(SetupForSolidFill);
 
1987
    HOOK(SubsequentSolidFillRect);
 
1988
    localRecPtr->SolidFillFlags = 0;
 
1989
#endif
 
1990
 
 
1991
#if GX_MONO_8X8_PAT_SUPPORT
 
1992
    /* Color expansion */
 
1993
    HOOK(SetupForMono8x8PatternFill);
 
1994
    HOOK(SubsequentMono8x8PatternFillRect);
 
1995
/*         BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD | NO_TRANSPARENCY | */
 
1996
    localRecPtr->Mono8x8PatternFillFlags = BIT_ORDER_IN_BYTE_MSBFIRST |
 
1997
        HARDWARE_PATTERN_PROGRAMMED_BITS | HARDWARE_PATTERN_SCREEN_ORIGIN;
 
1998
#endif
 
1999
 
 
2000
#if GX_CLREXP_8X8_PAT_SUPPORT
 
2001
    /* Color expansion */
 
2002
    HOOK(SetupForColor8x8PatternFill);
 
2003
    HOOK(SubsequentColor8x8PatternFillRect);
 
2004
/*         BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD | NO_TRANSPARENCY | */
 
2005
    localRecPtr->Color8x8PatternFillFlags =
 
2006
        BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD |
 
2007
        HARDWARE_PATTERN_PROGRAMMED_BITS | HARDWARE_PATTERN_PROGRAMMED_ORIGIN;
 
2008
#endif
 
2009
 
 
2010
#if GX_SCR2SCRCPY_SUPPORT
 
2011
    /* HOOK SCREEN TO SCREEN COPIES
 
2012
     * Set flag to only allow copy if transparency is enabled.
 
2013
     */
 
2014
    HOOK(SetupForScreenToScreenCopy);
 
2015
    HOOK(SubsequentScreenToScreenCopy);
 
2016
    localRecPtr->ScreenToScreenCopyFlags =
 
2017
        BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD;
 
2018
#endif
 
2019
 
 
2020
#if GX_BRES_LINE_SUPPORT
 
2021
    /* HOOK BRESENHAM SOLID LINES */
 
2022
    localRecPtr->SolidLineFlags = NO_PLANEMASK;
 
2023
    HOOK(SetupForSolidLine);
 
2024
    HOOK(SubsequentSolidBresenhamLine);
 
2025
    HOOK(SubsequentSolidHorVertLine);
 
2026
    HOOK(SubsequentSolidTwoPointLine);
 
2027
    localRecPtr->SolidBresenhamLineErrorTermBits = 15;
 
2028
#endif
 
2029
 
 
2030
#if GX_DASH_LINE_SUPPORT
 
2031
    /* HOOK BRESENHAM DASHED LINES */
 
2032
    HOOK(SetupForDashedLine);
 
2033
    HOOK(SubsequentDashedBresenhamLine);
 
2034
    HOOK(SubsequentDashedTwoPointLine);
 
2035
    localRecPtr->DashedBresenhamLineErrorTermBits = 15;
 
2036
    localRecPtr->DashPatternMaxLength = 64;
 
2037
    localRecPtr->DashedLineFlags = NO_PLANEMASK |       /* TRANSPARENCY_ONLY | */
 
2038
        LINE_PATTERN_POWER_OF_2_ONLY | LINE_PATTERN_MSBFIRST_MSBJUSTIFIED;
 
2039
#endif
 
2040
 
 
2041
#if GX_SCR2SCREXP_SUPPORT
 
2042
    /* Color expansion */
 
2043
    HOOK(SetupForScreenToScreenColorExpandFill);
 
2044
    HOOK(SubsequentScreenToScreenColorExpandFill);
 
2045
    localRecPtr->ScreenToScreenColorExpandFillFlags =
 
2046
        BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD | NO_TRANSPARENCY;
 
2047
#endif
 
2048
 
 
2049
    if (pGeode->AccelImageWriteBuffers) {
 
2050
#if GX_SCANLINE_SUPPORT
 
2051
        localRecPtr->ScanlineImageWriteBuffers = pGeode->AccelImageWriteBuffers;
 
2052
        localRecPtr->NumScanlineImageWriteBuffers = pGeode->NoOfImgBuffers;
 
2053
        HOOK(SetupForScanlineImageWrite);
 
2054
        HOOK(SubsequentScanlineImageWriteRect);
 
2055
        HOOK(SubsequentImageWriteScanline);
 
2056
        localRecPtr->ScanlineImageWriteFlags = NO_PLANEMASK | NO_GXCOPY |
 
2057
            BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD;
 
2058
#endif
 
2059
 
 
2060
    }
 
2061
    else {
 
2062
        localRecPtr->PixmapCacheFlags = DO_NOT_BLIT_STIPPLES;
 
2063
    }
 
2064
 
 
2065
    if (pGeode->AccelColorExpandBuffers) {
 
2066
#if GX_CPU2SCREXP_SUPPORT
 
2067
        /* Color expansion */
 
2068
        localRecPtr->ScanlineColorExpandBuffers =
 
2069
            pGeode->AccelColorExpandBuffers;
 
2070
        localRecPtr->NumScanlineColorExpandBuffers =
 
2071
            pGeode->NoOfColorExpandLines;
 
2072
        HOOK(SetupForScanlineCPUToScreenColorExpandFill);
 
2073
        HOOK(SubsequentScanlineCPUToScreenColorExpandFill);
 
2074
        HOOK(SubsequentColorExpandScanline);
 
2075
        localRecPtr->ScanlineCPUToScreenColorExpandFillFlags = NO_PLANEMASK |
 
2076
            BIT_ORDER_IN_BYTE_MSBFIRST | SCANLINE_PAD_DWORD;
 
2077
#endif
 
2078
    }
 
2079
#if GX_WRITE_PIXMAP_SUPPORT
 
2080
    pGeode->WritePixmap = localRecPtr->WritePixmap;
 
2081
    HOOK(WritePixmap);
 
2082
#endif
 
2083
 
 
2084
    return (XAAInit(pScrn, localRecPtr));
 
2085
#else /* XF86XAA */
 
2086
    return FALSE;
 
2087
#endif
 
2088
}
 
2089
 
 
2090
/* END OF FILE */