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"
44 static struct intel_region
*
45 copypix_src_region(struct intel_context
*intel
, GLenum type
)
49 return intel_readbuf_region(intel
);
51 /* Don't think this is really possible execpt at 16bpp, when we have no stencil.
53 if (intel
->depth_region
&& intel
->depth_region
->cpp
== 2)
54 return intel
->depth_region
;
56 /* Don't think this is really possible.
59 case GL_DEPTH_STENCIL_EXT
:
60 /* Does it matter whether it is stencil/depth or depth/stencil?
62 return intel
->depth_region
;
74 * Check if any fragment operations are in effect which might effect
78 intel_check_blit_fragment_ops(GLcontext
* ctx
)
81 _mesa_update_state(ctx
);
83 return !(ctx
->_ImageTransferState
||
84 ctx
->RenderMode
!= GL_RENDER
||
85 ctx
->Color
.AlphaEnabled
||
88 ctx
->Stencil
.Enabled
||
89 !ctx
->Color
.ColorMask
[0] ||
90 !ctx
->Color
.ColorMask
[1] ||
91 !ctx
->Color
.ColorMask
[2] ||
92 !ctx
->Color
.ColorMask
[3] || /* can do this! */
93 ctx
->Texture
._EnabledUnits
||
94 ctx
->FragmentProgram
._Enabled
||
95 ctx
->Color
.BlendEnabled
);
98 /* Doesn't work for overlapping regions. Could do a double copy or
102 do_texture_copypixels(GLcontext
* ctx
,
103 GLint srcx
, GLint srcy
,
104 GLsizei width
, GLsizei height
,
105 GLint dstx
, GLint dsty
, GLenum type
)
107 struct intel_context
*intel
= intel_context(ctx
);
108 struct intel_region
*dst
= intel_drawbuf_region(intel
);
109 struct intel_region
*src
= copypix_src_region(intel
, type
);
113 DBG("%s %d,%d %dx%d --> %d,%d\n", __FUNCTION__
,
114 srcx
, srcy
, width
, height
, dstx
, dsty
);
116 if (!src
|| !dst
|| type
!= GL_COLOR
||
117 ctx
->_ImageTransferState
||
118 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
||
119 ctx
->RenderMode
!= GL_RENDER
||
120 ctx
->Texture
._EnabledUnits
||
121 ctx
->FragmentProgram
._Enabled
||
125 /* Can't handle overlapping regions. Don't have sufficient control
126 * over rasterization to pull it off in-place. Punt on these for
129 * XXX: do a copy to a temporary.
131 if (src
->buffer
== dst
->buffer
) {
132 drm_clip_rect_t srcbox
;
133 drm_clip_rect_t dstbox
;
138 srcbox
.x2
= srcx
+ width
- 1;
139 srcbox
.y2
= srcy
+ height
- 1;
143 dstbox
.x2
= dstx
+ width
- 1;
144 dstbox
.y2
= dsty
+ height
- 1;
146 DBG("src %d,%d %d,%d\n", srcbox
.x1
, srcbox
.y1
, srcbox
.x2
, srcbox
.y2
);
147 DBG("dst %d,%d %d,%d (%dx%d) (%f,%f)\n", dstbox
.x1
, dstbox
.y1
, dstbox
.x2
, dstbox
.y2
,
148 width
, height
, ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
150 if (intel_intersect_cliprects(&tmp
, &srcbox
, &dstbox
)) {
151 DBG("%s: regions overlap\n", __FUNCTION__
);
156 intelFlush(&intel
->ctx
);
158 intel
->vtbl
.install_meta_state(intel
);
160 /* Is this true? Also will need to turn depth testing on according
163 intel
->vtbl
.meta_no_stencil_write(intel
);
164 intel
->vtbl
.meta_no_depth_write(intel
);
166 /* Set the 3d engine to draw into the destination region:
168 intel
->vtbl
.meta_draw_region(intel
, dst
, intel
->depth_region
);
170 intel
->vtbl
.meta_import_pixel_state(intel
);
174 src_type
= GL_UNSIGNED_SHORT_5_6_5
;
177 src_format
= GL_BGRA
;
178 src_type
= GL_UNSIGNED_BYTE
;
181 /* Set the frontbuffer up as a large rectangular texture.
183 intel
->vtbl
.meta_frame_buffer_texture( intel
, srcx
- dstx
, srcy
- dsty
);
185 intel
->vtbl
.meta_texture_blend_replace(intel
);
187 if (intel
->driDrawable
->numClipRects
)
188 intel
->vtbl
.meta_draw_quad( intel
,
191 ctx
->Current
.RasterPos
[ 2 ],
192 0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0 );
194 intel
->vtbl
.leave_meta_state( intel
);
196 DBG("%s: success\n", __FUNCTION__
);
201 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
204 do_blit_copypixels(GLcontext
* ctx
,
205 GLint srcx
, GLint srcy
,
206 GLsizei width
, GLsizei height
,
207 GLint dstx
, GLint dsty
, GLenum type
)
209 struct intel_context
*intel
= intel_context(ctx
);
210 struct intel_region
*dst
= intel_drawbuf_region(intel
);
211 struct intel_region
*src
= copypix_src_region(intel
, type
);
213 /* Copypixels can be more than a straight copy. Ensure all the
214 * extra operations are disabled:
216 if (!intel_check_blit_fragment_ops(ctx
) ||
217 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
225 intelFlush(&intel
->ctx
);
227 /* intel->vtbl.render_start(intel); */
228 /* intel->vtbl.emit_state(intel); */
230 LOCK_HARDWARE(intel
);
232 if (intel
->driDrawable
->numClipRects
) {
233 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
234 drm_clip_rect_t
*box
= dPriv
->pClipRects
;
235 drm_clip_rect_t dest_rect
;
236 GLint nbox
= dPriv
->numClipRects
;
241 /* Do scissoring in GL coordinates:
243 if (ctx
->Scissor
.Enabled
)
245 GLint x
= ctx
->Scissor
.X
;
246 GLint y
= ctx
->Scissor
.Y
;
247 GLuint w
= ctx
->Scissor
.Width
;
248 GLuint h
= ctx
->Scissor
.Height
;
249 GLint dx
= dstx
- srcx
;
250 GLint dy
= dsty
- srcy
;
252 if (!_mesa_clip_to_region(x
, y
, x
+w
-1, y
+h
-1, &dstx
, &dsty
, &width
, &height
))
259 /* Convert from GL to hardware coordinates:
261 dsty
= dPriv
->h
- dsty
- height
;
262 srcy
= dPriv
->h
- srcy
- height
;
268 /* Clip against the source region. This is the only source
269 * clipping we do. Dst is clipped with cliprects below.
272 delta_x
= srcx
- dstx
;
273 delta_y
= srcy
- dsty
;
275 if (!_mesa_clip_to_region(0, 0, src
->pitch
, src
->height
,
276 &srcx
, &srcy
, &width
, &height
))
279 dstx
= srcx
- delta_x
;
280 dsty
= srcy
- delta_y
;
285 dest_rect
.x2
= dstx
+ width
;
286 dest_rect
.y2
= dsty
+ height
;
288 /* intel->vtbl.emit_flush(intel, 0); */
290 /* Could do slightly more clipping: Eg, take the intersection of
291 * the existing set of cliprects and those cliprects translated
292 * by delta_x, delta_y:
294 * This code will not overwrite other windows, but will
295 * introduce garbage when copying from obscured window regions.
297 for (i
= 0; i
< nbox
; i
++) {
298 drm_clip_rect_t rect
;
300 if (!intel_intersect_cliprects(&rect
, &dest_rect
, &box
[i
]))
304 intelEmitCopyBlit(intel
,
306 src
->pitch
, src
->buffer
, 0, src
->tiled
,
307 dst
->pitch
, dst
->buffer
, 0, dst
->tiled
,
309 rect
.y1
+ delta_y
, /* srcx, srcy */
310 rect
.x1
, rect
.y1
, /* dstx, dsty */
311 rect
.x2
- rect
.x1
, rect
.y2
- rect
.y1
,
312 ctx
->Color
.ColorLogicOpEnabled
?
313 ctx
->Color
.LogicOp
: GL_COPY
);
316 intel
->need_flush
= GL_TRUE
;
318 intel_batchbuffer_flush(intel
->batch
);
320 UNLOCK_HARDWARE(intel
);
325 intelCopyPixels(GLcontext
* ctx
,
326 GLint srcx
, GLint srcy
,
327 GLsizei width
, GLsizei height
,
328 GLint destx
, GLint desty
, GLenum type
)
330 if (INTEL_DEBUG
& DEBUG_PIXEL
)
331 fprintf(stderr
, "%s\n", __FUNCTION__
);
333 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
336 if (do_texture_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
339 if (INTEL_DEBUG
& DEBUG_PIXEL
)
340 _mesa_printf("fallback to _swrast_CopyPixels\n");
342 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);