ilo: add BLT-based blitting methods to ilo_blitter
[mesa.git] / src / gallium / drivers / ilo / ilo_blit.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "util/u_surface.h"
29 #include "intel_reg.h"
30
31 #include "ilo_blitter.h"
32 #include "ilo_context.h"
33 #include "ilo_cp.h"
34 #include "ilo_resource.h"
35 #include "ilo_screen.h"
36 #include "ilo_blit.h"
37
38 static void
39 ilo_resource_copy_region(struct pipe_context *pipe,
40 struct pipe_resource *dst,
41 unsigned dst_level,
42 unsigned dstx, unsigned dsty, unsigned dstz,
43 struct pipe_resource *src,
44 unsigned src_level,
45 const struct pipe_box *src_box)
46 {
47 struct ilo_context *ilo = ilo_context(pipe);
48
49 if (ilo_blitter_blt_copy_resource(ilo->blitter,
50 dst, dst_level, dstx, dsty, dstz,
51 src, src_level, src_box))
52 return;
53
54 util_resource_copy_region(&ilo->base, dst, dst_level,
55 dstx, dsty, dstz, src, src_level, src_box);
56 }
57
58 static void
59 ilo_clear(struct pipe_context *pipe,
60 unsigned buffers,
61 const union pipe_color_union *color,
62 double depth,
63 unsigned stencil)
64 {
65 struct ilo_context *ilo = ilo_context(pipe);
66
67 ilo_blitter_pipe_clear_fb(ilo->blitter, buffers, color, depth, stencil);
68 }
69
70 static void
71 ilo_clear_render_target(struct pipe_context *pipe,
72 struct pipe_surface *dst,
73 const union pipe_color_union *color,
74 unsigned dstx, unsigned dsty,
75 unsigned width, unsigned height)
76 {
77 struct ilo_context *ilo = ilo_context(pipe);
78
79 if (!width || !height || dstx >= dst->width || dsty >= dst->height)
80 return;
81
82 if (dstx + width > dst->width)
83 width = dst->width - dstx;
84 if (dsty + height > dst->height)
85 height = dst->height - dsty;
86
87 if (ilo_blitter_blt_clear_rt(ilo->blitter,
88 dst, color, dstx, dsty, width, height))
89 return;
90
91 ilo_blitter_pipe_clear_rt(ilo->blitter,
92 dst, color, dstx, dsty, width, height);
93 }
94
95 static void
96 ilo_clear_depth_stencil(struct pipe_context *pipe,
97 struct pipe_surface *dst,
98 unsigned clear_flags,
99 double depth,
100 unsigned stencil,
101 unsigned dstx, unsigned dsty,
102 unsigned width, unsigned height)
103 {
104 struct ilo_context *ilo = ilo_context(pipe);
105
106 if (!width || !height || dstx >= dst->width || dsty >= dst->height)
107 return;
108
109 if (dstx + width > dst->width)
110 width = dst->width - dstx;
111 if (dsty + height > dst->height)
112 height = dst->height - dsty;
113
114 if (ilo_blitter_blt_clear_zs(ilo->blitter,
115 dst, clear_flags, depth, stencil, dstx, dsty, width, height))
116 return;
117
118 ilo_blitter_pipe_clear_zs(ilo->blitter,
119 dst, clear_flags, depth, stencil, dstx, dsty, width, height);
120 }
121
122 static void
123 ilo_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)
124 {
125 struct ilo_context *ilo = ilo_context(pipe);
126
127 ilo_blitter_pipe_blit(ilo->blitter, info);
128 }
129
130 /**
131 * Initialize blit-related functions.
132 */
133 void
134 ilo_init_blit_functions(struct ilo_context *ilo)
135 {
136 ilo->base.resource_copy_region = ilo_resource_copy_region;
137 ilo->base.blit = ilo_blit;
138
139 ilo->base.clear = ilo_clear;
140 ilo->base.clear_render_target = ilo_clear_render_target;
141 ilo->base.clear_depth_stencil = ilo_clear_depth_stencil;
142 }