pb_bufmgr_alt.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00036 #include "pipe/p_compiler.h"
00037 #include "pipe/p_debug.h"
00038 #include "util/u_memory.h"
00039 
00040 #include "pb_buffer.h"
00041 #include "pb_bufmgr.h"
00042 
00043 
00044 struct pb_alt_manager
00045 {
00046    struct pb_manager base;
00047 
00048    struct pb_manager *provider1;
00049    struct pb_manager *provider2;
00050 };
00051 
00052 
00053 static INLINE struct pb_alt_manager *
00054 pb_alt_manager(struct pb_manager *mgr)
00055 {
00056    assert(mgr);
00057    return (struct pb_alt_manager *)mgr;
00058 }
00059 
00060 
00061 static struct pb_buffer *
00062 pb_alt_manager_create_buffer(struct pb_manager *_mgr, 
00063                              size_t size,
00064                              const struct pb_desc *desc)
00065 {
00066    struct pb_alt_manager *mgr = pb_alt_manager(_mgr);
00067    struct pb_buffer *buf;
00068    
00069    buf = mgr->provider1->create_buffer(mgr->provider1, size, desc);
00070    if(buf)
00071       return buf;
00072    
00073    buf = mgr->provider2->create_buffer(mgr->provider2, size, desc);
00074    return buf;
00075 }
00076 
00077 
00078 static void
00079 pb_alt_manager_flush(struct pb_manager *_mgr)
00080 {
00081    struct pb_alt_manager *mgr = pb_alt_manager(_mgr);
00082    
00083    assert(mgr->provider1->flush);
00084    if(mgr->provider1->flush)
00085       mgr->provider1->flush(mgr->provider1);
00086    
00087    assert(mgr->provider2->flush);
00088    if(mgr->provider2->flush)
00089       mgr->provider2->flush(mgr->provider2);
00090 }
00091 
00092 
00093 static void
00094 pb_alt_manager_destroy(struct pb_manager *mgr)
00095 {
00096    FREE(mgr);
00097 }
00098 
00099 
00100 struct pb_manager *
00101 pb_alt_manager_create(struct pb_manager *provider1, 
00102                       struct pb_manager *provider2)
00103 {
00104    struct pb_alt_manager *mgr;
00105 
00106    if(!provider1 || !provider2)
00107       return NULL;
00108    
00109    mgr = CALLOC_STRUCT(pb_alt_manager);
00110    if (!mgr)
00111       return NULL;
00112 
00113    mgr->base.destroy = pb_alt_manager_destroy;
00114    mgr->base.create_buffer = pb_alt_manager_create_buffer;
00115    mgr->base.flush = pb_alt_manager_flush;
00116    mgr->provider1 = provider1;
00117    mgr->provider2 = provider2;
00118       
00119    return &mgr->base;
00120 }

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4