pb_bufmgr_fenced.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00017  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
00018  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
00019  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
00020  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * The above copyright notice and this permission notice (including the
00023  * next paragraph) shall be included in all copies or substantial portions
00024  * of the Software.
00025  * 
00026  * 
00027  **************************************************************************/
00028 
00037 #include "pipe/p_debug.h"
00038 #include "util/u_memory.h"
00039 
00040 #include "pb_buffer.h"
00041 #include "pb_buffer_fenced.h"
00042 #include "pb_bufmgr.h"
00043 
00044 
00045 struct fenced_pb_manager
00046 {
00047    struct pb_manager base;
00048 
00049    struct pb_manager *provider;
00050    
00051    struct fenced_buffer_list *fenced_list;
00052 };
00053 
00054 
00055 static INLINE struct fenced_pb_manager *
00056 fenced_pb_manager(struct pb_manager *mgr)
00057 {
00058    assert(mgr);
00059    return (struct fenced_pb_manager *)mgr;
00060 }
00061 
00062 
00063 static struct pb_buffer *
00064 fenced_bufmgr_create_buffer(struct pb_manager *mgr, 
00065                             size_t size,
00066                             const struct pb_desc *desc)
00067 {
00068    struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
00069    struct pb_buffer *buf;
00070    struct pb_buffer *fenced_buf;
00071 
00072    /* check for free buffers before allocating new ones */
00073    fenced_buffer_list_check_free(fenced_mgr->fenced_list, 0);
00074    
00075    buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
00076    if(!buf) {
00077       /* try harder to get a buffer */
00078       fenced_buffer_list_check_free(fenced_mgr->fenced_list, 1);
00079       
00080       buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
00081       if(!buf) {
00082 #if 0
00083          fenced_buffer_list_dump(fenced_mgr->fenced_list);
00084 #endif
00085          
00086          /* give up */
00087          return NULL;
00088       }
00089    }
00090    
00091    fenced_buf = fenced_buffer_create(fenced_mgr->fenced_list, buf);
00092    if(!fenced_buf) {
00093       assert(buf->base.refcount == 1);
00094       pb_destroy(buf);
00095    }
00096    
00097    return fenced_buf;
00098 }
00099 
00100 
00101 static void
00102 fenced_bufmgr_flush(struct pb_manager *mgr)
00103 {
00104    struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
00105 
00106    fenced_buffer_list_check_free(fenced_mgr->fenced_list, TRUE);
00107 
00108    assert(fenced_mgr->provider->flush);
00109    if(fenced_mgr->provider->flush)
00110       fenced_mgr->provider->flush(fenced_mgr->provider);
00111 }
00112 
00113 
00114 static void
00115 fenced_bufmgr_destroy(struct pb_manager *mgr)
00116 {
00117    struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
00118 
00119    fenced_buffer_list_destroy(fenced_mgr->fenced_list);
00120 
00121    if(fenced_mgr->provider)
00122       fenced_mgr->provider->destroy(fenced_mgr->provider);
00123    
00124    FREE(fenced_mgr);
00125 }
00126 
00127 
00128 struct pb_manager *
00129 fenced_bufmgr_create(struct pb_manager *provider, 
00130                      struct pipe_winsys *winsys) 
00131 {
00132    struct fenced_pb_manager *fenced_mgr;
00133 
00134    if(!provider)
00135       return NULL;
00136    
00137    fenced_mgr = CALLOC_STRUCT(fenced_pb_manager);
00138    if (!fenced_mgr)
00139       return NULL;
00140 
00141    fenced_mgr->base.destroy = fenced_bufmgr_destroy;
00142    fenced_mgr->base.create_buffer = fenced_bufmgr_create_buffer;
00143    fenced_mgr->base.flush = fenced_bufmgr_flush;
00144 
00145    fenced_mgr->provider = provider;
00146    fenced_mgr->fenced_list = fenced_buffer_list_create(winsys);
00147    if(!fenced_mgr->fenced_list) {
00148       FREE(fenced_mgr);
00149       return NULL;
00150    }
00151       
00152    return &fenced_mgr->base;
00153 }

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