Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / util / u_simple_screen.c
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 #include "u_simple_screen.h"
29
30 #include "pipe/p_screen.h"
31 #include "pipe/p_state.h"
32 #include "pipe/internal/p_winsys_screen.h"
33
34
35 static struct pipe_buffer *
36 pass_buffer_create(struct pipe_screen *screen,
37 unsigned alignment,
38 unsigned usage,
39 unsigned size)
40 {
41 struct pipe_buffer *buffer =
42 screen->winsys->buffer_create(screen->winsys, alignment, usage, size);
43
44 buffer->screen = screen;
45
46 return buffer;
47 }
48
49 static struct pipe_buffer *
50 pass_user_buffer_create(struct pipe_screen *screen,
51 void *ptr,
52 unsigned bytes)
53 {
54 struct pipe_buffer *buffer =
55 screen->winsys->user_buffer_create(screen->winsys,
56 ptr, bytes);
57
58 buffer->screen = screen;
59
60 return buffer;
61 }
62
63 static struct pipe_buffer *
64 pass_surface_buffer_create(struct pipe_screen *screen,
65 unsigned width, unsigned height,
66 enum pipe_format format,
67 unsigned usage,
68 unsigned *stride)
69 {
70 struct pipe_buffer *buffer =
71 screen->winsys->surface_buffer_create(screen->winsys,
72 width, height,
73 format, usage, stride);
74
75 buffer->screen = screen;
76
77 return buffer;
78 }
79
80 static void *
81 pass_buffer_map(struct pipe_screen *screen,
82 struct pipe_buffer *buf,
83 unsigned usage)
84 {
85 return screen->winsys->buffer_map(screen->winsys,
86 buf, usage);
87 }
88
89 static void
90 pass_buffer_unmap(struct pipe_screen *screen,
91 struct pipe_buffer *buf)
92 {
93 screen->winsys->buffer_unmap(screen->winsys, buf);
94 }
95
96 static void
97 pass_buffer_destroy(struct pipe_buffer *buf)
98 {
99 buf->screen->winsys->buffer_destroy(buf);
100 }
101
102
103 static void
104 pass_flush_frontbuffer(struct pipe_screen *screen,
105 struct pipe_surface *surf,
106 void *context_private)
107 {
108 screen->winsys->flush_frontbuffer(screen->winsys,
109 surf, context_private);
110 }
111
112 static void
113 pass_fence_reference(struct pipe_screen *screen,
114 struct pipe_fence_handle **ptr,
115 struct pipe_fence_handle *fence)
116 {
117 screen->winsys->fence_reference(screen->winsys,
118 ptr, fence);
119 }
120
121 static int
122 pass_fence_signalled(struct pipe_screen *screen,
123 struct pipe_fence_handle *fence,
124 unsigned flag)
125 {
126 return screen->winsys->fence_signalled(screen->winsys,
127 fence, flag);
128 }
129
130 static int
131 pass_fence_finish(struct pipe_screen *screen,
132 struct pipe_fence_handle *fence,
133 unsigned flag)
134 {
135 return screen->winsys->fence_finish(screen->winsys,
136 fence, flag);
137 }
138
139 void u_simple_screen_init(struct pipe_screen *screen)
140 {
141 screen->buffer_create = pass_buffer_create;
142 screen->user_buffer_create = pass_user_buffer_create;
143 screen->surface_buffer_create = pass_surface_buffer_create;
144
145 screen->buffer_map = pass_buffer_map;
146 screen->buffer_unmap = pass_buffer_unmap;
147 screen->buffer_destroy = pass_buffer_destroy;
148 screen->flush_frontbuffer = pass_flush_frontbuffer;
149 screen->fence_reference = pass_fence_reference;
150 screen->fence_signalled = pass_fence_signalled;
151 screen->fence_finish = pass_fence_finish;
152 }
153
154 const char* u_simple_screen_winsys_name(struct pipe_screen *screen)
155 {
156 return screen->winsys->get_name(screen->winsys);
157 }