intel_regions.h revision a9a483b43ec090408148d069bc184c0a21323654
1/************************************************************************** 2 * 3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#ifndef INTEL_REGIONS_H 29#define INTEL_REGIONS_H 30 31#include "mtypes.h" 32#include "dri_bufmgr.h" 33 34struct intel_context; 35struct intel_buffer_object; 36 37/** 38 * A layer on top of the bufmgr buffers that adds a few useful things: 39 * 40 * - Refcounting for local buffer references. 41 * - Refcounting for buffer maps 42 * - Buffer dimensions - pitch and height. 43 * - Blitter commands for copying 2D regions between buffers. (really???) 44 */ 45struct intel_region 46{ 47 dri_bo *buffer; /**< buffer manager's buffer */ 48 GLuint refcount; /**< Reference count for region */ 49 GLuint cpp; /**< bytes per pixel */ 50 GLuint pitch; /**< in pixels */ 51 GLuint height; /**< in pixels */ 52 GLubyte *map; /**< only non-NULL when region is actually mapped */ 53 GLuint map_refcount; /**< Reference count for mapping */ 54 55 GLuint draw_offset; /**< Offset of drawing address within the region */ 56 GLboolean tiled; /**< True if the region is X or Y-tiled. Used on 965. */ 57 58 struct intel_buffer_object *pbo; /* zero-copy uploads */ 59}; 60 61 62/* Allocate a refcounted region. Pointers to regions should only be 63 * copied by calling intel_reference_region(). 64 */ 65struct intel_region *intel_region_alloc(struct intel_context *intel, 66 GLuint cpp, 67 GLuint pitch, GLuint height); 68 69void intel_region_reference(struct intel_region **dst, 70 struct intel_region *src); 71 72void intel_region_release(struct intel_region **ib); 73 74void intel_recreate_static_regions(struct intel_context *intel); 75 76/* Map/unmap regions. This is refcounted also: 77 */ 78GLubyte *intel_region_map(struct intel_context *intel, 79 struct intel_region *ib); 80 81void intel_region_unmap(struct intel_context *intel, struct intel_region *ib); 82 83 84/* Upload data to a rectangular sub-region 85 */ 86void intel_region_data(struct intel_context *intel, 87 struct intel_region *dest, 88 GLuint dest_offset, 89 GLuint destx, GLuint desty, 90 const void *src, GLuint src_stride, 91 GLuint srcx, GLuint srcy, GLuint width, GLuint height); 92 93/* Copy rectangular sub-regions 94 */ 95void intel_region_copy(struct intel_context *intel, 96 struct intel_region *dest, 97 GLuint dest_offset, 98 GLuint destx, GLuint desty, 99 struct intel_region *src, 100 GLuint src_offset, 101 GLuint srcx, GLuint srcy, GLuint width, GLuint height); 102 103/* Fill a rectangular sub-region 104 */ 105void intel_region_fill(struct intel_context *intel, 106 struct intel_region *dest, 107 GLuint dest_offset, 108 GLuint destx, GLuint desty, 109 GLuint width, GLuint height, GLuint color); 110 111/* Helpers for zerocopy uploads, particularly texture image uploads: 112 */ 113void intel_region_attach_pbo(struct intel_context *intel, 114 struct intel_region *region, 115 struct intel_buffer_object *pbo); 116void intel_region_release_pbo(struct intel_context *intel, 117 struct intel_region *region); 118void intel_region_cow(struct intel_context *intel, 119 struct intel_region *region); 120 121dri_bo *intel_region_buffer(struct intel_context *intel, 122 struct intel_region *region, 123 GLuint flag); 124 125void _mesa_copy_rect(GLubyte * dst, 126 GLuint cpp, 127 GLuint dst_pitch, 128 GLuint dst_x, 129 GLuint dst_y, 130 GLuint width, 131 GLuint height, 132 const GLubyte * src, 133 GLuint src_pitch, GLuint src_x, GLuint src_y); 134 135#endif 136