Merge branch 'master' into pipe-video
[mesa.git] / src / gallium / drivers / svga / svga_pipe_blit.c
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #include "svga_resource_texture.h"
27 #include "svga_context.h"
28 #include "svga_debug.h"
29 #include "svga_cmd.h"
30 #include "svga_surface.h"
31
32 #define FILE_DEBUG_FLAG DEBUG_BLIT
33
34
35 /* XXX I got my doubts about this, should maybe use svga_texture_copy_handle directly? */
36 static void svga_surface_copy(struct pipe_context *pipe,
37 struct pipe_resource* dst_tex,
38 struct pipe_subresource subdst,
39 unsigned dstx, unsigned dsty, unsigned dstz,
40 struct pipe_resource* src_tex,
41 struct pipe_subresource subsrc,
42 unsigned srcx, unsigned srcy, unsigned srcz,
43 unsigned width, unsigned height)
44 {
45 struct svga_context *svga = svga_context(pipe);
46 struct pipe_screen *screen = pipe->screen;
47 SVGA3dCopyBox *box;
48 enum pipe_error ret;
49 struct pipe_surface *srcsurf, *dstsurf;
50
51 svga_hwtnl_flush_retry( svga );
52
53 srcsurf = screen->get_tex_surface(screen, src_tex,
54 subsrc.face, subsrc.level, srcz,
55 PIPE_BIND_SAMPLER_VIEW);
56
57 dstsurf = screen->get_tex_surface(screen, dst_tex,
58 subdst.face, subdst.level, dstz,
59 PIPE_BIND_RENDER_TARGET);
60
61 SVGA_DBG(DEBUG_DMA, "blit to sid %p (%d,%d), from sid %p (%d,%d) sz %dx%d\n",
62 svga_surface(dstsurf)->handle,
63 dstx, dsty,
64 svga_surface(srcsurf)->handle,
65 srcx, srcy,
66 width, height);
67
68 ret = SVGA3D_BeginSurfaceCopy(svga->swc,
69 srcsurf,
70 dstsurf,
71 &box,
72 1);
73 if(ret != PIPE_OK) {
74
75 svga_context_flush(svga, NULL);
76
77 ret = SVGA3D_BeginSurfaceCopy(svga->swc,
78 srcsurf,
79 dstsurf,
80 &box,
81 1);
82 assert(ret == PIPE_OK);
83 }
84
85 box->x = dstx;
86 box->y = dsty;
87 box->z = 0;
88 box->w = width;
89 box->h = height;
90 box->d = 1;
91 box->srcx = srcx;
92 box->srcy = srcy;
93 box->srcz = 0;
94
95 SVGA_FIFOCommitAll(svga->swc);
96
97 svga_surface(dstsurf)->dirty = TRUE;
98 svga_propagate_surface(pipe, dstsurf);
99
100 pipe_surface_reference(&srcsurf, NULL);
101 pipe_surface_reference(&dstsurf, NULL);
102
103 }
104
105
106 void
107 svga_init_blit_functions(struct svga_context *svga)
108 {
109 svga->pipe.resource_copy_region = svga_surface_copy;
110 }