Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
/**************************************************************************
2
 *
3
 * Copyright 2009, VMware, Inc.
4
 * All Rights Reserved.
5
 * Copyright 2010 George Sapountzis 
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a
8
 * copy of this software and associated documentation files (the
9
 * "Software"), to deal in the Software without restriction, including
10
 * without limitation the rights to use, copy, modify, merge, publish,
11
 * distribute, sub license, and/or sell copies of the Software, and to
12
 * permit persons to whom the Software is furnished to do so, subject to
13
 * the following conditions:
14
 *
15
 * The above copyright notice and this permission notice (including the
16
 * next paragraph) shall be included in all copies or substantial portions
17
 * of the Software.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
 *
27
 **************************************************************************/
28
 
29
#include "pipe/p_compiler.h"
30
#include "pipe/p_format.h"
31
#include "util/u_inlines.h"
32
#include "util/u_format.h"
33
#include "util/u_math.h"
34
#include "util/u_memory.h"
35
 
36
#include "state_tracker/sw_winsys.h"
37
#include "dri_sw_winsys.h"
38
 
39
 
40
struct dri_sw_displaytarget
41
{
42
   enum pipe_format format;
43
   unsigned width;
44
   unsigned height;
45
   unsigned stride;
46
 
47
   void *data;
48
   void *mapped;
49
};
50
 
51
struct dri_sw_winsys
52
{
53
   struct sw_winsys base;
54
 
55
   struct drisw_loader_funcs *lf;
56
};
57
 
58
static INLINE struct dri_sw_displaytarget *
59
dri_sw_displaytarget( struct sw_displaytarget *dt )
60
{
61
   return (struct dri_sw_displaytarget *)dt;
62
}
63
 
64
static INLINE struct dri_sw_winsys *
65
dri_sw_winsys( struct sw_winsys *ws )
66
{
67
   return (struct dri_sw_winsys *)ws;
68
}
69
 
70
 
71
static boolean
72
dri_sw_is_displaytarget_format_supported( struct sw_winsys *ws,
73
                                          unsigned tex_usage,
74
                                          enum pipe_format format )
75
{
76
   /* TODO: check visuals or other sensible thing here */
77
   return TRUE;
78
}
79
 
80
static struct sw_displaytarget *
81
dri_sw_displaytarget_create(struct sw_winsys *winsys,
82
                            unsigned tex_usage,
83
                            enum pipe_format format,
84
                            unsigned width, unsigned height,
85
                            unsigned alignment,
86
                            unsigned *stride)
87
{
88
   struct dri_sw_displaytarget *dri_sw_dt;
89
   unsigned nblocksy, size, format_stride;
90
 
91
   dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget);
92
   if(!dri_sw_dt)
93
      goto no_dt;
94
 
95
   dri_sw_dt->format = format;
96
   dri_sw_dt->width = width;
97
   dri_sw_dt->height = height;
98
 
99
   format_stride = util_format_get_stride(format, width);
100
   dri_sw_dt->stride = align(format_stride, alignment);
101
 
102
   nblocksy = util_format_get_nblocksy(format, height);
103
   size = dri_sw_dt->stride * nblocksy;
104
 
105
   dri_sw_dt->data = align_malloc(size, alignment);
106
   if(!dri_sw_dt->data)
107
      goto no_data;
108
 
109
   *stride = dri_sw_dt->stride;
110
   return (struct sw_displaytarget *)dri_sw_dt;
111
 
112
no_data:
113
   FREE(dri_sw_dt);
114
no_dt:
115
   return NULL;
116
}
117
 
118
static void
119
dri_sw_displaytarget_destroy(struct sw_winsys *ws,
120
                             struct sw_displaytarget *dt)
121
{
122
   struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
123
 
124
   FREE(dri_sw_dt->data);
125
 
126
   FREE(dri_sw_dt);
127
}
128
 
129
static void *
130
dri_sw_displaytarget_map(struct sw_winsys *ws,
131
                         struct sw_displaytarget *dt,
132
                         unsigned flags)
133
{
134
   struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
135
   dri_sw_dt->mapped = dri_sw_dt->data;
136
   return dri_sw_dt->mapped;
137
}
138
 
139
static void
140
dri_sw_displaytarget_unmap(struct sw_winsys *ws,
141
                           struct sw_displaytarget *dt)
142
{
143
   struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
144
   dri_sw_dt->mapped = NULL;
145
}
146
 
147
static struct sw_displaytarget *
148
dri_sw_displaytarget_from_handle(struct sw_winsys *winsys,
149
                                 const struct pipe_resource *templ,
150
                                 struct winsys_handle *whandle,
151
                                 unsigned *stride)
152
{
153
   assert(0);
154
   return NULL;
155
}
156
 
157
static boolean
158
dri_sw_displaytarget_get_handle(struct sw_winsys *winsys,
159
                                struct sw_displaytarget *dt,
160
                                struct winsys_handle *whandle)
161
{
162
   assert(0);
163
   return FALSE;
164
}
165
 
166
static void
167
dri_sw_displaytarget_display(struct sw_winsys *ws,
168
                             struct sw_displaytarget *dt,
169
                             void *context_private)
170
{
171
   struct dri_sw_winsys *dri_sw_ws = dri_sw_winsys(ws);
172
   struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt);
173
   struct dri_drawable *dri_drawable = (struct dri_drawable *)context_private;
174
   unsigned width, height;
175
 
176
   /* Set the width to 'stride / cpp'.
177
    *
178
    * PutImage correctly clips to the width of the dst drawable.
179
    */
180
   width = dri_sw_dt->stride / util_format_get_blocksize(dri_sw_dt->format);
181
 
182
   height = dri_sw_dt->height;
183
 
184
   dri_sw_ws->lf->put_image(dri_drawable, dri_sw_dt->data, width, height);
185
}
186
 
187
 
188
static void
189
dri_destroy_sw_winsys(struct sw_winsys *winsys)
190
{
191
   FREE(winsys);
192
}
193
 
194
struct sw_winsys *
195
dri_create_sw_winsys(struct drisw_loader_funcs *lf)
196
{
197
   struct dri_sw_winsys *ws;
198
 
199
   ws = CALLOC_STRUCT(dri_sw_winsys);
200
   if (!ws)
201
      return NULL;
202
 
203
   ws->lf = lf;
204
   ws->base.destroy = dri_destroy_sw_winsys;
205
 
206
   ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported;
207
 
208
   /* screen texture functions */
209
   ws->base.displaytarget_create = dri_sw_displaytarget_create;
210
   ws->base.displaytarget_destroy = dri_sw_displaytarget_destroy;
211
   ws->base.displaytarget_from_handle = dri_sw_displaytarget_from_handle;
212
   ws->base.displaytarget_get_handle = dri_sw_displaytarget_get_handle;
213
 
214
   /* texture functions */
215
   ws->base.displaytarget_map = dri_sw_displaytarget_map;
216
   ws->base.displaytarget_unmap = dri_sw_displaytarget_unmap;
217
 
218
   ws->base.displaytarget_display = dri_sw_displaytarget_display;
219
 
220
   return &ws->base;
221
}
222
 
223
/* vim: set sw=3 ts=8 sts=3 expandtab: */