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 **************************************************************************/
37 #include "intel_reg.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_context.h"
40 #include "intel_blit.h"
41 #include "intel_regions.h"
49 * Copy the back buffer to the front buffer.
51 void intelCopyBuffer( const __DRIdrawablePrivate
*dPriv
,
52 const drm_clip_rect_t
*rect
)
54 struct intel_context
*intel
;
55 GLboolean missed_target
;
58 DBG("%s\n", __FUNCTION__
);
61 assert(dPriv
->driContextPriv
);
62 assert(dPriv
->driContextPriv
->driverPrivate
);
64 intel
= (struct intel_context
*) dPriv
->driContextPriv
->driverPrivate
;
65 intelFlush( &intel
->ctx
);
68 bmFinishFence(intel
, intel
->last_swap_fence
);
70 /* The LOCK_HARDWARE is required for the cliprects. Buffer offsets
71 * should work regardless.
73 LOCK_HARDWARE( intel
);
77 /* This is a really crappy way to do wait-for-vblank. I guess
78 * it sortof works in the single-application case.
80 UNLOCK_HARDWARE( intel
);
81 driWaitForVBlank( dPriv
, &intel
->vbl_seq
, intel
->vblank_flags
, & missed_target
);
82 LOCK_HARDWARE( intel
);
86 intelScreenPrivate
*intelScreen
= intel
->intelScreen
;
87 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
88 int nbox
= dPriv
->numClipRects
;
89 drm_clip_rect_t
*pbox
= dPriv
->pClipRects
;
90 int cpp
= intelScreen
->cpp
;
91 struct intel_region
*src
, *dst
;
94 int src_pitch
, dst_pitch
;
96 if (intel
->sarea
->pf_current_page
== 0) {
97 dst
= intel
->front_region
;
98 src
= intel
->back_region
;
102 src
= intel
->front_region
;
103 dst
= intel
->back_region
;
106 src_pitch
= src
->pitch
* src
->cpp
;
107 dst_pitch
= dst
->pitch
* dst
->cpp
;
110 BR13
= (0xCC << 16) | (1<<24);
111 CMD
= XY_SRC_COPY_BLT_CMD
;
114 BR13
= (0xCC << 16) | (1<<24) | (1<<25);
115 CMD
= (XY_SRC_COPY_BLT_CMD
| XY_SRC_COPY_BLT_WRITE_ALPHA
|
116 XY_SRC_COPY_BLT_WRITE_RGB
);
129 for (i
= 0 ; i
< nbox
; i
++, pbox
++)
131 drm_clip_rect_t tmp
= *pbox
;
134 if (!intel_intersect_cliprects(&tmp
, &tmp
, rect
))
139 if (tmp
.x1
> tmp
.x2
||
141 tmp
.x2
> intelScreen
->width
||
142 tmp
.y2
> intelScreen
->height
)
145 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
147 OUT_BATCH( dst_pitch
| BR13
);
148 OUT_BATCH( (tmp
.y1
<< 16) | tmp
.x1
);
149 OUT_BATCH( (tmp
.y2
<< 16) | tmp
.x2
);
150 OUT_BATCH( bmBufferOffset(intel
, dst
->buffer
) );
151 OUT_BATCH( (tmp
.y1
<< 16) | tmp
.x1
);
152 OUT_BATCH( src_pitch
);
153 OUT_BATCH( bmBufferOffset(intel
, src
->buffer
) );
158 intel_batchbuffer_flush( intel
->batch
);
159 intel
->second_last_swap_fence
= intel
->last_swap_fence
;
160 intel
->last_swap_fence
= bmSetFence( intel
);
161 UNLOCK_HARDWARE( intel
);
166 (*dri_interface
->getUST
)(&ust
);
168 intel
->swap_missed_count
++;
169 intel
->swap_missed_ust
= ust
- intel
->swap_ust
;
172 intel
->swap_ust
= ust
;
180 void intelEmitFillBlit( struct intel_context
*intel
,
183 struct buffer
*dst_buffer
,
186 GLshort x
, GLshort y
,
187 GLshort w
, GLshort h
,
199 BR13
= (0xF0 << 16) | (1<<24);
200 CMD
= XY_COLOR_BLT_CMD
;
203 BR13
= (0xF0 << 16) | (1<<24) | (1<<25);
204 CMD
= (XY_COLOR_BLT_CMD
| XY_COLOR_BLT_WRITE_ALPHA
|
205 XY_COLOR_BLT_WRITE_RGB
);
216 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
218 OUT_BATCH( dst_pitch
| BR13
);
219 OUT_BATCH( (y
<< 16) | x
);
220 OUT_BATCH( ((y
+h
) << 16) | (x
+w
) );
221 OUT_BATCH( bmBufferOffset(intel
, dst_buffer
) + dst_offset
);
229 void intelEmitCopyBlit( struct intel_context
*intel
,
232 struct buffer
*src_buffer
,
236 struct buffer
*dst_buffer
,
239 GLshort src_x
, GLshort src_y
,
240 GLshort dst_x
, GLshort dst_y
,
241 GLshort w
, GLshort h
)
244 int dst_y2
= dst_y
+ h
;
245 int dst_x2
= dst_x
+ w
;
249 DBG("%s src:buf(%d)/%d %d,%d dst:buf(%d)/%d %d,%d sz:%dx%d\n",
251 src_buffer
, src_pitch
, src_x
, src_y
,
252 dst_buffer
, dst_pitch
, dst_x
, dst_y
,
262 BR13
= (0xCC << 16) | (1<<24);
263 CMD
= XY_SRC_COPY_BLT_CMD
;
266 BR13
= (0xCC << 16) | (1<<24) | (1<<25);
267 CMD
= (XY_SRC_COPY_BLT_CMD
| XY_SRC_COPY_BLT_WRITE_ALPHA
|
268 XY_SRC_COPY_BLT_WRITE_RGB
);
284 if (dst_y2
< dst_y
||
292 /* Initial y values don't seem to work with negative pitches. If
293 * we adjust the offsets manually (below), it seems to work fine.
296 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
298 OUT_BATCH( dst_pitch
| BR13
);
299 OUT_BATCH( (dst_y
<< 16) | dst_x
);
300 OUT_BATCH( (dst_y2
<< 16) | dst_x2
);
301 OUT_BATCH( bmBufferOffset(intel
, dst_buffer
) + dst_offset
);
302 OUT_BATCH( (src_y
<< 16) | src_x
);
303 OUT_BATCH( src_pitch
);
304 OUT_BATCH( bmBufferOffset(intel
, src_buffer
) + src_offset
);
308 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
310 OUT_BATCH( (dst_pitch
& 0xffff) | BR13
);
311 OUT_BATCH( (0 << 16) | dst_x
);
312 OUT_BATCH( (h
<< 16) | dst_x2
);
313 OUT_BATCH( bmBufferOffset(intel
, dst_buffer
) + dst_offset
+ dst_y
* dst_pitch
);
314 OUT_BATCH( (0 << 16) | src_x
);
315 OUT_BATCH( (src_pitch
& 0xffff) );
316 OUT_BATCH( bmBufferOffset(intel
, src_buffer
) + src_offset
+ src_y
* src_pitch
);
323 void intelClearWithBlit(GLcontext
*ctx
, GLbitfield flags
, GLboolean all
,
324 GLint cx1
, GLint cy1
, GLint cw
, GLint ch
)
326 struct intel_context
*intel
= intel_context( ctx
);
327 intelScreenPrivate
*intelScreen
= intel
->intelScreen
;
328 GLuint clear_depth
, clear_color
;
330 GLint cpp
= intelScreen
->cpp
;
332 struct intel_region
*front
= intel
->front_region
;
333 struct intel_region
*back
= intel
->back_region
;
334 struct intel_region
*depth
= intel
->depth_region
;
335 GLuint BR13
, FRONT_CMD
, BACK_CMD
, DEPTH_CMD
;
342 clear_color
= intel
->ClearColor
;
345 if (flags
& BUFFER_BIT_DEPTH
) {
346 clear_depth
= (GLuint
)(ctx
->Depth
.Clear
* intel
->ClearDepth
);
349 if (flags
& BUFFER_BIT_STENCIL
) {
350 clear_depth
|= (ctx
->Stencil
.Clear
& 0xff) << 24;
355 BR13
= (0xF0 << 16) | (1<<24);
356 BACK_CMD
= FRONT_CMD
= XY_COLOR_BLT_CMD
;
357 DEPTH_CMD
= XY_COLOR_BLT_CMD
;
360 BR13
= (0xF0 << 16) | (1<<24) | (1<<25);
361 BACK_CMD
= FRONT_CMD
= (XY_COLOR_BLT_CMD
|
362 XY_COLOR_BLT_WRITE_ALPHA
|
363 XY_COLOR_BLT_WRITE_RGB
);
364 DEPTH_CMD
= XY_COLOR_BLT_CMD
;
365 if (flags
& BUFFER_BIT_DEPTH
) DEPTH_CMD
|= XY_COLOR_BLT_WRITE_RGB
;
366 if (flags
& BUFFER_BIT_STENCIL
) DEPTH_CMD
|= XY_COLOR_BLT_WRITE_ALPHA
;
374 intelFlush( &intel
->ctx
);
375 LOCK_HARDWARE( intel
);
377 /* Refresh the cx/y/w/h values as they may have been invalidated
378 * by a new window position or size picked up when we did
379 * LOCK_HARDWARE above. The values passed by mesa are not
383 cx
= ctx
->DrawBuffer
->_Xmin
;
384 cy
= ctx
->DrawBuffer
->_Ymin
;
385 ch
= ctx
->DrawBuffer
->_Ymax
- ctx
->DrawBuffer
->_Ymin
;
386 cw
= ctx
->DrawBuffer
->_Xmax
- ctx
->DrawBuffer
->_Xmin
;
389 /* flip top to bottom */
390 cy
= intel
->driDrawable
->h
-cy1
-ch
;
391 cx
= cx1
+ intel
->drawX
;
394 /* adjust for page flipping */
395 if ( intel
->sarea
->pf_current_page
== 0 ) {
396 front
= intel
->front_region
;
397 back
= intel
->back_region
;
400 back
= intel
->front_region
;
401 front
= intel
->back_region
;
404 front_pitch
= front
->pitch
* front
->cpp
;
405 back_pitch
= back
->pitch
* back
->cpp
;
406 depth_pitch
= depth
->pitch
* depth
->cpp
;
409 FRONT_CMD
|= XY_DST_TILED
;
414 BACK_CMD
|= XY_DST_TILED
;
419 DEPTH_CMD
|= XY_DST_TILED
;
423 for (i
= 0 ; i
< intel
->numClipRects
; i
++)
425 drm_clip_rect_t
*box
= &intel
->pClipRects
[i
];
431 GLint w
= box
->x2
- x
;
432 GLint h
= box
->y2
- y
;
434 if (x
< cx
) w
-= cx
- x
, x
= cx
;
435 if (y
< cy
) h
-= cy
- y
, y
= cy
;
436 if (x
+ w
> cx
+ cw
) w
= cx
+ cw
- x
;
437 if (y
+ h
> cy
+ ch
) h
= cy
+ ch
- y
;
438 if (w
<= 0) continue;
439 if (h
<= 0) continue;
452 b
.x2
> intelScreen
->width
||
453 b
.y2
> intelScreen
->height
)
456 if ( flags
& BUFFER_BIT_FRONT_LEFT
) {
457 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
458 OUT_BATCH( FRONT_CMD
);
459 OUT_BATCH( front_pitch
| BR13
);
460 OUT_BATCH( (b
.y1
<< 16) | b
.x1
);
461 OUT_BATCH( (b
.y2
<< 16) | b
.x2
);
462 OUT_BATCH( bmBufferOffset(intel
, front
->buffer
) );
463 OUT_BATCH( clear_color
);
467 if ( flags
& BUFFER_BIT_BACK_LEFT
) {
468 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
469 OUT_BATCH( BACK_CMD
);
470 OUT_BATCH( back_pitch
| BR13
);
471 OUT_BATCH( (b
.y1
<< 16) | b
.x1
);
472 OUT_BATCH( (b
.y2
<< 16) | b
.x2
);
473 OUT_BATCH( bmBufferOffset(intel
, back
->buffer
) );
474 OUT_BATCH( clear_color
);
478 if ( flags
& (BUFFER_BIT_STENCIL
| BUFFER_BIT_DEPTH
) ) {
479 BEGIN_BATCH(6, INTEL_BATCH_NO_CLIPRECTS
);
480 OUT_BATCH( DEPTH_CMD
);
481 OUT_BATCH( depth_pitch
| BR13
);
482 OUT_BATCH( (b
.y1
<< 16) | b
.x1
);
483 OUT_BATCH( (b
.y2
<< 16) | b
.x2
);
484 OUT_BATCH( bmBufferOffset(intel
, depth
->buffer
) );
485 OUT_BATCH( clear_depth
);
490 intel_batchbuffer_flush( intel
->batch
);
491 UNLOCK_HARDWARE( intel
);