nouveau: match gallium code reorginisation.
[mesa.git] / src / gallium / drivers / nv30 / nv30_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 "nv30_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 "util/p_tile.h"
35
36 static boolean
37 nv30_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 nv30_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 nv30_miptree *nv30mt = (struct nv30_miptree *)pt;
82 struct pipe_surface *ps;
83
84 ps = ws->surface_alloc(ws);
85 if (!ps)
86 return NULL;
87 pipe_buffer_reference(ws, &ps->buffer, nv30mt->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 = nv30mt->level[level].pitch / ps->cpp;
93
94 if (pt->target == PIPE_TEXTURE_CUBE) {
95 ps->offset = nv30mt->level[level].image_offset[face];
96 } else
97 if (pt->target == PIPE_TEXTURE_3D) {
98 ps->offset = nv30mt->level[level].image_offset[zslice];
99 } else {
100 ps->offset = nv30mt->level[level].image_offset[0];
101 }
102
103 return ps;
104 }
105
106 static void
107 nv30_surface_copy(struct pipe_context *pipe, unsigned do_flip,
108 struct pipe_surface *dest, unsigned destx, unsigned desty,
109 struct pipe_surface *src, unsigned srcx, unsigned srcy,
110 unsigned width, unsigned height)
111 {
112 struct nv30_context *nv30 = nv30_context(pipe);
113 struct nouveau_winsys *nvws = nv30->nvws;
114
115 nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy,
116 width, height);
117 }
118
119 static void
120 nv30_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
121 unsigned destx, unsigned desty, unsigned width,
122 unsigned height, unsigned value)
123 {
124 struct nv30_context *nv30 = nv30_context(pipe);
125 struct nouveau_winsys *nvws = nv30->nvws;
126
127 nvws->surface_fill(nvws, dest, destx, desty, width, height, value);
128 }
129
130 void
131 nv30_init_surface_functions(struct nv30_context *nv30)
132 {
133 nv30->pipe.is_format_supported = nv30_surface_format_supported;
134 nv30->pipe.get_tex_surface = nv30_get_tex_surface;
135 nv30->pipe.surface_copy = nv30_surface_copy;
136 nv30->pipe.surface_fill = nv30_surface_fill;
137 }