Merge branch 'gallium-0.1' into gallium-tex-surfaces
[mesa.git] / src / gallium / drivers / i965simple / brw_surface.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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 #include "brw_blit.h"
29 #include "brw_context.h"
30 #include "brw_state.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_util.h"
33 #include "pipe/p_inlines.h"
34 #include "pipe/p_winsys.h"
35 #include "util/p_tile.h"
36
37
38
39 /* Assumes all values are within bounds -- no checking at this level -
40 * do it higher up if required.
41 */
42 static void
43 brw_surface_copy(struct pipe_context *pipe,
44 unsigned do_flip,
45 struct pipe_surface *dst,
46 unsigned dstx, unsigned dsty,
47 struct pipe_surface *src,
48 unsigned srcx, unsigned srcy, unsigned width, unsigned height)
49 {
50 assert(dst != src);
51 assert(dst->cpp == src->cpp);
52
53 if (0) {
54 void *dst_map = pipe->screen->surface_map( pipe->screen,
55 dst,
56 PIPE_BUFFER_USAGE_CPU_WRITE );
57
58 const void *src_map = pipe->screen->surface_map( pipe->screen,
59 src,
60 PIPE_BUFFER_USAGE_CPU_READ );
61
62 pipe_copy_rect(dst_map,
63 dst->cpp,
64 dst->pitch,
65 dstx, dsty,
66 width, height,
67 src_map,
68 do_flip ? -(int) src->pitch : src->pitch,
69 srcx, do_flip ? 1 - srcy - height : srcy);
70
71 pipe->screen->surface_unmap(pipe->screen, src);
72 pipe->screen->surface_unmap(pipe->screen, dst);
73 }
74 else {
75 brw_copy_blit(brw_context(pipe),
76 do_flip,
77 dst->cpp,
78 (short) src->pitch, src->buffer, src->offset, FALSE,
79 (short) dst->pitch, dst->buffer, dst->offset, FALSE,
80 (short) srcx, (short) srcy, (short) dstx, (short) dsty,
81 (short) width, (short) height, PIPE_LOGICOP_COPY);
82 }
83 }
84
85 /* Fill a rectangular sub-region. Need better logic about when to
86 * push buffers into AGP - will currently do so whenever possible.
87 */
88 static void *
89 get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
90 {
91 return (char *)dst_map + (y * dst->pitch + x) * dst->cpp;
92 }
93
94
95 static void
96 brw_surface_fill(struct pipe_context *pipe,
97 struct pipe_surface *dst,
98 unsigned dstx, unsigned dsty,
99 unsigned width, unsigned height, unsigned value)
100 {
101 if (0) {
102 unsigned i, j;
103 void *dst_map = pipe->screen->surface_map( pipe->screen,
104 dst,
105 PIPE_BUFFER_USAGE_CPU_WRITE );
106
107
108 switch (dst->cpp) {
109 case 1: {
110 ubyte *row = get_pointer(dst, dst_map, dstx, dsty);
111 for (i = 0; i < height; i++) {
112 memset(row, value, width);
113 row += dst->pitch;
114 }
115 }
116 break;
117 case 2: {
118 ushort *row = get_pointer(dst, dst_map, dstx, dsty);
119 for (i = 0; i < height; i++) {
120 for (j = 0; j < width; j++)
121 row[j] = (ushort) value;
122 row += dst->pitch;
123 }
124 }
125 break;
126 case 4: {
127 unsigned *row = get_pointer(dst, dst_map, dstx, dsty);
128 for (i = 0; i < height; i++) {
129 for (j = 0; j < width; j++)
130 row[j] = value;
131 row += dst->pitch;
132 }
133 }
134 break;
135 default:
136 assert(0);
137 break;
138 }
139
140 pipe->screen->surface_unmap(pipe->screen, dst);
141 }
142 else {
143 brw_fill_blit(brw_context(pipe),
144 dst->cpp,
145 (short) dst->pitch,
146 dst->buffer, dst->offset, FALSE,
147 (short) dstx, (short) dsty,
148 (short) width, (short) height,
149 value);
150 }
151 }
152
153
154 void
155 brw_init_surface_functions(struct brw_context *brw)
156 {
157 brw->pipe.surface_copy = brw_surface_copy;
158 brw->pipe.surface_fill = brw_surface_fill;
159 }