1ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora/*
2ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * Copyright (C) 2010 Maciej Cencora <m.cencora@gmail.com>
3ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora *
4ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * All Rights Reserved.
5ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora *
6ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * Permission is hereby granted, free of charge, to any person obtaining
7ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * a copy of this software and associated documentation files (the
8ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * "Software"), to deal in the Software without restriction, including
9ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * without limitation the rights to use, copy, modify, merge, publish,
10ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * distribute, sublicense, and/or sell copies of the Software, and to
11ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * permit persons to whom the Software is furnished to do so, subject to
12ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * the following conditions:
13ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora *
14ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * The above copyright notice and this permission notice (including the
15ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * next paragraph) shall be included in all copies or substantial
16ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * portions of the Software.
17ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora *
18ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora *
26ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora */
27ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
28ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "stdint.h"
29ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "main/bufferobj.h"
30ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "main/enums.h"
3147941bfaea6e8a60e2c31f7a2c8c233f2a10ecb1Brian Paul#include "main/fbobject.h"
32ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "main/image.h"
331161facaf9bb14086807714c72a7554ed229a52fBrian Paul#include "main/readpix.h"
34ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "main/state.h"
35ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
3650b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet#include "radeon_buffer_objects.h"
37ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "radeon_common_context.h"
38ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "radeon_debug.h"
39ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora#include "radeon_mipmap_tree.h"
40ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
41ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencorastatic gl_format gl_format_and_type_to_mesa_format(GLenum format, GLenum type)
42ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora{
43ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    switch (format)
44ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    {
45ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        case GL_RGB:
46ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            switch (type) {
47ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_SHORT_5_6_5:
48ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_RGB565;
49ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_SHORT_5_6_5_REV:
50ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_RGB565_REV;
51ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            }
52ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            break;
53ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        case GL_RGBA:
54ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            switch (type) {
55ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_FLOAT:
56ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_RGBA_FLOAT32;
57aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_SHORT_5_5_5_1:
58aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_RGBA5551;
59aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_INT_8_8_8_8:
60aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_RGBA8888;
61aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_BYTE:
62aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_INT_8_8_8_8_REV:
63aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_RGBA8888_REV;
64aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora            }
65aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora            break;
66aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora        case GL_BGRA:
67aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora            switch (type) {
68ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_SHORT_4_4_4_4:
69aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_ARGB4444_REV;
70ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_SHORT_4_4_4_4_REV:
71ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_ARGB4444;
72ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_SHORT_5_5_5_1:
73ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_ARGB1555_REV;
74aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_SHORT_1_5_5_5_REV:
75aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_ARGB1555;
76ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                case GL_UNSIGNED_INT_8_8_8_8:
77ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                    return MESA_FORMAT_ARGB8888_REV;
78aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_BYTE:
79aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                case GL_UNSIGNED_INT_8_8_8_8_REV:
80aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora                    return MESA_FORMAT_ARGB8888;
81aba40bd4345e36fb56817673369b275f0e9a9c43Maciej Cencora
82ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            }
83ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora            break;
84ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
85ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
86ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    return MESA_FORMAT_NONE;
87ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora}
88ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
89ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencorastatic GLboolean
90f9995b30756140724f41daf963fa06167912be7fKristian Høgsbergdo_blit_readpixels(struct gl_context * ctx,
91ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                   GLint x, GLint y, GLsizei width, GLsizei height,
92ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                   GLenum format, GLenum type,
93ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                   const struct gl_pixelstore_attrib *pack, GLvoid * pixels)
94ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora{
95ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    radeonContextPtr radeon = RADEON_CONTEXT(ctx);
96ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    const struct radeon_renderbuffer *rrb = radeon_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
97ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    const gl_format dst_format = gl_format_and_type_to_mesa_format(format, type);
98ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    unsigned dst_rowstride, dst_imagesize, aligned_rowstride, flip_y;
99ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    struct radeon_bo *dst_buffer;
100ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    GLint dst_x = 0, dst_y = 0;
10150b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    intptr_t dst_offset;
102ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
103ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    /* It's not worth if number of pixels to copy is really small */
104ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (width * height < 100) {
105ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_FALSE;
106ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
107ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
108ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (dst_format == MESA_FORMAT_NONE ||
109b2596c36c8f73e8bb7a0b1679b491662aeb2f9d9Dave Airlie        !radeon->vtbl.check_blit(dst_format, rrb->pitch / rrb->cpp) || !radeon->vtbl.blit) {
110ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_FALSE;
111ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
112ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
1132836aab2031d5b6926923fbc70f867ec638301bdIan Romanick    if (ctx->_ImageTransferState || ctx->Color.ColorLogicOpEnabled) {
114ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_FALSE;
115ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
116ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
117ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (pack->SwapBytes || pack->LsbFirst) {
118ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_FALSE;
119ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
120ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
121ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (pack->RowLength > 0) {
122ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        dst_rowstride = pack->RowLength;
123ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    } else {
124ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        dst_rowstride = width;
125ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
126ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
127ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (!_mesa_clip_copytexsubimage(ctx, &dst_x, &dst_y, &x, &y, &width, &height)) {
128ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_TRUE;
129ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
130ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    assert(x >= 0 && y >= 0);
131ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
132beb3e81b86698359e037d49f35feba3ca53626b2Dave Airlie    aligned_rowstride = get_texture_image_row_stride(radeon, dst_format, dst_rowstride, 0, GL_TEXTURE_2D);
13350b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    dst_rowstride *= _mesa_get_format_bytes(dst_format);
13450b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    if (_mesa_is_bufferobj(pack->BufferObj) && aligned_rowstride != dst_rowstride)
13550b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        return GL_FALSE;
136ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    dst_imagesize = get_texture_image_size(dst_format,
137ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                                           aligned_rowstride,
138ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                                           height, 1, 0);
13950b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet
14050b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    if (!_mesa_is_bufferobj(pack->BufferObj))
14150b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    {
14250b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        dst_buffer = radeon_bo_open(radeon->radeonScreen->bom, 0, dst_imagesize, 1024, RADEON_GEM_DOMAIN_GTT, 0);
14350b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        dst_offset = 0;
14450b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    }
14550b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    else
14650b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    {
14750b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        dst_buffer = get_radeon_buffer_object(pack->BufferObj)->bo;
14850b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        dst_offset = (intptr_t)pixels;
14950b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    }
150ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
151ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    /* Disable source Y flipping for FBOs */
15247941bfaea6e8a60e2c31f7a2c8c233f2a10ecb1Brian Paul    flip_y = _mesa_is_winsys_fbo(ctx->ReadBuffer);
153ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (pack->Invert) {
154c080202db5363a18a759a9a7c82b40ac558c8abeBrian Paul        y = rrb->base.Base.Height - height - y;
155ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        flip_y = !flip_y;
156ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
157ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
158ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (radeon->vtbl.blit(ctx,
159ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          rrb->bo,
160ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          rrb->draw_offset,
161c080202db5363a18a759a9a7c82b40ac558c8abeBrian Paul                          rrb->base.Base.Format,
162ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          rrb->pitch / rrb->cpp,
163c080202db5363a18a759a9a7c82b40ac558c8abeBrian Paul                          rrb->base.Base.Width,
164c080202db5363a18a759a9a7c82b40ac558c8abeBrian Paul                          rrb->base.Base.Height,
165ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          x,
166ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          y,
167ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          dst_buffer,
16850b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet                          dst_offset,
169ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          dst_format,
170ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          aligned_rowstride / _mesa_get_format_bytes(dst_format),
171ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          width,
172ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          height,
173ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          0, /* dst_x */
174ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          0, /* dst_y */
175ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          width,
176ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          height,
177ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                          flip_y))
178ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    {
17950b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        if (!_mesa_is_bufferobj(pack->BufferObj))
18050b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        {
18150b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet            radeon_bo_map(dst_buffer, 0);
18250b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet            copy_rows(pixels, dst_rowstride, dst_buffer->ptr,
18350b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet                      aligned_rowstride, height, dst_rowstride);
18450b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet            radeon_bo_unmap(dst_buffer);
18550b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet            radeon_bo_unref(dst_buffer);
18650b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        }
18750b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet
188ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return GL_TRUE;
189ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    }
19050b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet
19150b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    if (!_mesa_is_bufferobj(pack->BufferObj))
19250b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet        radeon_bo_unref(dst_buffer);
19350b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet
19450b9c54ef6b813b348df7e63a0cf291d3d9d39f4Henri Verbeet    return GL_FALSE;
195ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora}
196ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
197ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencoravoid
198f9995b30756140724f41daf963fa06167912be7fKristian HøgsbergradeonReadPixels(struct gl_context * ctx,
199ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                 GLint x, GLint y, GLsizei width, GLsizei height,
200ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                 GLenum format, GLenum type,
201ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                 const struct gl_pixelstore_attrib *pack, GLvoid * pixels)
202ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora{
203646d2e9fbc41bf49075013009e9583bec4a51168Mario Kleiner    radeonContextPtr radeon = RADEON_CONTEXT(ctx);
204646d2e9fbc41bf49075013009e9583bec4a51168Mario Kleiner    radeon_prepare_render(radeon);
205646d2e9fbc41bf49075013009e9583bec4a51168Mario Kleiner
206ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (do_blit_readpixels(ctx, x, y, width, height, format, type, pack, pixels))
207ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        return;
208ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
2091161facaf9bb14086807714c72a7554ed229a52fBrian Paul    /* Update Mesa state before calling _mesa_readpixels().
2101161facaf9bb14086807714c72a7554ed229a52fBrian Paul     * XXX this may not be needed since ReadPixels no longer uses the
2111161facaf9bb14086807714c72a7554ed229a52fBrian Paul     * span code.
212ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora     */
213ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    radeon_print(RADEON_FALLBACKS, RADEON_NORMAL,
214ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                 "Falling back to sw for ReadPixels (format %s, type %s)\n",
215ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora                 _mesa_lookup_enum_by_nr(format), _mesa_lookup_enum_by_nr(type));
216ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
217ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora    if (ctx->NewState)
218ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora        _mesa_update_state(ctx);
219ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora
2201161facaf9bb14086807714c72a7554ed229a52fBrian Paul    _mesa_readpixels(ctx, x, y, width, height, format, type, pack, pixels);
221ac2b7835d5e61629f0a1f8b6c35eb1efa2ffbfa2Maciej Cencora}
222