1 /**************************************************************************
2  *
3  * Copyright 2003 VMware, Inc.
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 VMWARE 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 #include "main/fbobject.h"
34 
35 #include "drivers/common/meta.h"
36 
37 #include "intel_screen.h"
38 #include "intel_context.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41 #include "intel_fbo.h"
42 #include "intel_tex.h"
43 #include "intel_blit.h"
44 
45 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
46 
47 
48 static bool
intel_copy_texsubimage(struct intel_context * intel,struct intel_texture_image * intelImage,GLint dstx,GLint dsty,GLint slice,struct intel_renderbuffer * irb,GLint x,GLint y,GLsizei width,GLsizei height)49 intel_copy_texsubimage(struct intel_context *intel,
50                        struct intel_texture_image *intelImage,
51                        GLint dstx, GLint dsty, GLint slice,
52                        struct intel_renderbuffer *irb,
53                        GLint x, GLint y, GLsizei width, GLsizei height)
54 {
55    const GLenum internalFormat = intelImage->base.Base.InternalFormat;
56 
57    intel_prepare_render(intel);
58 
59    if (!intelImage->mt || !irb || !irb->mt) {
60       if (unlikely(INTEL_DEBUG & DEBUG_PERF))
61 	 fprintf(stderr, "%s fail %p %p (0x%08x)\n",
62 		 __func__, intelImage->mt, irb, internalFormat);
63       return false;
64    }
65 
66    /* blit from src buffer to texture */
67    if (!intel_miptree_blit(intel,
68                            irb->mt, irb->mt_level, irb->mt_layer,
69                            x, y, irb->Base.Base.Name == 0,
70                            intelImage->mt, intelImage->base.Base.Level,
71                            intelImage->base.Base.Face + slice,
72                            dstx, dsty, false,
73                            width, height, COLOR_LOGICOP_COPY)) {
74       return false;
75    }
76 
77    return true;
78 }
79 
80 
81 static void
intelCopyTexSubImage(struct gl_context * ctx,GLuint dims,struct gl_texture_image * texImage,GLint xoffset,GLint yoffset,GLint slice,struct gl_renderbuffer * rb,GLint x,GLint y,GLsizei width,GLsizei height)82 intelCopyTexSubImage(struct gl_context *ctx, GLuint dims,
83                      struct gl_texture_image *texImage,
84                      GLint xoffset, GLint yoffset, GLint slice,
85                      struct gl_renderbuffer *rb,
86                      GLint x, GLint y,
87                      GLsizei width, GLsizei height)
88 {
89    struct intel_context *intel = intel_context(ctx);
90 
91    /* Try the BLT engine. */
92    if (intel_copy_texsubimage(intel,
93                               intel_texture_image(texImage),
94                               xoffset, yoffset, slice,
95                               intel_renderbuffer(rb), x, y, width, height)) {
96       return;
97    }
98 
99    /* Otherwise, fall back to meta.  This will likely be slow. */
100    perf_debug("%s - fallback to swrast\n", __func__);
101    _mesa_meta_CopyTexSubImage(ctx, dims, texImage,
102                               xoffset, yoffset, slice,
103                               rb, x, y, width, height);
104 }
105 
106 
107 void
intelInitTextureCopyImageFuncs(struct dd_function_table * functions)108 intelInitTextureCopyImageFuncs(struct dd_function_table *functions)
109 {
110    functions->CopyTexSubImage = intelCopyTexSubImage;
111 }
112