159d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul/**********************************************************
259d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * Copyright 2008-2012 VMware, Inc.  All rights reserved.
359d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul *
459d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * Permission is hereby granted, free of charge, to any person
559d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * obtaining a copy of this software and associated documentation
659d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * files (the "Software"), to deal in the Software without
759d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * restriction, including without limitation the rights to use, copy,
859d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * modify, merge, publish, distribute, sublicense, and/or sell copies
959d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * of the Software, and to permit persons to whom the Software is
1059d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * furnished to do so, subject to the following conditions:
1159d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul *
1259d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * The above copyright notice and this permission notice shall be
1359d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * included in all copies or substantial portions of the Software.
1459d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul *
1559d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1659d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1759d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1859d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
1959d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2059d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2159d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2259d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul * SOFTWARE.
2359d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul *
2459d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul **********************************************************/
2559d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul
26287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "util/u_debug.h"
27287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
28287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "svga_resource.h"
29287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "svga_resource_buffer.h"
30287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "svga_resource_texture.h"
31287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "svga_context.h"
32287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell#include "svga_screen.h"
33287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
34287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
35287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstatic struct pipe_resource *
36287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellsvga_resource_create(struct pipe_screen *screen,
3759d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul                     const struct pipe_resource *template)
38287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
39287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   if (template->target == PIPE_BUFFER)
40287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell      return svga_buffer_create(screen, template);
41287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   else
422a5667a0082232b63a957841c4ae45a88860955eJakob Bornecrantz      return svga_texture_create(screen, template);
43287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
44287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
4559d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul
46287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstatic struct pipe_resource *
47287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellsvga_resource_from_handle(struct pipe_screen * screen,
4859d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul                          const struct pipe_resource *template,
4959d2c4f8e5a00133c093137b2f4836313f633d60Brian Paul                          struct winsys_handle *whandle)
50287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
51287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   if (template->target == PIPE_BUFFER)
52287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell      return NULL;
53287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   else
5435d960cc744c374ccaad48c3d80559b59c74e28aJakob Bornecrantz      return svga_texture_from_handle(screen, template, whandle);
55287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
56287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
57287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
58287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid
59287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellsvga_init_resource_functions(struct svga_context *svga)
60287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
61287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.get_transfer = u_get_transfer_vtbl;
62287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.transfer_map = u_transfer_map_vtbl;
63287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.transfer_flush_region = u_transfer_flush_region_vtbl;
64287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.transfer_unmap = u_transfer_unmap_vtbl;
65287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.transfer_destroy = u_transfer_destroy_vtbl;
66287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   svga->pipe.transfer_inline_write = u_transfer_inline_write_vtbl;
67287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
68287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell
69287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellvoid
70287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellsvga_init_screen_resource_functions(struct svga_screen *is)
71287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell{
72287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   is->screen.resource_create = svga_resource_create;
73287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   is->screen.resource_from_handle = svga_resource_from_handle;
74287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   is->screen.resource_get_handle = u_resource_get_handle_vtbl;
75287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   is->screen.resource_destroy = u_resource_destroy_vtbl;
76287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell}
77