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_size.h"
37 * Adjust x, y, width, height to lie on tile bounds.
40 adjust_to_tile_bounds(unsigned x
, unsigned y
, unsigned width
, unsigned height
,
41 unsigned *x_tile
, unsigned *y_tile
,
42 unsigned *w_tile
, unsigned *h_tile
)
44 *x_tile
= x
& ~(TILE_SIZE
- 1);
45 *y_tile
= y
& ~(TILE_SIZE
- 1);
46 *w_tile
= ((x
+ width
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *x_tile
;
47 *h_tile
= ((y
+ height
+ TILE_SIZE
- 1) & ~(TILE_SIZE
- 1)) - *y_tile
;
53 lp_surface_copy(struct pipe_context
*pipe
,
54 struct pipe_surface
*dst
, unsigned dstx
, unsigned dsty
,
55 struct pipe_surface
*src
, unsigned srcx
, unsigned srcy
,
56 unsigned width
, unsigned height
)
58 struct llvmpipe_resource
*src_tex
= llvmpipe_resource(src
->texture
);
59 struct llvmpipe_resource
*dst_tex
= llvmpipe_resource(dst
->texture
);
60 const enum pipe_format format
= src_tex
->base
.format
;
62 llvmpipe_flush_texture(pipe
,
63 dst
->texture
, dst
->face
, dst
->level
,
65 FALSE
, /* read_only */
66 FALSE
, /* cpu_access */
67 FALSE
); /* do_not_flush */
69 llvmpipe_flush_texture(pipe
,
70 src
->texture
, src
->face
, src
->level
,
73 FALSE
, /* cpu_access */
74 FALSE
); /* do_not_flush */
77 printf("surface copy from %u to %u: %u,%u to %u,%u %u x %u\n",
78 src_tex->id, dst_tex->id,
79 srcx, srcy, dstx, dsty, width, height);
82 /* set src tiles to linear layout */
84 unsigned tx
, ty
, tw
, th
;
87 adjust_to_tile_bounds(srcx
, srcy
, width
, height
, &tx
, &ty
, &tw
, &th
);
89 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
90 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
91 (void) llvmpipe_get_texture_tile_linear(src_tex
,
92 src
->face
, src
->level
,
99 /* set dst tiles to linear layout */
101 unsigned tx
, ty
, tw
, th
;
103 enum lp_texture_usage usage
;
105 /* XXX for the tiles which are completely contained by the
106 * dest rectangle, we could set the usage mode to WRITE_ALL.
107 * Just test for the case of replacing the whole dest region for now.
109 if (width
== dst_tex
->base
.width0
&& height
== dst_tex
->base
.height0
)
110 usage
= LP_TEX_USAGE_WRITE_ALL
;
112 usage
= LP_TEX_USAGE_READ_WRITE
;
114 adjust_to_tile_bounds(dstx
, dsty
, width
, height
, &tx
, &ty
, &tw
, &th
);
116 for (y
= 0; y
< th
; y
+= TILE_SIZE
) {
117 for (x
= 0; x
< tw
; x
+= TILE_SIZE
) {
118 (void) llvmpipe_get_texture_tile_linear(dst_tex
,
119 dst
->face
, dst
->level
,
128 const ubyte
*src_linear_ptr
129 = llvmpipe_get_texture_image_address(src_tex
, src
->face
,
131 LP_TEX_LAYOUT_LINEAR
);
132 ubyte
*dst_linear_ptr
133 = llvmpipe_get_texture_image_address(dst_tex
, dst
->face
,
135 LP_TEX_LAYOUT_LINEAR
);
137 util_copy_rect(dst_linear_ptr
, format
,
138 llvmpipe_resource_stride(&dst_tex
->base
, dst
->level
),
142 llvmpipe_resource_stride(&src_tex
->base
, src
->level
),
149 lp_init_surface_functions(struct llvmpipe_context
*lp
)
151 lp
->pipe
.surface_copy
= lp_surface_copy
;
152 lp
->pipe
.surface_fill
= util_surface_fill
;