1 /**************************************************************************
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef INTEL_REGIONS_H
29 #define INTEL_REGIONS_H
31 /** @file intel_regions.h
33 * Structure definitions and prototypes for intel_region handling, which is
34 * the basic structure for rectangular collections of pixels stored in a dri_bo.
38 #include "dri_bufmgr.h"
41 struct intel_buffer_object
;
44 * A layer on top of the bufmgr buffers that adds a few useful things:
46 * - Refcounting for local buffer references.
47 * - Refcounting for buffer maps
48 * - Buffer dimensions - pitch and height.
49 * - Blitter commands for copying 2D regions between buffers. (really???)
53 dri_bo
*buffer
; /**< buffer manager's buffer */
54 GLuint refcount
; /**< Reference count for region */
55 GLuint cpp
; /**< bytes per pixel */
56 GLuint pitch
; /**< in pixels */
57 GLuint height
; /**< in pixels */
58 GLubyte
*map
; /**< only non-NULL when region is actually mapped */
59 GLuint map_refcount
; /**< Reference count for mapping */
61 GLuint draw_offset
; /**< Offset of drawing address within the region */
62 uint32_t tiling
; /**< Which tiling mode the region is in */
63 uint32_t bit_6_swizzle
; /**< GEM flag for address swizzling requirement */
64 drmAddress classic_map
; /**< drmMap of the region when not in GEM mode */
65 struct intel_buffer_object
*pbo
; /* zero-copy uploads */
69 /* Allocate a refcounted region. Pointers to regions should only be
70 * copied by calling intel_reference_region().
72 struct intel_region
*intel_region_alloc(struct intel_context
*intel
,
74 GLuint pitch
, GLuint height
);
77 intel_region_alloc_for_handle(struct intel_context
*intel
,
78 GLuint cpp
, GLuint pitch
, GLuint height
,
79 unsigned int handle
, const char *name
);
81 void intel_region_reference(struct intel_region
**dst
,
82 struct intel_region
*src
);
84 void intel_region_release(struct intel_region
**ib
);
86 void intel_recreate_static_regions(struct intel_context
*intel
);
88 /* Map/unmap regions. This is refcounted also:
90 GLubyte
*intel_region_map(struct intel_context
*intel
,
91 struct intel_region
*ib
);
93 void intel_region_unmap(struct intel_context
*intel
, struct intel_region
*ib
);
96 /* Upload data to a rectangular sub-region
98 void intel_region_data(struct intel_context
*intel
,
99 struct intel_region
*dest
,
101 GLuint destx
, GLuint desty
,
102 const void *src
, GLuint src_stride
,
103 GLuint srcx
, GLuint srcy
, GLuint width
, GLuint height
);
105 /* Copy rectangular sub-regions
107 void intel_region_copy(struct intel_context
*intel
,
108 struct intel_region
*dest
,
110 GLuint destx
, GLuint desty
,
111 struct intel_region
*src
,
113 GLuint srcx
, GLuint srcy
, GLuint width
, GLuint height
);
115 /* Fill a rectangular sub-region
117 void intel_region_fill(struct intel_context
*intel
,
118 struct intel_region
*dest
,
120 GLuint destx
, GLuint desty
,
121 GLuint width
, GLuint height
, GLuint color
);
123 /* Helpers for zerocopy uploads, particularly texture image uploads:
125 void intel_region_attach_pbo(struct intel_context
*intel
,
126 struct intel_region
*region
,
127 struct intel_buffer_object
*pbo
);
128 void intel_region_release_pbo(struct intel_context
*intel
,
129 struct intel_region
*region
);
130 void intel_region_cow(struct intel_context
*intel
,
131 struct intel_region
*region
);
133 dri_bo
*intel_region_buffer(struct intel_context
*intel
,
134 struct intel_region
*region
,
137 void _mesa_copy_rect(GLubyte
* dst
,
145 GLuint src_pitch
, GLuint src_x
, GLuint src_y
);