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_swapbuffers.h"
31 #include "intel_batchbuffer.h"
32 #include "intel_reg.h"
33 #include "intel_winsys.h"
35 #include "pipe/p_context.h"
36 #include "state_tracker/st_public.h"
37 #include "state_tracker/st_context.h"
38 #include "state_tracker/st_cb_fbo.h"
39 #include "intel_egl.h"
43 intel_display_surface(struct egl_drm_drawable
*draw
,
44 struct pipe_surface
*surf
);
46 void intel_swap_buffers(struct egl_drm_drawable
*draw
)
48 struct intel_framebuffer
*intel_fb
= (struct intel_framebuffer
*)draw
->priv
;
49 struct pipe_surface
*back_surf
;
52 assert(intel_fb
->stfb
);
54 back_surf
= st_get_framebuffer_surface(intel_fb
->stfb
, ST_SURFACE_BACK_LEFT
);
56 st_notify_swapbuffers(intel_fb
->stfb
);
57 intel_display_surface(draw
, back_surf
);
58 st_notify_swapbuffers_complete(intel_fb
->stfb
);
63 intel_display_surface(struct egl_drm_drawable
*draw
,
64 struct pipe_surface
*surf
)
66 struct intel_screen
*intel
= (struct intel_screen
*)draw
->device
->priv
;
67 struct intel_framebuffer
*intel_fb
= (struct intel_framebuffer
*)draw
->priv
;
68 struct _DriFenceObject
*fence
;
70 //const int srcWidth = surf->width;
71 //const int srcHeight = surf->height;
72 const int srcPitch
= surf
->pitch
;
74 const int dstWidth
= intel_fb
->front
->width
;
75 const int dstHeight
= intel_fb
->front
->height
;
76 const int dstPitch
= intel_fb
->front
->pitch
/ 4;//draw->front.cpp;
78 const int cpp
= 4;//intel_fb->front->cpp;
84 BR13
= (dstPitch
* cpp
) | (0xCC << 16) | (1 << 24) | (1 << 25);
85 CMD
= (XY_SRC_COPY_BLT_CMD
| XY_SRC_COPY_BLT_WRITE_ALPHA
|
86 XY_SRC_COPY_BLT_WRITE_RGB
);
88 printf("srcPitch: %u, dstWidth: %u, dstHeight: %u, dstPitch: %u, cpp: %u\n", srcPitch
, dstWidth
, dstHeight
, dstPitch
, cpp
);
89 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
92 OUT_BATCH((0 << 16) | 0);
93 OUT_BATCH((dstHeight
<< 16) | dstWidth
);
95 OUT_RELOC(intel_fb
->front_buffer
,
96 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_WRITE
,
97 DRM_BO_MASK_MEM
| DRM_BO_FLAG_WRITE
, 0);
99 OUT_BATCH((0 << 16) | 0);
100 OUT_BATCH((srcPitch
* cpp
) & 0xffff);
101 OUT_RELOC(dri_bo(surf
->buffer
),
102 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_READ
,
103 DRM_BO_MASK_MEM
| DRM_BO_FLAG_READ
, 0);
107 fence
= intel_batchbuffer_flush(intel
->batch
);
108 driFenceUnReference(&fence
);
109 intel_batchbuffer_finish(intel
->batch
);
114 * Display a colorbuffer surface in an X window.
115 * Used for SwapBuffers and flushing front buffer rendering.
117 * \param dPriv the window/drawable to display into
118 * \param surf the surface to display
119 * \param rect optional subrect of surface to display (may be NULL).
122 intelDisplaySurface(__DRIdrawablePrivate
*dPriv
,
123 struct pipe_surface
*surf
,
124 const drm_clip_rect_t
*rect
)
126 struct intel_screen
*intelScreen
= intel_screen(dPriv
->driScreenPriv
);
127 //struct intel_context *intel = intelScreen->dummyContext;
129 DBG(SWAP
, "%s\n", __FUNCTION__
);
133 /* XXX this is where some kind of extra/meta context could be useful */
138 if (intel
->last_swap_fence
) {
139 driFenceFinish(intel
->last_swap_fence
, DRM_FENCE_TYPE_EXE
, TRUE
);
140 driFenceUnReference(&intel
->last_swap_fence
);
141 intel
->last_swap_fence
= NULL
;
143 intel
->last_swap_fence
= intel
->first_swap_fence
;
144 intel
->first_swap_fence
= NULL
;
146 /* The LOCK_HARDWARE is required for the cliprects. Buffer offsets
147 * should work regardless.
149 LOCK_HARDWARE(intel
);
150 /* if this drawable isn't currently bound the LOCK_HARDWARE done on the
151 * current context (which is what intelScreenContext should return) might
152 * not get a contended lock and thus cliprects not updated (tests/manywin)
154 if (intel_context(dPriv
->driContextPriv
) != intel
)
155 DRI_VALIDATE_DRAWABLE_INFO(intel
->driScreen
, dPriv
);
158 if (dPriv
&& dPriv
->numClipRects
) {
159 const int srcWidth
= surf
->width
;
160 const int srcHeight
= surf
->height
;
161 const int nbox
= dPriv
->numClipRects
;
162 const drm_clip_rect_t
*pbox
= dPriv
->pClipRects
;
163 const int pitch
= intelScreen
->front
.pitch
/ intelScreen
->front
.cpp
;
164 const int cpp
= intelScreen
->front
.cpp
;
165 const int srcpitch
= surf
->pitch
;
169 ASSERT(surf
->buffer
);
170 ASSERT(surf
->cpp
== cpp
);
172 DBG(SWAP
, "screen pitch %d src surface pitch %d\n",
176 BR13
= (pitch
* cpp
) | (0xCC << 16) | (1 << 24);
177 CMD
= XY_SRC_COPY_BLT_CMD
;
180 BR13
= (pitch
* cpp
) | (0xCC << 16) | (1 << 24) | (1 << 25);
181 CMD
= (XY_SRC_COPY_BLT_CMD
| XY_SRC_COPY_BLT_WRITE_ALPHA
|
182 XY_SRC_COPY_BLT_WRITE_RGB
);
185 for (i
= 0; i
< nbox
; i
++, pbox
++) {
187 drm_clip_rect_t sbox
;
189 if (pbox
->x1
> pbox
->x2
||
190 pbox
->y1
> pbox
->y2
||
191 pbox
->x2
> intelScreen
->front
.width
||
192 pbox
->y2
> intelScreen
->front
.height
) {
193 /* invalid cliprect, skip it */
200 /* intersect cliprect with user-provided src rect */
201 drm_clip_rect_t rrect
;
203 rrect
.x1
= dPriv
->x
+ rect
->x1
;
204 rrect
.y1
= (dPriv
->h
- rect
->y1
- rect
->y2
) + dPriv
->y
;
205 rrect
.x2
= rect
->x2
+ rrect
.x1
;
206 rrect
.y2
= rect
->y2
+ rrect
.y1
;
207 if (rrect
.x1
> box
.x1
)
209 if (rrect
.y1
> box
.y1
)
211 if (rrect
.x2
< box
.x2
)
213 if (rrect
.y2
< box
.y2
)
216 if (box
.x1
> box
.x2
|| box
.y1
> box
.y2
)
220 /* restrict blit to size of actually rendered area */
221 if (box
.x2
- box
.x1
> srcWidth
)
222 box
.x2
= srcWidth
+ box
.x1
;
223 if (box
.y2
- box
.y1
> srcHeight
)
224 box
.y2
= srcHeight
+ box
.y1
;
226 DBG(SWAP
, "box x1 x2 y1 y2 %d %d %d %d\n",
227 box
.x1
, box
.x2
, box
.y1
, box
.y2
);
229 sbox
.x1
= box
.x1
- dPriv
->x
;
230 sbox
.y1
= box
.y1
- dPriv
->y
;
232 assert(box
.x1
< box
.x2
);
233 assert(box
.y1
< box
.y2
);
235 /* XXX this could be done with pipe->surface_copy() */
236 BEGIN_BATCH(8, INTEL_BATCH_NO_CLIPRECTS
);
239 OUT_BATCH((box
.y1
<< 16) | box
.x1
);
240 OUT_BATCH((box
.y2
<< 16) | box
.x2
);
242 OUT_RELOC(intelScreen
->front
.buffer
,
243 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_WRITE
,
244 DRM_BO_MASK_MEM
| DRM_BO_FLAG_WRITE
, 0);
245 OUT_BATCH((sbox
.y1
<< 16) | sbox
.x1
);
246 OUT_BATCH((srcpitch
* cpp
) & 0xffff);
247 OUT_RELOC(dri_bo(surf
->buffer
),
248 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_READ
,
249 DRM_BO_MASK_MEM
| DRM_BO_FLAG_READ
, 0);
254 if (intel
->first_swap_fence
)
255 driFenceUnReference(&intel
->first_swap_fence
);
256 intel
->first_swap_fence
= intel_batchbuffer_flush(intel
->batch
);
259 UNLOCK_HARDWARE(intel
);
261 if (intel
->lastStamp
!= dPriv
->lastStamp
) {
262 intelUpdateWindowSize(dPriv
);
263 intel
->lastStamp
= dPriv
->lastStamp
;
270 * This will be called whenever the currently bound window is moved/resized.
273 intelUpdateWindowSize(__DRIdrawablePrivate
*dPriv
)
275 struct intel_framebuffer
*intelfb
= intel_framebuffer(dPriv
);
276 assert(intelfb
->stfb
);
277 st_resize_framebuffer(intelfb
->stfb
, dPriv
->w
, dPriv
->h
);
283 intelSwapBuffers(__DRIdrawablePrivate
* dPriv
)
285 struct intel_framebuffer
*intel_fb
= intel_framebuffer(dPriv
);
286 struct pipe_surface
*back_surf
;
289 assert(intel_fb
->stfb
);
291 back_surf
= st_get_framebuffer_surface(intel_fb
->stfb
,
292 ST_SURFACE_BACK_LEFT
);
294 st_notify_swapbuffers(intel_fb
->stfb
);
295 intelDisplaySurface(dPriv
, back_surf
, NULL
);
296 st_notify_swapbuffers_complete(intel_fb
->stfb
);
302 * Called via glXCopySubBufferMESA() to copy a subrect of the back
303 * buffer to the front buffer/screen.
306 intelCopySubBuffer(__DRIdrawablePrivate
* dPriv
, int x
, int y
, int w
, int h
)
308 struct intel_framebuffer
*intel_fb
= intel_framebuffer(dPriv
);
309 struct pipe_surface
*back_surf
;
312 assert(intel_fb
->stfb
);
314 back_surf
= st_get_framebuffer_surface(intel_fb
->stfb
,
315 ST_SURFACE_BACK_LEFT
);
317 drm_clip_rect_t rect
;
323 st_notify_swapbuffers(intel_fb
->stfb
);
324 intelDisplaySurface(dPriv
, back_surf
, &rect
);