Squashed commit of the following:
[profile/ivi/mesa.git] / src / gallium / state_trackers / python / p_device.i
1  /**************************************************************************
2  * 
3  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4  * All Rights Reserved.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  * 
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  * 
26  **************************************************************************/
27
28 /**
29  * @file
30  * SWIG interface definion for Gallium types.
31  *
32  * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
33  */
34
35
36 %nodefaultctor st_device;
37 %nodefaultdtor st_device;
38
39
40 struct st_device {
41 };
42
43 %newobject st_device::texture_create;
44 %newobject st_device::context_create;
45 %newobject st_device::buffer_create;
46
47 %extend st_device {
48    
49    st_device(int hardware = 1) {
50       return st_device_create(hardware ? TRUE : FALSE);
51    }
52
53    ~st_device() {
54       st_device_destroy($self);
55    }
56    
57    const char * get_name( void ) {
58       return $self->screen->get_name($self->screen);
59    }
60
61    const char * get_vendor( void ) {
62       return $self->screen->get_vendor($self->screen);
63    }
64
65    /**
66     * Query an integer-valued capability/parameter/limit
67     * \param param  one of PIPE_CAP_x
68     */
69    int get_param( int param ) {
70       return $self->screen->get_param($self->screen, param);
71    }
72
73    /**
74     * Query a float-valued capability/parameter/limit
75     * \param param  one of PIPE_CAP_x
76     */
77    float get_paramf( int param ) {
78       return $self->screen->get_paramf($self->screen, param);
79    }
80
81    /**
82     * Check if the given pipe_format is supported as a texture or
83     * drawing surface.
84     * \param tex_usage bitmask of PIPE_BIND flags
85     */
86    int is_format_supported( enum pipe_format format, 
87                             enum pipe_texture_target target,
88                             unsigned tex_usage, 
89                             unsigned geom_flags ) {
90       /* We can't really display surfaces with the python statetracker so mask
91        * out that usage */
92       tex_usage &= ~PIPE_BIND_DISPLAY_TARGET;
93
94       return $self->screen->is_format_supported( $self->screen, 
95                                                  format, 
96                                                  target, 
97                                                  tex_usage, 
98                                                  geom_flags );
99    }
100
101    struct st_context *
102    context_create(void) {
103       return st_context_create($self);
104    }
105
106    struct pipe_resource * 
107    texture_create(
108          enum pipe_format format,
109          unsigned width,
110          unsigned height,
111          unsigned depth = 1,
112          unsigned last_level = 0,
113          enum pipe_texture_target target = PIPE_TEXTURE_2D,
114          unsigned tex_usage = 0
115       ) {
116       struct pipe_resource templat;
117
118       /* We can't really display surfaces with the python statetracker so mask
119        * out that usage */
120       tex_usage &= ~PIPE_BIND_DISPLAY_TARGET;
121
122       memset(&templat, 0, sizeof(templat));
123       templat.format = format;
124       templat.width0 = width;
125       templat.height0 = height;
126       templat.depth0 = depth;
127       templat.last_level = last_level;
128       templat.target = target;
129       templat.bind = tex_usage;
130
131       return $self->screen->resource_create($self->screen, &templat);
132    }
133
134    struct pipe_resource *
135    buffer_create(unsigned size, unsigned bind = 0) {
136       return pipe_buffer_create($self->screen, bind, size);
137    }
138
139 };