i915: EGL almost works again
[mesa.git] / src / gallium / winsys / egl_drm / intel / intel_swapbuffers.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "intel_screen.h"
29 #include "intel_context.h"
30 #include "intel_batchbuffer.h"
31 #include "intel_reg.h"
32
33 #include "pipe/p_context.h"
34 #include "state_tracker/st_public.h"
35 #include "state_tracker/st_context.h"
36 #include "state_tracker/st_cb_fbo.h"
37 #include "intel_egl.h"
38
39
40 static void
41 intel_display_surface(struct egl_drm_drawable *draw,
42 struct pipe_surface *surf);
43
44 void intel_swap_buffers(struct egl_drm_drawable *draw)
45 {
46 struct intel_framebuffer *intel_fb = (struct intel_framebuffer *)draw->priv;
47 struct pipe_surface *back_surf;
48
49 assert(intel_fb);
50 assert(intel_fb->stfb);
51
52 back_surf = st_get_framebuffer_surface(intel_fb->stfb, ST_SURFACE_BACK_LEFT);
53 if (back_surf) {
54 st_notify_swapbuffers(intel_fb->stfb);
55 if (intel_fb->front)
56 intel_display_surface(draw, back_surf);
57 st_notify_swapbuffers_complete(intel_fb->stfb);
58 }
59 }
60
61 static void
62 intel_display_surface(struct egl_drm_drawable *draw,
63 struct pipe_surface *surf)
64 {
65 struct intel_context *intel = NULL;
66 struct intel_framebuffer *intel_fb = (struct intel_framebuffer *)draw->priv;
67 struct _DriFenceObject *fence;
68
69 //const int srcWidth = surf->width;
70 //const int srcHeight = surf->height;
71
72 intel = intel_fb->screen->dummy;
73 if (!intel) {
74 printf("No dummy context\n");
75 return;
76 }
77
78 const int dstWidth = intel_fb->front->width;
79 const int dstHeight = intel_fb->front->height;
80 const int dstPitch = intel_fb->front->pitch / 4;//draw->front.cpp;
81
82 const int cpp = 4;//intel_fb->front->cpp;
83 const int srcPitch = surf->stride / cpp;
84
85 int BR13, CMD;
86 //int i;
87
88 BR13 = (dstPitch * cpp) | (0xCC << 16) | (1 << 24) | (1 << 25);
89 CMD = (XY_SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
90 XY_SRC_COPY_BLT_WRITE_RGB);
91
92 BEGIN_BATCH(8, 2);
93 OUT_BATCH(CMD);
94 OUT_BATCH(BR13);
95 OUT_BATCH((0 << 16) | 0);
96 OUT_BATCH((dstHeight << 16) | dstWidth);
97
98 OUT_RELOC(intel_fb->front_buffer,
99 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_WRITE,
100 DRM_BO_MASK_MEM | DRM_BO_FLAG_WRITE, 0);
101
102 OUT_BATCH((0 << 16) | 0);
103 OUT_BATCH((srcPitch * cpp) & 0xffff);
104 OUT_RELOC(dri_bo(surf->buffer),
105 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
106 DRM_BO_MASK_MEM | DRM_BO_FLAG_READ, 0);
107
108 fence = intel_be_batchbuffer_flush(intel->base.batch);
109 driFenceUnReference(&fence);
110 intel_be_batchbuffer_finish(intel->base.batch);
111 }