1 /**********************************************************
2  * Copyright 2008-2009 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 #ifndef SVGA_TEXTURE_H
27 #define SVGA_TEXTURE_H
28 
29 
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_state.h"
32 #include "util/u_inlines.h"
33 #include "util/u_transfer.h"
34 #include "svga_screen_cache.h"
35 
36 struct pipe_context;
37 struct pipe_screen;
38 struct svga_context;
39 struct svga_winsys_surface;
40 enum SVGA3dSurfaceFormat;
41 
42 
43 #define SVGA_MAX_TEXTURE_LEVELS 16
44 
45 
46 extern struct u_resource_vtbl svga_texture_vtbl;
47 
48 
49 struct svga_texture
50 {
51    struct u_resource b;
52 
53    boolean defined[6][SVGA_MAX_TEXTURE_LEVELS];
54 
55    struct svga_sampler_view *cached_view;
56 
57    unsigned view_age[SVGA_MAX_TEXTURE_LEVELS];
58    unsigned age;
59 
60    boolean views_modified;
61 
62    /**
63     * Creation key for the host surface handle.
64     *
65     * This structure describes all the host surface characteristics so that it
66     * can be looked up in cache, since creating a host surface is often a slow
67     * operation.
68     */
69    struct svga_host_surface_cache_key key;
70 
71    /**
72     * Handle for the host side surface.
73     *
74     * This handle is owned by this texture. Views should hold on to a reference
75     * to this texture and never destroy this handle directly.
76     */
77    struct svga_winsys_surface *handle;
78 };
79 
80 
81 
82 /* Note this is only used for texture (not buffer) transfers:
83  */
84 struct svga_transfer
85 {
86    struct pipe_transfer base;
87 
88    unsigned face;
89 
90    struct svga_winsys_buffer *hwbuf;
91 
92    /* Height of the hardware buffer in pixel blocks */
93    unsigned hw_nblocksy;
94 
95    /* Temporary malloc buffer when we can't allocate a hardware buffer
96     * big enough */
97    void *swbuf;
98 };
99 
100 
svga_texture(struct pipe_resource * resource)101 static INLINE struct svga_texture *svga_texture( struct pipe_resource *resource )
102 {
103    struct svga_texture *tex = (struct svga_texture *)resource;
104    assert(tex == NULL || tex->b.vtbl == &svga_texture_vtbl);
105    return tex;
106 }
107 
108 
109 static INLINE struct svga_transfer *
svga_transfer(struct pipe_transfer * transfer)110 svga_transfer(struct pipe_transfer *transfer)
111 {
112    assert(transfer);
113    return (struct svga_transfer *)transfer;
114 }
115 
116 
117 
118 struct pipe_resource *
119 svga_texture_create(struct pipe_screen *screen,
120                     const struct pipe_resource *template);
121 
122 struct pipe_resource *
123 svga_texture_from_handle(struct pipe_screen * screen,
124 			const struct pipe_resource *template,
125 			struct winsys_handle *whandle);
126 
127 
128 
129 
130 #endif /* SVGA_TEXTURE_H */
131