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 **************************************************************************/
34 #include "swrast/swrast.h"
36 #include "intel_screen.h"
37 #include "intel_context.h"
38 #include "intel_ioctl.h"
39 #include "intel_batchbuffer.h"
40 #include "intel_blit.h"
41 #include "intel_regions.h"
42 #include "intel_buffers.h"
43 #include "intel_pixel.h"
45 #define FILE_DEBUG_FLAG DEBUG_PIXEL
47 static struct intel_region
*
48 copypix_src_region(struct intel_context
*intel
, GLenum type
)
52 return intel_readbuf_region(intel
);
54 /* Don't think this is really possible execpt at 16bpp, when we have no stencil.
56 if (intel
->depth_region
&& intel
->depth_region
->cpp
== 2)
57 return intel
->depth_region
;
59 /* Don't think this is really possible.
62 case GL_DEPTH_STENCIL_EXT
:
63 /* Does it matter whether it is stencil/depth or depth/stencil?
65 return intel
->depth_region
;
77 * Check if any fragment operations are in effect which might effect
81 intel_check_blit_fragment_ops(GLcontext
* ctx
)
84 _mesa_update_state(ctx
);
86 return !(ctx
->_ImageTransferState
||
87 ctx
->RenderMode
!= GL_RENDER
||
88 ctx
->Color
.AlphaEnabled
||
91 ctx
->Stencil
.Enabled
||
92 !ctx
->Color
.ColorMask
[0] ||
93 !ctx
->Color
.ColorMask
[1] ||
94 !ctx
->Color
.ColorMask
[2] ||
95 !ctx
->Color
.ColorMask
[3] || /* can do this! */
96 ctx
->Texture
._EnabledUnits
||
97 ctx
->FragmentProgram
._Enabled
||
98 ctx
->Color
.BlendEnabled
);
101 /* Doesn't work for overlapping regions. Could do a double copy or
105 do_texture_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
);
116 DBG("%s %d,%d %dx%d --> %d,%d\n", __FUNCTION__
,
117 srcx
, srcy
, width
, height
, dstx
, dsty
);
119 if (!src
|| !dst
|| type
!= GL_COLOR
||
120 ctx
->_ImageTransferState
||
121 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
||
122 ctx
->RenderMode
!= GL_RENDER
||
123 ctx
->Texture
._EnabledUnits
||
124 ctx
->FragmentProgram
._Enabled
||
128 /* Can't handle overlapping regions. Don't have sufficient control
129 * over rasterization to pull it off in-place. Punt on these for
132 * XXX: do a copy to a temporary.
134 if (src
->buffer
== dst
->buffer
) {
135 drm_clip_rect_t srcbox
;
136 drm_clip_rect_t dstbox
;
141 srcbox
.x2
= srcx
+ width
- 1;
142 srcbox
.y2
= srcy
+ height
- 1;
146 dstbox
.x2
= dstx
+ width
- 1;
147 dstbox
.y2
= dsty
+ height
- 1;
149 DBG("src %d,%d %d,%d\n", srcbox
.x1
, srcbox
.y1
, srcbox
.x2
, srcbox
.y2
);
150 DBG("dst %d,%d %d,%d (%dx%d) (%f,%f)\n", dstbox
.x1
, dstbox
.y1
, dstbox
.x2
, dstbox
.y2
,
151 width
, height
, ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
153 if (intel_intersect_cliprects(&tmp
, &srcbox
, &dstbox
)) {
154 DBG("%s: regions overlap\n", __FUNCTION__
);
159 intelFlush(&intel
->ctx
);
161 intel
->vtbl
.install_meta_state(intel
);
163 /* Is this true? Also will need to turn depth testing on according
166 intel
->vtbl
.meta_no_stencil_write(intel
);
167 intel
->vtbl
.meta_no_depth_write(intel
);
169 /* Set the 3d engine to draw into the destination region:
171 intel
->vtbl
.meta_draw_region(intel
, dst
, intel
->depth_region
);
173 intel
->vtbl
.meta_import_pixel_state(intel
);
177 src_type
= GL_UNSIGNED_SHORT_5_6_5
;
180 src_format
= GL_BGRA
;
181 src_type
= GL_UNSIGNED_BYTE
;
184 /* Set the frontbuffer up as a large rectangular texture.
186 intel
->vtbl
.meta_frame_buffer_texture( intel
, srcx
- dstx
, srcy
- dsty
);
188 intel
->vtbl
.meta_texture_blend_replace(intel
);
190 if (intel
->driDrawable
->numClipRects
)
191 intel
->vtbl
.meta_draw_quad( intel
,
194 ctx
->Current
.RasterPos
[ 2 ],
195 0, 0.0, 0.0, 0.0, 0.0 );
197 intel
->vtbl
.leave_meta_state( intel
);
199 DBG("%s: success\n", __FUNCTION__
);
204 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
207 do_blit_copypixels(GLcontext
* ctx
,
208 GLint srcx
, GLint srcy
,
209 GLsizei width
, GLsizei height
,
210 GLint dstx
, GLint dsty
, GLenum type
)
212 struct intel_context
*intel
= intel_context(ctx
);
213 struct intel_region
*dst
= intel_drawbuf_region(intel
);
214 struct intel_region
*src
= copypix_src_region(intel
, type
);
216 /* Copypixels can be more than a straight copy. Ensure all the
217 * extra operations are disabled:
219 if (!intel_check_blit_fragment_ops(ctx
) ||
220 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
228 intelFlush(&intel
->ctx
);
230 /* intel->vtbl.render_start(intel); */
231 /* intel->vtbl.emit_state(intel); */
233 LOCK_HARDWARE(intel
);
235 if (intel
->driDrawable
->numClipRects
) {
236 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
237 __DRIdrawablePrivate
*dReadPriv
= intel
->driReadDrawable
;
238 drm_clip_rect_t
*box
= dPriv
->pClipRects
;
239 drm_clip_rect_t dest_rect
;
240 GLint nbox
= dPriv
->numClipRects
;
245 /* Do scissoring in GL coordinates:
247 if (ctx
->Scissor
.Enabled
)
249 GLint x
= ctx
->Scissor
.X
;
250 GLint y
= ctx
->Scissor
.Y
;
251 GLuint w
= ctx
->Scissor
.Width
;
252 GLuint h
= ctx
->Scissor
.Height
;
253 GLint dx
= dstx
- srcx
;
254 GLint dy
= dsty
- srcy
;
256 if (!_mesa_clip_to_region(x
, y
, x
+w
-1, y
+h
-1, &dstx
, &dsty
, &width
, &height
))
263 /* Convert from GL to hardware coordinates:
265 dsty
= dPriv
->h
- dsty
- height
;
266 srcy
= dPriv
->h
- srcy
- height
;
269 srcx
+= dReadPriv
->x
;
270 srcy
+= dReadPriv
->y
;
272 /* Clip against the source region. This is the only source
273 * clipping we do. Dst is clipped with cliprects below.
276 delta_x
= srcx
- dstx
;
277 delta_y
= srcy
- dsty
;
279 if (!_mesa_clip_to_region(0, 0, src
->pitch
, src
->height
,
280 &srcx
, &srcy
, &width
, &height
))
283 dstx
= srcx
- delta_x
;
284 dsty
= srcy
- delta_y
;
289 dest_rect
.x2
= dstx
+ width
;
290 dest_rect
.y2
= dsty
+ height
;
292 /* intel->vtbl.emit_flush(intel, 0); */
294 /* Could do slightly more clipping: Eg, take the intersection of
295 * the existing set of cliprects and those cliprects translated
296 * by delta_x, delta_y:
298 * This code will not overwrite other windows, but will
299 * introduce garbage when copying from obscured window regions.
301 for (i
= 0; i
< nbox
; i
++) {
302 drm_clip_rect_t rect
;
304 if (!intel_intersect_cliprects(&rect
, &dest_rect
, &box
[i
]))
308 intelEmitCopyBlit(intel
,
310 src
->pitch
, src
->buffer
, 0, src
->tiled
,
311 dst
->pitch
, dst
->buffer
, 0, dst
->tiled
,
313 rect
.y1
+ delta_y
, /* srcx, srcy */
314 rect
.x1
, rect
.y1
, /* dstx, dsty */
315 rect
.x2
- rect
.x1
, rect
.y2
- rect
.y1
,
316 ctx
->Color
.ColorLogicOpEnabled
?
317 ctx
->Color
.LogicOp
: GL_COPY
);
321 intel_batchbuffer_flush(intel
->batch
);
323 UNLOCK_HARDWARE(intel
);
328 intelCopyPixels(GLcontext
* ctx
,
329 GLint srcx
, GLint srcy
,
330 GLsizei width
, GLsizei height
,
331 GLint destx
, GLint desty
, GLenum type
)
333 if (INTEL_DEBUG
& DEBUG_PIXEL
)
334 fprintf(stderr
, "%s\n", __FUNCTION__
);
336 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
339 if (do_texture_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
342 if (INTEL_DEBUG
& DEBUG_PIXEL
)
343 _mesa_printf("fallback to _swrast_CopyPixels\n");
345 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);