00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
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 }