1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/**************************************************************************
*
* Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* @file
* SWIG interface definion for Gallium types.
*
* @author Jose Fonseca <jrfonseca@tungstengraphics.com>
*/
%nodefaultctor pipe_texture;
%nodefaultctor st_surface;
%nodefaultctor pipe_buffer;
%nodefaultdtor pipe_texture;
%nodefaultdtor st_surface;
%nodefaultdtor pipe_buffer;
%ignore pipe_texture::screen;
%immutable st_surface::texture;
%immutable st_surface::face;
%immutable st_surface::level;
%immutable st_surface::zslice;
%newobject pipe_texture::get_surface;
%extend pipe_texture {
~pipe_texture() {
struct pipe_texture *ptr = $self;
pipe_texture_reference(&ptr, NULL);
}
unsigned get_width(unsigned level=0) {
return u_minify($self->width0, level);
}
unsigned get_height(unsigned level=0) {
return u_minify($self->height0, level);
}
unsigned get_depth(unsigned level=0) {
return u_minify($self->depth0, level);
}
/** Get a surface which is a "view" into a texture */
struct st_surface *
get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0)
{
struct st_surface *surface;
if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
SWIG_exception(SWIG_ValueError, "face out of bounds");
if(level > $self->last_level)
SWIG_exception(SWIG_ValueError, "level out of bounds");
if(zslice >= u_minify($self->depth0, level))
SWIG_exception(SWIG_ValueError, "zslice out of bounds");
surface = CALLOC_STRUCT(st_surface);
if(!surface)
return NULL;
pipe_texture_reference(&surface->texture, $self);
surface->face = face;
surface->level = level;
surface->zslice = zslice;
return surface;
fail:
return NULL;
}
};
struct st_surface
{
%immutable;
struct pipe_texture *texture;
unsigned face;
unsigned level;
unsigned zslice;
};
%extend st_surface {
%immutable;
unsigned format;
unsigned width;
unsigned height;
~st_surface() {
pipe_texture_reference(&$self->texture, NULL);
FREE($self);
}
};
%{
static enum pipe_format
st_surface_format_get(struct st_surface *surface)
{
return surface->texture->format;
}
static unsigned
st_surface_width_get(struct st_surface *surface)
{
return u_minify(surface->texture->width0, surface->level);
}
static unsigned
st_surface_height_get(struct st_surface *surface)
{
return u_minify(surface->texture->height0, surface->level);
}
%}
/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
%rename(read) read_;
%rename(write) write_;
%extend pipe_buffer {
~pipe_buffer() {
struct pipe_buffer *ptr = $self;
pipe_buffer_reference(&ptr, NULL);
}
unsigned __len__(void)
{
assert(p_atomic_read(&$self->reference.count) > 0);
return $self->size;
}
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
void read_(char **STRING, int *LENGTH)
{
struct pipe_screen *screen = $self->screen;
assert(p_atomic_read(&$self->reference.count) > 0);
*LENGTH = $self->size;
*STRING = (char *) malloc($self->size);
if(!*STRING)
return;
pipe_buffer_read(screen, $self, 0, $self->size, *STRING);
}
%cstring_input_binary(const char *STRING, unsigned LENGTH);
void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0)
{
struct pipe_screen *screen = $self->screen;
assert(p_atomic_read(&$self->reference.count) > 0);
if(offset > $self->size)
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
if(offset + LENGTH > $self->size)
SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
pipe_buffer_write(screen, $self, offset, LENGTH, STRING);
fail:
return;
}
};
|