1 /************************************************************************** 2 * 3 * Copyright 2009 VMware, Inc. 4 * Copyright 2012 Marek Olšák <maraeo@gmail.com> 5 * All Rights Reserved. 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 THE AUTHORS 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 /* A simple allocator that suballocates memory from a large buffer. */ 30 31 #ifndef U_SUBALLOC 32 #define U_SUBALLOC 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 struct pipe_context; 39 40 struct u_suballocator { 41 struct pipe_context *pipe; 42 43 unsigned size; /* Size of the whole buffer, in bytes. */ 44 unsigned bind; /* Bitmask of PIPE_BIND_* flags. */ 45 enum pipe_resource_usage usage; 46 unsigned flags; /* bitmask of PIPE_RESOURCE_FLAG_x */ 47 boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */ 48 49 struct pipe_resource *buffer; /* The buffer we suballocate from. */ 50 unsigned offset; /* Aligned offset pointing at the first unused byte. */ 51 }; 52 53 void 54 u_suballocator_init(struct u_suballocator *allocator, 55 struct pipe_context *pipe, 56 unsigned size, unsigned bind, 57 enum pipe_resource_usage usage, unsigned flags, 58 boolean zero_buffer_memory); 59 60 void 61 u_suballocator_destroy(struct u_suballocator *allocator); 62 63 void 64 u_suballocator_alloc(struct u_suballocator *allocator, unsigned size, 65 unsigned alignment, unsigned *out_offset, 66 struct pipe_resource **outbuf); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif 73