Merge branch 'gallium-0.2' into gallium-winsys-private
[mesa.git] / src / gallium / drivers / nv50 / nv50_surface.c
1 /*
2 * Copyright 2008 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "nv50_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_winsys.h"
26 #include "pipe/p_inlines.h"
27
28 #include "util/u_tile.h"
29
30 static void
31 nv50_surface_copy(struct pipe_context *pipe, boolean flip,
32 struct pipe_surface *dest, unsigned destx, unsigned desty,
33 struct pipe_surface *src, unsigned srcx, unsigned srcy,
34 unsigned width, unsigned height)
35 {
36 struct nv50_context *nv50 = (struct nv50_context *)pipe;
37 struct nouveau_winsys *nvws = nv50->screen->nvws;
38
39 if (flip) {
40 desty += height;
41 while (height--) {
42 nvws->surface_copy(nvws, dest, destx, desty--, src,
43 srcx, srcy++, width, 1);
44 }
45 } else {
46 nvws->surface_copy(nvws, dest, destx, desty, src, srcx, srcy,
47 width, height);
48 }
49 }
50
51 static void
52 nv50_surface_fill(struct pipe_context *pipe, struct pipe_surface *dest,
53 unsigned destx, unsigned desty, unsigned width,
54 unsigned height, unsigned value)
55 {
56 struct nv50_context *nv50 = (struct nv50_context *)pipe;
57 struct nouveau_winsys *nvws = nv50->screen->nvws;
58
59 nvws->surface_fill(nvws, dest, destx, desty, width, height, value);
60 }
61
62 static void *
63 nv50_surface_map(struct pipe_screen *screen, struct pipe_surface *ps,
64 unsigned flags )
65 {
66 struct pipe_winsys *ws = screen->winsys;
67
68 return ws->_buffer_map(ws, ps->buffer, flags);
69 }
70
71 static void
72 nv50_surface_unmap(struct pipe_screen *pscreen, struct pipe_surface *ps)
73 {
74 struct pipe_winsys *ws = pscreen->winsys;
75
76 ws->_buffer_unmap(ws, ps->buffer);
77 }
78
79 void
80 nv50_init_surface_functions(struct nv50_context *nv50)
81 {
82 nv50->pipe.surface_copy = nv50_surface_copy;
83 nv50->pipe.surface_fill = nv50_surface_fill;
84 }
85
86 void
87 nv50_surface_init_screen_functions(struct pipe_screen *pscreen)
88 {
89 pscreen->surface_map = nv50_surface_map;
90 pscreen->surface_unmap = nv50_surface_unmap;
91 }
92