Lift common winsys functions into pipe's new p_winsys.
[mesa.git] / src / mesa / drivers / dri / intel_winsys / intel_winsys_i915.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
24 * of the Software.
25 *
26 *
27 **************************************************************************/
28 /*
29 * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
30 */
31
32 #include <stdlib.h>
33 #include <xf86drm.h>
34 #include "dri_bufpool.h"
35 #include "dri_bufmgr.h"
36
37 #include "intel_context.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_winsys.h"
40 #include "intel_blit.h"
41
42 #include "pipe/i915simple/i915_winsys.h"
43
44
45 struct intel_i915_winsys {
46 struct i915_winsys winsys;
47 struct intel_context *intel;
48 };
49
50
51 /* Turn a i915simple winsys into an intel/i915simple winsys:
52 */
53 static inline struct intel_i915_winsys *
54 intel_i915_winsys( struct i915_winsys *sws )
55 {
56 return (struct intel_i915_winsys *)sws;
57 }
58
59
60 /* Simple batchbuffer interface:
61 */
62
63 static unsigned *intel_i915_batch_start( struct i915_winsys *sws,
64 unsigned dwords,
65 unsigned relocs )
66 {
67 struct intel_context *intel = intel_i915_winsys(sws)->intel;
68
69 /* XXX: check relocs.
70 */
71 if (intel_batchbuffer_space( intel->batch ) >= dwords * 4) {
72 /* XXX: Hmm, the driver can't really do much with this pointer:
73 */
74 return (unsigned *)intel->batch->ptr;
75 }
76 else
77 return NULL;
78 }
79
80 static void intel_i915_batch_dword( struct i915_winsys *sws,
81 unsigned dword )
82 {
83 struct intel_context *intel = intel_i915_winsys(sws)->intel;
84 intel_batchbuffer_emit_dword( intel->batch, dword );
85 }
86
87 static void intel_i915_batch_reloc( struct i915_winsys *sws,
88 struct pipe_buffer_handle *buf,
89 unsigned access_flags,
90 unsigned delta )
91 {
92 struct intel_context *intel = intel_i915_winsys(sws)->intel;
93 unsigned flags = DRM_BO_FLAG_MEM_TT;
94 unsigned mask = DRM_BO_MASK_MEM;
95
96 if (access_flags & I915_BUFFER_ACCESS_WRITE) {
97 flags |= DRM_BO_FLAG_WRITE;
98 mask |= DRM_BO_FLAG_WRITE;
99 }
100
101 if (access_flags & I915_BUFFER_ACCESS_READ) {
102 flags |= DRM_BO_FLAG_READ;
103 mask |= DRM_BO_FLAG_READ;
104 }
105
106 intel_batchbuffer_emit_reloc( intel->batch,
107 dri_bo( buf ),
108 flags, mask,
109 delta );
110 }
111
112
113
114 static void intel_i915_batch_flush( struct i915_winsys *sws )
115 {
116 struct intel_context *intel = intel_i915_winsys(sws)->intel;
117
118 intel_batchbuffer_flush( intel->batch );
119 if (0) intel_i915_batch_wait_idle( sws );
120 }
121
122
123
124
125 struct pipe_context *
126 intel_create_i915simple( struct intel_context *intel )
127 {
128 struct intel_i915_winsys *iws = CALLOC_STRUCT( intel_i915_winsys );
129
130 /* Fill in this struct with callbacks that i915simple will need to
131 * communicate with the window system, buffer manager, etc.
132 */
133 iws->winsys.batch_start = intel_i915_batch_start;
134 iws->winsys.batch_dword = intel_i915_batch_dword;
135 iws->winsys.batch_reloc = intel_i915_batch_reloc;
136 iws->winsys.batch_flush = intel_i915_batch_flush;
137 iws->intel = intel;
138
139 /* Create the i915simple context:
140 */
141 return i915_create( intel_create_pipe_winsys(intel),
142 &iws->winsys,
143 intel->intelScreen->deviceID );
144 }