1af69d88dSmrg/************************************************************************** 2af69d88dSmrg * 3af69d88dSmrg * Copyright 2009 VMware, Inc. 4af69d88dSmrg * Copyright 2012 Marek Olšák <maraeo@gmail.com> 5af69d88dSmrg * All Rights Reserved. 6af69d88dSmrg * 7af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 8af69d88dSmrg * copy of this software and associated documentation files (the 9af69d88dSmrg * "Software"), to deal in the Software without restriction, including 10af69d88dSmrg * without limitation the rights to use, copy, modify, merge, publish, 11af69d88dSmrg * distribute, sub license, and/or sell copies of the Software, and to 12af69d88dSmrg * permit persons to whom the Software is furnished to do so, subject to 13af69d88dSmrg * the following conditions: 14af69d88dSmrg * 15af69d88dSmrg * The above copyright notice and this permission notice (including the 16af69d88dSmrg * next paragraph) shall be included in all copies or substantial portions 17af69d88dSmrg * of the Software. 18af69d88dSmrg * 19af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20af69d88dSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21af69d88dSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22af69d88dSmrg * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR 23af69d88dSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24af69d88dSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25af69d88dSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26af69d88dSmrg * 27af69d88dSmrg **************************************************************************/ 28af69d88dSmrg 29af69d88dSmrg/* A simple allocator that suballocates memory from a large buffer. */ 30af69d88dSmrg 31af69d88dSmrg#ifndef U_SUBALLOC 32af69d88dSmrg#define U_SUBALLOC 33af69d88dSmrg 347ec681f3Smrg#ifdef __cplusplus 357ec681f3Smrgextern "C" { 367ec681f3Smrg#endif 377ec681f3Smrg 387ec681f3Smrgstruct pipe_context; 397ec681f3Smrg 407ec681f3Smrgstruct u_suballocator { 417ec681f3Smrg struct pipe_context *pipe; 427ec681f3Smrg 437ec681f3Smrg unsigned size; /* Size of the whole buffer, in bytes. */ 447ec681f3Smrg unsigned bind; /* Bitmask of PIPE_BIND_* flags. */ 457ec681f3Smrg enum pipe_resource_usage usage; 467ec681f3Smrg unsigned flags; /* bitmask of PIPE_RESOURCE_FLAG_x */ 477ec681f3Smrg boolean zero_buffer_memory; /* If the buffer contents should be zeroed. */ 48af69d88dSmrg 497ec681f3Smrg struct pipe_resource *buffer; /* The buffer we suballocate from. */ 507ec681f3Smrg unsigned offset; /* Aligned offset pointing at the first unused byte. */ 517ec681f3Smrg}; 527ec681f3Smrg 537ec681f3Smrgvoid 547ec681f3Smrgu_suballocator_init(struct u_suballocator *allocator, 557ec681f3Smrg struct pipe_context *pipe, 567ec681f3Smrg unsigned size, unsigned bind, 577ec681f3Smrg enum pipe_resource_usage usage, unsigned flags, 587ec681f3Smrg boolean zero_buffer_memory); 59af69d88dSmrg 60af69d88dSmrgvoid 61af69d88dSmrgu_suballocator_destroy(struct u_suballocator *allocator); 62af69d88dSmrg 63af69d88dSmrgvoid 64af69d88dSmrgu_suballocator_alloc(struct u_suballocator *allocator, unsigned size, 6501e04c3fSmrg unsigned alignment, unsigned *out_offset, 6601e04c3fSmrg struct pipe_resource **outbuf); 67af69d88dSmrg 687ec681f3Smrg#ifdef __cplusplus 697ec681f3Smrg} 707ec681f3Smrg#endif 717ec681f3Smrg 72af69d88dSmrg#endif 73