1 /**************************************************************************
3 * Copyright 2006 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
30 * Michel Dänzer <daenzer@vmware.com>
33 #include "pipe/p_context.h"
34 #include "pipe/p_defines.h"
35 #include "util/u_inlines.h"
36 #include "util/u_math.h"
37 #include "util/u_memory.h"
39 #include "i915_context.h"
40 #include "i915_resource.h"
45 i915_buffer_get_handle(struct pipe_screen
*screen
,
46 struct pipe_resource
*resource
,
47 struct winsys_handle
*handle
)
53 i915_buffer_destroy(struct pipe_screen
*screen
,
54 struct pipe_resource
*resource
)
56 struct i915_buffer
*buffer
= i915_buffer(resource
);
57 if (buffer
->free_on_destroy
)
58 align_free(buffer
->data
);
64 i915_buffer_transfer_map(struct pipe_context
*pipe
,
65 struct pipe_resource
*resource
,
68 const struct pipe_box
*box
,
69 struct pipe_transfer
**ptransfer
)
71 struct i915_context
*i915
= i915_context(pipe
);
72 struct i915_buffer
*buffer
= i915_buffer(resource
);
73 struct pipe_transfer
*transfer
= util_slab_alloc(&i915
->transfer_pool
);
78 transfer
->resource
= resource
;
79 transfer
->level
= level
;
80 transfer
->usage
= usage
;
82 *ptransfer
= transfer
;
84 return buffer
->data
+ transfer
->box
.x
;
88 i915_buffer_transfer_unmap(struct pipe_context
*pipe
,
89 struct pipe_transfer
*transfer
)
91 struct i915_context
*i915
= i915_context(pipe
);
92 util_slab_free(&i915
->transfer_pool
, transfer
);
96 i915_buffer_transfer_inline_write( struct pipe_context
*rm_ctx
,
97 struct pipe_resource
*resource
,
100 const struct pipe_box
*box
,
103 unsigned layer_stride
)
105 struct i915_buffer
*buffer
= i915_buffer(resource
);
107 memcpy(buffer
->data
+ box
->x
,
113 struct u_resource_vtbl i915_buffer_vtbl
=
115 i915_buffer_get_handle
, /* get_handle */
116 i915_buffer_destroy
, /* resource_destroy */
117 i915_buffer_transfer_map
, /* transfer_map */
118 u_default_transfer_flush_region
, /* transfer_flush_region */
119 i915_buffer_transfer_unmap
, /* transfer_unmap */
120 i915_buffer_transfer_inline_write
/* transfer_inline_write */
125 struct pipe_resource
*
126 i915_buffer_create(struct pipe_screen
*screen
,
127 const struct pipe_resource
*template)
129 struct i915_buffer
*buf
= CALLOC_STRUCT(i915_buffer
);
134 buf
->b
.b
= *template;
135 buf
->b
.vtbl
= &i915_buffer_vtbl
;
136 pipe_reference_init(&buf
->b
.b
.reference
, 1);
137 buf
->b
.b
.screen
= screen
;
138 buf
->data
= align_malloc(template->width0
, 64);
139 buf
->free_on_destroy
= TRUE
;
153 struct pipe_resource
*
154 i915_user_buffer_create(struct pipe_screen
*screen
,
159 struct i915_buffer
*buf
= CALLOC_STRUCT(i915_buffer
);
164 pipe_reference_init(&buf
->b
.b
.reference
, 1);
165 buf
->b
.vtbl
= &i915_buffer_vtbl
;
166 buf
->b
.b
.screen
= screen
;
167 buf
->b
.b
.format
= PIPE_FORMAT_R8_UNORM
; /* ?? */
168 buf
->b
.b
.usage
= PIPE_USAGE_IMMUTABLE
;
169 buf
->b
.b
.bind
= bind
;
171 buf
->b
.b
.width0
= bytes
;
172 buf
->b
.b
.height0
= 1;
174 buf
->b
.b
.array_size
= 1;
177 buf
->free_on_destroy
= FALSE
;