1 /**************************************************************************
3 * Copyright 2007-2008 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 **************************************************************************/
30 * Allocate buffers from two alternative buffer providers.
32 * \author Jose Fonseca <jrfonseca@tungstengraphics.com>
36 #include "pipe/p_compiler.h"
37 #include "util/u_debug.h"
38 #include "util/u_memory.h"
40 #include "pb_buffer.h"
41 #include "pb_bufmgr.h"
46 struct pb_manager base
;
48 struct pb_manager
*provider1
;
49 struct pb_manager
*provider2
;
53 static INLINE
struct pb_alt_manager
*
54 pb_alt_manager(struct pb_manager
*mgr
)
57 return (struct pb_alt_manager
*)mgr
;
61 static struct pb_buffer
*
62 pb_alt_manager_create_buffer(struct pb_manager
*_mgr
,
64 const struct pb_desc
*desc
)
66 struct pb_alt_manager
*mgr
= pb_alt_manager(_mgr
);
67 struct pb_buffer
*buf
;
69 buf
= mgr
->provider1
->create_buffer(mgr
->provider1
, size
, desc
);
73 buf
= mgr
->provider2
->create_buffer(mgr
->provider2
, size
, desc
);
79 pb_alt_manager_flush(struct pb_manager
*_mgr
)
81 struct pb_alt_manager
*mgr
= pb_alt_manager(_mgr
);
83 assert(mgr
->provider1
->flush
);
84 if(mgr
->provider1
->flush
)
85 mgr
->provider1
->flush(mgr
->provider1
);
87 assert(mgr
->provider2
->flush
);
88 if(mgr
->provider2
->flush
)
89 mgr
->provider2
->flush(mgr
->provider2
);
94 pb_alt_manager_destroy(struct pb_manager
*mgr
)
101 pb_alt_manager_create(struct pb_manager
*provider1
,
102 struct pb_manager
*provider2
)
104 struct pb_alt_manager
*mgr
;
106 if(!provider1
|| !provider2
)
109 mgr
= CALLOC_STRUCT(pb_alt_manager
);
113 mgr
->base
.destroy
= pb_alt_manager_destroy
;
114 mgr
->base
.create_buffer
= pb_alt_manager_create_buffer
;
115 mgr
->base
.flush
= pb_alt_manager_flush
;
116 mgr
->provider1
= provider1
;
117 mgr
->provider2
= provider2
;