1 /**************************************************************************
3 * Copyright © 2009 Jakob Bornecrantz
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 **************************************************************************/
26 #include "util/u_inlines.h"
27 #include "util/u_memory.h"
28 #include "i915_screen.h"
29 #include "i915_buffer.h"
31 struct i915_winsys_buffer;
35 struct pipe_buffer base;
37 struct i915_winsys_buffer *ibuf; /** hw buffer */
39 void *data; /**< user and malloc data */
40 boolean own; /**< we own the data incase of malloc */
43 static INLINE struct i915_buffer *
44 i915_buffer(struct pipe_buffer *buffer)
46 return (struct i915_buffer *)buffer;
49 static struct pipe_buffer *
50 i915_buffer_create(struct pipe_screen *screen,
55 struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
60 pipe_reference_init(&buf->base.reference, 1);
61 buf->base.alignment = alignment;
62 buf->base.screen = screen;
63 buf->base.usage = usage;
64 buf->base.size = size;
65 buf->data = MALLOC(size);
78 static struct pipe_buffer *
79 i915_user_buffer_create(struct pipe_screen *screen,
83 struct i915_buffer *buf = CALLOC_STRUCT(i915_buffer);
88 pipe_reference_init(&buf->base.reference, 1);
89 buf->base.alignment = 0;
90 buf->base.screen = screen;
92 buf->base.size = bytes;
100 i915_buffer_map(struct pipe_screen *screen,
101 struct pipe_buffer *buffer,
104 struct i915_buffer *buf = i915_buffer(buffer);
110 i915_buffer_unmap(struct pipe_screen *screen,
111 struct pipe_buffer *buffer)
113 struct i915_buffer *buf = i915_buffer(buffer);
119 i915_buffer_destroy(struct pipe_buffer *buffer)
121 struct i915_buffer *buf = i915_buffer(buffer);
129 void i915_init_screen_buffer_functions(struct i915_screen *screen)
131 screen->base.buffer_create = i915_buffer_create;
132 screen->base.user_buffer_create = i915_user_buffer_create;
133 screen->base.buffer_map = i915_buffer_map;
134 screen->base.buffer_map_range = NULL;
135 screen->base.buffer_flush_mapped_range = NULL;
136 screen->base.buffer_unmap = i915_buffer_unmap;
137 screen->base.buffer_destroy = i915_buffer_destroy;