intel_tex_copy.c revision 56b57aa360a8bad0c4b68fbdf7c64ac33f9e7661
1/************************************************************************** 2 * 3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 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: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 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. 25 * 26 **************************************************************************/ 27 28#include "main/mtypes.h" 29#include "main/enums.h" 30#include "main/image.h" 31#include "main/teximage.h" 32#include "main/texstate.h" 33 34#include "drivers/common/meta.h" 35 36#include "intel_screen.h" 37#include "intel_context.h" 38#include "intel_mipmap_tree.h" 39#include "intel_regions.h" 40#include "intel_fbo.h" 41#include "intel_tex.h" 42#include "intel_blit.h" 43 44#define FILE_DEBUG_FLAG DEBUG_TEXTURE 45 46 47bool 48intel_copy_texsubimage(struct intel_context *intel, 49 struct intel_texture_image *intelImage, 50 GLint dstx, GLint dsty, 51 struct intel_renderbuffer *irb, 52 GLint x, GLint y, GLsizei width, GLsizei height) 53{ 54 struct gl_context *ctx = &intel->ctx; 55 struct intel_region *region; 56 const GLenum internalFormat = intelImage->base.Base.InternalFormat; 57 bool copy_supported = false; 58 bool copy_supported_with_alpha_override = false; 59 60 intel_prepare_render(intel); 61 62 if (!intelImage->mt || !irb || !irb->mt) { 63 if (unlikely(INTEL_DEBUG & DEBUG_FALLBACKS)) 64 fprintf(stderr, "%s fail %p %p (0x%08x)\n", 65 __FUNCTION__, intelImage->mt, irb, internalFormat); 66 return false; 67 } else { 68 region = irb->mt->region; 69 assert(region); 70 } 71 72 copy_supported = intelImage->base.Base.TexFormat == irb->Base.Format; 73 74 /* Converting ARGB8888 to XRGB8888 is trivial: ignore the alpha bits */ 75 if (irb->Base.Format == MESA_FORMAT_ARGB8888 && 76 intelImage->base.Base.TexFormat == MESA_FORMAT_XRGB8888) { 77 copy_supported = true; 78 } 79 80 /* Converting XRGB8888 to ARGB8888 requires setting the alpha bits to 1.0 */ 81 if (irb->Base.Format == MESA_FORMAT_XRGB8888 && 82 intelImage->base.Base.TexFormat == MESA_FORMAT_ARGB8888) { 83 copy_supported_with_alpha_override = true; 84 } 85 86 if (!copy_supported && !copy_supported_with_alpha_override) { 87 if (unlikely(INTEL_DEBUG & DEBUG_FALLBACKS)) 88 fprintf(stderr, "%s mismatched formats %s, %s\n", 89 __FUNCTION__, 90 _mesa_get_format_name(intelImage->base.Base.TexFormat), 91 _mesa_get_format_name(irb->Base.Format)); 92 return false; 93 } 94 95 { 96 GLuint image_x, image_y; 97 GLshort src_pitch; 98 99 /* get dest x/y in destination texture */ 100 intel_miptree_get_image_offset(intelImage->mt, 101 intelImage->base.Base.Level, 102 intelImage->base.Base.Face, 103 0, 104 &image_x, &image_y); 105 106 /* The blitter can't handle Y-tiled buffers. */ 107 if (intelImage->mt->region->tiling == I915_TILING_Y) { 108 return false; 109 } 110 111 if (ctx->ReadBuffer->Name == 0) { 112 /* Flip vertical orientation for system framebuffers */ 113 y = ctx->ReadBuffer->Height - (y + height); 114 src_pitch = -region->pitch; 115 } else { 116 /* reading from a FBO, y is already oriented the way we like */ 117 src_pitch = region->pitch; 118 } 119 120 /* blit from src buffer to texture */ 121 if (!intelEmitCopyBlit(intel, 122 intelImage->mt->cpp, 123 src_pitch, 124 region->bo, 125 0, 126 region->tiling, 127 intelImage->mt->region->pitch, 128 intelImage->mt->region->bo, 129 0, 130 intelImage->mt->region->tiling, 131 irb->draw_x + x, irb->draw_y + y, 132 image_x + dstx, image_y + dsty, 133 width, height, 134 GL_COPY)) { 135 return false; 136 } 137 } 138 139 if (copy_supported_with_alpha_override) 140 intel_set_teximage_alpha_to_one(ctx, intelImage); 141 142 return true; 143} 144 145 146static void 147intelCopyTexSubImage1D(struct gl_context *ctx, 148 struct gl_texture_image *texImage, 149 GLint xoffset, 150 struct gl_renderbuffer *rb, 151 GLint x, GLint y, GLsizei width) 152{ 153 if (!intel_copy_texsubimage(intel_context(ctx), 154 intel_texture_image(texImage), 155 xoffset, 0, 156 intel_renderbuffer(rb), x, y, width, 1)) { 157 fallback_debug("%s - fallback to swrast\n", __FUNCTION__); 158 _mesa_meta_CopyTexSubImage1D(ctx, texImage, xoffset, 159 rb, x, y, width); 160 } 161} 162 163 164static void 165intelCopyTexSubImage2D(struct gl_context *ctx, 166 struct gl_texture_image *texImage, 167 GLint xoffset, GLint yoffset, 168 struct gl_renderbuffer *rb, 169 GLint x, GLint y, GLsizei width, GLsizei height) 170{ 171 if (!intel_copy_texsubimage(intel_context(ctx), 172 intel_texture_image(texImage), 173 xoffset, yoffset, 174 intel_renderbuffer(rb), x, y, width, height)) { 175 fallback_debug("%s - fallback to swrast\n", __FUNCTION__); 176 _mesa_meta_CopyTexSubImage2D(ctx, texImage, 177 xoffset, yoffset, 178 rb, x, y, width, height); 179 } 180} 181 182 183void 184intelInitTextureCopyImageFuncs(struct dd_function_table *functions) 185{ 186 functions->CopyTexSubImage1D = intelCopyTexSubImage1D; 187 functions->CopyTexSubImage2D = intelCopyTexSubImage2D; 188} 189