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_blit.h"
29 #include "intel_buffers.h"
30 #include "intel_swapbuffers.h"
31 #include "intel_fbo.h"
32 #include "intel_batchbuffer.h"
33 #include "drirenderbuffer.h"
40 * Correct a drawablePrivate's set of vblank flags WRT the current context.
41 * When considering multiple crtcs.
44 intelFixupVblank(struct intel_context
*intel
, __DRIdrawable
*dPriv
)
46 if (!intel
->intelScreen
->driScrnPriv
->dri2
.enabled
&&
47 intel
->intelScreen
->driScrnPriv
->ddx_version
.minor
>= 7) {
48 volatile drm_i915_sarea_t
*sarea
= intel
->sarea
;
49 drm_clip_rect_t drw_rect
= { .x1
= dPriv
->x
, .x2
= dPriv
->x
+ dPriv
->w
,
50 .y1
= dPriv
->y
, .y2
= dPriv
->y
+ dPriv
->h
};
51 drm_clip_rect_t planeA_rect
= { .x1
= sarea
->planeA_x
, .y1
= sarea
->planeA_y
,
52 .x2
= sarea
->planeA_x
+ sarea
->planeA_w
,
53 .y2
= sarea
->planeA_y
+ sarea
->planeA_h
};
54 drm_clip_rect_t planeB_rect
= { .x1
= sarea
->planeB_x
, .y1
= sarea
->planeB_y
,
55 .x2
= sarea
->planeB_x
+ sarea
->planeB_w
,
56 .y2
= sarea
->planeB_y
+ sarea
->planeB_h
};
57 GLint areaA
= driIntersectArea( drw_rect
, planeA_rect
);
58 GLint areaB
= driIntersectArea( drw_rect
, planeB_rect
);
63 if (areaB
> areaA
|| (areaA
== areaB
&& areaB
> 0)) {
64 flags
= dPriv
->vblFlags
| VBLANK_FLAG_SECONDARY
;
66 flags
= dPriv
->vblFlags
& ~VBLANK_FLAG_SECONDARY
;
69 /* Do the stupid test: Is one of them actually disabled?
71 if (sarea
->planeA_w
== 0 || sarea
->planeA_h
== 0) {
72 flags
= dPriv
->vblFlags
| VBLANK_FLAG_SECONDARY
;
73 } else if (sarea
->planeB_w
== 0 || sarea
->planeB_h
== 0) {
74 flags
= dPriv
->vblFlags
& ~VBLANK_FLAG_SECONDARY
;
79 return dPriv
->vblFlags
& ~VBLANK_FLAG_SECONDARY
;
84 * This will be called whenever the currently bound window is moved/resized.
85 * XXX: actually, it seems to NOT be called when the window is only moved (BP).
88 intelWindowMoved(struct intel_context
*intel
)
90 GLcontext
*ctx
= &intel
->ctx
;
91 __DRIdrawable
*dPriv
= intel
->driDrawable
;
92 struct intel_framebuffer
*intel_fb
= dPriv
->driverPrivate
;
94 if (!intel
->intelScreen
->driScrnPriv
->dri2
.enabled
&&
95 intel
->intelScreen
->driScrnPriv
->ddx_version
.minor
>= 7) {
96 GLuint flags
= intelFixupVblank(intel
, dPriv
);
98 /* Check to see if we changed pipes */
99 if (flags
!= dPriv
->vblFlags
&& dPriv
->vblFlags
&&
100 !(dPriv
->vblFlags
& VBLANK_FLAG_NO_IRQ
)) {
106 * Deal with page flipping
108 vbl
.request
.type
= DRM_VBLANK_ABSOLUTE
;
110 if ( dPriv
->vblFlags
& VBLANK_FLAG_SECONDARY
) {
111 vbl
.request
.type
|= DRM_VBLANK_SECONDARY
;
114 for (i
= 0; i
< 2; i
++) {
115 if (!intel_fb
->color_rb
[i
] ||
116 (intel_fb
->vbl_waited
- intel_fb
->color_rb
[i
]->vbl_pending
) <=
120 vbl
.request
.sequence
= intel_fb
->color_rb
[i
]->vbl_pending
;
121 drmWaitVBlank(intel
->driFd
, &vbl
);
125 * Update msc_base from old pipe
127 driDrawableGetMSC32(dPriv
->driScreenPriv
, dPriv
, &count
);
128 dPriv
->msc_base
= count
;
130 * Then get new vblank_base and vblSeq values
132 dPriv
->vblFlags
= flags
;
133 driGetCurrentVBlank(dPriv
);
134 dPriv
->vblank_base
= dPriv
->vblSeq
;
136 intel_fb
->vbl_waited
= dPriv
->vblSeq
;
138 for (i
= 0; i
< 2; i
++) {
139 if (intel_fb
->color_rb
[i
])
140 intel_fb
->color_rb
[i
]->vbl_pending
= intel_fb
->vbl_waited
;
144 dPriv
->vblFlags
&= ~VBLANK_FLAG_SECONDARY
;
147 /* Update Mesa's notion of window size */
148 driUpdateFramebufferSize(ctx
, dPriv
);
149 intel_fb
->Base
.Initialized
= GL_TRUE
; /* XXX remove someday */
151 /* Update hardware scissor */
152 if (ctx
->Driver
.Scissor
!= NULL
) {
153 ctx
->Driver
.Scissor(ctx
, ctx
->Scissor
.X
, ctx
->Scissor
.Y
,
154 ctx
->Scissor
.Width
, ctx
->Scissor
.Height
);
157 /* Re-calculate viewport related state */
158 if (ctx
->Driver
.DepthRange
!= NULL
)
159 ctx
->Driver
.DepthRange( ctx
, ctx
->Viewport
.Near
, ctx
->Viewport
.Far
);