1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
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 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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
27 **************************************************************************/
29 * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
34 #include "dri_bufpool.h"
35 #include "dri_bufmgr.h"
37 #include "intel_context.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_winsys.h"
41 #include "pipe/i915simple/i915_winsys.h"
44 struct intel_i915_winsys
{
45 struct i915_winsys winsys
;
46 struct intel_context
*intel
;
50 /* Turn a i915simple winsys into an intel/i915simple winsys:
52 static inline struct intel_i915_winsys
*
53 intel_i915_winsys( struct i915_winsys
*sws
)
55 return (struct intel_i915_winsys
*)sws
;
59 /* Simple batchbuffer interface:
62 static unsigned *intel_i915_batch_start( struct i915_winsys
*sws
,
66 struct intel_context
*intel
= intel_i915_winsys(sws
)->intel
;
70 if (intel_batchbuffer_space( intel
->batch
) >= dwords
* 4) {
71 /* XXX: Hmm, the driver can't really do much with this pointer:
73 return (unsigned *)intel
->batch
->ptr
;
79 static void intel_i915_batch_dword( struct i915_winsys
*sws
,
82 struct intel_context
*intel
= intel_i915_winsys(sws
)->intel
;
83 intel_batchbuffer_emit_dword( intel
->batch
, dword
);
86 static void intel_i915_batch_reloc( struct i915_winsys
*sws
,
87 struct pipe_buffer_handle
*buf
,
88 unsigned access_flags
,
91 struct intel_context
*intel
= intel_i915_winsys(sws
)->intel
;
92 unsigned flags
= DRM_BO_FLAG_MEM_TT
;
93 unsigned mask
= DRM_BO_MASK_MEM
;
95 if (access_flags
& I915_BUFFER_ACCESS_WRITE
) {
96 flags
|= DRM_BO_FLAG_WRITE
;
97 mask
|= DRM_BO_FLAG_WRITE
;
100 if (access_flags
& I915_BUFFER_ACCESS_READ
) {
101 flags
|= DRM_BO_FLAG_READ
;
102 mask
|= DRM_BO_FLAG_READ
;
105 intel_batchbuffer_emit_reloc( intel
->batch
,
113 static void intel_i915_batch_flush( struct i915_winsys
*sws
)
115 struct intel_context
*intel
= intel_i915_winsys(sws
)->intel
;
117 intel_batchbuffer_flush( intel
->batch
);
118 // if (0) intel_i915_batch_wait_idle( sws );
123 static struct pipe_region
*
124 intel_i915_region_alloc(struct pipe_winsys
*winsys
,
125 unsigned cpp
, unsigned width
,
126 unsigned height
, unsigned flags
)
128 struct pipe_region
*region
= calloc(sizeof(*region
), 1);
129 const unsigned alignment
= 64;
131 /* Choose a pitch to match hardware requirements - requires 64 byte
132 * alignment of render targets.
134 * XXX: is this ok for textures??
135 * clearly want to be able to render to textures under some
136 * circumstances, but maybe not always a requirement.
140 /* XXX is the pitch different for textures vs. drawables? */
141 if (flags
& PIPE_SURFACE_FLAG_TEXTURE
) /* or PIPE_SURFACE_FLAG_RENDER? */
142 pitch
= ((cpp
* width
+ 63) & ~63) / cpp
;
144 pitch
= ((cpp
* width
+ 63) & ~63) / cpp
;
147 region
->pitch
= pitch
;
148 region
->height
= height
; /* needed? */
149 region
->refcount
= 1;
151 region
->buffer
= winsys
->buffer_create( winsys
, alignment
);
153 winsys
->buffer_data( winsys
,
155 pitch
* cpp
* height
,
162 intel_i915_region_release(struct pipe_winsys
*winsys
,
163 struct pipe_region
**region
)
168 assert((*region
)->refcount
> 0);
169 (*region
)->refcount
--;
171 if ((*region
)->refcount
== 0) {
172 assert((*region
)->map_refcount
== 0);
174 winsys
->buffer_reference( winsys
,
175 &((*region
)->buffer
), NULL
);
182 struct pipe_context
*
183 intel_create_i915simple( struct intel_context
*intel
)
185 struct intel_i915_winsys
*iws
= CALLOC_STRUCT( intel_i915_winsys
);
187 /* Fill in this struct with callbacks that i915simple will need to
188 * communicate with the window system, buffer manager, etc.
190 iws
->winsys
.batch_start
= intel_i915_batch_start
;
191 iws
->winsys
.batch_dword
= intel_i915_batch_dword
;
192 iws
->winsys
.batch_reloc
= intel_i915_batch_reloc
;
193 iws
->winsys
.batch_flush
= intel_i915_batch_flush
;
196 iws
->winsys
.region_alloc
= intel_i915_region_alloc
;
197 iws
->winsys
.region_release
= intel_i915_region_release
;
199 /* Create the i915simple context:
201 return i915_create( intel_create_pipe_winsys(intel
),
203 intel
->intelScreen
->deviceID
);