1 /**************************************************************************
3 * Copyright 2006 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 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Michel Dänzer <michel@tungstengraphics.com>
33 #include "pipe/p_context.h"
34 #include "pipe/p_defines.h"
35 #include "util/u_inlines.h"
36 #include "util/u_format.h"
37 #include "util/u_math.h"
38 #include "util/u_memory.h"
40 #include "i915_context.h"
41 #include "i915_resource.h"
42 #include "i915_screen.h"
47 i915_buffer_get_handle(struct pipe_screen
*screen
,
48 struct pipe_resource
*resource
,
49 struct winsys_handle
*handle
)
55 i915_buffer_destroy(struct pipe_screen
*screen
,
56 struct pipe_resource
*resource
)
58 struct i915_buffer
*buffer
= i915_buffer(resource
);
59 if (buffer
->free_on_destroy
)
60 align_free(buffer
->data
);
66 i915_buffer_transfer_map( struct pipe_context
*pipe
,
67 struct pipe_transfer
*transfer
)
69 struct i915_buffer
*buffer
= i915_buffer(transfer
->resource
);
70 return buffer
->data
+ transfer
->box
.x
;
75 i915_buffer_transfer_inline_write( struct pipe_context
*rm_ctx
,
76 struct pipe_resource
*resource
,
77 struct pipe_subresource sr
,
79 const struct pipe_box
*box
,
82 unsigned slice_stride
)
84 struct i915_buffer
*buffer
= i915_buffer(resource
);
86 memcpy(buffer
->data
+ box
->x
,
92 struct u_resource_vtbl i915_buffer_vtbl
=
94 i915_buffer_get_handle
, /* get_handle */
95 i915_buffer_destroy
, /* resource_destroy */
96 NULL
, /* is_resource_referenced */
97 u_default_get_transfer
, /* get_transfer */
98 u_default_transfer_destroy
, /* transfer_destroy */
99 i915_buffer_transfer_map
, /* transfer_map */
100 u_default_transfer_flush_region
, /* transfer_flush_region */
101 u_default_transfer_unmap
, /* transfer_unmap */
102 i915_buffer_transfer_inline_write
/* transfer_inline_write */
107 struct pipe_resource
*
108 i915_buffer_create(struct pipe_screen
*screen
,
109 const struct pipe_resource
*template)
111 struct i915_buffer
*buf
= CALLOC_STRUCT(i915_buffer
);
116 buf
->b
.b
= *template;
117 buf
->b
.vtbl
= &i915_buffer_vtbl
;
118 pipe_reference_init(&buf
->b
.b
.reference
, 1);
119 buf
->b
.b
.screen
= screen
;
121 buf
->data
= MALLOC(template->width0
);
122 buf
->free_on_destroy
= TRUE
;
136 struct pipe_resource
*
137 i915_user_buffer_create(struct pipe_screen
*screen
,
142 struct i915_buffer
*buf
= CALLOC_STRUCT(i915_buffer
);
147 pipe_reference_init(&buf
->b
.b
.reference
, 1);
148 buf
->b
.vtbl
= &i915_buffer_vtbl
;
149 buf
->b
.b
.screen
= screen
;
150 buf
->b
.b
.format
= PIPE_FORMAT_R8_UNORM
; /* ?? */
151 buf
->b
.b
._usage
= PIPE_USAGE_IMMUTABLE
;
152 buf
->b
.b
.bind
= bind
;
154 buf
->b
.b
.width0
= bytes
;
155 buf
->b
.b
.height0
= 1;
159 buf
->free_on_destroy
= FALSE
;