p_screen.h revision e1238b5cad3845c029f60d92c08e810274517d33
1/**************************************************************************
2 *
3 * Copyright 2007 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 *
31 * Screen, Adapter or GPU
32 *
33 * These are driver functions/facilities that are context independent.
34 */
35
36
37#ifndef P_SCREEN_H
38#define P_SCREEN_H
39
40
41#include "pipe/p_compiler.h"
42#include "pipe/p_format.h"
43#include "pipe/p_defines.h"
44
45
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51
52/** Opaque type */
53struct winsys_handle;
54/** Opaque type */
55struct pipe_fence_handle;
56struct pipe_winsys;
57struct pipe_texture;
58struct pipe_resource;
59struct pipe_surface;
60struct pipe_transfer;
61
62
63/**
64 * Gallium screen/adapter context.  Basically everything
65 * hardware-specific that doesn't actually require a rendering
66 * context.
67 */
68struct pipe_screen {
69   struct pipe_winsys *winsys;
70
71   void (*destroy)( struct pipe_screen * );
72
73
74   const char *(*get_name)( struct pipe_screen * );
75
76   const char *(*get_vendor)( struct pipe_screen * );
77
78   /**
79    * Query an integer-valued capability/parameter/limit
80    * \param param  one of PIPE_CAP_x
81    */
82   int (*get_param)( struct pipe_screen *, enum pipe_cap param );
83
84   /**
85    * Query a float-valued capability/parameter/limit
86    * \param param  one of PIPE_CAP_x
87    */
88   float (*get_paramf)( struct pipe_screen *, enum pipe_cap param );
89
90   struct pipe_context * (*context_create)( struct pipe_screen *,
91					    void *priv );
92
93   /**
94    * Check if the given pipe_format is supported as a texture or
95    * drawing surface.
96    * \param bindings  bitmask of PIPE_BIND_*
97    * \param geom_flags  bitmask of PIPE_TEXTURE_GEOM_*
98    */
99   boolean (*is_format_supported)( struct pipe_screen *,
100                                   enum pipe_format format,
101                                   enum pipe_texture_target target,
102                                   unsigned bindings,
103                                   unsigned geom_flags );
104
105   /**
106    * Create a new texture object, using the given template info.
107    */
108   struct pipe_resource * (*resource_create)(struct pipe_screen *,
109					     const struct pipe_resource *templat);
110
111   /**
112    * Create a texture from a winsys_handle. The handle is often created in
113    * another process by first creating a pipe texture and then calling
114    * texture_get_handle.
115    */
116   struct pipe_resource * (*resource_from_handle)(struct pipe_screen *,
117						  const struct pipe_resource *templat,
118						  struct winsys_handle *handle);
119
120   /**
121    * Get a winsys_handle from a texture. Some platforms/winsys requires
122    * that the texture is created with a special usage flag like
123    * DISPLAYTARGET or PRIMARY.
124    */
125   boolean (*resource_get_handle)(struct pipe_screen *,
126				  struct pipe_resource *tex,
127				  struct winsys_handle *handle);
128
129
130   void (*resource_destroy)(struct pipe_screen *,
131			    struct pipe_resource *pt);
132
133   /** Get a 2D surface which is a "view" into a texture
134    * \param usage  bitmaks of PIPE_BIND_* flags
135    */
136   struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
137                                           struct pipe_resource *resource,
138                                           unsigned face, unsigned level,
139                                           unsigned zslice,
140                                           unsigned usage );
141
142   void (*tex_surface_destroy)(struct pipe_surface *);
143
144
145
146   /**
147    * Create a buffer that wraps user-space data.
148    *
149    * Effectively this schedules a delayed call to buffer_create
150    * followed by an upload of the data at *some point in the future*,
151    * or perhaps never.  Basically the allocate/upload is delayed
152    * until the buffer is actually passed to hardware.
153    *
154    * The intention is to provide a quick way to turn regular data
155    * into a buffer, and secondly to avoid a copy operation if that
156    * data subsequently turns out to be only accessed by the CPU.
157    *
158    * Common example is OpenGL vertex buffers that are subsequently
159    * processed either by software TNL in the driver or by passing to
160    * hardware.
161    *
162    * XXX: What happens if the delayed call to buffer_create() fails?
163    *
164    * Note that ptr may be accessed at any time upto the time when the
165    * buffer is destroyed, so the data must not be freed before then.
166    */
167   struct pipe_resource *(*user_buffer_create)(struct pipe_screen *screen,
168					       void *ptr,
169					       unsigned bytes,
170					       unsigned bind_flags);
171
172   /**
173    * Do any special operations to ensure frontbuffer contents are
174    * displayed, eg copy fake frontbuffer.
175    * \param winsys_drawable_handle  an opaque handle that the calling context
176    *                                gets out-of-band
177    */
178   void (*flush_frontbuffer)( struct pipe_screen *screen,
179                              struct pipe_surface *surf,
180                              void *winsys_drawable_handle );
181
182
183
184   /** Set ptr = fence, with reference counting */
185   void (*fence_reference)( struct pipe_screen *screen,
186                            struct pipe_fence_handle **ptr,
187                            struct pipe_fence_handle *fence );
188
189   /**
190    * Checks whether the fence has been signalled.
191    * \param flags  driver-specific meaning
192    * \return zero on success.
193    */
194   int (*fence_signalled)( struct pipe_screen *screen,
195                           struct pipe_fence_handle *fence,
196                           unsigned flags );
197
198   /**
199    * Wait for the fence to finish.
200    * \param flags  driver-specific meaning
201    * \return zero on success.
202    */
203   int (*fence_finish)( struct pipe_screen *screen,
204                        struct pipe_fence_handle *fence,
205                        unsigned flags );
206
207};
208
209
210#ifdef __cplusplus
211}
212#endif
213
214#endif /* P_SCREEN_H */
215