include surface.offset in address calculations
[mesa.git] / src / mesa / pipe / softpipe / sp_buffer.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 "sp_context.h"
34 #include "sp_winsys.h"
35 #include "sp_buffer.h"
36
37
38
39 /* Most callbacks map direcly onto winsys operations:
40 */
41 static struct pipe_buffer_handle *
42 sp_create_buffer(struct pipe_context *pipe,
43 unsigned alignment,
44 unsigned flags)
45 {
46 struct softpipe_context *sp = softpipe_context( pipe );
47 return sp->winsys->create_buffer( sp->winsys, alignment );
48 }
49
50 static void *sp_buffer_map(struct pipe_context *pipe,
51 struct pipe_buffer_handle *buf,
52 unsigned flags )
53 {
54 struct softpipe_context *sp = softpipe_context( pipe );
55 return sp->winsys->buffer_map( sp->winsys, buf );
56 }
57
58 static void sp_buffer_unmap(struct pipe_context *pipe,
59 struct pipe_buffer_handle *buf)
60 {
61 struct softpipe_context *sp = softpipe_context( pipe );
62 sp->winsys->buffer_unmap( sp->winsys, buf );
63 }
64
65 static struct pipe_buffer_handle *
66 sp_buffer_reference(struct pipe_context *pipe,
67 struct pipe_buffer_handle *buf)
68 {
69 struct softpipe_context *sp = softpipe_context( pipe );
70 return sp->winsys->buffer_reference( sp->winsys, buf );
71 }
72
73 static void sp_buffer_unreference(struct pipe_context *pipe,
74 struct pipe_buffer_handle **buf)
75 {
76 struct softpipe_context *sp = softpipe_context( pipe );
77 sp->winsys->buffer_unreference( sp->winsys, buf );
78 }
79
80 static void sp_buffer_data(struct pipe_context *pipe,
81 struct pipe_buffer_handle *buf,
82 unsigned size, const void *data )
83 {
84 struct softpipe_context *sp = softpipe_context( pipe );
85 sp->winsys->buffer_data( sp->winsys, buf, size, data );
86 }
87
88 static void sp_buffer_subdata(struct pipe_context *pipe,
89 struct pipe_buffer_handle *buf,
90 unsigned long offset,
91 unsigned long size,
92 const void *data)
93 {
94 struct softpipe_context *sp = softpipe_context( pipe );
95 sp->winsys->buffer_subdata( sp->winsys, buf, offset, size, data );
96 }
97
98 static void sp_buffer_get_subdata(struct pipe_context *pipe,
99 struct pipe_buffer_handle *buf,
100 unsigned long offset,
101 unsigned long size,
102 void *data)
103 {
104 struct softpipe_context *sp = softpipe_context( pipe );
105 sp->winsys->buffer_get_subdata( sp->winsys, buf, offset, size, data );
106 }
107
108
109 void
110 sp_init_buffer_functions( struct softpipe_context *sp )
111 {
112 sp->pipe.create_buffer = sp_create_buffer;
113 sp->pipe.buffer_map = sp_buffer_map;
114 sp->pipe.buffer_unmap = sp_buffer_unmap;
115 sp->pipe.buffer_reference = sp_buffer_reference;
116 sp->pipe.buffer_unreference = sp_buffer_unreference;
117 sp->pipe.buffer_data = sp_buffer_data;
118 sp->pipe.buffer_subdata = sp_buffer_subdata;
119 sp->pipe.buffer_get_subdata = sp_buffer_get_subdata;
120 }