gallium: rename copy/fill_rect utility functions
[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_inlines.h"
33 #include "pipe/internal/p_winsys_screen.h"
34 #include "util/u_tile.h"
35 #include "util/u_rect.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 struct pipe_surface *dst,
45 unsigned dstx, unsigned dsty,
46 struct pipe_surface *src,
47 unsigned srcx, unsigned srcy, unsigned width, unsigned height)
48 {
49 assert( dst != src );
50 assert( dst->block.size == src->block.size );
51 assert( dst->block.width == src->block.height );
52 assert( dst->block.height == src->block.height );
53
54 if (0) {
55 void *dst_map = pipe->screen->surface_map( pipe->screen,
56 dst,
57 PIPE_BUFFER_USAGE_CPU_WRITE );
58
59 const void *src_map = pipe->screen->surface_map( pipe->screen,
60 src,
61 PIPE_BUFFER_USAGE_CPU_READ );
62
63 util_copy_rect(dst_map,
64 &dst->block,
65 dst->stride,
66 dstx, dsty,
67 width, height,
68 src_map,
69 src->stride,
70 srcx, srcy);
71
72 pipe->screen->surface_unmap(pipe->screen, src);
73 pipe->screen->surface_unmap(pipe->screen, dst);
74 }
75 else {
76 struct brw_texture *dst_tex = (struct brw_texture *)dst->texture;
77 struct brw_texture *src_tex = (struct brw_texture *)src->texture;
78 assert(dst->block.width == 1);
79 assert(dst->block.height == 1);
80 brw_copy_blit(brw_context(pipe),
81 FALSE,
82 dst->block.size,
83 (short) src->stride/src->block.size, src_tex->buffer, src->offset, FALSE,
84 (short) dst->stride/dst->block.size, dst_tex->buffer, dst->offset, FALSE,
85 (short) srcx, (short) srcy, (short) dstx, (short) dsty,
86 (short) width, (short) height, PIPE_LOGICOP_COPY);
87 }
88 }
89
90
91 static void
92 brw_surface_fill(struct pipe_context *pipe,
93 struct pipe_surface *dst,
94 unsigned dstx, unsigned dsty,
95 unsigned width, unsigned height, unsigned value)
96 {
97 if (0) {
98 void *dst_map = pipe->screen->surface_map( pipe->screen,
99 dst,
100 PIPE_BUFFER_USAGE_CPU_WRITE );
101
102 util_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
103
104 pipe->screen->surface_unmap(pipe->screen, dst);
105 }
106 else {
107 struct brw_texture *tex = (struct brw_texture *)dst->texture;
108 assert(dst->block.width == 1);
109 assert(dst->block.height == 1);
110 brw_fill_blit(brw_context(pipe),
111 dst->block.size,
112 (short) dst->stride/dst->block.size,
113 tex->buffer, dst->offset, FALSE,
114 (short) dstx, (short) dsty,
115 (short) width, (short) height,
116 value);
117 }
118 }
119
120
121 void
122 brw_init_surface_functions(struct brw_context *brw)
123 {
124 brw->pipe.surface_copy = brw_surface_copy;
125 brw->pipe.surface_fill = brw_surface_fill;
126 }