intel_regions.h revision 3e43adef95ee24dd218279d2de56939b90edcb4c
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/** @file intel_regions.h 32 * 33 * Structure definitions and prototypes for intel_region handling, 34 * which is the basic structure for rectangular collections of pixels 35 * stored in a drm_intel_bo. 36 */ 37 38#include <xf86drm.h> 39 40#include "main/mtypes.h" 41#include "intel_bufmgr.h" 42 43struct intel_context; 44struct intel_buffer_object; 45 46/** 47 * A layer on top of the bufmgr buffers that adds a few useful things: 48 * 49 * - Refcounting for local buffer references. 50 * - Refcounting for buffer maps 51 * - Buffer dimensions - pitch and height. 52 * - Blitter commands for copying 2D regions between buffers. (really???) 53 */ 54struct intel_region 55{ 56 drm_intel_bo *buffer; /**< buffer manager's buffer */ 57 GLuint refcount; /**< Reference count for region */ 58 GLuint cpp; /**< bytes per pixel */ 59 GLuint width; /**< in pixels */ 60 GLuint height; /**< in pixels */ 61 GLuint pitch; /**< in pixels */ 62 GLubyte *map; /**< only non-NULL when region is actually mapped */ 63 GLuint map_refcount; /**< Reference count for mapping */ 64 65 GLuint draw_offset; /**< Offset of drawing address within the region */ 66 GLuint draw_x, draw_y; /**< Offset of drawing within the region */ 67 68 uint32_t tiling; /**< Which tiling mode the region is in */ 69 struct intel_buffer_object *pbo; /* zero-copy uploads */ 70 71 uint32_t name; /**< Global name for the bo */ 72 struct intel_screen *screen; 73}; 74 75 76/* Allocate a refcounted region. Pointers to regions should only be 77 * copied by calling intel_reference_region(). 78 */ 79struct intel_region *intel_region_alloc(struct intel_screen *screen, 80 uint32_t tiling, 81 GLuint cpp, GLuint width, 82 GLuint height, 83 GLboolean expect_accelerated_upload); 84 85struct intel_region * 86intel_region_alloc_for_handle(struct intel_screen *screen, 87 GLuint cpp, 88 GLuint width, GLuint height, GLuint pitch, 89 unsigned int handle, const char *name); 90 91GLboolean 92intel_region_flink(struct intel_region *region, uint32_t *name); 93 94void intel_region_reference(struct intel_region **dst, 95 struct intel_region *src); 96 97void intel_region_release(struct intel_region **ib); 98 99void intel_recreate_static_regions(struct intel_context *intel); 100 101/* Map/unmap regions. This is refcounted also: 102 */ 103GLubyte *intel_region_map(struct intel_context *intel, 104 struct intel_region *ib); 105 106void intel_region_unmap(struct intel_context *intel, struct intel_region *ib); 107 108 109/* Upload data to a rectangular sub-region 110 */ 111void intel_region_data(struct intel_context *intel, 112 struct intel_region *dest, 113 GLuint dest_offset, 114 GLuint destx, GLuint desty, 115 const void *src, GLuint src_stride, 116 GLuint srcx, GLuint srcy, GLuint width, GLuint height); 117 118/* Copy rectangular sub-regions 119 */ 120GLboolean 121intel_region_copy(struct intel_context *intel, 122 struct intel_region *dest, 123 GLuint dest_offset, 124 GLuint destx, GLuint desty, 125 struct intel_region *src, 126 GLuint src_offset, 127 GLuint srcx, GLuint srcy, GLuint width, GLuint height, 128 GLboolean flip, 129 GLenum logicop); 130 131/* Helpers for zerocopy uploads, particularly texture image uploads: 132 */ 133void intel_region_attach_pbo(struct intel_context *intel, 134 struct intel_region *region, 135 struct intel_buffer_object *pbo); 136void intel_region_release_pbo(struct intel_context *intel, 137 struct intel_region *region); 138void intel_region_cow(struct intel_context *intel, 139 struct intel_region *region); 140 141drm_intel_bo *intel_region_buffer(struct intel_context *intel, 142 struct intel_region *region, 143 GLuint flag); 144 145uint32_t intel_region_tile_offsets(struct intel_region *region, 146 uint32_t *tile_x, 147 uint32_t *tile_y); 148 149void _mesa_copy_rect(GLubyte * dst, 150 GLuint cpp, 151 GLuint dst_pitch, 152 GLuint dst_x, 153 GLuint dst_y, 154 GLuint width, 155 GLuint height, 156 const GLubyte * src, 157 GLuint src_pitch, GLuint src_x, GLuint src_y); 158 159struct __DRIimageRec { 160 struct intel_region *region; 161 GLenum internal_format; 162 GLuint format; 163 GLenum data_type; 164 void *data; 165}; 166 167#endif 168