gallium: move pipe_copy_rect(), pipe_fill_rect() protos into new u_rect.h header
[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 #include "util/u_rect.h"
37
38
39
40 /* Assumes all values are within bounds -- no checking at this level -
41 * do it higher up if required.
42 */
43 static void
44 brw_surface_copy(struct pipe_context *pipe,
45 boolean do_flip,
46 struct pipe_surface *dst,
47 unsigned dstx, unsigned dsty,
48 struct pipe_surface *src,
49 unsigned srcx, unsigned srcy, unsigned width, unsigned height)
50 {
51 assert( dst != src );
52 assert( dst->block.size == src->block.size );
53 assert( dst->block.width == src->block.height );
54 assert( dst->block.height == src->block.height );
55
56 if (0) {
57 void *dst_map = pipe->screen->surface_map( pipe->screen,
58 dst,
59 PIPE_BUFFER_USAGE_CPU_WRITE );
60
61 const void *src_map = pipe->screen->surface_map( pipe->screen,
62 src,
63 PIPE_BUFFER_USAGE_CPU_READ );
64
65 pipe_copy_rect(dst_map,
66 &dst->block,
67 dst->stride,
68 dstx, dsty,
69 width, height,
70 src_map,
71 do_flip ? -(int) src->stride : src->stride,
72 srcx, do_flip ? height - 1 - srcy : srcy);
73
74 pipe->screen->surface_unmap(pipe->screen, src);
75 pipe->screen->surface_unmap(pipe->screen, dst);
76 }
77 else {
78 assert(dst->block.width == 1);
79 assert(dst->block.height == 1);
80 brw_copy_blit(brw_context(pipe),
81 do_flip,
82 dst->block.size,
83 (short) src->stride/src->block.size, src->buffer, src->offset, FALSE,
84 (short) dst->stride/dst->block.size, dst->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 pipe_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 assert(dst->block.width == 1);
108 assert(dst->block.height == 1);
109 brw_fill_blit(brw_context(pipe),
110 dst->block.size,
111 (short) dst->stride/dst->block.size,
112 dst->buffer, dst->offset, FALSE,
113 (short) dstx, (short) dsty,
114 (short) width, (short) height,
115 value);
116 }
117 }
118
119
120 void
121 brw_init_surface_functions(struct brw_context *brw)
122 {
123 brw->pipe.surface_copy = brw_surface_copy;
124 brw->pipe.surface_fill = brw_surface_fill;
125 }