Debian Codegraph @

2dlib/surface.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/2dlib/surface.cpp $
21 * $Revision: 7 $
22 * $Date: 11/30/98 5:50p $
23 * $Author: Jason $
24 *
25 * Master Surface class
26 *
27 * $Log: /DescentIII/Main/2dlib/surface.cpp $
28 *
29 * 7 11/30/98 5:50p Jason
30 * added 4444 bitmap support
31 *
32 * 6 4/23/98 6:38p Jason
33 * made bitmaps use 1555 format
34 *
35 * 5 12/19/97 2:26p Jason
36 * more fixes for 2d/3d intergration
37 *
38 * 4 12/19/97 12:32p Samir
39 * lock now calls renderer functions.
40 *
41 * 3 11/11/97 1:24p Samir
42 * Fixed problem with clearing using the renderer.
43 *
44 * 2 10/15/97 5:20p Jason
45 * did a HUGE overhaul of the bitmap system
46 *
47 * 24 6/12/97 6:29p Samir
48 * DDGR v2.0 Changes in 2d system implemented.
49 *
50 * 23 6/06/97 12:18p Samir
51 * OpenGL HACKS to call renderer for some drawing functions. Must fix.
52 *
53 * 22 5/19/97 5:10p Jason
54 * changes for our new abstracted renderer code
55 *
56 * 21 4/30/97 3:15p Jason
57 * changes to support both 8bit and 16bit rendering in software
58 *
59 * 20 3/28/97 3:07p Samir
60 * Clear function now takes a color
61 *
62 * 19 3/27/97 11:11a Samir
63 * Moved code from ddgr library to 2dlib because it was ANSI compliant and
64 * should work on all systems
65 *
66 * 18 2/28/97 2:51p Samir
67 * took out __cdecl in atexit function.
68 *
69 * 17 2/17/97 2:19p Jason
70 * made blit function scale instead of clip
71 *
72 * 16 2/11/97 3:19p Jason
73 * added displaying of 8bit palettized graphics on 16bit surfaces
74 *
75 * 15 2/04/97 12:49p Samir
76 * Added lock(x,y) for those special cases.
77 *
78 * 14 2/03/97 3:01p Samir
79 * Used one memory surface global to grSurface for scratchpad blitting.
80 *
81 * 13 1/30/97 6:01p Samir
82 * The partition of memory and os surfaces as well as the change in
83 * ddgr_surface structure and all related changes.
84 *
85 * $NoKeywords: $
86 */
87
88 #include <algorithm>
89 #include <cstdlib>
90 #include <cstring>
91
92 #include "bitmap.h"cxx . . $ `<file>/lib/bitmap.h`/
93 #include "lib2d.h"cxx . . $ `<file>/2dlib/lib2d.h`/
94 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
95 #include "renderer.h"cxx . . $ `<file>/lib/renderer.h`/
96
97 static inline unsigned XLAT_RGB_TO_16cxx . . $ XLAT_RGB_TO_16(2141b656ce2cc063).(ddgr_colorcxx . . $ ddgr_color# c) {
98 uint8_tcxx . . $ uint8_t# r, g, b;
99 r = (uint8_tcxx . . $ uint8_t#)((c & 0x00ff0000) >> 16);
100 g = (uint8_tcxx . . $ uint8_t#)((c & 0x0000ff00) >> 8);
101 b = (uint8_tcxx . . $ uint8_t#)(c & 0x000000ff);
102
103 return (((r >> 3) << 10) + ((g >> 3) << 5) + (b >> 3));
104 }
105
106 ddgr_surface_nodecxx . . $ ddgr_surface_node# *grSurfacecxx . . $ grSurface#::surf_listcxx . . $ grSurface#surf_list. = nullptr; // the surface list
107 ddgr_surface_nodecxx . . $ ddgr_surface_node# *grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur. = nullptr; // current node on list.
108 ddgr_surfacecxx . . $ ddgr_surface# *grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf. = nullptr;
109
110 void grSurfacecxx . . $ grSurface#::init_systemcxx . . $ grSurface#init_system(49f6e7a06ebc5aa8).() {
111 // allocate our scratch memory surface used in uniblt
112 if (!grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.) {
113 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf. = new ddgr_surfacecxx . . $ ddgr_surface#;
114 memset(grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf., 0, sizeof(ddgr_surfacecxx . . $ ddgr_surface#));
115 }
116
117 atexit(grSurfacecxx . . $ grSurface#::close_systemcxx . . $ grSurface#close_system(49f6e7a06ebc5aa8).);
118 }
119
120 void grSurfacecxx . . $ grSurface#::close_systemcxx . . $ grSurface#close_system(49f6e7a06ebc5aa8).() {
121 // cleanup our scratch memory surface for blt
122 if (grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.) {
123 if (grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->objcxx . . $ ddgr_surface#obj. != nullptr)
124 gr_mem_surf_Destroycxx . . $ gr_mem_surf_Destroy(8a7e7c096868029c).(grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.);
125
126 delete grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.;
127 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf. = nullptr;
128 }
129 }
130
131 // ---------------------------------------------------------------------------
132 // grSurface constructor and destructor
133 // ---------------------------------------------------------------------------
134
135 grSurfacecxx . . $ grSurface#::grSurfacecxx . . $ grSurface#grSurface(49f6e7a06ebc5aa8).() {
136 surf_Lockedcxx . . $ grSurface#surf_Locked. = 0;
137 m_SurfInitcxx . . $ grSurface#m_SurfInit. = 0;
138 memset(&ddsfObjcxx . . $ grSurface#ddsfObj., 0, sizeof(ddgr_surfacecxx . . $ ddgr_surface#));
139 }
140
141 grSurfacecxx . . $ grSurface#::grSurfacecxx . . $ grSurface#grSurface(589a245ae52835fb).(int w, int h, int bpp, unsigned type, unsigned flags, const char *name) {
142 surf_Lockedcxx . . $ grSurface#surf_Locked. = 0;
143 m_SurfInitcxx . . $ grSurface#m_SurfInit. = 0;
144
145 grSurfacecxx . . $ grSurface#::createcxx . . $ grSurface#create(589a245ae52835fb).(w, h, bpp, type, flags, name);
146 }
147
148 grSurfacecxx . . $ grSurface#::~cxx . . $ grSurface#`~grSurface`(ced63f7c635d850d).grSurfacecxx . . $ grSurface#() { grSurfacecxx . . $ grSurface#::freecxx . . $ grSurface#free(49f6e7a06ebc5aa8).(); }
149
150 void grSurfacecxx . . $ grSurface#::createcxx . . $ grSurface#create(589a245ae52835fb).(int w, int h, int bpp, unsigned type, unsigned flags, const char *name) {
151 bool grerr;
152
153 if (m_SurfInitcxx . . $ grSurface#m_SurfInit.)
154 grSurfacecxx . . $ grSurface#::freecxx . . $ grSurface#free(49f6e7a06ebc5aa8).();
155
156 // create new surface: set up surface structure
157 memset(&ddsfObjcxx . . $ grSurface#ddsfObj., 0, sizeof(ddgr_surfacecxx . . $ ddgr_surface#));
158 ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w. = w;
159 ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h. = h;
160 ddsfObjcxx . . $ grSurface#ddsfObj..bppcxx . . $ ddgr_surface#bpp. = bpp;
161 ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type. = (uint16_tcxx . . $ uint16_t#)type;
162 ddsfObjcxx . . $ grSurface#ddsfObj..flagscxx . . $ ddgr_surface#flags. = (uint16_tcxx . . $ uint16_t#)flags;
163
164 if (name)
165 strncpy(ddsfObjcxx . . $ grSurface#ddsfObj..namecxx . . $ ddgr_surface#name., name, 15);
166
167 switch (type) {
168 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
169 grerr = ddgr_surf_InitVideocxx . . $ ddgr_surf_InitVideo(8a7e7c096868029c).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
170 break;
171 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
172 grerr = ddgr_surf_Createcxx . . $ ddgr_surf_Create(8a7e7c096868029c).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
173 break;
174 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
175 grerr = (bool)gr_mem_surf_Createcxx . . $ gr_mem_surf_Create(8a7e7c096868029c).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
176 break;
177 default:
178 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Invalid!!
179 }
180 if (!grerr)
181 Int3cxx . . $ `misc/pserror.h:247:9`!();
182
183 add_to_listcxx . . $ grSurface#add_to_list(b6325dd6f6bb1424).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
184
185 m_SurfInitcxx . . $ grSurface#m_SurfInit. = 1;
186 }
187
188 void grSurfacecxx . . $ grSurface#::freecxx . . $ grSurface#free(49f6e7a06ebc5aa8).() {
189 /* Freeing surface is same regardless of whether it was loaded from a bitmap handle or
190 created ourselves
191 */
192 if (!m_SurfInitcxx . . $ grSurface#m_SurfInit.)
193 return;
194 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!surf_Locked);
195
196 switch (ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type.) {
197 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
198 ddgr_surf_CloseVideocxx . . $ ddgr_surf_CloseVideo(b6325dd6f6bb1424).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
199 break;
200 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
201 ddgr_surf_Destroycxx . . $ ddgr_surf_Destroy(b6325dd6f6bb1424).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
202 break;
203 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
204 gr_mem_surf_Destroycxx . . $ gr_mem_surf_Destroy(8a7e7c096868029c).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
205 break;
206 default:
207 Int3cxx . . $ `misc/pserror.h:247:9`!(); // This really shouldn't happen. bad type!
208 }
209
210 remove_from_listcxx . . $ grSurface#remove_from_list(b6325dd6f6bb1424).(&ddsfObjcxx . . $ grSurface#ddsfObj.);
211
212 m_SurfInitcxx . . $ grSurface#m_SurfInit. = 0;
213 }
214
215 void grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(d4f767463ce0a6b3).(int handle) {
216 /* just load the bitmap from the handle info */
217 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
218
219 grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(e90830e4537cf0fa).((char *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, 0), bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, 0), bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, 0), bm_bppcxx . . $ bm_bpp(7864480464b09eea).(handle), bm_formatcxx . . $ bm_format(7864480464b09eea).(handle));
220 }
221
222 void grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(e90830e4537cf0fa).(char *data, int w, int h, int bpp, int format) {
223 // copy defined bitmap given as arguments to this surface, with correct bpp translation.
224 int rowsize;
225 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
226
227 /* perform lock, then copy data to this surface, then unlock */
228 grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize);
229
230 switch (ddsfObjcxx . . $ grSurface#ddsfObj..bppcxx . . $ ddgr_surface#bpp.) {
231 case BPP_16cxx . . $ `lib/grdefs.h:61:9`!:
232 if (bpp == BPP_16cxx . . $ `lib/grdefs.h:61:9`!)
233 xlat16_16cxx . . $ grSurface#xlat16_16(51648a5edc2089b5).(data, w, h, format);
234 if (bpp == BPP_24cxx . . $ `lib/grdefs.h:62:9`!)
235 xlat24_16cxx . . $ grSurface#xlat24_16(dcbbfe1ffd04514b).(data, w, h);
236 if (bpp == BPP_32cxx . . $ `lib/grdefs.h:63:9`!)
237 xlat32_16cxx . . $ grSurface#xlat32_16(dcbbfe1ffd04514b).(data, w, h);
238 break;
239
240 case BPP_24cxx . . $ `lib/grdefs.h:62:9`!:
241 if (bpp == BPP_16cxx . . $ `lib/grdefs.h:61:9`!)
242 xlat16_24cxx . . $ grSurface#xlat16_24(dcbbfe1ffd04514b).(data, w, h);
243 break;
244
245 default:
246 Int3cxx . . $ `misc/pserror.h:247:9`!(); // NOT SUPPORTED YET
247 }
248
249 grSurfacecxx . . $ grSurface#::unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).();
250 }
251
252 // loads 8bit palettized data onto this surface.
253 void grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(577809987ad7a468).(int handle, char *pal) {
254 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
255
256 grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(1428750e2ba86a39).((char *)bm_datacxx . . $ bm_data(501e1bc9f482c6bd).(handle, 0), bm_wcxx . . $ bm_w(9b79fb6aee4c0440).(handle, 0), bm_hcxx . . $ bm_h(9b79fb6aee4c0440).(handle, 0), pal);
257 }
258
259 // loads 8bit palettized data onto this surface.
260 void grSurfacecxx . . $ grSurface#::loadcxx . . $ grSurface#load(1428750e2ba86a39).(char *data, int w, int h, char *pal) {
261 int rowsize;
262 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
263
264 /* perform lock, then copy data to this surface, then unlock */
265 grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize);
266
267 switch (ddsfObjcxx . . $ grSurface#ddsfObj..bppcxx . . $ ddgr_surface#bpp.) {
268 case BPP_16cxx . . $ `lib/grdefs.h:61:9`!:
269 // TODO: This is probably software renderer only?
270 xlat16_16cxx . . $ grSurface#xlat16_16(51648a5edc2089b5).(data, w, h);
271 default:
272 Int3cxx . . $ `misc/pserror.h:247:9`!(); // NOT SUPPORTED YET
273 }
274
275 grSurfacecxx . . $ grSurface#::unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).();
276 }
277
278 // ---------------------------------------------------------------------------
279 // blt functions:: clear
280 // ---------------------------------------------------------------------------
281
282 void grSurfacecxx . . $ grSurface#::clearcxx . . $ grSurface#clear(cb2f890c2fdad230).(ddgr_colorcxx . . $ ddgr_color# col) { grSurfacecxx . . $ grSurface#::clearcxx . . $ grSurface#clear(6fb2c7d311165c4f).(0, 0, ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w., ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h., col); }
283
284 void grSurfacecxx . . $ grSurface#::clearcxx . . $ grSurface#clear(6fb2c7d311165c4f).(int l, int t, int w, int h, ddgr_colorcxx . . $ ddgr_color# col) {
285 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
286 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!surf_Locked);
287
288 switch (ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type.) {
289 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
290 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
291 // HACK!!!!!!! I MUST CHANGE THIS
292 // ---------------------------------------------------------------------------
293 if (ddsfObjcxx . . $ grSurface#ddsfObj..flagscxx . . $ ddgr_surface#flags. & SURFFLAG_RENDERERcxx . . $ SURFFLAG_RENDERER.) {
294 rend_FillRectcxx . . $ rend_FillRect(fe09a4b73d8d396f).(col, l, t, l + w, t + h);
295 return;
296 }
297 // ---------------------------------------------------------------------------
298 ddgr_surf_Clearcxx . . $ ddgr_surf_Clear(18895a2c8f8b731a).(&ddsfObjcxx . . $ grSurface#ddsfObj., col, l, t, w, h);
299 break;
300 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
301 gr_mem_surf_Clearcxx . . $ gr_mem_surf_Clear(18895a2c8f8b731a).(&ddsfObjcxx . . $ grSurface#ddsfObj., col, l, t, w, h);
302 break;
303 default:
304 Int3cxx . . $ `misc/pserror.h:247:9`!();
305 }
306 }
307
308 // ---------------------------------------------------------------------------
309 // blt functions:
310 // these functions must support memory->os, os->memory, os->os, mem->mem blts.
311 // note that (os) blts and (video) blts use the os library.
312 // ---------------------------------------------------------------------------
313
314 void grSurfacecxx . . $ grSurface#::unibltcxx . . $ grSurface#uniblt(ff120d6cc88a52cd).(int dx, int dy, grSurfacecxx . . $ grSurface# *ssf, int sx, int sy, int sw, int sh) {
315 int rowsize;
316
317 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
318
319 // mode 11b = dd_to_dd, 01b = mem_to_dd, 10b = dd_to_mem, 00b = mem_to_mem
320 int mode = 0;
321 ddgr_surfacecxx . . $ ddgr_surface# *dsfs = &ddsfObjcxx . . $ grSurface#ddsfObj., *ssfs = &ssf->ddsfObjcxx . . $ grSurface#ddsfObj.;
322 bool err;
323
324 // setup blitting mode
325 if (ssfs->typecxx . . $ ddgr_surface#type. == SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC. || ssfs->typecxx . . $ ddgr_surface#type. == SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.)
326 mode = mode | 0x1;
327 if (dsfs->typecxx . . $ ddgr_surface#type. == SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC. || dsfs->typecxx . . $ ddgr_surface#type. == SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.)
328 mode = mode | 0x2;
329
330 /* case 1: os->os
331 just invoke os blitter
332 */
333 if (mode == 0x3) {
334 ASSERTcxx . . $ `misc/pserror.h:246:9`!(!surf_Locked);
335 err = ddgr_surf_Bltcxx . . $ ddgr_surf_Blt(5ac5614b4169eec2).(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
336 return;
337 }
338
339 /* case 2: mem->mem
340 just lock both surfaces and do a memory blt.
341 */
342 if (mode == 0) {
343 err = gr_mem_surf_Bltcxx . . $ gr_mem_surf_Blt(5ac5614b4169eec2).(dsfs, dx, dy, ssfs, sx, sy, sw, sh);
344 return;
345 }
346
347 /* case 3: os->mem
348 This requires locking both surfaces and performing a memory blt.
349 This also means tricking the memory blitter into thinking that the OS surface
350 is a memory surface
351 */
352 if (mode == 0x1) {
353 char *data = ssf->lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize);
354
355 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->wcxx . . $ ddgr_surface#w. = ssfs->wcxx . . $ ddgr_surface#w.;
356 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->hcxx . . $ ddgr_surface#h. = ssfs->hcxx . . $ ddgr_surface#h.;
357 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->bppcxx . . $ ddgr_surface#bpp. = ssfs->bppcxx . . $ ddgr_surface#bpp.;
358 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->typecxx . . $ ddgr_surface#type. = SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.;
359 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->flagscxx . . $ ddgr_surface#flags. = ssfs->flagscxx . . $ ddgr_surface#flags.;
360
361 gr_mem_surf_Initcxx . . $ gr_mem_surf_Init(29b5e7245e149caf).(grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf., data, rowsize);
362 err = gr_mem_surf_Bltcxx . . $ gr_mem_surf_Blt(5ac5614b4169eec2).(dsfs, dx, dy, grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf., sx, sy, sw, sh);
363
364 ssf->unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).();
365 return;
366 }
367
368 /* case 4: mem->os
369 This requires locking both surfaces and performing a memory blt.
370 This also means tricking the memory blitter into thinking that the OS surface
371 is a memory surface
372 */
373 if (mode == 0x2) {
374 grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize);
375
376 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->wcxx . . $ ddgr_surface#w. = dsfs->wcxx . . $ ddgr_surface#w.;
377 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->hcxx . . $ ddgr_surface#h. = dsfs->hcxx . . $ ddgr_surface#h.;
378 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->bppcxx . . $ ddgr_surface#bpp. = dsfs->bppcxx . . $ ddgr_surface#bpp.;
379 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->typecxx . . $ ddgr_surface#type. = SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.;
380 grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf.->flagscxx . . $ ddgr_surface#flags. = dsfs->flagscxx . . $ ddgr_surface#flags.;
381
382 gr_mem_surf_Initcxx . . $ gr_mem_surf_Init(29b5e7245e149caf).(grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf., m_DataPtrcxx . . $ grSurface#m_DataPtr., m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
383 err = gr_mem_surf_Bltcxx . . $ gr_mem_surf_Blt(5ac5614b4169eec2).(grSurfacecxx . . $ grSurface#::scratch_mem_surfcxx . . $ grSurface#scratch_mem_surf., dx, dy, ssfs, sx, sy, sw, sh);
384
385 grSurfacecxx . . $ grSurface#::unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).();
386 return;
387 }
388 }
389
390 void grSurfacecxx . . $ grSurface#::bltcxx . . $ grSurface#blt(3c4a031b05aa6aa3).(int dx, int dy, grSurfacecxx . . $ grSurface# *ssf) {
391 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
392 grSurfacecxx . . $ grSurface#::unibltcxx . . $ grSurface#uniblt(ff120d6cc88a52cd).(dx, dy, ssf, 0, 0, ssf->widthcxx . . $ grSurface#width(455f465bc33b4cdf).(), ssf->heightcxx . . $ grSurface#height(455f465bc33b4cdf).());
393 }
394
395 void grSurfacecxx . . $ grSurface#::bltcxx . . $ grSurface#blt(ff120d6cc88a52cd).(int dx, int dy, grSurfacecxx . . $ grSurface# *ssf, int sx, int sy, int sw, int sh) {
396 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
397 grSurfacecxx . . $ grSurface#::unibltcxx . . $ grSurface#uniblt(ff120d6cc88a52cd).(dx, dy, ssf, sx, sy, sw, sh);
398 }
399
400 /* Helper functions
401 replace_color, simply replaces one color in the surface with another
402 */
403 void grSurfacecxx . . $ grSurface#::replace_colorcxx . . $ grSurface#replace_color(b4d55b1286ff73e8).(ddgr_colorcxx . . $ ddgr_color# sc, ddgr_colorcxx . . $ ddgr_color# dc) {
404 int rowsize;
405 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
406
407 grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(&rowsize);
408
409 switch (ddsfObjcxx . . $ grSurface#ddsfObj..bppcxx . . $ ddgr_surface#bpp.) {
410 case BPP_16cxx . . $ `lib/grdefs.h:61:9`!: {
411 uint16_tcxx . . $ uint16_t# *data = (uint16_tcxx . . $ uint16_t# *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
412 int rowsize_w = m_DataRowsizecxx . . $ grSurface#m_DataRowsize. / 2;
413 uint16_tcxx . . $ uint16_t# scc = XLAT_RGB_TO_16cxx . . $ XLAT_RGB_TO_16(2141b656ce2cc063).(sc), dcc = XLAT_RGB_TO_16cxx . . $ XLAT_RGB_TO_16(2141b656ce2cc063).(dc);
414
415 for (int y = 0; y < ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.; y++) {
416 for (int x = 0; x < ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.; x++)
417 if (data[x] == scc)
418 data[x] = dcc;
419
420 data += rowsize_w;
421 }
422 break;
423 }
424
425 case BPP_32cxx . . $ `lib/grdefs.h:63:9`!:
426 default:
427 Int3cxx . . $ `misc/pserror.h:247:9`!();
428 }
429
430 grSurfacecxx . . $ grSurface#::unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).();
431 }
432
433 // ---------------------------------------------------------------------------
434 // lock and unlock functions
435 // these handle memory and os locks
436 // ---------------------------------------------------------------------------
437
438 char *grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(3f31f7b3b80edb32).(int *rowsize) {
439 bool grerr;
440
441 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
442
443 switch (ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type.) {
444 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
445 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
446 grerr = ddgr_surf_Lockcxx . . $ ddgr_surf_Lock(52c8467f55fe71c1).(&ddsfObjcxx . . $ grSurface#ddsfObj., (void **)&m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr., &m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
447 break;
448 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
449 grerr = gr_mem_surf_Lockcxx . . $ gr_mem_surf_Lock(52c8467f55fe71c1).(&ddsfObjcxx . . $ grSurface#ddsfObj., (void **)&m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr., &m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
450 break;
451 default:
452 Int3cxx . . $ `misc/pserror.h:247:9`!(); // invalid type!!
453 }
454
455 m_DataPtrcxx . . $ grSurface#m_DataPtr. = m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.;
456 *rowsize = m_DataRowsizecxx . . $ grSurface#m_DataRowsize.;
457
458 if (!grerr)
459 return nullptr;
460
461 surf_Lockedcxx . . $ grSurface#surf_Locked.++; // increment lock counter for this surface
462
463 rend_SetSoftwareParameterscxx . . $ rend_SetSoftwareParameters(d26b1bbbc1a6742).(ddgr_GetAspectRatiocxx . . $ ddgr_GetAspectRatio(9b8c9e39889c762c).(), ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w., ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h., m_DataRowsizecxx . . $ grSurface#m_DataRowsize., (uint8_tcxx . . $ uint8_t# *)m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.);
464
465 return m_DataPtrcxx . . $ grSurface#m_DataPtr.;
466 }
467
468 /* do lock based off of x,y offsets */
469 char *grSurfacecxx . . $ grSurface#::lockcxx . . $ grSurface#lock(f35eb304381040d9).(int x, int y, int *rowsize) {
470 bool grerr = false;
471
472 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
473
474 switch (ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type.) {
475 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
476 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
477 grerr = ddgr_surf_Lockcxx . . $ ddgr_surf_Lock(52c8467f55fe71c1).(&ddsfObjcxx . . $ grSurface#ddsfObj., (void **)&m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr., &m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
478 break;
479 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
480 grerr = gr_mem_surf_Lockcxx . . $ gr_mem_surf_Lock(52c8467f55fe71c1).(&ddsfObjcxx . . $ grSurface#ddsfObj., (void **)&m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr., &m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
481 break;
482 default:
483 Int3cxx . . $ `misc/pserror.h:247:9`!(); // invalid type!!
484 }
485
486 *rowsize = m_DataRowsizecxx . . $ grSurface#m_DataRowsize.;
487 if (!grerr)
488 return nullptr;
489
490 /* calculate the adjusted data pointer based off of x,y,bpp */
491 char *data = m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.;
492
493 data += (y * m_DataRowsizecxx . . $ grSurface#m_DataRowsize.);
494
495 switch (ddsfObjcxx . . $ grSurface#ddsfObj..bppcxx . . $ ddgr_surface#bpp.) {
496 case BPP_16cxx . . $ `lib/grdefs.h:61:9`!:
497 data += (x * 2);
498 break;
499 case BPP_32cxx . . $ `lib/grdefs.h:63:9`!:
500 data += (x * 4);
501 break;
502 default:
503 Int3cxx . . $ `misc/pserror.h:247:9`!();
504 }
505
506 m_DataPtrcxx . . $ grSurface#m_DataPtr. = data;
507
508 surf_Lockedcxx . . $ grSurface#surf_Locked.++; // increment lock counter for this surface
509
510 rend_SetSoftwareParameterscxx . . $ rend_SetSoftwareParameters(d26b1bbbc1a6742).(ddgr_GetAspectRatiocxx . . $ ddgr_GetAspectRatio(9b8c9e39889c762c).(), ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w., ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h., m_DataRowsizecxx . . $ grSurface#m_DataRowsize., (uint8_tcxx . . $ uint8_t# *)m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.);
511
512 return m_DataPtrcxx . . $ grSurface#m_DataPtr.;
513 }
514
515 void grSurfacecxx . . $ grSurface#::unlockcxx . . $ grSurface#unlock(49f6e7a06ebc5aa8).() {
516 bool grerr;
517
518 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
519 ASSERTcxx . . $ `misc/pserror.h:246:9`!(surf_Locked);
520
521 switch (ddsfObjcxx . . $ grSurface#ddsfObj..typecxx . . $ ddgr_surface#type.) {
522 case SURFTYPE_VIDEOSCREENcxx . . $ SURFTYPE_VIDEOSCREEN.:
523 case SURFTYPE_GENERICcxx . . $ SURFTYPE_GENERIC.:
524 grerr = ddgr_surf_Unlockcxx . . $ ddgr_surf_Unlock(274a3a14c0c4a006).(&ddsfObjcxx . . $ grSurface#ddsfObj., m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.);
525 break;
526 case SURFTYPE_MEMORYcxx . . $ SURFTYPE_MEMORY.:
527 grerr = gr_mem_surf_Unlockcxx . . $ gr_mem_surf_Unlock(274a3a14c0c4a006).(&ddsfObjcxx . . $ grSurface#ddsfObj., m_OrigDataPtrcxx . . $ grSurface#m_OrigDataPtr.);
528 break;
529 default:
530 Int3cxx . . $ `misc/pserror.h:247:9`!(); // invalid type!!
531 }
532
533 surf_Lockedcxx . . $ grSurface#surf_Locked.--;
534 }
535
536 // ---------------------------------------------------------------------------
537 // miscellaneous
538 // ---------------------------------------------------------------------------
539
540 void grSurfacecxx . . $ grSurface#::attach_to_windowcxx . . $ grSurface#attach_to_window(cb2f890c2fdad230).(unsigned handle) {
541 ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_SurfInit);
542 ddgr_surf_AttachHandlecxx . . $ ddgr_surf_AttachHandle(a3d021018aea9e2c).(&ddsfObjcxx . . $ grSurface#ddsfObj., handle);
543 }
544
545 // Private functions
546 // conversion_xlat
547 // ---------------------------------------------------------------------------
548
549 void grSurfacecxx . . $ grSurface#::xlat8_16cxx . . $ grSurface#xlat8_16(1428750e2ba86a39).(char *data, int w, int h, char *pal) {
550 /* copy from 8bit source bitmap to destination surface just created and
551 locked
552 */
553 uint16_tcxx . . $ uint16_t# *dptr;
554 char *sptr;
555 int row, col;
556 int rowsize_w;
557 int height, width;
558 uint8_tcxx . . $ uint8_t# *upal = (uint8_tcxx . . $ uint8_t# *)pal;
559
560 dptr = (uint16_tcxx . . $ uint16_t# *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
561 sptr = (char *)data;
562 rowsize_w = m_DataRowsizecxx . . $ grSurface#m_DataRowsize. / 2;
563
564 height = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(h, ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.);
565 width = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(w, ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.);
566
567 for (row = 0; row < height; row++) {
568 for (col = 0; col < width; col++) {
569 uint8_tcxx . . $ uint8_t# spix = sptr[col];
570 if (spix != 0) {
571 int r = upal[spix * 3] >> 3;
572 int g = upal[spix * 3 + 1] >> 2;
573 int b = upal[spix * 3 + 2] >> 3;
574 uint16_tcxx . . $ uint16_t# destpix = (r << 11) | (g << 5) | b;
575
576 dptr[col] = destpix;
577 } else
578 dptr[col] = 0;
579 }
580 sptr += 256;
581 dptr += rowsize_w;
582 }
583 }
584
585 void grSurfacecxx . . $ grSurface#::xlat16_16cxx . . $ grSurface#xlat16_16(51648a5edc2089b5).(char *data, int w, int h, int format) {
586 /* 16-bit copy from source bitmap to destination surface just created and
587 locked
588 This function performs scaling if the source width and height don't match
589 that of the destinations - JL
590 */
591 uint16_tcxx . . $ uint16_t# *sptr, *dptr;
592 int row, col;
593 int rowsize_w;
594 int height, width;
595 fixcxx . . $ fix# xstep = IntToFixcxx . . $ `fix/fix.h:105:9`!(w) / ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.;
596 fixcxx . . $ fix# ystep = IntToFixcxx . . $ `fix/fix.h:105:9`!(h) / ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.;
597 fixcxx . . $ fix# fu = 0, fv = 0;
598
599 dptr = (uint16_tcxx . . $ uint16_t# *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
600 sptr = (uint16_tcxx . . $ uint16_t# *)data;
601 rowsize_w = m_DataRowsizecxx . . $ grSurface#m_DataRowsize. / 2;
602
603 height = ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.;
604 width = ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.;
605
606 // height = SET_MIN(h, ddsfObj.h);
607 // width = SET_MIN(w, ddsfObj.w);
608
609 for (row = 0; row < height; row++, fv += ystep, fu = 0) {
610 for (col = 0; col < width; col++, fu += xstep) {
611 int newpix;
612
613 if (format == BITMAP_FORMAT_1555cxx . . $ `lib/bitmap.h:56:9`!)
614 newpix = sptr[(FixToIntcxx . . $ `fix/fix.h:108:9`!(fv) * w) + FixToIntcxx . . $ `fix/fix.h:108:9`!(fu)];
615 else {
616 int temp_pix = sptr[(FixToIntcxx . . $ `fix/fix.h:108:9`!(fv) * w) + FixToIntcxx . . $ `fix/fix.h:108:9`!(fu)];
617 int r = (temp_pix >> 8) & 0xf;
618 int g = (temp_pix >> 4) & 0xf;
619 int b = (temp_pix) & 0xf;
620
621 r <<= 4;
622 g <<= 4;
623 b <<= 4;
624
625 newpix = OPAQUE_FLAGcxx . . $ `lib/grdefs.h:72:9`! | GR_RGB16cxx . . $ GR_RGB16(6461fafb79bad5b9).(r, g, b);
626 }
627
628 dptr[col] = newpix;
629 }
630
631 dptr += rowsize_w;
632 }
633 }
634
635 void grSurfacecxx . . $ grSurface#::xlat16_24cxx . . $ grSurface#xlat16_24(dcbbfe1ffd04514b).(char *data, int w, int h) {
636 uint16_tcxx . . $ uint16_t# *sptr;
637 char *dptr;
638 int scol, dcol, row;
639 int height, width;
640
641 dptr = (char *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
642 sptr = (uint16_tcxx . . $ uint16_t# *)data;
643 height = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(h, ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.);
644 width = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(w, ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.);
645
646 for (row = 0; row < height; row++) {
647 dcol = 0;
648 for (scol = 0; scol < width; scol++) {
649 uint16_tcxx . . $ uint16_t# pix;
650 ddgr_colorcxx . . $ ddgr_color# new_color;
651 char r, g, b;
652 pix = sptr[scol];
653
654 new_color = GR_16_TO_COLORcxx . . $ GR_16_TO_COLOR(909d59720f161188).(pix);
655
656 r = GR_COLOR_REDcxx . . $ GR_COLOR_RED(4c679297bf94b9eb).(new_color);
657 g = GR_COLOR_GREENcxx . . $ GR_COLOR_GREEN(4c679297bf94b9eb).(new_color);
658 b = GR_COLOR_BLUEcxx . . $ GR_COLOR_BLUE(4c679297bf94b9eb).(new_color);
659
660 dptr[dcol++] = r;
661 dptr[dcol++] = g;
662 dptr[dcol++] = b;
663 }
664 sptr += w;
665 dptr += m_DataRowsizecxx . . $ grSurface#m_DataRowsize.;
666 }
667 }
668
669 void grSurfacecxx . . $ grSurface#::xlat24_16cxx . . $ grSurface#xlat24_16(dcbbfe1ffd04514b).(char *data, int w, int h) {
670 char *sptr;
671 uint16_tcxx . . $ uint16_t# *dptr;
672 int scol, dcol, row;
673 int rowsize_w, height, width;
674
675 dptr = (uint16_tcxx . . $ uint16_t# *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
676 sptr = (char *)data;
677 rowsize_w = m_DataRowsizecxx . . $ grSurface#m_DataRowsize. / 2;
678 height = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(h, ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.);
679 width = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(w, ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.);
680
681 for (row = 0; row < height; row++) {
682 scol = 0;
683 for (dcol = 0; dcol < width; dcol++) {
684 uint16_tcxx . . $ uint16_t# pix;
685 char r, g, b;
686 r = sptr[scol++];
687 g = sptr[scol++];
688 b = sptr[scol++];
689 pix = ((uint16_tcxx . . $ uint16_t#)(r >> 3) << 11) + ((uint16_tcxx . . $ uint16_t#)(g >> 2) << 5) + ((uint16_tcxx . . $ uint16_t#)(b >> 3));
690 dptr[dcol] = pix;
691 }
692 sptr += (w * 3);
693 dptr += m_DataRowsizecxx . . $ grSurface#m_DataRowsize.;
694 }
695 }
696
697 void grSurfacecxx . . $ grSurface#::xlat32_16cxx . . $ grSurface#xlat32_16(dcbbfe1ffd04514b).(char *data, int w, int h) {
698 unsigned *sptr;
699 uint16_tcxx . . $ uint16_t# *dptr;
700 int col, row;
701 int rowsize_w, height, width;
702
703 ASSERTcxx . . $ `misc/pserror.h:246:9`!((w % 4) == 0);
704
705 dptr = (uint16_tcxx . . $ uint16_t# *)m_DataPtrcxx . . $ grSurface#m_DataPtr.;
706 sptr = (unsigned *)data;
707 rowsize_w = m_DataRowsizecxx . . $ grSurface#m_DataRowsize. / 2;
708 height = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(h, ddsfObjcxx . . $ grSurface#ddsfObj..hcxx . . $ ddgr_surface#h.);
709 width = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(w, ddsfObjcxx . . $ grSurface#ddsfObj..wcxx . . $ ddgr_surface#w.);
710
711 for (row = 0; row < height; row++) {
712 for (col = 0; col < width; col++) {
713 unsigned pix;
714 uint16_tcxx . . $ uint16_t# spix;
715
716 pix = sptr[col];
717 spix = (uint16_tcxx . . $ uint16_t#)(pix & 0x000000f8) >> 3;
718 spix |= (uint16_tcxx . . $ uint16_t#)(pix & 0x0000fc00) >> 5;
719 spix |= (uint16_tcxx . . $ uint16_t#)(pix & 0x00f80000) >> 8;
720 dptr[col] = spix;
721 }
722 sptr += w;
723 dptr += rowsize_w;
724 }
725 }
726
727 //-----------------------------------------------------------------------------
728 // surface list functions
729
730 void grSurfacecxx . . $ grSurface#::add_to_listcxx . . $ grSurface#add_to_list(b6325dd6f6bb1424).(ddgr_surfacecxx . . $ ddgr_surface# *sf) {
731 ddgr_surface_nodecxx . . $ ddgr_surface_node# *node;
732
733 ASSERTcxx . . $ `misc/pserror.h:246:9`!(sf != nullptr);
734
735 if (!grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur.) {
736 // first surface on list
737 node = new ddgr_surface_nodecxx . . $ ddgr_surface_node#;
738 node->sfcxx . . $ ddgr_surface_node#sf. = sf;
739 node->prevcxx . . $ ddgr_surface_node#prev. = nullptr;
740 grSurfacecxx . . $ grSurface#::surf_listcxx . . $ grSurface#surf_list. = grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur. = node;
741 } else {
742 // next surface on list.
743 node = new ddgr_surface_nodecxx . . $ ddgr_surface_node#;
744 node->sfcxx . . $ ddgr_surface_node#sf. = sf;
745 node->prevcxx . . $ ddgr_surface_node#prev. = grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur.;
746 grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur. = node;
747 }
748
749 // mprintf(0, "Allocated surface %s [%d].\n", sf->name, DDData.surfs_alloc);
750 }
751
752 void grSurfacecxx . . $ grSurface#::remove_from_listcxx . . $ grSurface#remove_from_list(b6325dd6f6bb1424).(ddgr_surfacecxx . . $ ddgr_surface# *sf) {
753 ddgr_surface_nodecxx . . $ ddgr_surface_node# *node, *next_node;
754
755 ASSERTcxx . . $ `misc/pserror.h:246:9`!(grSurface::surf_list_cur);
756 ASSERTcxx . . $ `misc/pserror.h:246:9`!(sf != nullptr);
757
758 // node is current node. next node is node after it on the list. since we are
759 // going from end to beginning, this may confuse you.
760 node = grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur.;
761 next_node = nullptr; // grSurface::surf_list_cur should be at end of list, so no next node
762
763 while (node) {
764 if (node->sfcxx . . $ ddgr_surface_node#sf. == sf) {
765 if (next_node) { // delete from within list.
766 next_node->prevcxx . . $ ddgr_surface_node#prev. = node->prevcxx . . $ ddgr_surface_node#prev.;
767 } else { // delete from end of list. set list tail to deleted node prev.
768 grSurfacecxx . . $ grSurface#::surf_list_curcxx . . $ grSurface#surf_list_cur. = node->prevcxx . . $ ddgr_surface_node#prev.;
769 }
770 delete node;
771
772 node = nullptr; // break out of loop
773 } else {
774 // go down one node.
775 next_node = node;
776 node = node->prevcxx . . $ ddgr_surface_node#prev.;
777 }
778 }
779
780 // mprintf(0, "Freed surface %s [%d].\n", sf->name, DDData.surfs_alloc);
781 }