~ubuntu-branches/ubuntu/edgy/xorg-server/edgy-updates

« back to all changes in this revision

Viewing changes to hw/xgl/xglsync.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Parra Novo
  • Date: 2006-07-25 20:06:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060725200628-gjmmd9gxfxdc4ejs
Tags: 1:1.1.1-0ubuntu1
* New Upstream version
* Changed Build-Depends from mesa-swrast-source to mesa-swx11-source,
  following Debian package nomenclature
* Re-did 12_security_policy_in_etc.diff for 1.1.1
* Dropped 15_security_allocate_local.diff (applied upstream)
* Dropped 16_SECURITY_setuid.diff (applied upstream)
* Dropped 000_ubuntu_fix_read_kernel_mapping.patch (applied upstream)
* Dropped 002_ubuntu_fix_for_certain_intel_chipsets.patch (applied upstream)
* Updated versioned Build-Depends on mesa-swx11-source to version
  6.5.0.cvs.20060725-0ubuntu1
* Added arrayobj.c, arrayobj.h, bitset.h & rbadaptors.h to
  GL/symlink-mesa.sh (linked from mesa-swx11-source)
* Added arrayobj.c to default build target on GL/mesa/main

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2004 David Reveman
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * David Reveman not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * David Reveman makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: David Reveman <davidr@novell.com>
 
24
 */
 
25
 
 
26
#include "xgl.h"
 
27
 
 
28
Bool
 
29
xglSyncBits (DrawablePtr pDrawable,
 
30
             BoxPtr      pExtents)
 
31
{
 
32
    RegionRec region;
 
33
    BoxRec    box;
 
34
 
 
35
    XGL_DRAWABLE_PIXMAP (pDrawable);
 
36
    XGL_PIXMAP_PRIV (pPixmap);
 
37
 
 
38
    if (pPixmapPriv->allBits)
 
39
        return xglMapPixmapBits (pPixmap);
 
40
 
 
41
    if (pPixmapPriv->target == xglPixmapTargetIn && pExtents)
 
42
    {
 
43
        box.x1 = 0;
 
44
        box.y1 = 0;
 
45
        box.x2 = pPixmap->drawable.width;
 
46
        box.y2 = pPixmap->drawable.height;
 
47
        if (pExtents->x1 > box.x1)
 
48
            box.x1 = pExtents->x1;
 
49
        if (pExtents->y1 > box.y1)
 
50
            box.y1 = pExtents->y1;
 
51
        if (pExtents->x2 < box.x2)
 
52
            box.x2 = pExtents->x2;
 
53
        if (pExtents->y2 < box.y2)
 
54
            box.y2 = pExtents->y2;
 
55
 
 
56
        if (box.x2 <= box.x1 || box.y2 <= box.y1)
 
57
            return xglMapPixmapBits (pPixmap);
 
58
 
 
59
        if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
 
60
        {
 
61
            switch (RECT_IN_REGION (pDrawable->pScreen,
 
62
                                    &pPixmapPriv->bitRegion,
 
63
                                    &box)) {
 
64
            case rgnIN:
 
65
                REGION_INIT (pDrawable->pScreen, &region, NullBox, 0);
 
66
                break;
 
67
            case rgnOUT:
 
68
                REGION_INIT (pDrawable->pScreen, &region, &box, 1);
 
69
                REGION_UNION (pDrawable->pScreen,
 
70
                              &pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
 
71
                              &region);
 
72
                break;
 
73
            case rgnPART:
 
74
                REGION_INIT (pDrawable->pScreen, &region, &box, 1);
 
75
                REGION_SUBTRACT (pDrawable->pScreen, &region, &region,
 
76
                                 &pPixmapPriv->bitRegion);
 
77
                REGION_UNION (pDrawable->pScreen,
 
78
                              &pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
 
79
                              &region);
 
80
                break;
 
81
            }
 
82
        }
 
83
        else
 
84
        {
 
85
            REGION_INIT (pDrawable->pScreen, &region, &box, 1);
 
86
            REGION_SUBTRACT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
 
87
                             &region, &pPixmapPriv->bitRegion);
 
88
        }
 
89
 
 
90
        if (REGION_NUM_RECTS (&pPixmapPriv->bitRegion) == 1)
 
91
        {
 
92
            BoxPtr pBox;
 
93
 
 
94
            pBox = REGION_RECTS (&pPixmapPriv->bitRegion);
 
95
 
 
96
            if (pBox->x1 <= 0                       &&
 
97
                pBox->y1 <= 0                       &&
 
98
                pBox->x2 >= pPixmap->drawable.width &&
 
99
                pBox->y2 >= pPixmap->drawable.height)
 
100
                pPixmapPriv->allBits = TRUE;
 
101
        }
 
102
    }
 
103
    else
 
104
    {
 
105
        box.x1 = 0;
 
106
        box.y1 = 0;
 
107
        box.x2 = pPixmap->drawable.width;
 
108
        box.y2 = pPixmap->drawable.height;
 
109
 
 
110
        REGION_INIT (pDrawable->pScreen, &region, &box, 1);
 
111
        REGION_SUBTRACT (pDrawable->pScreen, &region, &region,
 
112
                         &pPixmapPriv->bitRegion);
 
113
 
 
114
        pPixmapPriv->allBits = TRUE;
 
115
    }
 
116
 
 
117
    if (!pPixmapPriv->buffer)
 
118
        if (!xglAllocatePixmapBits (pPixmap, XGL_PIXMAP_USAGE_HINT_DEFAULT))
 
119
            return FALSE;
 
120
 
 
121
    if (REGION_NOTEMPTY (pDrawable->pScreen, &region) && pPixmapPriv->surface)
 
122
    {
 
123
        glitz_pixel_format_t format;
 
124
        BoxPtr               pBox;
 
125
        BoxPtr               pExt;
 
126
        int                  nBox;
 
127
 
 
128
        if (!xglSyncSurface (pDrawable))
 
129
            FatalError (XGL_SW_FAILURE_STRING);
 
130
 
 
131
        xglUnmapPixmapBits (pPixmap);
 
132
 
 
133
        pBox = REGION_RECTS (&region);
 
134
        nBox = REGION_NUM_RECTS (&region);
 
135
        pExt = REGION_EXTENTS (pDrawable->pScreen, &region);
 
136
 
 
137
        format.fourcc  = GLITZ_FOURCC_RGB;
 
138
        format.masks   = pPixmapPriv->pVisual->pPixel->masks;
 
139
        format.xoffset = pExt->x1;
 
140
 
 
141
        if (pPixmapPriv->stride < 0)
 
142
        {
 
143
            format.skip_lines     = pPixmap->drawable.height - pExt->y2;
 
144
            format.bytes_per_line = -pPixmapPriv->stride;
 
145
            format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
 
146
        }
 
147
        else
 
148
        {
 
149
            format.skip_lines     = pExt->y1;
 
150
            format.bytes_per_line = pPixmapPriv->stride;
 
151
            format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
 
152
        }
 
153
 
 
154
        glitz_surface_set_clip_region (pPixmapPriv->surface,
 
155
                                       0, 0, (glitz_box_t *) pBox, nBox);
 
156
 
 
157
        glitz_get_pixels (pPixmapPriv->surface,
 
158
                          pExt->x1,
 
159
                          pExt->y1,
 
160
                          pExt->x2 - pExt->x1,
 
161
                          pExt->y2 - pExt->y1,
 
162
                          &format,
 
163
                          pPixmapPriv->buffer);
 
164
 
 
165
        glitz_surface_set_clip_region (pPixmapPriv->surface, 0, 0, NULL, 0);
 
166
    }
 
167
 
 
168
    REGION_UNINIT (pDrawable->pScreen, &region);
 
169
 
 
170
    if (pPixmapPriv->allBits)
 
171
    {
 
172
        box.x1 = 0;
 
173
        box.y1 = 0;
 
174
        box.x2 = pPixmap->drawable.width;
 
175
        box.y2 = pPixmap->drawable.height;
 
176
 
 
177
        REGION_UNINIT (pDrawable->pScreen, &pPixmapPriv->bitRegion);
 
178
        REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion, &box, 1);
 
179
    }
 
180
 
 
181
    return xglMapPixmapBits (pPixmap);
 
182
}
 
183
 
 
184
void
 
185
xglSyncDamageBoxBits (DrawablePtr pDrawable)
 
186
{
 
187
    XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
 
188
 
 
189
    if (!xglSyncBits (pDrawable, &pPixmapPriv->damageBox))
 
190
        FatalError (XGL_SW_FAILURE_STRING);
 
191
}
 
192
 
 
193
Bool
 
194
xglSyncSurface (DrawablePtr pDrawable)
 
195
{
 
196
    RegionPtr pRegion;
 
197
 
 
198
    XGL_DRAWABLE_PIXMAP (pDrawable);
 
199
    XGL_PIXMAP_PRIV (pPixmap);
 
200
 
 
201
    if (!pPixmapPriv->surface)
 
202
    {
 
203
        if (!xglCreatePixmapSurface (pPixmap))
 
204
            return FALSE;
 
205
    }
 
206
 
 
207
    pRegion = DamageRegion (pPixmapPriv->pDamage);
 
208
 
 
209
    if (REGION_NOTEMPTY (pDrawable->pScreen, pRegion))
 
210
    {
 
211
        glitz_pixel_format_t format;
 
212
        BoxPtr               pBox;
 
213
        BoxPtr               pExt;
 
214
        int                  nBox;
 
215
 
 
216
        xglUnmapPixmapBits (pPixmap);
 
217
 
 
218
        nBox = REGION_NUM_RECTS (pRegion);
 
219
        pBox = REGION_RECTS (pRegion);
 
220
        pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion);
 
221
 
 
222
        format.fourcc  = pPixmapPriv->pVisual->format.surface->color.fourcc;
 
223
        format.masks   = pPixmapPriv->pVisual->pPixel->masks;
 
224
        format.xoffset = pExt->x1;
 
225
 
 
226
        if (pPixmapPriv->stride < 0)
 
227
        {
 
228
            format.skip_lines     = pPixmap->drawable.height - pExt->y2;
 
229
            format.bytes_per_line = -pPixmapPriv->stride;
 
230
            format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_BOTTOM_UP;
 
231
        }
 
232
        else
 
233
        {
 
234
            format.skip_lines     = pExt->y1;
 
235
            format.bytes_per_line = pPixmapPriv->stride;
 
236
            format.scanline_order = GLITZ_PIXEL_SCANLINE_ORDER_TOP_DOWN;
 
237
        }
 
238
 
 
239
        glitz_surface_set_clip_region (pPixmapPriv->surface,
 
240
                                       0, 0, (glitz_box_t *) pBox, nBox);
 
241
 
 
242
        glitz_set_pixels (pPixmapPriv->surface,
 
243
                          pExt->x1,
 
244
                          pExt->y1,
 
245
                          pExt->x2 - pExt->x1,
 
246
                          pExt->y2 - pExt->y1,
 
247
                          &format,
 
248
                          pPixmapPriv->buffer);
 
249
 
 
250
        glitz_surface_set_clip_region (pPixmapPriv->surface, 0, 0, NULL, 0);
 
251
 
 
252
        REGION_EMPTY (pDrawable->pScreen, pRegion);
 
253
    }
 
254
 
 
255
    return TRUE;
 
256
}
 
257
 
 
258
Bool
 
259
xglPrepareTarget (DrawablePtr pDrawable)
 
260
{
 
261
    XGL_DRAWABLE_PIXMAP (pDrawable);
 
262
    XGL_PIXMAP_PRIV (pPixmap);
 
263
 
 
264
    switch (pPixmapPriv->target) {
 
265
    case xglPixmapTargetNo:
 
266
        break;
 
267
    case xglPixmapTargetOut:
 
268
        if (xglSyncSurface (pDrawable))
 
269
        {
 
270
            glitz_drawable_format_t *format;
 
271
 
 
272
            XGL_SCREEN_PRIV (pDrawable->pScreen);
 
273
 
 
274
            if (!pPixmapPriv->drawable)
 
275
            {
 
276
                unsigned int width, height;
 
277
 
 
278
                format = pPixmapPriv->pVisual->format.drawable;
 
279
                width  = pPixmap->drawable.width;
 
280
                height = pPixmap->drawable.height;
 
281
 
 
282
                if (pPixmapPriv->pVisual->pbuffer)
 
283
                {
 
284
                    pPixmapPriv->drawable =
 
285
                        glitz_create_pbuffer_drawable (pScreenPriv->drawable,
 
286
                                                       format, width, height);
 
287
                }
 
288
                else
 
289
                {
 
290
                    pPixmapPriv->drawable =
 
291
                        glitz_create_drawable (pScreenPriv->drawable,
 
292
                                               format, width, height);
 
293
                }
 
294
            }
 
295
 
 
296
            if (pPixmapPriv->drawable)
 
297
            {
 
298
                glitz_surface_attach (pPixmapPriv->surface,
 
299
                                      pPixmapPriv->drawable,
 
300
                                      GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
 
301
 
 
302
                pPixmapPriv->target = xglPixmapTargetIn;
 
303
 
 
304
                return TRUE;
 
305
            }
 
306
        }
 
307
        pPixmapPriv->target = xglPixmapTargetNo;
 
308
        break;
 
309
    case xglPixmapTargetIn:
 
310
        if (xglSyncSurface (pDrawable))
 
311
            return TRUE;
 
312
        break;
 
313
    }
 
314
 
 
315
    return FALSE;
 
316
}
 
317
 
 
318
void
 
319
xglAddSurfaceDamage (DrawablePtr pDrawable,
 
320
                     RegionPtr   pRegion)
 
321
{
 
322
    glitz_surface_t *surface;
 
323
    int             xOff, yOff;
 
324
 
 
325
    XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
 
326
 
 
327
    pPixmapPriv->damageBox = miEmptyBox;
 
328
 
 
329
    XGL_GET_DRAWABLE (pDrawable, surface, xOff, yOff);
 
330
 
 
331
    if (xOff || yOff)
 
332
        REGION_TRANSLATE (pDrawable->pScreen, pRegion, xOff, yOff);
 
333
 
 
334
    if (pPixmapPriv->pDamage)
 
335
    {
 
336
        RegionPtr pDamageRegion;
 
337
 
 
338
        pDamageRegion = DamageRegion (pPixmapPriv->pDamage);
 
339
 
 
340
        REGION_UNION (pDrawable->pScreen,
 
341
                      pDamageRegion, pDamageRegion,
 
342
                      pRegion);
 
343
    }
 
344
 
 
345
    REGION_UNION (pDrawable->pScreen,
 
346
                  &pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
 
347
                  pRegion);
 
348
 
 
349
    if (xOff || yOff)
 
350
        REGION_TRANSLATE (pDrawable->pScreen, pRegion, -xOff, -yOff);
 
351
}
 
352
 
 
353
void
 
354
xglAddCurrentSurfaceDamage (DrawablePtr pDrawable)
 
355
{
 
356
    XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
 
357
 
 
358
    if (BOX_NOTEMPTY (&pPixmapPriv->damageBox))
 
359
    {
 
360
        RegionRec region;
 
361
 
 
362
        REGION_INIT (pDrawable->pScreen, &region, &pPixmapPriv->damageBox, 1);
 
363
 
 
364
        if (pPixmapPriv->pDamage)
 
365
        {
 
366
            RegionPtr pDamageRegion;
 
367
 
 
368
            pDamageRegion = DamageRegion (pPixmapPriv->pDamage);
 
369
 
 
370
            REGION_UNION (pDrawable->pScreen,
 
371
                          pDamageRegion, pDamageRegion,
 
372
                          &region);
 
373
        }
 
374
 
 
375
        REGION_UNION (pDrawable->pScreen,
 
376
                      &pPixmapPriv->bitRegion, &pPixmapPriv->bitRegion,
 
377
                      &region);
 
378
 
 
379
        REGION_UNINIT (pDrawable->pScreen, &region);
 
380
 
 
381
        pPixmapPriv->damageBox = miEmptyBox;
 
382
    }
 
383
}
 
384
 
 
385
void
 
386
xglAddBitDamage (DrawablePtr pDrawable,
 
387
                 RegionPtr   pRegion)
 
388
{
 
389
    XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
 
390
 
 
391
    if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
 
392
    {
 
393
        BoxPtr pBox;
 
394
        BoxPtr pExt, pBitExt;
 
395
        int    nBox;
 
396
 
 
397
        pBox = REGION_RECTS (pRegion);
 
398
        pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion);
 
399
        nBox = REGION_NUM_RECTS (pRegion);
 
400
 
 
401
        pBitExt = REGION_EXTENTS (pDrawable->pScreen, &pPixmapPriv->bitRegion);
 
402
 
 
403
        if (pExt->x1 < pBitExt->x2 &&
 
404
            pExt->y1 < pBitExt->y2 &&
 
405
            pExt->x2 > pBitExt->x1 &&
 
406
            pExt->y2 > pBitExt->y1)
 
407
        {
 
408
            while (nBox--)
 
409
            {
 
410
                if (pBox->x1 < pBitExt->x2 &&
 
411
                    pBox->y1 < pBitExt->y2 &&
 
412
                    pBox->x2 > pBitExt->x1 &&
 
413
                    pBox->y2 > pBitExt->y1)
 
414
                {
 
415
                    REGION_UNINIT (pDrawable->pScreen,
 
416
                                   &pPixmapPriv->bitRegion);
 
417
                    REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
 
418
                                 NullBox, 0);
 
419
                    pPixmapPriv->allBits = FALSE;
 
420
                    return;
 
421
                }
 
422
 
 
423
                pBox++;
 
424
            }
 
425
        }
 
426
    }
 
427
}
 
428
 
 
429
void
 
430
xglAddCurrentBitDamage (DrawablePtr pDrawable)
 
431
{
 
432
    XGL_DRAWABLE_PIXMAP_PRIV (pDrawable);
 
433
 
 
434
    if (REGION_NOTEMPTY (pDrawable->pScreen, &pPixmapPriv->bitRegion))
 
435
    {
 
436
        BoxPtr pBitExt;
 
437
 
 
438
        pBitExt = REGION_EXTENTS (pDrawable->pScreen, &pPixmapPriv->bitRegion);
 
439
 
 
440
        if (pPixmapPriv->damageBox.x1 < pBitExt->x2 &&
 
441
            pPixmapPriv->damageBox.y1 < pBitExt->y2 &&
 
442
            pPixmapPriv->damageBox.x2 > pBitExt->x1 &&
 
443
            pPixmapPriv->damageBox.y2 > pBitExt->y1)
 
444
        {
 
445
            REGION_UNINIT (pDrawable->pScreen, &pPixmapPriv->bitRegion);
 
446
            REGION_INIT (pDrawable->pScreen, &pPixmapPriv->bitRegion,
 
447
                         NullBox, 0);
 
448
            pPixmapPriv->allBits = FALSE;
 
449
        }
 
450
    }
 
451
 
 
452
    pPixmapPriv->damageBox = miEmptyBox;
 
453
}