r300: Remove unnecessary headers.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_tex_copy.c
1 /*
2 * Copyright (C) 2009 Maciej Cencora <m.cencora@gmail.com>
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a 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, sublicense, 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
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28 #include "radeon_common.h"
29 #include "radeon_texture.h"
30
31 #include "main/image.h"
32 #include "main/teximage.h"
33 #include "main/texstate.h"
34 #include "drivers/common/meta.h"
35
36 #include "radeon_mipmap_tree.h"
37 #include <main/debug.h>
38
39 static GLboolean
40 do_copy_texsubimage(GLcontext *ctx,
41 GLenum target, GLint level,
42 struct radeon_tex_obj *tobj,
43 radeon_texture_image *timg,
44 GLint dstx, GLint dsty,
45 GLint x, GLint y,
46 GLsizei width, GLsizei height)
47 {
48 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
49 struct radeon_renderbuffer *rrb;
50
51 if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) > 0) {
52 rrb = radeon_get_depthbuffer(radeon);
53 } else {
54 rrb = radeon_get_colorbuffer(radeon);
55 }
56
57 if (!timg->mt) {
58 radeon_validate_texture_miptree(ctx, &tobj->base);
59 }
60
61 assert(rrb && rrb->bo);
62 assert(timg->mt->bo);
63 assert(timg->base.Width >= dstx + width);
64 assert(timg->base.Height >= dsty + height);
65
66 intptr_t src_offset = rrb->draw_offset;
67 intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level);
68
69 if (0) {
70 fprintf(stderr, "%s: copying to face %d, level %d\n",
71 __FUNCTION__, _mesa_tex_target_to_face(target), level);
72 fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset);
73 fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d\n",
74 x, y, rrb->base.Width, rrb->base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
75 fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size);
76
77 }
78
79 /* blit from src buffer to texture */
80 return radeon->vtbl.blit(ctx, rrb->bo, src_offset, rrb->base.Format, rrb->pitch/rrb->cpp,
81 rrb->base.Width, rrb->base.Height, x, y,
82 timg->mt->bo, dst_offset, timg->base.TexFormat,
83 timg->mt->levels[level].rowstride / _mesa_get_format_bytes(timg->base.TexFormat),
84 timg->base.Width, timg->base.Height,
85 dstx, dsty, width, height, 1);
86 }
87
88 void
89 radeonCopyTexImage2D(GLcontext *ctx, GLenum target, GLint level,
90 GLenum internalFormat,
91 GLint x, GLint y, GLsizei width, GLsizei height,
92 GLint border)
93 {
94 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
95 struct gl_texture_object *texObj =
96 _mesa_select_tex_object(ctx, texUnit, target);
97 struct gl_texture_image *texImage =
98 _mesa_select_tex_image(ctx, texObj, target, level);
99 int srcx, srcy, dstx, dsty;
100
101 if (border)
102 goto fail;
103
104 /* Setup or redefine the texture object, mipmap tree and texture
105 * image. Don't populate yet.
106 */
107 ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
108 width, height, border,
109 GL_RGBA, GL_UNSIGNED_BYTE, NULL,
110 &ctx->DefaultPacking, texObj, texImage);
111
112 srcx = x;
113 srcy = y;
114 dstx = 0;
115 dsty = 0;
116 if (!_mesa_clip_copytexsubimage(ctx,
117 &dstx, &dsty,
118 &srcx, &srcy,
119 &width, &height)) {
120 return;
121 }
122
123 if (!do_copy_texsubimage(ctx, target, level,
124 radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
125 0, 0, x, y, width, height)) {
126 goto fail;
127 }
128
129 return;
130
131 fail:
132 _mesa_meta_CopyTexImage2D(ctx, target, level, internalFormat, x, y,
133 width, height, border);
134 }
135
136 void
137 radeonCopyTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
138 GLint xoffset, GLint yoffset,
139 GLint x, GLint y,
140 GLsizei width, GLsizei height)
141 {
142 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
143 struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target);
144 struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level);
145
146 if (!do_copy_texsubimage(ctx, target, level,
147 radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
148 xoffset, yoffset, x, y, width, height)) {
149
150 //DEBUG_FALLBACKS
151
152 _mesa_meta_CopyTexSubImage2D(ctx, target, level,
153 xoffset, yoffset, x, y, width, height);
154 }
155 }