1975d729e473b4d15dee4c0ddbb3b75e1e878a73
[mesa.git] / src / mesa / drivers / dri / intel / intel_regions.h
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
34 struct intel_context;
35 struct 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 */
45 struct 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 */
65 struct intel_region *intel_region_alloc(struct intel_context *intel,
66 GLuint cpp,
67 GLuint pitch, GLuint height);
68
69 void intel_region_reference(struct intel_region **dst,
70 struct intel_region *src);
71
72 void intel_region_release(struct intel_region **ib);
73
74 void intel_recreate_static_regions(struct intel_context *intel);
75
76 void intel_region_idle(struct intel_context *intel,
77 struct intel_region *ib);
78
79 /* Map/unmap regions. This is refcounted also:
80 */
81 GLubyte *intel_region_map(struct intel_context *intel,
82 struct intel_region *ib);
83
84 void intel_region_unmap(struct intel_context *intel, struct intel_region *ib);
85
86
87 /* Upload data to a rectangular sub-region
88 */
89 void intel_region_data(struct intel_context *intel,
90 struct intel_region *dest,
91 GLuint dest_offset,
92 GLuint destx, GLuint desty,
93 const void *src, GLuint src_stride,
94 GLuint srcx, GLuint srcy, GLuint width, GLuint height);
95
96 /* Copy rectangular sub-regions
97 */
98 void intel_region_copy(struct intel_context *intel,
99 struct intel_region *dest,
100 GLuint dest_offset,
101 GLuint destx, GLuint desty,
102 struct intel_region *src,
103 GLuint src_offset,
104 GLuint srcx, GLuint srcy, GLuint width, GLuint height);
105
106 /* Fill a rectangular sub-region
107 */
108 void intel_region_fill(struct intel_context *intel,
109 struct intel_region *dest,
110 GLuint dest_offset,
111 GLuint destx, GLuint desty,
112 GLuint width, GLuint height, GLuint color);
113
114 /* Helpers for zerocopy uploads, particularly texture image uploads:
115 */
116 void intel_region_attach_pbo(struct intel_context *intel,
117 struct intel_region *region,
118 struct intel_buffer_object *pbo);
119 void intel_region_release_pbo(struct intel_context *intel,
120 struct intel_region *region);
121 void intel_region_cow(struct intel_context *intel,
122 struct intel_region *region);
123
124 dri_bo *intel_region_buffer(struct intel_context *intel,
125 struct intel_region *region,
126 GLuint flag);
127
128 #endif