1 /**********************************************************
2  * Copyright 2008-2012 VMware, Inc.  All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  **********************************************************/
25 
26 #include "util/u_debug.h"
27 
28 #include "svga_resource.h"
29 #include "svga_resource_buffer.h"
30 #include "svga_resource_texture.h"
31 #include "svga_context.h"
32 #include "svga_screen.h"
33 
34 
35 static struct pipe_resource *
svga_resource_create(struct pipe_screen * screen,const struct pipe_resource * template)36 svga_resource_create(struct pipe_screen *screen,
37                      const struct pipe_resource *template)
38 {
39    if (template->target == PIPE_BUFFER)
40       return svga_buffer_create(screen, template);
41    else
42       return svga_texture_create(screen, template);
43 }
44 
45 
46 static struct pipe_resource *
svga_resource_from_handle(struct pipe_screen * screen,const struct pipe_resource * template,struct winsys_handle * whandle)47 svga_resource_from_handle(struct pipe_screen * screen,
48                           const struct pipe_resource *template,
49                           struct winsys_handle *whandle)
50 {
51    if (template->target == PIPE_BUFFER)
52       return NULL;
53    else
54       return svga_texture_from_handle(screen, template, whandle);
55 }
56 
57 
58 void
svga_init_resource_functions(struct svga_context * svga)59 svga_init_resource_functions(struct svga_context *svga)
60 {
61    svga->pipe.get_transfer = u_get_transfer_vtbl;
62    svga->pipe.transfer_map = u_transfer_map_vtbl;
63    svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl;
64    svga->pipe.transfer_unmap = u_transfer_unmap_vtbl;
65    svga->pipe.transfer_destroy = u_transfer_destroy_vtbl;
66    svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl;
67 }
68 
69 void
svga_init_screen_resource_functions(struct svga_screen * is)70 svga_init_screen_resource_functions(struct svga_screen *is)
71 {
72    is->screen.resource_create = svga_resource_create;
73    is->screen.resource_from_handle = svga_resource_from_handle;
74    is->screen.resource_get_handle = u_resource_get_handle_vtbl;
75    is->screen.resource_destroy = u_resource_destroy_vtbl;
76 }
77