~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to GL/glx/glxmem.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/GL/glx/glxmem.c,v 1.6 2001/10/31 22:50:27 tsi Exp $ */
 
2
/*
 
3
** License Applicability. Except to the extent portions of this file are
 
4
** made subject to an alternative license as permitted in the SGI Free
 
5
** Software License B, Version 1.1 (the "License"), the contents of this
 
6
** file are subject only to the provisions of the License. You may not use
 
7
** this file except in compliance with the License. You may obtain a copy
 
8
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
 
9
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
 
10
** 
 
11
** http://oss.sgi.com/projects/FreeB
 
12
** 
 
13
** Note that, as provided in the License, the Software is distributed on an
 
14
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
 
15
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
 
16
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
 
17
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
 
18
** 
 
19
** Original Code. The Original Code is: OpenGL Sample Implementation,
 
20
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
 
21
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
 
22
** Copyright in any portions created by third parties is as indicated
 
23
** elsewhere herein. All Rights Reserved.
 
24
** 
 
25
** Additional Notice Provisions: The application programming interfaces
 
26
** established by SGI in conjunction with the Original Code are The
 
27
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
 
28
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
 
29
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
 
30
** Window System(R) (Version 1.3), released October 19, 1998. This software
 
31
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
 
32
** published by SGI, but has not been independently verified as being
 
33
** compliant with the OpenGL(R) version 1.2.1 Specification.
 
34
**
 
35
*/
 
36
 
 
37
/*
 
38
** Implementation of a buffer in main memory
 
39
*/
 
40
 
 
41
#ifdef HAVE_DIX_CONFIG_H
 
42
#include <dix-config.h>
 
43
#endif
 
44
 
 
45
#include "glxserver.h"
 
46
#include "glxmem.h"
 
47
#include "glxext.h"
 
48
#include "GL/internal/glcore.h"
 
49
 
 
50
/* don't want to include glmath.h */
 
51
extern GLuint __glFloorLog2(GLuint);
 
52
 
 
53
/* ---------------------------------------------------------- */
 
54
 
 
55
#define BUF_ALIGN 32    /* x86 cache alignment (used for assembly paths) */
 
56
#define BUF_ALIGN_MASK  (BUF_ALIGN-1)
 
57
 
 
58
static GLboolean
 
59
Resize(__GLdrawableBuffer *buf, 
 
60
       GLint x, GLint y, GLuint width, GLuint height,
 
61
       __GLdrawablePrivate *glPriv, GLuint bufferMask)
 
62
{
 
63
    GLuint newSize;
 
64
    void *ubase;
 
65
    GLint pixelWidth;
 
66
    GLint alignedWidth;
 
67
 
 
68
    /*
 
69
    ** Note: 
 
70
    **  buf->handle : unaligned base
 
71
    **  buf->base   : aligned base
 
72
    */
 
73
 
 
74
    pixelWidth = BUF_ALIGN / buf->elementSize;
 
75
    alignedWidth = (width & ~(pixelWidth-1)) + pixelWidth;
 
76
 
 
77
    newSize = alignedWidth * height * buf->elementSize;
 
78
 
 
79
    /*
 
80
    ** Only allocate buffer space for the SGI core.
 
81
    ** Mesa and Aqua handle their own buffer allocations.
 
82
    */
 
83
#if defined(__GL_BUFFER_SIZE_TRACKS_WINDOW)
 
84
    if (__glXCoreType() == GL_CORE_SGI) {
 
85
#else
 
86
    if (newSize > buf->size && __glXCoreType() == GL_CORE_SGI) {
 
87
#endif
 
88
        if (buf->handle) {
 
89
            ubase = (*glPriv->realloc)(buf->handle, newSize + BUF_ALIGN_MASK);
 
90
            if (ubase == NULL) {
 
91
                return GL_FALSE;
 
92
            }
 
93
        } else {
 
94
            ubase = (*glPriv->malloc)(newSize + BUF_ALIGN_MASK);
 
95
            if (ubase == NULL) {
 
96
                return GL_FALSE;
 
97
            }
 
98
        }
 
99
        buf->size = newSize;
 
100
 
 
101
        buf->handle = ubase;
 
102
        buf->base = (void *)(((size_t)ubase + BUF_ALIGN_MASK) &
 
103
                             (unsigned int) ~BUF_ALIGN_MASK);
 
104
        assert(((size_t)buf->base % BUF_ALIGN) == 0);
 
105
    }
 
106
 
 
107
    buf->width = width;
 
108
    buf->height = height;
 
109
    buf->byteWidth = alignedWidth * buf->elementSize;
 
110
    buf->outerWidth = alignedWidth;
 
111
 
 
112
    return GL_TRUE;
 
113
}
 
114
 
 
115
static void
 
116
Lock(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
 
117
{
 
118
}
 
119
 
 
120
static void
 
121
Unlock(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
 
122
{
 
123
}
 
124
 
 
125
static void
 
126
Free(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
 
127
{
 
128
    if (buf->handle) {
 
129
        (*glPriv->free)(buf->handle);
 
130
        buf->handle = NULL;
 
131
    }
 
132
}
 
133
 
 
134
 
 
135
void
 
136
__glXInitMem(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv, GLint bits)
 
137
{
 
138
    buf->width = buf->height = 0;       /* to be filled during Update */
 
139
    buf->depth = bits;
 
140
    buf->size = 0;
 
141
    buf->handle = buf->base = NULL;     /* to be filled during Update */
 
142
    buf->byteWidth = 0;
 
143
    buf->elementSize = ((bits - 1) / 8) + 1;
 
144
    buf->elementSizeLog2 = __glFloorLog2(buf->elementSize);
 
145
 
 
146
    buf->resize = Resize;
 
147
    buf->lock = Lock;
 
148
    buf->unlock = Unlock;
 
149
    buf->fill = NULL;
 
150
    buf->free = Free;
 
151
}