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_buffers.h"
41 #include "intel_blit.h"
42 #include "intel_regions.h"
43 #include "intel_tris.h"
44 #include "intel_pixel.h"
46 #define FILE_DEBUG_FLAG DEBUG_PIXEL
48 static struct intel_region
*
49 copypix_src_region(struct intel_context
*intel
, GLenum type
)
53 return intel_readbuf_region(intel
);
55 /* Don't think this is really possible execpt at 16bpp, when we have no stencil.
57 if (intel
->intelScreen
->depth_region
&&
58 intel
->intelScreen
->depth_region
->cpp
== 2)
59 return intel
->intelScreen
->depth_region
;
61 /* Don't think this is really possible.
64 case GL_DEPTH_STENCIL_EXT
:
65 /* Does it matter whether it is stencil/depth or depth/stencil?
67 return intel
->intelScreen
->depth_region
;
77 * Check if any fragment operations are in effect which might effect
78 * glCopyPixels. Differs from intel_check_blit_fragment_ops in that
82 intel_check_copypixel_blit_fragment_ops(GLcontext
* ctx
)
85 _mesa_update_state(ctx
);
87 /* Could do logicop with the blitter:
89 return !(ctx
->_ImageTransferState
||
90 ctx
->Color
.AlphaEnabled
||
93 ctx
->Stencil
.Enabled
||
94 !ctx
->Color
.ColorMask
[0] ||
95 !ctx
->Color
.ColorMask
[1] ||
96 !ctx
->Color
.ColorMask
[2] ||
97 !ctx
->Color
.ColorMask
[3] ||
98 ctx
->Texture
._EnabledUnits
||
99 ctx
->FragmentProgram
._Enabled
||
100 ctx
->Color
.BlendEnabled
);
103 /* Doesn't work for overlapping regions. Could do a double copy or
107 do_texture_copypixels(GLcontext
* ctx
,
108 GLint srcx
, GLint srcy
,
109 GLsizei width
, GLsizei height
,
110 GLint dstx
, GLint dsty
, GLenum type
)
112 struct intel_context
*intel
= intel_context(ctx
);
113 struct intel_region
*dst
= intel_drawbuf_region(intel
);
114 struct intel_region
*src
= copypix_src_region(intel
, type
);
118 DBG("%s %d,%d %dx%d --> %d,%d\n", __FUNCTION__
,
119 srcx
, srcy
, width
, height
, dstx
, dsty
);
121 if (!src
|| !dst
|| type
!= GL_COLOR
)
124 /* Can't handle overlapping regions. Don't have sufficient control
125 * over rasterization to pull it off in-place. Punt on these for
128 * XXX: do a copy to a temporary.
130 if (src
->buffer
== dst
->buffer
) {
131 drm_clip_rect_t srcbox
;
132 drm_clip_rect_t dstbox
;
137 srcbox
.x2
= srcx
+ width
;
138 srcbox
.y2
= srcy
+ height
;
142 dstbox
.x2
= dstx
+ width
* ctx
->Pixel
.ZoomX
;
143 dstbox
.y2
= dsty
+ height
* ctx
->Pixel
.ZoomY
;
145 DBG("src %d,%d %d,%d\n", srcbox
.x1
, srcbox
.y1
, srcbox
.x2
, srcbox
.y2
);
146 DBG("dst %d,%d %d,%d (%dx%d) (%f,%f)\n", dstbox
.x1
, dstbox
.y1
, dstbox
.x2
, dstbox
.y2
,
147 width
, height
, ctx
->Pixel
.ZoomX
, ctx
->Pixel
.ZoomY
);
149 if (intel_intersect_cliprects(&tmp
, &srcbox
, &dstbox
)) {
150 DBG("%s: regions overlap\n", __FUNCTION__
);
155 intelFlush(&intel
->ctx
);
157 intel
->vtbl
.install_meta_state(intel
);
159 /* Is this true? Also will need to turn depth testing on according
162 intel
->vtbl
.meta_no_stencil_write(intel
);
163 intel
->vtbl
.meta_no_depth_write(intel
);
165 /* Set the 3d engine to draw into the destination region:
167 intel
->vtbl
.meta_draw_region(intel
, dst
, intel
->intelScreen
->depth_region
);
169 intel
->vtbl
.meta_import_pixel_state(intel
);
173 src_type
= GL_UNSIGNED_SHORT_5_6_5
;
176 src_format
= GL_BGRA
;
177 src_type
= GL_UNSIGNED_BYTE
;
180 /* Set the frontbuffer up as a large rectangular texture.
182 if (!intel
->vtbl
.meta_tex_rect_source(intel
, src
->buffer
, 0,
184 src
->height
, src_format
, src_type
)) {
185 intel
->vtbl
.leave_meta_state(intel
);
190 intel
->vtbl
.meta_texture_blend_replace(intel
);
192 LOCK_HARDWARE(intel
);
194 if (intel
->driDrawable
->numClipRects
) {
195 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
198 srcy
= dPriv
->h
- srcy
- height
; /* convert from gl to hardware coords */
203 /* Clip against the source region. This is the only source
204 * clipping we do. XXX: Just set the texcord wrap mode to clamp
212 if (!_mesa_clip_to_region(0, 0, src
->pitch
, src
->height
,
213 &srcx
, &srcy
, &width
, &height
))
216 dstx
+= srcx
- orig_x
;
217 dsty
+= (srcy
- orig_y
) * ctx
->Pixel
.ZoomY
;
220 /* Just use the regular cliprect mechanism... Does this need to
221 * even hold the lock???
223 intel_meta_draw_quad(intel
,
225 dstx
+ width
* ctx
->Pixel
.ZoomX
,
226 dPriv
->h
- (dsty
+ height
* ctx
->Pixel
.ZoomY
),
227 dPriv
->h
- (dsty
), 0, /* XXX: what z value? */
229 srcx
, srcx
+ width
, srcy
, srcy
+ height
);
232 intel
->vtbl
.leave_meta_state(intel
);
233 intel_batchbuffer_flush(intel
->batch
);
235 UNLOCK_HARDWARE(intel
);
237 DBG("%s: success\n", __FUNCTION__
);
246 * CopyPixels with the blitter. Don't support zooming, pixel transfer, etc.
249 do_blit_copypixels(GLcontext
* ctx
,
250 GLint srcx
, GLint srcy
,
251 GLsizei width
, GLsizei height
,
252 GLint dstx
, GLint dsty
, GLenum type
)
254 struct intel_context
*intel
= intel_context(ctx
);
255 struct intel_region
*dst
= intel_drawbuf_region(intel
);
256 struct intel_region
*src
= copypix_src_region(intel
, type
);
258 /* Copypixels can be more than a straight copy. Ensure all the
259 * extra operations are disabled:
261 if (!intel_check_copypixel_blit_fragment_ops(ctx
) ||
262 ctx
->Pixel
.ZoomX
!= 1.0F
|| ctx
->Pixel
.ZoomY
!= 1.0F
)
270 intelFlush(&intel
->ctx
);
272 LOCK_HARDWARE(intel
);
274 if (intel
->driDrawable
->numClipRects
) {
275 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
276 drm_clip_rect_t
*box
= dPriv
->pClipRects
;
277 drm_clip_rect_t dest_rect
;
278 GLint nbox
= dPriv
->numClipRects
;
283 /* Do scissoring in GL coordinates:
285 if (ctx
->Scissor
.Enabled
)
287 GLint x
= ctx
->Scissor
.X
;
288 GLint y
= ctx
->Scissor
.Y
;
289 GLuint w
= ctx
->Scissor
.Width
;
290 GLuint h
= ctx
->Scissor
.Height
;
291 GLint dx
= dstx
- srcx
;
292 GLint dy
= dsty
- srcy
;
294 if (!_mesa_clip_to_region(x
, y
, x
+w
-1, y
+h
-1, &dstx
, &dsty
, &width
, &height
))
301 /* Convert from GL to hardware coordinates:
303 dsty
= dPriv
->h
- dsty
- height
;
304 srcy
= dPriv
->h
- srcy
- height
;
310 /* Clip against the source region. This is the only source
311 * clipping we do. Dst is clipped with cliprects below.
314 delta_x
= srcx
- dstx
;
315 delta_y
= srcy
- dsty
;
317 if (!_mesa_clip_to_region(0, 0, src
->pitch
, src
->height
,
318 &srcx
, &srcy
, &width
, &height
))
321 dstx
= srcx
- delta_x
;
322 dsty
= srcy
- delta_y
;
327 dest_rect
.x2
= dstx
+ width
;
328 dest_rect
.y2
= dsty
+ height
;
330 /* Could do slightly more clipping: Eg, take the intersection of
331 * the existing set of cliprects and those cliprects translated
332 * by delta_x, delta_y:
334 * This code will not overwrite other windows, but will
335 * introduce garbage when copying from obscured window regions.
337 for (i
= 0; i
< nbox
; i
++) {
338 drm_clip_rect_t rect
;
340 if (!intel_intersect_cliprects(&rect
, &dest_rect
, &box
[i
]))
344 intelEmitCopyBlit(intel
, dst
->cpp
,
345 src
->pitch
, src
->buffer
, 0,
346 dst
->pitch
, dst
->buffer
, 0,
348 rect
.y1
+ delta_y
, /* srcx, srcy */
349 rect
.x1
, rect
.y1
, /* dstx, dsty */
350 rect
.x2
- rect
.x1
, rect
.y2
- rect
.y1
,
351 ctx
->Color
.ColorLogicOpEnabled
?
352 ctx
->Color
.LogicOp
: GL_COPY
);
356 intel_batchbuffer_flush(intel
->batch
);
358 UNLOCK_HARDWARE(intel
);
360 DBG("%s: success\n", __FUNCTION__
);
366 intelCopyPixels(GLcontext
* ctx
,
367 GLint srcx
, GLint srcy
,
368 GLsizei width
, GLsizei height
,
369 GLint destx
, GLint desty
, GLenum type
)
371 if (INTEL_DEBUG
& DEBUG_PIXEL
)
372 fprintf(stderr
, "%s\n", __FUNCTION__
);
374 if (do_blit_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
377 if (do_texture_copypixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
))
380 DBG("fallback to _swrast_CopyPixels\n");
382 _swrast_CopyPixels(ctx
, srcx
, srcy
, width
, height
, destx
, desty
, type
);