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 "intel_screen.h"
29 #include "intel_context.h"
30 #include "intel_blit.h"
31 #include "intel_buffers.h"
32 #include "intel_depthstencil.h"
33 #include "intel_fbo.h"
34 #include "intel_tris.h"
35 #include "intel_regions.h"
36 #include "intel_batchbuffer.h"
37 #include "intel_reg.h"
40 #include "drirenderbuffer.h"
41 #include "framebuffer.h"
42 #include "swrast/swrast.h"
46 /* This block can be removed when libdrm >= 2.3.1 is required */
48 #ifndef DRM_VBLANK_FLIP
50 #define DRM_VBLANK_FLIP 0x8000000
52 typedef struct drm_i915_flip
{
56 #undef DRM_IOCTL_I915_FLIP
57 #define DRM_IOCTL_I915_FLIP DRM_IOW(DRM_COMMAND_BASE + DRM_I915_FLIP, \
64 * XXX move this into a new dri/common/cliprects.c file.
67 intel_intersect_cliprects(drm_clip_rect_t
* dst
,
68 const drm_clip_rect_t
* a
,
69 const drm_clip_rect_t
* b
)
73 GLint bw
= b
->x2
- bx
;
74 GLint bh
= b
->y2
- by
;
77 bw
-= a
->x1
- bx
, bx
= a
->x1
;
79 bh
-= a
->y1
- by
, by
= a
->y1
;
98 * Return pointer to current color drawing region, or NULL.
100 struct intel_region
*
101 intel_drawbuf_region(struct intel_context
*intel
)
103 struct intel_renderbuffer
*irbColor
=
104 intel_renderbuffer(intel
->ctx
.DrawBuffer
->_ColorDrawBuffers
[0][0]);
106 return irbColor
->region
;
112 * Return pointer to current color reading region, or NULL.
114 struct intel_region
*
115 intel_readbuf_region(struct intel_context
*intel
)
117 struct intel_renderbuffer
*irb
118 = intel_renderbuffer(intel
->ctx
.ReadBuffer
->_ColorReadBuffer
);
128 * Update the following fields for rendering:
129 * intel->numClipRects
133 intelSetRenderbufferClipRects(struct intel_context
*intel
)
135 /* zero-sized buffers might be legal? */
136 assert(intel
->ctx
.DrawBuffer
->Width
> 0);
137 assert(intel
->ctx
.DrawBuffer
->Height
> 0);
138 intel
->fboRect
.x1
= 0;
139 intel
->fboRect
.y1
= 0;
140 intel
->fboRect
.x2
= intel
->ctx
.DrawBuffer
->Width
;
141 intel
->fboRect
.y2
= intel
->ctx
.DrawBuffer
->Height
;
142 intel
->numClipRects
= 1;
143 intel
->pClipRects
= &intel
->fboRect
;
148 * This will be called whenever the currently bound window is moved/resized.
149 * XXX: actually, it seems to NOT be called when the window is only moved (BP).
152 intelWindowMoved(struct intel_context
*intel
)
154 GLcontext
*ctx
= &intel
->ctx
;
155 __DRIdrawablePrivate
*dPriv
= intel
->driDrawable
;
156 struct intel_framebuffer
*intel_fb
= dPriv
->driverPrivate
;
158 if (!intel
->ctx
.DrawBuffer
) {
159 /* when would this happen? -BP */
161 intel
->numClipRects
= 0;
164 /* Update Mesa's notion of window size */
165 driUpdateFramebufferSize(ctx
, dPriv
);
166 intel_fb
->Base
.Initialized
= GL_TRUE
; /* XXX remove someday */
169 drmI830Sarea
*sarea
= intel
->sarea
;
170 drm_clip_rect_t drw_rect
= { .x1
= dPriv
->x
, .x2
= dPriv
->x
+ dPriv
->w
,
171 .y1
= dPriv
->y
, .y2
= dPriv
->y
+ dPriv
->h
};
172 drm_clip_rect_t pipeA_rect
= { .x1
= sarea
->pipeA_x
, .y1
= sarea
->pipeA_y
,
173 .x2
= sarea
->pipeA_x
+ sarea
->pipeA_w
,
174 .y2
= sarea
->pipeA_y
+ sarea
->pipeA_h
};
175 drm_clip_rect_t pipeB_rect
= { .x1
= sarea
->pipeB_x
, .y1
= sarea
->pipeB_y
,
176 .x2
= sarea
->pipeB_x
+ sarea
->pipeB_w
,
177 .y2
= sarea
->pipeB_y
+ sarea
->pipeB_h
};
178 GLint areaA
= driIntersectArea( drw_rect
, pipeA_rect
);
179 GLint areaB
= driIntersectArea( drw_rect
, pipeB_rect
);
180 GLuint flags
= intel_fb
->vblank_flags
;
184 /* Update page flipping info
194 intel_fb
->pf_current_page
= (intel
->sarea
->pf_current_page
>>
195 (intel_fb
->pf_pipes
& 0x2)) & 0x3;
197 intel_fb
->pf_num_pages
= 2 /*intel->intelScreen->third.handle ? 3 : 2*/;
199 pf_active
= pf_pipes
&& (pf_pipes
& intel
->sarea
->pf_active
) == pf_pipes
;
201 if (INTEL_DEBUG
& DEBUG_LOCK
)
202 if (pf_active
!= intel_fb
->pf_active
)
203 _mesa_printf("%s - Page flipping %sactive\n", __progname
,
204 pf_active
? "" : "in");
207 /* Sync pages between pipes if we're flipping on both at the same time */
208 if (pf_pipes
== 0x3 && pf_pipes
!= intel_fb
->pf_pipes
&&
209 (intel
->sarea
->pf_current_page
& 0x3) !=
210 (((intel
->sarea
->pf_current_page
) >> 2) & 0x3)) {
211 drm_i915_flip_t flip
;
213 if (intel_fb
->pf_current_page
==
214 (intel
->sarea
->pf_current_page
& 0x3)) {
215 /* XXX: This is ugly, but emitting two flips 'in a row' can cause
216 * lockups for unknown reasons.
218 intel
->sarea
->pf_current_page
=
219 intel
->sarea
->pf_current_page
& 0x3;
220 intel
->sarea
->pf_current_page
|=
221 ((intel_fb
->pf_current_page
+ intel_fb
->pf_num_pages
- 1) %
222 intel_fb
->pf_num_pages
) << 2;
226 intel
->sarea
->pf_current_page
=
227 intel
->sarea
->pf_current_page
& (0x3 << 2);
228 intel
->sarea
->pf_current_page
|=
229 (intel_fb
->pf_current_page
+ intel_fb
->pf_num_pages
- 1) %
230 intel_fb
->pf_num_pages
;
235 drmCommandWrite(intel
->driFd
, DRM_I915_FLIP
, &flip
, sizeof(flip
));
238 intel_fb
->pf_pipes
= pf_pipes
;
241 intel_fb
->pf_active
= pf_active
;
242 intel_flip_renderbuffers(intel_fb
);
243 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
245 /* Update vblank info
247 if (areaB
> areaA
|| (areaA
== areaB
&& areaB
> 0)) {
248 flags
= intel_fb
->vblank_flags
| VBLANK_FLAG_SECONDARY
;
250 flags
= intel_fb
->vblank_flags
& ~VBLANK_FLAG_SECONDARY
;
253 if (flags
!= intel_fb
->vblank_flags
) {
257 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
259 if ( intel_fb
->vblank_flags
& VBLANK_FLAG_SECONDARY
) {
260 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
263 for (i
= 0; i
< intel_fb
->pf_num_pages
; i
++) {
264 if (!intel_fb
->color_rb
[i
])
267 vbl
.request
.sequence
= intel_fb
->color_rb
[i
]->vbl_pending
;
268 drmWaitVBlank(intel
->driFd
, &vbl
);
271 intel_fb
->vblank_flags
= flags
;
272 driGetCurrentVBlank(dPriv
, intel_fb
->vblank_flags
, &intel_fb
->vbl_seq
);
273 intel_fb
->vbl_waited
= intel_fb
->vbl_seq
;
275 for (i
= 0; i
< intel_fb
->pf_num_pages
; i
++) {
276 if (intel_fb
->color_rb
[i
])
277 intel_fb
->color_rb
[i
]->vbl_pending
= intel_fb
->vbl_waited
;
282 /* Update hardware scissor */
283 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
284 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
286 /* Re-calculate viewport related state */
287 ctx
->Driver
.DepthRange( ctx
, ctx
->Viewport
.Near
, ctx
->Viewport
.Far
);
292 /* A true meta version of this would be very simple and additionally
293 * machine independent. Maybe we'll get there one day.
296 intelClearWithTris(struct intel_context
*intel
, GLbitfield mask
)
298 GLcontext
*ctx
= &intel
->ctx
;
299 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
300 drm_clip_rect_t clear
;
302 if (INTEL_DEBUG
& DEBUG_BLIT
)
303 _mesa_printf("%s 0x%x\n", __FUNCTION__
, mask
);
305 LOCK_HARDWARE(intel
);
307 if (intel
->numClipRects
) {
308 GLint cx
, cy
, cw
, ch
;
311 intel
->vtbl
.install_meta_state(intel
);
313 /* Get clear bounds after locking */
319 /* note: regardless of 'all', cx, cy, cw, ch are now correct */
325 /* Back and stencil cliprects are the same. Try and do both
329 (BUFFER_BIT_BACK_LEFT
| BUFFER_BIT_STENCIL
| BUFFER_BIT_DEPTH
)) {
330 struct intel_region
*backRegion
=
331 intel_get_rb_region(fb
, BUFFER_BACK_LEFT
);
332 struct intel_region
*depthRegion
=
333 intel_get_rb_region(fb
, BUFFER_DEPTH
);
334 const GLuint clearColor
= (backRegion
&& backRegion
->cpp
== 4)
335 ? intel
->ClearColor8888
: intel
->ClearColor565
;
337 intel
->vtbl
.meta_draw_region(intel
, backRegion
, depthRegion
);
339 if (mask
& BUFFER_BIT_BACK_LEFT
)
340 intel
->vtbl
.meta_color_mask(intel
, GL_TRUE
);
342 intel
->vtbl
.meta_color_mask(intel
, GL_FALSE
);
344 if (mask
& BUFFER_BIT_STENCIL
)
345 intel
->vtbl
.meta_stencil_replace(intel
,
346 intel
->ctx
.Stencil
.WriteMask
[0],
347 intel
->ctx
.Stencil
.Clear
);
349 intel
->vtbl
.meta_no_stencil_write(intel
);
351 if (mask
& BUFFER_BIT_DEPTH
)
352 intel
->vtbl
.meta_depth_replace(intel
);
354 intel
->vtbl
.meta_no_depth_write(intel
);
356 /* XXX: Using INTEL_BATCH_NO_CLIPRECTS here is dangerous as the
357 * drawing origin may not be correctly emitted.
359 intel_meta_draw_quad(intel
, clear
.x1
, clear
.x2
, clear
.y1
, clear
.y2
,
360 intel
->ctx
.Depth
.Clear
, clearColor
, 0, 0, 0, 0); /* texcoords */
363 ~(BUFFER_BIT_BACK_LEFT
| BUFFER_BIT_STENCIL
| BUFFER_BIT_DEPTH
);
366 /* clear the remaining (color) renderbuffers */
367 for (buf
= 0; buf
< BUFFER_COUNT
&& mask
; buf
++) {
368 const GLuint bufBit
= 1 << buf
;
370 struct intel_renderbuffer
*irbColor
=
371 intel_renderbuffer(fb
->Attachment
[buf
].Renderbuffer
);
372 GLuint color
= (irbColor
->region
->cpp
== 4)
373 ? intel
->ClearColor8888
: intel
->ClearColor565
;
377 intel
->vtbl
.meta_no_depth_write(intel
);
378 intel
->vtbl
.meta_no_stencil_write(intel
);
379 intel
->vtbl
.meta_color_mask(intel
, GL_TRUE
);
380 intel
->vtbl
.meta_draw_region(intel
, irbColor
->region
, NULL
);
382 /* XXX: Using INTEL_BATCH_NO_CLIPRECTS here is dangerous as the
383 * drawing origin may not be correctly emitted.
385 intel_meta_draw_quad(intel
, clear
.x1
, clear
.x2
, clear
.y1
, clear
.y2
, 0, /* depth clear val */
386 color
, 0, 0, 0, 0); /* texcoords */
392 intel
->vtbl
.leave_meta_state(intel
);
393 intel_batchbuffer_flush(intel
->batch
);
395 UNLOCK_HARDWARE(intel
);
400 * Called by ctx->Driver.Clear.
403 intelClear(GLcontext
*ctx
, GLbitfield mask
)
405 struct intel_context
*intel
= intel_context(ctx
);
406 const GLuint colorMask
= *((GLuint
*) & ctx
->Color
.ColorMask
);
407 GLbitfield tri_mask
= 0;
408 GLbitfield blit_mask
= 0;
409 GLbitfield swrast_mask
= 0;
410 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
414 fprintf(stderr
, "%s\n", __FUNCTION__
);
416 /* HW color buffers (front, back, aux, generic FBO, etc) */
417 if (colorMask
== ~0) {
418 /* clear all R,G,B,A */
419 /* XXX FBO: need to check if colorbuffers are software RBOs! */
420 blit_mask
|= (mask
& BUFFER_BITS_COLOR
);
423 /* glColorMask in effect */
424 tri_mask
|= (mask
& BUFFER_BITS_COLOR
);
428 if (mask
& BUFFER_BIT_STENCIL
) {
429 const struct intel_region
*stencilRegion
430 = intel_get_rb_region(fb
, BUFFER_STENCIL
);
432 /* have hw stencil */
433 if ((ctx
->Stencil
.WriteMask
[0] & 0xff) != 0xff) {
434 /* not clearing all stencil bits, so use triangle clearing */
435 tri_mask
|= BUFFER_BIT_STENCIL
;
438 /* clearing all stencil bits, use blitting */
439 blit_mask
|= BUFFER_BIT_STENCIL
;
445 if (mask
& BUFFER_BIT_DEPTH
) {
446 /* clear depth with whatever method is used for stencil (see above) */
447 if (tri_mask
& BUFFER_BIT_STENCIL
)
448 tri_mask
|= BUFFER_BIT_DEPTH
;
450 blit_mask
|= BUFFER_BIT_DEPTH
;
453 /* SW fallback clearing */
454 swrast_mask
= mask
& ~tri_mask
& ~blit_mask
;
456 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
457 GLuint bufBit
= 1 << i
;
458 if ((blit_mask
| tri_mask
) & bufBit
) {
459 if (!fb
->Attachment
[i
].Renderbuffer
->ClassID
) {
460 blit_mask
&= ~bufBit
;
462 swrast_mask
|= bufBit
;
468 intelFlush(ctx
); /* XXX intelClearWithBlit also does this */
471 intelClearWithBlit(ctx
, blit_mask
);
474 intelClearWithTris(intel
, tri_mask
);
477 _swrast_Clear(ctx
, swrast_mask
);
481 /* Emit wait for pending flips */
483 intel_wait_flips(struct intel_context
*intel
, GLuint batch_flags
)
485 struct intel_framebuffer
*intel_fb
=
486 (struct intel_framebuffer
*) intel
->ctx
.DrawBuffer
;
487 struct intel_renderbuffer
*intel_rb
=
488 intel_get_renderbuffer(&intel_fb
->Base
,
489 intel_fb
->Base
._ColorDrawBufferMask
[0] ==
490 BUFFER_BIT_FRONT_LEFT
? BUFFER_FRONT_LEFT
:
493 if (intel_fb
->Base
.Name
== 0 && intel_rb
->pf_pending
== intel_fb
->pf_seq
) {
494 GLint pf_pipes
= intel_fb
->pf_pipes
;
497 /* Wait for pending flips to take effect */
498 BEGIN_BATCH(2, batch_flags
);
499 OUT_BATCH(pf_pipes
& 0x1 ? (MI_WAIT_FOR_EVENT
| MI_WAIT_FOR_PLANE_A_FLIP
)
501 OUT_BATCH(pf_pipes
& 0x2 ? (MI_WAIT_FOR_EVENT
| MI_WAIT_FOR_PLANE_B_FLIP
)
505 intel_rb
->pf_pending
--;
510 /* Flip the front & back buffers
513 intelPageFlip(const __DRIdrawablePrivate
* dPriv
)
515 struct intel_context
*intel
;
517 struct intel_framebuffer
*intel_fb
= dPriv
->driverPrivate
;
519 if (INTEL_DEBUG
& DEBUG_IOCTL
)
520 fprintf(stderr
, "%s\n", __FUNCTION__
);
523 assert(dPriv
->driContextPriv
);
524 assert(dPriv
->driContextPriv
->driverPrivate
);
526 intel
= (struct intel_context
*) dPriv
->driContextPriv
->driverPrivate
;
528 if (intel
->intelScreen
->drmMinor
< 9)
531 intelFlush(&intel
->ctx
);
535 LOCK_HARDWARE(intel
);
537 if (dPriv
->numClipRects
&& intel_fb
->pf_active
) {
538 drm_i915_flip_t flip
;
540 flip
.pipes
= intel_fb
->pf_pipes
;
542 ret
= drmCommandWrite(intel
->driFd
, DRM_I915_FLIP
, &flip
, sizeof(flip
));
545 UNLOCK_HARDWARE(intel
);
547 if (ret
|| !intel_fb
->pf_active
)
550 if (!dPriv
->numClipRects
) {
551 usleep(10000); /* throttle invisible client 10ms */
554 intel_fb
->pf_current_page
= (intel
->sarea
->pf_current_page
>>
555 (intel_fb
->pf_pipes
& 0x2)) & 0x3;
557 if (dPriv
->numClipRects
!= 0) {
558 intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_FRONT_LEFT
)->pf_pending
=
559 intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
)->pf_pending
=
563 intel_flip_renderbuffers(intel_fb
);
564 intel_draw_buffer(&intel
->ctx
, &intel_fb
->Base
);
566 if (INTEL_DEBUG
& DEBUG_IOCTL
)
567 fprintf(stderr
, "%s: success\n", __FUNCTION__
);
575 intelScheduleSwap(const __DRIdrawablePrivate
* dPriv
, GLboolean
*missed_target
)
577 struct intel_framebuffer
*intel_fb
= dPriv
->driverPrivate
;
578 unsigned int interval
= driGetVBlankInterval(dPriv
, intel_fb
->vblank_flags
);
579 struct intel_context
*intel
=
580 intelScreenContext(dPriv
->driScreenPriv
->private);
581 const intelScreenPrivate
*intelScreen
= intel
->intelScreen
;
583 drm_i915_vblank_swap_t swap
;
586 if ((intel_fb
->vblank_flags
& VBLANK_FLAG_NO_IRQ
) ||
587 intelScreen
->drmMinor
< (intel_fb
->pf_active
? 9 : 6))
590 swap
.seqtype
= DRM_VBLANK_ABSOLUTE
;
592 if (intel_fb
->vblank_flags
& VBLANK_FLAG_SYNC
) {
593 swap
.seqtype
|= DRM_VBLANK_NEXTONMISS
;
594 } else if (interval
== 0) {
598 swap
.drawable
= dPriv
->hHWDrawable
;
599 target
= swap
.sequence
= intel_fb
->vbl_seq
+ interval
;
601 if ( intel_fb
->vblank_flags
& VBLANK_FLAG_SECONDARY
) {
602 swap
.seqtype
|= DRM_VBLANK_SECONDARY
;
605 LOCK_HARDWARE(intel
);
607 intel_batchbuffer_flush(intel
->batch
);
609 if ( intel_fb
->pf_active
) {
610 swap
.seqtype
|= DRM_VBLANK_FLIP
;
612 intel_fb
->pf_current_page
= (((intel
->sarea
->pf_current_page
>>
613 (intel_fb
->pf_pipes
& 0x2)) & 0x3) + 1) %
614 intel_fb
->pf_num_pages
;
617 if (!drmCommandWriteRead(intel
->driFd
, DRM_I915_VBLANK_SWAP
, &swap
,
619 intel_fb
->vbl_seq
= swap
.sequence
;
620 swap
.sequence
-= target
;
621 *missed_target
= swap
.sequence
> 0 && swap
.sequence
<= (1 << 23);
623 intel_get_renderbuffer(&intel_fb
->Base
, BUFFER_BACK_LEFT
)->vbl_pending
=
624 intel_get_renderbuffer(&intel_fb
->Base
,
625 BUFFER_FRONT_LEFT
)->vbl_pending
=
628 if (swap
.seqtype
& DRM_VBLANK_FLIP
) {
629 intel_flip_renderbuffers(intel_fb
);
630 intel_draw_buffer(&intel
->ctx
, intel
->ctx
.DrawBuffer
);
635 if (swap
.seqtype
& DRM_VBLANK_FLIP
) {
636 intel_fb
->pf_current_page
= ((intel
->sarea
->pf_current_page
>>
637 (intel_fb
->pf_pipes
& 0x2)) & 0x3) %
638 intel_fb
->pf_num_pages
;
644 UNLOCK_HARDWARE(intel
);
650 intelSwapBuffers(__DRIdrawablePrivate
* dPriv
)
652 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
653 GET_CURRENT_CONTEXT(ctx
);
654 struct intel_context
*intel
;
659 intel
= intel_context(ctx
);
661 if (ctx
->Visual
.doubleBufferMode
) {
662 GLboolean missed_target
;
663 struct intel_framebuffer
*intel_fb
= dPriv
->driverPrivate
;
666 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
668 if (!intelScheduleSwap(dPriv
, &missed_target
)) {
669 driWaitForVBlank(dPriv
, &intel_fb
->vbl_seq
, intel_fb
->vblank_flags
,
672 intelCopyBuffer(dPriv
, NULL
);
675 intel_fb
->swap_count
++;
676 (*dri_interface
->getUST
) (&ust
);
678 intel_fb
->swap_missed_count
++;
679 intel_fb
->swap_missed_ust
= ust
- intel_fb
->swap_ust
;
682 intel_fb
->swap_ust
= ust
;
686 /* XXX this shouldn't be an error but we can't handle it for now */
687 fprintf(stderr
, "%s: drawable has no context!\n", __FUNCTION__
);
692 intelCopySubBuffer(__DRIdrawablePrivate
* dPriv
, int x
, int y
, int w
, int h
)
694 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
695 struct intel_context
*intel
=
696 (struct intel_context
*) dPriv
->driContextPriv
->driverPrivate
;
697 GLcontext
*ctx
= &intel
->ctx
;
699 if (ctx
->Visual
.doubleBufferMode
) {
700 drm_clip_rect_t rect
;
701 /* fixup cliprect (driDrawable may have changed?) later */
706 _mesa_notifySwapBuffers(ctx
); /* flush pending rendering comands */
707 intelCopyBuffer(dPriv
, &rect
);
711 /* XXX this shouldn't be an error but we can't handle it for now */
712 fprintf(stderr
, "%s: drawable has no context!\n", __FUNCTION__
);
718 * Update the hardware state for drawing into a window or framebuffer object.
720 * Called by glDrawBuffer, glBindFramebufferEXT, MakeCurrent, and other
721 * places within the driver.
723 * Basically, this needs to be called any time the current framebuffer
724 * changes, the renderbuffers change, or we need to draw into different
728 intel_draw_buffer(GLcontext
* ctx
, struct gl_framebuffer
*fb
)
730 struct intel_context
*intel
= intel_context(ctx
);
731 struct intel_region
*colorRegion
, *depthRegion
= NULL
;
732 struct intel_renderbuffer
*irbDepth
= NULL
, *irbStencil
= NULL
;
735 /* this can happen during the initial context initialization */
739 /* Do this here, not core Mesa, since this function is called from
740 * many places within the driver.
742 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_COLOR
| _NEW_PIXEL
)) {
743 /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */
744 _mesa_update_framebuffer(ctx
);
745 /* this updates the DrawBuffer's Width/Height if it's a FBO */
746 _mesa_update_draw_buffer_bounds(ctx
);
749 if (fb
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
750 /* this may occur when we're called by glBindFrameBuffer() during
751 * the process of someone setting up renderbuffers, etc.
753 /*_mesa_debug(ctx, "DrawBuffer: incomplete user FBO\n");*/
758 intel_validate_paired_depth_stencil(ctx
, fb
);
761 * How many color buffers are we drawing into?
763 if (fb
->_NumColorDrawBuffers
[0] != 1) {
764 /* writing to 0 or 2 or 4 color buffers */
765 /*_mesa_debug(ctx, "Software rendering\n");*/
766 FALLBACK(intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
769 /* draw to exactly one color buffer */
770 /*_mesa_debug(ctx, "Hardware rendering\n");*/
771 FALLBACK(intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
775 * Get the intel_renderbuffer for the colorbuffer we're drawing into.
776 * And set up cliprects.
779 struct intel_renderbuffer
*irb
;
780 intelSetRenderbufferClipRects(intel
);
781 irb
= intel_renderbuffer(fb
->_ColorDrawBuffers
[0][0]);
782 colorRegion
= (irb
&& irb
->region
) ? irb
->region
: NULL
;
785 /* Update culling direction which changes depending on the
786 * orientation of the buffer:
788 if (ctx
->Driver
.FrontFace
)
789 ctx
->Driver
.FrontFace(ctx
, ctx
->Polygon
.FrontFace
);
791 ctx
->NewState
|= _NEW_POLYGON
;
794 FALLBACK(intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
797 FALLBACK(intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
801 *** Get depth buffer region and check if we need a software fallback.
802 *** Note that the depth buffer is usually a DEPTH_STENCIL buffer.
804 if (fb
->_DepthBuffer
&& fb
->_DepthBuffer
->Wrapped
) {
805 irbDepth
= intel_renderbuffer(fb
->_DepthBuffer
->Wrapped
);
806 if (irbDepth
&& irbDepth
->region
) {
807 FALLBACK(intel
, INTEL_FALLBACK_DEPTH_BUFFER
, GL_FALSE
);
808 depthRegion
= irbDepth
->region
;
811 FALLBACK(intel
, INTEL_FALLBACK_DEPTH_BUFFER
, GL_TRUE
);
816 /* not using depth buffer */
817 FALLBACK(intel
, INTEL_FALLBACK_DEPTH_BUFFER
, GL_FALSE
);
823 *** This can only be hardware accelerated if we're using a
824 *** combined DEPTH_STENCIL buffer (for now anyway).
826 if (fb
->_StencilBuffer
&& fb
->_StencilBuffer
->Wrapped
) {
827 irbStencil
= intel_renderbuffer(fb
->_StencilBuffer
->Wrapped
);
828 if (irbStencil
&& irbStencil
->region
) {
829 ASSERT(irbStencil
->Base
._ActualFormat
== GL_DEPTH24_STENCIL8_EXT
);
830 FALLBACK(intel
, INTEL_FALLBACK_STENCIL_BUFFER
, GL_FALSE
);
831 /* need to re-compute stencil hw state */
832 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
834 depthRegion
= irbStencil
->region
;
837 FALLBACK(intel
, INTEL_FALLBACK_STENCIL_BUFFER
, GL_TRUE
);
841 /* XXX FBO: instead of FALSE, pass ctx->Stencil.Enabled ??? */
842 FALLBACK(intel
, INTEL_FALLBACK_STENCIL_BUFFER
, GL_FALSE
);
843 /* need to re-compute stencil hw state */
844 ctx
->Driver
.Enable(ctx
, GL_STENCIL_TEST
, ctx
->Stencil
.Enabled
);
849 ** Release old regions, reference new regions
852 intel
->vtbl
.set_draw_region(intel
, colorRegion
, depthRegion
);
854 /* update viewport since it depends on window size */
855 ctx
->Driver
.Viewport(ctx
, ctx
->Viewport
.X
, ctx
->Viewport
.Y
,
856 ctx
->Viewport
.Width
, ctx
->Viewport
.Height
);
858 /* Update hardware scissor */
859 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
860 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
865 intelDrawBuffer(GLcontext
* ctx
, GLenum mode
)
867 intel_draw_buffer(ctx
, ctx
->DrawBuffer
);
872 intelReadBuffer(GLcontext
* ctx
, GLenum mode
)
874 if (ctx
->ReadBuffer
== ctx
->DrawBuffer
) {
875 /* This will update FBO completeness status.
876 * A framebuffer will be incomplete if the GL_READ_BUFFER setting
877 * refers to a missing renderbuffer. Calling glReadBuffer can set
878 * that straight and can make the drawing buffer complete.
880 intel_draw_buffer(ctx
, ctx
->DrawBuffer
);
882 /* Generally, functions which read pixels (glReadPixels, glCopyPixels, etc)
883 * reference ctx->ReadBuffer and do appropriate state checks.
889 intelInitBufferFuncs(struct dd_function_table
*functions
)
891 functions
->Clear
= intelClear
;
892 functions
->DrawBuffer
= intelDrawBuffer
;
893 functions
->ReadBuffer
= intelReadBuffer
;