1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_rect.h"
29 #include "lp_context.h"
31 #include "lp_surface.h"
32 #include "lp_texture.h"
33 #include "lp_tile_image.h"
34 #include "lp_tile_size.h"
38 * Adjust x, y, width, height to lie on tile bounds.
41 adjust_to_tile_bounds(unsigned x
, unsigned y
, unsigned width
, unsigned height
,
42 unsigned *x_tile
, unsigned *y_tile
,
43 unsigned *w_tile
, unsigned *h_tile
)
45 *x_tile
= x
& ~(TILE_SIZE
- 1);
46 *y_tile
= y
& ~(TILE_SIZE
- 1);
47 *w_tile
= ((x
+ width
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *x_tile
;
48 *h_tile
= ((y
+ height
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *y_tile
;
54 lp_surface_copy(struct pipe_context
*pipe
,
55 struct pipe_surface
*dst
, unsigned dstx
, unsigned dsty
,
56 struct pipe_surface
*src
, unsigned srcx
, unsigned srcy
,
57 unsigned width
, unsigned height
)
59 llvmpipe_flush_texture(pipe
,
60 dst
->texture
, dst
->face
, dst
->level
,
62 FALSE
, /* read_only */
63 FALSE
, /* cpu_access */
64 FALSE
); /* do_not_flush */
66 llvmpipe_flush_texture(pipe
,
67 src
->texture
, src
->face
, src
->level
,
70 FALSE
, /* cpu_access */
71 FALSE
); /* do_not_flush */
73 /* Look for special case in which we're copying from a tiled image
77 struct llvmpipe_resource
*src_tex
= llvmpipe_resource(src
->texture
);
78 struct llvmpipe_resource
*dst_tex
= llvmpipe_resource(dst
->texture
);
79 enum pipe_format format
= src_tex
->base
.format
;
82 printf("surface copy from %u to %u: %u,%u to %u,%u %u x %u\n",
83 src_tex->id, dst_tex->id,
84 srcx, srcy, dstx, dsty, width, height);
87 /* set src tiles to linear layout */
89 unsigned tx
, ty
, tw
, th
;
92 adjust_to_tile_bounds(srcx
, srcy
, width
, height
, &tx
, &ty
, &tw
, &th
);
94 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
95 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
96 (void) llvmpipe_get_texture_tile_linear(src_tex
,
97 src
->face
, src
->level
,
104 /* set dst tiles to linear layout */
106 unsigned tx
, ty
, tw
, th
;
108 enum lp_texture_usage usage
;
110 /* XXX for the tiles which are completely contained by the
111 * dest rectangle, we could set the usage mode to WRITE_ALL.
112 * Just test for the case of replacing the whole dest region for now.
114 if (width
== dst_tex
->base
.width0
&& height
== dst_tex
->base
.height0
)
115 usage
= LP_TEX_USAGE_WRITE_ALL
;
117 usage
= LP_TEX_USAGE_READ_WRITE
;
119 adjust_to_tile_bounds(dstx
, dsty
, width
, height
, &tx
, &ty
, &tw
, &th
);
121 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
122 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
123 (void) llvmpipe_get_texture_tile_linear(dst_tex
,
124 dst
->face
, dst
->level
,
133 const ubyte
*src_linear_ptr
134 = llvmpipe_get_texture_image_address(src_tex
, src
->face
,
136 LP_TEX_LAYOUT_LINEAR
);
137 ubyte
*dst_linear_ptr
138 = llvmpipe_get_texture_image_address(dst_tex
, dst
->face
,
140 LP_TEX_LAYOUT_LINEAR
);
142 util_copy_rect(dst_linear_ptr
, format
,
143 dst_tex
->stride
[dst
->level
],
146 src_linear_ptr
, src_tex
->stride
[src
->level
],
152 util_surface_copy(pipe
, FALSE
,
159 lp_init_surface_functions(struct llvmpipe_context
*lp
)
161 lp
->pipe
.surface_copy
= lp_surface_copy
;
162 lp
->pipe
.surface_fill
= util_surface_fill
;