make directory name inline with other tests
[AROS.git] / workbench / libs / mesa / src / gallium / state_trackers / arosmesa / arosmesa_funcs.c
blob8ac1290ee85f44c9ceb66d08d696eb17f0c735fd
1 /*
2 Copyright 2009-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "arosmesa_funcs.h"
7 #include <proto/utility.h>
8 #include <proto/exec.h>
9 #include <proto/graphics.h>
10 #include <proto/cybergraphics.h>
11 #include <cybergraphx/cybergraphics.h>
12 #include <graphics/rpattr.h>
13 #include <aros/debug.h>
15 VOID AROSMesaSelectRastPort(struct arosmesa_context * amesa, struct TagItem * tagList)
17 amesa->Screen = (struct Screen *)GetTagData(GLA_Screen, 0, tagList);
18 amesa->window = (struct Window *)GetTagData(GLA_Window, 0, tagList);
19 amesa->visible_rp = (struct RastPort *)GetTagData(GLA_RastPort, 0, tagList);
21 if (amesa->Screen)
23 D(bug("[AROSMESA] AROSMesaSelectRastPort: Screen @ %x\n", amesa->Screen));
24 if (amesa->window)
26 D(bug("[AROSMESA] AROSMesaSelectRastPort: Window @ %x\n", amesa->window));
27 if (!(amesa->visible_rp))
29 /* Use the windows rastport */
30 amesa->visible_rp = amesa->window->RPort;
31 D(bug("[AROSMESA] AROSMesaSelectRastPort: Windows RastPort @ %x\n", amesa->visible_rp));
34 else
36 if (!(amesa->visible_rp))
38 /* Use the screens rastport */
39 amesa->visible_rp = &amesa->Screen->RastPort;
40 D(bug("[AROSMESA] AROSMesaSelectRastPort: Screens RastPort @ %x\n", amesa->visible_rp));
44 else
46 /* Not passed a screen */
47 if (amesa->window)
49 D(bug("[AROSMESA] AROSMesaSelectRastPort: Window @ %x\n", amesa->window));
50 /* Use the windows Screen */
51 amesa->Screen = amesa->window->WScreen;
52 D(bug("[AROSMESA] AROSMesaSelectRastPort: Windows Screen @ %x\n", amesa->Screen));
54 if (!(amesa->visible_rp))
56 /* Use the windows rastport */
57 amesa->visible_rp = amesa->window->RPort;
58 D(bug("[AROSMESA] AROSMesaSelectRastPort: Windows RastPort @ %x\n", amesa->visible_rp));
61 else
63 /* Only Passed A Rastport */
64 D(bug("[AROSMESA] AROSMesaSelectRastPort: Using RastPort only!\n"));
68 D(bug("[AROSMESA] AROSMesaSelectRastPort: Using RastPort @ %x\n", amesa->visible_rp));
71 BOOL AROSMesaStandardInit(struct arosmesa_context * amesa, struct TagItem *tagList)
73 LONG requestedwidth = 0, requestedheight = 0;
74 LONG requestedright = 0, requestedbottom = 0;
75 LONG defaultleft = 0, defaulttop = 0;
76 LONG defaultright = 0, defaultbottom = 0;
78 /* Set the defaults based on window information */
79 if (amesa->window)
81 if(!(amesa->window->Flags & WFLG_GIMMEZEROZERO))
83 defaultleft = amesa->window->BorderLeft;
84 defaulttop = amesa->window->BorderTop;
85 defaultright = amesa->window->BorderRight;
86 defaultbottom = amesa->window->BorderBottom;
90 D(bug("[AROSMESA] AROSMesaStandardInit(amesa @ %x, taglist @ %x)\n", amesa, tagList));
91 D(bug("[AROSMESA] AROSMesaStandardInit: Using RastPort @ %x\n", amesa->visible_rp));
93 amesa->visible_rp = CloneRastPort(amesa->visible_rp);
95 D(bug("[AROSMESA] AROSMesaStandardInit: Cloned RastPort @ %x\n", amesa->visible_rp));
97 /* We assume left and top are given or if there is a window, set to border left/top
98 or if there is no window set to 0 */
99 amesa->left = GetTagData(GLA_Left, defaultleft, tagList);
100 amesa->top = GetTagData(GLA_Top, defaulttop, tagList);
102 requestedright = GetTagData(GLA_Right, -1, tagList);
103 requestedbottom = GetTagData(GLA_Bottom, -1, tagList);
104 requestedwidth = GetTagData(GLA_Width, -1 , tagList);
105 requestedheight = GetTagData(GLA_Height, -1 , tagList);
107 /* Calculate rastport dimensions */
108 amesa->visible_rp_width =
109 amesa->visible_rp->Layer->bounds.MaxX - amesa->visible_rp->Layer->bounds.MinX + 1;
111 amesa->visible_rp_height =
112 amesa->visible_rp->Layer->bounds.MaxY - amesa->visible_rp->Layer->bounds.MinY + 1;
114 /* right will be either passed or calculated from width or 0 */
115 amesa->right = 0;
116 if (requestedright < 0)
118 if (requestedwidth >= 0)
120 requestedright = amesa->visible_rp_width - amesa->left - requestedwidth;
121 if (requestedright < 0) requestedright = 0;
123 else
124 requestedright = defaultright; /* Set the default here, not in GetDataData */
126 amesa->right = requestedright;
128 /* bottom will be either passed or calculated from height or 0 */
129 amesa->bottom = 0;
130 if (requestedbottom < 0)
132 if (requestedheight >= 0)
134 requestedbottom = amesa->visible_rp_height - amesa->top - requestedheight;
135 if (requestedbottom < 0) requestedbottom = 0;
137 else
138 requestedbottom = defaultbottom; /* Set the default here, not in GetDataData */
140 amesa->bottom = requestedbottom;
142 /* Init screen information */
143 if (amesa->Screen)
144 amesa->BitsPerPixel = GetCyberMapAttr(amesa->Screen->RastPort.BitMap, CYBRMATTR_BPPIX) * 8;
146 D(bug("[AROSMESA] AROSMesaStandardInit: Context Base dimensions set -:\n"));
147 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->visible_rp_width = %d\n", amesa->visible_rp_width));
148 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->visible_rp_height = %d\n", amesa->visible_rp_height));
149 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->left = %d\n", amesa->left));
150 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->right = %d\n", amesa->right));
151 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->top = %d\n", amesa->top));
152 D(bug("[AROSMESA] AROSMesaStandardInit: amesa->bottom = %d\n", amesa->bottom));
154 return TRUE;
157 VOID AROSMesaRecalculateBufferWidthHeight(struct arosmesa_context * amesa)
159 ULONG newwidth = 0;
160 ULONG newheight = 0;
162 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight\n"));
165 amesa->visible_rp_width =
166 amesa->visible_rp->Layer->bounds.MaxX - amesa->visible_rp->Layer->bounds.MinX + 1;
168 amesa->visible_rp_height =
169 amesa->visible_rp->Layer->bounds.MaxY - amesa->visible_rp->Layer->bounds.MinY + 1;
172 newwidth = amesa->visible_rp_width - amesa->left - amesa->right;
173 newheight = amesa->visible_rp_height - amesa->top - amesa->bottom;
175 if (newwidth < 0) newwidth = 0;
176 if (newheight < 0) newheight = 0;
179 if ((newwidth != amesa->framebuffer->width) || (newheight != amesa->framebuffer->height))
181 /* The drawing area size has changed. Buffer must change */
182 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight: current height = %d\n", amesa->framebuffer->height));
183 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight: current width = %d\n", amesa->framebuffer->width));
184 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight: new height = %d\n", newheight));
185 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight: new width = %d\n", newwidth));
187 amesa->framebuffer->width = newwidth;
188 amesa->framebuffer->height = newheight;
189 amesa->framebuffer->resized = TRUE;
191 if (amesa->window)
193 struct Rectangle rastcliprect;
194 struct TagItem crptags[] =
196 { RPTAG_ClipRectangle , (IPTR)&rastcliprect },
197 { RPTAG_ClipRectangleFlags , (RPCRF_RELRIGHT | RPCRF_RELBOTTOM) },
198 { TAG_DONE }
201 D(bug("[AROSMESA] AROSMesaRecalculateBufferWidthHeight: Clipping Rastport to Window's dimensions\n"));
203 /* Clip the rastport to the visible area */
204 rastcliprect.MinX = amesa->left;
205 rastcliprect.MinY = amesa->top;
206 rastcliprect.MaxX = amesa->left + amesa->framebuffer->width;
207 rastcliprect.MaxY = amesa->top + amesa->framebuffer->height;
208 SetRPAttrsA(amesa->visible_rp, crptags);
213 VOID AROSMesaFreeContext(struct arosmesa_context * amesa)
215 if (amesa)
217 FreeVec(amesa);