Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / i965 / brw_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 BRW_RESOURCE_H
29 #define BRW_RESOURCE_H
30
31 struct brw_screen;
32
33 #include "util/u_transfer.h"
34 #include "util/u_debug.h"
35
36 #include "brw_screen.h"         /* for brw_surface */
37
38 struct brw_context;
39 struct brw_screen;
40
41
42 struct brw_buffer {
43    struct u_resource b;
44
45    /* One of either bo or user_buffer will be non-null, depending on
46     * whether this is a hardware or user buffer.
47     */
48    struct brw_winsys_buffer *bo;
49    void *user_buffer;
50
51    /* Mapped pointer??
52     */
53    void *ptr;
54 };
55
56 #define BRW_MAX_TEXTURE_2D_LEVELS 11  /* max 1024x1024 */
57 #define BRW_MAX_TEXTURE_3D_LEVELS  8  /* max 128x128x128 */
58
59
60
61 struct brw_texture {
62    struct u_resource b;
63    struct brw_winsys_buffer *bo;
64    struct brw_surface_state ss;
65
66    unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS];
67    unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS];
68    unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS];
69
70    boolean compressed;
71    unsigned brw_target;
72    unsigned pitch;
73    unsigned tiling;
74    unsigned cpp;
75    unsigned total_height;
76
77    struct brw_surface views[2];
78 };
79
80
81 void brw_init_screen_resource_functions(struct brw_screen *is);
82 void brw_init_resource_functions(struct brw_context *brw );
83
84 extern struct u_resource_vtbl brw_buffer_vtbl;
85 extern struct u_resource_vtbl brw_texture_vtbl;
86
87 static INLINE struct brw_texture *brw_texture( struct pipe_resource *resource )
88 {
89    struct brw_texture *tex = (struct brw_texture *)resource;
90    assert(tex->b.vtbl == &brw_texture_vtbl);
91    return tex;
92 }
93
94 static INLINE struct brw_buffer *brw_buffer( struct pipe_resource *resource )
95 {
96    struct brw_buffer *tex = (struct brw_buffer *)resource;
97    assert(tex->b.vtbl == &brw_buffer_vtbl);
98    return tex;
99 }
100
101 struct pipe_resource *
102 brw_texture_create(struct pipe_screen *screen,
103                     const struct pipe_resource *template);
104
105 struct pipe_resource *
106 brw_texture_from_handle(struct pipe_screen * screen,
107                         const struct pipe_resource *template,
108                         struct winsys_handle *whandle);
109
110
111 struct pipe_resource *
112 brw_user_buffer_create(struct pipe_screen *screen,
113                         void *ptr,
114                         unsigned bytes,
115                         unsigned usage);
116
117 struct pipe_resource *
118 brw_buffer_create(struct pipe_screen *screen,
119                    const struct pipe_resource *template);
120
121
122 /*
123 boolean
124 brw_is_format_supported( struct pipe_screen *screen,
125                          enum pipe_format format,
126                          enum pipe_texture_target target,
127                          unsigned sample_count,
128                          unsigned tex_usage,
129                          unsigned geom_flags );
130 */
131
132 /* Pipe buffer helpers
133  */
134 static INLINE boolean
135 brw_buffer_is_user_buffer( const struct pipe_resource *buf )
136 {
137    return ((const struct brw_buffer *)buf)->user_buffer != NULL;
138 }
139
140
141 /***********************************************************************
142  * Internal functions 
143  */
144 GLboolean brw_texture_layout(struct brw_screen *brw_screen,
145                              struct brw_texture *tex );
146
147 void brw_update_texture( struct brw_screen *brw_screen,
148                          struct brw_texture *tex );
149
150
151
152 #endif /* BRW_RESOURCE_H */