bb3f5ba102fbba76304b522280d92bb5d2678c34
[profile/ivi/mesa.git] / src / gallium / auxiliary / util / u_simple_screen.h
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
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 #ifndef U_SIMPLE_SCREEN_H
29 #define U_SIMPLE_SCREEN_H
30
31 #include "pipe/p_format.h"
32
33 struct pipe_screen;
34 struct pipe_fence_handle;
35 struct pipe_surface;
36 struct pipe_buffer;
37
38 /**
39  * Gallium3D drivers are (meant to be!) independent of both GL and the
40  * window system.  The window system provides a buffer manager and a
41  * set of additional hooks for things like command buffer submission,
42  * etc.
43  *
44  * There clearly has to be some agreement between the window system
45  * driver and the hardware driver about the format of command buffers,
46  * etc.
47  */
48 struct pipe_winsys
49 {
50    void (*destroy)( struct pipe_winsys *ws );
51
52    /** Returns name of this winsys interface */
53    const char *(*get_name)( struct pipe_winsys *ws );
54
55    /**
56     * Do any special operations to ensure buffer size is correct
57     */
58    void (*update_buffer)( struct pipe_winsys *ws,
59                           void *context_private );
60    /**
61     * Do any special operations to ensure frontbuffer contents are
62     * displayed, eg copy fake frontbuffer.
63     */
64    void (*flush_frontbuffer)( struct pipe_winsys *ws,
65                               struct pipe_surface *surf,
66                               void *context_private );
67
68
69    /**
70     * Buffer management. Buffer attributes are mostly fixed over its lifetime.
71     *
72     * Remember that gallium gets to choose the interface it needs, and the
73     * window systems must then implement that interface (rather than the
74     * other way around...).
75     *
76     * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
77     * usage argument is only an optimization hint, not a guarantee, therefore
78     * proper behavior must be observed in all circumstances.
79     *
80     * alignment indicates the client's alignment requirements, eg for
81     * SSE instructions.
82     */
83    struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,
84                                          unsigned alignment,
85                                          unsigned usage,
86                                          unsigned size );
87
88    /**
89     * Create a buffer that wraps user-space data.
90     *
91     * Effectively this schedules a delayed call to buffer_create
92     * followed by an upload of the data at *some point in the future*,
93     * or perhaps never.  Basically the allocate/upload is delayed
94     * until the buffer is actually passed to hardware.
95     *
96     * The intention is to provide a quick way to turn regular data
97     * into a buffer, and secondly to avoid a copy operation if that
98     * data subsequently turns out to be only accessed by the CPU.
99     *
100     * Common example is OpenGL vertex buffers that are subsequently
101     * processed either by software TNL in the driver or by passing to
102     * hardware.
103     *
104     * XXX: What happens if the delayed call to buffer_create() fails?
105     *
106     * Note that ptr may be accessed at any time upto the time when the
107     * buffer is destroyed, so the data must not be freed before then.
108     */
109    struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,
110                                                     void *ptr,
111                                                     unsigned bytes);
112
113    /**
114     * Allocate storage for a display target surface.
115     *
116     * Often surfaces which are meant to be blitted to the front screen (i.e.,
117     * display targets) must be allocated with special characteristics, memory
118     * pools, or obtained directly from the windowing system.
119     *
120     * This callback is invoked by the pipe_screenwhen creating a texture marked
121     * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag  to get the underlying
122     * buffer storage.
123     */
124    struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
125                                                 unsigned width, unsigned height,
126                                                 enum pipe_format format,
127                                                 unsigned usage,
128                                                 unsigned tex_usage,
129                                                 unsigned *stride);
130
131
132    /**
133     * Map the entire data store of a buffer object into the client's address.
134     * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
135     */
136    void *(*buffer_map)( struct pipe_winsys *ws,
137                         struct pipe_buffer *buf,
138                         unsigned usage );
139
140    void (*buffer_unmap)( struct pipe_winsys *ws,
141                          struct pipe_buffer *buf );
142
143    void (*buffer_destroy)( struct pipe_buffer *buf );
144
145
146    /** Set ptr = fence, with reference counting */
147    void (*fence_reference)( struct pipe_winsys *ws,
148                             struct pipe_fence_handle **ptr,
149                             struct pipe_fence_handle *fence );
150
151    /**
152     * Checks whether the fence has been signalled.
153     * \param flags  driver-specific meaning
154     * \return zero on success.
155     */
156    int (*fence_signalled)( struct pipe_winsys *ws,
157                            struct pipe_fence_handle *fence,
158                            unsigned flag );
159
160    /**
161     * Wait for the fence to finish.
162     * \param flags  driver-specific meaning
163     * \return zero on success.
164     */
165    int (*fence_finish)( struct pipe_winsys *ws,
166                         struct pipe_fence_handle *fence,
167                         unsigned flag );
168
169 };
170
171 /**
172  * The following function initializes a simple passthrough screen.
173  *
174  * All the relevant screen function pointers will forwarded to the
175  * winsys.
176  */
177 void u_simple_screen_init(struct pipe_screen *screen);
178
179 /**
180  * Returns the name of the winsys associated with this screen.
181  */
182 const char* u_simple_screen_winsys_name(struct pipe_screen *screen);
183
184 #endif