1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "main/glheader.h"
29 #include "main/image.h"
30 #include "main/state.h"
31 #include "main/mtypes.h"
32 #include "main/condrender.h"
33 #include "drivers/common/meta.h"
35 #include "intel_context.h"
36 #include "intel_buffers.h"
37 #include "intel_mipmap_tree.h"
38 #include "intel_regions.h"
39 #include "intel_pixel.h"
40 #include "intel_fbo.h"
42 #define FILE_DEBUG_FLAG DEBUG_PIXEL
45 * Check if any fragment operations are in effect which might effect
46 * glCopyPixels. Differs from intel_check_blit_fragment_ops in that
50 intel_check_copypixel_blit_fragment_ops(struct gl_context
* ctx
)
53 _mesa_update_state(ctx
);
55 /* Could do logicop with the blitter:
57 return !(ctx
->_ImageTransferState
||
58 ctx
->Color
.AlphaEnabled
||
61 ctx
->Stencil
._Enabled
||
62 !ctx
->Color
.ColorMask
[0][0] ||
63 !ctx
->Color
.ColorMask
[0][1] ||
64 !ctx
->Color
.ColorMask
[0][2] ||
65 !ctx
->Color
.ColorMask
[0][3] ||
66 ctx
->Texture
._EnabledUnits
||
67 ctx
->FragmentProgram
._Enabled
||
68 ctx
->Color
.BlendEnabled
);
73 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
76 do_blit_copypixels(struct gl_context
* ctx
,
77 GLint srcx
, GLint srcy
,
78 GLsizei width
, GLsizei height
,
79 GLint dstx
, GLint dsty
, GLenum type
)
81 struct intel_context
*intel
= intel_context(ctx
);
82 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
83 struct gl_framebuffer
*read_fb
= ctx
->ReadBuffer
;
89 struct intel_renderbuffer
*draw_irb
= NULL
;
90 struct intel_renderbuffer
*read_irb
= NULL
;
92 /* Update draw buffer bounds */
93 _mesa_update_state(ctx
);
97 if (fb
->_NumColorDrawBuffers
!= 1) {
98 fallback_debug("glCopyPixels() fallback: MRT\n");
102 draw_irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[0]);
103 read_irb
= intel_renderbuffer(read_fb
->_ColorReadBuffer
);
105 case GL_DEPTH_STENCIL_EXT
:
106 draw_irb
= intel_renderbuffer(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
108 intel_renderbuffer(read_fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
111 fallback_debug("glCopyPixels() fallback: GL_DEPTH\n");
114 fallback_debug("glCopyPixels() fallback: GL_STENCIL\n");
117 fallback_debug("glCopyPixels(): Unknown type\n");
122 fallback_debug("glCopyPixels() fallback: missing draw buffer\n");
127 fallback_debug("glCopyPixels() fallback: missing read buffer\n");
131 if (draw_irb
->Base
.Format
!= read_irb
->Base
.Format
&&
132 !(draw_irb
->Base
.Format
== MESA_FORMAT_XRGB8888
&&
133 read_irb
->Base
.Format
== MESA_FORMAT_ARGB8888
)) {
134 fallback_debug("glCopyPixels() fallback: mismatched formats (%s -> %s\n",
135 _mesa_get_format_name(read_irb
->Base
.Format
),
136 _mesa_get_format_name(draw_irb
->Base
.Format
));
140 /* Copypixels can be more than a straight copy. Ensure all the
141 * extra operations are disabled:
143 if (!intel_check_copypixel_blit_fragment_ops(ctx
) ||
144 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
147 intel_prepare_render(intel
);
149 intel_flush(&intel
->ctx
);
151 /* Clip to destination buffer. */
154 if (!_mesa_clip_to_region(fb
->_Xmin
, fb
->_Ymin
,
155 fb
->_Xmax
, fb
->_Ymax
,
156 &dstx
, &dsty
, &width
, &height
))
158 /* Adjust src coords for our post-clipped destination origin */
159 srcx
+= dstx
- orig_dstx
;
160 srcy
+= dsty
- orig_dsty
;
162 /* Clip to source buffer. */
165 if (!_mesa_clip_to_region(0, 0,
166 read_fb
->Width
, read_fb
->Height
,
167 &srcx
, &srcy
, &width
, &height
))
169 /* Adjust dst coords for our post-clipped source origin */
170 dstx
+= srcx
- orig_srcx
;
171 dsty
+= srcy
- orig_srcy
;
173 /* Flip dest Y if it's a window system framebuffer. */
175 /* copypixels to a window system framebuffer */
176 dsty
= fb
->Height
- dsty
- height
;
180 /* Flip source Y if it's a window system framebuffer. */
181 if (read_fb
->Name
== 0) {
182 srcy
= read_fb
->Height
- srcy
- height
;
186 srcx
+= read_irb
->draw_x
;
187 srcy
+= read_irb
->draw_y
;
188 dstx
+= draw_irb
->draw_x
;
189 dsty
+= draw_irb
->draw_y
;
191 if (!intel_region_copy(intel
,
192 draw_irb
->mt
->region
, 0, dstx
, dsty
,
193 read_irb
->mt
->region
, 0, srcx
, srcy
,
195 ctx
->Color
.ColorLogicOpEnabled
?
196 ctx
->Color
.LogicOp
: GL_COPY
)) {
197 DBG("%s: blit failure\n", __FUNCTION__
);
202 intel_check_front_buffer_rendering(intel
);
204 DBG("%s: success\n", __FUNCTION__
);
210 intelCopyPixels(struct gl_context
* ctx
,
211 GLint srcx
, GLint srcy
,
212 GLsizei width
, GLsizei height
,
213 GLint destx
, GLint desty
, GLenum type
)
215 DBG("%s\n", __FUNCTION__
);
217 if (!_mesa_check_conditional_render(ctx
))
220 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
223 /* this will use swrast if needed */
224 _mesa_meta_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);