2 /**************************************************************************
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
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"
37 nv40_surface_format_supported(struct pipe_context *pipe,
38 enum pipe_format format, uint type)
43 case PIPE_FORMAT_A8R8G8B8_UNORM:
44 case PIPE_FORMAT_R5G6B5_UNORM:
45 case PIPE_FORMAT_Z24S8_UNORM:
46 case PIPE_FORMAT_Z16_UNORM:
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:
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)
80 struct pipe_winsys *ws = pipe->winsys;
81 struct nv40_miptree *nv40mt = (struct nv40_miptree *)pt;
82 struct pipe_surface *ps;
84 ps = ws->surface_alloc(ws);
87 ws->buffer_reference(ws, &ps->buffer, nv40mt->buffer);
88 ps->format = pt->format;
90 ps->width = pt->width[level];
91 ps->height = pt->height[level];
92 ps->pitch = nv40mt->level[level].pitch / ps->cpp;
94 if (pt->target == PIPE_TEXTURE_CUBE) {
95 ps->offset = nv40mt->level[level].image_offset[face];
97 if (pt->target == PIPE_TEXTURE_3D) {
98 ps->offset = nv40mt->level[level].image_offset[zslice];
100 ps->offset = nv40mt->level[level].image_offset[0];
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)
112 struct nv40_context *nv40 = (struct nv40_context *)pipe;
113 struct nouveau_winsys *nvws = nv40->nvws;
115 nvws->surface_data(nvws, dest, destx, desty, src, src_stride,
116 srcx, srcy, width, height);
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)
124 struct nv40_context *nv40 = (struct nv40_context *)pipe;
125 struct nouveau_winsys *nvws = nv40->nvws;
127 nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy,
132 nv40_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
133 unsigned destx, unsigned desty, unsigned width,
134 unsigned height, unsigned value)
136 struct nv40_context *nv40 = (struct nv40_context *)pipe;
137 struct nouveau_winsys *nvws = nv40->nvws;
139 nvws->surface_fill(nvws, dest, destx, desty, width, height, value);
143 nv40_init_surface_functions(struct nv40_context *nv40)
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;