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