91ac9e3694865b1feff543f8469a6bda9a633b27
[profile/ivi/mesa.git] / src / mesa / pipe / nv40 / nv40_surface.c
1
2 /**************************************************************************
3  * 
4  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5  * All Rights Reserved.
6  * 
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  * 
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  * 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  * 
27  **************************************************************************/
28
29 #include "nv40_context.h"
30 #include "pipe/p_defines.h"
31 #include "pipe/p_util.h"
32 #include "pipe/p_winsys.h"
33 #include "pipe/p_inlines.h"
34 #include "pipe/util/p_tile.h"
35
36 static boolean
37 nv40_surface_format_supported(struct pipe_context *pipe,
38                               enum pipe_format format, uint type)
39 {
40         switch (type) {
41         case PIPE_SURFACE:
42                 switch (format) {
43                 case PIPE_FORMAT_A8R8G8B8_UNORM:
44                 case PIPE_FORMAT_R5G6B5_UNORM: 
45                 case PIPE_FORMAT_Z24S8_UNORM:
46                 case PIPE_FORMAT_Z16_UNORM:
47                         return TRUE;
48                 default:
49                         break;
50                 }
51                 break;
52         case PIPE_TEXTURE:
53                 switch (format) {
54                 case PIPE_FORMAT_A8R8G8B8_UNORM:
55                 case PIPE_FORMAT_A1R5G5B5_UNORM:
56                 case PIPE_FORMAT_A4R4G4B4_UNORM:
57                 case PIPE_FORMAT_R5G6B5_UNORM: 
58                 case PIPE_FORMAT_U_L8:
59                 case PIPE_FORMAT_U_A8:
60                 case PIPE_FORMAT_U_I8:
61                 case PIPE_FORMAT_U_A8_L8:
62                 case PIPE_FORMAT_Z16_UNORM:
63                 case PIPE_FORMAT_Z24S8_UNORM:
64                         return TRUE;
65                 default:
66                         break;
67                 }
68                 break;
69         default:
70                 assert(0);
71         };
72
73         return FALSE;
74 }
75
76 static struct pipe_surface *
77 nv40_get_tex_surface(struct pipe_context *pipe, struct pipe_texture *pt,
78                      unsigned face, unsigned level, unsigned zslice)
79 {
80         struct pipe_winsys *ws = pipe->winsys;
81         struct nv40_miptree *nv40mt = (struct nv40_miptree *)pt;
82         struct pipe_surface *ps;
83
84         ps = ws->surface_alloc(ws);
85         if (!ps)
86                 return NULL;
87         ws->buffer_reference(ws, &ps->buffer, nv40mt->buffer);
88         ps->format = pt->format;
89         ps->cpp = pt->cpp;
90         ps->width = pt->width[level];
91         ps->height = pt->height[level];
92         ps->pitch = nv40mt->level[level].pitch / ps->cpp;
93
94         if (pt->target == PIPE_TEXTURE_CUBE) {
95                 ps->offset = nv40mt->level[level].image_offset[face];
96         } else
97         if (pt->target == PIPE_TEXTURE_3D) {
98                 ps->offset = nv40mt->level[level].image_offset[zslice];
99         } else {
100                 ps->offset = nv40mt->level[level].image_offset[0];
101         }
102
103         return ps;
104 }
105
106 static void
107 nv40_surface_data(struct pipe_context *pipe, struct pipe_surface *dest,
108                   unsigned destx, unsigned desty, const void *src,
109                   unsigned src_stride, unsigned srcx, unsigned srcy,
110                   unsigned width, unsigned height)
111 {
112         struct nv40_context *nv40 = (struct nv40_context *)pipe;
113         struct nouveau_winsys *nvws = nv40->nvws;
114
115         nvws->surface_data(nvws, dest, destx, desty, src, src_stride,
116                            srcx, srcy, width, height);
117 }
118
119 static void
120 nv40_surface_copy(struct pipe_context *pipe, struct pipe_surface *dest,
121                   unsigned destx, unsigned desty, struct pipe_surface *src,
122                   unsigned srcx, unsigned srcy, unsigned width, unsigned height)
123 {
124         struct nv40_context *nv40 = (struct nv40_context *)pipe;
125         struct nouveau_winsys *nvws = nv40->nvws;
126
127         nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy,
128                            width, height);
129 }
130
131 static void
132 nv40_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
133                   unsigned destx, unsigned desty, unsigned width,
134                   unsigned height, unsigned value)
135 {
136         struct nv40_context *nv40 = (struct nv40_context *)pipe;
137         struct nouveau_winsys *nvws = nv40->nvws;
138
139         nvws->surface_fill(nvws, dest, destx, desty, width, height, value);
140 }
141
142 void
143 nv40_init_surface_functions(struct nv40_context *nv40)
144 {
145         nv40->pipe.is_format_supported = nv40_surface_format_supported;
146         nv40->pipe.get_tex_surface = nv40_get_tex_surface;
147         nv40->pipe.get_tile = pipe_get_tile_raw;
148         nv40->pipe.put_tile = pipe_put_tile_raw;
149         nv40->pipe.surface_data = nv40_surface_data;
150         nv40->pipe.surface_copy = nv40_surface_copy;
151         nv40->pipe.surface_fill = nv40_surface_fill;
152 }