cell: Update for cpp removal.
[mesa.git] / src / gallium / drivers / cell / ppu / cell_surface.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 "pipe/p_defines.h"
29 #include "pipe/p_util.h"
30 #include "pipe/p_inlines.h"
31 #include "pipe/p_winsys.h"
32 #include "util/p_tile.h"
33 #include "cell_context.h"
34 #include "cell_surface.h"
35
36
37 static void
38 cell_surface_copy(struct pipe_context *pipe,
39 boolean do_flip,
40 struct pipe_surface *dst,
41 unsigned dstx, unsigned dsty,
42 struct pipe_surface *src,
43 unsigned srcx, unsigned srcy,
44 unsigned width, unsigned height)
45 {
46 assert( dst->cpp == src->cpp );
47
48 pipe_copy_rect(pipe_surface_map(dst),
49 &dst->block,
50 dst->stride,
51 dstx, dsty,
52 width, height,
53 pipe_surface_map(src),
54 do_flip ? -src->stride : src->stride,
55 srcx, do_flip ? height - 1 - srcy : srcy);
56
57 pipe_surface_unmap(src);
58 pipe_surface_unmap(dst);
59 }
60
61
62 static void *
63 get_pointer(struct pipe_surface *dst, void *dst_map, unsigned x, unsigned y)
64 {
65 return (char *)dst_map + y / dst->block.height * dst->stride + x / dst->block.width * dst->block.size;
66 }
67
68
69 #define UBYTE_TO_USHORT(B) ((B) | ((B) << 8))
70
71
72 /**
73 * Fill a rectangular sub-region. Need better logic about when to
74 * push buffers into AGP - will currently do so whenever possible.
75 */
76 static void
77 cell_surface_fill(struct pipe_context *pipe,
78 struct pipe_surface *dst,
79 unsigned dstx, unsigned dsty,
80 unsigned width, unsigned height, unsigned value)
81 {
82 unsigned i, j;
83 void *dst_map = pipe_surface_map(dst);
84
85 assert(dst->stride > 0);
86
87 switch (dst->block.size) {
88 case 1:
89 case 2:
90 case 4:
91 pipe_fill_rect(dst_map, &dst->block, dst->stride, dstx, dsty, width, height, value);
92 break;
93 case 8:
94 {
95 /* expand the 4-byte clear value to an 8-byte value */
96 ushort *row = (ushort *) get_pointer(dst, dst_map, dstx, dsty);
97 ushort val0 = UBYTE_TO_USHORT((value >> 0) & 0xff);
98 ushort val1 = UBYTE_TO_USHORT((value >> 8) & 0xff);
99 ushort val2 = UBYTE_TO_USHORT((value >> 16) & 0xff);
100 ushort val3 = UBYTE_TO_USHORT((value >> 24) & 0xff);
101 val0 = (val0 << 8) | val0;
102 val1 = (val1 << 8) | val1;
103 val2 = (val2 << 8) | val2;
104 val3 = (val3 << 8) | val3;
105 for (i = 0; i < height; i++) {
106 for (j = 0; j < width; j++) {
107 row[j*4+0] = val0;
108 row[j*4+1] = val1;
109 row[j*4+2] = val2;
110 row[j*4+3] = val3;
111 }
112 row += dst->stride/2;
113 }
114 }
115 break;
116 default:
117 assert(0);
118 break;
119 }
120
121 pipe_surface_unmap( dst );
122 }
123
124
125 void
126 cell_init_surface_functions(struct cell_context *cell)
127 {
128 cell->pipe.surface_copy = cell_surface_copy;
129 cell->pipe.surface_fill = cell_surface_fill;
130 }