Squashed commit of the following:
[profile/ivi/mesa.git] / src / gallium / drivers / i915 / i915_resource.h
1 /**************************************************************************
2  * 
3  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 #ifndef I915_RESOURCE_H
29 #define I915_RESOURCE_H
30
31 struct i915_screen;
32
33 #include "util/u_transfer.h"
34 #include "util/u_debug.h"
35
36
37 struct i915_context;
38 struct i915_screen;
39
40
41 struct i915_buffer {
42    struct u_resource b;
43    uint8_t *data;
44    boolean free_on_destroy;
45 };
46
47 #define I915_MAX_TEXTURE_2D_LEVELS 11  /* max 1024x1024 */
48 #define I915_MAX_TEXTURE_3D_LEVELS  8  /* max 128x128x128 */
49
50
51
52 struct i915_texture {
53    struct u_resource b;
54
55    unsigned stride;
56    unsigned depth_stride;          /* per-image on i945? */
57    unsigned total_nblocksy;
58
59    unsigned sw_tiled; /**< tiled with software flags */
60    unsigned hw_tiled; /**< tiled with hardware fences */
61
62    unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS];
63
64    /* Explicitly store the offset of each image for each cube face or
65     * depth value.
66     */
67    unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS];   /**< array [depth] of offsets */
68
69    /* The data is held here:
70     */
71    struct i915_winsys_buffer *buffer;
72 };
73
74 void i915_init_screen_resource_functions(struct i915_screen *is);
75 void i915_init_resource_functions(struct i915_context *i915 );
76
77 extern struct u_resource_vtbl i915_buffer_vtbl;
78 extern struct u_resource_vtbl i915_texture_vtbl;
79
80 static INLINE struct i915_texture *i915_texture( struct pipe_resource *resource )
81 {
82    struct i915_texture *tex = (struct i915_texture *)resource;
83    assert(tex->b.vtbl == &i915_texture_vtbl);
84    return tex;
85 }
86
87 static INLINE struct i915_buffer *i915_buffer( struct pipe_resource *resource )
88 {
89    struct i915_buffer *tex = (struct i915_buffer *)resource;
90    assert(tex->b.vtbl == &i915_buffer_vtbl);
91    return tex;
92 }
93
94 struct pipe_resource *
95 i915_texture_create(struct pipe_screen *screen,
96                     const struct pipe_resource *template);
97
98 struct pipe_resource *
99 i915_texture_from_handle(struct pipe_screen * screen,
100                          const struct pipe_resource *template,
101                          struct winsys_handle *whandle);
102
103
104 struct pipe_resource *
105 i915_user_buffer_create(struct pipe_screen *screen,
106                         void *ptr,
107                         unsigned bytes,
108                         unsigned usage);
109
110 struct pipe_resource *
111 i915_buffer_create(struct pipe_screen *screen,
112                    const struct pipe_resource *template);
113
114 #endif /* I915_RESOURCE_H */