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 VMWARE 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 #include "pipe/p_screen.h"
30 #include "pipe/p_state.h"
31 #include "util/u_memory.h"
32 
33 #include "id_public.h"
34 #include "id_screen.h"
35 #include "id_context.h"
36 #include "id_objects.h"
37 
38 
39 static void
identity_screen_destroy(struct pipe_screen * _screen)40 identity_screen_destroy(struct pipe_screen *_screen)
41 {
42    struct identity_screen *id_screen = identity_screen(_screen);
43    struct pipe_screen *screen = id_screen->screen;
44 
45    screen->destroy(screen);
46 
47    FREE(id_screen);
48 }
49 
50 static const char *
identity_screen_get_name(struct pipe_screen * _screen)51 identity_screen_get_name(struct pipe_screen *_screen)
52 {
53    struct identity_screen *id_screen = identity_screen(_screen);
54    struct pipe_screen *screen = id_screen->screen;
55 
56    return screen->get_name(screen);
57 }
58 
59 static const char *
identity_screen_get_vendor(struct pipe_screen * _screen)60 identity_screen_get_vendor(struct pipe_screen *_screen)
61 {
62    struct identity_screen *id_screen = identity_screen(_screen);
63    struct pipe_screen *screen = id_screen->screen;
64 
65    return screen->get_vendor(screen);
66 }
67 
68 static int
identity_screen_get_param(struct pipe_screen * _screen,enum pipe_cap param)69 identity_screen_get_param(struct pipe_screen *_screen,
70                           enum pipe_cap param)
71 {
72    struct identity_screen *id_screen = identity_screen(_screen);
73    struct pipe_screen *screen = id_screen->screen;
74 
75    return screen->get_param(screen,
76                             param);
77 }
78 
79 static int
identity_screen_get_shader_param(struct pipe_screen * _screen,unsigned shader,enum pipe_shader_cap param)80 identity_screen_get_shader_param(struct pipe_screen *_screen,
81                           unsigned shader, enum pipe_shader_cap param)
82 {
83    struct identity_screen *id_screen = identity_screen(_screen);
84    struct pipe_screen *screen = id_screen->screen;
85 
86    return screen->get_shader_param(screen, shader,
87                             param);
88 }
89 
90 static float
identity_screen_get_paramf(struct pipe_screen * _screen,enum pipe_capf param)91 identity_screen_get_paramf(struct pipe_screen *_screen,
92                            enum pipe_capf param)
93 {
94    struct identity_screen *id_screen = identity_screen(_screen);
95    struct pipe_screen *screen = id_screen->screen;
96 
97    return screen->get_paramf(screen,
98                              param);
99 }
100 
101 static boolean
identity_screen_is_format_supported(struct pipe_screen * _screen,enum pipe_format format,enum pipe_texture_target target,unsigned sample_count,unsigned tex_usage)102 identity_screen_is_format_supported(struct pipe_screen *_screen,
103                                     enum pipe_format format,
104                                     enum pipe_texture_target target,
105                                     unsigned sample_count,
106                                     unsigned tex_usage)
107 {
108    struct identity_screen *id_screen = identity_screen(_screen);
109    struct pipe_screen *screen = id_screen->screen;
110 
111    return screen->is_format_supported(screen,
112                                       format,
113                                       target,
114                                       sample_count,
115                                       tex_usage);
116 }
117 
118 static struct pipe_context *
identity_screen_context_create(struct pipe_screen * _screen,void * priv)119 identity_screen_context_create(struct pipe_screen *_screen,
120                                void *priv)
121 {
122    struct identity_screen *id_screen = identity_screen(_screen);
123    struct pipe_screen *screen = id_screen->screen;
124    struct pipe_context *result;
125 
126    result = screen->context_create(screen, priv);
127    if (result)
128       return identity_context_create(_screen, result);
129    return NULL;
130 }
131 
132 static struct pipe_resource *
identity_screen_resource_create(struct pipe_screen * _screen,const struct pipe_resource * templat)133 identity_screen_resource_create(struct pipe_screen *_screen,
134                                 const struct pipe_resource *templat)
135 {
136    struct identity_screen *id_screen = identity_screen(_screen);
137    struct pipe_screen *screen = id_screen->screen;
138    struct pipe_resource *result;
139 
140    result = screen->resource_create(screen,
141                                     templat);
142 
143    if (result)
144       return identity_resource_create(id_screen, result);
145    return NULL;
146 }
147 
148 static struct pipe_resource *
identity_screen_resource_from_handle(struct pipe_screen * _screen,const struct pipe_resource * templ,struct winsys_handle * handle)149 identity_screen_resource_from_handle(struct pipe_screen *_screen,
150                                      const struct pipe_resource *templ,
151                                      struct winsys_handle *handle)
152 {
153    struct identity_screen *id_screen = identity_screen(_screen);
154    struct pipe_screen *screen = id_screen->screen;
155    struct pipe_resource *result;
156 
157    /* TODO trace call */
158 
159    result = screen->resource_from_handle(screen, templ, handle);
160 
161    result = identity_resource_create(identity_screen(_screen), result);
162 
163    return result;
164 }
165 
166 static boolean
identity_screen_resource_get_handle(struct pipe_screen * _screen,struct pipe_resource * _resource,struct winsys_handle * handle)167 identity_screen_resource_get_handle(struct pipe_screen *_screen,
168                                     struct pipe_resource *_resource,
169                                     struct winsys_handle *handle)
170 {
171    struct identity_screen *id_screen = identity_screen(_screen);
172    struct identity_resource *id_resource = identity_resource(_resource);
173    struct pipe_screen *screen = id_screen->screen;
174    struct pipe_resource *resource = id_resource->resource;
175 
176    /* TODO trace call */
177 
178    return screen->resource_get_handle(screen, resource, handle);
179 }
180 
181 
182 
183 static void
identity_screen_resource_destroy(struct pipe_screen * screen,struct pipe_resource * _resource)184 identity_screen_resource_destroy(struct pipe_screen *screen,
185                                  struct pipe_resource *_resource)
186 {
187    identity_resource_destroy(identity_resource(_resource));
188 }
189 
190 
191 static void
identity_screen_flush_frontbuffer(struct pipe_screen * _screen,struct pipe_resource * _resource,unsigned level,unsigned layer,void * context_private)192 identity_screen_flush_frontbuffer(struct pipe_screen *_screen,
193                                   struct pipe_resource *_resource,
194                                   unsigned level, unsigned layer,
195                                   void *context_private)
196 {
197    struct identity_screen *id_screen = identity_screen(_screen);
198    struct identity_resource *id_resource = identity_resource(_resource);
199    struct pipe_screen *screen = id_screen->screen;
200    struct pipe_resource *resource = id_resource->resource;
201 
202    screen->flush_frontbuffer(screen,
203                              resource,
204                              level, layer,
205                              context_private);
206 }
207 
208 static void
identity_screen_fence_reference(struct pipe_screen * _screen,struct pipe_fence_handle ** ptr,struct pipe_fence_handle * fence)209 identity_screen_fence_reference(struct pipe_screen *_screen,
210                                 struct pipe_fence_handle **ptr,
211                                 struct pipe_fence_handle *fence)
212 {
213    struct identity_screen *id_screen = identity_screen(_screen);
214    struct pipe_screen *screen = id_screen->screen;
215 
216    screen->fence_reference(screen,
217                            ptr,
218                            fence);
219 }
220 
221 static boolean
identity_screen_fence_signalled(struct pipe_screen * _screen,struct pipe_fence_handle * fence)222 identity_screen_fence_signalled(struct pipe_screen *_screen,
223                                 struct pipe_fence_handle *fence)
224 {
225    struct identity_screen *id_screen = identity_screen(_screen);
226    struct pipe_screen *screen = id_screen->screen;
227 
228    return screen->fence_signalled(screen,
229                                   fence);
230 }
231 
232 static boolean
identity_screen_fence_finish(struct pipe_screen * _screen,struct pipe_fence_handle * fence,uint64_t timeout)233 identity_screen_fence_finish(struct pipe_screen *_screen,
234                              struct pipe_fence_handle *fence,
235                              uint64_t timeout)
236 {
237    struct identity_screen *id_screen = identity_screen(_screen);
238    struct pipe_screen *screen = id_screen->screen;
239 
240    return screen->fence_finish(screen,
241                                fence,
242                                timeout);
243 }
244 
245 static uint64_t
identity_screen_get_timestamp(struct pipe_screen * _screen)246 identity_screen_get_timestamp(struct pipe_screen *_screen)
247 {
248    struct identity_screen *id_screen = identity_screen(_screen);
249    struct pipe_screen *screen = id_screen->screen;
250 
251    return screen->get_timestamp(screen);
252 }
253 
254 struct pipe_screen *
identity_screen_create(struct pipe_screen * screen)255 identity_screen_create(struct pipe_screen *screen)
256 {
257    struct identity_screen *id_screen;
258 
259    id_screen = CALLOC_STRUCT(identity_screen);
260    if (!id_screen) {
261       return NULL;
262    }
263 
264    id_screen->base.destroy = identity_screen_destroy;
265    id_screen->base.get_name = identity_screen_get_name;
266    id_screen->base.get_vendor = identity_screen_get_vendor;
267    id_screen->base.get_param = identity_screen_get_param;
268    id_screen->base.get_shader_param = identity_screen_get_shader_param;
269    id_screen->base.get_paramf = identity_screen_get_paramf;
270    id_screen->base.is_format_supported = identity_screen_is_format_supported;
271    id_screen->base.context_create = identity_screen_context_create;
272    id_screen->base.resource_create = identity_screen_resource_create;
273    id_screen->base.resource_from_handle = identity_screen_resource_from_handle;
274    id_screen->base.resource_get_handle = identity_screen_resource_get_handle;
275    id_screen->base.resource_destroy = identity_screen_resource_destroy;
276    id_screen->base.flush_frontbuffer = identity_screen_flush_frontbuffer;
277    id_screen->base.fence_reference = identity_screen_fence_reference;
278    id_screen->base.fence_signalled = identity_screen_fence_signalled;
279    id_screen->base.fence_finish = identity_screen_fence_finish;
280    id_screen->base.get_timestamp = identity_screen_get_timestamp;
281 
282    id_screen->screen = screen;
283 
284    return &id_screen->base;
285 }
286