mesa: remove gl_renderbuffer:RowStride field
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_span.c
1 /**************************************************************************
2
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
5 VA Linux Systems Inc., Fremont, California.
6
7 The Weather Channel (TM) funded Tungsten Graphics to develop the
8 initial release of the Radeon 8500 driver under the XFree86 license.
9 This notice must be preserved.
10
11 All Rights Reserved.
12
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
20
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial
23 portions of the Software.
24
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
29 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
33 **************************************************************************/
34
35 /*
36 * Authors:
37 * Kevin E. Martin <martin@valinux.com>
38 * Gareth Hughes <gareth@valinux.com>
39 * Keith Whitwell <keith@tungstengraphics.com>
40 *
41 */
42
43 #include "main/glheader.h"
44 #include "main/texformat.h"
45 #include "main/renderbuffer.h"
46 #include "swrast/swrast.h"
47 #include "swrast/s_renderbuffer.h"
48
49 #include "radeon_common.h"
50 #include "radeon_span.h"
51
52
53 static void
54 radeon_renderbuffer_map(struct gl_context *ctx, struct gl_renderbuffer *rb)
55 {
56 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
57 GLubyte *map;
58 int stride;
59
60 if (!rb || !rrb)
61 return;
62
63 ctx->Driver.MapRenderbuffer(ctx, rb, 0, 0, rb->Width, rb->Height,
64 GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
65 &map, &stride);
66
67 rb->Map = map;
68 rb->RowStrideBytes = stride;
69 }
70
71 static void
72 radeon_renderbuffer_unmap(struct gl_context *ctx, struct gl_renderbuffer *rb)
73 {
74 struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
75 if (!rb || !rrb)
76 return;
77
78 ctx->Driver.UnmapRenderbuffer(ctx, rb);
79
80 rb->Map = NULL;
81 rb->RowStrideBytes = 0;
82 }
83
84 static void
85 radeon_map_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
86 {
87 GLuint i;
88
89 radeon_print(RADEON_MEMORY, RADEON_TRACE,
90 "%s( %p , fb %p )\n",
91 __func__, ctx, fb);
92
93 /* check for render to textures */
94 for (i = 0; i < BUFFER_COUNT; i++)
95 radeon_renderbuffer_map(ctx, fb->Attachment[i].Renderbuffer);
96
97 radeon_check_front_buffer_rendering(ctx);
98 }
99
100 static void
101 radeon_unmap_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
102 {
103 GLuint i;
104
105 radeon_print(RADEON_MEMORY, RADEON_TRACE,
106 "%s( %p , fb %p)\n",
107 __func__, ctx, fb);
108
109 /* check for render to textures */
110 for (i = 0; i < BUFFER_COUNT; i++)
111 radeon_renderbuffer_unmap(ctx, fb->Attachment[i].Renderbuffer);
112
113 radeon_check_front_buffer_rendering(ctx);
114 }
115
116 static void radeonSpanRenderStart(struct gl_context * ctx)
117 {
118 radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
119 int i;
120
121 radeon_firevertices(rmesa);
122
123 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
124 if (ctx->Texture.Unit[i]._ReallyEnabled) {
125 radeon_validate_texture_miptree(ctx, ctx->Texture.Unit[i]._Current);
126 radeon_swrast_map_texture_images(ctx, ctx->Texture.Unit[i]._Current);
127 }
128 }
129
130 radeon_map_framebuffer(ctx, ctx->DrawBuffer);
131 if (ctx->ReadBuffer != ctx->DrawBuffer)
132 radeon_map_framebuffer(ctx, ctx->ReadBuffer);
133 }
134
135 static void radeonSpanRenderFinish(struct gl_context * ctx)
136 {
137 int i;
138
139 _swrast_flush(ctx);
140
141 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++)
142 if (ctx->Texture.Unit[i]._ReallyEnabled)
143 radeon_swrast_unmap_texture_images(ctx, ctx->Texture.Unit[i]._Current);
144
145 radeon_unmap_framebuffer(ctx, ctx->DrawBuffer);
146 if (ctx->ReadBuffer != ctx->DrawBuffer)
147 radeon_unmap_framebuffer(ctx, ctx->ReadBuffer);
148 }
149
150 void radeonInitSpanFuncs(struct gl_context * ctx)
151 {
152 struct swrast_device_driver *swdd =
153 _swrast_GetDeviceDriverReference(ctx);
154 swdd->SpanRenderStart = radeonSpanRenderStart;
155 swdd->SpanRenderFinish = radeonSpanRenderFinish;
156 }
157