1
/* $XFree86: xc/programs/Xserver/GL/glx/glxmem.c,v 1.6 2001/10/31 22:50:27 tsi Exp $ */
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:
11
** http://oss.sgi.com/projects/FreeB
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.
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.
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.
38
** Implementation of a buffer in main memory
41
#ifdef HAVE_DIX_CONFIG_H
42
#include <dix-config.h>
45
#include "glxserver.h"
48
#include "GL/internal/glcore.h"
50
/* don't want to include glmath.h */
51
extern GLuint __glFloorLog2(GLuint);
53
/* ---------------------------------------------------------- */
55
#define BUF_ALIGN 32 /* x86 cache alignment (used for assembly paths) */
56
#define BUF_ALIGN_MASK (BUF_ALIGN-1)
59
Resize(__GLdrawableBuffer *buf,
60
GLint x, GLint y, GLuint width, GLuint height,
61
__GLdrawablePrivate *glPriv, GLuint bufferMask)
70
** buf->handle : unaligned base
71
** buf->base : aligned base
74
pixelWidth = BUF_ALIGN / buf->elementSize;
75
alignedWidth = (width & ~(pixelWidth-1)) + pixelWidth;
77
newSize = alignedWidth * height * buf->elementSize;
80
** Only allocate buffer space for the SGI core.
81
** Mesa and Aqua handle their own buffer allocations.
83
#if defined(__GL_BUFFER_SIZE_TRACKS_WINDOW)
84
if (__glXCoreType() == GL_CORE_SGI) {
86
if (newSize > buf->size && __glXCoreType() == GL_CORE_SGI) {
89
ubase = (*glPriv->realloc)(buf->handle, newSize + BUF_ALIGN_MASK);
94
ubase = (*glPriv->malloc)(newSize + BUF_ALIGN_MASK);
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);
108
buf->height = height;
109
buf->byteWidth = alignedWidth * buf->elementSize;
110
buf->outerWidth = alignedWidth;
116
Lock(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
121
Unlock(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
126
Free(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv)
129
(*glPriv->free)(buf->handle);
136
__glXInitMem(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv, GLint bits)
138
buf->width = buf->height = 0; /* to be filled during Update */
141
buf->handle = buf->base = NULL; /* to be filled during Update */
143
buf->elementSize = ((bits - 1) / 8) + 1;
144
buf->elementSizeLog2 = __glFloorLog2(buf->elementSize);
146
buf->resize = Resize;
148
buf->unlock = Unlock;