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"
39 #define FILE_DEBUG_FLAG DEBUG_PIXEL
41 static struct intel_region
*
42 copypix_src_region(struct intel_context
*intel
, GLenum type
)
46 return intel_readbuf_region(intel
);
48 /* Don't think this is really possible execpt at 16bpp, when we have no stencil.
50 if (intel
->depth_region
&& intel
->depth_region
->cpp
== 2)
51 return intel
->depth_region
;
53 /* Don't think this is really possible.
56 case GL_DEPTH_STENCIL_EXT
:
57 /* Does it matter whether it is stencil/depth or depth/stencil?
59 return intel
->depth_region
;
69 * Check if any fragment operations are in effect which might effect
70 * glCopyPixels. Differs from intel_check_blit_fragment_ops in that
74 intel_check_copypixel_blit_fragment_ops(GLcontext
* ctx
)
77 _mesa_update_state(ctx
);
79 /* Could do logicop with the blitter:
81 return !(ctx
->_ImageTransferState
||
82 ctx
->Color
.AlphaEnabled
||
85 ctx
->Stencil
._Enabled
||
86 !ctx
->Color
.ColorMask
[0] ||
87 !ctx
->Color
.ColorMask
[1] ||
88 !ctx
->Color
.ColorMask
[2] ||
89 !ctx
->Color
.ColorMask
[3] ||
90 ctx
->Texture
._EnabledUnits
||
91 ctx
->FragmentProgram
._Enabled
||
92 ctx
->Color
.BlendEnabled
);
97 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
100 do_blit_copypixels(GLcontext
* ctx
,
101 GLint srcx
, GLint srcy
,
102 GLsizei width
, GLsizei height
,
103 GLint dstx
, GLint dsty
, GLenum type
)
105 struct intel_context
*intel
= intel_context(ctx
);
106 struct intel_region
*dst
= intel_drawbuf_region(intel
);
107 struct intel_region
*src
= copypix_src_region(intel
, type
);
108 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
109 struct gl_framebuffer
*read_fb
= ctx
->ReadBuffer
;
110 unsigned int num_cliprects
;
111 drm_clip_rect_t
*cliprects
;
114 if (type
== GL_DEPTH
|| type
== GL_STENCIL
) {
115 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
116 fprintf(stderr
, "glCopyPixels() fallback: GL_DEPTH || GL_STENCIL\n");
120 /* Update draw buffer bounds */
121 _mesa_update_state(ctx
);
123 /* Copypixels can be more than a straight copy. Ensure all the
124 * extra operations are disabled:
126 if (!intel_check_copypixel_blit_fragment_ops(ctx
) ||
127 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
135 intelFlush(&intel
->ctx
);
137 LOCK_HARDWARE(intel
);
139 intel_get_cliprects(intel
, &cliprects
, &num_cliprects
, &x_off
, &y_off
);
140 if (num_cliprects
!= 0) {
149 /* XXX: We fail to handle different inversion between read and draw framebuffer. */
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 /* Convert from GL to hardware coordinates:
176 /* copypixels to a system framebuffer */
178 dsty
= y_off
+ (fb
->Height
- dsty
- height
);
180 /* copypixels to a user framebuffer object */
185 /* Flip source Y if it's a system framebuffer. */
186 if (read_fb
->Name
== 0) {
187 srcx
= intel
->driReadDrawable
->x
+ srcx
;
188 srcy
= intel
->driReadDrawable
->y
+ (fb
->Height
- srcy
- height
);
191 delta_x
= srcx
- dstx
;
192 delta_y
= srcy
- dsty
;
193 /* Could do slightly more clipping: Eg, take the intersection of
194 * the destination cliprects and the read drawable cliprects
196 * This code will not overwrite other windows, but will
197 * introduce garbage when copying from obscured window regions.
199 for (i
= 0; i
< num_cliprects
; i
++) {
202 GLint clip_w
= width
;
203 GLint clip_h
= height
;
205 if (!_mesa_clip_to_region(cliprects
[i
].x1
, cliprects
[i
].y1
,
206 cliprects
[i
].x2
, cliprects
[i
].y2
,
207 &clip_x
, &clip_y
, &clip_w
, &clip_h
))
210 if (!intel_region_copy(intel
,
211 dst
, 0, clip_x
, clip_y
,
212 src
, 0, clip_x
+ delta_x
, clip_y
+ delta_y
,
214 ctx
->Color
.ColorLogicOpEnabled
?
215 ctx
->Color
.LogicOp
: GL_COPY
)) {
216 DBG("%s: blit failure\n", __FUNCTION__
);
217 UNLOCK_HARDWARE(intel
);
223 UNLOCK_HARDWARE(intel
);
225 intel_check_front_buffer_rendering(intel
);
227 DBG("%s: success\n", __FUNCTION__
);
233 intelCopyPixels(GLcontext
* ctx
,
234 GLint srcx
, GLint srcy
,
235 GLsizei width
, GLsizei height
,
236 GLint destx
, GLint desty
, GLenum type
)
238 if (INTEL_DEBUG
& DEBUG_PIXEL
)
239 fprintf(stderr
, "%s\n", __FUNCTION__
);
241 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
244 /* this will use swrast if needed */
245 _mesa_meta_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);