e002516cdd04f0ada4cf9209c81855ddac262df5
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 "drivers/common/meta.h"
34 #include "intel_context.h"
35 #include "intel_buffers.h"
36 #include "intel_regions.h"
37 #include "intel_pixel.h"
38 #include "intel_fbo.h"
40 #define FILE_DEBUG_FLAG DEBUG_PIXEL
42 static struct intel_region
*
43 copypix_src_region(struct intel_context
*intel
, GLenum type
)
45 struct intel_renderbuffer
*depth
;
47 depth
= (struct intel_renderbuffer
*)
48 &intel
->ctx
.DrawBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
52 return intel_readbuf_region(intel
);
54 /* Don't think this is really possible execpt at 16bpp, when we
56 if (depth
&& depth
->region
->cpp
== 2)
59 /* Don't think this is really possible. */
61 case GL_DEPTH_STENCIL_EXT
:
62 /* Does it matter whether it is stencil/depth or depth/stencil?
74 * Check if any fragment operations are in effect which might effect
75 * glCopyPixels. Differs from intel_check_blit_fragment_ops in that
79 intel_check_copypixel_blit_fragment_ops(GLcontext
* ctx
)
82 _mesa_update_state(ctx
);
84 /* Could do logicop with the blitter:
86 return !(ctx
->_ImageTransferState
||
87 ctx
->Color
.AlphaEnabled
||
90 ctx
->Stencil
._Enabled
||
91 !ctx
->Color
.ColorMask
[0][0] ||
92 !ctx
->Color
.ColorMask
[0][1] ||
93 !ctx
->Color
.ColorMask
[0][2] ||
94 !ctx
->Color
.ColorMask
[0][3] ||
95 ctx
->Texture
._EnabledUnits
||
96 ctx
->FragmentProgram
._Enabled
||
97 ctx
->Color
.BlendEnabled
);
102 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
105 do_blit_copypixels(GLcontext
* ctx
,
106 GLint srcx
, GLint srcy
,
107 GLsizei width
, GLsizei height
,
108 GLint dstx
, GLint dsty
, GLenum type
)
110 struct intel_context
*intel
= intel_context(ctx
);
111 struct intel_region
*dst
= intel_drawbuf_region(intel
);
112 struct intel_region
*src
= copypix_src_region(intel
, type
);
113 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
114 struct gl_framebuffer
*read_fb
= ctx
->ReadBuffer
;
115 unsigned int num_cliprects
;
116 drm_clip_rect_t
*cliprects
;
119 if (type
== GL_DEPTH
|| type
== GL_STENCIL
) {
120 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
121 fprintf(stderr
, "glCopyPixels() fallback: GL_DEPTH || GL_STENCIL\n");
125 /* Update draw buffer bounds */
126 _mesa_update_state(ctx
);
128 /* Copypixels can be more than a straight copy. Ensure all the
129 * extra operations are disabled:
131 if (!intel_check_copypixel_blit_fragment_ops(ctx
) ||
132 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
140 intelFlush(&intel
->ctx
);
142 intel_get_cliprects(intel
, &cliprects
, &num_cliprects
, &x_off
, &y_off
);
143 if (num_cliprects
!= 0) {
152 /* XXX: We fail to handle different inversion between read and draw framebuffer. */
154 /* Clip to destination buffer. */
157 if (!_mesa_clip_to_region(fb
->_Xmin
, fb
->_Ymin
,
158 fb
->_Xmax
, fb
->_Ymax
,
159 &dstx
, &dsty
, &width
, &height
))
161 /* Adjust src coords for our post-clipped destination origin */
162 srcx
+= dstx
- orig_dstx
;
163 srcy
+= dsty
- orig_dsty
;
165 /* Clip to source buffer. */
168 if (!_mesa_clip_to_region(0, 0,
169 read_fb
->Width
, read_fb
->Height
,
170 &srcx
, &srcy
, &width
, &height
))
172 /* Adjust dst coords for our post-clipped source origin */
173 dstx
+= srcx
- orig_srcx
;
174 dsty
+= srcy
- orig_srcy
;
176 /* Convert from GL to hardware coordinates:
179 /* copypixels to a system framebuffer */
181 dsty
= y_off
+ (fb
->Height
- dsty
- height
);
183 /* copypixels to a user framebuffer object */
188 /* Flip source Y if it's a system framebuffer. */
189 if (read_fb
->Name
== 0) {
190 srcx
= intel
->driReadDrawable
->x
+ srcx
;
191 srcy
= intel
->driReadDrawable
->y
+ (fb
->Height
- srcy
- height
);
194 delta_x
= srcx
- dstx
;
195 delta_y
= srcy
- dsty
;
196 /* Could do slightly more clipping: Eg, take the intersection of
197 * the destination cliprects and the read drawable cliprects
199 * This code will not overwrite other windows, but will
200 * introduce garbage when copying from obscured window regions.
202 for (i
= 0; i
< num_cliprects
; i
++) {
205 GLint clip_w
= width
;
206 GLint clip_h
= height
;
208 if (!_mesa_clip_to_region(cliprects
[i
].x1
, cliprects
[i
].y1
,
209 cliprects
[i
].x2
, cliprects
[i
].y2
,
210 &clip_x
, &clip_y
, &clip_w
, &clip_h
))
213 if (!intel_region_copy(intel
,
214 dst
, 0, clip_x
, clip_y
,
215 src
, 0, clip_x
+ delta_x
, clip_y
+ delta_y
,
217 ctx
->Color
.ColorLogicOpEnabled
?
218 ctx
->Color
.LogicOp
: GL_COPY
)) {
219 DBG("%s: blit failure\n", __FUNCTION__
);
226 intel_check_front_buffer_rendering(intel
);
228 DBG("%s: success\n", __FUNCTION__
);
234 intelCopyPixels(GLcontext
* ctx
,
235 GLint srcx
, GLint srcy
,
236 GLsizei width
, GLsizei height
,
237 GLint destx
, GLint desty
, GLenum type
)
239 if (INTEL_DEBUG
& DEBUG_PIXEL
)
240 fprintf(stderr
, "%s\n", __FUNCTION__
);
242 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
245 /* this will use swrast if needed */
246 _mesa_meta_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);